// JavaScript Document


$(document).ready(function() {
	
	$("#main_other_wrapper").hide();
	$("#main_other_wrapper2").hide();
	$("#js").val("yes");
	$("#thecaptcha").hide();
	
	

	
	jQuery.validator.messages.phoneUS = "";
	jQuery.validator.messages.email = "";
	jQuery.validator.messages.required = "";
	
	jQuery.validator.addMethod("phoneUS", function(phone_number, element) {
    phone_number = phone_number.replace(/\s+/g, ""); 
	return this.optional(element) || phone_number.length > 9 &&
		phone_number.match(/^(1-?)?(\([2-9]\d{2}\)|[2-9]\d{2})-?[2-9]\d{2}-?\d{4}$/);
	}, "");

	
	if($("#contact_form").length > 0){
		$("#contact_form").validate({
		invalidHandler: function(e, validator) {
			var errors = validator.numberOfInvalids();
			if (errors) {
				var message = errors == 1
					? 'You missed 1 field. It has been highlighted above'
					: 'You missed ' + errors + ' fields.  They have been highlighted above';
				$("div.error span").html(message);
				$("div.error").show();
			} else {
				$("div.error").hide();
			}
		}
		});
	}
	
	
	
	$("#mini_fname").focus(function(){
		if($("#mini_fname").val() == "First Name"){
			$("#mini_fname").val("");	
		}
	});
	
	$("#mini_lname").focus(function(){
		if($("#mini_lname").val() == "Last Name"){
			$("#mini_lname").val("");	
		}
	});
	
	$("#mini_phone").focus(function(){
		if($("#mini_phone").val() == "Phone"){
			$("#mini_phone").val("");	
		}
	});
	
	$("#mini_email").focus(function(){
		if($("#mini_email").val() == "e-Mail"){
			$("#mini_email").val("");	
		}
	});
	
	$("#mini_comment").focus(function(){
		if($("#mini_comment").val() == "Tell us more                                           (limit 200 characters)"){
			$("#mini_comment").val("");	
		}
	});
	
	$("#mini_fname").blur(function(){
		if($("#mini_fname").val() == ""){
			$("#mini_fname").val("First Name");	
		}
	});
	
	$("#mini_lname").blur(function(){
		if($("#mini_lname").val() == ""){
			$("#mini_lname").val("Last Name");	
		}
	});
	
	$("#mini_phone").blur(function(){
		if($("#mini_phone").val() == ""){
			$("#mini_phone").val("Phone");	
		}
	});
	
	$("#mini_email").blur(function(){
		if($("#mini_email").val() == ""){
			$("#mini_email").val("e-Mail");	
		}
	});
	
	$("#mini_comment").blur(function(){
		if($("#mini_comment").val() == ""){
			$("#mini_comment").val("Tell us more                                           (limit 200 characters)");	
		}
	});
		
		
		
	
	
	if($("#mini_form").length >0){
		$("#mini_form").validate();
	}
	
	
		
	$("#how_heard").change(function(){
		if($('#other1:selected').length){
			$("#main_other_wrapper").show();
		}
		else
		{
			$("#main_other_wrapper").hide();
		}
		
		
	});
	
	$("#interested").change(function(){
		if($('#other2:selected').length){
			$("#main_other_wrapper2").show();
		}
		else
		{
			$("#main_other_wrapper2").hide();
		}
		
		
	});
	
	
	

	
	
	
});

