jQuery(function($) {
		
	// Adding validation to the registration form basic step
	$("#frmRegisterBasic").validate({
		rules: {
			frmFirstName: 		{required:true, minlength:2, maxlength:50},
			frmLastName: 		{required:true, minlength:2, maxlength:50},
			/*frmDay: 			{required:function(element) 
											{
												dayValue = element.value;
												monthValue = document.getElementById('frmMonth').value;
												yearValue = document.getElementById('frmYear').value;
												if(dayValue == '' && monthValue == '' && yearValue == '' && dayValue != 'day'  && monthValue != 'month' && yearValue != 'year')
												{
													return false;
												}
												else
												{
													if(dayValue == '31' && (monthValue == '02' || monthValue == '04' || monthValue == '06' || monthValue == '09' || monthValue == '11'))
													{
														do
													}
													
													else if(dayValue == '30' && (monthValue == '01' || monthValue == '03' || monthValue == '05' || monthValue == '07' || monthValue == '08' || monthValue == '10' || monthValue == '12'))
													{	
														return true;
													}
													
													else if(dayValue == '29' && (monthValue == '02') && (yearValue%4 != 0))
													{
														return true;	
													}
													else
													{
														return false;
													}
												}
											}},*/
			frmUsername: 		{required:true, minlength:2, maxlength:25, remote:"rpc.php"},
			frmPassword: 		{required:true, minlength:6, maxlength:20, password:true},
			frmConfirmPassword: {required:true, minlength:2, equalTo:"#frmPassword", password:true},
			frmEmail: 			{required:true, email:true},
			frmConfirmEmail: 	{required:true, email:true, equalTo:"#frmEmail"},
			frmSecurityCode: 	{required:true},
			frmTerms:"required",
			frmPolicy:"required"
		},
		messages: {
			frmFirstName: 		{required:"First Name is required", minlength:"First Name must contain atleast 2 chars", maxlength:"First Name can contain max 50 chars"},
			frmLastName: 		{required:"Last Name is required", minlength:"Last Name must contain atleast 2 chars", maxlength:"Last Name can contain max 50 chars"},
			frmUsername: 		{required:"Username is required", minlength:"Username must contain atleast 2 chars", maxlength:"Username can contain max 25 chars", remote:"This username has already been taken.<br /> Please choose a different username"},
			frmPassword: 		{required:"Password is required", minlength:"Password must contain atleast 6 chars", maxlength:"Password can contain max 20 chars"},
			frmConfirmPassword: {required:"Confirm Password is required", minlength:"Confirm Password must contain atleast 6 chars", equalTo:"Password and Confirm Password does not match"},
			frmEmail: 			{required:"Email is required", email:"Email must contain a valid email address"},
			frmConfirmEmail: 	{required:"Confirm Email is required", email:"Confirm Email must contain email address", equalTo:"Email and Confirm Email does not match"},
			frmSecurityCode: 	{required:"Security Code is required"},
			frmTerms:"Please accept terms and conditions",
			frmPolicy:"Please accept data protection policy"
		},
		submitHandler: function(form) {
			var options = { 
				target: '',   // target element(s) to be updated with server response 
				beforeSubmit: showLoader,
				success: showSuccessResponse,  // post-submit callback 
				url: 'login_action.php',         // override for form's 'action' attribute 
				type: 'post',        // 'get' or 'post', override for form's 'method' attribute 
				clearForm: false        // clear all form fields after successful submit 
			}; 
			$(form).ajaxSubmit(options);
		}
	});
	
	/*$("#frmGroupRegister").validate({
		rules: {
			frmFirstName	: 	{required:true, minlength:2, maxlength:50},
			frmLastName		: 	{required:true, minlength:2, maxlength:50},
			frmEmail		: 	{required:true, email:true},
			frmPassword		: 	{required:true, minlength:6, maxlength:20, password:true},
			frmCountry		:	{required:true},
			frmCity			: 	{required:true, maxlength:50},
			frmStatus 		: 	{required:true},
			frmCompany		: 	{required:true, maxlength:80},
			frmTitle		: 	{required:true, maxlength:80},
			frmIndustry		: 	{required:true},
			frmTerms:"required"
		},
		messages: {
			frmFirstName	: 	{required:"First Name is required", minlength:"First Name must contain atleast 2 chars", maxlength:"First Name can contain max 50 chars"},
			frmLastName		: 	{required:"Last Name is required", minlength:"Last Name must contain atleast 2 chars", maxlength:"Last Name can contain max 50 chars"},
			frmEmail		: 	{required:"Email is required", email:"Email must contain a valid email address"},
			frmPassword		: 	{required:"Password is required", minlength:"Password must contain atleast 6 chars", maxlength:"Password can contain max 20 chars"},
			frmCountry		: 	{required:"Country is required"},
			frmCity			: 	{required:"City is required", maxlength:"City can contain max 80 characters"},
			frmStatus		: 	{required:"Status is required"},
			frmCompany		: 	{required:"Company is required", maxlength:"Company name can contain max 80 characters"},
			frmTitle		: 	{required:"Title is required", maxlength:"Title can contain max 80 characters"},
			frmIndustry		: 	{required:"Industry is required"},
			frmTerms:"Please accept terms and conditions"
		},
		submitHandler: function(form) {
			var options = { 
				target: '',   // target element(s) to be updated with server response 
				success: showSuccessResponse,  // post-submit callback 
				url: 'grp_reg_action.php',         // override for form's 'action' attribute 
				type: 'post',        // 'get' or 'post', override for form's 'method' attribute 
				clearForm: false        // clear all form fields after successful submit 
			}; 
			$(form).ajaxSubmit(options);
		}
	});*/
	
	// Adding validation to the registration form business step
	$("#frmRegisterBusiness").validate({
		rules: {
			frmStatus 				: 	{required:true},
			frmCompany				: 	{required:
											function(element) 
											{
												if(element.value == 'Freelancers please enter your own name.' || element.value == 'for example J.N.U., University of De.')
												{
													element.value = '';
												}
											}
											, maxlength:80},
			frmTitle				:	{required:
											function(element) 
											{
												if(element.value == 'E.g. CEO, Journalist, Head of Marketing')
												{
													element.value = '';
												}
											}
											, maxlength:80},
			frmIndustry				: 	{required:true},
			frmCountry				:	{required:true},
			frmState				: 	{required:true, maxlength:80},
			frmZip					:	{maxlength:8},
			frmCity					: 	{required:true, maxlength:50},
			frmAddress				:	{maxlength:80},
			frmAcademicUniversity	:	{maxlength:80},
			frmAcademicDegree		:	{maxlength:80},
			frmAcademicUniversityReq: 	{required:true, maxlength:80}
		},
		messages: {
			
			frmStatus				: 	{required:"this field is required"},
			frmCompany				: 	{required:"this field is required", maxlength:"this field can contain max 80 characters"},
			frmTitle				: 	{required:"this field is required", maxlength:"this field can contain max 80 characters"},
			frmIndustry				: 	{required:"this field is required"},
			frmCountry				: 	{required:"this field is required"},
			frmState				: 	{required:"this field is required", maxlength:"this field can contain max 80 characters"},
			frmZip					:	{maxlength:"Zip can contain max 8 chars"},
			frmCity					: 	{required:"this field is required", maxlength:"this field can contain max 80 characters"},
			frmAddress				:	{maxlength:"this field can contain max 80 characters"}
		},
		submitHandler: function(form) {
			var options = { 
				target: '',   // target element(s) to be updated with server response 
				beforeSubmit: showLoader,
				success: showSuccessResponse,  // post-submit callback 
				url: 'login_action.php',         // override for form's 'action' attribute 
				type: 'post',        // 'get' or 'post', override for form's 'method' attribute 
				clearForm: false        // clear all form fields after successful submit 
			}; 
			$(form).ajaxSubmit(options);
		}
	});
	
	
	// Adding validation to the login form
	$("#frmLoginForm").validate({
		rules: {
			frmMemberPassword : 	{password:true							}
		},
		//messages: {
			
			//frmMemberUserName : 		{required:"username is required"},
			//frmMemberPassword : 		{required:"password is required"}
		//},
		submitHandler: function(form) {
			var options = { 
				target: '',   // target element(s) to be updated with server response 
				beforeSubmit: showLoader,
				success: showSuccessResponse,  // post-submit callback 
				url: 'login_action.php',         // override for form's 'action' attribute 
				type: 'post',        // 'get' or 'post', override for form's 'method' attribute 
				clearForm: false        // clear all form fields after successful submit 
			}; 
			$(form).ajaxSubmit(options);
		}
	});
	
	// Adding validation to the registration form basic step
	$("#frmForgotPassword").validate({
		rules: {
			frmMemberData : 	{required:true}
		},
		messages: {
			frmMemberData : 		{required:"Either username or email is required"}
		},
		submitHandler: function(form) {
			var options = { 
				target: '',   // target element(s) to be updated with server response 
				success: showSuccessResponse,  // post-submit callback 
				url: 'login_action.php',         // override for form's 'action' attribute 
				type: 'post',        // 'get' or 'post', override for form's 'method' attribute 
				clearForm: false        // clear all form fields after successful submit 
			}; 
			$(form).ajaxSubmit(options);
		}
	});
	
	// Adding validation to the registration form basic step
	$("#frmResetPwForm").validate({
		rules: {
			frmNewPassword 			: 	{required:true},
			frmConfirmNewPassword	: 	{required:true, equalTo:"#frmNewPassword"}
		},
		messages: {
			frmNewPassword 			: 	{required:"please enter your new password"},
			frmConfirmNewPassword	: 	{required:"please confirm your new password", equalTo:"entered passwords do not match"}
		},
		submitHandler: function(form) {
			var options = { 
				target: '',   // target element(s) to be updated with server response 
				success: showSuccessResponse,  // post-submit callback 
				url: 'login_action.php',         // override for form's 'action' attribute 
				type: 'post',        // 'get' or 'post', override for form's 'method' attribute 
				clearForm: false        // clear all form fields after successful submit 
			}; 
			$(form).ajaxSubmit(options);
		}
	});
	
	// Adding validation to the registration form basic step
	$("#frmContinueRegistration").validate({
		rules: {
			frmContinueRegEmail 		: 	{required:true, email:true},
			frmConfirmContinueRegEmail	:	{required:true, email:true, equalTo:"#frmContinueRegEmail"}
		},
		messages: {
			frmContinueRegEmail			: 	{required:"Email is required", email:"Email must contain a valid email address"},
			frmConfirmContinueRegEmail	: 	{required:"Confirm Email is required", email:"Confirm Email must contain email address", equalTo:"Email and Confirm Email does not match"}
		},
		submitHandler: function(form) {
			var options = { 
				target: '',   // target element(s) to be updated with server response 
				beforeSubmit: showLoader,
				success: showSuccessResponse,  // post-submit callback 
				url: 'login_action.php',         // override for form's 'action' attribute 
				type: 'post',        // 'get' or 'post', override for form's 'method' attribute 
				clearForm: false        // clear all form fields after successful submit 
			}; 
			$(form).ajaxSubmit(options);
		}
	});
	
	$("#frmRegisterEmail").validate({
		rules: {
			frmNewRegisterEmail 		: 	{required:true, email:true}
		},
		messages: {
			frmNewRegisterEmail			: 	{required:"Email is required", email:"Email must contain a valid email address"}
		},
		submitHandler: function(form) {
			var options = { 
				target: '',   // target element(s) to be updated with server response 
				success: showResendEmailSuccessResponse,  // post-submit callback 
				url: 'login_action.php',         // override for form's 'action' attribute 
				type: 'post',        // 'get' or 'post', override for form's 'method' attribute 
				clearForm: false        // clear all form fields after successful submit 
			}; 
			$(form).ajaxSubmit(options);
		}
	});
});


// post-submit callback 
function showSuccessResponse(responseText, statusText)  
{ 
	$('.loader').remove();
	$('.submitBtn').removeAttr('disabled');
	window.location.href = responseText;
	//document.write(responseText);
} 

function showResendEmailSuccessResponse(responseText, statusText)
{
	document.getElementById('frmResendEmail').innerHTML = 'We have just sent a confirmation email to your address <br /><br /><strong>'+responseText+'</strong><br /><br />Simple click on the link in the email to confirm your registration.';		
}

function showLoader()
{
	$('.submitBtn').attr('disabled','disabled');
	$('.submitBtnCtn').append('<img src="common/images/ajax_loader.gif" class="loader" align="absmiddle" />');	
}