
 //==========================================================================

// Declare patterns for different Regular Expression

var PatternsDict = new Object()

//year enterpattern is example : 2002-2003

//PatternsDict.YeartoYear = "^(\d{8}|(\d{4}-\d{4}))?$"

// mathes telephone no.
PatternsDict.telpat  = "^(\d{10}|(\d{3}-\d{3}-\d{4}))?$"

// matches numeric
PatternsDict.numericpat  = "^\d*$" // Any number is allowed, but are optional

// matches character
 PatternsDict.charpat = "^\D*$"

// matches white space
PatternsDict.whitespacepat = "/\s+/"

// matches zip code
PatternsDict.zippat = "^(\d{5}|\d{9}|(\d{5}-\d{4}))?$"

PatternsDict.YeartoYear = "^(\d{1,4}\-\d{1,4})?$"

// matches IP address
PatternsDict.IPpat = "^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})?$"

// matches hex number
PatternsDict.hexpat = "^([a-fA-F0-9]+)?$"

// matches any alphanumeric character,hyphen(-) or an underscore(_)
// including white space
PatternsDict.validpat = "^[a-zA-Z0-9-_]+$"

// matches required field
PatternsDict.requiredpat = "^((/\s+)|'')?$"

// matches character
 PatternsDict.charpat = "^\D*$"

// mathes email
PatternsDict.emailpat = "^[\\w-_\.]*[\\w-_\.]\@{1}[\\w]\.+[\\w]+[\\w]$"

// matches any alphanumeric character,hyphen(-) or an underscore(_)
// including white space
PatternsDict.validpatc = "^[a-zA-Z0-9-_ ]+$"

// matches any alphanumeric character,hyphen(-) or an underscore(_)
// including white space
PatternsDict.validpatcnos = "^[a-zA-Z0-9-_\s]*$"

//numeric with decimal
//PatternsDict.numericpat1234

//PatternsDict.numericpat1234  =  "^\d*$"

// End of pattern declaration
//=================================================================================

//check for validyeartoyear entry

function isYeartoYearvalid(str1,msg)
{
   var strInput   = new String(str1.value)
   var objregExp  = new RegExp(PatternsDict.YeartoYear)
   
   if(objregExp.test(strInput))
   
     {
       return true
     
     }
   
     alert(msg)
     str1.focus()
     return false
 
 }



// Check for valid email format

function isEmail(str1,msg)
 {
 
   var strInput   = new String(str1.value)
   var objregExp  = new RegExp(PatternsDict.emailpat)
   
   if(objregExp.test(strInput))
   
     {
       return true
     
     }
     
     if(strInput != "")
		{
		alert(msg)
		 return false
		}
	else
		{     
			return true	 
		}
     
 
 }
 
/* function isValidc(str1,msg)
 {
	//alert("inside the fucniton")
   var strInput = new String(str1.value)
      
   var objregExp  = new RegExp(PatternsDict.validpat)
   if(objregExp.test(strInput))
     {
      return true
     } 
     if(strInput != "")
		{
		
		alert(msg)
		str1.focus()
		return false
		
		}
	else
		{     
			return true	 
		}
 }*/

 
 
 
 
  
 // Checks a not character type field

function isNotChar(str1,msg)
 {
  
   var strInput = new String(str1.value) 
   var objregExp  = new RegExp(PatternsDict.charpat)
   
   if(objregExp.test(strInput))
     {
       
       return true
     }
     alert(msg)
     str1.focus()
     return false 
 }
 
// Checks a character type field

function isChar(str1,msg)
 {
  
   var strInput = new String(str1.value) 
   var objregExp  = new RegExp(PatternsDict.charpat)
   
   if(objregExp.test(strInput))
   
     {
       return true
     }
     alert(msg)
     str1.focus()
     return false 
 }
// Check if field contains any character except alplanumeric and -/_
// including white space

function isValid(str1,msg)
 {
	//alert("inside the fucniton")
   var strInput = new String(str1.value)
   
   var objregExp  = new RegExp(PatternsDict.validpat)
   if(objregExp.test(strInput))
     {
      return true
     } 
     alert(msg)
     str1.focus()
     return false 
 }
 
// Checks mandatory field
 
function IsRequired(str1,msg)
  {
    var strInput = new String(str1.value)
    var objregExp  = new RegExp(PatternsDict.requiredpat)
   
  
   if(objregExp.test(strInput))
   
     {
       alert(msg)
       str1.focus()
       return false
      }
     return true
  }
 
// Checks valid hexa decimal number

function isHex(str1,msg)

 {
   var strInput   = new String(str1.value)
   var objregExp  = new RegExp(PatternsDict.hexpat)
   
   if(objregExp.test(strInput))
   
     {
       return true
     
     }
   
     alert(msg)
     str1.focus()
     return false
 
 }

// Checks valid IP address

function isvalidIP(str1,msg)
{
   var strInput   = new String(str1.value)
   var objregExp  = new RegExp(PatternsDict.IPpat)
   
   if(objregExp.test(strInput))
   
     {
       return true
     
     }
   
     alert(msg)
     str1.focus()
     return false
 
 }

// Checks for valid zip no.

function isZip(str1,msg)

 {
   var strInput   = new String(str1.value)
   var objregExp  = new RegExp(PatternsDict.zippat)
   

   if(objregExp.test(strInput))
   
     {
       return true
     
     }
   
     alert(msg)
     str1.focus()
     return false
 
 }

// Checks for white space

function isWhitespace(str)

 {
   var objregExp  = new RegExp(PatternsDict.whitespacepat)
   
   if(objregExp.test(str))
      return true
   
   return false
 
 }
 
// Checks for numeric input


/*
function isNumeric(str1,msg)

 {
   var strInput   = new String(str1.value)
   var objregExp  = new RegExp(PatternsDict.numericpat)
   
   if(objregExp.test(strInput))
   
     {
       return true
     
     }
   
     alert(msg)
     str1.focus()
     return false
 
 }

*/
 

// Checks for valid telephone no.

function isPh(str1,msg)
 {
  
   var strInput   = new String(str1.value)
   var objregExp  = new RegExp(PatternsDict.validph)
   
   if(objregExp.test(strInput))
   
     {
       return true
     
     }
   
     alert("please enter valid Phone number ")
     val.focus()
     return false
 
 }

function isTel(str1,msg)
 {
  
   var strInput   = new String(str1.value)
   var objregExp  = new RegExp(PatternsDict.telpat)
   
   if(objregExp.test(strInput))
   
     {
       return true
     
     }
   
     alert(msg)
     str1.focus()
     return false
 
 }

// Checks partial phone number
 
 function isFilled(str1,msg)
  {
   var strInput   = new String(str1.value)
   var objregExp  = new RegExp(PatternsDict.telpat)
   
   if(objregExp.test(strInput))
   
     {
       return true
     
     }
   
     alert(msg)
     str1.focus()
     return false
  }   


// =======================================================================================
// This function is used to change any text to Uppercase text   

function UpperCase(toconvert)
 {
  text      = new String(toconvert);
  toconvert = text.toUpperCase();
 
  return  toconvert;
 } 

     
  // Check for numeric field


   
   

 function isNumeric(val,length)
   {
    
     var strInput = new String(val.value)
     
         
     if(strInput.length > 0 && !isWhitespace (strInput))
      {
       if(strInput.length < length)
        {
         alert("Field must be " + length + " characters long")
         val.focus()
         return false
        }
     
       for(i = 0; i < strInput.length; i++)
        {
         if(strInput.charAt(i) < '0' ||  strInput.charAt(i) > '9')
          {
           alert("Field should be numeric")
           val.focus()
           return false
          }
        }
     }   
     return true
   }


   
 // Check whether Passwords are matched 
 
 function IsPwdMatch(pwd,cpwd,msg)
  {
  
    if (pwd.value != cpwd.value )
     {
       alert(msg);
       cpwd.focus()
       return false
     } 
    else
      return true 
  }


//check if the field is of max length

function isMaxlen(val,len,msg)
 {
  strInput = new String(val.value)
  sLength  = strInput.length
  if(sLength > len)
   {
    alert(msg)
    val.focus()
    return false
   }  
  return true 
 }


 // Check if the field is of min length

function isMinlen(val,len,msg)
 {
  strInput = new String(val.value)
  sLength  = strInput.length
  if(sLength < len)
   {
    alert(msg)
    val.focus()
    return false
   }  
  return true 
 }

// Check if two fields are indentical

 function isSimilar(str1,str2,msg)
  {
   strInput1 = new String(str1.value)
   strInput2 = new String(str2.value)

   if(strInput1.valueOf() == strInput2.valueOf())
       {
     alert(msg)
     str2.focus()
     return true
    } 

    return false 
  }
  
// Check if two or motr email ids are are indentical

 function isEmailSimilar(str1,str2,str3,str4,str5,msg)
  {
 
   strInput1 = new String(str1)
   strInput2 = new String(str2)
   strInput3 = new String(str3)
   strInput4 = new String(str4)
   strInput5 = new String(str5)
 

     var fstr,sstr;
     for(i=1;i<=5;i++)
      {
      fstr = new String(eval("strInput" + i))
      
        for(j=i+1;j<=5;j++)
        {
   
         sstr = new String(eval("strInput" + j))
         
        if(fstr.valueOf() != "" && sstr.valueOf() != "")
          {
        
			if(fstr.valueOf() == sstr.valueOf())
              {
                alert(msg)
			    return false
		      }	
		  }    
	    } 
      }
     return true
  }
  //==Check whether Pwd Question & Ans. are entered..
  function CheckQA(val1,val2)
  {
	str1 = new String(val1.value)
	str2 = new String(val2.value)
	if(str1.length > 0 || str2.length > 0)
	{
		if(str1.length == 0)
		{
			alert("Please enter the Password Question")
			val1.focus()
			return false
		}
		else if(str2.length == 0)
		{
			alert("Please enter the Secret Answer")
			val2.focus()
			return false
		}
		else
			return true
	}return true
  }

function trim(strString)
{
	var strCopy = new String(strString)
		strCopy = strCopy.replace(/^\s+/,"")
		strCopy = strCopy.replace(/\s+$/, "")
		return strCopy.toString()
}	



// Check if field contains any character except alplanumeric and -/_
// including white space

function isValidc(str1,msg)
 {
	//alert("inside the fucniton")
   var strInput = new String(str1.value)
      
   var objregExp  = new RegExp(PatternsDict.validpatc)
   if(objregExp.test(strInput))
     {
      return true
     } 
     if(strInput != "")
		{
		
		alert(msg)
		str1.focus()
		return false
		
		}
	else
		{     
			return true	 
		}
 }
 
 
 /*//numeric pat with decimal
 
 function1234(str1,msg)

 {
   var strInput   = new String(str1.value)
   var objregExp  = new RegExp(PatternsDict.numericpat1234)
   
   if(objregExp.test(strInput))
   
     {
       return true
     
     }
   
     alert(msg)
     str1.focus()
     return false
 
 }*/
 
 
 
 //validpatcnos
  
 function isValidcnos(str1,msg)
 {
	//alert("inside the fucniton")
   var strInput = new String(str1.value)
      
   var objregExp  = new RegExp(PatternsDict.validpatcnos)
   if(objregExp.test(strInput))
     {
      return true
     } 
     if(strInput != "")
		{
		
		alert(msg)
		str1.focus()
		return false
		
		}
	else
		{     
			return true	 
		}
 }
 
 