var form_Check=false;
var validation_msg_validation_head = "Validation errors";
var validation_exc_mandatory = "is mandatory";
var validation_exc_number_format = "number format incorrect";
var validation_exc_date_format = "date format incorrect";
var validation_exc_length = "length wrong";
var validation_exc_range = "out of range";
var validation_exc_regexp = "error on validation rules";
var validation_exc_mask_format = "error on mask rule";
var validation_msg_component="";

// =======================================================================
// GLOBAL VARIABLES
// =======================================================================

var validation_form;
var formName;
var validation_widgets  = new Array(); // WIDGET'S DATATYPE
var validation_widgetsI18N = new Array(); // WIDGET I18N descrizione nome campo
var validation_required = new Array(); // IS REQUIRED?
var validation_format   = new Array(); // SPECIAL FORMAT
var validation_user     = new Array(); // CUSTOM USER FUNCTION
var validation_length   = new Array(); // LENGTH
var validation_range    = new Array(); // RANGE
var validation_regexp   = new Array(); // REGEXP
var validation_accept 	= new Array(); // ACCEPT KEYS
var validation_pad	= new Array(); // AUTOMATI
var validationRequiredArray = new Array();
var validationRegExpArray = new Array();
var futureDateAllowed_err_msg = new Array();
var server_side_form  = new Array();
var server_side_errors = new Array();
var validation_messages = new Array(); // VALIDATION ERROR MESSAGES
var validation_mask_messages = new Array(); 
var validation_datatype_messages = new Array();
var validation_docheck   = new Array(); // WHICH FORMS TO CHECK

var errorsWithIdsAsKey   = new Array(); //TO MAP WIDGET'S ID'S TO ERROR MESSAGES
var errors = new Array();
// Validator Object
var valid = new Object();
var phone;
var phoneNo =0;
var show_payment_errors=false;

// REGEX Elements

// ArrivalDepartureNumber 
valid.adn1 = /^[0-9]{3}$/;
valid.adn2 = /^[0-9]{8}$/;

// matches cin number
valid.cin = /^[0-9]+$/;

// matches credit card number
valid.creditcardnumber = /^[0-9]+$/;

// matches all digits
valid.digits = /^[0-9]+$/;

//Height and Weight
valid.heightandweight=/^\d{1,3}(\.{0,1}\d{0,2})?$/;

// matches everything except digits
valid.alphabets = /^[a-zA-Z]+[\s|\-]?[a-zA-Z]+[\s|\-]?[a-zA-Z]*$/;


//Name as per efiling agency specific
valid.name=/^[a-zA-Z\s|\,|\.|\-|\'|\#]+$/;

//Name as per efiling agency specific validation changes
valid.newname=/^[a-zA-Z|\,|\.|\-|\'|\&]+$/;


//Common efiling agency specific 
valid.agencySpecific=/^[a-zA-Z0-9\s|\-|\,|\'|\.|\#]+$/;


//Middle Initial
valid.initial=/^[a-zA-Z]+$/;

// AlphaNumeric
valid.alphanumeric = /^[\s0-9a-zA-Z-]*$/;

// matches zip codes
valid.zipCode = /^\d{5,10}$/;
valid.careOfZipCode = /^\d{5}(-?\d{4})?$/;
valid.zipCode5or9 = /^\d{5}(-?\d{4})?$/;

// matches $17.23 or $14,281,545.45 or ...
valid.Currency = /^\$?\d{1,3}(,\d{3})*(\.\d{2})?$/;

//matches email
valid.emailAddress =  /^[\w_\.\-]+[a-zA-Z0-9]+@[\w.\-]+\.[a-zA-Z]{2,4}$/;


//matches phone ###-###-#######
valid.phoneNumberCountryCode = /^\d{3}$/;
valid.phoneNumberCityCode = /^\d{3}$/;
valid.phoneNumber = /^\d{7,10}$/;

// Social Security Number
valid.ssn1 = /^\d{3}$/;
valid.ssn2 = /^\d{2}$/;
valid.ssn3 = /^\d{4}$/;

// phone 
valid.newphone1 = /^\d{3}$/;
//valid.newphone2 = /^\d{7,10}$/;
valid.newphone2 = /^\d{7,10}$/;
valid.newphone3 = /^[\s\-\(\)\[\]\/\\\.\_\#]{0,20}[0-9]([\s\-\(\)\[\]\/\\\.\_\#0-9]){7,20}$/;

// Anumber
valid.anumber=/^(^[a|A]{1}|-{1})*\d{3}(-{1}|\s{1})*\d{3}(-{1}|\s{1})*(\d{2}|\d{3})$/;

//password
valid.password = /^[0-9A-Za-z\!\@\#\$\%\^\&\*\+\_\-\}\{\[\]\'\<\>\,\.\/\?\|]{6,11}$/;

//receipt
valid.receipt = /^[0-9|\*]+$/;

//liberal
valid.liberal=/^[a-zA-Z0-9\s|\'|\&|\*|\"|\,|\.|\#|\@|\\|\/]+$/;

//careOf
valid.careof=/^[a-zA-Z0-9\s|\,|\.|\-|\'|\#]+$/;

valid.cityName=/^[a-zA-Z\s]+$/



//Efile
valid.areaCode = /^\d{3}$/;
valid.phoneNumber1 = /^\d{3}$/;
valid.phoneNumber2 = /^\d{4}$/;
valid.phoneNumber3 = /^\d{7,15}$/;

function setDoCheck(iWidget,doIt) {
   validation_docheck[iWidget] = doIt;
}

function setRequired(iWidget,isRequired) {
   validation_required[iWidget] = isRequired;
}

function getWidgetValue(iName)
{
  var element = document.getElementsByName( iName );
  if(element[0] != null && element[0].type != null && element[0].type != undefined && element[0].type == "radio"){
        for (var i = 0; i < element.length; i++) {
            if (element[i].checked) {
                return element[i].value;
            }
        }
  }
  else if (element[0] != null && element[0].type != null && element[0].type != undefined && element[0].type == "checkbox")
  {
       for (var i = 0; i < element.length; i++) {         
        if (element[i].checked) {
            return element[i].value;
         }
       }

  }
  else
  {
        var field = validation_form.elements[iName];

        if( field != null )
            return trim(field.value);

  }
  return null;
}

function setWidgetValue( iName , value )
{
  var field = validation_form.elements[ iName ];
  if( field != null )
    field.value = value;
}

function isBlank(val)
{
	if(val==null)
	{
		return true;
	}
	for(var i=0;i<val.length;i++)
	{
		if((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r"))
		{
			return false;
		}
	}
	return true;
}

function isDigit(num)
{
	if(num.length>1)
	{
		return false;
	}
	var string="1234567890";
	if(string.indexOf(num)!=-1)
	{
		return true;
	}
return false;
}

function isInteger(val)
{
if(isBlank(val))
	{
		return false;
	}
for(var i=0;i<val.length;i++)
{
	if(!isDigit(val.charAt(i)))
	{
		return false;
	}
}
return true;
}

function isFloat( iValue )
{
  if( iValue == null || iValue == "" )
    return true;

  //TODO TEST ONLY THE TRUE CURRENCY FORMAT AND NOT BOTH
  //var reFloatF1 = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/;
  //var reFloatF2 = /^((\d+(\,\d*)?)|((\d*\,)?\d+))$/;
  //return reFloatF1.test( iValue ) || reFloatF2.test( iValue );
  //TODO works only with italian number pattern; extend to other locales
  var newReFloat = /^([\d\.]*(\,\d*)?)$/;
  return newReFloat.test(iValue);
}        
function validation_preRegister(iWidget,iMaskErrorMessage,iDataTypeErrorMessage)
{

if(iMaskErrorMessage != '' && iMaskErrorMessage != null)
validation_mask_messages[iWidget]=iMaskErrorMessage;
if(iDataTypeErrorMessage != '' && iDataTypeErrorMessage != null)
validation_datatype_messages[iWidget]=iDataTypeErrorMessage;
}
function validation_register( iWidget, iWidgetI18N, iRequired, iDatatype, iFormat, iUserFunction,iLength, iRange, iRegexp, iAccept, iErrorMessage) {
  validation_widgets[iWidget] = iDatatype;

  validation_widgetsI18N[iWidget] = iWidgetI18N;
  // REQUIRED
  if( iRequired )
    validation_required[iWidget] = true;
  else if( iRequired == null || iRequired == "null" || iRequired == false || iRequired == "false" )
      validation_required[iWidget] = false;


  // FORMAT
  if( iFormat )
    validation_format[iWidget] = iFormat;

  // USER FUNCTION
  if( iUserFunction )
    validation_user[iWidget] = iUserFunction;

  // LENGTH
  if( iLength )
    validation_length[iWidget] = iLength;

  // RANGE
  if( iRange )
    validation_range[iWidget] = iRange;
    
  // REGEXP
  if( iRegexp ){
    validation_regexp[iWidget] = iRegexp;
  }	
    
  if ( iAccept ) {
  	validation_accept[iWidget] = iAccept;
  } 
  
  if ( iErrorMessage ) {
	validation_msg_component = iErrorMessage;
  	validation_messages[iWidget] = iErrorMessage;
  }
}

/* the following function returns the trimmed value of the argument */

function trim(val) {
    if(val != null)
	return val.replace(/^\s+|\s+$/g,"");
        return null;
}

//***************************************************************************************************//
// the following function is to initialize validation of all the fields, that are within the given div
//***************************************************************************************************//

function initializeValidation(secid) {
    var divs=document.getElementById(secid);
    var select=divs.getElementsByTagName("select");
    var input=divs.getElementsByTagName("input");
    var textarea=divs.getElementsByTagName("textarea");
    
    // optimizing code sureshbabu Nov 23 part 2.
	// removed more number of dom operations 
    
    
    for( i=0 ;i<select.length;i++)
	{
    	var attributeName = select[i].getAttribute("name");
	    validationRequiredArray[attributeName] = validation_required[attributeName];
	}
    for( i=0 ;i<input.length;i++)
	{
    	var attributeName = input[i].getAttribute("name");
	    validationRequiredArray[attributeName] = validation_required[attributeName];
	    validationRegExpArray[attributeName] = validation_regexp[attributeName];
	}
    for( i=0 ;i<textarea.length;i++)
	{
    	var attributeName = textarea[i].getAttribute("name");
	    validationRequiredArray[attributeName] = validation_required[attributeName];
	    validationRegExpArray[attributeName] = validation_regexp[attributeName];
	}
}

//***************************************************************************************************//
// the following function is to disable validation of all the fields, that are within the given div
//***************************************************************************************************//
function disableValidation(secid) {
    var divs=document.getElementById(secid);
    var select=divs.getElementsByTagName("select");
    var input=divs.getElementsByTagName("input");
    var textarea=divs.getElementsByTagName("textarea");

    // optimizing code sureshbabu Nov 23 part 3.
	// removed more number of dom operations 
    
    for( i=0 ;i<select.length;i++)
	{
    	var attributeName = select[i].getAttribute("name");
	    validationRequiredArray[attributeName]=validation_required[attributeName];
	    validation_required[attributeName] = false;
	}
    for( i=0 ;i<input.length;i++)
	{
    	var attributeName = input[i].getAttribute("name");
	    validationRequiredArray[attributeName]=validation_required[attributeName];
	    validationRegExpArray[attributeName]=validation_regexp[attributeName];
	    validation_required[attributeName] = false;
	    validation_regexp[attributeName] = undefined;
	}
    for( i=0 ;i<textarea.length;i++)
	{
    	var attributeName = textarea[i].getAttribute("name");
	    validationRequiredArray[attributeName]=validation_required[attributeName];
	    validationRegExpArray[attributeName]=validation_regexp[attributeName];
	    validation_required[attributeName] = false;
	    validation_regexp[attributeName] = undefined;
	}
}

//***************************************************************************************************//
// the following function is to enable validation of all the fields, that are within the given div
//***************************************************************************************************//
function enableValidation(secid) {
	
    var divs=document.getElementById(secid);
    var select=divs.getElementsByTagName("select");
    var input=divs.getElementsByTagName("input");
    var textarea=divs.getElementsByTagName("textarea");

    for( i=0 ;i<select.length;i++)
	{
    	var attributeName = select[i].getAttribute("name");
	    validation_required[attributeName] = validationRequiredArray[attributeName];
	}
    for( i=0 ;i<input.length;i++)
	{
    	var attributeName = input[i].getAttribute("name");
	    validation_required[attributeName]=validationRequiredArray[attributeName];
	    validation_regexp[attributeName]=validationRegExpArray[attributeName];
	}
    for( i=0 ;i<textarea.length;i++)
	{
    	var attributeName = textarea[i].getAttribute("name");
	    validation_required[attributeName]=validationRequiredArray[attributeName];
	    validation_regexp[attributeName]=validationRegExpArray[attributeName];
	}
}

function validation_precheck_widget( iWidget )
{
  if( !iWidget || iWidget == null )
    return;
  var value = getWidgetValue( iWidget );
  var ret = null;
  // LENGTH
  var length = validation_length[iWidget];
  if( length != null && value != null )
  {
    var min   = length[0];
    var max   = length[1];
    var exact = length[2];

	var maxval = (max && max != null && value.length > max) ? max : 999999;
	if (exact && exact != null && exact < maxval) maxval = exact;
	if (maxval && maxval != null && value.length > maxval) {
		if (window.confirm(validation_widgetsI18N[widget] + validation_msg_trunk)) {
			value = value.substring(0,maxval);
			setWidgetValue(iWidget, value);
			ret = validation_msg_recheck;
		}
	} else if( min && min   != null && value.length < min) {
	
		var pad = validation_pad[iWidget];
		if (pad != null && value && value != null && value != '') {
			var side = pad[0];
			var val = pad[1];
			if (!side || side == null || side == '') side = 'left';
			if (val && val != null && val != '') {
				while (value.length < min) {
					if (side == 'left') {
						value = val + value;
					} else {
						value = value + val;
					}
				}
				if (maxval && maxval != null && value.length > maxval) {
					value = value.substring(0,maxval);
				}
				setWidgetValue(iWidget, value);
				ret = validation_msg_padrecheck;				
			}
		}
	}
  }
  return ret;
}

var datecomparecheck = 0;
var daterangecheck = 0;
var ssn = 0;
var adn = 0;
var receipt=0 ;
var creditcardcheck = 0;
var cin = 0;
var datecompare=false;
function validation_check_widget( iWidget )
{
  var value = getWidgetValue( iWidget );
	
  if(trim(value) == "")
  setWidgetValue(iWidget,trim(value));
  

  var datatype = validation_widgets[iWidget];
		
  if(iWidget.substring(iWidget.lastIndexOf('.')+1,iWidget.length) == 'ssn1')
  {
     ssn = 0; 
  }

  if(iWidget.substring(iWidget.lastIndexOf('.')+1,iWidget.length) == 'adn1')
  {
     adn = 0; 
  }
if( datatype == "signupPhone" )
  {
    var iwidget = iWidget.substring(0,iWidget.lastIndexOf("."));
    iwidget = iwidget.substring(0,iwidget.lastIndexOf("."));
    var areaCode = iwidget+".areaCode";
    var phone1 = iwidget+".phone1";
    var phone2 = iwidget+".phone2";
    var phone3 = iwidget+".phone3";
    var country = iwidget+".country.countrymenu";
    var phone1Value = getWidgetValue(iwidget+".phone1");
    var phone2Value = getWidgetValue(iwidget+".phone2");
    var phone3Value = getWidgetValue(iwidget+".phone3");
    var areaCodeValue = getWidgetValue(iwidget+".areaCode");
    var countryValue = getWidgetValue(iwidget+".country.countrymenu");
    
       if(phone3Value != "" && countryValue == "")
        {
	  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
	  errors.push( [phone1,"", "Please select a country"] );
        }else if(phone3Value == "" && countryValue == "")
        {
         if(validation_required[iWidget] == true)
          {
           errorsWithIdsAsKey.push( [phone3, "error on validation rules" ] );
           errors.push( [ phone3,"", "Please complete the highlighted area"] );
          }
	}
       if((countryValue == "1" || countryValue == " 1"))
	{
         if((!areaCodeValue) && (!phone1Value) && (!phone2Value) ) 
	  {
	    errorsWithIdsAsKey.push( [areaCode, "error on validation rules" ] );
	    errors.push( [areaCode,"", "Please enter your area code and telephone number"] );
	  }else if((!areaCodeValue) && (phone1Value) && (phone2Value) ) 
	  {
	    errorsWithIdsAsKey.push( [areaCode, "error on validation rules" ] );
	    errors.push( [ areaCode,"", "Please enter the area code"] );
	  }else if(((areaCodeValue) && (!phone1Value) && (!phone2Value)) || ((areaCodeValue) && (!phone1Value) && (phone2Value)) || ((areaCodeValue) && (phone1Value) && (!phone2Value))) 
	  {
	    errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
	    errors.push( [ phone1,"", "Please enter the phone number"] );
	  }else if((areaCodeValue.search(valid[validation_regexp[areaCode]]) == -1) && (phone1Value.search(valid[validation_regexp[phone1]]) != -1) && (phone2Value.search(valid[validation_regexp[phone2]]) != -1)) 
	  {
	   if(areaCodeValue.search(/^[0-9]*$/) == -1)
	     {
	       errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
	       errors.push( [ phone1,"", "Please enter numbers only."] );
	     }else{
	       errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
	       errors.push( [ phone1,"", "The area code you entered is incorrect"] );
	     }
	  }else if(((areaCodeValue.search(valid[validation_regexp[areaCode]]) != -1) && (phone1Value.search(valid[validation_regexp[phone1]]) == -1) && (phone2Value.search(valid[validation_regexp[phone2]]) != -1)) || ((areaCodeValue.search(valid[validation_regexp[areaCode]]) != -1) && (phone1Value.search(valid[validation_regexp[phone1]]) != -1) && (phone2Value.search(valid[validation_regexp[phone2]]) == -1)) || ((areaCodeValue.search(valid[validation_regexp[areaCode]]) != -1) && (phone1Value.search(valid[validation_regexp[phone1]]) == -1) && (phone2Value.search(valid[validation_regexp[phone2]]) == -1))|| ((areaCodeValue.search(valid[validation_regexp[areaCode]]) == -1) && (phone1Value.search(valid[validation_regexp[phone1]]) == -1) && (phone2Value.search(valid[validation_regexp[phone2]]) == -1)) || ((areaCodeValue.search(valid[validation_regexp[areaCode]]) == -1) && (phone1Value.search(valid[validation_regexp[phone1]]) == -1) && (phone2Value.search(valid[validation_regexp[phone2]]) != -1)) || ((areaCodeValue.search(valid[validation_regexp[areaCode]]) == -1) && (phone1Value.search(valid[validation_regexp[phone1]]) != -1) && (phone2Value.search(valid[validation_regexp[phone2]]) == -1))) 
	  {
	      if(phone1Value.search(/^[0-9]*$/) == -1 || phone2Value.search(/^[0-9]*$/) == -1 ||areaCodeValue.search(/^[0-9]*$/) == -1)
	     {
	       errorsWithIdsAsKey.push( [phone3, "error on validation rules" ] );
	       errors.push( [ phone3,"", "Please enter numbers only"] );
	     }else{
	       errorsWithIdsAsKey.push( [phone3, "error on validation rules" ] );
	       errors.push( [ phone3,"", "The phone number you entered is incorrect"] );
	     }
	   }

        }else 
	  {	
	     if((!phone3Value) && (countryValue != "")) 
	      {
		errorsWithIdsAsKey.push( [phone3, "error on validation rules" ] );
		errors.push( [phone3,"", "Please enter your phone number"] );	     	 
	      }else if((phone3Value.search(valid[validation_regexp[phone3]]) == -1) && (countryValue != ""))
	      {		
		  if(phone3Value.search(/^[0-9]*$/) == -1)
		 {
		   errorsWithIdsAsKey.push([phone2, "error on validation rules" ] );
		   errors.push([phone2,"", "Please enter numbers only"] );
                 }else {
		   errorsWithIdsAsKey.push([phone2, "error on validation rules" ] );
		   errors.push([phone2,"", "The phone number you entered is incorrect"] );
		 }
	      }

	 }
}
  if( datatype == "newphone" )
      {
	  var iwidget = iWidget.substring(0,iWidget.lastIndexOf("."));
	  iwidget = iwidget.substring(0,iwidget.lastIndexOf("."));
	  var phone1 = iwidget+".phone1";
	  var phone2 = iwidget+".phone2";
	  var phone3 = iwidget+".phone3";
	  var country = iwidget+".country.countrymenu";
	  var phone1value = getWidgetValue(iwidget+".phone1");
	  var phone2value = getWidgetValue(iwidget+".phone2");
	  var phone3value = getWidgetValue(iwidget+".phone3");
	  var countryvalue = getWidgetValue(iwidget+".country.countrymenu");

	  if (phone3value != "" && countryvalue == "")
              {
		  errorsWithIdsAsKey.push( [phone3, "error on validation rules" ] );
		  errors.push( [ phone3,"", "Please choose one of the options."] );
              }else if (phone3value == "" && countryvalue == "")
              {
                  errorsWithIdsAsKey.push( [phone3, "error on validation rules" ] );
                  errors.push( [ phone3,"", "You must complete this field to continue."] );

              }
	  if((countryvalue == "1" || countryvalue == " 1"))
	      {
		  if((!phone1value) && (!phone2value) ) 
		      {
			if(validation_required[iWidget] == true)
			{
			  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
			  errors.push( [ phone1,"", "Please enter a valid phone number."] );
			}
		      }
		  else if((!phone1value) && (phone2value) ) 
		      {
			  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
			  errors.push( [ phone1,"", "Please enter a valid phone number."] );
		      }
		  else if((phone1value) && (!phone2value) ) 
		      {
			  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
			  errors.push( [ phone1,"", "Please enter a valid phone number."] );
		      }
		  else
		      { // TODO sureshbabu optimization required for calling the methos in each if loop below.
			  if((phone1value.search(valid[validation_regexp[phone1]]) == -1) && (phone2value.search(valid[validation_regexp[phone2]]) != -1)) 
			      {
				  if(phone1value.search(/^[0-9]*$/) == -1)
				      {
					  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
					  errors.push( [ phone1,"", "Your entry may include only digits."] );

				      }
				  else
				      {
					  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
					  errors.push( [ phone1,"", "Your entry may include only digits."] );
				      }
			      }
			  else if((phone1value.search(valid[validation_regexp[phone1]]) != -1) && (phone2value.search(valid[validation_regexp[phone2]]) == -1)) 
			      {
				  if(phone2value.search(/^[0-9]*$/) == -1)
				      {
					  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
					  errors.push( [ phone1,"", "Your entry may include only digits."] );
				      }
				  else
				      {
					  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
					  errors.push( [ phone1,"", "Your entry may include only digits."] );
				      }
			      }
			  else if((phone1value.search(valid[validation_regexp[phone1]]) == -1) && (phone2value.search(valid[validation_regexp[phone2]]) == -1)) 
			      {
				  if((phone1value.search(/^[0-9]*$/) == -1) || (phone2value.search(/^[0-9]*$/) == -1))
				      {
					  errorsWithIdsAsKey.push( [phone1, "error on validation rules"] );
					  errors.push( [phone1,"", "Your entry may include only digits."] );
				      }
				  else
				      {
					  errorsWithIdsAsKey.push( [phone1, "error on validation rules"] );
					  errors.push( [phone1,"", "Your entry may include only digits."] );
				      }
			      }
		      }
	      }

	  else
	      {
		  if(phone3value == "" &&  countryvalue != "")
		      {
			if(validation_required[iWidget] == true)
			{
			  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
			  errors.push( [ phone1,"", "Please enter a valid phone number."] );
			}
		      }
		  else if((phone3value) && (phone3value.search(valid[validation_regexp[phone3]]) == -1) && countryvalue != "")
		      {
			  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
			  errors.push( [ phone1,"", "Your entry may include only digits."] );
		      }
	      }
      }


if( datatype == "passwordcheck" )
  {
	confirmpasswordiWidget = "confirm" + iWidget.substring(0,iWidget.length);
	var passwordValue = getWidgetValue(iWidget);
	var confirmpasswordValue = getWidgetValue(confirmpasswordiWidget);
	var passwordStatus;

	var passwordregexp = validation_regexp[iWidget];
	var confirmpasswordregexp = validation_regexp[confirmpasswordiWidget];
	// TODO sureshbabu optimization required for calling the methos in each if loop below.
	if ((passwordValue != null && passwordValue != '' && passwordValue != undefined) && (confirmpasswordValue != null && confirmpasswordValue != '' && confirmpasswordValue != undefined ) && (passwordValue.search(valid[passwordregexp]) != -1) && (confirmpasswordValue.search(valid[confirmpasswordregexp]) != -1))
	{
	 passwordStatus = doPasswordCheck(getWidgetValue(iWidget),getWidgetValue(confirmpasswordiWidget));
		
	if (passwordStatus == false)
	{
	   errorsWithIdsAsKey.push( [iWidget, "error on validation rules" ] );
	   errorsWithIdsAsKey.push( [confirmpasswordiWidget, "error on validation rules" ] );
	   errors.push( [ confirmpasswordiWidget,"", validation_datatype_messages[ iWidget ] ] );
	}
	}
	if(passwordStatus == false)
	    return validation_exc_number_format;
 
 
  }
 if( datatype == "currentpasswordcheck" )
  {

        confirmpasswordiWidget = "currentPasswordFrmBean";
        var currentpasswordValue = getWidgetValue(iWidget);
        var currentPasswordFrmBeanValue = getWidgetValue(confirmpasswordiWidget);
        var passwordStatus;
        var regexp = validation_regexp[iWidget];
        if ((currentpasswordValue != null && currentpasswordValue != '' && currentpasswordValue != undefined) && (currentPasswordFrmBeanValue != null && currentPasswordFrmBeanValue != '' && currentPasswordFrmBeanValue != undefined ))
        {
         passwordStatus = doPasswordCheck(getWidgetValue(iWidget),getWidgetValue(confirmpasswordiWidget));

        if (passwordStatus == false)
        {
           errorsWithIdsAsKey.push( [iWidget, "error on validation rules" ] );
           errors.push( [ iWidget,"", validation_datatype_messages[ iWidget ] ] );
        }
        }
        if(passwordStatus == false)
            return validation_exc_number_format;

  }


  if( datatype == "emailcheck" )
  {
        confirmemailiWidget = "confirm" + iWidget.substring(0,iWidget.length);
        var emailValue = getWidgetValue(iWidget);
        var confirmemailValue = getWidgetValue(confirmemailiWidget);
        var emailStatus;
        
	var emailregexp = validation_regexp[iWidget];
	var confirmemailregexp = validation_regexp[confirmemailiWidget];
        
        if ((emailValue != null && emailValue != '' && emailValue != undefined) && (confirmemailValue != null && confirmemailValue != '' && confirmemailValue != undefined ) && (emailValue.search(valid[emailregexp]) != -1) && (confirmemailValue.search(valid[confirmemailregexp]) != -1) )
        {
         emailStatus = doEmailCheck(getWidgetValue(iWidget),getWidgetValue(confirmemailiWidget));
        }
        if (emailStatus == false)
        {
	
	  errorsWithIdsAsKey.push( [iWidget, "error on validation rules" ] );
	  errorsWithIdsAsKey.push( [confirmemailiWidget, "error on validation rules" ] );
	  errors.push( [ iWidget,"", validation_datatype_messages[ iWidget ] ] );
        }
	if(emailStatus == false)
	   return validation_exc_number_format;
 
  }


  if( datatype == "creditcardcheck" )
  {
        cardNumberiWidget = "CARDNUM";
        var cardTypeValue = getWidgetValue(iWidget);
        var cardNumberValue = getWidgetValue(cardNumberiWidget);
        var creditcardStatus;
        if ((cardNumberValue != null && cardNumberValue != '' && cardNumberValue != undefined) && (cardTypeValue != null && cardTypeValue != '' && cardTypeValue != undefined && cardTypeValue != 'UNKNOWN' ))
        {
         creditcardStatus = doCreditCardCheck(getWidgetValue(cardNumberiWidget),getWidgetValue(iWidget));
	if(cardNumberValue.search(valid[validation_regexp[cardNumberiWidget]]) == -1)
	{
         errorsWithIdsAsKey.push( [cardNumberiWidget, "error on validation rules" ] );
if(validation_mask_messages[cardNumberiWidget] != "" && validation_mask_messages[cardNumberiWidget] != null && validation_mask_messages[cardNumberiWidget] != undefined)
          errors.push( [ cardNumberiWidget,"", validation_mask_messages[cardNumberiWidget] ] );
else
          errors.push( [ cardNumberiWidget,"", "Your entry must include only numbers." ] );
          creditcardcheck = 1;
          return validation_exc_number_format;
	}
        else if (creditcardStatus == false)
        {
	  errorsWithIdsAsKey.push( [iWidget, "error on validation rules" ] );
         errorsWithIdsAsKey.push( [cardNumberiWidget, "error on validation rules" ] );
	  errors.push( [ cardNumberiWidget,"", validation_datatype_messages[ cardNumberiWidget ] ] );
	  creditcardcheck = 1; 
	  return validation_exc_number_format;
        }
	}
  }

  if( datatype == "cvvcheck" )
  {
	var cinname = iWidget;
	var cinvalue = getWidgetValue(cinname)
	var cinlength = cinvalue.length;
	if(cinname == 'CIN')
	{
	  var ctname = 'cardType';
	  var ctvalue = getWidgetValue(ctname);
          
if(cinvalue != "" && cinvalue != null && cinvalue != undefined)
{
if(cinvalue.search(valid[validation_regexp[cinname]]) != -1)
{
	  if((ctvalue == 'ccamericanexp' || ctvalue == 'ccjcb') && cinvalue!='' &&  cinlength<4)
	  {
	    errorsWithIdsAsKey.push( [iWidget, "error on validation rules" ] );	
	    errors.push( [ iWidget,"",validation_datatype_messages[iWidget]]  );
cin = 1;
	  }
	  if(ctvalue == 'ccvisa' && cinvalue!='' && (cinlength < 3 || cinlength > 3 ))
	  {
	    errorsWithIdsAsKey.push( [iWidget, "error on validation rules" ] );
       	    errors.push( [ iWidget,"", validation_datatype_messages[iWidget]] ); 
cin = 1;
	  }
	  if(ctvalue == 'ccdiscover' && cinvalue!='' && (cinlength < 3 || cinlength > 3 ))
	  {
            errorsWithIdsAsKey.push( [iWidget, "error on validation rules" ] );
            errors.push( [ iWidget,"", validation_datatype_messages[iWidget]] ); 
cin = 1;
 	  }
	  if(ctvalue == 'ccmaster' && cinvalue!='' && (cinlength < 3 || cinlength > 3 ))
	  {
            errorsWithIdsAsKey.push( [iWidget, "error on validation rules" ] );
            errors.push( [ iWidget,"", validation_datatype_messages[iWidget]] ); 
cin = 1;
	  }
}
else
{
            errorsWithIdsAsKey.push( [iWidget, "error on validation rules" ] );
            errors.push( [ iWidget,"", "Your entry must include only numbers."] );
cin = 1;

}
}
  }

  }


  if( datatype == "expirydate" )
  {
	  yeariWidget = "year";
	monthiWidget = "month";
	monthyeariWidget = "monthyear";
        var yearValue = getWidgetValue(yeariWidget);
        var monthValue = getWidgetValue(iWidget);
        var monthyearValue = getWidgetValue(monthyeariWidget);
        var expirydateStatus;
        if (yearValue == '' && monthValue != '') 
        {
	  errorsWithIdsAsKey.push( [yeariWidget, "error on validation rules" ] );
	  errors.push( [ yeariWidget,"", "Please choose a date." ] );
	}
        else if (yearValue != '' && monthValue == '') 
        {
	  errorsWithIdsAsKey.push( [monthiWidget, "error on validation rules" ] );
	  errors.push( [ monthiWidget,"", "Please choose a date." ] );
	}
        else if (yearValue == '' && monthValue == '') 
        {
	  errorsWithIdsAsKey.push( [iWidget, "error on validation rules" ] );
	  errors.push( [ iWidget,"",validation_mask_messages[iWidget]]);
	}
	else if ((yearValue != null && yearValue != '' && yearValue != undefined) || (monthValue != null && monthValue != '' && monthValue != undefined ) || (monthyearValue != null && monthyearValue != '' && monthyearValue != undefined ))
        {
         expirydateStatus = doExpiryDateCheck(getWidgetValue(iWidget),getWidgetValue(yeariWidget),getWidgetValue(monthyeariWidget));
        
        if (!expirydateStatus)
        {
	  //pushErrorsId(iWidget, 'error on validation rules');
	  errorsWithIdsAsKey.push( [iWidget, "error on validation rules" ] );
	  errors.push( [ iWidget,"", validation_datatype_messages[ iWidget ] ] );
	  return validation_exc_number_format;
        }
	}
        else if (yearValue != null && yearValue != '' && yearValue != undefined)
        {
          return null;
        }

  }
  if( datatype == "marriageduration" )
  {
    var startDateiWidget=iWidget.substring(0,iWidget.lastIndexOf('.'));
	var endDateiWidget=startDateiWidget.substring(0,startDateiWidget.lastIndexOf('.'));
	endDateiWidget = endDateiWidget + ".dateMarriageEnded";
	var startDateiWidgetMonth =startDateiWidget + ".month";
	
       if ((getWidgetValue(startDateiWidget+".month") != null && getWidgetValue(startDateiWidget+".month") != '' && getWidgetValue(startDateiWidget+".month") != undefined) && (getWidgetValue(startDateiWidget+".day") != null && getWidgetValue(startDateiWidget+".day") != '' && getWidgetValue(startDateiWidget+".day") != undefined ) && (getWidgetValue(startDateiWidget+".year") != null && getWidgetValue(startDateiWidget+".year") != '' && getWidgetValue(startDateiWidget+".year") != undefined ) && (getWidgetValue(endDateiWidget+".month") != null && getWidgetValue(endDateiWidget+".month") != '' && getWidgetValue( endDateiWidget+".month") != undefined) && (getWidgetValue( endDateiWidget+".day") != null && getWidgetValue( endDateiWidget+".day") != '' && getWidgetValue( endDateiWidget+".day") != undefined ) && (getWidgetValue( endDateiWidget+".year") != null && getWidgetValue(endDateiWidget+".year") != '' && getWidgetValue(endDateiWidget+".year") != undefined ))
        {
        var startDateValue = getWidgetValue(startDateiWidget+".day") + " " +getWidgetValue(startDateiWidget+".month") +" "+ getWidgetValue(startDateiWidget+".year");

        var endDateValue = getWidgetValue( endDateiWidget+".day") + "  " + getWidgetValue( endDateiWidget+".month") + " "+ getWidgetValue( endDateiWidget+".year");

        if(!doDateCheck(startDateValue,endDateValue))
        {
          var iwidget=startDateiWidget + ".daterange";
          errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
          var tempWidget = startDateiWidget + ".month";
          errorsWithIdsAsKey.push( [tempWidget, "error on validation rules" ] );

          var tempWidget = endDateiWidget + ".month";
          errorsWithIdsAsKey.push( [tempWidget, "error on validation rules" ] );
          if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
          {
             errors.push( [ iwidget,"", validation_datatype_messages[ iwidget ] ] );
          }
          else
          {
             errors.push( [ iwidget,"", "Date of Marriage should be prior to Date Marriage Ended." ] );
          }
          return validation_exc_number_format;
        }
        return;
        }
  }



  if( datatype == "daterange" )
  {

    var fromDateiWidget = iWidget.substring(0,iWidget.lastIndexOf('.'));
	if(iWidget.indexOf('fromDate') != -1)
	    var toDateiWidget = iWidget.substring(0,iWidget.lastIndexOf('.')).replace('from','to');	
	else if(iWidget.indexOf('dateOfMarriage') != -1)
	    var toDateiWidget = iWidget.substring(0,iWidget.lastIndexOf('.')).replace('dateOfMarriage','dateMarriageEnded');	
	else return;
	
	//optimizing code sureshbabu Nov 23
	// Day variables
	var fromDateDay_DOM = validation_form.elements[fromDateiWidget+".day"];
	var fromDateDay = getWidgetValue(fromDateiWidget+".day");
	
	var toDateDay_DOM = validation_form.elements[toDateiWidget+".day"];
	var toDateDay = getWidgetValue(toDateiWidget+".day");
	
	// Month variables
	var fromDateMonth_DOM;
	var fromDateMonth = getWidgetValue(fromDateiWidget+".month");
	
	var toDateMonth_DOM = validation_form.elements[toDateiWidget+".month"];
	var toDateMonth = getWidgetValue(toDateiWidget+".month"); 
	
	// Year variables
	var fromDateYear_DOM;
	var fromDateYear = getWidgetValue(fromDateiWidget+".year");
	
	var toDateYear_DOM;
	var toDateYear = getWidgetValue(toDateiWidget+".year");
	
	if((toDateMonth_DOM.parentNode.parentNode.parentNode).style.display == "none") 
		return ;
	
       if ((fromDateMonth != null && fromDateMonth != '') && 
    	   (fromDateYear != null && fromDateYear != '') && 
    	   (toDateMonth != null && toDateMonth != '') && 
    	   (toDateYear != null && toDateYear != ''))
       {
    	   var fromDateValue;
    	   var toDateValue;
    	   
    	   if((fromDateDay_DOM) && (toDateDay_DOM))
    	   {
    		   if((fromDateDay != null && fromDateDay != '') && 
    			  (toDateDay != null && toDateDay != ''))
    		   {
    			   fromDateValue = fromDateDay + " " + fromDateMonth +" "+ fromDateYear;

    			   toDateValue = toDateDay + "  " + toDateMonth + " "+ toDateYear;
    		   }
    	   }
    	   else
    	   {
	        fromDateValue = 1 + " " + fromDateMonth +" "+ fromDateYear;

	        toDateValue = 2 + "  " + toDateMonth + " "+ toDateYear;
    	   }

    	   if(!doDateCheck(fromDateValue,toDateValue) && (daterangecheck != 1))
    	   {

    		   var iwidget = fromDateiWidget + ".daterange";
    		   errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
    		   var tempWidget = fromDateiWidget + ".year";
    		   errorsWithIdsAsKey.push( [tempWidget, "error on validation rules" ] );
    		   var tempWidget = toDateiWidget + ".year";
    		   errorsWithIdsAsKey.push( [tempWidget, "error on validation rules" ] );
    		   if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
    		   {
    			   errors.push( [ iwidget,"", validation_datatype_messages[ iwidget ] ] );
    		   }
    		   else
    		   {
    			   errors.push( [ iwidget,"", "Start date should be prior to end date." ] );
    		   }
    		   return validation_exc_number_format;
    	   }
    	   return;
       }
  }

  if( datatype == "datecompare-gt" || datatype == "datecompare-lt")
  {

    var fromDateiWidget=iWidget.substring(0,iWidget.lastIndexOf('.'));
	fromDateiWidget = "compareWith." + fromDateiWidget;
    var toDateiWidget=iWidget.substring(0,iWidget.lastIndexOf('.'));
    
	if(toDateiWidget.lastIndexOf('_') > 0)
	{
	    toDateiWidget=toDateiWidget.substring(0,iWidget.lastIndexOf('_'));
	}
       if ((getWidgetValue( fromDateiWidget+".month") != null && getWidgetValue( fromDateiWidget+".month") != '' && getWidgetValue( fromDateiWidget+".month") != undefined) && (getWidgetValue( fromDateiWidget+".day") != null && getWidgetValue( fromDateiWidget+".day") != '' && getWidgetValue( fromDateiWidget+".day") != undefined ) && (getWidgetValue( fromDateiWidget+".year") != null && getWidgetValue( fromDateiWidget+".year") != '' && getWidgetValue( fromDateiWidget+".year") != undefined ) && (getWidgetValue( toDateiWidget+".month") != null && getWidgetValue( toDateiWidget+".month") != ''&& getWidgetValue( toDateiWidget+".month") != undefined) && (getWidgetValue( toDateiWidget+".day") != null && getWidgetValue( toDateiWidget+".day") != '' && getWidgetValue( toDateiWidget+".day") !=undefined ) && (getWidgetValue( toDateiWidget+".year") != null && getWidgetValue( toDateiWidget+".year") != '' && getWidgetValue( toDateiWidget+".year") != undefined ))
        {
        var fromDateValue = getWidgetValue( fromDateiWidget+".day") + " " +getWidgetValue( fromDateiWidget+".month") +" "+ getWidgetValue( fromDateiWidget+".year");

        var toDateValue = getWidgetValue( toDateiWidget+".day") + "  " + getWidgetValue( toDateiWidget+".month") + " "+ getWidgetValue( toDateiWidget+".year");
	
	if(datatype == "datecompare-gt")
	{
        if(!doDateCheck(fromDateValue,toDateValue))
        {

	  var tempWidget = toDateiWidget + ".month";
          var iwidget=fromDateiWidget.substring((fromDateiWidget.indexOf(".")+1),fromDateiWidget.length) + ".compareWith";
          errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
	  if(!datecompare)
	  {
          errorsWithIdsAsKey.push( [tempWidget, "error on validation rules" ] );
          if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
          {
             errors.push( [ tempWidget,"", validation_datatype_messages[ iwidget ] ] );
          }
	  else
          {
             errors.push( [ tempWidget,"", "" ] );
          }
          
	  }
	  else
	  {
          if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
          {
	     var tempValue = "";
	     for(var i=0; i < errors.length; ++i)
	     {
		if(tempWidget == errors[i][0])
		{
		   tempValue = errors[i][2];
		}
	     } 
             errors.push( [ tempWidget,"", tempValue + '<br/>' + validation_datatype_messages[ iwidget ] ] );
          }		
	  }	  
          return validation_exc_number_format;
        }
	}
        if(datatype == "datecompare-lt")
        {     
	    if((!doDateCheck(toDateValue,fromDateValue)) && (datecomparecheck != 1))
        {
          var tempWidget = toDateiWidget + ".month";
          var iwidget=fromDateiWidget.substring((fromDateiWidget.indexOf(".")+1),fromDateiWidget.length) + ".compareWith";
          errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
          if(!datecompare)
          {
          errorsWithIdsAsKey.push( [tempWidget, "error on validation rules" ] );
          if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
          {
             errors.push( [ tempWidget,"", validation_datatype_messages[ iwidget ] ] );
          }
          else
          {
             errors.push( [ tempWidget,"", "" ] );
          }

          }
          else
          {
          if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
          {
             var tempValue = "";
             for(var i=0; i < errors.length; ++i)
             {
                if(tempWidget == errors[i][0])
                {
                   tempValue = errors[i][2];
                }
             }
             errors.push( [ tempWidget,"", tempValue + '<br/>' + validation_datatype_messages[ iwidget ] ] );
          }
          }
          return validation_exc_number_format;
        }
        }	
        return;
        }
}
if( datatype == "ADN")
{
var iwidget = iWidget.substring(0,(iWidget.length - 1));


	if(validation_required[iwidget + "1"] != true && (getWidgetValue(iWidget) == null || getWidgetValue(iWidget) == undefined || getWidgetValue(iWidget) == '') && (getWidgetValue(iwidget + "2") == null || getWidgetValue(iwidget + "2") == undefined || getWidgetValue(iwidget + "2") == ''))
	{

	return;
	}

        if((getWidgetValue(iWidget) == null || getWidgetValue(iWidget)=='' || getWidgetValue(iWidget) == undefined) &&(getWidgetValue(iwidget+ "2") == null || getWidgetValue(iwidget + "2") =='' ||getWidgetValue(iwidget +"2") == undefined) )
	{
	    adn=1;
	    errorsWithIdsAsKey.push( [iwidget, "error on validationrules" ] );
          if(validation_datatype_messages[iWidget] != null &&validation_datatype_messages[iWidget] != undefined)
          {
             errors.push( [ iwidget,"",validation_datatype_messages[ iWidget ] ] );
          }
          else
          {
             errors.push( [ iwidget,"", "Please enter the I-94 number." ] );
          }
	return null;
        }
        if((getWidgetValue(iWidget) != null || getWidgetValue(iWidget) !='' || getWidgetValue(iWidget) != undefined) && (getWidgetValue(iwidget+ "2") == null || getWidgetValue(iwidget + "2") =='' ||getWidgetValue(iwidget +"2") == undefined) )
	{
		adn=1;
		iwidget=iwidget+"2";
		errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
		errors.push( [ iwidget,"", validation_messages[ iwidget ] ] );
		return null;
        }

        if((getWidgetValue(iWidget) == null || getWidgetValue(iWidget)=='' || getWidgetValue(iWidget) == undefined) && (getWidgetValue(iwidget+ "2") != null || getWidgetValue(iwidget + "2") !='' ||getWidgetValue(iwidget +"2") != undefined) )
	{
		adn=1;
		iwidget=iwidget+"1";
		errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
		errors.push( [ iwidget,"", validation_messages[ iwidget ] ] );
//		return null;
        }

}

  if( datatype == "SSN")
  {
	  
	var iwidget=iWidget.substring(0,(iWidget.length - 1));
	if(validation_required[iwidget + "1"] != true && (getWidgetValue(iWidget) == null || getWidgetValue(iWidget) == undefined || getWidgetValue(iWidget) == '') && (getWidgetValue(iwidget + "2") == null || getWidgetValue(iwidget + "2") == undefined || getWidgetValue(iwidget + "2") == '') && (getWidgetValue(iwidget + "3") == null || getWidgetValue(iwidget + "3") == undefined || getWidgetValue(iwidget + "3") == ''))
	{
	return;
	}
        if((getWidgetValue(iWidget) == null || getWidgetValue(iWidget) =='' || getWidgetValue(iWidget) == undefined) && (getWidgetValue(iwidget + "2") == null || getWidgetValue(iwidget + "2") =='' || getWidgetValue(iwidget +"2") == undefined) && (getWidgetValue(iwidget + "3") == null || getWidgetValue(iwidget + "3") =='' || getWidgetValue(iwidget +"3") == undefined))
	{
	    ssn=1;
	    errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
          if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
          {
             errors.push( [ iwidget,"", validation_datatype_messages[ iwidget ] ] );
          }
          else
          {
             errors.push( [ iwidget,"", "Please enter the Social Security Number." ] );
          }
	return null;
        }
        if((getWidgetValue(iWidget) != null && getWidgetValue(iWidget) !='' && getWidgetValue(iWidget) != undefined) && (getWidgetValue(iwidget + "2") == null || getWidgetValue(iwidget + "2") =='' || getWidgetValue(iwidget +"2") == undefined) && (getWidgetValue(iwidget + "3") == null || getWidgetValue(iwidget + "3") =='' || getWidgetValue(iwidget +"3") == undefined))
	{
            ssn=1;
            errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
          if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
          {
             errors.push( [ iwidget,"", validation_datatype_messages[ iwidget ] ] );
          }
          else
          {
             errors.push( [ iwidget,"", "The Social Security Number is not valid. Please enter the 9 digit number in the boxes above. Do not include the hyphens." ] );
          }
	return null;
	}
	if((getWidgetValue(iwidget + "2") != null && getWidgetValue(iwidget + "2") !='' && getWidgetValue(iwidget + "2") != undefined) && (getWidgetValue(iWidget) == null || getWidgetValue(iWidget) =='' || getWidgetValue(iWidget) == undefined) && (getWidgetValue(iwidget + "3") == null || getWidgetValue(iwidget + "3") =='' || getWidgetValue(iwidget +"3") == undefined))
	{
            ssn=1;
            errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
          if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
          {
             errors.push( [ iwidget,"", validation_datatype_messages[ iwidget ] ] );
          }
          else
          {
             errors.push( [ iwidget,"", "The Social Security Number is not valid. Please enter the 9 digit number in the boxes above. Do not include the hyphens." ] );
          }
	return null;
	}
        if((getWidgetValue(iwidget+ "3") != null && getWidgetValue(iwidget + "3") !='' && getWidgetValue(iwidget + "3") != undefined) && (getWidgetValue(iWidget) == null || getWidgetValue(iWidget) =='' || getWidgetValue(iWidget) == undefined) && (getWidgetValue(iwidget + "2") == null || getWidgetValue(iwidget + "2") =='' || getWidgetValue(iwidget +"2") == undefined))
	{
            ssn=1;
            errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
          if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
          {
             errors.push( [ iwidget,"", validation_datatype_messages[ iwidget ] ] );
          }
          else
          {
             errors.push( [ iwidget,"", "The Social Security Number is not valid. Please enter the 9 digit number in the boxes above. Do not include the hyphens." ] );
          }
	return null;

	}
        if((getWidgetValue(iWidget) != null && getWidgetValue(iWidget) !='' && getWidgetValue(iWidget) != undefined) && (getWidgetValue(iwidget + "2") != null && getWidgetValue(iwidget + "2") !='' && getWidgetValue(iwidget +"2") != undefined) && (getWidgetValue(iwidget + "3") == null || getWidgetValue(iwidget + "3") =='' || getWidgetValue(iwidget +"3") == undefined))
	{
		ssn=1;
		iwidget = iwidget + "3";
		errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
		errors.push( [ iwidget, validation_messages[ iwidget ] ] );
		return null;
		
	}
	if ((getWidgetValue(iwidget + "2") != null && getWidgetValue(iwidget + "2") !='' && getWidgetValue(iwidget + "2") != undefined) && (getWidgetValue(iWidget) == null || getWidgetValue(iWidget) =='' || getWidgetValue(iWidget) == undefined) && (getWidgetValue(iwidget + "3") != null && getWidgetValue(iwidget + "3") !='' && getWidgetValue(iwidget +"3") != undefined))
	{
		ssn=1;
                errorsWithIdsAsKey.push( [iWidget, "error on validation rules" ] );
                errors.push( [ iWidget, validation_messages[ iWidget ] ] );	
		return null;
	}
	
        if ((getWidgetValue(iwidget+ "3") != null && getWidgetValue(iwidget + "3") !='' && getWidgetValue(iwidget + "3") != undefined) && (getWidgetValue(iWidget) != null && getWidgetValue(iWidget) !='' && getWidgetValue(iWidget) != undefined) && (getWidgetValue(iwidget + "2") == null || getWidgetValue(iwidget + "2") =='' || getWidgetValue(iwidget +"2") == undefined))
      {
		ssn=1;
	        iwidget = iwidget + "2";	
                errorsWithIdsAsKey.push([iwidget, "error on validation rules" ] );
                errors.push( [ iwidget, validation_messages[ iwidget ] ] );	
		return null;
      }
    
  }

if(datatype == "efilePhone")
    {
	var areaCode ="areaCode";
	var phone1 ="phoneNo1";
	var phone2 ="phoneNo2";
	if(validation_required[iWidget] == true && getWidgetValue(areaCode) == "" && getWidgetValue(phone1) =="" && getWidgetValue(phone2 )=="")
	    {
		phoneNo=1;
		errors.push( [iWidget,"Please enter a valid phone number." ] );
	    }

	if((getWidgetValue(areaCode) == "" && getWidgetValue(phone1) !="" && getWidgetValue(phone2 ) =="") || (getWidgetValue(areaCode) == "" && getWidgetValue(phone1) =="" && getWidgetValue(phone2 )!="") || (getWidgetValue(areaCode) == "" && getWidgetValue(phone1) !="" && getWidgetValue(phone2 ) !=""))
	    {
		phoneNo=1;
		errors.push( [ iWidget,"Please enter a valid phone number." ] );
	    }

	if((getWidgetValue(areaCode) != "" && getWidgetValue(phone1) =="" && getWidgetValue(phone2 )!="") || (getWidgetValue(areaCode) != "" && getWidgetValue(phone1) !="" && getWidgetValue(phone2 )=="") || (getWidgetValue(areaCode) != "" && getWidgetValue(phone1) =="" && getWidgetValue(phone2 )==""))
	    {
		phoneNo=1;
		errorsWithIdsAsKey.push( [iWidget, "error on validation rules" ] );
		errors.push( [ iWidget,"Please enter a valid phone number." ] );
	    }

	if(getWidgetValue(areaCode) != "" && getWidgetValue(phone1) !="" && getWidgetValue(phone2)!="") 
	    {
		phoneNo=0;
	    }
    }

  if( datatype == "date" )
  {
	  iWidget=iWidget.substring(0,iWidget.lastIndexOf('.'));
      var iwidget = iWidget + ".month";
      var futuredateallowedwidget = iWidget + ".futuredateallowed";
      var dayvalue;
    //optimizing code sureshbabu Nov 23
      var day_DOM = validation_form.elements[iWidget+".day"];
    	  
      var widgetDay = getWidgetValue(iWidget+".day");
      var widgetMonth = getWidgetValue(iWidget+".month");
      var widgetYear = getWidgetValue(iWidget+".year");
    	  
if(document.getElementById(futuredateallowedwidget) && getWidgetValue(futuredateallowedwidget) == "false")
	{
		var month_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun",
				    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
 
		var d = new Date();
		var current_day = d.getDate();
		var current_month = d.getMonth();
		var current_year = d.getFullYear();
		var current_date = ( current_day  +" " +month_names[current_month] + " " +  current_year);
		dayValue = (day_DOM) ? widgetDay : 1 ;

		if ((widgetMonth != null && widgetMonth != '') && 
			(widgetYear != null && widgetYear != ''))
		{
		        var dateValue = widgetMonth +" "+ dayValue +" "+ widgetYear;
		        var futureDateAllowedValue = dayValue + " " + widgetMonth +" "+ widgetYear;
		        var futureDateAllowed = new Date(futureDateAllowedValue);
		        var currentDate = new Date(current_date);
			if((chkdate(dateValue) != false ) && (Date.parse(futureDateAllowed) > Date.parse(currentDate))) 
			{
				var tempWidget = iWidget + ".year";
				errorsWithIdsAsKey.push( [tempWidget, "error on validation rules" ] );
				errors.push( [ tempWidget,"", validation_messages[futuredateallowedwidget]] );
				daterangecheck = 1;
				futureDateAllowed_err_msg[iWidget] = true;
				return;
			}
			else
			{
				futureDateAllowed_err_msg[iWidget] = false;
				daterangecheck = 0;
			}

}

}


  if (((day_DOM) && (widgetDay == null || widgetDay == ''))  || 
		widgetMonth == null || widgetMonth == '' || 
		widgetYear == null || widgetYear == '')
        {
	if(validation_required[iwidget] == true)
	{
         errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
             if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
             {
                errors.push( [ iwidget,"", validation_datatype_messages[ iwidget ] ] );
             }
             else
             {

                errors.push( [ iwidget,"", "Please choose a date." ] );
             }
          return validation_exc_number_format;
	}
	else 
	{
	if(day_DOM) 
		
		dayvalue = widgetDay;	
		var monthvalue = widgetMonth;
		var yearvalue = widgetYear;
	
	if (((dayvalue) && (!monthvalue || !yearvalue) ) || ( (!dayvalue || !yearvalue) && (monthvalue) ) || ( (!dayvalue || !monthvalue) && (yearvalue) ))
	{
         errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
             if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
             {
                errors.push( [ iwidget,"", validation_datatype_messages[ iwidget ] ] );
             }
             else
             {

                errors.push( [ iwidget,"", "Please choose a date." ] );
             }
          return validation_exc_number_format;

	}
	}
        }

       else if ((widgetMonth != null && widgetMonth != '') && 
    		    (widgetYear != null && widgetYear != ''))
        {

if((day_DOM) && (widgetDay != null && widgetDay != ''))
       
        var dateValue = widgetMonth +" "+ widgetDay +" "+ widgetYear;
else if(!day_DOM)
        var dateValue = widgetMonth +" "+ 1 +" "+ widgetYear;

//   the following code is to check whether the from date of DataRange tag is less than or equal to current date. If not, 
//   it throws error message. 

	if(iWidget.indexOf('fromDate') != -1)
	{
	var month_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun",
				    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");

	var d = new Date();
	var current_day = d.getDate();
	var current_month = d.getMonth();
	var current_year = d.getFullYear();
	var current_date = ( current_day  +" " +month_names[current_month] + " " +  current_year);
	
if(day_DOM)
        var fromDateValue = widgetDay + " " + widgetMonth +" "+ widgetYear;
else

        var fromDateValue = 1 + " " + widgetMonth +" "+ widgetYear;

      var fromDate=new Date(fromDateValue);
      var currentDate=new Date(current_date);

	if ((chkdate(dateValue) != false) && (Date.parse(fromDate) > Date.parse(currentDate)))
	{
      var tempWidget = iWidget + ".year";
	  errorsWithIdsAsKey.push( [tempWidget, "error on validation rules" ] );
	  errors.push( [ tempWidget,"", "From Date should be prior to or equal to Current Date "] );
	  daterangecheck = 1;
	}
	else
	{
	  daterangecheck = 0;
	}
	
	}

//   the following code is to throw error message, when the date tag is not given the enough data(it doesn't throw error 
//   message for fromdate of DateRange.tag, when the value is greater than current date, since  it is already having error 
//   message ). 

        if( dateValue && dateValue != "" && (chkdate( dateValue) == false))
        {

	  if(daterangecheck != 1 || iWidget.indexOf('fromDate') == -1)
	  {

            errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
            if(validation_mask_messages[iwidget] != null && validation_mask_messages[iwidget] != undefined)
            {

               errors.push( [ iwidget,"", validation_mask_messages[ iwidget ] ] );
            }
            else
            {

               errors.push( [ iwidget,"", "The date which you entered is not valid" ] );
            }
	  daterangecheck = 1;
          return validation_exc_mask_format;
	  }
        }

        return;
        }
}
  if( datatype == "prevSpouse")
  {
        var iwidget=iWidget.substring(0,iWidget.lastIndexOf('.'));
if(futureDateAllowed_err_msg[iwidget+".dateOfBirth"] != true)
{
        var dobdaywidgetvalue = getWidgetValue(iwidget + ".dateOfBirth.day");
        var dobmonthwidgetvalue = getWidgetValue(iwidget + ".dateOfBirth.month");
        var dobyearwidgetvalue = getWidgetValue(iwidget + ".dateOfBirth.year");
        
        var domdaywidgetvalue = getWidgetValue(iwidget + ".dateOfMarriage.day");
        var dommonthwidgetvalue = getWidgetValue(iwidget + ".dateOfMarriage.month");
        var domyearwidgetvalue = getWidgetValue(iwidget + ".dateOfMarriage.year");
        var dommonthwidget= iwidget + ".dateOfMarriage.month";
        
        var domedaywidgetvalue = getWidgetValue(iwidget + ".dateOfMarriageEnded.day");
        var domemonthwidgetvalue = getWidgetValue(iwidget + ".dateOfMarriageEnded.month");
        var domeyearwidgetvalue = getWidgetValue(iwidget + ".dateOfMarriageEnded.year");
        var domemonthwidget = iwidget + ".dateOfMarriageEnded.month";
        
    var dobValue, dob, dom, dome;
    
    if(dobdaywidgetvalue && dobmonthwidgetvalue && dobyearwidgetvalue)
    {
        dobValue = dobdaywidgetvalue + " " + dobmonthwidgetvalue +" "+ dobyearwidgetvalue;
        dob=new Date(dobValue);

        if(domdaywidgetvalue && dommonthwidgetvalue && domyearwidgetvalue)
        {
            dom=new Date(domdaywidgetvalue + " " + dommonthwidgetvalue +" "+ domyearwidgetvalue);
            if((chkdate(dobmonthwidgetvalue + " " + dobdaywidgetvalue +" "+ dobyearwidgetvalue) != false ) && (chkdate(dommonthwidgetvalue + " " + domdaywidgetvalue +" "+ domyearwidgetvalue) != false ) && ( Date.parse(dom) <= Date.parse(dob) )) 
            {
                errorsWithIdsAsKey.push( [dommonthwidget, "error on validation rules" ] );
                errors.push( [ dommonthwidget,"", validation_datatype_messages[iwidget+".dom"]] );
		daterangecheck = 1;
            }
        
        }
        if(domedaywidgetvalue && domemonthwidgetvalue && domeyearwidgetvalue)
        {
            dome=new Date(domedaywidgetvalue + " " + domemonthwidgetvalue +" "+ domeyearwidgetvalue);
            if((chkdate(dobmonthwidgetvalue + " " + dobdaywidgetvalue +" "+ dobyearwidgetvalue) != false ) && (chkdate(domemonthwidgetvalue + " " + domedaywidgetvalue +" "+ domeyearwidgetvalue) != false ) && (Date.parse(dome) <= Date.parse(dob)) ) 
            {
                errorsWithIdsAsKey.push( [domemonthwidget, "error on validation rules" ] );
                errors.push( [ domemonthwidget,"", validation_datatype_messages[iwidget+".dome"]] );
		daterangecheck = 1;
            }
            else { if(domdaywidgetvalue && dommonthwidgetvalue && domyearwidgetvalue && domedaywidgetvalue && domemonthwidgetvalue && domeyearwidgetvalue)
        {
            dom=new Date(domdaywidgetvalue + " " + dommonthwidgetvalue +" "+ domyearwidgetvalue);
            dome=new Date(domedaywidgetvalue + " " + domemonthwidgetvalue +" "+ domeyearwidgetvalue);
            if((chkdate(dommonthwidgetvalue + " " + domdaywidgetvalue +" "+ domyearwidgetvalue) != false ) && (chkdate(domemonthwidgetvalue + " " + domedaywidgetvalue +" "+ domeyearwidgetvalue) != false ) && (daterangecheck != 1) && (Date.parse(dome) < Date.parse(dom)) )
        {
                errorsWithIdsAsKey.push( [domemonthwidget, "error on validation rules" ] );
                errors.push( [ domemonthwidget,"", validation_datatype_messages[iwidget+".dome"]] );
		daterangecheck = 1;

        }
        
        }
        }
        
        }
    }
    else
    {
        if(domdaywidgetvalue && dommonthwidgetvalue && domyearwidgetvalue && domedaywidgetvalue && domemonthwidgetvalue && domeyearwidgetvalue)
        {
            dom=new Date(domdaywidgetvalue + " " + dommonthwidgetvalue +" "+ domyearwidgetvalue);
            dome=new Date(domedaywidgetvalue + " " + domemonthwidgetvalue +" "+ domeyearwidgetvalue);
            if((chkdate(dommonthwidgetvalue + " " + domdaywidgetvalue +" "+ domyearwidgetvalue) != false ) && (chkdate(domemonthwidgetvalue + " " + domedaywidgetvalue +" "+ domeyearwidgetvalue) != false ) && (daterangecheck != 1) && (Date.parse(dome) < Date.parse(dom)) )
            {
                errorsWithIdsAsKey.push( [domemonthwidget, "error on validation rules" ] );
                errors.push( [ domemonthwidget,"", validation_datatype_messages[iwidget+".dome"]] );
		daterangecheck = 1;
                
            }
        }
    
    }

}
    
  } // prevSpouse
  if( datatype == "datestay" )
  {
        iWidget=iWidget.substring(0,iWidget.lastIndexOf('.'));
        var iwidget = iWidget + ".month";
 if (getWidgetValue( iWidget+".year") == null || getWidgetValue( iWidget+".year") == '' || getWidgetValue( iWidget+".year") == undefined )
        {
             errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
             if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
             {
                errors.push( [ iwidget,"", validation_datatype_messages[ iwidget ] ] );
             }
             else
             {
                errors.push( [ iwidget,"", "You must complete this field to continue." ] );
             }
          return validation_exc_number_format;
        }
}
if( datatype == "multiCheckbox" )
{	
    iwidget=iWidget.substring(0,iWidget.lastIndexOf('.'));
	var error = true;
	var length = getWidgetValue(iWidget);
	for(var i=1;i<=length;i++)
	{
        if(document.getElementById(iwidget + ".raceList["+i+"].race-"+i).checked == true)
		{
			error = false;
			break;
		}
		else
			error = true;
	}
	if(error == true)
	{
         errorsWithIdsAsKey.push( [iwidget + ".common", "error on validation rules" ] );
         errorsWithIdsAsKey.push( [iwidget + ".raceList[1].race-1", "error on validation rules" ] );
         errors.push( [ iwidget + ".raceList[1].race-1","", validation_messages[ iwidget + ".common" ] ] );
	}
}


if( datatype == "multiOptionCheckbox" )
    {
        iwidget=iWidget.substring(0,iWidget.lastIndexOf('.'));
        var error = true;
        var length = getWidgetValue(iWidget);
        for(var i=1;i<=length;i++)
            {
                if(document.getElementById(iwidget + ".optionList["+i+"].value-"+i).checked == true)
                    {
                        error = false;
                        break;
                    }
                else
                    error = true;
            }
        if(error == true)
            {
                errorsWithIdsAsKey.push( [iwidget + ".common", "error on validation rules" ] );
                errorsWithIdsAsKey.push( [iwidget + ".optionList[1].value-1", "error on validation rules" ] );
                errors.push( [ iwidget + ".optionList[1].value-1","", validation_messages[ iwidget + ".common" ] ] );
            }
    }


if( datatype == "race" )
    {
        iwidget=iWidget.substring(0,iWidget.lastIndexOf('.'));
	if((getWidgetValue(iwidget + ".raceList[1].race") == null ) && (getWidgetValue(iwidget + ".raceList[2].race") == null) && (getWidgetValue(iwidget + ".raceList[3].race") == null) && (getWidgetValue(iwidget + ".raceList[4].race") == null) && (getWidgetValue(iwidget + ".raceList[5].race") == null))
	    {
		errorsWithIdsAsKey.push( [iwidget + ".common", "error on validation rules" ] );
		errorsWithIdsAsKey.push( [iwidget + ".raceList[5].race", "error on validation rules" ] );
		errors.push( [ iwidget + ".raceList[5].race","", validation_messages[ iwidget + ".common" ] ] );
	    }
    }

if( datatype == "checkheight" )
 {
        iWidget=iWidget.substring(0,iWidget.lastIndexOf('.'));
        var iwidget = iWidget + ".feet";
        var iwidgetinch = iWidget + ".inches";
        if (getWidgetValue( iWidget+".feet") == '' && getWidgetValue( iWidget+".inches") == '' || getWidgetValue( iWidget+".feet") == '' && getWidgetValue( iWidget+".inches") != ''  || getWidgetValue( iWidget+".feet") != '' && getWidgetValue( iWidget+".inches") == '')
        {
             errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );

             if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
             {

                errors.push( [ iwidget,"", validation_datatype_messages[ iwidget ] ] );
             }
            else if ( getWidgetValue( iWidget+".feet") == '' && getWidgetValue( iWidget+".inches") != '')
            {
                 errors.push( [ iwidget,"", "Please enter a valid height."] );
            }
          return validation_exc_number_format;
        }
     else if(getWidgetValue(iwidget).search(valid[validation_regexp[iwidget]]) == -1 || getWidgetValue(iwidgetinch).search(valid[validation_regexp[iwidget]]) == -1)
            {
                 errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
                 errors.push( [ iwidget,"", "Your entry may include only numbers and a decimal point."] );
            }
}

  if( datatype == "checkdatestay" )
  {
        iWidget=iWidget.substring(0,iWidget.lastIndexOf('.'));
        var iwidget = iWidget + ".month";
        if (getWidgetValue( iWidget+".year") == 0 && getWidgetValue( iWidget+".month") == 0 ||  getWidgetValue( iWidget+".month") != 0 && getWidgetValue( iWidget+".year") == '')

        {
             errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
             if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
             {
                errors.push( [ iwidget,"", validation_datatype_messages[ iwidget ] ] );
             }
             else  if ( getWidgetValue( iWidget+".month") != 0 && getWidgetValue( iWidget+".year") == '')
             {

               errors.push( [ iwidget,"", "Please enter zero if not applicable." ] );
             }

             else
             {
                errors.push( [ iwidget,"", "You must complete this field to continue." ] );
             }
          return validation_exc_number_format;
        }
}

if(datatype == "RECEIPT" )
  {
        iWidget=iWidget.substring(0,iWidget.lastIndexOf('.'));
        var iwidget = iWidget + ".name";
	if(getWidgetValue( iWidget+".name") != '' && getWidgetValue( iWidget+".no") != '')
	    {
		receipt = 0;
	    }
	if (getWidgetValue( iWidget+".no") == '' && getWidgetValue( iWidget+".name") == '' ||  getWidgetValue( iWidget+".name") != '' && getWidgetValue( iWidget+".no") == '' || getWidgetValue( iWidget+".name") == '' && getWidgetValue( iWidget+".no") != '')

            {         	       
               receipt = 1;
	       errorsWithIdsAsKey.push( [iwidget, "error on validation rules" ] );
             if(validation_datatype_messages[iwidget] != null && validation_datatype_messages[iwidget] != undefined)
             {
                errors.push( [ iwidget,"", validation_datatype_messages[ iwidget ] ] );
             }
	     else 
             {
                errors.push( [ iwidget,"", "Please enter the I-797 number." ] );
             }
            return validation_exc_number_format;

	}

}
  if(iWidget.substring(iWidget.lastIndexOf('.')+1,iWidget.length) == 'phone1')
  {
      phone = 0;
  }

  if( datatype=="phone")
  {
      var iwidgetphone1 = iWidget.substring(0,iWidget.length - 1);
      iwidgetphone1 = iwidgetphone1 + "1";
      var iwidgetphone2 = iWidget.substring(0,iWidget.length - 1);
      iwidgetphone2 = iwidgetphone2 + "2";
      var iwidgetphone3 = iWidget.substring(0,iWidget.length - 1);
      iwidgetphone3 = iwidgetphone3 + "3";	

      if(validation_required[iWidget] != true && (getWidgetValue(iwidgetphone1) == null || getWidgetValue(iwidgetphone1) =='' || getWidgetValue(iwidgetphone1) == undefined) && (getWidgetValue(iwidgetphone2) == null || getWidgetValue(iwidgetphone2) =='' || getWidgetValue(iwidgetphone2) == undefined) && (getWidgetValue(iwidgetphone3) == null || getWidgetValue(iwidgetphone3) =='' || getWidgetValue(iwidgetphone3) == undefined))
      {
        return;
      }


        if((getWidgetValue(iwidgetphone1) == null || getWidgetValue(iwidgetphone1) =='' || getWidgetValue(iwidgetphone1) == undefined) && (getWidgetValue(iwidgetphone2) == null || getWidgetValue(iwidgetphone2) =='' || getWidgetValue(iwidgetphone2) == undefined) && (getWidgetValue(iwidgetphone3) == null || getWidgetValue(iwidgetphone3) =='' || getWidgetValue(iwidgetphone3) == undefined))
      {
	   if(phone == 0)	 
	   {
	   phone = 1;
           errorsWithIdsAsKey.push( [iwidgetphone1, "error on validation rules" ] );
           errors.push( [ iwidgetphone1,"", validation_datatype_messages[ iwidgetphone1 ] ] );
	   return validation_exc_number_format;
	   }
       }
       if((getWidgetValue(iwidgetphone1) != null && getWidgetValue(iwidgetphone1) !='' && getWidgetValue(iwidgetphone1) != undefined) && (getWidgetValue(iwidgetphone2) == null || getWidgetValue(iwidgetphone2) =='' || getWidgetValue(iwidgetphone2) == undefined) && (getWidgetValue(iwidgetphone2) == null || getWidgetValue(iwidgetphone3) =='' || getWidgetValue(iwidgetphone3) == undefined))
      {
           if(phone == 0)
           {
	   phone = 1;
           errorsWithIdsAsKey.push( [iwidgetphone1, "error on validation rules" ] );
           errors.push( [ iwidgetphone1,"", validation_datatype_messages[ iwidgetphone1 ] ] );
	   return validation_exc_number_format;
	   }
       }
        if((getWidgetValue(iwidgetphone2) != null && getWidgetValue(iwidgetphone2) !='' && getWidgetValue(iwidgetphone2) != undefined) && (getWidgetValue(iwidgetphone1) == null || getWidgetValue(iwidgetphone1) =='' || getWidgetValue(iwidgetphone1) == undefined) && (getWidgetValue(iwidgetphone3) == null || getWidgetValue(iwidgetphone3) =='' || getWidgetValue(iwidgetphone3) == undefined))
        {
           if(phone == 0)
           {
	   phone = 1;
           errorsWithIdsAsKey.push( [iwidgetphone1, "error on validation rules" ] );
           errors.push( [ iwidgetphone1,"", validation_datatype_messages[ iwidgetphone1 ] ] );
	   return validation_exc_number_format;
           }
       }
        if((getWidgetValue(iwidgetphone3) != null && getWidgetValue(iwidgetphone3) !='' && getWidgetValue(iwidgetphone3) != undefined) && (getWidgetValue(iwidgetphone1) == null || getWidgetValue(iwidgetphone1) =='' || getWidgetValue(iwidgetphone1) == undefined) && (getWidgetValue(iwidgetphone2) == null || getWidgetValue(iwidgetphone2) =='' || getWidgetValue(iwidgetphone2) == undefined))
{
           if(phone == 0)
           {
                phone=1;
                errorsWithIdsAsKey.push( [iwidgetphone1, "error on validation rules" ] );
                errors.push( [ iwidgetphone1, validation_datatype_messages[ iwidgetphone1 ] ] );
                return null;
	   }
}
        if((getWidgetValue(iwidgetphone1) != null && getWidgetValue(iwidgetphone1) !='' && getWidgetValue(iwidgetphone1) != undefined) && (getWidgetValue(iwidgetphone2) != null && getWidgetValue(iwidgetphone2) !='' && getWidgetValue(iwidgetphone2) != undefined) && (getWidgetValue(iwidgetphone3) == null || getWidgetValue(iwidgetphone3) =='' || getWidgetValue(iwidgetphone3) == undefined))
        {
           if(phone == 0)
           {
                phone=1;
                errorsWithIdsAsKey.push( [iwidgetphone3, "error on validation rules" ] );
                errors.push( [ iwidgetphone3, validation_messages[ iwidgetphone3 ] ] );
                return null;
	   }
        }
        if ((getWidgetValue(iwidgetphone2) != null && getWidgetValue(iwidgetphone2) !='' && getWidgetValue(iwidgetphone2) != undefined) && (getWidgetValue(iwidgetphone1) == null || getWidgetValue(iwidgetphone1) =='' || getWidgetValue(iwidgetphone1) == undefined) && (getWidgetValue(iwidgetphone3) !=null && getWidgetValue(iwidgetphone3) !='' && getWidgetValue(iwidgetphone3) != undefined))
        {
           if(phone == 0)
           {
                phone=1;
                errorsWithIdsAsKey.push( [iwidgetphone1, "error on validation rules" ] );
                errors.push( [ iwidgetphone1, validation_messages[ iwidgetphone1 ] ] );
                return null;
	   }
        }
        if ((getWidgetValue(iwidgetphone3) != null && getWidgetValue(iwidgetphone3) !='' && getWidgetValue(iwidgetphone3) != undefined) && (getWidgetValue(iwidgetphone1) != null && getWidgetValue(iwidgetphone1) !='' && getWidgetValue(iwidgetphone1) != undefined) && (getWidgetValue(iwidgetphone2) == null || getWidgetValue(iwidgetphone2) =='' || getWidgetValue(iwidgetphone2) == undefined))
      {
           if(phone == 0)
           {
                phone=1;
                errorsWithIdsAsKey.push( [iwidgetphone2, "error on validation rules" ] );
                errors.push( [ iwidgetphone2, validation_messages[ iwidgetphone2 ] ] );
                return null;
	   }
      }
  }

  // VALUE NULL AND FIELD NOT REQUIRED RETURN NULL
  if( datatype=="nonZero" && value==0)
  {
             if(validation_datatype_messages[iWidget] != null && validation_datatype_messages[iWidget] != undefined)
	     {
	        errorsWithIdsAsKey.push( [iWidget, "error on validation rules" ] );
	        errors.push( [ iWidget,"", validation_datatype_messages[ iWidget ] ] );
		return "error on validation rules";
	     }
             else
      		return validation_exc_mandatory;
	
  }

  if( value && (datatype == "integer" || datatype == "long" ))
  {
    // INTEGER-LONG
    if( !isInteger( value ))
      return validation_exc_number_format;
  }
  else if( datatype == "double" || datatype == "decimal" )
  {
    // FLOAT-DOUBLE
    if( !isFloat( value ))
      return validation_exc_number_format;
  }
  
  // LENGTH
  var length = validation_length[iWidget];
  if( length != null && value != null )
  {
    var min   = length[0];
    var max   = length[1];
    var exact = length[2];
    var msg   = length[3];  

    if( !msg || msg == null )
      msg = validation_exc_length;

    if( min && min   != null && value.length < min ||
        max && max   != null && value.length > max ||
        exact && exact != null && value.length != exact )
      return msg;
  }

  // RANGE
  var range = validation_range[iWidget];
  if( range != null && value != null && range != undefined && range != "")
  {
    var min   = range[0];
    var max   = range[1];
    var exact = range[2];
    var msg   = range[3];
    
    if( !msg || msg == null )
      msg = validation_exc_range;

    if( min && min   != null && value < min ||
        max && max   != null && value > max ||
        exact && exact != null && value != exact )
      return msg;
    }
  // REGEXP

  var regexp = validation_regexp[iWidget];
  if( regexp != null && value != null )
  {
      msg = validation_exc_regexp;
      if(regexp != null) {
	      var regexpResult = value.search( valid[regexp] );
              if(regexp == "name" )
	      {
	      if( (value != null && value != '' && value != undefined))
              {
		if((getWidgetValue(iWidget).split("")).length > 49)
                {
		 errorsWithIdsAsKey.push( [iWidget, msg ] );
		 errors.push( [ iWidget,"", validation_mask_messages[ iWidget ]+" Max allowed is 49 characters." ] );

		 return msg;
                }
	      }
	      } // name mask
	      if( regexpResult == -1 && (value != null && value != '' && value != undefined))
	      {
                if(regexp == "Currency")
                {
                    if(valid[regexp+"alt"].test(value) == true)
			{
			    return null;
			}
                }


                if(regexp == "password" )
                {
		 errorsWithIdsAsKey.push( [iWidget, msg ] );
		 errors.push( [ iWidget,"", validation_mask_messages[ iWidget ] ] );

		 return msg;
                }
                else if(regexp == "alphabets" )
                {
		   errorsWithIdsAsKey.push( [iWidget, msg ] );
		   errors.push( [ iWidget,"", validation_mask_messages[ iWidget ] ] );
                 return msg;
                }
                  else if(regexp == "alphanumeric" )
                {
                   errorsWithIdsAsKey.push( [iWidget, msg ] );
                   errors.push( [ iWidget,"", validation_mask_messages[ iWidget ] ] );
                 return msg;
                }
		else if(regexp == "creditcardnumber"){
		  if(creditcardcheck == 0){
		     errorsWithIdsAsKey.push( [iWidget, msg ] );
		     errors.push( [ iWidget,"", validation_mask_messages[ iWidget ] ] );
		     return msg;
		   }
		}
		else if(regexp == "cin"){
		 if(cin == 0){
		    errorsWithIdsAsKey.push( [iWidget, msg ] );
		    errors.push( [ iWidget,"", validation_mask_messages[ iWidget ] ] );
		    return msg;
		  }
	        }
                else if(regexp == "emailAddress" )
                {
		  errorsWithIdsAsKey.push( [iWidget, msg ] );
		  errors.push( [ iWidget,"", validation_mask_messages[ iWidget ] ] );
		  return msg;
                }
                else if(regexp == "phoneNumber" || regexp == "phoneNumberCityCode" || regexp == "phoneNumberCountryCode")
                {
		  var iwidget = iWidget.substring(0,iWidget.length - 1);
		  iwidget = iwidget + "1";
		      if(phone == 0)
		      {
		      phone=1;
		      errorsWithIdsAsKey.push( [iwidget, msg ] );
		      errors.push( [ iwidget,"", validation_mask_messages[ iwidget ] ] ); 	
	  	      return msg;
		      }
                }
		else if(regexp == "ssn1" || regexp == "ssn2" || regexp == "ssn3")
		{
		  if(ssn == 0) 
		  {
		   ssn = 1;
		  var iwidget = iWidget.substring(0,iWidget.length - 1);
		  iwidget = iwidget + "1";
		  errorsWithIdsAsKey.push( [iwidget, msg ] );
		  errors.push( [ iwidget,"", validation_mask_messages[ iwidget ] ] );
		  return msg;
		  }
		}	
		else if(regexp == "adn1" || regexp == "adn2")
		{
		  if(adn == 0) 
		  {

		   adn = 1;
		  var iwidget = iWidget.substring(0,iWidget.length - 1);
		  iwidget = iwidget + "1";
		  errorsWithIdsAsKey.push( [iwidget, msg ] );
		  errors.push( [ iwidget,"", validation_mask_messages[ iwidget ] ] );
		  return msg;
		  }

                }
                else if(regexp == "receipt")
		 {
                    if(receipt == 0) 
		     {
		      receipt=1;
		      errorsWithIdsAsKey.push( [iWidget, msg ] );
		      errors.push( [ iWidget,"", validation_mask_messages[ iWidget ] ] );
		      return msg;
		     }
                }
               else if(regexp == "areaCode" || regexp == "phoneNumber1" ||regexp == "phoneNumber2" )
		{
		  if(phoneNo == 0) 
		  {
                    phoneNo=1;
		    var iwidget = iWidget.substring(0,iWidget.length);
                    errorsWithIdsAsKey.push( [iwidget, msg ] );
		    errors.push( [ iwidget,"", validation_mask_messages[ iwidget ] ] );
		   
                    return msg;				
		  }
		}

		else if(regexp == "newphone1" || regexp == "newphone2" || regexp == "newphone3")
		    {
			return msg;
		    }
		else if(regexp == "name" || regexp == "initial" || regexp =="liberal")
		    {

var error = false;
var temp1 = getWidgetValue(iWidget);
var temp2 = temp1.split("");
var code="";

		var umlauts = false;
		if(temp1.search( valid[regexp] ) == -1)
		{
			for(var i=0;i<temp2.length;i++)
			{
			code = temp2[i].charCodeAt(0);
			if(temp2[i].search( valid[regexp] ) == -1 ) 
			{ 
				if(((code < 192 || code > 215) && (code < 217 || code > 221) && (code < 224 || code > 246) && (code < 249 || code > 253) && code != 255 && temp2[i].search( valid[regexp+"temp"]) == -1 ) || ( temp2.length > 50))
				{
					error = true;
					 break; 
				} // if
				if(umlauts == false )
				{
				if((code > 192 && code < 215) || (code > 217 && code < 221) || (code > 224 && code < 246) || (code > 249 && code < 253) || code == 255 || code == 246)
					umlauts = true;        
				} // if

			} // if
			} // for
			if(error == true)
			{
				  errorsWithIdsAsKey.push( [iWidget, msg ] );
				  errors.push( [ iWidget,"", validation_mask_messages[ iWidget ] ] );
			} // if
		} // if
		if(error == false)
		{
			if(temp1.search("/^[a-zA-Z]$/") == -1 && umlauts == false && temp1.search( valid[regexp] ) == -1 )
			{
				  errorsWithIdsAsKey.push( [iWidget, msg ] );
				  errors.push( [ iWidget,"", validation_mask_messages[ iWidget ] ] );
			} // if

		} // if
  return msg;
		} // name mask
		else
		{
		  errorsWithIdsAsKey.push( [iWidget, msg ] );
		  errors.push( [ iWidget,"", validation_mask_messages[ iWidget ] ] );
                  return msg;
		}
	      }	
      }
  }

 var dateSubString = iWidget.substring(iWidget.lastIndexOf('.')+1,iWidget.length);
  if((!value || value == undefined || value == null || value == '' || value == "UNKNOWN")) {

     if( validation_required[iWidget] || validation_required[iWidget] != null )

     {
    var dateWidget = iWidget.substring(0,iWidget.lastIndexOf('.'));
	var dayWidget = validation_form.elements[iWidget+".day"];
	
	if (dateSubString == "day"){ 
    	var iWidgetDay = getWidgetValue(dateWidget + ".day");
    	var iWidgetYear = getWidgetValue(dateWidget + ".year");
    	
    	if(((dayWidget)&&(iWidgetDay == null || iWidgetDay == '')) && 
    	(iWidgetYear == null || iWidgetYear == ''))
    	{
    		return null;
    	}
    }

	if(dateSubString == "year"){ 
    	var iWidgetDay = getWidgetValue(dateWidget + ".day");
    	var iWidgetYear = getWidgetValue(dateWidget + ".year");
    	
    		if((iWidgetYear == null || iWidgetYear == '') && 
    		((dayWidget) && (iWidgetDay == null || iWidgetDay == '')))
    		{
    			return null;
    		}
    }
	var iwidget=iWidget.substring(0,(iWidget.length - 1));

	var ssnWidget=iwidget.substring((iwidget.lastIndexOf('.')+1),iWidget.length-1);

        if(ssnWidget == "ssn")
	{
		return null;
	}


	var iwidget=iWidget.substring(0,(iWidget.length - 1));

	var adnWidget=iwidget.substring((iwidget.lastIndexOf('.')+1),iWidget.length-1);

        if(adnWidget == "adn")
	{
		return null;
	}

	if(phone == 1 && (iWidget.substring(iWidget.lastIndexOf('.')+1,iWidget.length) == 'phone1' || iWidget.substring(iWidget.lastIndexOf('.')+1,iWidget.length) == 'phone2' || iWidget.substring(iWidget.lastIndexOf('.')+1,iWidget.length) == 'phone3'))
	   return null;

        if(validation_required[iWidget] == true)
        {
         return validation_exc_mandatory;
        }
        else
        {
          return null;
        }


     }

  }  

//USER FUNCTION (CALL IT WITH ITSELF AS ARGUMENT)
  var userFunction = validation_user[iWidget];
  if( userFunction != null && userFunction != undefined){
	  var JSONFile = userFunction;
	  eval(JSONFile);	 
  }
  if(validation_required[iWidget] != true){
	  return null;
  }
}

function validation_check_form( iForm )
{
 
  validation_form = iForm != null ? iForm : document.forms[formName];

  var msg;

  //Call the listener method to set/unset veto on field validation?
  if (typeof(preInitCheck) == 'function') 
	  preInitCheck();

  for(widget in validation_widgets) {	 
	  var valWidget = validation_form.elements[widget];
	    if(valWidget != null) {	    	
	  	if (!validation_docheck[widget] || validation_docheck[widget]=='' || validation_docheck[widget] == 'true') {
		    msg = validation_precheck_widget( widget );
		    if( msg != null ) {
				errorsWithIdsAsKey.push( [widget, msg ] );
				errors.push([ widget, msg ]);
		    }
		 }  
		}
	var temp = getParentSectionDiv(widget);
	var temp_widget;	
	var sectionDiv = document.getElementById(temp);
	
	if(sectionDiv != null && sectionDiv.style.display !="none"){
	 var tName = validation_form.elements[widget];
	 if(tName != null && tName != undefined && tName != "")
	 {
		temp_widget = document.getElementsByName(widget)[0] || document.getElementById(widget);		
          if(temp_widget.disabled != true && (temp_widget.parentNode.parentNode.parentNode).style.display != "none") 
            {   
            if (!validation_docheck[widget] || validation_docheck[widget]=='' || validation_docheck[widget] == 'true') {
            	msg = validation_check_widget( widget );            	
            	if( msg != null){
            		if (msg == validation_exc_mandatory)
            		{            			
                    errorsWithIdsAsKey.push( [widget, msg ] );
                    errors.push( [widget, validation_messages[ widget ] ] );
            		}
            	}			
            } 
	   
	 }
	}
	}
	
  }
  
  //Call the listener method to add message errors by other external validations
  if (typeof(postInitCheck) == 'function') {
  	errors = postInitCheck(errors);
  }
  
  return errors;
}

// =======================================================================
// Display all validation errors found. The array containing errors can be
// generated by calling validation_check_form(). If you want to add other errors to
// display, just update the array returned from validation_check_form() with yours 
// before calling this function.
//
// Usage:
function pushErrorsId(iWidget, msg)
{
   var check = "false";
   for(var i=0; i < errorsWithIdsAsKey.length; ++i)
   {	   
	var widget = errorsWithIdsAsKey[i][0];
	if(iWidget == widget)//errorsWithIdsAsKey[i][0])
	{
	    check = "true";
	    break;
	}
   }
      if(check == "false")	
      {
         errorsWithIdsAsKey.push( [iWidget, msg ] );
      }
}
// This is for tree actions, set form_Check var and use while highlighting and header err div 
// return accordingly
function formCheck(arg)
{
	form_Check = true;
	if(form_submit(arg))
		return true;
	else
		return false;
}
var isRefreshNeeded = false;
function form_submit(arg)
{
	
	errorFocusIndex = 0;
   formName = arg;
   validation_form = document.forms[formName];
   var form = document.forms[formName];
   errors = new Array();
   errorsWithIdsAsKey=new Array();

   if(isRefreshNeeded){
	   refreshErrorDivs();
	   refreshStyles(form);
   }
   if( !validation_show_errors( validation_check_form( form ) ) ) 
   {
	   isRefreshNeeded = true;	   
       return false;	
   }
   else
   {
	   isRefreshNeeded = false;
       if(document.getElementById("payment") != null && document.getElementById("payment").value == "true")
	   {
        if(document.getElementById("ADDRESS1") != null && document.getElementById("ADDRESS1") != undefined)
        {
            var streetNumber = document.getElementById("ADDRESS1").value;
            var regExp = new RegExp("[0-9]+", "g");
            var tempStreetNumber ="";
            tempStreetNumber = streetNumber.match(regExp);
            if(tempStreetNumber != null && tempStreetNumber != undefined)
            {
		if(document.getElementById("addrNum") != null || document.getElementById("addrNum") != undefined)
                {
                    document.getElementById("addrNum").value = tempStreetNumber[0];
	        }
	        else if(document.getElementsByName("addrNum")[0] != null || document.getElementsByName("addrNum")[0] != undefined)
                {
		    document.getElementsByName("addrNum")[0].value = tempStreetNumber[0];
		}
            }
            else
            {
                document.forms[0].addrNum.value ="";
            }
        }	
	iwidget="payment";
	var result;
	if(validation_mask_messages[iwidget] != null && validation_mask_messages[iwidget] !="" && validation_mask_messages[iwidget] != undefined)
        result = confirm (validation_mask_messages[iwidget]);
	else
	result = confirm ("Please wait a moment while we prepare your application.");
	if(!result){
              return false;
        }
	}
       
       if(document.getElementById("secure") != null || document.getElementsByName("secure")[0] != undefined)
       {
           var hostAction = document.forms[formName].action;
           if(hostAction.indexOf("http") < 0)
           {
           var hostName= window.location.hostname;
           if(hostName.indexOf("www") >=0)
              hostName = hostName.replace("www","secure");
           else if(hostName.indexOf("secure") < 0)
               hostName = "secure." + hostName;
           var pathName = window.location.pathname;
           pathName = pathName.substring(0,pathName.lastIndexOf("/"))
           document.forms[formName].action = "https:" + "//" + hostName + pathName + "/" + hostAction;
           }
           else
           {
             if(hostAction.indexOf("//www") >= 0)
             {
                hostAction = hostAction.replace("//www","//secure");
                hostAction = hostAction.replace("http:","https:");
                document.forms[formName].action= hostAction;
             }
             else if(hostAction.indexOf("//secure") <= 0)
             {
               hostAction = hostAction.replace("//","//secure.");
               hostAction = hostAction.replace("http:","https:");
               document.forms[formName].action= hostAction;
             }
           }
      }
      if(!form_Check)
      {
         form.submit();
      }
      else
      {
	return true;
      }
   }
 }


//
// param: iErrors It contains couples of field-name/error message
// 	 === MODIFIED TO DISPLAY ERROR MESSAGES ON DIV'S - ANIL 2006/03/16
// return: true if there are no errors, otherwise false
// =======================================================================
function validation_show_errors( iErrors )
{
  if( iErrors == null || iErrors.length == 0 )
    return true;
  var commoniWidjet="common"; 
  var msgCommon="";
  var msg="";
  var msgOnDiv="";
  var specificMsg="";
  var specificContent="";
  var sectionNameSubscript="errors-section-1";
  var msgCtr = 0;
  var specificMsgCtr = 0;
  var focusElement;
  isRefreshNeeded = true;
  for( var i = 0; i < errorsWithIdsAsKey.length; ++i )
  {	
   var firstElement = document.getElementById(errorsWithIdsAsKey[i][0]) || document.getElementsByName(errorsWithIdsAsKey[i][0])[0];  
	 
if(firstElement == null)
   {
	return true;
   }
    specificMsg = "";
    msg = "";
    for(j=0;j< errors.length;++j)
    {
    	if(errorsWithIdsAsKey[i][0] == errors[j][0])
    	{
    		if(errors[j][1] != undefined && errors[j][1] != '' && errors[j][1] != null)
    		{
    			msg = errors[j][1];
    		}
    		if(errors[j][2] != undefined && errors[j][2] != '' && errors[j][2] != null)
    		{
    			specificMsg = errors[j][2];
    		}
    	}
    }
    if(!form_Check)
    {    	
  	 highlight(firstElement,msg,specificMsg);
    }
}
  // Error focus
  	if(errorFocusElement != null && errorFocusElement.type != 'hidden'){
  		errorFocusElement.focus();    
  	}
    var errObj;
	if(document.getElementById("errors-page") != null || document.getElementById("errors-page") != undefined){
		errObj = document.getElementById("errors-page");
	} 
	
    if(!form_Check){
    	
    	if(validation_mask_messages["common"] != null && validation_mask_messages["common"] != undefined)
    	{
    		errObj.innerHTML= validation_mask_messages["common"];
    	}
    	else
    	{
    		errObj.innerHTML= "<b>Please complete the fields highlighted below.</b>";
    		if(document.getElementById("VQ-error") != null  )
    		{
    			document.getElementById("VQ-error").innerHTML= "<br><b>Please complete the fields highlighted below.</b></br>";
    		}

    	}
    }
    errObj.className = "page-errors";
    if(document.getElementById("VQ-error") !=null  )
    {
    	ShowContent('VQ-error');
    }
   else
    {
	   ShowContent('errors-page');
    }    
    sectionName=sectionNameSubscript;
  return false;
}

function getParentDiv(idValue){

    if(document.getElementById(idValue)!=null && document.getElementById(idValue).parentNode.tagName=="DIV" )
    {
    	var idValueObj = document.getElementById(idValue) || document.getElementsByName(idValue)[0];
    	var idParent = idValueObj.parentNode.getAttribute("id");
    	if(idParent != null && idParent != undefined && idParent != '')
    	{
            var id = idParent;		
            if(id.substring(0,14)=="errors-section")
            {
                return id;
            }
    	}
    }        
    var node = idValueObj;
            while(node != null && node != undefined)
            {
            	if(node.tagName == "BODY"){
                	break; 
                 }
            	
                 if(node.tagName == "DIV" && node.getAttribute("id") != null && node.getAttribute("id").substring(0,14)=="errors-section")
                	 break;
                 
                    if(node.previousSibling != null)
                    {
                            node = node.previousSibling;
                    }
                    else
                    {
                            node = node.parentNode;
                    }
            }
            if(node != null && node != undefined) {
            	var id=node.getAttribute("id");
            	if(id.substring(0,14)=="errors-section")
                    return id;
            	}
            	else
                    return "errors-page";
    
}

function getParentTAG(idValue,tag,userClass) 
{
	var cname;
	var parNode;
	if(idValue != null && idValue != undefined){
		parNode = idValue.parentNode; 
	}
	
	
	//if(idValue != null && idValue != undefined)
	//{
	if(parNode != null && parNode.getAttribute('class') != null && parNode.getAttribute('class') != undefined)
	{
	  cname = idValue.parentNode.className;
	}
        if(idValue != null && parNode != null && parNode.tagName == tag && cname != null && cname != undefined && cname.indexOf(userClass) >= 0) {
                return parNode;
        }
        else
        {
		node = parNode;
                while(node != null && node != undefined)
                {
                	var cNameTemp = node.className;
                    if(node.tagName == tag && cNameTemp != null && cNameTemp != undefined && cNameTemp.indexOf(userClass) >= 0 )
                    	break;
                    else
                    {
                    	node = node.parentNode;
                    }
                }
                if(node != null && node != undefined) {
                	cname = node.className;
                }
                if(node != null && node != undefined)
                {		
                   return node;
                }
                else
                        return null;
        }
       
    //}
}

function getParentSectionDiv(idValue)
{
	var idDivObj = document.getElementsByName(idValue)[0] || document.getElementById(idValue);
	
        if(idDivObj != null && idDivObj.parentNode.tagName == "DIV")
        {
        	var parentObj = idDivObj.parentNode;
        	var parentObjId = parentObj.getAttribute("id");
        	if(parentObjId != null && parentObjId != undefined && parentObjId != '')
        	{
                var secid = parentObjId;
				if(secid.substring(0,7)=="section"){
                 	 return secid;
                }
        	}
        }

	var node = idDivObj;
	while(node != null && node != undefined)
    {
		if(node.tagName == "BODY"){
			break;
		}
		var nodeID = node.getAttribute("id");
		if(node.tagName == "DIV" && nodeID != null && nodeID.substring(0,7)=="section")
	      	{
            	break;
	      	}
            else
            {
            	node = node.parentNode;
            }         
    }
    if(node != null && node != undefined) {
    	var id=node.getAttribute("id");
        if(id.substring(0,7)=="section")		
        	return id;
        }
        else
        	return "errors-page";
        
}


function validation_execute( iForm )
{
  if(!form_Check)
    validation_form.submit();

  if( !validation_show_errors( validation_check_form( iForm ) ) )
      return;
  else
    return true;
}

function checkdate(objName)
{
	var datefield = objName;
	if (chkdate(objName) == false)
	 {
		datefield.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function chkdate(strDate)
{
	var strDatestyle = "US"; //United States date style
	//var strDatestyle = "EU";  //European date style
	var strDate;
	var strDateArray;
	var strDay;
	var strMonth;
	var strYear;
	var intday;
	var intMonth;
	var intYear;
	var booFound = false;
	//var datefield = objName;
	var strSeparatorArray = new Array("-"," ","/",".");
	var intElementNr;
	var err = 0;
	var strMonthArray = new Array(12);
	strMonthArray[0] = "Jan";
	strMonthArray[1] = "Feb";
	strMonthArray[2] = "Mar";
	strMonthArray[3] = "Apr";
	strMonthArray[4] = "May";
	strMonthArray[5] = "Jun";
	strMonthArray[6] = "Jul";
	strMonthArray[7] = "Aug";
	strMonthArray[8] = "Sep";
	strMonthArray[9] = "Oct";
	strMonthArray[10] = "Nov";
	strMonthArray[11] = "Dec";
	//strDate = datefield.value;
	if (strDate.length < 1)
	{
		return true;
	}
	for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++)
	{
		if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1)
		{
			strDateArray = strDate.split(strSeparatorArray[intElementNr]);
			if (strDateArray.length != 3)
			{
				err = 1;
				return false;
			}
			else
			{
				strDay = strDateArray[0];
				strMonth = strDateArray[1];
				strYear = strDateArray[2];
			}	
			booFound = true;
		   }
	}
	if (booFound == false)
	{
		if (strDate.length>5)
		{
			strDay = strDate.substr(0, 2);
			strMonth = strDate.substr(2, 2);
			strYear = strDate.substr(4);
		}
	}
	// US style
	if (strDatestyle == "US")
	{
		strTemp = strDay;
		strDay = strMonth;
		strMonth = strTemp;
	}
	intday = parseInt(strDay, 10);
	if (isNaN(intday))
	{
		err = 2;
		return false;
	}
	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth))
	{
		for (i = 0;i<12;i++)
		{
			if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase())
			{
				intMonth = i+1;
				strMonth = strMonthArray[i];
				i = 12;
			}
		}
		if (isNaN(intMonth))
		{
			err = 3;
			return false;
		}
	}
	intYear = parseInt(strYear, 10);
	if (isNaN(intYear) || (intYear < 1900 || intYear > 2100))
	{
		err = 4;
		return false;
	}
	if (intMonth>12 || intMonth<1)
	{
		err = 5;
		return false;
	}
	if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1))
	{
		err = 6;
		return false;
	}
	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1))
	{
		err = 7;
		return false;
	}
	if (intMonth == 2)
	{
		if (intday < 1)
		{
			err = 8;
			return false;
		}
		if (LeapYear(intYear) == true)
		{
			if (intday > 29)
			{
				err = 9;
				return false;
			}
		}
		else
		{
			if (intday > 28)
			{
				err = 10;
				return false;
			}
		}	
	}
	return true;
}


function LeapYear(intYear)
{
	if (intYear % 100 == 0)
	{
		if (intYear % 400 == 0)
		{
			 return true;
		}
	}
	else
	{
		if ((intYear % 4) == 0)
		{
			 return true;
		}
	}
	return false;
}

function doDateCheck(from, to)
{
      var fromDate=new Date(from);
      var toDate=new Date(to);

      if (Date.parse(fromDate) >Date.parse(toDate))
              return false;
      else
              return true;
}

function doPasswordCheck(password,confirmpassword)
{
      if(password != confirmpassword)

           return false;
      else
	   return null;		
}

function doEmailCheck(email,confirmemail)
{
      if(email != confirmemail)

           return false;
      else
           return null;
}


function doCreditCardCheck(cc,type)
{

    var cctype=type;
    var ccno=cc;
    // Check if it is a master Card
    if(cctype=="ccmaster")
    {
        firstdig = cc.substring(0,1);
        seconddig = cc.substring(1,2);
        if((cc.length == 16) && (firstdig == 5) && (seconddig >= 1) && (seconddig <= 5))
           return null;
    }

    // Check if it is a Visa Card
    if(cctype=="ccvisa")
    {
       if (((cc.length == 16) || (cc.length == 13)) &&(cc.substring(0,1) == 4))
           return null;
    }

    // Check if it is a American Express Card
    if(cctype=="ccamericanexp")
    {
         firstdig = cc.substring(0,1);
         seconddig = cc.substring(1,2);
         if ((cc.length == 15) && (firstdig == 3) &&((seconddig == 4) || (seconddig == 7)))
             return null;
    }

    // Check if it is a Discover Card
    if(cctype=="ccdiscover")
    {
        first4digs = cc.substring(0,4);
	first2digs = cc.substring(0,2);
        if ((cc.length == 16) && ((first4digs == "6011") || (first2digs == "65")))
            return null;
    }
    // Check if it is a Diners Club Card
    if(cctype=="ccdinnersclub")
    {
        firstdig = cc.substring(0,1);
        seconddig = cc.substring(1,2);
        if (((cc.length == 14) && (firstdig == 3) && (seconddig == 6)) || ((cc.length == 16) && (firstdig == 5) && (seconddig == 5)))
            return null;
    }
     
    // Check if it is a Solo Card
    if(cctype=="ccsolo")
    {
        firstdig = cc.substring(0,1);
        first4digs = cc.substring(0,4);
        if ((((cc.length == 16) || (cc.length == 18) || (cc.length == 19)) && ((first4digs == "6334") || (first4digs == "6767") || (first4digs == "5020"))) || ((cc.length == 16) && (firstdig == 6)))
            return null;
    }

    // Check if it is a JCB
    if(cctype=="ccjcb")
    {
        first2digs = cc.substring(0,2);
        first4digs = cc.substring(0,4);
        if ((cc.length == 15 && (first4digs == "1800" || first4digs == "2131")) || (cc.length == 16 && first2digs == "35"))
            return null;
    }
    // Check if it is a Discover Card
    if(cctype=="ccothers")
    {
        if(isInteger(ccno))
           return null;
    }

    return false;
  }

function doExpiryDateCheck(month,year,monthyear)
{
    var strMonthArray = new Array(12);
    var intMonth;	
    strMonthArray[0] = "01";
    strMonthArray[1] = "02";
    strMonthArray[2] = "03";
    strMonthArray[3] = "04";
    strMonthArray[4] = "05";
    strMonthArray[5] = "06";
    strMonthArray[6] = "07";
    strMonthArray[7] = "08";
    strMonthArray[8] = "09";
    strMonthArray[9] = "10";
    strMonthArray[10] = "11";
    strMonthArray[11] = "12";
    for (i = 0;i<12;i++)
    {
        if (month.toUpperCase() == strMonthArray[i].toUpperCase())
        {
            intMonth = i+1;
            break;
         }
    }

    monthyear = monthyear.split(/_/);
    mon = monthyear[0];
	
    if(((monthyear[1] - year == 0) && (intMonth - monthyear[0] >= 0)) || (monthyear[1] - year < 0))
    {
        return true;
    }	
    else
        return false;

}

function refreshStyles(form) {
    var fields = form.elements;
    for(var i=0;i<fields.length;i++){
        var parentElement = getParentTAG(fields[i],"DIV","set");
        if(parentElement != null && parentElement.tagName != "BODY")
        {
           var cName=parentElement.className;
           if(cName.indexOf("error") > 0)
           {
              cName=cName.substring(0,cName.lastIndexOf(" "));
              parentElement.className = cName;
           }
        }
	if(parentElement == null)
	{
        parentElement = getParentTAG(fields[i],"P","set");
        if(parentElement != null)
        {
           var cName=parentElement.className;
           if(cName.indexOf("error") > 0)
           {
              cName=cName.substring(0,cName.lastIndexOf(" "));
              parentElement.className = cName;
           }
        }
	}

    }
}

function refreshErrorDivs() {
        var pList= document.getElementsByTagName("P");
        for(var i=0;i < pList.length;i++) {
		var pClass = pList[i].getAttribute("class");
		var pClassName = pList[i].getAttribute("className");
                if(pClass != null && pClass != '' && pClass != undefined && pClass == "error"){
                	var parentElement = getParentTAG(pList[i],"DIV","element");
                    parentElement.removeChild(pList[i]);
                    pList= document.getElementsByTagName("P");
                    i=0;
                }
                if(pClass == null)
                {
                	if(pClassName != null && pClassName != '' && pClassName != undefined && pClassName == "error"){
                        var parentElement = getParentTAG(pList[i],"DIV","element");
                        parentElement.removeChild(pList[i]);
                        pList= document.getElementsByTagName("P");
                        i=0;
                	}
                }	
        }
}


function setErrorFocus(){
     var reExp = new RegExp(/\berror\b/);
     var formnode = document.getElementsByTagName('form').item(f);
     for (var f = 0; formnode; f++){
        for (var i = 0; (node = formnode.getElementsByTagName('div').item(i)); i++) {
        	//alert("ds");
          if (reExp.exec(node.className)){
                  for (var  k= 0; (selectnode = node.getElementsByTagName('select').item(k)); k++) {
                            selectnode.focus();
                             return;
                         }
                 for (var j = 0; (inputnode = node.getElementsByTagName('input').item(j)); j++) {
                        if(inputnode.type != "hidden")    inputnode.focus();
                            return;
                      }
                for (var  m= 0; (textnode = node.getElementsByTagName('textarea').item(m)); m++) {
                            textnode.focus();
                            return;
               }
           }
        }
    }
}
// Error focus unwantedly looping. so removed it and stored the first element of 
// highlight element and focused it
var errorFocusElement;
var errorFocusIndex = 0;

function highlight(firstElement,msg,specificMsg)
{
	if(errorFocusIndex == 0){
		errorFocusElement = firstElement;
		errorFocusIndex ++;
	}
        var parentElement = getParentTAG(firstElement,"DIV","set");
        if(parentElement != null)
      	{
            parentElement.className = parentElement.className + " error";
      	}
	if(parentElement != null)
	{
	if(specificMsg != null && specificMsg != '' && specificMsg != undefined)
	{
		var pElement = document.createElement("P");
		var parentElement = getParentTAG(firstElement,"DIV","element");
		parentElement.appendChild(pElement);
		pElement.innerHTML= specificMsg;
		pElement.setAttribute((document.all ? 'className':'class'), "error");
		specificMsg="";

	}
	else if(msg != null && msg != '' && msg != undefined)
	{
                var pElement = document.createElement("P");
                var parentElement = getParentTAG(firstElement,"DIV","element");
                parentElement.appendChild(pElement);
                pElement.innerHTML= msg;
                pElement.setAttribute((document.all ? 'className':'class'), "error");
                msg="";
	}
     //setErrorFocus();
	}
}


// Script for ServerSide error display
var errorid;
function serverSideErrorDisplay()
{
    var argv=serverSideErrorDisplay.arguments;
    var argc=argv.length;
    var formId,genMsg,errMsg,controlId;
    formId = argv[0];
    errMsg = argv[1];
    if(argc > 2) {
        genMsg=argv[2];
    }
    if(argc > 3) {
	controlId = argv[3]
    }
    
      var errorDivId;	
        var sectionName="errors-section-1";
        var node = document.getElementById(formId);
	
        if(node == null)
        {
                node = document.getElementsByName(formId)[0];
        }
        if(node != null && node.tagName=="FORM" )
        {
	    getErrorDiv(node);
	}
	errorDivId = errorid;

	if(errorDivId == null)
	{
	        //document.getElementById("errors-section");
	    if(argc > 2)
		// document.getElementById("errors-page").className = "payment-errors";
		ShowContent("Payment-Error");
	    else
                document.getElementById("errors-page").className = "page-errors";

                if(controlId != null && controlId != undefined && controlId !="" && controlId != "null") {
		    highlight(document.getElementById(controlId),errMsg,"");
		}
		else
		    {
			if(errMsg != null && errMsg != undefined && errMsg !="") {
				genMsg = errMsg;
			}    
		    }
		if(genMsg != undefined){
		    if(show_payment_errors){
			document.getElementById("payment-errormsg").innerHTML=genMsg;
		    }else{
			document.getElementById("errors-page").innerHTML=genMsg;
		    }                        
		}

                ShowContent("errors-page");
	}
        else {
	    if(argc > 2)
		// document.getElementById("errors-page").className = "payment-errors";
		ShowContent("Payment-Error");
	    else
		document.getElementById(errorDivId).className = "section-errors";	
                if(controlId != null && controlId != undefined && controlId !="" && controlId != "null") {
		    highlight(document.getElementById(controlId),errMsg,"");
		}
		else
		    {
			if(errMsg != null && errMsg != undefined && errMsg !="") {
				genMsg = errMsg;
			}    
		    }

		if(genMsg != undefined) {
		    if(show_payment_errors){
			document.getElementById("payment-errormsg").innerHTML=genMsg;
		    }else{
			document.getElementById("errors-page").innerHTML=genMsg;
		    }
		}
		ShowContent(errorDivId);
	}
}

function showPaymentDeclineStatus(isRequired){
    show_payment_errors=isRequired;
}
function getErrorDiv(node)
{
	var nodelist=node.childNodes;
          	
	if (nodelist != null)
	{
	var i;
	for(i=0;i < nodelist.length ;i++)
	{
		if(nodelist[i].tagName == 'DIV')
		{
                   nodeid = nodelist[i].getAttribute("id");
                   if(nodeid.substring(0,14) == "errors-section")
                   {
                	   errorid = nodeid;                	  
                   }
		}
	        getErrorDiv(nodelist[i]);
        }
	}
	return errorid;	
}

function goToPage(pageID) {
   var action = document.forms['mainForm'].action;

   if (action.indexOf("?") != -1) {
        action += "&goto="+pageID;
   } else {
        action += "?goto="+pageID;
   }

 if(formCheck('mainForm')){
	if( action.indexOf("?") != -1)
            action += "&vstatus=true";
	else 
	    action += "?vstatus=true";
 }else{

	if( action.indexOf("?") != -1)
            action += "&vstatus=false";
	else 
	    action += "?vstatus=false";
 }

   document.forms['mainForm'].action = action;
   document.forms['mainForm'].submit();

}



function treeAction(selectNode) {

var expandNode;

var selectedNode = selectNode.indexOf('.');

  // Pass the following parameters - contid, userAction, next and expand
  var action = document.mainForm.action;
  if (action.indexOf("?") != -1) {
        action += "&tree="+selectNode;
  } else {
        action += "?tree="+selectNode;
  }

 if(formCheck('mainForm')){
	if( action.indexOf("?") != -1)
            action += "&vstatus=true";
	else 
	    action += "?vstatus=true";
 }else{

	if( action.indexOf("?") != -1)
            action += "&vstatus=false";
	else 
	    action += "?vstatus=false";
 }

  document.mainForm.action = action;
  document.mainForm.submit();
}

function enableValidationI485(secid) {
    var divs=document.getElementById(secid);
    var select=divs.getElementsByTagName("select");
    var input=divs.getElementsByTagName("input");
    var textarea=divs.getElementsByTagName("textarea");

    for( i=0 ;i<select.length;i++)
	{
	    validation_required[select[i].getAttribute("name")] = validationRequiredArray[select[i].getAttribute("name")];
	}
    for( i=0 ;i<input.length;i++)
	{
	    validation_required[input[i].getAttribute("name")]=validationRequiredArray[input[i].getAttribute("name")];
	    validation_regexp[input[i].getAttribute("name")]=validationRegExpArray[input[i].getAttribute("name")];
		if(validationRequiredArray[input[i].getAttribute("name")] == undefined || validationRequiredArray[input[i].getAttribute("name")] == false){
			validation_required[input[i].getAttribute("name")]=true;
		} 
	}
    for( i=0 ;i<textarea.length;i++)
	{
	    validation_required[textarea[i].getAttribute("name")]=validationRequiredArray[textarea[i].getAttribute("name")];
	    validation_regexp[textarea[i].getAttribute("name")]=validationRegExpArray[textarea[i].getAttribute("name")];
	}
}


// user function call for validating zip code
var wait_div;
var element_Dis;

function validateZipCode(addressValues){
    var zip = getWidgetValue(addressValues.zipcode);
	if(isNotPresent(addressValues.streetName, addressValues.city, addressValues.state, addressValues.zipcode)){
		var street = escapeQuote(getWidgetValue(addressValues.streetName));
		var apartmentNo = escapeQuote(getWidgetValue(addressValues.apartmentNumber));
		var city = escapeQuote(getWidgetValue(addressValues.city));
		var state = escapeQuote(getWidgetValue(addressValues.state));
		if(apartmentNo.search("&") != -1){
			pushErrorsId(addressValues.apartmentNumber, "error on validation rules");
    		errors.push( [ addressValues.apartmentNumber,"", "You have entered a character that our system does not recognize. Please try again."] );	
		}else{
			wait_div = document.getElementById('please-wait-'+addressValues.zipcode);
			wait_div.style.display = "inline";
			element_Dis = document.getElementsByName(addressValues.zipcode)[0];
			element_Dis.disabled=true;
	    	var JsonString = createJSONString(street, apartmentNo, city, state, zip);
	    	var url = "validateZipcode.do";
	    	var queryString = "address="+JsonString;
			execAjax(url, queryString, addressValues);
		}
	}
}


// check with errors array for regEx errors
function isNotPresent(street, city, state, zip){
	var doesNotExists = true;
	for( var i = 0; i < errorsWithIdsAsKey.length; ++i ){
		var widget = errorsWithIdsAsKey[i][0];
		if(widget == street || widget == city || widget == state || widget == zip){
			doesNotExists = false;
		}
	}
	return doesNotExists;
}

// simple JSON object formation for Address. If complex JSON object is to be converted as string then json.js can be downloaded from
// json.org and use "stringify" method. 
function createJSONString(street, apartmentNo, city, state, zip){
    var jsonString = "{'streetName':'"+street+"','apartmentNumber':'"+apartmentNo+"','city':'"+city+"','state':'"+state+"','zipcode':'"+zip+"'}";
    return jsonString;
}

// Ajax call to validate zip code
function execAjax(url, queryString, widget) {
	  if (window.XMLHttpRequest) {              
	    AJAX=new XMLHttpRequest();              
	  } else {                                  
	    AJAX=new ActiveXObject("Microsoft.XMLHTTP");
	  }
	  if (AJAX) {
		// synchronous call
	    AJAX.open("POST", url, false);
	    AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	    AJAX.send(queryString);
	    doZipCodeValidation(AJAX.responseText, widget);
	  }                      
	element_Dis.disabled=false;
	wait_div.style.display = "none";                
}


//parse the response object and convert it as error messages.
function doZipCodeValidation(responseObj, widget){
	responseObj = eval('(' + responseObj + ')');
	var errorMessage = '';
	if(!responseObj.found){
	    if(responseObj.usAddressSuggestions != undefined && responseObj.usAddressSuggestions != null && responseObj.usAddressSuggestions != ''){
		var suggestions = responseObj.usAddressSuggestions;
		for(var count = 0; count < suggestions.length; count++){
		    errorMessage += "<a href=\"#\" onclick=\"populateFields('"+widget.city+"','"+widget.state+"','"+widget.zipcode+"','"+suggestions[count].city+"','"+suggestions[count].state+"');return false;\">"+suggestions[count].city+", "+suggestions[count].state+"</a>";
		    errorMessage += "<br />";
		}
			var messageFirstLine="The USPS recognizes the following cities in ZIP code "+getWidgetValue(widget.zipcode)+". Please select your city by clicking on its name.";
			var messageLastLine="If you are unsure of your ZIP code, "+"<a href=\"http://zip4.usps.com/zip4/welcome.jsp\" target=\"_blank\">click here</a>"+" to find the correct ZIP code for your city.";
			errorMessage = "<br/>"+messageFirstLine+"<br/><br/>"+errorMessage+"<br/>"+messageLastLine;
	    }else{		
	    	errorMessage = "<br/>We could not validate your ZIP code. Please make sure you have entered it correctly. To look up your ZIP code, <a href=\"http://zip4.usps.com/zip4/welcome.jsp\" target=\"_blank\">click here</a>. If you are sure that this is the correct ZIP code, please <a href=\"/contact.jsp\" target=\"_blank\">contact us</a>.";
	    }
	    pushErrorsId(widget.zipcode, "error on validation rules");
	    errors.push( [ widget.zipcode,"", errorMessage] );
	}
}



function escapeQuote(widgetValue){
    var value = widgetValue;
    if(value.search("'") != -1)
	value = widgetValue.replace(/'/g,'\\\'');
    return value;                                                                                                    
}

//For populating state and city onclick of suggestion link in zipcodeValidation
function populateFields(cityWidget, stateWidget, zipWidget, cityValue, stateValue){
    document.getElementsByName(cityWidget)[0].value =cityValue;
    document.getElementsByName(stateWidget)[0].value = stateValue;
	removeErrorMesg(zipWidget);
	document.getElementsByName(cityWidget)[0].focus();
        
}

//For removing error message from a widget. This will also reset the css-style(yellow box) of widget.
function removeErrorMesg(widgetId){
	//removing error message div
	var siblingElements = document.getElementsByName(widgetId)[0].parentNode.getElementsByTagName("P");
	for(var i=0;i < siblingElements.length;i++) {
		var pClass = siblingElements[i].getAttribute("className") || siblingElements[i].getAttribute("class");
        if(pClass != null && pClass != '' && pClass != undefined && pClass == "error"){
        	var parentElement = getParentTAG(siblingElements[i],"DIV","element");
            parentElement.removeChild(siblingElements[i]);
			break;
        }
    }

	//Reseting the css-style(yellow box) of widget
    var parentElement = getParentTAG(document.getElementsByName(widgetId)[0],"DIV","set");
    if(parentElement != null)
    {
       var cName=parentElement.className;
       if(cName.indexOf("error") > 0)
       {
          cName=cName.substring(0,cName.lastIndexOf(" "));
          parentElement.className = cName;
       }
    }
}

// This Function is used to open a popup window from a text which would appear in payment decline error message                                                        

function errorMessagePopup(){
   window.open('/popup_sc.html','',"dependent=yes,toolbar=no,location=no,status=no,scrollbars=yes,resizable=\no,width=600,height=250,left=400,top=150");
}
