
function Validator(frmname)
{
	this.formobj=document.forms[frmname];
	
	if(!this.formobj)
	{
	  alert("Could not get value in Form "+frmname);
		return;
	}
	if(this.formobj.onsubmit)
	{
	 this.formobj.old_onsubmit = this.formobj.onsubmit;
	 this.formobj.onsubmit=null;
	}
	else
	{
	 this.formobj.old_onsubmit = null;
	}
	this.formobj.onsubmit=form_submit_handler;
	this.addValidation = add_validation;
	this.setAddnlValidationFunction=set_addnl_vfunction;
	this.setAddn2ValidationFunction=set_addn2_vfunction;
	this.clearAllValidations = clear_all_validations;
}
function set_addnl_vfunction(functionname)
{
  this.formobj.addnlvalidation = functionname;
}

function set_addn2_vfunction(functionname)
{
  this.formobj.addn2validation = functionname;
}

function clear_all_validations()
{
	for(var itr=0;itr < this.formobj.elements.length;itr++)
	{
		this.formobj.elements[itr].validationset = null;
	}
}
function form_submit_handler()
{
	for(var itr=0;itr < this.elements.length;itr++)
	{
		if(this.elements[itr].validationset &&
	   !this.elements[itr].validationset.validate())
		{
		  return false;
		}
	}
	if(this.addnlvalidation)
	{
	  str =" var ret = "+this.addnlvalidation+"()";
	  eval(str);
    if(!ret) return ret;
	}
	return true;
}
function add_validation(itemname,descriptor,errstr)
{
  if(!this.formobj)
	{
	  alert("BUG: the form object is not set properly");
		return;
	}//if
	var itemobj = this.formobj[itemname];
  if(!itemobj)
	{
	  alert("Couldnot get the input object named: "+itemname);
		return;
	}
	if(!itemobj.validationset)
	{
	  itemobj.validationset = new ValidationSet(itemobj);
	}
  itemobj.validationset.add(descriptor,errstr);
}
function ValidationDesc(inputitem,desc,error)
{
  this.desc=desc;
	this.error=error;
	this.itemobj = inputitem;
	this.validate=vdesc_validate;
}
function vdesc_validate()
{
 if(!V2validateData(this.desc,this.itemobj,this.error))
 {
    this.itemobj.focus();
		return false;
 }
 return true;
}
function ValidationSet(inputitem)
{
    this.vSet=new Array();
	this.add= add_validationdesc;
	this.validate= vset_validate;
	this.itemobj = inputitem;
}
function add_validationdesc(desc,error)
{
  this.vSet[this.vSet.length]= 
	  new ValidationDesc(this.itemobj,desc,error);
}
function vset_validate()
{
   for(var itr=0;itr<this.vSet.length;itr++)
	 {
	   if(!this.vSet[itr].validate())
		 {
		   return false;
		 }
	 }
	 return true;
}

//This function will for the precison form in the rate information
function ratePrecisionFormat(returnValue)
{
//	var val;
//	val = form_county.txt_pro_current.value;
	
	if(returnValue != "")
	{
		var temp = new Array();
		temp = returnValue.split('.');
		if(temp.length == 1)
		{
			returnValue = returnValue  + ".0000000000";
		}
		else
		{
			switch(temp[1].length)
			{
				case 1:
					returnValue = returnValue  + "000000000";
					break;
				case 2:
					returnValue = returnValue  + "00000000";
					break;
				case 3:
					returnValue = returnValue  + "0000000";
					break;
				case 4:
					returnValue = returnValue  + "000000";
					break;
				case 5:
					returnValue = returnValue  + "00000";
					break;
				case 6:
					returnValue = returnValue  + "0000";
					break;
				case 7:
					returnValue = returnValue  + "000";
					break;
				case 8:
					returnValue = returnValue  + "00";
					break;
				case 9:
					returnValue = returnValue  + "0";
					break;
			}
		}
	}
	else
	{
		returnValue = "0.0000000000";
	}
	return returnValue;

}

//Function for International phone numbers

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()-";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

/*function ValidateForm(){
	var Phone=document.frmSample.txtPhone
	
	if ((Phone.value==null)||(Phone.value=="")){
		alert("Please Enter your Phone Number")
		Phone.focus()
		return false
	}
	if (checkInternationalPhone(Phone.value)==false){
		alert("Please Enter a Valid Phone Number")
		Phone.value=""
		Phone.focus()
		return false
	}
	return true
 } */


//Validation for Date checking

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}
//

//Validation for Other Email

var emailErrorText
emailErrorText = ""
function validateEmailv2(email)
{
	// a very simple email validation checking. 
	// you can add more complex email checking if it helps 
	//**********

	var temp = new Array();
	temp = email.split(';');
	if(temp.length > 5)
	{
		//strError = "only 5 mail"; 
		emailErrorText = "Please Enter maximum five email addresses";
	    return false;
	}
	else
	{
		for(var itr=0;itr < temp.length;itr++)
		{
			temp[itr] = trim(temp[itr]);
			
			if(temp[itr].length == 0)
			{
				otherErrorText = "Please Enter valid email";
			    return false;
			}
			//
			var splitted = trim(temp[itr]).match("^(.+)@(.+)$");
			if(splitted == null){
				emailErrorText = "";
				return false;
			}
			if(splitted[1] != null )
			{
				var regexp_user=/^\"?[\w-_\.]*\"?$/;
				if(splitted[1].match(regexp_user) == null){
					emailErrorText = "";
					return false;
				}
			}
			if(splitted[2] != null)
			{
				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){
						emailErrorText = "";
						return false;
					}
				}// if
				//return false;
			}
	
		}
	}

	return true;
}

//

function validateEmailv1(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    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)
    {
      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;
}
//

//Validation for Other Contacts Field in all fields (in county, city, other, school)
otherErrorText = ""
function validateOther(other)
{
	
	// a very simple email validation checking. 
	// you can add more complex email checking if it helps 
	//**********
	var temp = new Array();
	temp = other.split(';');
	
	
	if(temp.length > 5)
	{
	
		//strError = "only 5 mail"; 
		otherErrorText = "Please Enter maximum five other contacts";
	    return false;
	}
	else
	{
		for(var itr=0;itr < temp.length;itr++)
		{
			temp[itr] = trim(temp[itr]);
			if(other.length > 0)
			{
				if(temp[itr].length == 0)
				{
					otherErrorText = "Please Enter valid other contact";
				    return false;
				}
			}
			
			//SANDEEP
			var charpos = trim(temp[itr]).search("[^A-Za-z ]"); 
			if(temp[itr].length > 0 &&  charpos >= 0) 
            { 
              	otherErrorText = "";
	            return false; 
            }
		}
			//SANDEEP END		
	}

	return true;
}

//Following TRIM function start

//Ltrim 
function ltrim(argvalue) {

  while (1) {
    if (argvalue.substring(0, 1) != " ")
      break;
    argvalue = argvalue.substring(1, argvalue.length);
  }

  return argvalue;
}


//RTrim
function rtrim(argvalue) {

  while (1) {
    if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ")
      break;
    argvalue = argvalue.substring(0, argvalue.length - 1);
  }

  return argvalue;
}


//Trim
function trim(argvalue) {
  var tmpstr = ltrim(argvalue);

  return rtrim(tmpstr);

}

//Above TRIM function End
//*******************

function V2validateData(strValidateStr,objValue,strError) 
{ 


    var epos = strValidateStr.search("="); 
    var  command  = ""; 
    var  cmdvalue = ""; 
	var doEncript = true;
	
	objValue.value = trim(objValue.value);

    if(epos >= 0) 
    { 
     command  = strValidateStr.substring(0,epos); 
     cmdvalue = strValidateStr.substr(epos+1); 
    } 
    else 
    { 
     command = strValidateStr; 
    } 
	
    switch(command) 
    { 
		
        //Used for required function
		case "req": 
        case "required": 
         { 
           if(eval(objValue.value.length) == 0) 
           { 
              if(!strError || strError.length ==0) 
              { 
                strError = "The field is required"; 
				objValue.select();
              }//if 
              alert(strError); 
			  doEncript = false;
              return false; 
           }//if 
           break;             
         }//case required 
		 
		 //Used for Maximum length to all fields
        case "maxlength": 
        case "maxlen": 
          { 
             if(eval(objValue.value.length) >  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : "+cmdvalue+" characters maximum"; 
				 objValue.select();
               }//if 
               alert(strError + "\nCurrent length is " + objValue.value.length); 
			   doEncript = false;
               return false; 
             }//if 
             break; 
          }//case maxlen
		  
		//Used for Minimum length to all fields
        case "minlength": 
        case "minlen": 
           { 
             if(eval(objValue.value.length) <  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : " + cmdvalue + " characters minimum  ";
				 objValue.select();
               }//if               
               alert(strError + "\nCurrent length = " + objValue.value.length); 
			   doEncript = false;
               return false;                 
             }//if 
             break; 
           }//case minlen 
			
		//Used for Alphanumeric validations
        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 = "Please enter only alphanumeric characters"; 
				  objValue.select();
                }//if 
                alert(strError);
				doEncript = false;
                return false; 
              }//if 
              break; 
           }//case alphanumeric 
		   
		   //used for select form part
		     case "selectformpart": 
           { 
              var charpos = objValue.value.search("[^A-Za-z0-9:\_]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 

                  strError = "Please enter valid path"; 
				  objValue.select();
                }//if 
                alert(strError);
				doEncript = false;
                return false; 
              }//if 
              break; 
           }//case alphanumeric 
		
		
        case "rad": 
        case "radCheck": 
           { 
				var anySelect
				anySelect = false;
				var ii ;
				
				for (ii = 1; ii<= eval(cmdvalue);ii++)
				{
					if(eval("document.all."+objValue.name+""+ii+".checked"))
					{
						anySelect = true;		
					}
				}
				if(!anySelect)
				{
					alert(strError);
					doEncript = false;
					return false;
				}
				break; 
           }//case alphanumeric 
		   //Used for property number.
		   case "propno": 
           { 
              var charpos = objValue.value.search("[^A-Za-z0-9-]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 

                  strError = "Please enter valid property number"; 
				  objValue.select();
                }//if 
                alert(strError);
				doEncript = false;
                return false; 
              }//if 
              break; 
           }//case property no
		   
		    case "passchar": 
           { 
		   		if(objValue.value.length < 4 )
				{
					alert("Please enter minimum of four charecters");
					return false;
				}
              var charpos = objValue.value.search("[^A-Za-z0-9_]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 
                  strError = "Please enter only alphanumeric characters";
				  objValue.select();
                }//if 
                alert(strError);
				doEncript = false;
                return false; 
              }//if 
              break; 
           }//case alphanumeric 
		   
		//Used for Numeric validations
        case "num": 
        case "numeric": 
           { 
		   	 if(isNaN(objValue.value))
			 {
			 	strError = "Please enter valid numeric value ";
				  objValue.select();
				  alert(strError);
					return false; 
			 }
              var charpos = objValue.value.search("[^0-9.]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = "Please enter valid numeric value ";
				  objValue.select();
                }//if               
				    alert(strError);
					doEncript = false;
					return false; 
              }//if 
			  	
	            
				
                

              break;               
           }
		   
		   //Validation for extension no. 
		   case "numericext": 
           { 
              var charpos = objValue.value.search("[^0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = "Please enter only numeric value.";
				  objValue.select();
                }//if               
                alert(strError);
				doEncript = false;
                return false; 
              }//if 
              break;               
           }
		   
		   //Validation for extension no. 
		   case "numericdate": 
           { 
              var charpos = objValue.value.search("[^0-9]"); 
              if(objValue.value.length > 2 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = "Please enter valid date.";
				  objValue.select();
                }//if               
                alert(strError);
				doEncript = false;
                return false; 
              }//if 
              break;               
           }
		   
		    case "phnum": 
           { 
              var charpos = objValue.value.search("[^0-9-/]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = "Please enter the numeric value eg. 999-999/9999";
				  objValue.select();
                }//if               
                alert(strError);
				doEncript = false;
                return false; 
              }//if 
              break;               
           }
		   
		   //Validation for Discount value
		   case "discount": 
           { 
              var charpos = objValue.value.search("[^0-9.]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = "Please enter only valid discount value";
				  objValue.select();
                }//if               
                alert(strError); 
				doEncript = false;
                return false; 
              }//if 
              break;               
           }
		   
		//Validation for alphabetic characters		   
        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 = "Please enter only alphabetic and space characters.";
				  objValue.select();
                }//if                             
                alert(strError);
				doEncript = false;
                return false; 
              }//if 
              break; 
           }
		   
		   //
		  case "mulemail": 
           { 
              var charpos = objValue.value.search("[\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*([,;]\s*\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*)*]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = "Please enter valid multiple email address";
				  objValue.select();
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
				doEncript = false;
                return false; 
              }//if 
              break; 
           }
		   
		   
		  //Validation for Other Contacts Fields
		  case "othercheck": 
           { 
		   //***********
		   othercontact=objValue.value;
		   var temp = new Array();
		   temp = othercontact.split(';');
		   if(temp.length > 5)
		   {
				//strError = "only 5 mail"; 
				contactErrorText = "Please Enter maximum five other contacts";
				objValue.select();
				doEncript = false;
	    		return false;
		   }
		    else
		  {
		   	//**********
			for(var itr=0;itr < temp.length;itr++)
		  {			
              var charpos = temp[itr].search("[^A-Za-z ]"); 
              if(temp[itr] > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = " Only alphabetic and space characters allowed ";
				  objValue.select();
                }//if                             
                alert(strError); 
				doEncript = false;
                return false; 
              }//if 
		  }
		  }
              break; 
        }
		
		//Validation for spacing in characters but not used yet
		 case "spacing": 
           { 
              var charpos = objValue.value.search("[\s\f\n\r\t\r\v]");
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                 if(!strError || strError.length ==0) 
                { 
                  strError = "Only one space characters allowed."; 
				  objValue.select();
                }//if                             
                alert(strError); 
				doEncript = false;
                return false; 
              }//if 
              break; 
           }
		   
		 // Used zip format before.
		case "zipbefore":
			{
              var charpos = objValue.value.search("[^A-Za-z0-9\-_]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _"; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
				doEncript = false;
                return false; 
              }//if 			
			break;
			}
			
		//Used validation for Numerals with hyphen(-)
		case "numhyphen":
			{
              var charpos = objValue.value.search("[^0-9-]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = "Please enter only 0-9 and - characters."; 
				  objValue.select();
                }//if                             
                alert(strError); 
				doEncript = false;
                return false; 
              }//if 			
			break;
			}
			
		//Used for Email validations
        case "email": 
          { 
              // if(!validateEmailv2(objValue.value)) 
			  if(objValue.value=='')
			{
				return true;
			}
			else
			{
			  if(validateEmailv2(objValue.value)==false)
               { 
                 if(!strError || strError.length ==0) 
				
                 { 
				 	if(emailErrorText == "") 
					{
                    	strError = "Enter a valid Email address";
					}
					else
					{
						strError = emailErrorText
					}
					
                 }//if                                               
                 alert(strError); 
				 doEncript = false;
                 return false; 
               }//if 
			}
           break; 
          }
		  //for New registration form for email
		     case "emailnewuser": 
          { 
               if(!validateEmailv1(objValue.value)) 
               { 
                 if(!strError || strError.length ==0) 
                 { 
                    strError = "Enter a valid email address.";
					objValue.select();
                 }//if                                               
                 alert(strError);
				 doEncript = false;
                 return false; 
               }//if 
           break; 
          }//case email 
		  
		  //Used Validation for Other contact Fields
		  case "contactalpha": 
          { 
		  
              // if(!validateOther(objValue.value)) 
			  if(validateOther(objValue.value)==false)
               { 
                 if(!strError || strError.length ==0) 
				{ 
				 	if(otherErrorText == "") 
					{
                    	strError = "Enter only alphabetic characters"; 
						objValue.select();
					}
					else
					{
						strError = otherErrorText;
						objValue.select();
					}
					
                 }//if                                               
                 alert(strError); 
				 doEncript = false;
                 return false; 
               }//if 
           break; 
          }
		  
		//Used validation for phone no, not using current.
		  
		case "phone": 
          { 
               if(!checkInternationalPhone(objValue.value)) 
               { 
               if (checkInternationalPhone(objValue.value)==false) 
                 { 
                    strError = "Enter a valid Phone Number"; 
					objValue.select();
                 }//if                                               
                 alert(strError); 
				 doEncript = false;
                 return false; 
               }//if 
           break; 
          }
		  
		//Used Validation for Date time function
		case "datetime": 
         {
		 		if(objValue.value=='')
					{
						return true;
					}
					
				else
					{			
		  			return isDate(objValue.value);
					objValue.select();
               		}
			break; 
		  }

		//Used validation for Less than numerals
        case "lt": 
        case "lessthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert("Please enter valid numeric value."); 
			  objValue.select();
              return false; 
            }//if 
            if(eval(objValue.value) >=  eval(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : value should be less than "+ cmdvalue; 
				objValue.select();
              }//if               
              alert(strError); 
			  doEncript = false;
              return false;                 
             }//if             
            break; 
         }//case lessthan 
		 
		//Used valiation for greater than numerals
        case "gt": 
        case "greaterthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert("Please enter valid numeric value."); 
              return false; 
            }//if 
             if(eval(objValue.value) <=  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : value should be greater than "+ cmdvalue;
				 objValue.select();
               }//if               
               alert(strError); 
			   doEncript = false;
               return false;                 
             }//if             
            break; 
         }//case greaterthan 
		 
		//Used validation for Reg Expression
        case "regexp": 
         { 
		 	if(objValue.value.length > 0)
			{
	            if(!objValue.value.match(cmdvalue)) 
	            { 
	              if(!strError || strError.length ==0) 
	              { 
	                strError = objValue.name+": Invalid characters found "; 
					objValue.select();
	              }//if                                                               
	              alert(strError); 
				  doEncript = false;
	              return false;                   
	            }//if 
			}
           break; 
         }//case regexp 
		 
		//Used validations for Select List box
        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 = "Please Select one option from the list box."; 
			  objValue.select();
              }//if                                                               
              alert(strError); 
			  doEncript = false;
              return false;                                   
             } 
             break; 
         }//case dontselect
		 
		 //Used validations for Matching the password with retype password in all fields
		 case "matchpassword":
		 {
		 	if(window.document.all.txt_repassword.value != window.document.all.txt_password.value)
			{
				alert("Your password does not match.");
				objValue.select();
				doEncript = false;
				return false;
			}
		 }
		 break;
		 
		 //Used validation for matching the password with retype password in Admin Forms
		 case "newmatchpassword":
		 {
		 	if(window.document.all.txt_new_password.value != window.document.all.txt_re_new_password.value)
			{
				alert("Your password does not match.");
				objValue.select();
				doEncript = false;
				return false;
			}
		 }
		 break;		 
 
		 //Used validations for Zip Fields
		 case "zip":
		 {
		 	reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);
 
	    	 if (!reZip.test(objValue.value)) {
   		 	      alert("Please enter valid Zip code.");
				  objValue.select();
				  doEncript = false;
        		  return false;
		     }
		 }
		 break;
		 
		 //for password (minimum characters validation
		 case "minpassword":
		 {
			 if(objValue.value=='')
			{
				return true;
			}
			else
			{
				var repass = new RegExp(/^[A-Za-z0-9]\w{2,}[A-Za-z0-9]$/);
				if (!repass.test(objValue.value)) 
				{
					alert("Enter minimum of 4 characters for password!"); 
					objValue.select();
					doEncript = false;
					return false;
				}
     		}
		 }
		 break;

		 //Used for Alphanumeric validations
        case "alphaspecial": 
           { 
              var charpos = objValue.value.search("[^A-Za-z0-9`~!@#$\\%&*()'_<+-{}=|;:\'\",./?\r\t\b\w>\n ]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 

                  strError = "Please enter only valid characters"; 
				  objValue.select();
                }//if 
                alert(strError); 
				doEncript = false;
                return false; 
              }//if 
              break; 
           }//case alphaspecial 		
		

		//Used validations for Phone Number in all fields.
		 case "phoneno":
		 {
		 	if(objValue.value=='')
			{
				return true;
			}
			else{
		     rePhoneNumber1 = new RegExp(/(^\d{3}-\d{3}-\d{4}$)/);
						 
      			if (!rePhoneNumber1.test(objValue.value)) {
          			alert("Please Enter valid Phone Number.");
					objValue.select();
					doEncript = false;
          			return false;
				}
     		}
		 }
		 break;

		//Used validations will decript the ' " $ = to spl charecters
		 case "encrypt":
		 {
			
				//Replacing the single quotes with § alt + 789
				ctrlVal =  replaceChars(objValue.value, "\'", "\§")

				//Replacing the double quotes with  alt + 012
				ctrlVal =  replaceChars(ctrlVal, "\"", "\")

				//Replacing the &  with Ç alt + 9856
				ctrlVal =  replaceChars(ctrlVal, "\&", "\Ç")

				//Replacing the = with « alt + 7854
				ctrlVal =  replaceChars(ctrlVal, "\=", "\«")

				//Replacing the = with « alt + 7854
				ctrlVal =  replaceChars(ctrlVal, "\=", "\«")

				//Replacing the \ with î alt + î
				ctrlVal =  replaceChars(ctrlVal, "\\", "\î")

				objValue.value = ctrlVal;
			

		 }
		 break;

		 //Used validations for Phone Number in all fields.
		 case "sqlInjection":
		 {
			var ctrlVal;

			ctrlVal = objValue.value;

			//ctrlVal = objValue.value;
			if(ctrlVal != '')
			{
				//String SQLKeywords = new String[]{"select","drop",";","--","insert","update","truncate","delete","sp_","xp_","(",")","union","drop",";","create","table"};
				var SQLKeywords = new Array("select","drop","--","insert","update","truncate","delete","sp_","xp_","(",")","union","drop","create","table");
				
				var testWords = ctrlVal.split(' ');
				
				for (var j = 0; j < testWords.length; j++)
				{
					for (var i = 0; i < SQLKeywords.length; i++)
					{
						if(testWords[j].toLowerCase() == SQLKeywords[i].toLowerCase())
						{
							testWords[j] = "";
						}
					}	
				}				
				objValue.value = testWords.join(' ');
			}

			return true;
		 }
		 break;
    }//switch 
    return true; 
}


//This function is replacing the x with y in argvalue
// is being used in the 
function replaceChars(argvalue, x, y)
{
  if(argvalue == null)	
  {
  	return false;
  }
  if ((x == y) || (parseInt(y.indexOf(x)) > -1)) {
	 return argvalue;
  }


  while (argvalue.indexOf(x) != -1) {

    var leading = argvalue.substring(0, argvalue.indexOf(x));
    var trailing = argvalue.substring(argvalue.indexOf(x) + x.length, 
	argvalue.length);
    argvalue = leading + y + trailing;
  }
  return argvalue;
}

//This function will decript back to special charecters
function decryptSpecialChars(objName)
{
	//Replacing the § quotes with '
	objName.value = replaceChars(objName.value, "\§", "\'");

	//Replacing the  quotes with "
	objName.value = replaceChars(objName.value, "\", "\"");

	//Replacing the Ç quotes with &
	objName.value = replaceChars(objName.value, "\Ç", "\&");

	//Replacing the «  quotes with =
	objName.value = replaceChars(objName.value, "\«", "\=");

	//Replacing the î quotes with \
	objName.value = replaceChars(objName.value, "\î", "\\");
	
}
