function ValidateEmailInput(strText) 
{
    //   '---- Email Input Fields ----
    //	'< > ( ) [ ] \ ; :

    var str= new Array(9);
    str[0] = /</;
	str[1] = />/;
	str[2] = /\(/;
	str[3] = /\)/;
    str[4] = /\[/;
    str[5] = /\]/;
    str[6] = /\\/; // escape the backslash
    str[7] = /;/;
    str[8] = /:/;
	
	for (i=0; i < str.length; i++)
	{
	    if (strText.search(str[i])!= -1)
	    {
	        return false;
	        break;
	    }
    }
    
	return true;
}

function ValidateSMTPCommand(strText) 
{
    
    //'---- SMTP commands ----
	//'HELO MAIL FROM RCPT TO DATA RSET SEND SOML SAML VRFY EXPN HELP NOOP QUIT TURN
    var str=new Array(16);
   
    
    str[0] = "HELO" ;
	 str[1] = "MAIL";
	 str[2] = "FROM";
	 str[3] = "RCPT";
	 str[4] = "TO";
	 str[5] = "DATA";
	 str[6] = "RSET";
	 str[7] = "SEND";
	 str[8] = "SOML";
	 str[9] = "SAML";
	 str[10] = "VRFY";
	 str[11] = "EXPN";
	 str[12] = "HELP";
	 str[13] = "NOOP";
	 str[14] = "QUIT";
	 str[15] = "TURN";
	
	for (i=0;i < str.length ;i++)
	{
	  if (strText.search(str[i])!= -1)
	    {
	     return false
	     }
	 }
	 return true 
    
    
}
//Declare all strings that have to be localized below
var strvsClientValidationMsg1 = "<%=Resources.Common.String17%>" + " ";
var strvsClientValidationMsg2 = "<%=Resources.Common.String14%>";
var clientValidationMsgForSpace = "<%=Resources.Common.String69%>";
//End section for declaring strings that have to be localized
function ValidateSQLInput(strText,Fname)
{
	var str=new Array(24);
	var invalid = " "; // Invalid character is a space
	
	 str[0] = "@@";
	 
	 str[1] = ">";
	 
	 str[2] = "';";
	 
	str[3] = /:\\/;
	 
    str[4] = "//";
	 
	 str[5] = /\(/;
	 
	 str[6] = /\)/;
	 
	 str[7]=/\.\./;
	 
	 str[8]=/\*/;
	 
	 str[9]="<";
	 
	 str[10]="xp_";
	 
	 str[11]="%";
	 
	 str[12]= "=";
	 
	 str[13]= "--";
	 
	 str[14]= "::";
	 
	 str[15]= "=/";
	 
	 str[16]= "0x";
	 
	 str[17]= /\+/;
	 
	 str[18]= /\?/;
	 
	 str[19] = /\$/;
	
	 
	 str[20]= /\|/; 
	 
	 str[21]=/\[/;
	 
	 str[22]=/\]/;
	 
	 str[23]=/\'/
	 
	 msgstr= "@@  " + ">  " + "';  " +":\\  " + "\  "+ "(  " + ")  "+ "\..  " + "*  "+"<  " + "xp_  " + "%  " + "=  " + "--  " + "::  "+ "=/  "+ "0x  "+ "+  " +"?  "+"| "+ "[ " +"] "+ " ' " + "$"
	  
	  
	for (i=0;i < str.length ;i++)
	{
	 
	 
	  if (strText.search(str[i])!= -1)
	    {
	    
	     strText= "";
	      alert(strvsClientValidationMsg1 + Fname + "\r\n" + strvsClientValidationMsg2 + "\r\n" + msgstr  );
	     return false
	     }
	 }


	if (Fname == 'Password') {
		
		if (strText.substring(0, 1) == " "  || (strText.substring(strText.length-1, strText.length) == " ")) {
			alert(strvsClientValidationMsg1 + Fname + "\r\n" + clientValidationMsgForSpace);
			return false;
		   }
	}

	 strText= "";
	 return true 
	
}

function ValidateUserInput(strText)
{
	var str=new Array(22);
	 str[0] = "@@";
	 str[1] = ">";
	 str[2] = "';";
     str[3] = /:\\/;
     str[4] = "//";
	 str[5] = /\(/;
	 str[6] = /\)/;
	 str[7]=/\.\./;
	 str[8]=/\*/;
	 str[9]="<";
	 str[10]="xp_";
	 str[11]="%";
	 str[12]= "=";
	 str[13]= "--";
	 str[14]= "::";
	 str[15]= "=/";
	 str[16]= "0x";
	 str[17]= /\+/;
	 str[18]= /\?/;
     str[19]= /\|/; 
	 str[20]=/\[/;
	 str[21]=/\]/;

	// msgstr= "@@  " + ">  " + "';  " +"\:  " + "\  "+ "(  " + ")  "+ "\..  " + "*  "+"<  " + "xp_  " + "%  " + "=  " + "--  " + "::  "+ "=/  "+ "0x  "+ "+  " +"?  "

	 for (i=0;i < str.length ;i++)
     {
      if (strText.search(str[i])!= -1)
     	    return false;
	 }
	return true
}

function ValidateUserInputAgainstConfigSQLInjectionChars(strText)
{
	var str=new Array();
	var configString = '<%=ConfigurationManager.AppSettings["SQLINJECTIONCHARACTERS"].ToString() %>';
	str = configString.split(' ');
	
	strText = strText.toLowerCase();
	
	 for (i=0;i < str.length ;i++)
     {
        if (strText.indexOf(str[i])!= -1)
 	        return false;
	 }
	return true;
}

function Trim(str)
{
    return str.replace(/^\s*|\s*$/g,"");
}

function truncateAllSpace(str)
{
    index = 0;
    strtemp = "";
    for (j=index; j<str.length; j++)
    {
        if (str.substr(j,1) !== ' ')
        {  
            strtemp = strtemp +  str.substr(j,1);
        }
    }
    return(strtemp);
}

function trim_spaces(strText)
{
    var retValue = strText;
    var ch = retValue.substring(0, 1);
    
    // Check for spaces at the beginning of the string
    while (ch == " ") 
    {
        retValue = retValue.substring(1, retValue.length);
        ch = retValue.substring(0, 1);
    }
   
    // Check for spaces at the end of the string
    ch = retValue.substring(retValue.length-1, retValue.length);
    while (ch == " ") 
    { 
        retValue = retValue.substring(0, retValue.length-1);
        ch = retValue.substring(retValue.length-1, retValue.length);
    }

    //removes multiple spaces from the middle.
    len = retValue.length
    for (i=0; i<len; i++)
    {
	    if (retValue.substr(i,1) == " " && retValue.substr(i+1,1) == " ")
	    {
		    retValue = retValue.substring(0,i) + retValue.substring (i+1,len);
		    i=0;
	    }
        len=retValue.length;
    }
    
    return retValue;
}

function ValidateEmailAddress(emailAddress)
{
    // Commenting out these 2 lines since this works only for EN and EN based languages. Fix for 463171 - Unable to enter russian characters
    
    //var EmailReg = new RegExp("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$"); 
    //return EmailReg.test(emailAddress);
    
    var atSymbol = "@";
	var dotSymbol = ".";
	var atSymbolLocation = emailAddress.indexOf(atSymbol);
	var emailLength = emailAddress.length;
		
	if (emailAddress.indexOf(atSymbol) == -1)
	    return false;
	
	if (emailAddress.indexOf(atSymbol) == -1 || emailAddress.indexOf(atSymbol)== 0 || emailAddress.indexOf(atSymbol) == emailLength)
	    return false;
	
	if (emailAddress.indexOf(dotSymbol) == -1 || emailAddress.indexOf(dotSymbol) == 0 || emailAddress.indexOf(dotSymbol) == emailLength)
	    return false;
	
	if (emailAddress.indexOf(atSymbol,(atSymbolLocation + 1)) != -1)
	    return false;

	 if (emailAddress.substring(atSymbolLocation -1, atSymbolLocation) == dotSymbol || emailAddress.substring(atSymbolLocation + 1, atSymbolLocation + 2) == dotSymbol)
	    return false;
	 
	 if (emailAddress.indexOf(dotSymbol,(atSymbolLocation + 2)) == -1)
	    return false;
	 	
	 if (emailAddress.indexOf(" ") != -1)
	    return false;
	 
	 return true;
}

function ValidateZIPCode(zipPattern,zipCode)
{
    var ZipReg = new RegExp(zipPattern); 
 	return ZipReg.test(zipCode);
}
