	function checkValidation(formobj, arrFieldNames ) {
	var s =""; 
	var result = true;  
	var name ="";
	var dispname ="";  
	var command ="";
	var sErr = "";


	for(var itr=0;itr < arrFieldNames.length; itr++)
	{ 
		s= arrFieldNames[itr];
		name = s.substr(0,s.search(","));
		dispname =s.substring(s.search(",")+1,s.search(";"));
		command =s.substring(s.search(";")+1,s.search(":"));
		sErr = s.substr(s.search(":")+1);
		if(validate(formobj.elements[name],dispname,command,sErr)==false) {
			if (command != "radio") {
				if ( formobj.elements[name].type != "hidden") {
					formobj.elements[name].focus();
				}
			}
			result=false;
			break;
		} 
	}
	return result;
}


function validate(objValue,dispname,strValidateStr, strError)
{
    var epos = strValidateStr.search("="); 
    var  command  = ""; 
    var  cmdvalue = ""; 
    if(epos >= 0) 
    { 
     command  = strValidateStr.substring(0,epos); 
     cmdvalue = strValidateStr.substr(epos+1); 
    } 
    else 
    {  
     command = strValidateStr; 
    } 
    
    switch(command) 
    { 
         
        
        case "req": 
        { 
           if(eval(objValue.value.length) == 0) 
           { 
              if(!strError || strError.length ==0) 
              { 
                strError = dispname; 
              }//if 
              alert(strError); 
              return false; 
           }//if  
           break;             
         }//case required 
        case "required": 
         { 
           if(eval(objValue.value.length) == 0) 
           { 
              if(!strError || strError.length ==0) 
              { 
                strError = dispname; 
              }//if 
              alert(strError); 
              return false; 
           }//if  
           break;             
         }//case required 
        case "maxlength": 
        case "maxlen": 
          { 
             if(eval(objValue.value.length) >  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = dispname; 
               }//if 
               alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               return false; 
             }//if 
             break; 
          }//case maxlen 
        case "minlength": 
        case "minlen": 
           { 
             if(eval(objValue.value.length) <  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = dispname; 
               }//if               
               alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               return false;                 
             }//if 
             break; 
            }//case minlen 
		case "minlenForSecQues": 
           { 
             if(eval(objValue.value.length) <  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = dispname; 
               }//if
			   alert(strError);
               return false;                 
             }//if 
             break; 
            }//case minlen
        case "alnum": 
        case "alphanumeric": 
           { 
              var charpos = objValue.value.search("[^A-Za-z0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 
                  strError = dispname; 
                }//if 
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break; 
           }//case alphanumeric 
		  
		
		 
        case "alnumspace": 
        case "alphanumericspace": 
           { 
              var charpos = objValue.value.search("[^A-Z a-z0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 
                  strError = dispname; 
                }//if 
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break; 
           }//case alphanumericspace 
        case "num": 
        case "numeric": 
           { 
              var charpos = objValue.value.search("[^0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = dispname; 
                }//if               
                alert(strError); 
                return false; 
              }//if 
              break;               
           }//numeric 
       case "flt": 
        case "float": 
           { 
              var charpos = objValue.value.search("[^0-9.]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = dispname; 
                }//if               
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break;               
           }//float 
         case "alphabetic": 
        case "alpha": 
           { 
              var charpos = objValue.value.search("[^A-Za-z]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = dispname; 
                }//if                             
                alert(strError); 
                return false; 
              }//if 
              break; 
           }//alpha 
         case "alphaspace": 
           { 
              var charpos = objValue.value.search("[^A-Z a-z]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = dispname; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break; 
           }//alphaspace 
        case "alphahyphen": 
           { 
              var charpos = objValue.value.search("[^A-Z a-z\-_]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = dispname; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break; 
           }//alphahyphen 
		 case "usercommonspecial": 
           { 
              var charpos = objValue.value.search("[^A-Za-z0-9\.@_-]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = dispname; 
                }//if                             
                alert(strError); 
                return false; 
              }//if 
              break; 
           }//alphahyphen 
		case "commonspecial":
			{
              var charpos = objValue.value.search("[^A-Z a-z0-9\-_.&,/|=:|;']"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = dispname;
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 			
	     break;
	  }

	  
	case "alphaSpecialnames":
		{
			var charpos = objValue.value.search("[^A-Z a-z 0-9,-']"); 
			if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = dispname;
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 			
	     break;
	  }
	
	case "qualification":
	 {
           
              var charpos = objValue.value.search("[^A-Z a-z.]"); 
           
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = dispname;
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 			
	     break;
 }

	case "alnumhyphen":
			{
              var charpos = objValue.value.search("[^A-Z a-z0-9\-_.]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = dispname; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 			
			break;
			}
	case "alnumhyphennospace":
			{
              var charpos = objValue.value.search("[^A-Za-z0-9\-]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = dispname; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 			
			break;
			}			
	case "emailchars":
			{
              var charpos = objValue.value.search("[^A-Z a-z0-9\-_.@]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = dispname; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 			
			break;
			}
        case "email": 
          { 
               if(!validateEmailv2(objValue.value)) 
               { 
                 if(!strError || strError.length ==0) 
                 { 
                    strError = dispname; 
                 }//if                                               
                 alert(strError); 
                 return false; 
               }//if 
           break; 
          }//case email 
		case "radio":
			{
				if(objValue.length>0) {
					var iCounter = 0;
					var iFlag = false;
					for(iCounter = 0; iCounter < objValue.length; iCounter++) {
						if(objValue[iCounter].checked) {
							iFlag = true;
						}
					}
					if(iFlag == false) {
		                 if(!strError || strError.length ==0) 
    		             { 
        		            strError = dispname; 
            		     }//if                                               
                		 alert(strError); 
	                	 return false; 
					 }
					}
				break;
			} //case radio
	case "dateofbirth":
	{
		var sDOB = objValue.value;
		var i1 = 0;
		var i2 = 0;
		i1 = sDOB.indexOf(",");
		i2 = sDOB.indexOf(",", i1+1);
		var my_year = "";
		var my_month = "";
		var my_date = "";
		my_year = sDOB.substring(0, i1);
		i1++;
		my_month = sDOB.substring(i1, i2);
		i2++;
		my_date = sDOB.substring(i2, sDOB.length);
			if(!isDate(parseInt(my_year),parseInt(my_month),parseInt(my_date))) 
               { 
                 if(!strError || strError.length ==0) 
                 { 
                    strError = "Selected Date is \"Invalid Date\""; 
					return false; 
					
                 }//if                                               
                 alert(strError); 
                 return false; 
               }//if 
           break; 
          }//case dateofbirth
	
        case "lt": 
        case "lessthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(dispname); 
              return false; 
            }//if 
            if(eval(objValue.value) >=  eval(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = dispname; 
              }//if               
              alert(strError); 
              return false;                 
             }//if             
            break; 
         }//case lessthan 
        case "gt": 
        case "greaterthan": 
         { 
		 	//alert("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
            if(isNaN(objValue.value)) 
            { 
              alert(dispname); 
              return false; 
            }//if 
             if(eval(objValue.value) <=  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = dispname; 
               }//if               
               alert(strError); 
               return false;                 
             }//if             
            break; 
         }//case greaterthan 
		
        case "regexp": 
         { 
            if(!objValue.value.match(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = dispname; 
              }//if                                                               
              alert(strError); 
              return false;                   
            }//if 
           break; 
         }//case regexp 
        case "dontselect": 
         { 
            
            if(objValue.selectedIndex == null) 
            { 
              alert("BUG: dontselect command for non-select Item"); 
              return false; 
            } 

            if(objValue.selectedIndex == eval(cmdvalue)) 
            { 
             if(!strError || strError.length ==0) 
              { 
              strError = dispname; 
			  //strError = " Please Select " + "<B>" dispname </B> ; 
              }//if                                                               
              alert(strError); 
              return false;                                   
             } 
             break; 
         }//case dontselect 
//		 *********** EPin - Enhancement Code Added by Patni Starts ********** //
		 case "secretAnswer": 
        case "secretAnswer": 
           { 
              var charpos = objValue.value.search("[!,#,%,^,*,@,$,(,),?,|,/,{,},`,~,;,:, ]"); 

              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 
                  strError = dispname; 
                }//if 
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if
			  
			var iChars = "[,]";
			
			for (var i = 0; i < objValue.value.length; i++) 
			{
				  
			  if (iChars.indexOf(objValue.value.charAt(i)) != -1)
				{
				   if(!strError || strError.length ==0) 
					{ 
						strError = dispname; 
					}//if 
					
					alert(strError + "\n [Error character position " + eval(i+1)+"]"); 
					return false; 
				}
			}

			var iChars = "\\";
			
			for (var i = 0; i < objValue.value.length; i++) 
			{
				  
			  if (iChars.indexOf(objValue.value.charAt(i)) != -1)
				{
				   if(!strError || strError.length ==0) 
					{ 
						strError = dispname; 
					}//if 
					
					alert(strError + "\n [Error character position " + eval(i+1)+"]"); 
					return false; 
				}
			}

              break; 
           }//case secretAnswer 
//		 *********** EPin - Enhancement Code Added by Patni Ends ********** //
    }//switch 
    return true; 
}
//		 *********** EPin - Enhancement Code Added by Patni Starts ********** //
function trimSpace(p_strInput) 

{
   while (p_strInput.substring(0,1) == ' ') 

      {

                p_strInput = p_strInput.substring(1,p_strInput.length);

      }



      while (p_strInput.substring(p_strInput.length-1,p_strInput.length) == ' ') 

      {

                p_strInput = p_strInput.substring(0,p_strInput.length-1);

      }
  return p_strInput;

}

//		 *********** EPin - Enhancement Code Added by Patni Ends ********** //


//---------------------------------EMail Check ------------------------------------ 

/*  checks the validity of an email address entered 
*   returns true or false 
*   
*/ 

function validateEmailv2(email)
{
	// a very simple email validation checking. 
	// you can add more complex email checking if it helps 
	//		 *********** EPin - Enhancement Code Added by Patni Starts ********** //
	// To avoid email starting with underscore
    if ( email == "" ) return true;	
	var firstletter = email.charAt(0);
	var firstletter1 = new String(firstletter);
	var searchfirst = firstletter1.search("[_]");
	if( searchfirst == 0){
		return false;
	}
	//		 *********** EPin - Enhancement Code Added by Patni Ends ********** //
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
		//		 *********** EPin - Enhancement Code Added by Patni Starts ********** //
		// To avoid a dot after @ 
		var dotletter = splitted[2].charAt(0);
		var dotletter1 = new String(dotletter);
		var searchdot = dotletter1.search("[.]");
		if( searchdot == 0){
			return false;
		}
		// To avoid an underscore after @ 
		var searchUnderScore = dotletter1.search("[_]");
		if( searchUnderScore == 0){
			return false;
		}
		// To avoid email ending with co
		var cletter = splitted[2].charAt(splitted[2].length-2);
		var cletter1 = new String(cletter);
		var searchc = cletter1.search("[c]");
		var oletter = splitted[2].charAt(splitted[2].length-1);
		var oletter1 = new String(oletter);
		var searcho = oletter1.search("[o]");
		if( searchc == 0 && searcho == 0 ){
			return false;
		}
/*		 *********** EPin - Enhancement Code Added by Patni Ends ********** //
    var regexp_domain=/^[\w-\.]*[A-Za-z]\.[A-Za-z]$/;
    var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
     if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
*/
      return true;
    }
return false;
}


function isDate (year, month, day)
{       

    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

var daysInMonth = new Array();
daysInMonth[1] = 31;
daysInMonth[2] = 29;   // must programmatically check this
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}

function daysInFebruary (year)
{
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}
function removeZeroes(oField) {
	var num = oField.value;
	num=num.replace(/^0+/, "");
	oField.value = num;
}
function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') || (s.substring(s.length-1,s.length) == '\n') || (s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
} 
