		 
	    $(document).ready(function(){
	       	 // moved to load method in popup.js since this obj doesnt exist until after contact form is loaded
	      /*  $('#send_message').click(function(e){
	        });
	        */
    	});
    
    /* allow access to this from call or jquery */
    function submitFunction(e){  
           //stop the form from being submitted
           e.preventDefault();

           /* declare the variables, var error is the variable that we use on the end
           to determine if there was an error or not */
           var error = false;
           var name = $('#name').val();
           var email = $('#email').val();
           var subject = $('#subject').val();
           var message = $('#message').val();
           /* */
           var validate = $('#validate').val();

           /* 
           
           */
           if(name.length == 0){
               var error = true;
               $('#name_error').fadeIn(500);
           }else{
               $('#name_error').fadeOut(500);
           }
           if(email.length == 0 || email.indexOf('@') == '-1'){
               var error = true;
               $('#email_error').fadeIn(500);
           }else{
               $('#email_error').fadeOut(500);
           }
           if(subject.length == 0){
               var error = true;
               $('#subject_error').fadeIn(500);
           }else{
               $('#subject_error').fadeOut(500);
           }
           if(message.length == 0){
               var error = true;
               $('#message_error').fadeIn(500);
           }else{
               $('#message_error').fadeOut(500);
           }
           if(validate.length == 0){
               var error = true;
               $('#validate_error').fadeIn(500);
           }else if(validate.length > 0 && !humanValidate(validate) ){
           	var error = true;
               $('#validate_error').fadeIn(500);
           }else{
               $('#validate_error').fadeOut(500);
           }

           //now when the validation is done we check if the error variable is false (no errors)
           if(error == false){
               //disable the submit button to avoid spamming
               //and change the button text to Sending...
               $('#send_message').attr({'disabled' : 'true', 'value' : 'Sending...' });

               /* 
               using the jquery's post(ajax) function and a lifesaver
               function serialize() which gets all the data from the form
               we submit it to send_email.php 
               */
               $.post("/contact/send_mail.php", $("#contact_form").serialize(),function(result){
                   //and after the ajax request ends we check the text returned
                   if(result == 'sent'){ 
                       //if the mail is sent remove the submit paragraph
                        $('#cf_submit_p').remove();
                       //and show the mail success div with fadeIn
                       $('#mail_success').fadeIn(500);
                   }else{  
                       //show the mail failed div
                       $('#mail_fail').fadeIn(500);
                       //reenable the submit button by removing attribute disabled and change the text back to Send The Message
                       $('#send_message').removeAttr('disabled').attr('value', 'Send The Message');
                   }
               });
           }
    }
    
    /* allow you to call from an explicit function call */
    function callSubmitFunction(e){ 
    	submitFunction(e);
    }
    /* Validate People are Here */
    function humanValidate(f){
	    if(f == 'm' || f == 'M' ){
	    	return true;
	    }else{
	    	return false;
	    }
    }