
function validateLogin()
{
	var isValid = true;	
	isFieldFocusSet = false;
	if(isEmptyValue("email")){xAlert('Please enter email','user_email'); isValid=false;}	
	else {xAlert('','user_email');}	
	if(!emailCheck("email")){xAlert('Please enter valid email ','user_email');
	  	document.getElementById("email").focus();
	  	isValid=false;}	
	else {xAlert('','user_email');}	
	if(isEmptyValue("password")){xAlert('Please enter password','user_password'); isValid=false;}	
	else {xAlert('','user_password');}
	
	if(isValid)
	{
		xDisableElement("loginBtn","WWIButtonDisable");
	}		
	return isValid;	
}

function clearLogin(){
	document.getElementById("email").focus();
	xAlert('','user_email');
	xAlert('','user_password');
}


function validateUsername()
{
	var isValid = true;	
	isFieldFocusSet = false;
	if(isEmptyValue("email")){xAlert('Please enter email','email_Div'); isValid=false;}	
	else {xAlert('','email_Div');}	
	if(isEmptyValue("email")){xAlert('Please enter valid email ','email_Div'); isValid=false;}	
	else {xAlert('','email_Div');}		
	return isValid;
}

function clearEmailChangeErr(){
	document.getElementById("newEmailId").focus();
	xAlert('','newEmailId_Div');
	xAlert('','confirmEmailId_Div');
}

function validateChangeEmail()
{
	var isValid = true;	
	isFieldFocusSet = false;
	if(isEmptyValue("newEmailId")){xAlert('Please enter new Email ID','newEmailId_Div'); isValid=false;}	
	else {xAlert('','newEmailId_Div');}	
	if(!emailCheck("newEmailId")){xAlert('Please enter valid new Email ','newEmailId_Div');
	  	document.getElementById("newEmailId").focus();
	  	isValid=false;}	
	else {xAlert('','newEmailId_Div');}	
	
	if(isEmptyValue("confirmEmailId")){xAlert('Please enter Confirm Email ID','confirmEmailId_Div'); isValid=false;}	
	else {xAlert('','confirmEmailId_Div');}	
	if(!emailCheck("confirmEmailId")){xAlert('Please enter valid Confirm Email ID','confirmEmailId_Div');
	  	document.getElementById("confirmEmailId").focus();
	  	isValid=false;}	
	else {
			if(!verify_confirm_input("newEmailId","confirmEmailId")){xAlert('Please enter same value in New Email and Confirm Email fields','confirmEmailId_Div'); isValid=false;}	
			else {xAlert('','confirmEmailId_Div');}	
		}	
	
	if(isValid)
	{
		xDisableElement("emailChange","WWIButtonDisable");
	}		
	return isValid;
}

function clearResetPasswordErr(){
	document.getElementById("password").focus();
	xAlert('','password_Div');
	xAlert('','newPassword_Div');
	xAlert('','confirmPassword_Div');
}

function validateResetPassword()
{
	var isValid = true;	
	isFieldFocusSet = false;
	if(isEmptyValue("password")){xAlert('Please enter current password','password_Div'); isValid=false;}	
	else {xAlert('','password_Div');}	
	if(isEmptyValue("newPassword")){xAlert('Please enter new password','newPassword_Div'); isValid=false;}	
	else {xAlert('','newPassword_Div');}
	var passwordVal1 = document.getElementById("newPassword").value;
	if(!isEmptyValue("newPassword") && passwordVal1.length < 6){
		 xAlert('Please enter password of six or more characters','newPassword_Div');
		 document.getElementById("confirmEmailId").focus();
		 isFieldFocusSet = true;
		 isValid=false;
	 }	
	if(isEmptyValue("confirmPassword")){xAlert('Please enter confirm new Password','confirmPassword_Div'); isValid=false;}	
	else {
			if(!verify_confirm_input("newPassword","confirmPassword")){xAlert('Please enter same value in new password and confirm new Password','confirmPassword_Div'); isValid=false;}	
			else {xAlert('','confirmPassword_Div');}	
	}
	if(isValid)
	{
		xDisableElement("passwordChange","WWIButtonDisable");
	}		
	return isValid;	
}

function clearRegsitration(){
	document.getElementById("email").focus();
	xAlert('','user_email');
	xAlert('','user_password');
	xAlert('','confirm_password');
	xAlert('','user_firstname');
	xAlert('','user_dob');
	xAlert('','user_gender');
	xAlert('','user_captcha');
}


function validateInput(){
	
	var isValid = true;
	isFieldFocusSet = false;	
	
	if(isEmptyValue("email")){xAlert('Please enter email','user_email'); isValid=false;}
	else {
		if(!emailCheck("email")){xAlert('Please enter valid Email Id','user_email');
		 document.getElementById("email").focus();
		 isFieldFocusSet = true;
		 isValid=false;
		 }
		else {xAlert('','user_email');}	
	}		
		
	if(isEmptyValue("password")){xAlert('Please enter password','user_password'); isValid=false;}
	else {xAlert('','user_password');}
	
	var passwordVal = document.getElementById("password").value;
	if(!isEmptyValue("password") && passwordVal.length < 6){xAlert('Please enter password of six or more characters','user_password');isFieldFocusSet = true; isValid=false;}
	
	if(isEmptyValue("confirmPassword")){xAlert('Please enter confirm password','confirm_password'); isValid=false;}
	else {xAlert('','confirm_password');}
	
	var passwordVal1 = document.getElementById("confirmPassword").value;
	if(!isEmptyValue("confirmPassword") && passwordVal1.length < 6){
		xAlert('Please enter password more than six characters','confirm_password');
		 isFieldFocusSet = true;
		 isValid=false;
	 }
	
	if(!isEmptyValue("password") && passwordVal.length > 5 && !isEmptyValue("confirmPassword") && passwordVal1.length > 5 && !verify_confirm_input("password","confirmPassword")){xAlert('Please enter same value in password and confirmpassword fields','confirm_password');isFieldFocusSet = true; isValid=false;}
	
	if(isEmptyValue("firstName")){xAlert('Please enter first name','user_firstname'); isValid=false;}
	else {xAlert('','user_firstname');}
	
	if(isEmptyValue("lastName")){xAlert('Please enter last name','user_lastname'); isValid=false;}
	else {xAlert('','user_lastname');}
	
	var dobValue = document.registration.dob.value;
	//alert('dateOfBirth.... ' +dobValue);
	if(dobValue.trim() == 'none' || dobValue.trim() == ''){
	xAlert('Please select your Date of Birth','user_dob'); 
	isValid=false;
	if(!isFieldFocusSet){
			document.registration.dob.focus();
			isFieldFocusSet=  true;
		}
	}
	else {
		if(!isValidDOB()){isValid=false;}
		else{xAlert('','user_dob');}	
	}
	
	var genderField = document.getElementById("gender");
	var selGender = genderField[genderField.selectedIndex].value;
	//alert('selGender .. '+selGender);
	if(selGender == '0'){
		isValid=false;
		xAlert('Please select gender.','user_gender');
		if(!isFieldFocusSet){
			document.getElementById("gender").focus();
			isFieldFocusSet=  true;
		}
	}else{
		xAlert('','user_gender');
	}
	
	if(isEmptyValue("captchaStr")){xAlert('Please enter security code','user_captcha'); isValid=false;}	
	else {xAlert('','user_captcha');}	
	
	if(isValid){
		var buttonField = document.getElementById('signUp');
		buttonField.disabled=true;
	}
	else{
		document.getElementById('signUp').disabled=false;
	}
	if(isValid)
	{
		xDisableElement("signUp","WWIButtonDisable");
	}	
	return  isValid;
}

function validatePasswordInput($char, $mozChar, errorMessageFld) {
	//alert($mozChar);
	//alert($char);
	var inputChar = 0;
	if($mozChar != null && $mozChar != 'undefined')  inputChar = $mozChar;
	else if($char != null && $char != 'undefined') inputChar = $char; 
	if(inputChar != null) { // Look for a Mozilla-compatible browser
		$RetVal = true;xAlert('',errorMessageFld);
		if(inputChar == 32)
		{
			$RetVal = false;
			xAlert('Space is not allowed in password',errorMessageFld);
			isFieldFocusSet = true;
		}
		/*
		else{
			var passwordVal = document.getElementById(fldId).value;
			if(!isEmptyValue(fldId) && passwordVal.length < 6){
				xAlert('Please enter password more than six characters',errorMessageFld);
					isFieldFocusSet = true;
				}
		}
		*/
	}else{xAlert('',errorMessageFld);}
	return $RetVal;
}

function verify_confirm_input(fieldName1, fieldName2){
	// do various checks, this will save people noticing mistakes on next page
	var field1 = document.getElementById(fieldName1);
	var field2 = document.getElementById(fieldName2);
	if (field1.value != field2.value)
	{
		if(!isFieldFocusSet){field2.focus();isFieldFocusSet = true;}
		return false;
	}		
	return true;
}

function isValidDOB(){
	var dob = getValue("dob");
	var d = (Date.today()).add(-5).years();
	//alert('d ...... '+d);
	var d1 = Date.parse(dob);
	
	var oldDate = (36500).days().ago();
	
	//alert('parsed eventStartDate d ... '+d);
	//alert('parsed eventEndDate d1 ... '+d1);
	//alert('parsed startDate d2 ... '+d2);
	//alert('comparision 1... '+d.compareTo(d2));
	//alert('comparision 2... '+d.compareTo(d1));
	
	if(d.compareTo(d1) <= 0){xAlert('You must be over 5 years to regsiter.','user_dob'); return false;};
	if(oldDate.compareTo(d1) >= 0){xAlert('You seems to over 100 years. Please verify.','user_dob'); return false;};
	return true;
}

function validateSubscriptionInput(){
	var isValid = true;
	isFieldFocusSet = false;	
	
	if(isEmptyValue("subscriptionEmailId")){xAlert('Please enter email','subscribe_email'); isValid=false;}
	else {
		if(!emailCheck("subscriptionEmailId")){xAlert('Please enter valid Email Id','subscribe_email');
		 document.getElementById("subscriptionEmailId").focus();
		 isFieldFocusSet = true;
		 isValid=false;
		 }
		else {xAlert('','subscribe_email');}	
	}
	if(isValid)
	{
		xDisableElement("subscribeBtn","WWIButtonDisable");
	}
	return  isValid;
}
function validateFeedbackForm(objForm) {	
	var isValid = true;	
	isFieldFocusSet = false;
	if(isEmptyValue("name")){xAlert('Please enter your name','name_Div'); isValid=false;}	
	else {xAlert('','name_Div');}	
	if(isEmptyValue("email")){xAlert('Please enter your email id ','email_Div'); isValid=false;}	
	else {
		if(!emailCheck("email")){xAlert('Please enter valid Email Id','email_Div');
		 document.getElementById("email").focus();
		 isFieldFocusSet = true;
		 isValid=false;
		 }
		else {xAlert('','email_Div');}	
	
	}
	
	if(document.getElementById("subject").value == -1){
		xAlert('Please select subject ','subject_Div'); isValid=false;
		isFieldFocusSet = true;
	}else {xAlert('','subject_Div');}	

	if(isEmptyValue("feedback")){xAlert('Please enter feedback  ','feedback_Div'); isValid=false;}	
	else {xAlert('','feedback_Div');}			
	if(isValid)
	{
		xDisableElement("Send","WWIButtonDisable");
	}	
	return isValid;	
}
function clearFeedBackForm(){
	xAlert('','name_Div');
	xAlert('','email_Div');
	xAlert('','subject_Div');
	xAlert('','feedback_Div');
}

//User Question function
function validateUserQuestion()
{
	var isValid = true;	
	isFieldFocusSet = false;
	if(document.getElementById("courseId").value == null || document.getElementById("courseId").selectedIndex==0){xAlert('Please select a course','faq_course'); isValid=false;document.getElementById("courseId").focus();}	
	else {xAlert('','faq_course');}
	if(isEmptyValue("question")){xAlert('Please enter the question','faq_question'); isValid=false;document.getElementById("question").focus();}	
	else if((document.getElementById("question").value).length>300){
		xAlert('Query should not exceed 300 letters','faq_question'); 
		isValid=false;
		document.getElementById("question").focus();
	}else {xAlert('','faq_question');}	
	if(isEmptyValue("userName")){xAlert('Please enter user name','faq_name'); isValid=false;document.getElementById("userName").focus();}	
	else {xAlert('','faq_name');}	
	if(!emailCheck("email")){xAlert('Please enter valid email ','faq_email');
	  	document.getElementById("email").focus();
	  	isValid=false;}	
	else {xAlert('','faq_email');}	
	if(isEmptyValue("captchaStr")){xAlert('Please enter user name','faq_captcha'); isValid=false;document.getElementById("captchaStr").focus();}	
	else {xAlert('','faq_captcha');}	
	if(isValid)
	{
		xDisableElement("submitButton","WWIButtonDisable");
	}
	return isValid;	
}

function clearUserQuestion(){
	xAlert('','faq_course');
	xAlert('','faq_question');
	xAlert('','faq_name');
	xAlert('','faq_email');
	xAlert('','faq_captcha');
}

//Contact us function
function validateContactUs()
{
	var isValid = true;	
	isFieldFocusSet = false;
	if(document.getElementById("purposeId").value == null || document.getElementById("purposeId").selectedIndex==0){xAlert('Please select a purpose','contactUs_purpose'); isValid=false;document.getElementById("purposeId").focus();}	
	else {xAlert('','contactUs_purpose');}
	if(isEmptyValue("query")){xAlert('Please enter the query','contactUs_query'); isValid=false;document.getElementById("query").focus();}	
	else if((document.getElementById("query").value).length>1000){
		xAlert('Query should not exceed 1000 letters','contactUs_query'); 
		isValid=false;
		document.getElementById("query").focus();
	}else {xAlert('','contactUs_query');}	
	if(isEmptyValue("firstName")){xAlert('Please enter first name','contactUs_firstName'); isValid=false;document.getElementById("firstName").focus();}	
	else {xAlert('','contactUs_firstName');}	
	if(isEmptyValue("lastName")){xAlert('Please enter last name','contactUs_lastName'); isValid=false;document.getElementById("lastName").focus();}
	else {xAlert('','contactUs_lastName');}	
	if(isEmptyValue("phoneNumber")){xAlert('Please enter phone number','contactUs_phoneNumber'); isValid=false;document.getElementById("phoneNumber").focus();}	
	else {xAlert('','contactUs_phoneNumber');}	
	if(!emailCheck("email")){xAlert('Please enter valid email ','contactUs_email');
	  	document.getElementById("email").focus();
	  	isValid=false;}	
	else {xAlert('','contactUs_email');}	
	if(isEmptyValue("captchaStr")){xAlert('Please enter captcha','contactUs_captcha'); isValid=false;document.getElementById("captchaStr").focus();}	
	else {xAlert('','contactUs_captcha');}	
	if(isValid)
	{
		xDisableElement("submitButton","WWIButtonDisable");
	}
	return isValid;	
}

function clearContactUs(){
	xAlert('','contactUs_purpose');
	xAlert('','contactUs_query');
	xAlert('','contactUs_firstName');
	xAlert('','contactUs_lastName');
	xAlert('','contactUs_phoneNumber');
	xAlert('','contactUs_email');
	xAlert('','contactUs_captcha');
	document.getElementById("purposeId").selectedIndex=0;
	document.getElementById("query").value="";
	document.getElementById("firstName").value="";
	document.getElementById("lastName").value="";
	document.getElementById("phoneNumber").value="";
	document.getElementById("email").value="";
	document.getElementById("captchaStr").value="";
}

function validateCareerForm() {

	var isValid = true;	
	isFieldFocusSet = false;
	
	
	if(isEmptyValue("name")){
		xAlert('Please enter your Name ','car_name');
	  	document.getElementById("name").focus();
	  	isValid=false;
	  }	
	 else {
		 xAlert('','car_name');
	 }
	if(!emailCheck("emailId")){
		xAlert('Please enter valid email ','car_email');
	  	document.getElementById("emailId").focus();
	  	isValid=false;
	  }	
	 else {
		 xAlert('','car_email');
	 }
	if(isEmptyValue("contact")){
		xAlert('Please enter contact number ','car_contact');
	  	isValid=false;
	  }	
	 else {
		 xAlert('','car_contact');
	 } 
	if(isEmptyValue("city")){
		xAlert('Please enter city ','car_city');
	  	isValid=false;
	  }	
	 else {
		 xAlert('','car_city');
	 } 	 

    if(document.getElementById("crsList")!=null){ 	
		 var interestField = document.getElementById("crsList");
		var selInterest = interestField[interestField.selectedIndex].value;
		//alert('selGender .. '+selGender);
		if(selInterest == '0'){
			xAlert('Please select the course','car_course'); isValid=false;
		}else{
			xAlert('','car_course');
		}
	}	
 

   
	
	if(document.getElementById("leadSource")!=null){ 	
		var interestField1 = document.getElementById("leadSource");
		var selInterest1 = interestField1[interestField1.selectedIndex].value;
		
		//alert(selInterest1);
		//alert('selGender .. '+selGender);
		if(selInterest1==0){
			xAlert('Please select the option "where did you here about WWI"','car_subject'); isValid=false;
		}else{
			xAlert('','car_subject');
		}
	}
	

	/*
	if(document.getElementById("leadSource")!=null){ 	
			var interestField2 = document.getElementById("leadSource");
			if(interestField2[interestField2.selectedIndex].value=="Other")
			  {
				 alert(interestField2[interestField2.selectedIndex].value);
				 document.getElementById("othername").disabled=false;
				 isValid=false;
				 	
			  }
			isValid=false;
		}
	*/





     /*
	if(document.getElementById("leadSource")=="Other")
		{ 	
			document.getElementById("othername").visibility=true;
		}	
    */

	if(isEmptyValue("careerQuery"))
	{
		xAlert('Please enter your query','car_query'); 
		isValid=false;
		document.getElementById("careerQuery").focus();
	}else if((document.getElementById("careerQuery").value).length>1000){
		xAlert('Query should not exceed 1000 letters','car_query'); 
		isValid=false;
		document.getElementById("careerQuery").focus();
	}else{
		xAlert('','car_query');
	}	
	/**
	if(isEmptyValue("subject"))
	{
		xAlert('Please enter the subject','car_subject'); 
		isValid=false;
		document.getElementById("subject").focus();
	}	
	else {
		xAlert('','car_subject');
	}	
	  	**/
	  	if(isValid)
	{
		xDisableElement("submitButton","WWIButtonDisable");
	}
	
	  	return isValid;	
	  	
}


//Contact us function
function validateStudentWorkshop()
{
	var isValid = true;	
	isFieldFocusSet = false;
	if(isEmptyValue("upload")){xAlert('Please upload the workshop','workshop_upload'); isValid=false;document.getElementById("upload").focus();}	
	else {xAlert('','workshop_upload');}	
	if(isEmptyValue("workshopDesc")){xAlert('Please enter the workshop detail','workshop_workshopDesc'); isValid=false;document.getElementById("workshopDesc").focus();}	
	else if((document.getElementById("workshopDesc").value).length>1000){
		xAlert('Description should not exceed 1000 letters','workshop_workshopDesc'); 
		isValid=false;
		document.getElementById("workshopDesc").focus();
	}else {xAlert('','workshop_workshopDesc');}	
	if(isEmptyValue("firstName")){xAlert('Please enter first name','workshop_firstName'); isValid=false;document.getElementById("firstName").focus();}	
	else {xAlert('','workshop_firstName');}	
	if(isEmptyValue("lastName")){xAlert('Please enter last name','workshop_lastName'); isValid=false;document.getElementById("lastName").focus();}	
	else {xAlert('','workshop_lastName');}	
	if(isEmptyValue("phoneNumber")){xAlert('Please enter phone number','workshop_phoneNumber'); isValid=false;document.getElementById("phoneNumber").focus();}	
	else {xAlert('','workshop_phoneNumber');}	
	if(!emailCheck("email")){xAlert('Please enter valid email ','workshop_email');
	  	document.getElementById("email").focus();
	  	isValid=false;}	
	else {xAlert('','workshop_email');}	
	if(isEmptyValue("captchaStr")){xAlert('Please enter captcha','workshop_captcha'); isValid=false;document.getElementById("captchaStr").focus();}	
	else {xAlert('','workshop_captcha');}	
	if(isValid)
	{
		xDisableElement("submitButton","WWIButtonDisable");
	}
	return isValid;	
}

function clearStudentWorkshop(){
	xAlert('','workshop_workshopDesc');
	xAlert('','workshop_firstName');
	xAlert('','workshop_lastName');
	xAlert('','workshop_phoneNumber');
	xAlert('','workshop_email');
	xAlert('','workshop_captcha');
}
