function profileEdit() //Validations for Edit profile
{
	
	//quickbooks integration starts here
	if (document.frmRegister.txtCustomerName.value=="")
	{
		alert("You have missed a mandatory field, please a enter a value in the Company Name field.");
		document.frmRegister.txtCustomerName.focus();
		return false;
	}
	//quickbooks integration ends here

	if (document.frmRegister.txtname.value=="")
	{
		alert("You have missed a mandatory field, please a enter a value in the First Name field.");
		document.frmRegister.txtname.focus();
		return false;
	}
	
	if (document.frmRegister.txtlname.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the Last Name field.");
		document.frmRegister.txtlname.focus();
		return false;
	}
	/*if (document.frmRegister.txtCname.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the Company Name field.");
		document.frmRegister.txtCname.focus();
		return false;
	}*/
	if (document.frmRegister.txtphone.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the Phone Number field.");
		document.frmRegister.txtphone.focus();
		return false;
	}
	if (document.frmRegister.txtadd.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the Address field.");
		document.frmRegister.txtadd.focus();
		return false;
	}
	if (document.frmRegister.txtcity.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the City field.");
		document.frmRegister.txtcity.focus();
		return false;
	}
	
	
	/*if (document.frmRegister.txtstate.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the State field.");
		document.frmRegister.txtstate.focus();
		return false;
	}*/
	
	
	if (document.frmRegister.txtzip.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the Zip field.");
		document.frmRegister.txtzip.focus();
		return false;
	}
	if (document.frmRegister.txtcountry.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the Country field.");
		document.frmRegister.txtcountry.focus();
		return false;
	}

	if (document.getElementById("txtcountry").value == "United States" && document.frmRegister.BillState.value=="")
	{
		alert("You have missed a mandatory field, please select a value in State field");
		return false;
	}
	
	str1 =	document.frmRegister.txtasi.value;

	str2 =	document.frmRegister.txtupic.value;
	str3 =	document.frmRegister.txtppac.value;
	str4 =	document.frmRegister.txtsage.value;

	if(str1=="" && str2=="" && str3=="" && str4 == "")
	{
		alert("Please enter valid ASI# / UPIC# / PPAI# / SAGE# .");
		document.frmRegister.txtasi.focus();
		return false;
	}

	// ------------- Code Start to prevent hacking --------------------
	if(isValidCode(document.frmRegister,"txtasi","ASI#")==false) return false;
	if(isValidCode(document.frmRegister,"txtupic","UPIC#")==false) return false;
	if(isValidCode(document.frmRegister,"txtppac","PPAC#")==false) return false;
	if(isValidCode(document.frmRegister,"txtsage","SAGE#")==false) return false;
	// ------------- Code End to prevent hacking --------------------
	
	// ------------- Code Start to for user to enter as much as he has --------------------	
	/*

	if (document.frmRegister.txtasi.value!="")
	{
		
		if (isNaN(document.frmRegister.txtasi.value))
		{
			alert("Please enter only numeric value in the ASI# field.")
			document.frmRegister.txtasi.focus();
			return false;
		}
		
	}
	if (document.frmRegister.txtppac.value!="")
	{
		if (isNaN(document.frmRegister.txtppac.value))
		{
			alert("Please enter only numeric value in the PPAI# field.")
			document.frmRegister.txtppac.focus();
			return false;
		}
		
	}
	if (document.frmRegister.txtupic.value!="")
	{
			var upassID=eval("document.frmRegister.txtupic")
			var upass_string = upassID.value;
			var sizechar=upass_string.length;
			 var valid="1234567890-abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

			for (var i=0; i<sizechar; i++)
			{
				if (valid.indexOf(upass_string.charAt(i)) < 0) 
				{
					alert('Your UPIC# contains invalid characters.');
					upassID.focus();
					return false;
				}
			}
	}
	
	c=0
	if ((document.frmRegister.txtasi.value!="") && (document.frmRegister.txtupic.value!=""))
	{
		c=1	
	}
	else
	if ((document.frmRegister.txtasi.value!="") && (document.frmRegister.txtppac.value!=""))
	{
		c=1
	}
	else 
	if ((document.frmRegister.txtppac.value!="") && (document.frmRegister.txtupic.value!=""))
	{
		c=1		
	}

	if (c==1)
	{
		alert("Enter Only one number, Either ASI# or UPIC# or PPAI# number.");
		document.frmRegister.txtasi.value=""
		document.frmRegister.txtupic.value=""
		document.frmRegister.txtppac.value=""
		document.frmRegister.txtasi.focus();

		return false;
	}*/

	else
	return true;	
	
}

	
function charchk() 
{
	event.keyCode=DisallowNum(event.keyCode)
}
function DisallowNum(keyPressed)
{
	if (keyPressed>=97 && keyPressed<=122 || keyPressed>=65 && keyPressed<=90 || keyPressed==32 || keyPressed==46)
	{
	}
	else
	{
		keyPressed = 0
	}
		return keyPressed	
}

function citycharchk() 
{
	event.keyCode=DisallowCity(event.keyCode)	
}
function DisallowCity(keyPressed)
{
	if (keyPressed>=97 && keyPressed<=122 || keyPressed>=65 && keyPressed<=90 || keyPressed==32 || keyPressed==45)
	{
	}
	else
	{
		keyPressed = 0
	}
		return keyPressed	
}

function zipnumchk() 
{
	event.keyCode=ZipDisallowChar(event.keyCode)	
}
function ZipDisallowChar(keyPressed)
{
	if (keyPressed>=48 && keyPressed<=57)
	{
	}
	else
	{
		keyPressed = 0
	}
		return keyPressed	
}

function telnumchk() 
{
	event.keyCode=TelDisallowChar(event.keyCode)	
}
function TelDisallowChar(keyPressed)
{
	if (keyPressed>=48 && keyPressed<=57 || keyPressed>=65 && keyPressed<=90 || keyPressed>=97 && keyPressed<=122 || keyPressed==32 || keyPressed==45)
	{
	}
	else
	{
		keyPressed = 0
	}
		return keyPressed	
}
function faxnumchk() 
{
	event.keyCode=FaxDisallowChar(event.keyCode)	
}
function FaxDisallowChar(keyPressed)
{
	if (keyPressed>=48 && keyPressed<=57 || keyPressed==32 || keyPressed==45)
	{
	}
	else
	{
		keyPressed = 0
	}
		return keyPressed	
}

function clientRegister() //Validations for Registration
{
	
	var strLogId = document.frmRegister.txtLoginid.value.indexOf("@") ;
	if (document.frmRegister.txtLoginid.value.substring(0,strLogId)=="guest")
	{
		alert("This Email Id has already been registered, please register using a different Email Id.");
		document.frmRegister.txtLoginid.select();
		return false;
	}

		if (document.frmRegister.txtLoginid.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the Email Id field.");
		document.frmRegister.txtLoginid.select();
		return false;
	}	
	
	if (document.frmRegister.txtLoginid.value.indexOf("@") == -1 || document.frmRegister.txtLoginid.value.indexOf(".") == -1 || ! isEmail(document.frmRegister.txtLoginid.value))
	{
		alert("Invalid Email Id, Please include a proper Email Address as your Email Id.");
		document.frmRegister.txtLoginid.select();
		return false;
	}
	//quickbooks integration starts here
	if (document.frmRegister.txtCustomerName.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the Company Name field.");
		document.frmRegister.txtCustomerName.focus();
		return false;
	}
	//quickbooks integration ends here
	if (document.frmRegister.txtPassword.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the Password field.");
		document.frmRegister.txtPassword.focus();
		return false;
	}
	
	if(isValidCode(document.frmRegister,"txtPassword","Password")==false) return false;	
	

	if (document.frmRegister.txtPassword.value.length < 5)
	{
		alert("Password cannot be less than 5 characters.");
		document.frmRegister.txtPassword.focus();
		return false;
	}
	if (document.frmRegister.txtRePassword.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the Confirm Password field.");
		document.frmRegister.txtRePassword.focus();
		return false;
	}
	
	if (document.frmRegister.txtPassword.value!=document.frmRegister.txtRePassword.value)
	{
		alert("The passwords are not matching, please enter the passwords again.");
		document.frmRegister.txtRePassword.focus();
		return false;
	}
	
	
	if (document.frmRegister.txtname.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the First Name field.");
		document.frmRegister.txtname.focus();
		return false;
	}
	/*if (document.frmRegister.txtmname.value=="")
	{
		alert("Middle Name can not be empty!!!");
		document.frmRegister.txtmname.focus();
		return false;
	}
*/
	if (document.frmRegister.txtlname.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the Last Name field.");
		document.frmRegister.txtlname.focus();
		return false;
	}
	/*if (document.frmRegister.txtCname.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the Company Name field.");
		document.frmRegister.txtCname.focus();
		return false;
	}*/
	if (document.frmRegister.txtphone.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in Phone number field");
		document.frmRegister.txtphone.focus();
		return false;
	}
	if (document.frmRegister.txtadd.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in Address field");
		document.frmRegister.txtadd.focus();
		return false;
	}
	if (document.frmRegister.txtcity.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in City field");
		document.frmRegister.txtcity.focus();
		return false;
	}
	

	if (document.getElementById("BillCountry").value =="United States" && document.frmRegister.BillState.value=="")
	{
		alert("You have missed a mandatory field, please select a value in State field");
		return false;
	}

	if (document.frmRegister.txtzip.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in Zip Code field");
		document.frmRegister.txtzip.focus();
		return false;
	}
	/*if (document.frmRegister.txtcountry.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in Country field");
		document.frmRegister.txtcountry.focus();
		return false;
	}*/
	
	else
		return true;
}

function isEmail(strEMail) //validations for email
{
	var strInvalidChars,blnTemp,i,strTemp,intdot,IsMail,strEMailRev,intAtTheRate;
    intdot = strEMail.lastIndexOf(".");
	if (intdot == -1 )
		return false;
    
	intdot=strEMail.length-intdot-1;
	if (intdot < 2 )
		return false;
    
    // Disallowed characters
    strInvalidChars = "!#$%^&*()=+{}[]|\;:'/?>,< ";

	intAtTheRate = strEMail.indexOf("@") ;

    // Check that there is at least one '@' and a character before @
    if (intAtTheRate < 1)
		blnTemp=true;
	else
		blnTemp=false;

    if (blnTemp)
		return !blnTemp;
	
	// Check that there is at least one '.' in the form a@a.com
    /*Below code changed by sagar < 3 replace with < 1*/
    blnTemp = (strEMail.indexOf(".") < 1);
   if (blnTemp)
		return !blnTemp;
	
	//   Check that there is at least one char between '.' and @ after @
	intdot= strEMail.indexOf(intAtTheRate+1,".");
	blnTemp = (intdot==2);
     if (blnTemp)
		return !blnTemp;

	//   Check that there is at least one char between '.' and @ before @
    blnTemp = (strEMail.substring(intAtTheRate - 1, intAtTheRate) == ".");
    if (blnTemp)
		return !blnTemp;

	//  and that the length is at least six (a@a.co)
    blnTemp = (strEMail.length < 6);
   if (blnTemp) 
		return !blnTemp;
	//  Check that there is only one '@'
    blnTemp = (intAtTheRate != strEMail.lastIndexOf("@"));
    
   if (blnTemp)
	return !blnTemp;
   //    extra checks
  //     AFTER '@' space is not allowed
	strTemp=strEMail.substring(intAtTheRate+1);
	blnTemp = (strTemp.indexOf(" ") > 0);
   if (blnTemp) 
		return !blnTemp;

  //   Check that there is one dot AFTER '@'
    blnTemp = (strTemp.indexOf(".") == 0);
   if (blnTemp)
		return !blnTemp;

   /*Below code added by sagar to check one dot after @ starts here*/
  //   Check that there is one dot AFTER '@'
   if (strTemp.indexOf(".") == -1)
		return false;
   /*Below code added by sagar to check one dot after @ ends here*/
   
	//    Check if there's a quote (")
    blnTemp = strEMail.indexOf("\"") > 0;
     if (blnTemp )
		return !blnTemp;
    
	//     Check if there's any other disallowed chars
	//     optimize a little if strEMail longer than strInvalidChars
	//     check the other way around
    if (strEMail.length > strInvalidChars.length)
	{
        for(var i = 0; i< strInvalidChars.length;i++)
		{
            if (strEMail.indexOf(strInvalidChars.substring(i,i+1)) > 0 )
                  blnTemp = true;
            if (blnTemp )
				break;
        } //end for
    } //end if
	else
	{
        for(var i = 0 ;i< strEMail.length;i++)
		{
            if (strInvalidChars.indexOf(strEMail.substring(i,i+1)) > 0) 
                  blnTemp = true;
            if (blnTemp )
				break;
        } //end for
    } //end else
    if (blnTemp)
		return !blnTemp;
    
	//     extra check
	 //    no two consecutive dots
    blnTemp = strEMail.indexOf("..") > 0;
    if (blnTemp)
		return !blnTemp;
    
	//    if any of the above are true, invalid e-mail
    return !blnTemp;

}



function clientLogin(reffile)
{
	if (document.forms[0].txtLoginid.value=="")
	{
		alert("You have missed an Email Address field, please enter a value in the Email Address field.");
		document.forms[0].txtLoginid.focus();
		return false;
	}
	if (document.forms[0].txtPassword.value=="")
	{
		alert("You have missed a Password field, please enter a value in the Password field..");
		document.forms[0].txtPassword.focus();
		return false;
	}
	else
		document.forms[0].method = "post";
		document.forms[0].action = "ClientCheckLogin.asp?submit=yes&Filename="+reffile;
		document.forms[0].submit();
}

function clientForgotPassword()
{
	if (document.frmClientLogin.txtLoginid.value=="")
	{
		alert("You have missed an Email Address field, please enter a value in the Email Address field.");
		document.frmClientLogin.txtLoginid.focus();
		//return false;
	}
	else if (document.frmClientLogin.txtLoginid.value.indexOf("@") == -1 || document.frmClientLogin.txtLoginid.value.indexOf(".") == -1 || ! isEmail(document.frmClientLogin.txtLoginid.value))
	{
		alert("Invalid Email Address, Please include a proper Email Address.");
		document.frmClientLogin.txtLoginid.select();
		//return false;
	}
	else
	{
		document.frmClientLogin.method = "post";
		document.frmClientLogin.action = "ClientForgotPwd.asp";
		document.frmClientLogin.submit();
	}
}

function clientLoginpage1(reffile,cartdet)
{

	if (document.forms[0].txtLoginid.value=="")
	{
		alert("Please enter the login id !!!");
		document.forms[0].txtLoginid.focus();
		return;
	}
	if (document.forms[0].txtLoginid.value.indexOf("@") == -1 || document.forms[0].txtLoginid.value.indexOf(".") == -1 || ! isEmail(document.forms[0].txtLoginid.value))
	{
		alert("Invalid Login Id, Please include a proper Email Address as your login Id.");
		document.forms[0].txtLoginid.select();
		return;
	}
	if (document.forms[0].txtPassword.value=="")
	{
		alert("Please enter the password !!!");
		document.forms[0].txtPassword.focus();
		return ;
	}
	else
	{
		var flname=cartdet;
		var flname2=""
		if (flname!="")
		{
			var flname1=""
			flname1=flname.substring(0,1);
			if(flname1=="G")
			{
				flname2=reffile+"?filename="+flname;
			}
			else
			{				
				flname1=flname.substring(0,4);
				if (flname1=="logo")
				{
					flname2=reffile+"?filename="+flname;
				}
				else
				{
					if (flname1=="prod")
					{
						flname2=reffile+"?filename="+flname;
					}
					else
					{
						flname2=reffile;
					}
				}
			}
		}

		if (flname2 !="")
		{
			document.forms[0].action = "ClientCheckLogin.asp?submit=yes&Filename="+flname2;
		}
		else
		{
			document.forms[0].action = "ClientCheckLogin.asp?submit=yes&Filename="+reffile;
		}
		document.forms[0].method = "post";
	//	alert(document.forms[0].action);
		document.forms[0].submit();
	}
}

function clientLoginpage(reffile)
{
	if (document.frmClientLogin.txtLoginid.value=="")
	{
		alert("Please enter the login id !!!");
		document.frmClientLogin.txtLoginid.focus();
		return false;
	}
	if (document.frmClientLogin.txtLoginid.value.indexOf("@") == -1 || document.frmClientLogin.txtLoginid.value.indexOf(".") == -1 || ! isEmail(document.frmClientLogin.txtLoginid.value))
	{
		alert("Invalid Login Id, Please include a proper Email Address as your login Id.");
		document.frmClientLogin.txtLoginid.select();
		return false;
	}
	if (document.frmClientLogin.txtPassword.value=="")
	{
		alert("Please enter the password !!!");
		document.frmClientLogin.txtPassword.focus();
		return false;
	}
	else
		document.frmClientLogin.method = "post";
		document.frmClientLogin.action = "ClientCheckLogin.asp?submit=yes&Filename="+reffile;
		document.frmClientLogin.submit();
}

function clientChangePassword() //Validations for Change Password
{
	
	if (document.frmChangePassword.txtOldPassword.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the Old Password field.");
		document.frmChangePassword.txtOldPassword.focus();
		return false;
	}
	if (document.frmChangePassword.txtOldPassword.value.length < 5)
	{
		alert("The password cannot be less than 5 characters.");
		document.frmChangePassword.txtOldPassword.focus();
		return false;
	}
	if (document.frmChangePassword.txtNewPassword.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the New Password field.");
		document.frmChangePassword.txtNewPassword.focus();
		return false;
	}
	if (document.frmChangePassword.txtNewPassword.value.length < 5)
	{
		alert("The password cannot be less than 5 characters.");
		document.frmChangePassword.txtNewPassword.focus();
		return false;
	}
	if (document.frmChangePassword.txtRePassword.value=="")
	{
		alert("You have missed a mandatory field, please enter a value in the Confirm Password field.");
		document.frmChangePassword.txtRePassword.focus();
		return false;
	}
	if (document.frmChangePassword.txtNewPassword.value!=document.frmChangePassword.txtRePassword.value)
	{
		alert("The passwords are not matching, please enter the passwords again.");
		document.frmChangePassword.txtRePassword.focus();
		return false;
	}
	else
		return true;
}

function chkasilogin(val,cartdet)
{
/*	//alert(cartdet);
	//var ecode=event.keyCode
	//alert(event.keyCode);
	//if (event.keyCode==13)
	//{
		while(''+document.frmLBMenu.asilogin.value.charAt(0)==' ')
		document.frmLBMenu.asilogin.value=document.frmLBMenu.asilogin.value.substring(1,document.frmLBMenu.asilogin.value.length);
		if(document.frmLBMenu.asilogin.value=="")
		{
				alert("Please Enter ASI Number");
				document.frmLBMenu.asilogin.focus();
		}
		else
		{
			var flname=cartdet;
		var flname2=""
		if (flname!="")
		{
			var flname1=""
			flname1=flname.substring(0,1);
			if(flname1=="G")
			{
				flname2=val+"?filename="+flname;
			}
			else
			{				
				flname1=flname.substring(0,4);
				if (flname1=="logo")
				{
					flname2=val+"?filename="+flname;
				}
				else
				{
					if (flname1=="prod")
					{
						flname2=val+"?filename="+flname;
					}
					else
					{
						flname2=reffile;
					}
				}
			}
		}
		if (flname2 !="")
		{
			document.forms[0].action = "ClientCheckLogin.asp?submit=yes&Filename="+flname2;
		}
		else
		{
			document.forms[0].action = "ClientCheckLogin.asp?submit=yes&Filename="+val;
		}
//		alert(document.forms[0].action);

		//	document.frmLBMenu.action="ClientcheckLogin.asp?submit=yes&Filename="+val; 
			document.frmLBMenu.submit();
		}
	//}*/
}

function chkasilogin1(val)
{
	//alert(event.keyCode);
	//if (event.keyCode==13)
	//{
/*		while(''+document.frmLBMenu1.asilogin.value.charAt(0)==' ')
		document.frmLBMenu1.asilogin.value=document.frmLBMenu1.asilogin.value.substring(1,document.frmLBMenu1.asilogin.value.length);
		if(document.frmLBMenu1.asilogin.value=="")
		{
				alert("Please Enter ASI Number");
				document.frmLBMenu1.asilogin.focus();
				return;
		}
		else
		{
			document.frmLBMenu1.action="ClientcheckLogin.asp?submit=yes&Filename="+val; 
			document.frmLBMenu1.method="post";
			document.frmLBMenu1.submit();
		}
	//}*/
}
