// JavaScript Document
$.validator.setDefaults({
submitHandler: function(){
$.post("../includes/register-contact.php", 
				{	
				first_name: $("#first_name").val(),
				last_name: $("#last_name").val(),
				title: $("#title").val(),
				company: $("#company").val(),
				email: $("#email").val(),
				phone: $("#phone").val(),
				aboutzyme: $('#aboutzyme option:selected').text(),
				interest: $("#interest").val(),
				webcast: $("#webcast").val(),
				subject: $("#subject").val(),
				code: $("#code").val()
				},
				function(data){
				if(data==true){
			 	webcast1 = $("#webcast").val();
				if(webcast1){
				window.location ="webcast-registration-thank-you.php"; 
				}else{
				 window.location ="contact-zyme-thanks.php"; 
				}
		
		}//end data
				else{
				 $("#msg").html(data);
	document.getElementById('captcha').src = '../secureimage/securimage_show.php?sid=' + Math.random();
				 }//end data
				}
				
				);
return false;
 }

});
//Ajax loading
$().ajaxSend(function(r,s){   
$("#successmsg").html('<img src="../images/loading_animation.gif" alt="Loading... please wait..."><br/><span style="font-size:11px;">Loading... please wait...</span>');   
}); 

/*  
$().ajaxStop(function(r,s){   
$("#loadingmsg").fadeOut("fast");   
});
*/ 
//Ajax loading
// this one requires the text "buga", we define a default message, too
$.validator.addMethod("accept", function(value) {
value = value.toLowerCase();
var valid = true;
var corporate = new Array("yahoo.com","gmail.com","sbcglobal.net","msn.com","hotmail.com","aol.com","earthlink.net","comcast.net","rediffmail.com","yahoomail.com","rediff.com");
for (x in corporate)
{
if (value.indexOf(corporate[x])!= -1)
{
valid = false;
}
}
if (value.indexOf('yahoo')!= -1){
	if((value.charAt(value.indexOf('yahoo')-1)=='@') && (value.charAt(value.indexOf('yahoo')+5)=='.'))
	valid = false;
}
return valid;	   
}, 'Please use your company email address.');
	
// this one requires the value to be the same as the first parameter
$.validator.methods.equal = function(value, element, param) {
		return value == param;
};	
	
$().ready(function() {
	// validate signup form on keyup and submit
$("#contact_form").validate({
		rules: {
			first_name: "required",
			last_name:"required",
			title: "required",
			company: "required",
			email: {
				required: true,
				email: true,
				accept: "accept"
			},
			phone: "number",
			aboutzyme: "required",
			interest: "required",
			code: "required"
		  },
		messages: {
			first_name: "Please enter first name",
			last_name: "Please enter last name",
			title: "Please enter title",
			company: "Please enter company",
			email: 
			{
			required: "Please enter email",
			email: "Please enter valid email"
			},
			phone:"Please enter valid phone number",
			aboutzyme: "Please enter How did you hear about Zyme?",
			interest: "Please enter reason for interest",
			code: "Please enter Security Code"
		}
	});
	
});