/*
  -------------------------------------------------------------------------
	                    JavaScript Form Validator 
                                Version 2.0.2
	Copyright 2003 JavaScript-coder.com. All rights reserved.
	You use this script in your Web pages, provided these opening credit
    lines are kept intact.
	The Form validation script is distributed free from JavaScript-Coder.com

	You may please add a link to JavaScript-Coder.com, 
	making it easy for others to find this script.
	Checkout the Give a link and Get a link page:
	http://www.javascript-coder.com/links/how-to-link.php

    You may not reprint or redistribute this code without permission from 
    JavaScript-Coder.com.
	
	JavaScript Coder
	It precisely codes what you imagine!
	Grab your copy here:
		http://www.javascript-coder.com/
    -------------------------------------------------------------------------  
*/

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}


// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}


function getTimeIndex(timestr) {
	var index = 0;
	
	++index;
	if (timestr == "08:00 AM")
		return index;		
	++index;
	if (timestr == "08:15 AM")
		return index;
	++index;
	if (timestr == "08:30 AM")
		return index;
	++index;
	if (timestr == "08:45 AM")
		return index;
	++index;
	if (timestr == "09:00 AM")
		return index;
	++index;
	if (timestr == "09:15 AM")
		return index;
	++index;
	if (timestr == "09:30 AM")
		return index;
	++index;
	if (timestr == "09:45 AM")
		return index;
	++index;
	if (timestr == "10:00 AM")
		return index;
	++index;
	if (timestr == "10:15 AM")
		return index;
	++index;
	if (timestr == "10:30 AM")
		return index;
	++index;
	if (timestr == "10:45 AM")
		return index;
	++index;
	if (timestr == "11:00 AM")
		return index;
	++index;
	if (timestr == "11:15 AM")
		return index;
	++index;
	if (timestr == "11:30 AM")
		return index;
	++index;
	if (timestr == "11:45 AM")
		return index;
	++index;
	if (timestr == "12:00 PM")
		return index;
	++index;
	if (timestr == "12:15 PM")
		return index;
	++index;
	if (timestr == "12:30 PM")
		return index;
	++index;
	if (timestr == "12:45 PM")
		return index;
	++index;
	if (timestr == "01:00 PM")
		return index;
	++index;
	if (timestr == "01:15 PM")
		return index;
	++index;
	if (timestr == "01:30 PM")
		return index;
	++index;
	if (timestr == "01:45 PM")
		return index;
	++index;
	if (timestr == "02:00 PM")
		return index;
	++index;
	if (timestr == "02:15 PM")
		return index;
	++index;
	if (timestr == "02:30 PM")
		return index;
	++index;
	if (timestr == "02:45 PM")
		return index;
	++index;
	if (timestr == "03:00 PM")
		return index;
	++index;
	if (timestr == "03:15 PM")
		return index;
	++index;
	if (timestr == "03:30 PM")
		return index;
	++index;
	if (timestr == "03:45 PM")
		return index;
	++index;
	if (timestr == "04:00 PM")
		return index;
	++index;
	if (timestr == "04:15 PM")
		return index;
	++index;
	if (timestr == "04:30 PM")
		return index;
	++index;
	if (timestr == "04:45 PM")
		return index;
	++index;
	if (timestr == "05:00 PM")
		return index;
	++index;
	if (timestr == "05:15 PM")
		return index;
	++index;
	if (timestr == "05:30 PM")
		return index;
	++index;
	if (timestr == "05:45 PM")
		return index;
	++index;
	if (timestr == "06:00 PM")
		return index;
	++index;
	if (timestr == "06:15 PM")
		return index;
	++index;
	if (timestr == "06:30 PM")
		return index;
	++index;
	if (timestr == "06:45 PM")
		return index;
	++index;
	if (timestr == "07:00 PM")
		return index;
	++index;
	if (timestr == "07:15 PM")
		return index;
	++index;
	if (timestr == "07:30 PM")
		return index;
	++index;
	if (timestr == "07:45 PM")
		return index;
	++index;
	if (timestr == "08:00 PM")
		return index;
		
	++index;
	if (timestr == "08:15 PM")
		return index;
	++index;
	if (timestr == "08:30 PM")
		return index;
	++index;
	if (timestr == "08:45 PM")
		return index;
	++index;
	if (timestr == "09:00 PM")
		return index;
	++index;
	if (timestr == "09:15 PM")
		return index;
	++index;
	if (timestr == "09:30 PM")
		return index;
	++index;
	if (timestr == "09:45 PM")
		return index;
	++index;
	if (timestr == "10:00 PM")
		return index;
	++index;
	if (timestr == "10:15 PM")
		return index;
	++index;
	if (timestr == "10:30 PM")
		return index;
	++index;
	if (timestr == "10:45 PM")
		return index;
	++index;
	if (timestr == "11:00 PM")
		return index;
	++index;
	if (timestr == "11:15 PM")
		return index;
	++index;
	if (timestr == "11:30 PM")
		return index;
	++index;
	if (timestr == "11:45 PM")
		return index;
	++index;
	if (timestr == "12:00 AM")
		return index;
	++index;
	if (timestr == "12:15 AM")
		return index;
	++index;
	if (timestr == "12:30 AM")
		return index;
	++index;
	if (timestr == "12:45 AM")
		return index;
	++index;
	if (timestr == "01:00 AM")
		return index;
	++index;
	if (timestr == "01:15 AM")
		return index;
	++index;
	if (timestr == "01:30 AM")
		return index;
	++index;
	if (timestr == "01:45 AM")
		return index;
	++index;
	if (timestr == "02:00 AM")
		return index;
	++index;
	if (timestr == "02:15 AM")
		return index;
	++index;
	if (timestr == "02:30 AM")
		return index;
	++index;
	if (timestr == "02:45 AM")
		return index;
	++index;
	if (timestr == "03:00 AM")
		return index;
	++index;
	if (timestr == "03:15 AM")
		return index;
	++index;
	if (timestr == "03:30 AM")
		return index;
	++index;
	if (timestr == "03:45 AM")
		return index;
	++index;
	if (timestr == "04:00 AM")
		return index;
	++index;
	if (timestr == "04:15 AM")
		return index;
	++index;
	if (timestr == "04:30 AM")
		return index;
	++index;
	if (timestr == "04:45 AM")
		return index;
	++index;
	if (timestr == "05:00 AM")
		return index;
	++index;
	if (timestr == "05:15 AM")
		return index;
	++index;
	if (timestr == "05:30 AM")
		return index;
	++index;
	if (timestr == "05:45 AM")
		return index;
	++index;
	if (timestr == "06:00 AM")
		return index;
	++index;
	if (timestr == "06:15 AM")
		return index;
	++index;
	if (timestr == "06:30 AM")
		return index;
	++index;
	if (timestr == "06:45 AM")
		return index;
	++index;
	if (timestr == "07:00 AM")
		return index;
	++index;
	if (timestr == "07:15 AM")
		return index;
	++index;
	if (timestr == "07:30 AM")
		return index;
	++index;
	if (timestr == "07:45 AM")
		return index;
		
	return 0;
}


function getStateIndex(state) {
	var index = -1;
	
	++index;
	if (state == "AL")
		return index;
	
	++index;
	if (state == "AK")
		return index;	
	
	++index;
	if (state == "AZ")
		return index;
	
	++index;
	if (state == "AR")
		return index;
		
	++index;
	if (state == "CA")
		return index;
	
	++index;
	if (state == "CO")
		return index;
		
	++index;
	if (state == "CT")
		return index;
		
	++index;
	if (state == "DE")
		return index;
		
	++index;
	if (state == "FL")
		return index;
		
	++index;
	if (state == "GA")
		return index;
		
	++index;
	if (state == "HI")
		return index;
	
	++index;
	if (state == "ID")
		return index;
		
	++index;
	if (state == "IL")
		return index;
	
	++index;
	if (state == "IN")
		return index;
	
	++index;
	if (state == "IA")
		return index;
		
	++index;
	if (state == "KS")
		return index;
	
	++index;
	if (state == "KY")
		return index;
		
	++index;
	if (state == "LA")
		return index;
		
	++index;
	if (state == "ME")
		return index;
		
	++index;
	if (state == "MD")
		return index;
		
	++index;
	if (state == "MA")
		return index;
		
	++index;
	if (state == "MI")
		return index;
		
	++index;
	if (state == "MN")
		return index;
		
	++index;
	if (state == "MS")
		return index;
		
	++index;
	if (state == "MO")
		return index;
		
	++index;
	if (state == "MT")
		return index;
		
	++index;
	if (state == "NE")
		return index;
		
	++index;
	if (state == "NV")
		return index;
		
	++index;
	if (state == "NH")
		return index;
	
	++index;
	if (state == "NJ")
		return index;
	
	++index;
	if (state == "NM")
		return index;
	
	++index;
	if (state == "NY")
		return index;
		
	++index;
	if (state == "NC")
		return index;
	
	++index;
	if (state == "ND")
		return index;
		
	++index;
	if (state == "OH")
		return index;
	
	++index;
	if (state == "OK")
		return index;
	
	++index;
	if (state == "OR")
		return index;
	
	++index;
	if (state == "PA")
		return index;

	++index;
	if (state == "RI")
		return index;
		
	++index;
	if (state == "SC")
		return index;
		
	++index;
	if (state == "SD")
		return index;
		
	++index;
	if (state == "TN")
		return index;
	
	++index;
	if (state == "TX")
		return index;
		
	++index;
	if (state == "UT")
		return index;
	
	++index;
	if (state == "VT")
		return index;
		
	++index;
	if (state == "VA")
		return index;
	
	++index;
	if (state == "WA")
		return index;
		
	++index;
	if (state == "DC")
		return index;
		
	++index;
	if (state == "WV")
		return index;
		
	++index;
	if (state == "WI")
		return index;
		
	++index;
	if (state == "WY")
		return index;

	return 8;
}


function Validator(frmname)
{
  this.formobj=document.forms[frmname];
	if(!this.formobj)
	{
	  alert("BUG: couldnot get Form object "+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.clearAllValidations = clear_all_validations;
}
function set_addnl_vfunction(functionname)
{
  this.formobj.addnlvalidation = 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("BUG: 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;
}
function validateEmailv2(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;
}
function V2validateData(strValidateStr,objValue,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": 
        case "required": 
         { 
           if(eval(objValue.value.trim().length) == 0) 
           { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : Required Field"; 
              }//if 
              alert(strError); 
              return false; 
           }//if 
           break;             
         }//case required 
        case "maxlength": 
        case "maxlen": 
          { 
             if(eval(objValue.value.trim().length) >  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : "+cmdvalue+" characters maximum "; 
               }//if 
               alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               return false; 
             }//if 
             break; 
          }//case maxlen 
        case "minlength": 
        case "minlen": 
           { 
             if(eval(objValue.value.trim().length) <  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : " + cmdvalue + " characters minimum  "; 
               }//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 = objValue.name+": Only alpha-numeric characters allowed "; 
                }//if 
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break; 
           }//case alphanumeric 
        case "num": 
        case "numeric": 
           { 
              var charpos = objValue.value.search("[^0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only digits allowed "; 
                }//if               
                alert(strError); 
                return false; 
              }//if 
              break;               
           }//numeric 
        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 = objValue.name+": Only alphabetic characters allowed "; 
                }//if                             
                alert(strError); 
                return false; 
              }//if 
              break; 
           }//alpha 
		case "alnumhyphen":
			{
              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)+"]"); 
                return false; 
              }//if 			
			break;
			}
        case "email": 
          { 
               if(!validateEmailv2(objValue.value)) 
               { 
                 if(!strError || strError.length ==0) 
                 { 
                    strError = objValue.name+": Enter a valid Email address "; 
                 }//if                                               
                 alert(strError); 
                 return false; 
               }//if 
           break; 
          }//case email 
        case "lt": 
        case "lessthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }//if 
            if(eval(objValue.value) >=  eval(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : value should be less than "+ cmdvalue; 
              }//if               
              alert(strError); 
              return false;                 
             }//if             
            break; 
         }//case lessthan 
        case "gt": 
        case "greaterthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }//if 
             if(eval(objValue.value) <=  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : value should be greater than "+ cmdvalue; 
               }//if               
               alert(strError); 
               return false;                 
             }//if             
            break; 
         }//case greaterthan 
        case "regexp": 
         { 
		 	if(objValue.value.length > 0)
			{
	            if(!objValue.value.match(cmdvalue)) 
	            { 
	              if(!strError || strError.length ==0) 
	              { 
	                strError = objValue.name+": Invalid characters found "; 
	              }//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 = objValue.name+": Please Select one option "; 
              }//if                                                               
              alert(strError); 
              return false;                                   
             } 
             break; 
         }//case dontselect 
    }//switch 
    return true; 
}
/*
	Copyright 2003 JavaScript-coder.com. All rights reserved.
*/