// JavaScript Document


$(document).ready(function() {
	
	$("#main_other_wrapper").hide();
	$("#main_other_wrapper2").hide();
	
/*	
	$('a[href*=/]').each(function() {
		var the_id = "";
		var the_class = "";						  
			if($(this).attr("id") != "logo"){
				if($(this).attr("id").length > 0){
					the_id = "id= '" + $(this).attr("id") + "' ";
				}
				if($(this).attr("class").length > 0){
					the_class = "class='" + $(this).attr("class") + "' ";
				}
				var a = $(this).attr("href");
				$(this).replaceWith("<a href='/dev" + a + "' " + the_id + the_class + ">" + $(this).text() + "</a>");
			}
	});
	
*/
	
	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_name").focus(function(){
		if($("#mini_name").val() == "Name"){
			$("#mini_name").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_question").focus(function(){
		if($("#mini_question").val() == "Tell us more"){
			$("#mini_question").val("");	
		}
	});
	
	$("#mini_name").blur(function(){
		if($("#mini_name").val() == ""){
			$("#mini_name").val("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_question").blur(function(){
		if($("#mini_question").val() == ""){
			$("#mini_question").val("Tell us more");	
		}
	});
		
		
		
	
	
	if($("#contact_mini").length >0){
		$("#contact_mini").validate();
	}
	
	
		
	$("#interested").change(function(){
		if($('#other1:selected').length){
			$("#main_other_wrapper").show();
		}
		else
		{
			$("#main_other_wrapper").hide();
		}
		
		
	});
	
	$("#learn").change(function(){
		if($('#other2:selected').length){
			$("#main_other_wrapper2").show();
		}
		else
		{
			$("#main_other_wrapper2").hide();
		}
		
		
	});
	
	
	

	
	
	
});
