$().ready(function() {
	
	//Used to remove and fill back in text form fields
	var default_values = new Array();
  	var default_ids = new Array();
  	
  	$(".default-value").each(function( intIndex ){
  	
  		if (!default_values[this.id]) {
  			//alert(this.id + " " + intIndex);
			default_ids[intIndex] = this.id;
		  	default_values[this.id] = this.value;
		}
  	
  	});
  
	$(".default-value").focus(function() {
		
		if (this.value == default_values[this.id]) {
	  		this.value = '';
		}
	
		$(this).blur(function() {
			if (this.value == '') {
				this.value = default_values[this.id];
			}
		});
	});
  
  	$('.default-submit').click(function() {
  		  	
  		$("input.default-value").each(function( intIndex ){
  			if( this.value == default_values[this.id] ) {
				this.value = "";
			}
  		});
  	
	});
	
	// validate signup form on keyup and submit
	$("#job-form").validate({
		rules: {
			contact_form_name: "required",
			contact_form_phone: "required"
		},
		messages: {
			contact_form_name: "Please enter your name",
			contact_form_phone: "Please enter your phone"
		},
		invalidHandler: function(form, validator) {

				$(".default-value").each(function( intIndex ){
		  			if (this.value == "") {
				  		this.value = default_values[this.id];
					}
		  		});
		}
	});
	
	// validate signup form on keyup and submit
	$("#warranty-form").validate({
		rules: {
			contact_form_name: "required",
			contact_form_phone: "required"
		},
		messages: {
			contact_form_name: "Please enter your name",
			contact_form_phone: "Please enter your phone"
		},
		invalidHandler: function(form, validator) {

				$(".default-value").each(function( intIndex ){
		  			if (this.value == "") {
				  		this.value = default_values[this.id];
					}
		  		});
		}
	});
	
	// validate signup form on keyup and submit
	$("#contact-form").validate({
		rules: {
			contact_form_name: "required",
			contact_form_preferred: "required",
			contact_form_hearus: "required"
		},
		messages: {
			contact_form_name: "Please enter your name",
			contact_form_preferred: "Please select a preferred method",
			contact_form_hearus: "Please choose how you heard of us"
		},
		invalidHandler: function(form, validator) {

				$(".default-value").each(function( intIndex ){
		  			if (this.value == "") {
				  		this.value = default_values[this.id];
					}
		  		});
		}
	});
				
});