$(document).ready(function() { 

    $('.error').hide();
	$('#feedback').hide();

    var options = { 
        target:        '#feedback',   // target element(s) to be updated with server response 
        beforeSubmit:  validate,  // pre-submit callback 
        success:       showResponse,  // post-submit callback 
       url: 'http://www.newgenfunds.com/bin/submit.php',
	    clearForm: true        // clear all form fields after successful submit 
        //resetForm: true        // reset the form after successful submit 
    }; 
 
    $('#applyForm').ajaxForm(options); 
}); 
 

function validate(formData, jqForm, options) { 
	
	var full_name = $("input#full_name").val();
  		if (full_name == "") {
        $("input#full_name").focus();
 		$("#full_name_error").show();
		return false;
      } else {
		 $("#full_name_error").hide(); 
	  }
		
		
		
		var email = $("input#email_contact").val();
				
		var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]­{1}[a-z0-9]+)*[\.]{1}(com|ca|net|org|fr|us|qc.ca|gouv.qc.ca)$', 'i');

  		if (email == "" || reg.test(email) == false) {
        $("input#email_contact").focus();
 		$("#email_contact_error").show();
		return false;
      } else {
		 $("#email_contact_error").hide(); 
	  }
	  
	  
	  	var phone = $("input#phone").val();
  		if (phone == "") {
        $("input#phone").focus();
 		$("#phone_error").show();
		return false;
      } else {
		 $("#phone_error").hide(); 
	  }
//	What is the approximate value of your contemplated structure?

 
  
 	
	  	var description = $("textarea#description").val();
  		if (description == "") {
        $("textarea#description").focus();
 		$("#description_error").show();
		return false;
      } else {
		 $("#description_error").hide(); 
	  }

}

function showResponse(responseText, statusText)  { 

    alert('Your submission has been received and we will be in touch with you shortly.'); 
		$('#applyForm').fadeTo("slow", 0.66);
			    $('.error').hide();
} 


