// JavaScript Document
$.validator.setDefaults({
submitHandler: function(){
	 
$.post("../registration/success1.php", 
				{	
				firstname: $("#firstname").val(),
				lastname: $("#lastname").val(),
				emailid: $("#emailid").val(),
				password: $("#password").val(),
				code: $("#seccode").val()
				},
				function(data){
				if(data==true){
				 $("#register").hide().slideUp();;
				 $("#successmsg").show().slideDown();
			 msg = "Thank you for registering with Tech Channel Index.<br /><br />You are now logged in. <br /><br />A copy of your username and password have been sent to your "+$("#emailid").val()+"<br /><br /><a style='color:#CE7400;text-decoration:underline;' href='../registration/preferences.php'>Please click here to update your preference</a><br /><br /><a style='color:#CE7400;text-decoration:underline;' href='"+$("#archivelogin").attr('href')+"'>Go to feature article</a>";
				 
				 $("#successmsg").html(msg);
				 
				 //window.location = removeHash(window.location);
				 
				}
				else{
				 $("#successmsg").show().slideDown();
				 $("#successmsg").html(data);
				 }//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");
for (x in corporate)
{
if (value.indexOf(corporate[x])!= -1)
{
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
	$("#registrationform").validate({
		rules: {
			firstname: "required",
			lastname:"required",
			emailid: {
				required: true,
				email: true,
				accept: "accept"
			},
			password: {
				required: true,
				minlength: 4
			},
			confirm_password: {
				required: true,
				minlength: 4,
				equalTo: "#password"
			},
			code: "required"
	   },
		messages: {
			firstname: "Please enter first name",
			lastname: "Please enter last name",
			emailid: 
			{
			required: "Please enter e-mail",
			email: "Please enter valid e-mail"
			},
			password: {
				required: "Please enter password",
				minlength: "Your password must be at least 4 characters long"
			},
			confirm_password: {
				required: "Please confirm password",
				minlength: "Your password must be at least 4 characters long",
				equalTo: "Please enter the same password as above"
			},
			code: "Please enter security code"
	
		}
	});
	
					
	
});