/**************************************************
Execute on page load
***************************************************/
$(document).ready(function() {

 }); //end doc ready

function validateContactForm(){	
var email=$("#email").val();
var subject=$("#subject").val();
var message=$("#message").val();
	
	
var val=1;

//now let's run some validation checks to prevent bad data
var alertMsg='';
if(!subject){
		val=0;
		alertMsg=alertMsg+="<li>Subject</li>";
		$("#sub_label").addClass("validate");
	}
if(!message){
		val=0;
		alertMsg=alertMsg+="<li>Message</li>";
		$("#msg_label").addClass("validate");
	}
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
     if (document.mailer.email.value.search(emailRegEx) == -1) {
          val=0;
		alertMsg=alertMsg+="<li>Email Address</li>";
		$("#email_label").addClass("validate");
	}
	
if(val==0){	jqalert("Your message cannot be sent without the following items:<ul class='alert_list'"+alertMsg+"</ul>","Missing Items"); }
if(!val==0){//validation checks all are fine - proceed



//now this needs to be modified to pass form info to ajax page for db insertion	
var data = {
	email: email,
	subject: subject, 
	message: message
	};
	content="email=" + data.email+ "&subject="+data.subject+"&message="+data.message;
$.ajax({ //pass the data to the ajax function for saving to the db
			url: "includes/sendmail.php",
			type: "POST",
			data: content,
			dataType: "html",
			success: function(html){
				
				if(html=="success"){
				$.prompt("Your mail has been sent.",{ callback: mycallbackfunc, prefix:'cleanblue' });
				}
				if(html=="fail"){
				$.prompt("There was a problem sending your email. Please try again or contact the webmaster.",{prefix:'cleanblue'});
				}
				parent.tb_remove();
				},
			error: function(request) {
					jqalert("There was a problem with this data." + request+"<br />Please try again.","Program Error",{icon: "images_new/alert_icon_warning.png"});
				//	el_form.children("div").html(data.original_html);
				}
			});
//

}
}
function mycallbackfunc(){
	window.location="contact.php";
}