 function isMicrosoft() {
  /*
  ** Check if the browser is Microsoft Internet Explorer compatible
  **    v  version number
  ** returns  true if MSIE and version equals or greater
  */
  return isBrowser("Microsoft");
  }
function isBrowser(b) {
  /*
  ** Check if the current browser is compatible
  **  b  browser name
  **  v  version number (if 0 don't check version)
  ** returns true if browser equals and version equals or greater
  */
  browserOk = false;
 

  browserOk = (navigator.appName.indexOf(b) != -1);
  if(browserOk)
	  alert("Browser ok");
  else
	   alert("Browser Not ok");
  return browserOk;
  }

 function checkKey()
    {
        if (window.event.keyCode == 13)
        {
            validate();
        }
    }

/**********validate LOGIN ID and PASSWORD***********/
function validate()
{
	
	var loginCheck=false;
	
	if (trim(document.LoginForm.loginId.value)== "")
	{	
		alert("Please Enter User id")
		LoginForm.loginId.focus();
		LoginForm.loginId.select();
	}
	else 
	{
		loginCheck=verifyLogin(document.LoginForm);
		if(loginCheck==true)
		{
			var passcheck=verifyPass();
			if(passcheck==true)
			{
				document.LoginForm.LF_nav_next_block.value="LOGIN";
				document.LoginForm.action="dispatcher";
				document.LoginForm.submit();
			}
		}
	}
}
/**********END***********/
/**********SUBFUNCTION of validate(), for login check***********/
function verifyLogin(form)
{
	var blanks=0;	
	var iChars = "*|,\":<>[]{}`\';.()@&$#%+-_^~!&?/";
	var loginValue=form.loginId.value;
	for(var i=0;i<loginValue.length;i++)
	{
		var chr=loginValue.charAt(i);
		if(chr==" ")
		{
			blanks=blanks+1;
		}
	}
	if(blanks>0)
	{
		alert("User id cannot contain blank Spaces.");
		form.loginId.focus();
		form.loginId.select();
	}		
	
	/*else if((loginValue.length) < 8 )
	{
		alert("Length of username should be atleast 8 characters")
		document.LoginForm.loginId.focus();
		document.LoginForm.loginId.select();
	}
	else if (CheckUserName(loginValue) == false) 
	{
		alert("Username can not contain special character");
		document.LoginForm.loginId.focus();
	}*/
	else return true;	
}
/******************END*************/
/***********function to check format of LOGIN ID*************/
function CheckUserName(string)
{
	var alphaCount=0
	var numCount=0    
	var iChars = "*|,\":<>[]{}'`\';.()@&$#%+-_^~!&?/";
	var num_valid="0123456789"
    var alph_valid="abcdefghijklmnopqrstuvwxyz"
	if (!string) return false;
	for (var i = 0; i < string.length; i++) 
	{
		if (iChars.indexOf(string.charAt(i)) != -1)
		{
			numCount++;
		}
	}
	if(numCount > 0)
	{
		return false;		    
	}		
}
/******************END***********************/
/***********function to validate PASSWORD*************/
function verifyPass()
{	
	var blanks=0;
	var specialChar=0;
    var iChars = "*|,\":<>[]{}`\';.()@&$#%+-_^~!&?/";
	var passValue=document.LoginForm.password.value
	for(var i=0;i<passValue.length;i++)
	{
		var chr=passValue.charAt(i);
		if(chr==" ")
		{
			blanks=blanks+1;
		}
		if (iChars.indexOf(passValue.charAt(i)) != -1)
		{
			specialChar++;
		}
	}
	if(blanks>0)
	{
		alert("Password cannot contain blank Spaces.");
		document.LoginForm.password.focus();
		document.LoginForm.password.select();
		return false;
	}		
	else if (trim(passValue)== "")
	{	
		alert("Please Enter Password")
		document.LoginForm.password.focus();	
	}
	/*else if((passValue.length) < 8 )
	{
		alert("Length of password should be atleast 8  characters")
		document.LoginForm.password.focus();
		document.LoginForm.password.select();
		return false;
	}
	else if(specialChar<1)
	{
	    alert("Passoword must have atleast one special character");
		document.LoginForm.password.focus();
		document.LoginForm.password.select();
	}*/
	else return true;	
}
/************ FORWARDING THE ACTION *****************/
function fnForwardAction(request_type)
{
		if(request_type=="ADD_USER")
		{
			document.SelectForm.fromRequest.value="DIR_ADD_USR";
		}
		document.SelectForm.LF_nav_next_block.value="SELECT_ACTION";
		document.SelectForm.REQUEST_TYPE.value=request_type;
		document.SelectForm.action="dispatcher";
		document.SelectForm.submit();
}
/************ END FORWARDING THE ACTION **************/
/************ VALIDATION ON ADD VENDOR *****************/
function validateVendor()
{
	frm = document.VendorForm;
	var compName = trim(frm.compName.value);
	var apCode = trim(frm.apCode.value);
	var phoneNo = trim(frm.phoneNum.value);
	var faxNo = trim(frm.faxNum.value);
	var emailId = trim(frm.emailId.value);
	var website = trim(frm.website.value);
	var desc = trim(frm.description.value);
	var flag = true;
	if(flag==true&&validateAPCode(apCode) == false)
	{
		flag = false;
	}
	if(flag==true&&validateCompName(compName) == false)
	{
		flag = false;
	}
	if(flag==true&&phoneNo!="")
	{
		if(validateFaxOrFone(phoneNo)==false)
		{
			flag=false;
		}
	}
	if(flag==true&&emailId!="")
	{
		if(validateEmailId(emailId) == false)
		{
			flag=false;
		}
	}
	if(flag==true&&faxNo!="")
	{
		if(validateFaxOrFone(faxNo)==false)
		{
			flag=false;
		}
	}
	if(flag==true&&website!="")
	{
		if(validateWebSite(website) == false)
		{
			flag=false;
		}
	}
	if(flag==true&&desc.length>100)
	{
		flag=false;
		alert("Description can only have 100 characters at most");
	}
	if(flag == true)
	{
		frm.LF_nav_next_block.value="ADD_VENDOR";
		frm.action="dispatcher"
		frm.submit();		
	}


}

/************ END VALIDATION ON ADD VENDOR **************/

function validateCompName(compName)
{
	if(compName == "")
	{
		alert("Please Enter Company Name");
		return false;
	}
	else if(fnCheckCompany(compName) == false)
	{
		alert("Company name can not have special character other than .,' and &.");
		return false;
	}
	return true;
}

/************ End Validate Company Name **********************/
/**************Check Company name****************/
function fnCheckCompany(compName)
{
	var splcnt=0;
	var iChars = "*|,\":<>[]{}`\;()@$#%+_^~!?/";
	for (var i = 0; i < compName.length; i++) 
	{
		if (iChars.indexOf(compName.charAt(i)) != -1)
		{
			splcnt++;
		}
	}
	if(splcnt>0)
	{
		return false;
	}
	else
		return true;

}
/************ Validate APCode **************************/

function validateAPCode(apCode)
{
	if(apCode == "")
	{
		alert("Please Enter APCode");
		return false;
	}
	else if(fnCheckApCode(apCode)==false)
	{
		alert("APCode can not have special character");
		return false;
	}
	return true;
}

/************ End Validate APCode **********************/
/*************Check APCode*******************/
function fnCheckApCode(apCode)
{
var splcnt=0;
	var iChars = "*|,\":<>[]{}'`\';.()@&$#%+_^~!&?/";
	for (var i = 0; i < apCode.length; i++) 
	{
		if (iChars.indexOf(apCode.charAt(i)) != -1)
		{
			splcnt++;
		}
	}
	if(splcnt>0)
	{
		return false;
	}
	else
		return true;
}

/************ Validate Email-Id **************************/

function validateEmailId(emailId)
{
	if(emailId == "")
	{
		alert("Please Enter Email-Id");
		return false;
	}
	else if(validateMail(emailId)==false)
	{
		alert("Please enter a valid email id");
		return false;
	}
	return true;
}
/************ End Validate Email-Id **********************/
/************ Validate Website **********************/

function validateWebSite(website)
{
	if(website.length > 0 &&fnCheckWeb(website)==false)
	{
	    alert("WebSite can not contains special characters");
		return false;
	}
	return true;
}

/************ End Validate Website **********************/
/*************Check website name*****************/
function fnCheckWeb(website)
{
	var splcnt=0;
	var iChars = "*|,\":<>[]{}'`\';()@&$#%+_^~!&?/";
	for (var i = 0; i < website.length; i++) 
	{
		if (iChars.indexOf(website.charAt(i)) != -1)
		{
			splcnt++;
		}
	}
	if(splcnt>0)
	{
		return false;
	}
	else
		return true;
}

/************ APCode LookUp *****************************/

function APCodeLookUp(request_type,formName,DBType)
{	
	window.open('dispatcher?LF_nav_next_block=LOOK_UP&REQUEST_TYPE='+request_type+'&formName='+formName+'&DBType='+DBType,null,"height=400,width=400,status=yes,toolbar=no,menubar=no,location=no");
}

function SearchApCode(request_type,formName,DBType)
{
		var apCode = trim(document.LookUpForm.apCode.value);
		var compName = trim(document.LookUpForm.compName.value);

		if((apCode == null || apCode =="") && (compName == null || compName ==""))
		{
			alert('Please select either of the ApCode or Company Name while searching APCode');
			return false;
		}
		else if((apCode != null || apCode !="" ) && fnCheckApCode(apCode)==false)
		{
			alert("APCode can not have special character");
			return false;
		}
		else if((compName != null || compName !="" )&&fnCheckCompany(compName)==false)
		{
			alert("Company name can not have special character other than .,' and &.");
			return false;
		}
		document.LookUpForm.LF_nav_next_block.value="LOOK_UP";
		document.LookUpForm.action='dispatcher?REQUEST_TYPE='+request_type+'&formName='+formName+'&DBType='+DBType;
		document.LookUpForm.submit();
}
function setFields(apCode,CompName,forWhat)
{
	window.opener.document.forms[1].apCode.value = apCode;
	window.opener.document.forms[1].compName.value = replaceAll(CompName);
	window.close();
	if(forWhat=="VendorForm")
	{
		window.opener.document.forms[1].LF_nav_next_block.value="LOAD_VENDOR";
		window.opener.document.forms[1].action='dispatcher';
		window.opener.document.forms[1].submit();
	}
	
}

function vendorDetails()
{
		document.VendorForm.LF_nav_next_block.value="MODIFY_VENDOR";
		document.VendorForm.action='dispatcher';
		document.VendorForm.submit();
}

function modifyVendor()
{
	frm = document.VendorForm;
	var compName = trim(frm.compName.value);
	var apCode = trim(frm.apCode.value);
	var phoneNo = trim(frm.phoneNum.value);
	var faxNo = trim(frm.faxNum.value);
	var emailId = trim(frm.emailId.value);
	var website = trim(frm.website.value);
	var desc = trim(frm.description.value);
	var flag = true;
	if(flag==true&&validateAPCode(apCode) == false)
	{
		flag = false;
	}
	if(flag==true&&validateCompName(compName) == false)
	{
		flag = false;
	}
	if(flag==true&&phoneNo!="")
	{
		if(validateFaxOrFone(phoneNo)==false)
		{
			flag=false;
		}
	}
	if(flag==true&&emailId!="")
	{
		if(validateEmailId(emailId) == false)
		{
			flag=false;
		}
	}
	if(flag==true&&faxNo!="")
	{
		if(validateFaxOrFone(faxNo)==false)
		{
			flag=false;
		}
	}
	if(flag==true&&website!="")
	{
		if(validateWebSite(website) == false)
		{
			flag=false;
		}
	}
    if(flag==true&&desc.length>100)
	{
		flag=false;
		alert("Description can only have 100 characters at most");
	}
	if(flag == true)
	{

		frm.modified.value = "true";
		frm.LF_nav_next_block.value="MODIFY_VENDOR";
		frm.action='dispatcher';
		frm.submit();		
	}
}
/************ End APCode LookUp *****************************/
/************ Validation function while crating login for new user**********/
function fnCreateLoginCheck()
{
	
	var frstName=trim(document.UserForm.firstName.value);
	var lstName=trim(document.UserForm.lastName.value);
	var faxNum=trim(document.UserForm.faxNum.value);
	var phneNum=trim(document.UserForm.phoneNum.value);
	var mailId=trim(document.UserForm.mailId.value);
	var status=true;
	if(fnCheckName(frstName)==false&&status==true)
	{
		status=false;
		document.UserForm.firstName.focus();
		document.UserForm.firstName.select();
	}
	if(status==true&&fnCheckName(lstName)==false)
	{
		status=false;
		document.UserForm.lastName.focus();
		document.UserForm.lastName.select();
	}
	if(status==true)
	{
		status=validateMail(mailId);
		if(status==false){
			alert("Please enter a valid email id");
			document.UserForm.mailId.focus();
			document.UserForm.mailId.select();
		}
	}
	if(status==true&&faxNum!="")
	{	
		status=validateFaxOrFone(faxNum);
		if(status==false){
			document.UserForm.faxNum.focus();
			document.UserForm.faxNum.select();
		}
	}
	if(status==true&&phneNum!="")
	{
		status=validateFaxOrFone(phneNum);
			if(status==false){
				document.UserForm.phoneNum.focus();
				document.UserForm.phoneNum.select();
			}
	}
	
	if(status==true)
	{
		document.UserForm.LF_nav_next_block.value="CREATE_USER";
		document.UserForm.action='dispatcher';
		document.UserForm.submit();
	}
	
}
/************ END**********/
/************ Validation function while Adding a new user**********/
function fnAddUserCheck(form)
{
	
	var frstName=trim(form.firstName.value);
	var lstName=trim(form.lastName.value);
	var faxNum=trim(form.faxNum.value);
	var phneNum=trim(form.phoneNum.value);
	var mailId=trim(form.mailId.value);
	var apCode=trim(form.apCode.value);
	var usrClsKey=trim(form.userClassKey.value);
	var loginId=trim(form.loginId.value);
	var password=trim(form.password.value);
	var loggedUserType=trim(form.loggedUserType.value);
	var usrBsnsKey = trim(form.userBusinessKey.value);
	var status=true;
	if(status==true&&fnCheckName(frstName)==false)
	{
		status=false
		form.firstName.focus();
		form.firstName.select();
	}
	if(status==true&&fnCheckName(lstName)==false)
	{
		status=false
		form.lastName.focus();
		form.lastName.select();
	}
	if(status==true&&phneNum=="")
	{
		status=false
		alert("Please enter phone number");
		form.phoneNum.focus();
		form.phoneNum.select();
	}
	if(status==true&&validateFaxOrFone(phneNum)==false)
	{
		status=false
		form.phoneNum.focus();
		form.phoneNum.select();
	}
	if(status==true&&faxNum!="")
	{	
		status=validateFaxOrFone(faxNum);
		if(status==false){
			form.faxNum.focus();
			form.faxNum.select();
		}
	}
	if(status==true&&mailId=="")
	{
		status=false
		alert("Please enter a email id");
		form.mailId.focus();
		form.mailId.select();
	}
	if(status==true&&validateMail(mailId)==false)
	{
		status=false
		alert("Please enter a valid email id");
		form.mailId.focus();
		form.mailId.select();
	}
	if(loggedUserType=="GES_ADMIN")
	{
		if(usrClsKey=="3")
		{
			if(status==true)
			{
				if(validateApCode(apCode)==false)
				{
					status=false
					alert("Please select an APCode");
				}
				else if(validateLogin(loginId)==false)
				{
					status=false;
					alert("Please create a login id for user before adding");
				}
				else
				{
					form.LF_nav_next_block.value="ADD_USER";
					form.action='dispatcher';
					form.submit();
				}
			}
		}
		else
		{
			if(status==true)
			{
				if(validateLogin(loginId)==false)
				{
					status=false;
					alert("Please create a login id for user before adding");
				}
				else
				{
					form.LF_nav_next_block.value="ADD_USER";
					form.action='dispatcher';
					form.submit();
				}
			}
		}
	}
	else
	{
		if(status==true)
		{
			if(validateApCode(apCode)==false)
			{
				status=false
				alert("Please select an APCode");
			}
			else if(validateLogin(loginId)==false)
			{
				status=false;
				alert("Please create a login id for user before adding");
			}
			else
			{
			form.LF_nav_next_block.value="ADD_USER";
			form.action='dispatcher';
			form.submit();
			}
		}
	}
}
/************ END**********/
/******************Validate name*******************/ 
function fnCheckName(name)
{
	//commented by Naved for task-3522--to remove hyphen validation on name field
	//var iChars = "*|,\":<>[]{}`\.;()@&$#%+-_^~!&?/";
	var iChars = "*|,\":<>[]{}`\.;()@&$#%+_^~!&?/";
	var numbers="0123456789"
	var splcnt=0;
	var numcnt=0;
	var blanks=0;
	for (var i = 0; i < name.length; i++) 
	{
		if (iChars.indexOf(name.charAt(i)) != -1)
		{
			splcnt++;
		}
	}
	for (var i = 0; i < name.length; i++) 
	{
		if (numbers.indexOf(name.charAt(i)) != -1)
		{
			numcnt++;
		}
	}
//Added by Naved for task id-3522---start
     var hyphen="-";
	 var hyphenCount=0;
	for (var i = 0; i < name.length; i++) 
	{
		if (hyphen.indexOf(name.charAt(i)) != -1)
		{
			hyphenCount++;
		}
	}
	//Added by Naved for task id-3522---End
	
	for(var i=0;i<name.length;i++)
	{
		var chr=name.charAt(i);
		if(chr==" ")
		{
			blanks=blanks+1;
		}
	}
	//commented by Naved for task id-3522
	/* 
        if(blanks>0)
	{
		alert("Name should not have any space");
		return false;
	}*/
        
      //Added by Naved for task id-3522---start  
	var TotalCount=0;
	var TotalCount=hyphenCount + blanks;
	//Added by Naved for task id-3522---End
	if(splcnt>0)
	{
		alert("Name should not have any special character");
		return false;
	}
	else if(numcnt>0)
	{
		alert("Name can not contain numbers");
		return false;
	}
	else if(name.length<=0)
	{
		alert("First and last name are mandatory");
		return false;
	}
//Added by Naved for task id-3522---start
	else if (TotalCount==name.length)
	{
        alert("Invalid First/Last Name");
		return false;
	}

	//Added by Naved for task id-3522---End
	else
	{
		return true;
	}

		
}
/******************END Validate name*******************/ 
/******************Validate EMAIL*******************/ 
function validateMail(email)
{
	
    var returnCode = false;
    // check the validity of an email address
    if (( email == "") || (email == null))
                    returnCode = false;

    // Basic tests for email validity >> Only one @ and No trailing '.'
    
    var trailing_dot = /\.{1}$/;
    var email_test = /\S+@{1}\S+\.\S+/;       

    var nat = 0;
    var i;
    var s = email;
    var emailLength= s.length;

    for (var i=0; i<emailLength; i++)
    {
        if (s.charAt(i) == "@") nat++
    }

    if (email_test.test(s) && !trailing_dot.test(s) && nat < 2)
    {
		
        returnCode = CheckSplEmail(email);
    }
	else if(emailLength>50)
	{
		returnCode= false;	
	}
    else
    {
        returnCode =  false;
    }
    return returnCode;
}
/******************END Validate EMAIL*******************/ 
/******Validate EMAIL subfunction, for special characted check*********/ 
function CheckSplEmail(emailid)
{   
      for(var i=0;i<emailid.length;i++)
      {
          var j=emailid.charAt(i);
          var asciij=ascii_value(j);
          if(j=='_' || j=='@' || j=='.' || j=='-')
		  {
		  }
          else
          {
              if((asciij>=32 && asciij<=47) || (asciij>=58 && asciij<=63) || (asciij>=91 && asciij<=96) || (asciij>=123 && asciij<=126))      
                { 
                 //alert("Please do not use special characters in your e-mail address.");
                 return false;
                } 
                 
          } 
      }
      return true;
}
/******************END*******************/ 
/********Validate EMAIL subfunction for ascii check*********/ 
function ascii_value (c)
{
	
	c = c . charAt (0);

	
	var i;
	for (i = 0; i < 256; ++ i)
	{
		
		var h = i . toString (16);
		if (h . length == 1)
		h = "0" + h;
		h = "%" + h;
		h = unescape (h);
             	if (h == c)
		break;
	}
	return i;
}
/******************END*******************/ 
/******************Validate APCODE*******************/ 
function validateApCode(apCode)
{
	if(apCode.length<=0)
		return false;
	else
		return true;
}
/******************END Validate APCODE*******************/ 
/******************Validate LOGIN ID of new user*******************/ 
function validateLogin(loginId)
{
	if(loginId.length<=0)
		return false;
	else
		return true;
}
/******************END Validate LOGIN ID of new user***************/ 

/********* Removes leading whitespaces*********/
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}
/********* END*********/
/********* Removes leading whitespaces*********/
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}
/********* END*********/

/********* Removes leading and ending whitespaces*********/
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}
/********* END*********/

/*****************on userclass change function*******************/
function chg_user_class(form)
{
	
	if(form.loggedUserType.value=="GES_ADMIN"&&form.requestFrom.value=="DIR_ADD_USR")
	{
		var strOptSelected = form.userClassKey.options[form.userClassKey.selectedIndex].value;
		if(!document.getElementById) return false; 
		if (trim(strOptSelected) == "2") 
		{

			document.getElementById("divSupplyUser").style.display = "";
			document.getElementById("divVendorAdmin").style.display = "none";
		}
		else if(trim(strOptSelected) == "3")
		{
			document.getElementById("divSupplyUser").style.display = "none";
			document.getElementById("divVendorAdmin").style.display = "";
		}
	}
}
/*****************END*******************/
/*****************On loading ADD USER page*******************/
function onloadCall(form,reloadedUsrCls)
{
		if(!document.getElementById) return false; 
		if (trim(reloadedUsrCls) == "2") 
		{
			document.getElementById("divSupplyUser").style.display = "";
			document.getElementById("divVendorAdmin").style.display = "none";
		}
		else if(trim(reloadedUsrCls) == "3")
		{
			document.getElementById("divSupplyUser").style.display = "none";
			document.getElementById("divVendorAdmin").style.display = "";
		}
}
/*****************END*******************/
function onLoadAlert(mailAlert,userExist)
{
	var alertDone=false;
	if(mailAlert=="MS")
	{
			alert("User added and invitation sent");
			alertDone=true;
	}
	if(alertDone==false&&userExist=="Y")
	{
		alertDone=true;
		retValue = window.confirm("Profile found.Proceed with user addition?");
		if(retValue==false)
		{
			document.UserForm.fromRequest.value="DIR_ADD_USR";
			document.UserForm.LF_nav_next_block.value="SELECT_ACTION";
			document.UserForm.action='dispatcher?REQUEST_TYPE=ADD_USER';
			document.UserForm.submit();
		}
	}
	if(alertDone==false&&mailAlert=="MD")
	{
		var firstName=trim(document.UserForm.firstName.value);
		var lastName=trim(document.UserForm.lastName.value);
		var userType=trim(document.UserForm.userType.value);
		if(userType=="Supply")
			alert(firstName+" "+lastName+" is already a GEXPRO user/admin with same profile");
		else if(userType=="VendorSameApCode")
			alert(firstName+" "+lastName+" is already a vendor user/admin associated with same APCODE")
		else if(userType=="VendorAnyApCode")
			alert(firstName+" "+lastName+" is already a vendor user/admin. Can not be added as GEXPRO User");
	}
}
/*************Searching a user**********/
function fnSearchUserCheck()
{
	var roleKey=trim(document.UserForm.roleKey.value);
	var login=trim(document.UserForm.loginId.value);
	var frstName=trim(document.UserForm.firstName.value);
	var lstName=trim(document.UserForm.lastName.value);
	var apCode=trim(document.UserForm.apCode.value);
	var status=true;
	if(roleKey=="3")
	{
		if(apCode=="")
		{
			alert("Please select APCode");
			status=false;
		}
	}
	if(status==true&&login==""&&frstName=="")
	{
		if(lstName==""&&apCode=="")
		{
			alert("Please enter atleast one search criteria");
			status=false;
		}
	}
	if(status==true&&login!="")
	{
		status=verifyLogin(document.UserForm);
	}
	if(status==true&&frstName!="")
	{
		status=fnCheckName(frstName);
		if(status==false)
		{
			document.UserForm.firstName.focus();
			document.UserForm.firstName.select();
		}
	}
	if(status==true&&lstName!="")
	{
		status=fnCheckName(lstName);
		if(status==false)
		{
			document.UserForm.lastName.focus();
			document.UserForm.lastName.select();
		}
	}
	if(status==true)
	{
		document.UserForm.LF_nav_next_block.value="SEARCH_USER";
		document.UserForm.action='dispatcher';
		document.UserForm.submit();
	}
}
/********************END********************/
/******************Delete users after search************/
function fnDeleteUsers(form)
{
	var names="";
	var deleteArray=new Array();
	var firstTime=true;
	var j=0;
	if(form.deletelist.length>0)
	{
		for(var i=0; i < form.deletelist.length; i++)
		{
			if(form.deletelist[i].checked)
			{
				// populate array with checked values:
				deleteArray[j] = form.deletelist[i].value;

				if(firstTime==true)
				{
					firstTime=false;
					names=names+deleteArray[j];
				}
				else
				{
					names=names+", "+deleteArray[j];
				}
				j++;
			}
		}
	}
	else
	{
		if(form.deletelist.checked)
		{
			names=names+form.deletelist.value;
		}
	}
	if(trim(names)!="")
	{
		retValue = window.confirm("Following users will be deleted: "+names+". Are you sure?");
		if(retValue)
		{
			form.LF_nav_next_block.value="DELETE_USER";
			form.action='dispatcher';
			form.submit();
		}
	}
	else
	{
	alert("Select user for deletion");
	}
}
/********************END*************************/
/*****************Modify the user****************/
function fnModifyUser(form)
{
	var frstName=trim(form.firstName.value);
	var lstName=trim(form.lastName.value);
	var phneNum=trim(form.phoneNum.value);
	var faxNum=trim(form.faxNum.value);
	var mailId=trim(form.mailId.value);
	var status=true;
	if(status==true&&fnCheckName(frstName)==false)
	{
		status=false
		form.firstName.focus();
		form.firstName.select();
	}
	if(status==true&&fnCheckName(lstName)==false)
	{
		status=false
		form.lastName.focus();
		form.lastName.select();
	}
	if(status==true&&faxNum!="")
	{	
		status=validateFaxOrFone(faxNum);
		if(status==false){
			form.faxNum.focus();
			form.faxNum.select();
		}
	}
	if(status==true&&phneNum=="")
	{
		status=false
		alert("Please enter the phone number");
		form.phoneNum.focus();
		form.phoneNum.select();
	}
	if(status==true&&phneNum!="")
	{
		status=validateFaxOrFone(phneNum);
			if(status==false){
				form.phoneNum.focus();
				form.phoneNum.select();
			}
	}
	if(status==true&&mailId=="")
	{
		status=false
		alert("Please enter the mail id");
		form.mailId.focus();
		form.mailId.select();
	}
	if(status==true&&mailId!="")
	{
		status=validateMail(mailId);
		if(status==false){
			alert("Please enter a valid email id");
			form.mailId.focus();
			form.mailId.select();
		}
	}
	if(status==true)
	{
		form.LF_nav_next_block.value="MODIFY_USER";
		form.action='dispatcher';
		form.submit();
	}
}
/************************END****************************/
function fnUpdateMe(form)
{
	var phneNum=trim(form.phoneNum.value);
	var faxNum=trim(form.faxNum.value);
	var mailId=trim(form.mailId.value);
	var loginId=trim(form.loginId.value);
	var pass=trim(form.password.value);
	var cPass=trim(form.confPassword.value);
	var status=true;
	if(status==true&&phneNum=="")
	{
		status=false
		alert("Please enter the phone number");
		form.phoneNum.focus();
		form.phoneNum.select();
	}
	if(status==true&&phneNum!="")
	{
		status=validateFaxOrFone(phneNum);
			if(status==false){
				form.phoneNum.focus();
				form.phoneNum.select();
			}
	}
	if(status==true&&faxNum!="")
	{	
		status=validateFaxOrFone(faxNum);
		if(status==false){
			form.faxNum.focus();
			form.faxNum.select();
		}
	}
	if(status==true&&mailId=="")
	{
		status=false
		alert("Please enter the mail id");
		form.mailId.focus();
		form.mailId.select();
	}
	if(status==true&&mailId!="")
	{
		status=validateMail(mailId);
		if(status==false){
			alert("Please enter a valid email id");
			form.mailId.focus();
			form.mailId.select();
		}
	}
	if(status==true&&pass!=cPass)
	{
		status=false;
		alert("Password confirmation failed");
		form.confPassword.focus();
		form.confPassword.select();
	}
	if(pass!="")
	{
		if(pass.length<8)
		{
			status=false
			alert("Password must have at least 8 character");
		}
		else if((status==true)&&(loginId==pass.substring(0,loginId.length)))
		{
			status=false;
			alert("Do not use login id as substring of password");
		}
		else if(status==true&&passCheck(pass)==false)
		{
			status=false
            		alert("Password should not have spaces and must have at least 1 special character");
			}
	}
	if(status==true)
	{
		form.LF_nav_next_block.value="EDIT_PROFILE";
		form.action='dispatcher';
		form.submit();
	}
}
/**************Password check***************/
function passCheck(pass)
{	
	var blanks=0;
	var specialChar=0;
	var iChars = "*|,\":<>[]{}`\';.()@&$#%+-_^~!&?/";
	var passValue=pass;
	for(var i=0;i<passValue.length;i++)
	{		
		var chr=passValue.charAt(i);
		if(chr==" ")
		{
			blanks=blanks+1;
		}
		if (iChars.indexOf(passValue.charAt(i)) != -1)
		{
			specialChar++;
		}
	}
	if(blanks>0||specialChar<1)
	{
		return false;
	}		
	else return true;
}
/******************************END************************/
/*******************Clear User Search criteria************/
function fnClearUser(form,userClsKey)
{
	form.loginId.value="";
	form.firstName.value="";
	form.lastName.value="";
	if(userClsKey=="1")
	{
		form.apCode.value="";
		form.compName.value="";
	}
	
}
function fnClearInv(form,userClsKey)
{
	form.invNum.value="";
	form.fromDate.value="";
	form.toDate.value="";
	if(userClsKey=="1"||userClsKey=="2")
	{
		form.apCode.value="";
		form.compName.value="";
	}
	
}
function onVendorLoad(loadCheck,isExistInDWH)
{
	if(loadCheck=="Y")
	{
		document.VendorForm.LF_nav_next_block.value="SELECT_ACTION";
		document.VendorForm.action='dispatcher?REQUEST_TYPE=ADD_USER';
		document.VendorForm.submit();
	}
	if(loadCheck=="N"&&isExistInDWH=="N")
	{
		alert("APCODE does not exist");
	}
}
function checkForListModify(isDeleted)
{
	if(isDeleted=="Y")
	{
		document.UserForm.LF_nav_next_block.value="SEARCH_USER";
		document.UserForm.action='dispatcher';
		document.UserForm.submit();
	}
}
function fnSearchInvoice()
{
	var roleKey=trim(document.InvSearchForm.roleKey.value);
	var invNum=trim(document.InvSearchForm.invNum.value);
	var frmDateText=trim(document.InvSearchForm.fromDate.value);
	var toDateText=trim(document.InvSearchForm.toDate.value);
	var payfrmDateText=trim(document.InvSearchForm.payfromDate.value);
	var paytoDateText=trim(document.InvSearchForm.paytoDate.value);
	var apCode=trim(document.InvSearchForm.apCode.value);
	var statusVal=trim(document.InvSearchForm.status.value);
	var purchaseOrder=trim(document.InvSearchForm.purchaseOrder.value);
	var voucherNum=trim(document.InvSearchForm.voucherNum.value);
	var fromDate=""
	var toDate=""
	var payfromDate=""
	var paytoDate=""
	var dateCheck=""
	var status=true;
	if(roleKey=="3"||roleKey=="4")
	{
		if(apCode=="")
		{
			alert("Please select APCode");
			status=false;
		}
	}
	if(status==true&&invNum==""&&frmDateText=="")
	{
		if(apCode==""&&purchaseOrder==""&&toDateText=="")
		{
			//18518708 - Supplier Portal Data display issue
			//Change started by AMOL BHONSLE
			//if(voucherNum==""&&statusVal=="ALL")
			// Status PAID and UNPAID also included if no search criteria is selected before Submit.
			if(voucherNum==""&&(statusVal=="ALL" || statusVal=="PAID" || statusVal=="UNPAID"))
			//Change ended by AMOL BHONSLE
			{
			  if(payfrmDateText==""&&paytoDateText=="")
			  {
				alert("Please enter atleast one search criteria");
				status=false;
			  }	
			}
		}
	}
	if(status==true&&(trim(frmDateText)!="")&&(trim(payfrmDateText)!=""))
	{
	   status=false;
	   alert("Please enter either Invoice date or Pay Date search criteria"); 
	  
	}
	
	if(trim(frmDateText)!="")
	{
		var fromDate=new Date(frmDateText);
	}
	if(trim(toDateText)!="")
	{
		var toDate=new Date(toDateText);
	}
	
	if(status==true&&toDate!="")
	{
		if(fromDate=="")
		{
			status=false;
			alert("From date is mandatory if To date is not null")
		}
		else
		{
			fromDateY=fromDate.getYear();
			
			toDateY=toDate.getYear();
			
			fromDateM=fromDate.getMonth();
		
			toDateM=toDate.getMonth();
			
			fromDateD=fromDate.getDate();
			
			toDateD=toDate.getDate();
			
			if((status==true)&&(fromDateY>toDateY))
			{
				status=false;
				alert("From date can not be greater than to date");
			}
			if((status==true)&&(fromDateY==toDateY))
			{
				if(fromDateM>toDateM)
				{
					status=false;
					alert("From date can not be greater than to date");
				}
				if((status==true)&&(fromDateM==toDateM))
				{
					if(fromDateD>toDateD)
					{
						status=false;
						alert("From date can not be greater than to date");
					}
				}
			}
		}
	}
	
	
	
	if(trim(payfrmDateText)!="")
	{
		var payfromDate=new Date(payfrmDateText);
	}
	if(trim(paytoDateText)!="")
	{
		var paytoDate=new Date(paytoDateText);
	}
	if(status==true&&paytoDate!="")
	{
		if(payfromDate=="")
		{
			status=false;
			alert("From date is mandatory if To date is not null")
		}
		else
		{
			payfromDateY=payfromDate.getYear();
			
			paytoDateY=paytoDate.getYear();
			
			payfromDateM=payfromDate.getMonth();
		
			paytoDateM=paytoDate.getMonth();
			
			payfromDateD=payfromDate.getDate();
			
			paytoDateD=paytoDate.getDate();
			
			if((status==true)&&(payfromDateY>paytoDateY))
			{
				status=false;
				alert("From date can not be greater than to date");
			}
			if((status==true)&&(payfromDateY==paytoDateY))
			{
				if(payfromDateM>paytoDateM)
				{
					status=false;
					alert("From date can not be greater than to date");
				}
				if((status==true)&&(payfromDateM==paytoDateM))
				{
					if(payfromDateD>paytoDateD)
					{
						status=false;
						alert("From date can not be greater than to date");
					}
				}
			}
		}
	}
	
	if(status==true&&(trim(payfrmDateText)!="")&&statusVal!="PAID" )
	{
	   status=false;
	   alert("Pay date criteria is only applicable for PAID status"); 
	  
	}
	
	
	if(status==true&&invNum.length>0)
	{
		if(invNum.length<3)
		{
			status=false;
			alert("Minimum 3 characters should be provided in invoice number");
			document.InvSearchForm.invNum.focus();
			document.InvSearchForm.invNum.select();
		}
		if(status==true&&checkInvoiceNum(invNum)==false)
		{
			status=false;
			alert("Invoice number can not have special character and blank");
			document.InvSearchForm.invNum.focus();
			document.InvSearchForm.invNum.select();
		}
		
	}
	if(status==true&&purchaseOrder.length>0)
	{
		if(purchaseOrder.length<3)
		{
			status=false;
			alert("Minimum 3 characters should be provided in purchase order");
			document.InvSearchForm.purchaseOrder.focus();
			document.InvSearchForm.purchaseOrder.select();
		}
		if(status==true&&checkPurchaseOrder(purchaseOrder)==false)
		{
			status=false;
			alert("Purchase order can not have special character and blank");
			document.InvSearchForm.purchaseOrder.focus();
			document.InvSearchForm.purchaseOrder.select();
		}
		
	}
	if(status==true&&voucherNum.length>0)
	{
		if(voucherNum.length<3)
		{
			status=false;
			alert("Minimum 3 characters should be provided in Voucher number");
			document.InvSearchForm.voucherNum.focus();
			document.InvSearchForm.voucherNum.select();
		}
		if(status==true&&checkvoucherNum(voucherNum)==false)
		{
			status=false;
			alert("Voucher number can not have special character and blank");
			document.InvSearchForm.voucherNum.focus();
			document.InvSearchForm.voucherNum.select();
		}
		
	}
	if(status==true)
	{
		document.InvSearchForm.LF_nav_next_block.value="SEARCH_INVOICES";
		document.InvSearchForm.action='dispatcher';
		document.InvSearchForm.submit();
	}
	
}
function checkInvoiceNum(invNum)
{
	var iChars = "*|,\":<>[]{}`\';()@&$#%+-_.^~!&?/";
	var blanks=0;
	var splcnt=0;
	for (var i = 0; i < invNum.length; i++) 
	{
		chr=invNum.charAt(i)
		if(chr==" ")
		{
			blanks=blanks+1;
		}
		if (iChars.indexOf(chr) != -1)
		{
			splcnt++;
		}
	}
	if(splcnt>0||blanks>0)
		return false;
	return true;
}

function fnMailToUser(form)
{
	var activeFlg=form.activateFlg;
	var choice;
	for (i=0;i<activeFlg.length ;i++ )
	{
		if(activeFlg[i].checked)
			choice=activeFlg[i].value;
	}
	if(choice=="N")
	{
		alert("Please activate the user before sending him mail");
	}
	else
	{
		ret=window.confirm("Login Id and password send to user ?")
			if(ret)
			{
				form.LF_nav_next_block.value="MAIL_TO_USER";
				form.action='dispatcher';
				form.submit();
			}
		
	}
}

function showChangePass()
{
	document.getElementById("divPassChange").style.display = "";
}
function hideChangePass()
{
	document.UserForm.password.value="";
	document.UserForm.confPassword.value="";
	document.getElementById("divPassChange").style.display = "none";
}
function clearInvSearch(userClassKey)
{
	document.InvSearchForm.invNum.value="";
	document.InvSearchForm.fromDate.value="";
	document.InvSearchForm.toDate.value="";
	document.InvSearchForm.payfromDate.value="";
	document.InvSearchForm.paytoDate.value="";
	document.InvSearchForm.status.value="ALL";
	document.InvSearchForm.purchaseOrder.value="";
	document.InvSearchForm.voucherNum.value="";
	if(userClassKey=="1"||userClassKey=="2")
	{
		document.InvSearchForm.apCode.value="";
		document.InvSearchForm.compName.value="";
	}
}
function clearUserSearch(userClassKey)
{
	document.UserForm.loginId.value="";
	document.UserForm.firstName.value="";
	document.UserForm.lastName.value="";
	if(userClassKey=="1")
	{
		document.UserForm.apCode.value="";
		document.UserForm.compName.value="";
	}
}
function clearLookup()
{
	document.LookUpForm.apCode.value="";
	document.LookUpForm.compName.value="";
}
/*******Load the user for modification*****/
function LoadUser(loginId,apCode)
{
	
	if(apCode.length==0)
		apCode="GEXPRO";
	document.UserForm.LF_nav_next_block.value="LOAD_MODIFY_USER";
	document.UserForm.action="dispatcher?loginApcode="+loginId+"-"+apCode;
	document.UserForm.submit();
}
/************Changing password while user logs in first time********/
function fnChangePass()
{
	var loginId=trim(document.ChangePassForm.loginId.value);
	var oldPass=trim(document.ChangePassForm.oldPass.value);
	var pass=trim(document.ChangePassForm.newPass.value);
	var cPass=trim(document.ChangePassForm.cNewPass.value);
	var status=true
	if(status==true&&pass=="")
	{
		status=false;
		alert("Please enter the password");
		document.ChangePassForm.newPass.focus();
		document.ChangePassForm.newPass.select();
	}
	if(status==true&&cPass=="")
	{
		status=false;
		alert("Please confirm the password");
		document.ChangePassForm.cNewPass.focus();
		document.ChangePassForm.cNewPass.select();
	}
	if(status==true&&(pass.length<8||cPass.length<8))
	{
		status=false;
		alert("Password must have atleast 8 character");
	}
	if(status==true&&pass!=cPass)
	{
		status=false;
		alert("Password confirmation failed");
		document.ChangePassForm.cNewPass.focus();
		document.ChangePassForm.cNewPass.select();
	}
	if((status==true)&&(oldPass==pass||oldPass==cPass))
	{
		status=false;
		alert("Please do not use previous/default password");
	}
	if((status==true)&&(loginId==pass.substring(0,loginId.length)))
	{
		status=false;
		alert("Do not use login id as substring of password");
	}
	if(status==true&&passCheck(pass)==false)
		{
			status=false
			alert("Password should not have spaces and must have at least 1 special character");
		}
	
	if(status==true)
	{
		document.ChangePassForm.LF_nav_next_block.value="CHANGE_PASSWORD";
		document.ChangePassForm.action='dispatcher';
		document.ChangePassForm.submit();
	}
}
/***********************Forgot password*******************/
function fnForgotPass()
{
	var loginId=trim(document.LoginForm.loginId.value);
	if (loginId== "")
	{	
		alert("Please Enter Login id")
		document.LoginForm.loginId.focus();
		document.LoginForm.loginId.select();
	}
	else 
	{
		loginCheck=verifyLogin(document.LoginForm);
		if(loginCheck==true)
		{
			document.LoginForm.LF_nav_next_block.value="FORGOT_PASSWORD";
			document.LoginForm.action='dispatcher';
			document.LoginForm.submit();
		}
	}
}
/******************Function to fetch vendor detail while adding(from DWH)****/
function fnFetchVendorDetail()
{
	var apCode=trim(document.VendorForm.apCode.value);
	if(apCode=="")
		alert("Please enter the apcode");
	else
	{
		document.VendorForm.LF_nav_next_block.value="FETCH_VENDOR_DETAIL";
		document.VendorForm.action="dispatcher";
		document.VendorForm.submit();
	}
}
/*****************TO Check valid voucher number*******************/
function checkvoucherNum(voucherNum)
{
	var splChars = ".*|,\":<>[]{}`\;()@$#%+_^~!?/";
	var blanks=0;
	var splcnt=0;
	for(var i=0;i<voucherNum.length;i++)
	{
		var chr=voucherNum.charAt(i);
		if(chr==" ")
		{
			blanks=blanks+1;
		}
	}
	if(blanks>0)
	{
		return false;
	}		
	for (var i = 0; i < voucherNum.length; i++) 
	{
		if (splChars.indexOf(voucherNum.charAt(i)) != -1)
		{
			splcnt++;
		}
	}
	if(splcnt>0)
	{
		return false;
	}
	else
		return true;
}
/*******************To Check valid purchase order***********/
function checkPurchaseOrder(purchaseCorder)
{
	var splChars = ".*|,\":<>[]{}`\;()@$#%+_^~!?/";
	var blanks=0;
	var splcnt=0;
	for(var i=0;i<purchaseCorder.length;i++)
	{
		var chr=purchaseCorder.charAt(i);
		if(chr==" ")
		{
			blanks=blanks+1;
		}
	}
	if(blanks>0)
	{
		return false;
	}		
	for (var i = 0; i < purchaseCorder.length; i++) 
	{
		if (splChars.indexOf(purchaseCorder.charAt(i)) != -1)
		{
			splcnt++;
		}
	}
	if(splcnt>0)
	{
		return false;
	}
	else
		return true;
}
function fnSetCompany(apcodeList,compList)
{
	var compArr=compList.split("-");
	var apCodeArr=apcodeList.split("-");
	var apCodeSelected = document.UserForm.apCode.options[document.UserForm.apCode.selectedIndex].value;
	var selectedIndex=0;
	for(var i=0;i<apCodeArr.length;i++)
	{
		if(trim(apCodeSelected)==trim(apCodeArr[i]))
		{
			selectedIndex=i;
		}
	}
	document.UserForm.compName.value=compArr[selectedIndex];
}
function validateFaxOrFone(string)
{
	var iChars_inv = "*|,\":<>[]{}'.`\';@&$#%_^~!&?/";
	var alph_inv="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
	var splcnt=0;
	var charcnt=0;
	var blanks=0;
	var status=true;
	for (var i = 0; i < string.length; i++) 
	{
		if (iChars_inv.indexOf(string.charAt(i)) != -1)
		{
			splcnt++;
		}
	}
	for (var i = 0; i < string.length; i++) 
	{
		if (alph_inv.indexOf(string.charAt(i)) != -1)
		{
			charcnt++;
		}
	}
	if(status==true&&splcnt>0)
	{
		status=false;
		alert("Phone or Fax can not have special character except +,(,),- and spaces");
		return false;
	}
	if(status==true&&string.length<10)
	{
		status=false;
		alert("Phone or Fax must have at least 10 character");
		return false;
	}
	if(status==true&&charcnt>0)
	{
		status=false;
		alert("Please do not enter characters for Phone/FAX");
		return false;
	}
	if(status=true)
	{
		return true;
	}
		
}
function replaceAll(str){
	var str = str.replace(/&apos;/g, "'");
    return str;
}
