function loginValidation(){
	if (document.forms[0].username.value == ""){
		alert("Please enter the username");
		document.forms[0].username.focus();
		return false;
	}
	
	if (document.forms[0].password.value == ""){
		alert("Please enter the password");
		document.forms[0].password.focus();
		return false;
	}
	
	//document.forms[0].submit();
	return true;
}


function forgetPasswordValidation(){
	if (document.forms[1].username.value == ""){
		alert("Please enter the username");
		document.forms[1].username.focus();
		return false;
	}
	
	if (document.forms[1].email.value == ""){
		alert("Please enter the E-mail Address");
		document.forms[1].email.focus();
		return false;
	}
	
	if (!emailCheck(document.forms[1].email.value)){
		document.forms[1].email.focus();
		return false;
    }
	
	document.forms[1].submit();
}

function searchprofileValidation(){
	//alert("TEST");
	if (document.forms[1].lookingfor.value == ""){
		alert("Please select the Looking ");
		document.forms[1].lookingfor.focus();
		return false;
	}
	
	if (document.forms[1].agefrom.value == ""){
		alert("Please provide the Starting Age");
		document.forms[1].agefrom.focus();
		return false;
	}
	
	if (document.forms[1].ageto.value == ""){
		alert("Please provide the Ending Age");
		document.forms[1].ageto.focus();
		return false;
	}	
	
	if (document.forms[1].ageto.value < document.forms[1].agefrom.value){
		alert("Please select To-Age as Greaterthan or Equal of From-Age");
		document.forms[1].ageto.focus();
		return false;
	}
	
	if (document.forms[1].caste.value == ""){
		alert("Please provide the Caste");
		document.forms[1].caste.focus();
		return false;
	}	
	
	if (document.forms[1].subcaste.value == ""){
		alert("Please provide the Subcaste");
		document.forms[1].subcaste.focus();
		return false;
	}	
	
	if (!document.forms[1].with_photo.checked){
		document.forms[1].with_photo.value = "N";
	}				
//	alert(document.forms[1].with_photo.value);
	return true;
}


function searchValidation(){
	if (document.forms[1].lookingfor.value == ""){
		alert("Please provide looking for");
		document.forms[1].lookingfor.focus();
		return false;
	}
}


function changePasswordValidation(){
//	alert("TEST");
	if (document.forms[0].password.value == ""){
		alert("Please enter the New Password");
		document.forms[0].password.focus();
		return false;
	}
	
	if (document.forms[0].confirmpassword.value == ""){
		alert("Please enter the Confirm New Password");
		document.forms[0].confirmpassword.focus();
		return false;
	}
	
	if (document.forms[0].confirmpassword.value != document.forms[0].password.value){
		alert("Please enter the Same New Password as Confirm New Password");
		document.forms[0].confirmpassword.focus();
		return false;
	}
	
	document.forms[0].submit();
}



/* Function used for validating the Enquiry Form Fields */
function enquiryValidation(){
	//alert ("EnquiryValidation Method");
	if (document.forms[1].name.value == ""){
		alert("Please enter the Name");
		document.forms[1].name.focus();
		return false;
	}
	if (document.forms[1].email.value == ""){
		alert("Please enter the E-mail");
		document.forms[1].email.focus();
		return false;
	}

	if (!emailCheck(document.forms[1].email.value)){
		document.forms[1].email.focus();
		return false;
    }
	
	if (document.forms[1].mobile.value == "")
		if (document.forms[1].telephone.value == ""){
		alert("Please provide Telephone or Mobile Number");
		document.forms[1].telephone.focus();
		return false;
	}
	
	if (document.forms[1].telephone.value != ""){
		if (!phonenumber(document.forms[1].telephone.value , "Telephone")){
			document.forms[1].telephone.focus();
			return false;
		}	
	}
	
	if (document.forms[1].mobile.value != ""){	
		if (!phonenumber(document.forms[1].mobile.value , "Mobile")){
			document.forms[1].mobile.focus();
			return false;
		}		
	}	
		
	enquiry_information = "";
	flag = false;
	if(document.forms[1].enquiry_about ) {
		for(var i=0; i<document.forms[1].enquiry_about.length; i++){
			if (document.forms[1].enquiry_about[i].checked){
				enquiry_information += document.forms[1].enquiry_about[i].value+ ", ";
				flag = true;
			}
		}
		if (!flag){
			alert ("Please choose any one of checkbox about Enquiry");
			return false;
		}else{
			document.forms[1].enquiry_information.value = enquiry_information;
//			alert(document.forms[1].enquiry_about.value);
//			return false;
		}
	}
	
	if (document.forms[1].enquiry.value != ""){	
		alert ("Please enter the enquiry information");
		document.forms[1].enquiry.focus();
		return false;		
	}		

	return true;
}

/* Validation for user registeration */
function registerValidation(){
	//alert ("RegisterValidation Function"); 
	if (document.forms[1].name.value == ""){
		alert("Please enter the Name");
		document.forms[1].name.focus();
		return false;
	}
	
	if (document.forms[1].username.value == ""){
		alert("Please enter the User Name");
		document.forms[1].username.focus();
		return false;
	}	

	if (document.forms[1].username.value.length < 4){
		alert("Please enter the User Name with atleast 4 Charactres");
		document.forms[1].username.focus();
		return false;
	}	
	
	if (document.forms[1].password.value == ""){
		alert("Please enter the Password");
		document.forms[1].password.focus();
		return false;
	}	
	
	if (document.forms[1].password.value.length < 4){
		alert("Please enter the Password with atleast 4 Charactres");
		document.forms[1].password.focus();
		return false;
	}	
	
	if (document.forms[1].confirmpassword.value == ""){
		alert("Please enter the Confirm Password");
		document.forms[1].confirmpassword.focus();
		return false;
	}	
	
	if (document.forms[1].confirmpassword.value != document.forms[1].password.value){
		alert("Please enter the same Password as Confirm Password");
		document.forms[1].confirmpassword.focus();
		return false;
	}	
	
	if (document.forms[1].email.value == ""){
		alert("Please enter the E-mail");
		document.forms[1].email.focus();
		return false;
	}	
	
	if (!emailCheck(document.forms[1].email.value)){
		document.forms[1].email.focus();
		return false;
    }	
	
	if (document.forms[1].telephone.value != ""){
		if (!phonenumber(document.forms[1].telephone.value , "Telephone")){
			document.forms[1].telephone.focus();
			return false;
		}	
	}
	
	if (document.forms[1].mobile.value != ""){	
		if (!phonenumber(document.forms[1].mobile.value , "Mobile")){
			document.forms[1].mobile.focus();
			return false;
		}		
	}
	
  
	if (document.forms[1].dateofbirth.value == ""){
		alert ("Please provide the Date Of Birth");
		document.forms[1].dateofbirth.focus();
		return false;
	}   

	if (document.forms[1].sex.value == ""){
		alert ("Please provide the sex");
		document.forms[1].sex.focus();
		return false;
	}		
	

	if (document.forms[1].marital_status.value == ""){
		alert ("Please provide the marital status");
		document.forms[1].marital_status.focus();
		return false;
	}	
	
	if (document.forms[1].caste.value == ""){
		alert ("Please provide the caste");
		document.forms[1].caste.focus();
		return false;
	}		
	
	if (document.forms[1].sub_caste.value == ""){
		alert ("Please provide the Subcaste");
		document.forms[1].sub_caste.focus();
		return false;
	}	
	
	if (document.forms[1].eating_habits.value == ""){
		alert ("Please provide the Eating Habits");
		document.forms[1].eating_habits.focus();
		return false;
	}	


	how_do_you_know_about_mmm_information = "";
	flag = false;
	if(document.forms[1].how_do_you_know_about_mmm ) {
//		alert("Raja");
		for(var i=0; i<document.forms[1].how_do_you_know_about_mmm.length; i++){
			if (document.forms[1].how_do_you_know_about_mmm[i].checked){
				how_do_you_know_about_mmm_information += document.forms[1].how_do_you_know_about_mmm[i].value+ ", ";
				flag = true;
			}
		}
		if (flag){
			document.forms[1].how_do_you_know_about_mmm_information.value = how_do_you_know_about_mmm_information;
//			alert(document.forms[1].how_do_you_know_about_mmm_information.value);
//			return false;
		}
	}
	
	return true;
}


/* Validation for user updation */
function updateProfileValidation(){
	//alert ("RegisterValidation Function"); 
	if (document.forms[1].name.value == ""){
		alert("Please enter the Name");
		document.forms[1].name.focus();
		return false;
	}
	
	if (document.forms[1].email.value == ""){
		alert("Please enter the E-mail");
		document.forms[1].email.focus();
		return false;
	}	
	
	if (!emailCheck(document.forms[1].email.value)){
		document.forms[1].email.focus();
		return false;
    }	
	
	if (document.forms[1].telephone.value != ""){
		if (!phonenumber(document.forms[1].telephone.value , "Telephone")){
			document.forms[1].telephone.focus();
			return false;
		}	
	}
	
	if (document.forms[1].mobile.value != ""){	
		if (!phonenumber(document.forms[1].mobile.value , "Mobile")){
			document.forms[1].mobile.focus();
			return false;
		}		
	}
	  
	if (document.forms[1].dateofbirth.value == ""){
		alert ("Please provide the Date Of Birth");
		document.forms[1].dateofbirth.focus();
		return false;
	}   

	if (document.forms[1].sex.value == ""){
		alert ("Please provide the sex");
		document.forms[1].sex.focus();
		return false;
	}		
	
	if (document.forms[1].maritalstatus.value == ""){
		alert ("Please provide the marital status");
		document.forms[1].maritalstatus.focus();
		return false;
	}	
	
	if (document.forms[1].smallphoto.value != ""){
		//alert (document.forms[1].smallphoto.value);
		//document.forms[1].smallphoto.focus();
		//return false;
	}		
	
	if (document.forms[1].caste.value == ""){
		alert ("Please provide the caste");
		document.forms[1].caste.focus();
		return false;
	}		
	
	if (document.forms[1].subcaste.value == ""){
		alert ("Please provide the Subcaste");
		document.forms[1].subcaste.focus();
		return false;
	}	
	
	if (document.forms[1].eatinghabits.value == ""){
		alert ("Please provide the Eating Habits");
		document.forms[1].eatinghabits.focus();
		return false;
	}	


	howdoyouknowaboutmmminformation = "";
	flag = false;
	if(document.forms[1].howdoyouknowaboutmmm ) {
		//alert("Raja");
		for(var i=0; i<document.forms[1].howdoyouknowaboutmmm.length; i++){
			if (document.forms[1].howdoyouknowaboutmmm[i].checked){
				howdoyouknowaboutmmminformation += document.forms[1].howdoyouknowaboutmmm[i].value+ ", ";
				flag = true;
			}
		}
		if (flag){
			document.forms[1].howdoyouknowaboutmmminformation.value = howdoyouknowaboutmmminformation;
	//  		alert(document.forms[1].howdoyouknowaboutmmminformation.value);
	//		return false;
		}
	}
	
	return true;
}

function clearField(test){
	//alert(test.value);
	test.value = "";
}


function emailCheck(emailStr){
	var valid1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ -_1234567890@.abcdefghijklmnopqrstuvwxyz"
	var ok1="yes";
	var temp1;
	for (var i=0; i<emailStr.length; i++) {
		temp1 = "" + emailStr.substring(i, i+1);
		if (valid1.indexOf(temp1) == "-1") ok1 = "no";
	}
	if (ok1 == "no") {
		alert("Enter a valid e-mail ID!")
		return false
	}
	var checkTLD=1;
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null) {
		alert("Enter a valid e-mail ID!");
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i)>127) {
			alert("The username contains invalid characters.");
			return false;
		}
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i)>127) {
			alert("Ths domain name contains invalid characters.");
			return false;
		 }
	}
	if (user.match(userPat)==null) {
		alert("Enter a valid e-mail ID!");
		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				alert("Destination IP address is invalid!");
				return false;
			}
		}
		return true;
	}
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
			if (domArr[i].search(atomPat)==-1) {
			alert("The domain name does not seem to be valid.");
			return false;
			}
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) {
	alert("Enter a valid e-mail ID!");
	return false;
	}
	if (len<2) {
		alert("This address is missing a hostname!");
		return false;
	}
	return true;
}

function phonenumber(field,msg) {
	if(field.length!=0){
		var valid = "0123456789 -()+"
		var ok = "yes";
		var temp;
		for (var i=0; i<field.length; i++) {
			temp = "" + field.substring(i, i+1)
			if (valid.indexOf(temp) == "-1") ok = "no"
		}
		if (ok == "no") {
			alert("Invalid entry in " + msg);
			return false
		}
		return true
	}else{
		alert("Enter " + msg);
		return false
	}
}
