//  Removed CartId from Line No. 70, 72, 128, 130, 159, 161 by Armour - 23/12/2004
var IndexVal; // used in sec_ans_validate(frmname), secretValidate() & checkreguser()

//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function will validate the secret answer(s). It passes the 
//  @                     Indexval to the main function through global variable.
//	@	  Pages Affected  : acclogin.asp
//  @		Function Name		: sec_ans_validate(frmname)									
//	@		Input Parameters: form name
//	@		Output Parameters: 0-success, 1-failure
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function sec_ans_validate(frmname){
	var iIndex, len, answer_count, selected_index, name;
	answer_count = 0;
	
	frm = eval("document." + frmname);
	len = frm.elements.length;
	for(iIndex=0;iIndex<=parseInt(len)-1;iIndex++){
		if(frm.elements[iIndex].type.substring(0,4) == "text"){
			if((frm.elements[iIndex].value != "") && (frm.elements[iIndex].value.indexOf(" ") < 0)){
				answer_count++
				selected_index = iIndex 
			}
		}
	}
	
	if(answer_count < 1){
		alert(getMessage("iEnterSecretAns"));
		return 1;//failure
	}
	if(answer_count > 1){
		alert(getMessage("iMoreThanOneSecretAns"));
		return 1;//failure
	}
	name = frm.elements[selected_index].name;
	IndexVal = name.substring(13,name.length);
	return 0;//success
}
// End of the function sec_ans_validate(frmname)


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function will validate the secret answer(s). It calls  
//  @                     sec_ans_validate() for validating and assigns the acc name and 
//  @                     secret answer to another form and submits the form.
//	@	  Pages Affected  : acclogin.asp
//  @		Function Name		: secretValidate(option)								
//	@		Input Parameters: option=1->NonSecurepath,2->Securepath
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function secretValidate(option)
{

	if(document.frmForgot.secret_answer.value=="") {
		alert(getMessage("iEnterSecretAns"));
		return false;
	}
	if(document.frmForgot.secret_answer.value.indexOf(" ") == 0){
		alert(getMessage("iSecretAnsNoSpace"));
		document.frmForgot.secret_answer.focus();
		document.frmForgot.secret_answer.select();
		return false;
	}
	document.frmdumForgot.accname.value = document.frmForgot.accname.value;
	document.frmdumForgot.addr_code.value = document.frmForgot.addr_code.value;
	document.frmdumForgot.secret_answer.value = document.frmForgot.secret_answer.value
	if(option==2)
		document.frmdumForgot.action = sSecurePath + "sendmail.asp?msg=" + sMessage + "&url=AL&Tp=" + sTpCatalog;
	else
		document.frmdumForgot.action = sNonSecurePath + "sendmail.asp?msg=" + sMessage + "&url=AL&Tp=" + sTpCatalog;
	document.frmdumForgot.submit();
	return false;
}
// End of the function secretValidate(option)


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@	Description			: This function will validate the the login field for forgot password part.
//	@	Pages Affected  : acclogin.asp
//  @	Function Name		: validateMail()
//	@	Input Parameters: null
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function validateMail()
{
	var regExpression;
	regExpression = /^[^'^"]*$/;	// Checking for the existence of ' and " in login name
	if((document.frmForgot.forgotLogin.value == "") || (document.frmForgot.forgotLogin.value.indexOf(" ") > -1) || (!regExpression.test(document.frmForgot.forgotLogin.value))){
		alert(getMessage("iLoginEmail"));
		document.frmForgot.forgotLogin.focus();
		document.frmForgot.forgotLogin.select();
		return false;
	}
	document.frmForgot.submit();
}
// End of the function validateMail()


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function will validate the the login field and the password 
//  @                     field for the main login part.
//	@	  Pages Affected  : acclogin.asp
//  @		Function Name		: loginme(option)								
//	@		Input Parameters: option=1->NonSecurepath,2->Securepath
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function loginme(option){
	var regExpression;
	regExpression = /^[^'^"]*$/;		// Checking for the existence of ' and " in login name
	if (document.frmLogin.accname.value == ""){
		alert(getMessage("iLoginEmpty"));
		document.frmLogin.accname.focus();
		return false;
	}
	if (!regExpression.test(document.frmLogin.accname.value)){
		alert("Please enter valid login name.");
		document.frmLogin.accname.focus();
		return false;
	}
	if((document.frmLogin.accname.value.indexOf(" ") > -1) || (document.frmLogin.mypassword.value.indexOf(" ") > -1)){
			alert(getMessage("iLoginPassNoSpace"));
			document.frmLogin.accname.focus();
			return false;
		}
	if(option==2)
		document.frmLogin.action = sSecurePath + "acclogin.asp?msg=" + sMessage + "&ic=" + sIc + "&EqCode=" + sEqCode + "&Qty=" + iQty + "&type=" + sDocType + "&order=" + sDocNum + "&url=AL&SSL=1&Tp=" + sTpCatalog;
	else
		document.frmLogin.action = sNonSecurePath + "acclogin.asp?msg=" + sMessage + "&ic=" + sIc + "&EqCode=" + sEqCode + "&Qty=" + iQty + "&type=" + sDocType + "&order=" + sDocNum + "&url=AL&Tp=" + sTpCatalog;
	document.frmLogin.submit();
	return false;
}
// End of the function loginme(option)


//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
//	@		Description			: This function will validate the secret answer(s). It calls  
//  @                     sec_ans_validate() for validating and assigns the acc name, 
//  @                     address code, address type and secret answer to another form and
//  @                     submits the form.
//	@	  Pages Affected  : acclogin.asp
//  @		Function Name		: checkreguser(option)								
//	@		Input Parameters: option=1->NonSecurepath,2->Securepath
//	@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

function checkreguser(option)
{
	var retVal;
	 
	retVal = sec_ans_validate("frmmaillogin")
	if(retVal==1) return false;
	
	document.frmdummaillogin.accname.value = eval("document.frmmaillogin.accname" + IndexVal + ".value");
	document.frmdummaillogin.addr_code.value = eval("document.frmmaillogin.addr_code" + IndexVal + ".value")
	document.frmdummaillogin.addr_type.value = eval("document.frmmaillogin.addr_type" + IndexVal + ".value")
	document.frmdummaillogin.secret_answer.value = eval("document.frmmaillogin.secret_answer" + IndexVal + ".value")
	if(option==2)
		document.frmdummaillogin.action = sSecurePath + "acclogin.asp?msg=" + sMessage + "&url=AL&Tp=" + sTpCatalog;
	else
		document.frmdummaillogin.action = sNonSecurePath + "acclogin.asp?msg=" + sMessage + "&url=AL&Tp=" + sTpCatalog;
	document.frmdummaillogin.submit();
	return false;
}
// End of the function checkreguser(option)
