// Form
$(document).ready(function() {	
	// Input Remove / Replace
	
	$("input, textarea").not("#submit, #search_submit").each(function() {
	   var default_value = this.value;
	   $(this).focus(function() {
	       if(this.value == default_value) {
	           this.value = '';
	       }
	   });
	   $(this).blur(function() {
	       if(this.value == '') {
	           this.value = default_value;
	       }
	   });
	});

// Validation
$(".enquiryform form").submit(function() {
		var hasError = false;
		var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		
		var nameVal = $('#name').val();
		if(nameVal == '' || nameVal == ' ' || nameVal == 'Name') {
			$('#name').css({ "color" : "#C00" });
			hasError = true;
		} else $('#name').css({ "color" : "#999" });
		
		var emailVal = $('#email').val();
		if(emailVal == '') {
			$('#email').css({ "color" : "#C00" });
			hasError = true;
		} else if(!emailReg.test(emailVal)) {	
			$('#email').css({ "color" : "#C00" });
			hasError = true;
		} else $('#email').css({ "color" : "#999" });
		
		var subjectVal = $('#phone').val();
		if(subjectVal == '' || subjectVal == ' ' || subjectVal == 'Phone' || subjectVal == 'Phone') {
			$('#phone').css({ "color" : "#C00" });
			hasError = true;
		} else $('#phone').css({ "color" : "#999" });
		
		var cityVal = $('#city').val();
		if(cityVal == '' || cityVal == ' ' || cityVal == 'City') {
			$('#city').css({ "color" : "#C00" });
			hasError = true;
		} else $('#city').css({ "color" : "#999" });
        
        var messageVal = $('#message').val();
        
		if(hasError == false) {
			$('#submit').attr("disabled", "disabled");
			$.post("emailForm.php",
   				{ subject: subjectVal, city: cityVal, phone: phoneVal, message: messageVal, name: nameVal, email: emailVal},
   					function(data) { window.location = 'thanks.php'; });
            
		}
		
		return false;
	});
});
