 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] = /:/;
	
	msgstremail= "<  "+">  "+"(  "+")  "+"[  "+"]  "+"\\  "+";  "+":  ";
	
	for (i=0;i < str.length ;i++)
	{
	  if (strText.search(str[i])!= -1)
	    {
	     alert("Invalid Input:\r\nThe following characters are not allowed" + "\r\n"+msgstremail);
	     return false
	     }
	 }
	 
	 // Check SQL validation (regardless of whether it will be saved in database or not; just for consistency).
	 if (!ValidateSQLInput(strText,"Email Address"))
		return false;
	 
	 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 
    
    
}

function ValidateSQLInput(strText,Fname) 
{


	var str=new Array(23);
	
	 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[18]
	
	 
	 str[20]= /\|/; 
	 
	 str[21]=/\[/;
	 
	 str[22]=/\]/;
	 
	 msgstr= "@@  " + ">  " + "';  " +"\:  " + "\  "+ "(  " + ")  "+ "\..  " + "*  "+"<  " + "xp_  " + "%  " + "=  " + "--  " + "::  "+ "=/  "+ "0x  "+ "+  " +"?  "
	  
	  
	for (i=0;i < str.length ;i++)
	{
	 
	 
	  if (strText.search(str[i])!= -1)
	    {
	    
	     strText= "";
	     alert("Invalid Input: " + Fname + "\r\n" + "Following characters are not allowed"+ "\r\n"+ msgstr );
	     return false
	     }
	 }
	 strText= "";
	 return true
	 
	 
	
}
function ValidatePPSQLInput(strText) 
{
	var str=new Array(23);
	
	 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[18]
	
	 
	 str[20]= /\|/; 
	 
	 str[21]=/\[/;
	 
	 str[22]=/\]/;
	 
	 msgstr= "@@  " + ">  " + "';  " +"\:  " + "\  "+ "(  " + ")  "+ "\..  " + "*  "+"<  " + "xp_  " + "%  " + "=  " + "--  " + "::  "+ "=/  "+ "0x  "+ "+  " +"?  "
	  
	  
	for (i=0;i < str.length ;i++)
	{
	 
	 
	  if (strText.search(str[i])!= -1)
	    {
	    
	    // strText= "";
	     //alert("Invalid Input: " + Fname + "\r\n" + "Following characters are not allowed"+ "\r\n"+ msgstr );
	     return false
	     }
	 }
	 strText= "";
	 return true
	 
	 
	
}
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 ValidateSQLFormElements(theForm)
{
	var oElementColl = theForm.elements;
	var iCount =  oElementColl.length;
	var i;

	for (i = 0; i < iCount; i++) {
		if (oElementColl[i].type == "text") {			
			if (!(ValidateSQLInput(oElementColl[i].value," ")))	{
				oElementColl[i].focus();
				return false;
			}			
		}
	}
	return true;
}

