/*
 * JavaScript Ajax Form
 * (12-DEC-2009)
 * 
 *
 * 
 * 
 *   
 *   
 */

$(document).ready(function(){
  
  //bind form using 'ajaxForm' 
  $('#contact-form').ajaxForm({  
    target:"#hiddenDIV", 
    beforeSubmit:function() {
       $("#msg").html("Sending...");
       $("#msg").css({border:"1px solid #CCCCCC", backgroundColor:"#F2F2F2", paddingTop:"10px", paddingBottom:"10px", marginTop:"10px", marginBottom:"10px"});
	   $(".field-name-first").html('<label for="name" id="name_label">Full Name:</label>');
	   $(".field-name-email").html('<label for="email" id="email_label">Email Address:</label>');
	   $(".field-name-message").html('<label for="additional" id="additional_label">Enquiry:</label>');
    },
    success:function(response) {
      if (response=="success") {
        $("#contact-form").resetForm();
        $("#msg").html("Thank you for your enquiry.");
        
      } else {
        $("#msg").html( "Make sure you enter the * required information where indicated." );
		var sentence= $("#hiddenDIV #content ul").html();
		if (sentence.indexOf("Name")!=-1) {
		$(".field-name-first").html('<label for="name" id="name_label_active" style="font-weight: bold;color: #f00;">Full Name:*</label>');
		}
		if (sentence.indexOf("email")!=-1||sentence.indexOf("Email")!=-1) {
		$(".field-name-email").html('<label for="email" id="email_label_active" style="font-weight: bold;color: #f00;">Email Address:*</label>');
		}
		if (sentence.indexOf("Enquiry")!=-1) {
		$(".field-name-message").html('<label for="additional" id="additional_label_active" style="font-weight: bold;color: #f00;">Enquiry:*</label>');
		}
	
        $("#hiddenDIV").empty(); 
      }
    }
  });

});
