/*
 * Form Validator Error Message Constants
 */
 var d = new Date();
 
// gender
var SEL_GENDER="Please select your gender";

// date of birth month
var DOB_MM_REQ = "Please enter your birth month following this example: 1/12/1975.";
var DOB_MM_NUMERIC = "It looks you may have entered a letter for your birth month. Please re-enter your birth month using only numerals, following this example: 1/12/1975.";
var DOB_MM_LESS_THAN = "It looks like the month of your birth is an invalid value. Keep in mind a birth month can be no greater than 12. Please re-enter your month of birth.";
var DOB_MM_GREATER_THAN = "It looks like the month of your birth is an invalid value. Keep in mind a birth month can be no less than 1. Please re-enter your month of birth.";

// date of birth day
var DOB_DD_REQ = "Please enter your day of birth following this example: 1/12/1975.";
var DOB_DD_NUMERIC = "It looks like you might have entered a letter for the day of your birth. Please re-enter your birth day following this example: 1/12/1975.";
var DOB_DD_LESS_THAN = "It looks like the day of your birth is an invalid value. Keep in mind a birth day can be no greater than 31. Please re-enter your day of birth.";
var DOB_DD_GREATER_THAN = "It looks like the day of your birth is an invalid value. Keep in mind a birth day can be no less than 1. Please re-enter your day of birth.";

// date of birth year
var DOB_YYYY_REQ = "Your birth year is required.";
var DOB_YYYY_NUMERIC = "It looks like you might have entered a letter in your birth year. Please re-enter your birth year following this example: 1/12/1975.";
var DOB_YYYY_MIN_LEN = "Your birth year must be in 4 digits, for example: 1975.";
var DOB_YYYY_LESS_THAN = "Your birth year has to be "+d.getFullYear()+" or before.";
var DOB_YYYY_GREATER_THAN = "Your birth year has to be "+ (d.getFullYear()-100) +" or after.";

//date of birth in the future
var DOB_IN_FUTURE = "Your birth date can not be in the future.";

// height (feet)
var HEIGHT_FT_REQ = "Please enter your height in feet.";
var HEIGHT_FT_NUMERIC = "It looks like you might have entered an invalid character for your height in feet. Please enter your height using only numbers.";
var HEIGHT_FT_LESS_THAN = "It looks like you might have entered a number larger than 7. Your height should be 7 feet or less.";
var HEIGHT_FT_GREATER_THAN = "Please enter a positive number for your height in feet.";

// height (inches)
var HEIGHT_IN_REQ = "Please enter your height in inches.";
var HEIGHT_IN_NUMERIC = "It looks like you might have entered an invalid character for your height in inches. Please enter your height using only numbers.";
var HEIGHT_IN_LESS_THAN = "It looks like you might have entered a number larger than 11. Your height should be 11 inches or less.";
var HEIGHT_IN_GREATER_THAN = "Please enter a positive number for your height in inches.";
 
// weight
var WEIGHT_REQ = "Please enter your weight in pounds";
var WEIGHT_NUMERIC = "It looks like you might have entered an invalid character for your weight. Please enter your weight using only numbers.";
var WEIGHT_GREATER_THAN = "Please enter a positive number for your weight in pounds.";

// smoker
var SMOKER_REQ = "Do you smoke? Please select Yes or No.";

// first name
var FIRST_NAME_REQ = "Please enter your first name.";
var FIRST_NAME_MAX_LENGTH = "You can only enter up to 35 letters for your first name. Please re-enter your first name using fewer than 35 letters.";
var FIRST_NAME_NAME = "It looks like you may have entered a number for your first name. Please re-enter your first name using only letters.";

// last name
var LAST_NAME_REQ = "Please enter your last name.";
var LAST_NAME_MAX_LENGTH = "You can only enter up to 35 letters for your last name. Please re-enter your last name using fewer than 35 letters.";
var LAST_NAME_MIN_LENGTH = "You must enter at least 2 letters for your last name. Please re-enter your last name using at least 2 letters.";
var LAST_NAME_NAME = "It looks like you may have entered a number for your last name. Please re-enter your last name using only letters.";

// health conditions
var HEALTH_CONDITIONS_SEL = "Do you have any current major medical problem?";
var HEALTH_CONDITIONS_REQ = "Please specify pre-existing health conditions. If you have no pre-existing conditions, please select \"No\".";

// address
var ADDRESS_STREET_REQ = "Please enter your address following the following example: 123 Main St. Apt#2";
var ADDRESS_STREET_ADDRESS = "It looks like you entered an invalid character for your address. Please re-enter your address.";
var ADDRESS_STREET_ALPHADIGIT = "Please enter a valid address with your street name and number.";

// city
var ADDRESS_CITY_REQ = "Please enter your city.";
var ADDRESS_CITY_CITY = "It looks like you entered an invalid character for your city. Please re-enter your city using only letters.";
var ADDRESS_CITY_MIN_LENGTH = "It looks like you entered your city incorrectly. Please re-enter your city using only letters.";

// state
var ADDRESS_STATE_REQ = "Please select your state.";

// zip code
var ADDRESS_ZIP_REQ = "Please enter your valid 5-digit zip code.";
var ADDRESS_ZIP_MIN_LENGTH = "It looks like you entered an invalid zip code with less than 5 digits. Please re-enter your 5-digit zip code.";
var ADDRESS_ZIP_NUMERIC = "It looks like you entered an invalid character for your zip code. Please re-enter your 5-digit zip code using only numbers.";

// phone (part 1)
var PHONE_1_REQ = "Please enter your 3-digit area code using the following example: 123-123-1234";
var PHONE_1_NUMERIC = "It looks like you entered an invalid character for your area code. Please re-enter your 3-digit area code using the following example: 123-123-1234";
var PHONE_1_MIN_LENGTH = "It looks like you entered too few digits your area code. Please re-enter your 3-digit area code using the following example: 123-123-1234";

// phone (part 2)
var PHONE_2_REQ = "Please enter the first part of your phone number.";
var PHONE_2_NUMERIC = "It looks like you entered a letter or invalid character for the first part of your phone number. Please re-enter your number using only numbers.";
var PHONE_2_MIN_LENGTH = "It looks like you entered too few digits for the first part of your phone number. Please re-enter your number using the following example: 123-123-1234";

// phone (part 3)
var PHONE_3_REQ = "Please enter the second part of your phone number.";
var PHONE_3_NUMERIC = "It looks like you entered a letter or invalid character for the second part of your phone number. Please re-enter your number using only numbers.";
var PHONE_3_MIN_LENGTH = "It looks like you entered too few digits for the second part of your phone number. Please re-enter your number using the following example: 123-123-1234";
 
// password
var PASSWORD_REQ = "Please enter your password to resume your application.";

// email address
var EMAIL_REQ = "Please enter your email address using the following example: email@mydomain.com";
var EMAIL_EMAIL = "It looks like you entered an invalid character for your email address. Please re-enter your email using only periods, hyphens, or underscores.";
 
// spouse gender
var SPOUSE_SEL_GENDER = "Please select your spouse's gender.";
 
// spouse smoking history
var SPOUSE_SEL_SMOKING = "Does your spouse smoke? Please select yes or no.";
 
// spouse date of birth month
var SPOUSE_DOB_MM_REQ = "Please enter your spouse's birth month following this example: 1/12/1975.";
var SPOUSE_DOB_MM_NUMERIC = "It looks you may have entered a letter for your spouse's birth month. Please re-enter your spouse's birth month using only numerals, following this example: 1/12/1975.";
var SPOUSE_DOB_MM_LESS_THAN = "It looks like the month of your spouse's birth is an invalid value. Keep in mind a birth month can be no greater than 12. Please re-enter your spouse's month of birth.";
var SPOUSE_DOB_MM_GREATER_THAN = "It looks like the month of your spouse's birth is an invalid value. Keep in mind a birth month can be no less than 1. Please re-enter your spouse's month of birth.";
 
// spouse date of birth day
var SPOUSE_DOB_DD_REQ = "Please enter your spouse's day of birth following this example: 1/12/1975.";
var SPOUSE_DOB_DD_NUMERIC = "It looks like you might have entered a letter for the day of your spouse's birth. Please re-enter your spouse's birth day following this example: 1/12/1975.";
var SPOUSE_DOB_DD_LESS_THAN = "It looks like the day of your spouse's birth is an invalid value. Keep in mind a birth day can be no greater than 31. Please re-enter your spouse's day of birth.";
var SPOUSE_DOB_DD_GREATER_THAN = "It looks like the day of your spouse's birth is an invalid value. Keep in mind a birth day can be no less than 1. Please re-enter your spouse's day of birth.";

// spouse date of birth year
var SPOUSE_DOB_YYYY_REQ = "Your spouse's birth year is required.";
var SPOUSE_DOB_YYYY_NUMERIC = "It looks like you might have entered a letter in your spouse's birth year. Please re-enter your spouse's birth year following this example: 1/12/1975.";
var SPOUSE_DOB_YYYY_MIN_LEN = "Your spouse's birth year must be in 4 digits, for example: 1975.";
var SPOUSE_DOB_YYYY_LESS_THAN = "Your spouse's birth year has to be "+d.getFullYear()+" or before.";
var SPOUSE_DOB_YYYY_GREATER_THAN = "Your spouse's birth year has to be "+ (d.getFullYear()-100) +" or after.";

//date of birth in the future
var SPOUSE_DOB_IN_FUTURE = "Your spouse's birth date can not be in the future.";

// spouse height (feet)
var SPOUSE_HEIGHT_FT_REQ = "Please enter your spouse's height in feet.";
var SPOUSE_HEIGHT_FT_NUMERIC = "It looks like you might have entered an invalid character for your spouse's height in feet. Please enter your spouse's height using only numbers.";
var SPOUSE_HEIGHT_FT_LESS_THAN = "It looks like you might have entered a number larger than 7. Your spouse's height should be 7 feet or less.";
var SPOUSE_HEIGHT_FT_GREATER_THAN = "Please enter a positive number for your spouse's height in feet.";

// spouse height (inches)
var SPOUSE_HEIGHT_IN_REQ = "Please enter your spouse's height in inches.";
var SPOUSE_HEIGHT_IN_NUMERIC = "It looks like you might have entered an invalid character for your spouse's height in inches. Please enter your spouse's height using only numbers.";
var SPOUSE_HEIGHT_IN_LESS_THAN = "It looks like you might have entered a number larger than 11. Your spouse's height should be 11 inches or less.";
var SPOUSE_HEIGHT_IN_GREATER_THAN = "Please enter a positive number for your spouse's height in inches.";

// spouse weight
var SPOUSE_WEIGHT_REQ = "Please enter your spouse's weight in pounds";
var SPOUSE_WEIGHT_NUMERIC = "It looks like you might have entered an invalid character for your spouse's weight. Please enter your spouse's weight using only numbers.";
var SPOUSE_WEIGHT_GREATER_THAN = "Please enter a positive number for your spouse's weight in pounds.";

// child gender
var CHILD_SEL_GENDER="Please select your child's gender";

// child date of birth month
var CHILD_DOB_MM_REQ = "Please enter your child's birth month following this example: 1/12/1975.";
var CHILD_DOB_MM_NUMERIC = "It looks you may have entered a letter for your child's birth month. Please re-enter your child's birth month using only numerals, following this example: 1/12/1975.";
var CHILD_DOB_MM_LESS_THAN = "It looks like the month of your child's birth is an invalid value. Keep in mind a birth month can be no greater than 12. Please re-enter your child's month of birth.";
var CHILD_DOB_MM_GREATER_THAN = "It looks like the month of your child's birth is an invalid value. Keep in mind a birth month can be no less than 1. Please re-enter your child's month of birth.";

// child date of birth day
var CHILD_DOB_DD_REQ = "Please enter your child's day of birth following this example: 1/12/1975.";
var CHILD_DOB_DD_NUMERIC = "It looks like you might have entered a letter for the day of your child's birth. Please re-enter your child's birth day following this example: 1/12/1975.";
var CHILD_DOB_DD_LESS_THAN = "It looks like the day of your child's birth is an invalid value. Keep in mind a birth day can be no greater than 31. Please re-enter your child's day of birth.";
var CHILD_DOB_DD_GREATER_THAN = "It looks like the day of your child's birth is an invalid value. Keep in mind a birth day can be no less than 1. Please re-enter your child's day of birth.";

//date of birth in the future
var CHILD_DOB_IN_FUTURE = "Your child's birth date can not be in the future.";

// child date of birth year
var CHILD_DOB_YYYY_REQ = "Your child's birth year is required.";
var CHILD_DOB_YYYY_NUMERIC = "It looks like you might have entered a letter in your child's birth year. Please re-enter your child's birth year following this example: 1/12/1975.";
var CHILD_DOB_YYYY_MIN_LEN = "Your child's birth year must be in 4 digits, for example: 1975.";
var CHILD_DOB_YYYY_LESS_THAN = "Your child's birth year has to be "+d.getFullYear()+" or before.";
var CHILD_DOB_YYYY_GREATER_THAN = "Your child's birth year has to be "+ (d.getFullYear()-100) +" or after.";

// child height (feet)
var CHILD_HEIGHT_FT_REQ = "Please enter your child's height in feet.";
var CHILD_HEIGHT_FT_NUMERIC = "It looks like you might have entered an invalid character for your child's height in feet. Please enter your child's height using only numbers.";
var CHILD_HEIGHT_FT_LESS_THAN = "It looks like you might have entered a number larger than 7. Your child's height should be 7 feet or less.";
var CHILD_HEIGHT_FT_GREATER_THAN = "Please enter a positive number for your child's height in feet.";

// child height (inches)
var CHILD_HEIGHT_IN_REQ = "Please enter your child's height in inches.";
var CHILD_HEIGHT_IN_NUMERIC = "It looks like you might have entered an invalid character for your child's height in inches. Please enter your child's height using only numbers.";
var CHILD_HEIGHT_IN_LESS_THAN = "It looks like you might have entered a number larger than 11. Your child's height should be 11 inches or less.";
var CHILD_HEIGHT_IN_GREATER_THAN = "Please enter a positive number for your child's height in inches.";

// child weight
var CHILD_WEIGHT_REQ = "Please enter your child's weight in pounds";
var CHILD_WEIGHT_NUMERIC = "It looks like you might have entered an invalid character for your child's weight. Please enter your child's weight using only numbers.";
var CHILD_WEIGHT_GREATER_THAN = "Please enter a positive number for your child's weight in pounds.";

//date of birth in the future
var EMPLOYEE_DOB_IN_FUTURE = "Your employee's date of birth can not be in the future.";

/**
 * Returns true if the month/day/year after the param date.
 * 
 * @param month 0-11
 * @param day 1-31
 * @param year 
 * @param date Date Object
 * @return
 */
function isInFuture(month, day, year, today){
	var date1=new Date(year,month,day,0,0,0);
	return date1>today;
}

/*
  -------------------------------------------------------------------------
		      JavaScript Form Validator (gen_validatorv31.js)
              Version 3.1.1
	Copyright (C) 2003-2008 JavaScript-Coder.com. All rights reserved.
	You can freely use this script in your Web pages.
	You may adapt this script for your own needs, provided these opening credit
    lines are kept intact.
		
	The Form validation script is distributed free from JavaScript-Coder.com
	For updates, please visit:
	http://www.javascript-coder.com/html-form/javascript-form-validation.phtml
	
	Questions & comments please send to form.val at javascript-coder.com
  -------------------------------------------------------------------------  
*/
function Validator(frmname)
{
  this.formobj=document.forms[frmname];
	if(!this.formobj)
	{
	  alert("Error: 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._sfm_form_name=frmname;
	this.formobj.onsubmit=form_submit_handler;
	this.addValidation = add_validation;
	this.setAddnlValidationFunction=set_addnl_vfunction;
	this.clearAllValidations = clear_all_validations;
    this.disable_validations = false;//new
    document.error_disp_handler = new sfm_ErrorDisplayHandler();
    this.EnableOnPageErrorDisplay=validator_enable_OPED;
	this.EnableOnPageErrorDisplaySingleBox=validator_enable_OPED_SB;
    this.show_errors_together=true;
    this.EnableMsgsTogether=sfm_enable_show_msgs_together;
}
function set_addnl_vfunction(functionname)
{
  this.formobj.addnlvalidation = functionname;
}
function sfm_enable_show_msgs_together()
{
    this.show_errors_together=true;
    this.formobj.show_errors_together=true;
}
function clear_all_validations()
{
	for(var itr=0;itr < this.formobj.elements.length;itr++)
	{
		this.formobj.elements[itr].validationset = null;
	}
}
function form_submit_handler()
{
   var bRet = true;
    document.error_disp_handler.clear_msgs();
	
	var form = this;
	if(form_submit_handler.caller != null)
		form=frmvalidator.formobj;
	
	for(var itr=0;itr < form.elements.length;itr++)
	{
		if(form.elements[itr].validationset &&
	   !form.elements[itr].validationset.validate())
		{
		  bRet = false;
		}
        if(!bRet && !form.show_errors_together)
        {
          break;
        }
	}
    if(!bRet)
    {
      document.error_disp_handler.FinalShowMsg();
      return false;
    }

	if(form.addnlvalidation)
	{
	  str =" var ret = "+form.addnlvalidation+"()";
	  eval(str);
    if(!ret) return ret;
	}
	return true;
}
function add_validation(itemname,descriptor,errstr)
{
	var condition = null;
	if(arguments.length > 3)
	{
	 condition = arguments[3]; 
	}
  if(!this.formobj)
	{
		alert("Error: The form object is not set properly");
		return;
	}//if
	var itemobj = this.formobj[itemname];
    if(itemobj.length && isNaN(itemobj.selectedIndex) )
    //for radio button; don't do for 'select' item
	{
		itemobj = itemobj[0];
	}	
  if(!itemobj)
	{
		alert("Error: Couldnot get the input object named: "+itemname);
		return;
	}
	if(!itemobj.validationset)
	{
		itemobj.validationset = new ValidationSet(itemobj,this.show_errors_together);
	}
	itemobj.validationset.add(descriptor,errstr,condition);
    itemobj.validatorobj=this;
}
function validator_enable_OPED()
{
    document.error_disp_handler.EnableOnPageDisplay(false);
}

function validator_enable_OPED_SB()
{
	document.error_disp_handler.EnableOnPageDisplay(true);
}
function sfm_ErrorDisplayHandler()
{
  this.msgdisplay = new AlertMsgDisplayer();
  this.EnableOnPageDisplay= edh_EnableOnPageDisplay;
  this.ShowMsg=edh_ShowMsg;
  this.FinalShowMsg=edh_FinalShowMsg;
  this.all_msgs=new Array();
  this.clear_msgs=edh_clear_msgs;
}
function edh_clear_msgs()
{
    this.msgdisplay.clearmsg(this.all_msgs);
    this.all_msgs = new Array();
}
function edh_FinalShowMsg()
{
    this.msgdisplay.showmsg(this.all_msgs);
}
function edh_EnableOnPageDisplay(single_box)
{
	if(true == single_box)
	{
		this.msgdisplay = new SingleBoxErrorDisplay();
	}
	else
	{
		this.msgdisplay = new DivMsgDisplayer();		
	}
}
function edh_ShowMsg(msg,input_element)
{
	
   var objmsg = new Array();
   objmsg["input_element"] = input_element;
   objmsg["msg"] =  msg;
   this.all_msgs.push(objmsg);
}
function AlertMsgDisplayer()
{
  this.showmsg = alert_showmsg;
  this.clearmsg=alert_clearmsg;
}
function alert_clearmsg(msgs)
{

}
function alert_showmsg(msgs)
{
    var whole_msg="";
    var first_elmnt=null;
    for(var m=0;m < msgs.length;m++)
    {
        if(null == first_elmnt)
        {
            first_elmnt = msgs[m]["input_element"];
        }
        whole_msg += msgs[m]["msg"] + "\n";
    }
	
    alert(whole_msg);

    if(null != first_elmnt)
    {
		try{
			first_elmnt.focus();
		}catch(err){
			//ignore IE error about not focusing
		}
    }
}
function sfm_show_error_msg(msg,input_elmt)
{
    document.error_disp_handler.ShowMsg(msg,input_elmt);
}
function SingleBoxErrorDisplay()
{
 this.showmsg=sb_div_showmsg;
 this.clearmsg=sb_div_clearmsg;
}

function sb_div_clearmsg(msgs)
{
	var divname = form_error_div_name(msgs);
	show_div_msg(divname,"");
}

function sb_div_showmsg(msgs)
{
	var whole_msg="<ul>\n";
	for(var m=0;m < msgs.length;m++)
    {
        whole_msg += "<li>" + msgs[m]["msg"] + "</li>\n";
    }
	whole_msg += "</ul>";
	var divname = form_error_div_name(msgs);
	show_div_msg(divname,whole_msg);
}
function form_error_div_name(msgs)
{
	var input_element= null;

	for(var m in msgs)
	{
	 input_element = msgs[m]["input_element"];
	 if(input_element){break;}
	}

	var divname ="";
	if(input_element)
	{
	 divname = input_element.form._sfm_form_name + "_errorloc";
	}

	return divname;
}
function DivMsgDisplayer()
{
 this.showmsg=div_showmsg;
 this.clearmsg=div_clearmsg;
}
function div_clearmsg(msgs)
{
    for(var m in msgs)
    {
        var divname = element_div_name(msgs[m]["input_element"]);
        show_div_msg(divname,"");
    }
}
function element_div_name(input_element)
{
  var divname = input_element.form._sfm_form_name + "_" + 
                   input_element.name + "_errorloc";

  divname = divname.replace(/[\[\]]/gi,"");

  return divname;
}
function div_showmsg(msgs)
{
    var whole_msg;
    var first_elmnt=null;
    for(var m in msgs)
    {
        if(null == first_elmnt)
        {
            first_elmnt = msgs[m]["input_element"];
        }
        var divname = element_div_name(msgs[m]["input_element"]);
        show_div_msg(divname,msgs[m]["msg"]);
    }
    if(null != first_elmnt)
    {
		try{
			first_elmnt.focus();
		}catch(err){
			//ignore IE error message
		}
        
    }
}
function show_div_msg(divname,msgstring)
{
	if(divname.length<=0) return false;

	if(document.layers)
	{
		divlayer = document.layers[divname];
        if(!divlayer){return;}
		divlayer.document.open();
		divlayer.document.write(msgstring);
		divlayer.document.close();
	}
	else
	if(document.all)
	{
		divlayer = document.all[divname];
        if(!divlayer){return;}
		divlayer.innerHTML=msgstring;
	}
	else
	if(document.getElementById)
	{
		divlayer = document.getElementById(divname);
        if(!divlayer){return;}
		divlayer.innerHTML =msgstring;
	}
	divlayer.style.visibility="visible";	
	return false;
}
function ValidationDesc(inputitem,desc,error,condition)
{
  this.desc=desc;
	this.error=error;
	this.itemobj = inputitem;
	this.condition = condition;
	this.validate=vdesc_validate;
}
function vdesc_validate()
{
	if(this.condition != null )
	{
		if(!eval(this.condition))
		{
			return true;
		}
	}
	if(!validateInput(this.desc,this.itemobj,this.error))
	{
		this.itemobj.validatorobj.disable_validations=true;
      try{
			this.itemobj.focus()
		}catch(err){
			//ignore IE error message
		}
		return false;
	}

	return true;
}
function ValidationSet(inputitem,msgs_together)
{
    this.vSet=new Array();
	this.add= add_validationdesc;
	this.validate= vset_validate;
	this.itemobj = inputitem;
    this.msgs_together = msgs_together;
}
function add_validationdesc(desc,error,condition)
{
  this.vSet[this.vSet.length]= 
  new ValidationDesc(this.itemobj,desc,error,condition);
}
function vset_validate()
{
    var bRet = true;
    for(var itr=0;itr<this.vSet.length;itr++)
    {
        bRet = bRet && this.vSet[itr].validate();
        if(!bRet && !this.msgs_together)
        {
            break;
        }
    }
    return bRet;
}
function validateEmail(email)
{
    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 IsCheckSelected(objValue,chkValue)
{
    var selected=false;
	var objcheck = objValue.form.elements[objValue.name];
    if(objcheck.length)
	{
		var idxchk=-1;
		for(var c=0;c < objcheck.length;c++)
		{
		   if(objcheck[c].value == chkValue)
		   {
		     idxchk=c;
			 break;
		   }//if
		}//for
		if(idxchk>= 0)
		{
		  if(objcheck[idxchk].checked=="1")
		  {
		    selected=true;
		  }
		}//if
	}
	else
	{
		if(objValue.checked == "1")
		{
			selected=true;
		}//if
	}//else	

	return selected;
}
function TestDontSelectChk(objValue,chkValue,strError)
{
	var pass = true;
	pass = IsCheckSelected(objValue,chkValue)?false:true;

	if(pass==false)
	{
     if(!strError || strError.length ==0) 
        { 
        	strError = "Can't Proceed as you selected "+objValue.name;  
        }//if			  
	  sfm_show_error_msg(strError,objValue);
	  
	}
    return pass;
}
function TestShouldSelectChk(objValue,chkValue,strError)
{
	var pass = true;

	pass = IsCheckSelected(objValue,chkValue)?true:false;

	if(pass==false)
	{
     if(!strError || strError.length ==0) 
        { 
        	strError = "You should select "+objValue.name;  
        }//if			  
	  sfm_show_error_msg(strError,objValue);
	  
	}
    return pass;
}
function TestRequiredInput(objValue,strError)
{
 var ret = true;
 var val = objValue.value;
 val = val.replace(/^\s+|\s+$/g,"");//trim
    if(eval(val.length) == 0) 
    { 
       if(!strError || strError.length ==0) 
       { 
         strError = objValue.name + " : Required Field"; 
       }//if 
       sfm_show_error_msg(strError,objValue); 
       ret=false; 
    }//if 
return ret;
}
function TestMaxLen(objValue,strMaxLen,strError)
{
 var ret = true;
    if(eval(objValue.value.length) > eval(strMaxLen)) 
    { 
      if(!strError || strError.length ==0) 
      { 
        strError = objValue.name + " : "+ strMaxLen +" characters maximum "; 
      }//if 
      sfm_show_error_msg(strError,objValue); 
      ret = false; 
    }//if 
return ret;
}
function TestMinLen(objValue,strMinLen,strError)
{
 var ret = true;
    if(eval(objValue.value.length) <  eval(strMinLen)) 
    { 
      if(!strError || strError.length ==0) 
      { 
        strError = objValue.name + " : " + strMinLen + " characters minimum  "; 
      }//if               
      sfm_show_error_msg(strError,objValue); 
      ret = false;   
    }//if 
return ret;
}
function TestInputType(objValue,strRegExp,strError,strDefaultError)
{
   var ret = true;

    var charpos = objValue.value.search(strRegExp); 
    if(objValue.value.length > 0 &&  charpos >= 0) 
    { 
     if(!strError || strError.length ==0) 
      { 
        strError = strDefaultError;
      }//if 
      sfm_show_error_msg(strError,objValue); 
      ret = false; 
    }//if 
 return ret;
}
function TestEmail(objValue,strError)
{
var ret = true;
     if(objValue.value.length > 0 && !validateEmail(objValue.value)	 ) 
     { 
       if(!strError || strError.length ==0) 
       { 
          strError = objValue.name+": Enter a valid Email address "; 
       }//if                                               
       sfm_show_error_msg(strError,objValue); 
       ret = false; 
     }//if 
return ret;
}
function TestLessThan(objValue,strLessThan,strError)
{
var ret = true;
	  if(isNaN(objValue.value)) 
	  { 
	    sfm_show_error_msg(objValue.name +": Should be a number ",objValue); 
	    ret = false; 
	  }//if 
	  else
	  if(eval(objValue.value) >=  eval(strLessThan)) 
	  { 
	    if(!strError || strError.length ==0) 
	    { 
	      strError = objValue.name + " : value should be less than "+ strLessThan; 
	    }//if               
	    sfm_show_error_msg(strError,objValue); 
	    ret = false;                 
	   }//if   
return ret;          
}
function TestGreaterThan(objValue,strGreaterThan,strError)
{
var ret = true;
     if(isNaN(objValue.value)) 
     { 
       sfm_show_error_msg(objValue.name+": Should be a number ",objValue); 
       ret = false; 
     }//if 
	 else
     if(eval(objValue.value) <=  eval(strGreaterThan)) 
      { 
        if(!strError || strError.length ==0) 
        { 
          strError = objValue.name + " : value should be greater than "+ strGreaterThan; 
        }//if               
        sfm_show_error_msg(strError,objValue);  
        ret = false;
      }//if  
return ret;           
}
function TestRegExp(objValue,strRegExp,strError)
{
var ret = true;
    if( objValue.value.length > 0 && 
        !objValue.value.match(strRegExp) ) 
    { 
      if(!strError || strError.length ==0) 
      { 
        strError = objValue.name+": Invalid characters found "; 
      }//if                                                               
      sfm_show_error_msg(strError,objValue); 
      ret = false;                   
    }//if 
return ret;
}
function TestDontSelect(objValue,dont_sel_index,strError)
{
var ret = true;
    if(objValue.selectedIndex == null) 
    { 
      sfm_show_error_msg("ERROR: dontselect command for non-select Item"); 
      ret =  false; 
    } 
    if(objValue.selectedIndex == eval(dont_sel_index)) 
    { 
     if(!strError || strError.length ==0) 
      { 
      strError = objValue.name+": Please Select one option "; 
      }//if                                                               
      sfm_show_error_msg(strError,objValue); 
      ret =  false;                                   
     } 
return ret;
}
function TestSelectOneRadio(objValue,strError)
{
	var objradio = objValue.form.elements[objValue.name];
	var one_selected=false;
	for(var r=0;r < objradio.length;r++)
	{
	  if(objradio[r].checked)
	  {
	  	one_selected=true;
		break;
	  }
	}
	if(false == one_selected)
	{
      if(!strError || strError.length ==0) 
       {
	    strError = "Please select one option from "+objValue.name;
	   }	
	  sfm_show_error_msg(strError,objValue);
	}
return one_selected;
}

function validateInput(strValidateStr,objValue,strError) 
{ 
    var ret = true;
    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": 
         { 
		   ret = TestRequiredInput(objValue,strError)
           break;             
         }//case required 
        case "maxlength": 
        case "maxlen": 
          { 
			 ret = TestMaxLen(objValue,cmdvalue,strError)
             break; 
          }//case maxlen 
        case "minlength": 
        case "minlen": 
           { 
			 ret = TestMinLen(objValue,cmdvalue,strError)
             break; 
            }//case minlen 
        case "alnum": 
        case "alphanumeric": 
           { 
				ret = TestInputType(objValue,"[^A-Za-z0-9]",strError, 
						objValue.name+": Only alpha-numeric characters allowed ");
				break; 
           }
        case "alnum_s": 
        case "alphanumeric_space": 
           { 
				ret = TestInputType(objValue,"[^A-Za-z0-9\\s]",strError, 
						objValue.name+": Only alpha-numeric characters and space allowed ");
				break; 
           }		   
        case "num": 
        case "numeric": 
           { 
                ret = TestInputType(objValue,"[^0-9]",strError, 
						objValue.name+": Only digits allowed ");
                break;               
           }
        case "dec": 
        case "decimal": 
           { 
                ret = TestInputType(objValue,"[^0-9\.]",strError, 
						objValue.name+": Only numbers allowed ");
                break;               
           }
        case "alphabetic": 
        case "alpha": 
           { 
                ret = TestInputType(objValue,"[^A-Za-z]",strError, 
						objValue.name+": Only alphabetic characters allowed ");
                break; 
           }
        case "alphabetic_space": 
        case "alpha_s": 
           { 
                ret = TestInputType(objValue,"[^A-Za-z\\s]",strError, 
						objValue.name+": Only alphabetic characters and space allowed ");
                break; 
           }
		case "city":
        case "name":
           { 
				ret = TestInputType(objValue,"[^A-Za-z\\s\.-]",strError, objValue.name+": Only alphabetic characters, dash, period and space allowed ");
				break; 
           }
        case "1alpha_1digit": 
           {
        	   // Searches for one digit and one letter
        	   ret = TestInputType(objValue,"((?!(.*[0-9])+)(^.*))|((?!(.*[A-Za-z])+)(^.*))",strError, objValue.name+": One letter and one digit is required ");
        	   break;
           }
		case "address": 
           { 
				ret = TestInputType(objValue,"[^A-Za-z0-9\\s\.#&-]",strError, objValue.name+": Only alpha-numeric characters, dash, period, ampersand, pound sign and space allowed ");
				break; 
           }	
        case "email": 
          { 
			   ret = TestEmail(objValue,strError);
               break; 
          }
        case "lt": 
        case "lessthan": 
         { 
    	      ret = TestLessThan(objValue,cmdvalue,strError);
              break; 
         }
        case "gt": 
        case "greaterthan": 
         { 
			ret = TestGreaterThan(objValue,cmdvalue,strError);
            break; 
         }//case greaterthan 
        case "regexp": 
         { 
			ret = TestRegExp(objValue,cmdvalue,strError);
           break; 
         }
        case "dontselect": 
         { 
			 ret = TestDontSelect(objValue,cmdvalue,strError)
             break; 
         }
		case "dontselectchk":
		{
			ret = TestDontSelectChk(objValue,cmdvalue,strError)
			break;
		}
		case "shouldselchk":
		{
			ret = TestShouldSelectChk(objValue,cmdvalue,strError)
			break;
		}
		case "selone_radio":
		{
			ret = TestSelectOneRadio(objValue,strError);
		    break;
		}		 
    }//switch 
	return ret;
}
function VWZ_IsListItemSelected(listname,value)
{
 for(var i=0;i < listname.options.length;i++)
 {
  if(listname.options[i].selected == true &&
   listname.options[i].value == value) 
   {
     return true;
   }
 }
 return false;
}
function VWZ_IsChecked(objcheck,value)
{
 if(objcheck.length)
 {
     for(var c=0;c < objcheck.length;c++)
     {
       if(objcheck[c].checked == "1" && 
	     objcheck[c].value == value)
       {
        return true; 
       }
     }
 }
 else
 {
  if(objcheck.checked == "1" )
   {
    return true; 
   }    
 }
 return false;
}
/*
	Copyright (C) 2003-2008 JavaScript-Coder.com . All rights reserved.
*/

