/*
 1. Check, If empty 			        --								--	isFilled
 2. Check, If Name 					    --								--	isName
 3. Trim Leading and Trailling blank    --								--	trim
 4. Check, If Price						--								--	isPrice
 5. Check, If Number					--								--	isNumber
 6. Check, If the string is having numbers at the first five digits		--	isAccountNo 
 7. Check, If the City is valid         --								--  isCity 
 8. Check, If the string is Zipcode     --								--  isZip
 9. Check, If the string is Contact #   --								--  isContactNo
*/

//_______________________________________________________________________________________________________________________

// 1. Check, If empty -- Generic function for any page 

function isFilled(pToolName,pMessage)
   {
    var s;        
    s = trim(pToolName);
    if ( (s == null) || (s.length == 0)  )
       {
        alert(pMessage);
        eval("document." + frmName + "." + pToolName + ".focus()"); 
        return false;
       }
    else 
       {
        return true;       
       }              
   } // function isFilled(pToolName,pMessage)

//_______________________________________________________________________________________________________________________

// 2. Check, If Name -- Generic function for any page 
   
function isName(pToolName,pMessage)
   {    
   // var strAlpha='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .';
   // 65..90,97..122,46 and 32 
   // func Summary: Check, If the string is valid name
   var strInput, errCounter;
   if ( isFilled(pToolName,pMessage) == true )
      {
       strInput = eval("document." + frmName + "." + pToolName + ".value");
       errCounter = 'No';
       for (i=0;i<=strInput.length-1;i++)
           {
           if ( (strInput.charCodeAt(i)==32) || (strInput.charCodeAt(i)==46) || (strInput.charCodeAt(i)>=65 &&                            strInput.charCodeAt(i)<=90) || (strInput.charCodeAt(i)>=97 && strInput.charCodeAt(i)<=122)  )
              { null; }
           else
              {        
               errCounter = 'Yes';          
               break;          
              } // if ( (strInput.charCodeAt(i)==32)  
           } // for (i=0;i<=strInput.length;i++)       
       if ( errCounter == 'Yes' )
          {
           alert(pMessage);
           eval("document." + frmName + "." + pToolName + ".value = ''");		   
           eval("document." + frmName + "." + pToolName + ".focus()");                               
           return (false);
          }
       else
          {
           return (true);
          } // if (errCounter = 'Yes' )             
      }
   else
      {
       return (false);    
      }
   } // function isName(pToolName,pMessage)

//_______________________________________________________________________________________________________________________

// 3. Trim Leading and Trailling blank

function trim(pToolName)
   {
    var strInput, intWordLen;
    strInput = eval("document." + frmName + "." + pToolName + ".value");
    intWordLen = strInput.length-1;
    
    while ( strInput.charCodeAt(0) == 32 )
          {
           eval("document." + frmName + "." + pToolName + ".value ='" + strInput.substr(1,strInput.length) +"'"); 
           strInput = eval("document." + frmName + "." + pToolName + ".value");    
          } // while ( strInput.charCodeAt(0) == 32 )
          
    while ( strInput.charCodeAt(strInput.length-1) == 32 )
          {
           eval("document." + frmName + "." + pToolName + ".value ='" + strInput.substr(0,strInput.length-1) +"'");    
           strInput = eval("document." + frmName + "." + pToolName + ".value");
          } // while ( strInput.charCodeAt(strInput.length-1) == 32 )
    return eval("document." + frmName + "." + pToolName + ".value");
   } // function trim(pToolName)
   
//_______________________________________________________________________________________________________________________

// 4. Check, If Price -- Generic function for any page  

function isPrice(pToolName,pMessage)
   {
   // 0123456789 --> 48..57 . --> 46 Check the validity of Price
   var strInput, errCounter, cLIntDotCnt;
   if ( isFilled(pToolName,pMessage) == true )
      {
       strInput    = eval("document." + frmName + "." + pToolName + ".value");
       errCounter  = 'No';
       cLIntDotCnt = 0;
       if ( strInput <= 0 )
          {
           errCounter = 'Yes';           
          }
       else 
          {
           for (i=0;i<=strInput.length-1;i++)
               {                 
                if ( (strInput.charCodeAt(i)>=48 && strInput.charCodeAt(i)<=57) || (strInput.charCodeAt(i)==46) )
                   {          
                    if ( strInput.charCodeAt(i)==46 )
                       {          
                        cLIntDotCnt = cLIntDotCnt + 1; 
                        if ( cLIntDotCnt > 1 )
                           {
                            errCounter = 'Yes'; 
                            break;
                           }
                        else
                           { null; } // if ( cLIntDotCnt > 1 )  
                       }
                   }
                else
                   {        
                    errCounter = 'Yes';          
                    break;          
                   } // if ( (strInput.charCodeAt(i)>=48 && strInput.charCodeAt(i)<=57) ||  
               } // for (i=0;i<=strInput.length;i++) 
          }           
       if ( errCounter == 'Yes' )
          {
		   alert(pMessage);
           eval("document." + frmName + "." + pToolName + ".value = ''");		   
           eval("document." + frmName + "." + pToolName + ".focus()");                      
           return (false);
          }
       else
          {
           return (true);
          } // if (errCounter = 'Yes' )   
      }
   else
      {
       return (false);    
      }                  
   } // function isPrice(pToolName,pMessage)
//_______________________________________________________________________________________________________________________

// 5. Check, If Number -- Generic function for any page  

function isNumber(pToolName,pMessage)
   {
   // 0123456789 --> 48..57   true - If input is #; false - If input is String - Check the validity of number
   var strInput, errCounter;
   if ( isFilled(pToolName,pMessage) == true )
      { 
       strInput = eval("document." + frmName + "." + pToolName + ".value");
       errCounter = 'No';
       if ( strInput <= 0 )
          {
           errCounter = 'Yes';           
          }
       else 
          {  
           for (i=0;i<=strInput.length-1;i++)
               {
                if ( (strInput.charCodeAt(i)>=48 && strInput.charCodeAt(i)<=57)  )
                   { null; }
                else
                   {        
                    errCounter = 'Yes';          
                    break;          
                   } // if ( (strInput.charCodeAt(i)==32)  
               } // for (i=0;i<=strInput.length;i++)  
          } // if ( strInput <= 0 )   
                    
       if ( errCounter == 'Yes' )
          {
		   alert(pMessage);
           eval("document." + frmName + "." + pToolName + ".value = ''");		   
           eval("document." + frmName + "." + pToolName + ".focus()");                      
           return (false);
          }
       else
          {
           return (true);
          } // if (errCounter = 'Yes' )  
      } 
   else
      {
       return (false);    
      } // if ( isFilled(pToolName,pMessage) == true )                 
                  
   } // function isNumber(strInput)
//_______________________________________________________________________________________________________________________

// 6. Check, If the string is having numbers at the first five digits -- Generic function for any page 

function isAccountNo(pToolName,pMessage)
   {
   // var strAlpha='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -0123456789';
   // 65..90,97..122 and 32 
   var strInput, errCounter;
   strInput = trim(pToolName);
   errCounter = 'No';
   for (i=0;i<5;i++)
       {
       if ((strInput.charCodeAt(i)>=48) && (strInput.charCodeAt(i)<=57)  )
          { null; }
       else
          {        
          errCounter = 'Yes';          
          break;          
          } // if ( (strInput.charCodeAt(i)==32)  
       } // for (i=0;i<=strInput.length;i++)       
      if ( errCounter == 'Yes' )
         {
		  alert(pMessage);
          eval("document." + frmName + "." + pToolName + ".value = ''");		   
          eval("document." + frmName + "." + pToolName + ".focus()");                               
          return (false);
         }
      else
        {
         return (true);
        } // if (errCounter = 'Yes' )             
   } // function isAccountNo(pToolName,pMessage)
//_______________________________________________________________________________________________________________________

// 7. Check, If the City is valid -- Generic function for any page 

function isCity(pToolName,pMessage)
   {
    // var strAlpha='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz .';
    // 65..90,97..122 and 32    
    var strInput, errCounter;
    strInput = trim(pToolName);
    errCounter = 'No';
    for (i=0;i<=strInput.length-1;i++)
        {
         if ( (strInput.charCodeAt(i)==32) || (strInput.charCodeAt(i)==46) || (strInput.charCodeAt(i)>=65 && strInput.charCodeAt(i)<=90) || (strInput.charCodeAt(i)>=97 && strInput.charCodeAt(i)<=122)  )
            { null; }
         else
            {        
             errCounter = 'Yes';          
             break;          
            } // if ( (strInput.charCodeAt(i)==32)  
        } // for (i=0;i<=strInput.length;i++)       
   if ( errCounter == 'Yes' )
      {
	   alert(pMessage);
       eval("document." + frmName + "." + pToolName + ".value = ''");		   
       eval("document." + frmName + "." + pToolName + ".focus()");                                        
       return false;
      }
   else 
      { 
       return true;
      } // if (errCounter = 'Yes' )             
   } // function isCity(pToolName,pMessage)
//_______________________________________________________________________________________________________________________

// 8. Check, If the string is Zipcode -- Generic function for any page 

function isZip(pToolName,pMessage)
   {
    // var strAlpha='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -0123456789';
    // 65..90,97..122 and 32 Summary: Check, If the string is valid Zipcode
    var strInput, errCounter;
    strInput = trim(pToolName);
    errCounter = 'No';
    for (i=0;i<=strInput.length-1;i++)
        {
         if ( (strInput.charCodeAt(i)==32) || (strInput.charCodeAt(i)==45) || (strInput.charCodeAt(i)>=48 && strInput.charCodeAt(i)<=57)  )
            { null; }
         else
            {        
             errCounter = 'Yes';          
             break;          
            } // if ( (strInput.charCodeAt(i)==32)  
        } // for (i=0;i<=strInput.length;i++)       
    if ( errCounter == 'Yes' )
       {
	    alert(pMessage);
        eval("document." + frmName + "." + pToolName + ".value = ''");		   
        eval("document." + frmName + "." + pToolName + ".focus()");                               
        return (false);
       }
    else
       { return (true); } // if (errCounter = 'Yes' )             
   } // function isZip(pToolName,pMessage)
//_______________________________________________________________________________________________________________________

// 9. Check, If the string is Contact # -- Generic function for any page

function isContactNo(pToolName,pMessage)
   {   
   // 40 - ( | 41 - ) | 45 - Hiphen | 48..57 Numbers Summary: Check, If the string is valid Contact #
   var strInput, errCounter;
   strInput = trim(pToolName);   
   errCounter = 'No';
   for (i=0;i<=strInput.length-1;i++)
       {
       if ( (strInput.charCodeAt(i)==40) || (strInput.charCodeAt(i)==41) || (strInput.charCodeAt(i)==45) || (strInput.charCodeAt(i)>=48 && strInput.charCodeAt(i)<=57)  )
          { null; }
       else
          {        
          errCounter = 'Yes';          
          break;          
          } // if ( (strInput.charCodeAt(i)==32)  
       } // for (i=0;i<=strInput.length;i++)       
      if ( errCounter == 'Yes' )
         {
		  alert(pMessage);
          eval("document." + frmName + "." + pToolName + ".value = ''");		   
          eval("document." + frmName + "." + pToolName + ".focus()");                      
          return (false);
         }
      else
        { return (true); } // if (errCounter = 'Yes' )             
   } // function isContactNo(pToolName,pMessage)      
//_______________________________________________________________________________________________________________________
   