//
// Javascript code for eShakti Global Registration Page Validation
//


function trimString (str) 
{
	err=0;
	for (var i = 1; i < str.length; i++) 
		{
			var ch = str.substring(i, i + 1);
			if ( ((ch < "a" || "z" < ch) && (ch < "A" || "Z" < ch)) && (ch < "0" || "9" < ch) && (ch != '_') && (ch != '-') && (ch != '@') && (ch != '.') ) 
			{
				err = 1;
			}
		}
		if (trim(str)==0)
				err=1;
  	return err;
}


function trim(s)
{	s =  s.replace( /^\s*/, "" )
	s =  s.replace( /\s*$/, "" );
	return s.length;
}

function test(src) 
{
     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);
     return regex.test(src);
}




function isnumeric(s)
{
		err=0;
		
	for (var i = 1; i < s.length; i++) 
		{
			var ch = s.substring(i, i + 1);
			if ( (ch < "0" || "9" < ch) ) 
			{
				err = 1;
			}
		}	return err;
}
function validateaffliates(whichform)
 {
	
	errstr="Error in Submission:\n\n";
	errno=0;
	
	if (trim(whichform.item("name").value)==0)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please Enter Your name\n";
		}	
	
	if (test(whichform.item("mailid").value)==false)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please enter a Valid Email ID\n";
		}
	
		
	if (errno >0)
		{
		alert (errstr);
		return false;
		}
		else
		return true;
}


function validatechangepassword(whichform)
 {
	
	errstr="Error in Submission:\n\n";
	errno=0;
	
	if (test(whichform.item("user_logon_name").value)==false)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please enter a Valid Email ID\n";
		}	
	
	if (trimString(whichform.item("user_password").value)==1)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Password cannot contain blank spaces or cannot be empty\n";}
		
	if (trimString(whichform.item("user_password1").value)==1)
		{
		errno = errno+1;
		errstr = errstr + errno + ") New Password cannot contain blank spaces or cannot be empty\n";}
	
	if (trimString(whichform.item("user_password2").value)==1)
		{
		errno = errno+1;
		errstr = errstr + errno + ") New Password Again cannot contain blank spaces or cannot be empty\n";}		
		
	if (whichform.item("user_password1").value!=whichform.item("user_password2").value)
		{
		errno = errno+1;
		errstr = errstr + errno + ") New Password entered is not matching with one another\n";}		
		
	if (errno >0)
		{
		alert (errstr);
		return false;
		}
		else
		return true;
}



function validatesignin(whichform)
{
	
	errstr="Error in Submission:\n\n";
	errno=0;
	if (test(whichform.item("user_logon_name").value)==false)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please enter a Valid Email ID\n";
		}
	if (trimString(whichform.item("user_logon_name").value)==1)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Logon Name cannot contain blank spaces or cannot be empty\n";}
	
	if (trimString(whichform.item("user_password").value)==1)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Password cannot contain blank spaces or cannot be empty\n";}

	if (errno >0)
		{
		alert (errstr);
		return false;
		}
		else
		return true;
}


function validateforgetpwd(whichform)
{
	
	errstr="Error in Submission:\n\n";
	errno=0;
	
	if (test(whichform.item("user_logon_name").value)==false)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please enter a Valid Email ID\n";
		}
	if (errno >0)
		{
		alert (errstr);
		return false;
		}
		else
		return true;
}


function validategetcode(whichform)
{
	errstr="Error in Submission:\n\n";
	errno=0;
	if (test(whichform.item("u_email_address").value)==false)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please enter a Valid Email ID\n";
		}
	if (errno >0)
		{
		alert (errstr);
		return false;
		}
		else
		return true;
}

//Validation for the Askformore and Suggestion form
function validatemail(whichform)
{
	
	errstr="Error in Submission:\n\n";
	errno=0;
	
	if (trim(whichform.item("Your Name").value)==0)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please Enter Your name\n";
		}	
	
	if (test(whichform.item("Your eMail Address").value)==false)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please enter a Valid Email ID\n";
		}
	
	if (trim(whichform.item("Message").value)==0)
		{
		errno = errno+1;
		errstr = errstr + errno + ") The message box cannot be empty\n";}	
		
	if (errno >0)
		{
		alert (errstr);
		return false;
		}
		else
		return true;
}


//Validation for the Quantity
function validatequanty(nums)
{
	errstr="Error in Submission:\n\n";
	//errno=0;
	
	if (IsqtyNumeric(nums.value))
	
		{
		alert ("Please enter only Numerical value");
		nums.focus();
		}

}

function IsqtyNumeric(s)
{
	err=0;

	for (var i = 0; i < s.length; i++) 

		{
			var ch = s.substring(i, i + 1);
			if ( (ch < "0" || "9" < ch) ) 
			{
				err = 1;
			}
		}
	return err;
}




//Validation for the Checkout form
function validatecheckout(whichform)
{
	
	errstr="Error in Submission:\n\n";
	errno=0;
	
	
	if (test(whichform.item("email").value)==false)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please enter a Valid Email ID\n";
		}
			
	if (errno >0)
		{
		alert (errstr);
		return false;
		}
		else
		return true;
}



//Validation for Sendthispage form
function validatesendpage(whichform)
{
	
	errstr="Error in Submission:\n\n";
	errno=0;
	
	if (trim(whichform.item("Your Name").value)==0)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please Enter Your name\n";
		}	
	
	if (test(whichform.item("Your eMail Address").value)==false)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please enter a Valid Email ID\n";
		}
	
	if (test(whichform.item("Friend's eMail Address").value)==false)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please enter Friend's Valid Email ID\n";
		}	
		
	if (trim(whichform.item("Message").value)==0)
		{
		errno = errno+1;
		errstr = errstr + errno + ") The message box cannot be empty\n";}	
		
	if (errno >0)
		{
		alert (errstr);
		return false;
		}
		else
		return true;
}


//Validation for Search
function validatesearch(whichform)
{
	errstr="Error in Submission:\n\n";
	errno=0;
	
	if (whichform.item("catalog").value === "Movies")
	
	{
		if (trim(whichform.item("artist").value)==0)
			{
			errno = errno+1;
			errstr = errstr + errno + ") Please enter a value to Search\n";
			}	
	}		
	
	if (errno >0)
		{
		alert (errstr);
		return false;
		}
		else
		return true;
}


//Validation for MainSearch
function validatemainsrch(whichform)
{
	errstr="Error in Submission:\n\n";
	errno=0;
	
	if (trim(whichform.srch.value)==0)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please enter a value to Search\n";
		}	
		
	if (errno >0)
		{
		alert (errstr);
		return false;
		}
		else
		return true;
}


//Validation for Power Search
function validatepowersearch(whichform)
{
	errstr="Error in Submission:\n\n";
	errno=0;
	
	if ((whichform.category.options[whichform.category.selectedIndex].value.length) === 0)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please Select a Category to Search\n";
		}	
	
	if (trim(whichform.item("artist").value)==0 && trim(whichform.item("songname").value)==0 && trim(whichform.item("title").value)==0)
		{
		errno = errno+1;
		errstr = errstr + errno + ") Please enter a Criteria to Search\n";
		}	
	
	if (errno >0)
		{
		alert (errstr);
		return false;
		}
		else
		return true;
}



function validateform(whichform){	//Validation the logon details of the user
	errstr="Error in Submission:\n\n";
	errno=0;
	var ffirst=true;	if (test(whichform.item("logon_name").value)==false)
		{		if(ffirst==true){ffirst=false;whichform.item("logon_name").focus();}
		errno = errno+1;		errstr = errstr + errno + ") Please enter a Valid Email ID\n";}
		if (trimString(whichform.item("logon_name").value)==1)
		{
		if(ffirst==true){ffirst=false;whichform.item("logon_name").focus();}		errno = errno+1;		errstr = errstr + errno + ") Logon Name cannot contain blank spaces or cannot be empty\n";}	if (trimString(whichform.item("user_security_password").value)==1)		{if(ffirst==true){ffirst=false;whichform.item("user_security_password").focus();}
		errno = errno+1;		errstr = errstr + errno + ") Password cannot contain blank spaces or cannot be empty\n";}
	if (trimString(whichform.item("c_user_security_password").value)==1)		{if(ffirst==true){ffirst=false;whichform.item("c_user_security_password").focus();}
		errno = errno+1;		errstr = errstr + errno + ") Confirm Password cannot contain blank spaces or cannot be empty\n";}		if (whichform.item("c_user_security_password").value!=whichform.item("user_security_password").value)
		{if(ffirst==true){ffirst=false;whichform.item("c_user_security_password").focus();}		errno = errno+1;
		errstr = errstr + errno + ") Password and Confirm Password should be same\n";}		
	//Validation the Personal Details of  the User
	if (trim(whichform.item("first_name").value)==0)		{if(ffirst==true){ffirst=false;whichform.item("first_name").focus();}
		errno = errno+1;		errstr = errstr + errno + ") First Name cannot be Empty\n";	}	if (trim(whichform.item("last_name").value)==0)
		{if(ffirst==true){ffirst=false;whichform.item("last_name").focus();}
		errno = errno+1;		errstr = errstr + errno + ") last Name cannot be Empty\n";	}
	if (trim(whichform.item("postal_code").value)==0)
		{if(ffirst==true){ffirst=false;whichform.item("postal_code").focus();}
		errno = errno+1;		errstr = errstr + errno + ") Zip cannot be Empty\n";}
	if (trim(whichform.item("city").value)==0)
		{if(ffirst==true){ffirst=false;whichform.item("city").focus();}
		errno = errno+1;		errstr = errstr + errno + ") City cannot be Empty\n";}						
	if (trim(whichform.item("country_name").value)==0)
		{if(ffirst==true){ffirst=false;whichform.item("country_name").focus();}
		errno = errno+1;		errstr = errstr + errno + ") Country cannot be Empty\n";}
	//if(whichform.item("acceptance").checked==false)
	//	{
	//	errno = errno+1;	//	errstr = errstr + errno + ") Please confirm your acceptance to the terms and conditions.\n";}			
	if (errno >0)		{
			alert (errstr);				return false;
		}
	else
		return true;}

function validatereview(form)
{
	if (trim(form.yname.value)==0)
	{
		alert("Please provide your name");
		form.yname.focus();
		return false;
	}
	if (test(form.ymailid.value)==false)
	{
		alert("Please provide valid email address");
		form.ymailid.focus();
		return false;
	}
	if (trim(form.review.value)==0)
	{
		alert("Please provide your review");
		form.review.focus();
		return false;
	}}
//Validate the Women Size profile page
function validatesizeprof(form)
{
	if (trim(form.profname.value)==0)
	{
	alert ("Please enter valid profile name");
	form.profname.focus();
	return false;
	}
	
	if ((form.waddinst.value.length) > 500)
	{
	alert ("The Additional instruction cannot exceed more than 500 characters");
	form.waddinst.focus();
	return false;
	}
}

//Validate the Men Size profile page
function validatemensizeprof(form)
{
	if (trim(form.profname.value)==0)
	{
	alert ("Please enter valid profile name");
	form.profname.focus();
	return false;
	}
	if ((form.msplinst.value.length) > 500)
	{
	alert ("The Additional instruction cannot exceed more than 500 characters");
	form.msplinst.focus();
	return false;
	}
}

//Validate the Refer a Friend Page
function validatereferral(form)
{
	var refcount = 0;
	if (test(form.yemail.value)==false)
	{
		alert("Please provide your valid email address");
		form.yemail.focus();
		return false;
	}
	if (form.yfname.value=="")
	{
		alert("Please provide your first name");
		form.yfname.focus();
		return false;
	}
	if (form.ylname.value=="")
	{
		alert("Please provide your last name");
		form.ylname.focus();
		return false;
	}	for (var i=1; i <= 20; i++){		RefEmail = document.getElementById('fmailid' + i);		RefFname = document.getElementById('fname' + i);		RefLname = document.getElementById('lname' + i);
			if ((test(RefEmail.value)==false) && (RefEmail.value != ""))
			{
				alert("Please provide valid email address");
				RefEmail.focus();
				return false;
			}			else			{
			if(RefEmail.value != ""){
				if (RefFname.value=="")				{				alert("Please provide a valid first name");
				RefFname.focus();
				return false;
				}
				if (RefLname.value=="")				{				alert("Please provide a valid last name");
				RefLname.focus();
				return false;
				}				refcount = refcount + 1;
				}			}
	}
	//if (refcount < 2) {
	//			alert("Please provide a minimum of two referrals");
				
	//			return false;
	//			}
	
}


//Validate Signincheckout page
function validatesigncheckout(form)
{
	if (test(form.user_logon_name.value)==false)
	{
		alert("Please provide your valid email address");
		form.user_logon_name.focus();
		return false;
	}
		
}

function validatesize1(form)
{
alert (form.design.value);
return false;
}


//Validate Selected Size
function validatesize(form)
{	psize = "";
	for (var i=0; i < form.param_size.length; i++)
   {
   if (form.param_size[i].checked)
      {
      var psize = form.param_size[i].value;
      }
   }

	if  ((psize) == "")
		{				if  ((form.param_bust.value == "Select") || (form.param_waist.value == "Select") || (form.param_hip.value == "Select"))			{			alert("Please select a regular size or select your custom size measurements");
						return false;
			}		}	if ((form.param_height.value)=="Select")			{
				alert("Please Enter Your Height");				form.param_height.focus();				return false;			}	if  ((psize) == "")	{
	if  (form.param_bust.value == "Select")
		{				alert("Please select your bust size");
			form.param_bust.focus();			return false;		}
	if  (form.param_waist.value == "Select")
		{				alert("Please select your waist size");
			form.param_waist.focus();			return false;		}
	if  (form.param_hip.value == "Select")
		{				alert("Please select your hip size");
			form.param_hip.focus();			return false;		}
	}		
			
	}	


//Validate Customer Feedback formfunction validatecustfeedbackform()

{
	if (trim(document.tstest.custname.value)==0)
	{
		alert ("Please Enter Customer Name");
		document.tstest.custname.focus();
		return false;
	}
	if (trim(document.tstest.custfb.value)== 0)
	{
		alert ("Please Enter Customers Feedback");
		document.tstest.custfb.focus();
		return false;
	}
	if (trim(document.tstest.banner.value) == 0)
	{
		alert ("Please enter Banner Text");
		document.tstest.banner.focus();
		return false;
	}
	if ((document.tstest.banner.value.length) > 500)
	{
		alert ("The banner text cannot exceed more than 500 characters");
		document.tstest.banner.focus();
		return false;
	}
}

//Validate Glossary formfunction validateglossary()
{
	if (trim(document.tstest.mtext.value)==0)
	{
		alert ("Please Enter The Word");
		document.tstest.mtext.focus();
		return false;
	}
	if (trim(document.tstest.description.value)== 0)
	{
		alert ("Please Enter The Description");
		document.tstest.description.focus();
		return false;
	}
	//if ((document.tstest.description.value.length) > 600)
	//{
	//	alert ("The description cannot exceed more than 600 characters");
	//	document.tstest.description.focus();
	//	return false;
	//}
}
//Validate Forgot Password
function validateforgotpwd(form){
	if (test(form.uname.value)==false)
		{
			alert("Please provide your valid email address");
			form.uname.focus();
			return false;
		}
	if (trim(form.password.value)==0)
		{
			alert("Please provide your password");
			form.password.focus();
			return false;
		}	
}	

//Validate Signincheckout page
function validatesigninchk(form)
{

if (form.logon_name[1].checked ==true)
	{
	if (test(form.user_logon_name.value)==false)
		{
		alert("Please provide your valid email address");
		form.user_logon_name.focus();
		return false;
		}
	}
		
}


function validatelogentry(form)
{
	if (trim(form.title.value)==0)
	{
		alert ("Please enter a valid title");
		form.title.focus();
		return false;	
	}
	if (trim(form.logdt.value)==0)
	{
		alert ("Please enter a date.");
		form.logdt.focus();
		return false;	
	}
	if (trim(form.description.value)==0)
	{
		alert ("Please enter a description.");
		form.description.focus();
		return false;	
	}
	if ((form.description.value.length) > 299)
	{
		alert ("The description you have entered is too long. Please do not enter more than 290 characters.");
		form.description.focus();
		return false;	
	}
	
}


//Check length of the sleeve
	function sleevevalue1(form)
	{
	var sleevevalue 
	sleevevalue = form.param_sleeve.value;
	alert (sleevevalue);
	
	//if (sleevevalue == "Sleeveless")
	//	{
	//	document.form1.param_sleevelength.value = 0;
	//	document.form1.param_garmentsize.value = "Sleeveless Fit";
	//	document.form1.param_sleevelength.disabled = true;
	//	document.form1.param_garmentsize.disabled = true;
	//	document.form1.param_kameezlen.focus();
	//	}
	//else
	//	{
	//	document.form1.param_sleevelength.disabled = false;
	//	document.form1.param_garmentsize.disabled = false;
	//	document.form1.param_garmentsize.value = "As Shown";
	//	document.form1.param_sleevelength.focus();
	//	}
	}


//Check length of the kameez
	function kameezvalue()
	{
	document.form1.param_kameezlen.focus();
	}
	

//Validate advance search feature
	function validateadvsrch(form)
	{
		if (trim(form.srch.value)==0)
		{
			if (trim(form.cate.value)==0)
			{
			alert ("Please enter a keyword to search or select a category to search");
			form.srch.focus();
			return false;	
			}
		}
	}
		
		
//Validate Variants Sizes
function validatevariantsize(whichform)	
{
	if ((whichform.sizechart.value == "YES") && (whichform.designopt.value == "no"))
	{
	//	if (trim(whichform.param_kameezlength.value)==0)
	//	{
	//		alert("Please select Kameez Length");
	//		whichform.param_kameezlength.focus();
	//		return false;
	//	}
		if (trim(whichform.param_height.value)==0)
		{
			alert("Please Enter Your Height");
			whichform.param_height.focus();
			return false;
		}
	//	if (trim(whichform.param_inseam.value)==0)
	//	{
	//		alert("Please Enter Your Inseam Length");
	//		whichform.param_inseam.focus();
	//		return false;
	//	}
	}
}


//Validate western Section Size
function validatewesternsize(form)
{
	if  (form.param_size.value == "selectsize")
		{				alert("Please select your size");
			form.param_size.focus();			return false;		}	if ((form.param_size.value == "sizeinfo") && (form.param_sizeprof.value == "Not Applicable"))
		{
			alert("You have selected ''Your Size Information'' from the Size box, please choose a name from Your Size Information");
			form.param_sizeprof.focus();			return false;
		}	if (form.param_size.value == "customizesize")
		{
			alert ("customize");
			form.param_sizeprof.focus();			return false;
		}	if (form.designopt.value == "YES")
	{		if (form.param_size.value != "sizeinfo")	
			{				if (trim(form.param_kameezlength.value)==0)				{					alert("Please select Kameez Length");					form.param_kameezlength.focus();					return false;				}				if ((form.param_inseam.value)==0)				{
					alert("Please Enter Inseam Length");
					form.param_inseam.focus();					return false;				}
			}	}	}

//Validate western Variant Sizes
function validatewesternvarisize(form)
{
	if (form.designopt.value == "no")
	{
		if (form.sizechart.value == "YES")
		{
			if (form.sizeprofile.value == "no")
			{
				if (trim(form.param_kameezlength.value)==0)				{					alert("Please select Top Length");					form.param_kameezlength.focus();					return false;				}				if (trim(form.param_inseam.value)==0)				{
					alert("Please Enter Inseam Length");
					form.param_inseam.focus();					return false;				}
			}
			else
			{
				if (form.param_sizeprof.value == "Not Applicable")
				{
					if (trim(form.param_kameezlength.value)==0)					{						alert("Please select Top Length");						form.param_kameezlength.focus();						return false;					}					if (trim(form.param_inseam.value)==0)					{
						alert("Please Enter Inseam Length");
						form.param_inseam.focus();						return false;					}
				}
			}
		}
	}
}


//Validate western section search
function validatewestsrch(form)
{
	if (trim(form.srch.value)==0)
	{
		alert("Please enter a value to search");
		form.srch.focus();
		return false;
	}
}

//Validate Ethinic section search
function validateenq(form)
{
	if (trim(form.srch.value)==0)
	{
		alert("Please enter a value to search");
		form.srch.focus();
		return false;
	}
}