$(document).ready(function(){
	
	$('form#ajax_form .submit').click(function(){

		$('#ajax_form .error').hide();	//if error visibile, hide on new click
		
		var name = $('input#name').val();
		if (name == "" || name == " " || name == "Name") {
		    $('input#name').focus().before('<div class="error">Please enter your name.</div>');
		    return false;
		}
		
		var state = $('input#state').val();
		if (state == "" || state == " " || state == "State") {
		    $('input#state').focus().before('<div class="error">Please select a state.</div>');
		    return false;
		}
		
		var email_test = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
		var email = $('input#email').val();
		if (email == "" || email == " ") {
		   $('input#email').focus().before('<div class="error">Please enter your email address.</div>');
		   return false;
		} else if (!email_test.test(email)) {
		   $('input#email').select().before('<div class="error">Invalid email address.</div>');
		   return false;
		}
		
		
		var phone = $('input#phone').val();
		if (phone == "" || phone == " " || phone == "Phone") {
		    $('input#phone').focus().before('<div class="error">Please enter your phone number.</div>');
		    return false;
		}
		

		var data_string = $('form#ajax_form').serialize();

		$.ajax({
		    type:       "POST",
		    url:        "http://www.americandebtss.com/wp-content/themes/custom/email.php",
		    data:       data_string,
		    success:    function() {

		$('form#ajax_form').slideUp('fast').before('<div id="success"></div>');
		$('#success').html('<h3>SUCCESS!</h3><p>We are in receipt of your Quick Quote request.</p><p>We will be in touch within 24 hours.</p>').slideDown(9000);

		    }//end success function


		}) //end ajax call

		return false;


	}) //end click function
	
	var current_data = new Array();

	$('.clear').each(function(i){
		$(this).removeClass('clear').addClass('clear'+i);
		current_data.push($(this).val());

		$(this).focus(function(){
			if($(this).val() == current_data[i]) {
				$(this).val('');
			}
		});
		$(this).blur(function(){
			var stored_data = current_data[i];
			if($(this).val()==''){
				$(this).val(stored_data);
			}
		})
	});
})
