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;
// REGEX Elements

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

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

// matches digits with comma, requires atleast one digit and one or more comma
valid.digitswithcomma = /^[0-9][0-9\,]*$/;

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

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

//Height and Weight
valid.height=/^\d{1,3}(\.{0,1}\d{0,2})?$/;
valid.weight=/^\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]*$/;

// matches account id 
valid.AccountID = /^[0-9]+$/;

//Name
valid.Name=/^[a-zA-Z0-9\s|\,|\.|\-|\']+$/;
valid.Nametemp=/^([\s|\,|\.|\-|\']{0,})$/;

// for PortOfEntry.tag, other textbox
valid.poeothertext = /^([a-zA-Z]+[\s|\,|\.|\-|\']*)*$/;

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

// AlphaNumeric
valid.alphanumeric = /^[\s0-9a-zA-Z-]*$/;
//Street
valid.street=/^([a-zA-Z]|[0-9]|\.|\s|\-|\'|\,|\"|\&|\#|\/|\\|\(|\))+$/;

// matches zip codes
valid.zipCode = /^\d{5,10}$/;

// Province
valid.province=/^[a-zA-Z]+(\s{1}|-{1})?[a-zA-Z]*$/;

//city

valid.city=/^[0-9a-zA-Z\-\.\,\s]*[a-zA-Z][0-9a-zA-Z\-\.\,\s]*$/;

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

// matches 5:04 or 12:34 but not 75:83
valid.Time = /^([1-9]|1[0-2]):[0-5]\d$/;

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


//matches phone ###-###-#######
// valid.phoneNumber = /^\(?\d{3}\)?\s|-\d{3}-\d{4}$/;
valid.phoneNumberCountryCode = /^\d{3}$/;
valid.phoneNumberCityCode = /^\d{3}$/;
valid.phoneNumber = /^\d{7}$/;

// International Phone Number
valid.phoneNumberInternational = /^\d(\d|-){7,20}$/;

// IP Address
valid.ipAddress = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;

// Date xx/xx/xxxx
valid.Date = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/;

valid.dateDay = /^\d{1,2}$/;

valid.dateYear = /^\d{4}$/;

// State Abbreviation
valid.State = /^(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NB|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY)$/i;

// 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.newphone3 = /^[\s\-\(\)\[\]\/\\\.\_\#]{0,20}[0-9]([\s\-\(\)\[\]\/\\\.\_\#0-9]){0,20}$/;
valid.countryothertext = /^[^0-9\`\!\@\#\$\%\^\&\*]*[a-zA-Z][^0-9\`\!\@\#\$\%\^\&\*]*$/;

// Anumber
//valid.Anumber = /^\d{7,9}$/;
valid.Anumber=/^(^[a|A]{1}|-{1})*\d{3}(-{1}|\s{1})*\d{3}(-{1}|\s{1})*(\d{1}|\d{2}|\d{3})$/;
valid.password = /^[0-9A-Za-z\!\@\#\$\%\^\&\*\+\_\-\}\{\[\]\'\<\>\,\.\/\?\|]{6,11}$/;

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

//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;
  if(document.all)
  {
	var multiChoice = new Array();
	element = document.getElementById(iName);
	var counter = 0;
        var tNames;
        tNames=document.getElementsByTagName("input");
        for (var i = 0; i < tNames.length; i++)
        {
           if(tNames[i].getAttribute('name') != null && tNames[i].getAttribute('name') != undefined && tNames[i].getAttribute('name') != '' && tNames[i].getAttribute('name') == iName)
           {
		if(tNames[i].getAttribute('type') == 'radio')
		{
		  multiChoice.push([counter , tNames[i]]);
		  counter++;
		}
		else
		{
		if(element == null || element == undefined || element == '') 	
                  element = tNames[i];
		}
           }
        }
        tNames=document.getElementsByTagName("select");
        for (var i = 0; i < tNames.length; i++)
        {
           if(tNames[i].getAttribute('name') != null && tNames[i].getAttribute('name') != undefined && tNames[i].getAttribute('name') != '' && tNames[i].getAttribute('name') == iName)
           {
                element = tNames[i];
           }
        }
        tNames=document.getElementsByTagName("textarea");

        for (var i = 0; i < tNames.length; i++)
        {
           if(tNames[i].getAttribute('name') != null && tNames[i].getAttribute('name') != undefined && tNames[i].getAttribute('name') != '' && tNames[i].getAttribute('name') == iName)
           {
                element = tNames[i];
           }
        }
       if((element != null && element.type != null && element.type != undefined && element.type == "radio") || (multiChoice != null && multiChoice != undefined && multiChoice != ''))
       {
	if(multiChoice != null && multiChoice != undefined && multiChoice != '')
	{
          for (var i = 0; i < multiChoice.length; i++)
          {
            if (multiChoice[i][1].checked) {
                return multiChoice[i][1].value;
            }
          }
       }
      }
      else if (element != null && element.type != null && element.type != undefined && element.type == "checkbox")
      {
       var element= document.getElementsByName( iName );
       for (var i = 0; i < element.length; i++) {
         if (element[i].checked) {
             return element[i].value;
         }
       }
	
      }
      else
      {
	return trim(element.value);
      }

}
else
{

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 = document.forms[formName].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) {
//  var applyValidation= getApplyValidation();
//  if(applyValidation=="false")
//        return;
  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;
  } /*else {
  	if (iDatatype == 'integer' || iDatatype == 'long') {
  	  validation_accept[iWidget] = '[0-9\.]';
  	} else if (iDatatype == 'double' || iDatatype == 'decimal') {
  	  validation_accept[iWidget] = '[0-9\.\,]';  	
  	} else if (iDatatype == 'date') {
  	  validation_accept[iWidget] = '[0-9\\\/]';  	
  	} else if (iRegexp && iRegexp != null && iRegexp[0] != '') {
  	  var nre = iRegexp[0].toString();
  	  var removebrackets = new RegExp('\\{[0-9]*[\\,]?[0-9]*\\}','g');
  	  nre = nre.replace(removebrackets,'');
  	  var removesyntax = new RegExp('[\\(\\)\\|\\^\\$\\*\\+\\?\\[\\]]*','g');
  	  nre = nre.replace(removesyntax,'');  	  
  	  validation_accept[iWidget] = '[' + nre + ']';
  	}
  }*/
  
  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");

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

//***************************************************************************************************//
// 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");

    for( i=0 ;i<select.length;i++)
	{
	    validation_required[select[i].getAttribute("name")] = false;
	}
    for( i=0 ;i<input.length;i++)
	{
	    validation_required[input[i].getAttribute("name")] = false;
	    validation_regexp[input[i].getAttribute("name")] = undefined;
	}
    for( i=0 ;i<textarea.length;i++)
	{
	    validation_required[textarea[i].getAttribute("name")] = false;
	    validation_regexp[textarea[i].getAttribute("name")] = undefined;
	}
}
*/
function disableValidation(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++)
        {
            validationRequiredArray[select[i].getAttribute("name")] = false;
        }
    for( i=0 ;i<input.length;i++)
        {
            validationRequiredArray[input[i].getAttribute("name")] = false;
            validationRegExpArray[input[i].getAttribute("name")] = undefined;
        }
    for( i=0 ;i<textarea.length;i++)
        {
            validationRequiredArray[textarea[i].getAttribute("name")] = false;
            validationRegExpArray[textarea[i].getAttribute("name")] = 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++)
	{
	    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")];
	}
    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")];
	}
}


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 select a country"] );
              }else if (phone3value == "" && countryvalue == "")
              {
                  errorsWithIdsAsKey.push( [phone3, "error on validation rules" ] );
                  errors.push( [ phone3,"", "Please complete the highlighted area"] );

              }
	  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 your area code and telephone number"] );
			}
		      }
		  else if((!phone1value) && (phone2value) ) 
		      {
			  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
			  errors.push( [ phone1,"", "Please enter the area code"] );
		      }
		  else if((phone1value) && (!phone2value) ) 
		      {
			  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
			  errors.push( [ phone1,"", "Please enter the phone number"] );
		      }
		  else
		      {
			  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,"", "Please enter numbers only."] );

				      }
				  else
				      {
					  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
					  errors.push( [ phone1,"", "The area code you entered is incorrect"] );
				      }
			      }
			  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,"", "Please enter numbers only."] );
				      }
				  else
				      {
					  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
					  errors.push( [ phone1,"", "The phone number you entered is incorrect"] );
				      }
			      }
			  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,"", "Please enter numbers only."] );
				      }
				  else
				      {
					  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
					  errors.push( [ phone1,"", "Telephone number you entered is incorrect"] );
				      }
			      }
		      }
	      }

	  else
	      {
		  if(phone3value == "" &&  countryvalue != "")
		      {
			if(validation_required[iWidget] == true)
			{
			  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
			  errors.push( [ phone1,"", "Please enter your Telephone number"] );
			}
		      }
		  else if((phone3value) && (phone3value.search(valid[validation_regexp[phone3]]) == -1) && countryvalue != "")
		      {
			  errorsWithIdsAsKey.push( [phone1, "error on validation rules" ] );
			  errors.push( [ phone1,"", "Please enter numbers only."] );
		      }
	      }
      }


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];
	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,"", "Card Number you entered is not valid." ] );
          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,"", "The Card Identification number you entered is not valid."] );
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 select year" ] );
	}
        else if (yearValue != '' && monthValue == '') 
        {
	  errorsWithIdsAsKey.push( [monthiWidget, "error on validation rules" ] );
	  errors.push( [ monthiWidget,"", "Please select month" ] );
	}
        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;
if((document.getElementsByName(toDateiWidget+".month")[0].parentNode.parentNode.parentNode).style.display == "none") return ;
       if ((getWidgetValue( fromDateiWidget+".month") != null && getWidgetValue( fromDateiWidget+".month") != '' && getWidgetValue( fromDateiWidget+".month") != 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+".year") != null && getWidgetValue( toDateiWidget+".year") != '' && getWidgetValue( toDateiWidget+".year") != undefined ))
	{
	var fromDateValue;
	var toDateValue;
	if((document.getElementsByName(fromDateiWidget+".day")[0]) && (document.getElementsByName(toDateiWidget+".day")[0]))
	{
		if((getWidgetValue( fromDateiWidget+".day") != null && getWidgetValue( fromDateiWidget+".day") != '' && getWidgetValue( fromDateiWidget+".day") != undefined ) && (getWidgetValue( toDateiWidget+".day") != null && getWidgetValue( toDateiWidget+".day") != '' && getWidgetValue( toDateiWidget+".day") != undefined ))
		{
		        fromDateValue = getWidgetValue( fromDateiWidget+".day") + " " +getWidgetValue( fromDateiWidget+".month") +" "+ getWidgetValue( fromDateiWidget+".year");

		        toDateValue = getWidgetValue( toDateiWidget+".day") + "  " + getWidgetValue( toDateiWidget+".month") + " "+ getWidgetValue( toDateiWidget+".year");
		}
	}
	else
	{
	        fromDateValue = 1 + " " +getWidgetValue( fromDateiWidget+".month") +" "+ getWidgetValue( fromDateiWidget+".year");

	        toDateValue = 2 + "  " + getWidgetValue( toDateiWidget+".month") + " "+ getWidgetValue( toDateiWidget+".year");
	}

	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,"", "The I94 Number you entered is incomplete." ] );
          }
	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,"", "The Social Security Number you entered is incomplete." ] );
          }
	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 you entered is incomplete." ] );
          }
	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 you entered is incomplete." ] );
          }
	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 you entered is incomplete." ] );
          }
	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 == "date" )
  {
           iWidget=iWidget.substring(0,iWidget.lastIndexOf('.'));
        var iwidget = iWidget + ".month";
	var futuredateallowedwidget = iWidget + ".futuredateallowed";
	var dayvalue;
	
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 = (document.getElementsByName(iWidget+".day")[0]) ? getWidgetValue(iWidget+".day") : 1 ;

		if ((getWidgetValue( iWidget+".month") != null && getWidgetValue( iWidget+".month") != '' && getWidgetValue( iWidget+".month") != undefined ) && (getWidgetValue( iWidget+".year") != null && getWidgetValue( iWidget+".year") != '' && getWidgetValue( iWidget+".year") != undefined ))
		{
		        var dateValue = getWidgetValue( iWidget+".month") +" "+ dayValue +" "+ getWidgetValue( iWidget+".year");
		        var futureDateAllowedValue = dayValue + " " +getWidgetValue( iWidget+".month") +" "+ getWidgetValue( iWidget+".year");
		        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 (((document.getElementsByName(iWidget+".day")[0]) && (getWidgetValue( iWidget+".day") == null || getWidgetValue( iWidget+".day") == '' || getWidgetValue( iWidget+".day") == undefined))  || getWidgetValue( iWidget+".month") == null || getWidgetValue( iWidget+".month") == '' || getWidgetValue( iWidget+".month") == undefined || getWidgetValue( iWidget+".year") == null || getWidgetValue( iWidget+".year") == '' || getWidgetValue( iWidget+".year") == undefined )
        {
	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 complete the date" ] );
             }
          return validation_exc_number_format;
	}
	else 
	{
	if(document.getElementsByName(iWidget+".day")[0]) dayvalue = getWidgetValue( iWidget+".day");
	var monthvalue = getWidgetValue( iWidget+".month");
	var yearvalue = getWidgetValue( iWidget+".year");
	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 complete the date" ] );
             }
          return validation_exc_number_format;

	}
	}
        }

       else if ((getWidgetValue( iWidget+".month") != null && getWidgetValue( iWidget+".month") != '' && getWidgetValue( iWidget+".month") != undefined ) && (getWidgetValue( iWidget+".year") != null && getWidgetValue( iWidget+".year") != '' && getWidgetValue( iWidget+".year") != undefined ))
        {

if((document.getElementsByName(iWidget+".day")[0]) && (getWidgetValue( iWidget+".day") != null && getWidgetValue( iWidget+".day") != '' && getWidgetValue( iWidget+".day") != undefined ))
       
        var dateValue = getWidgetValue( iWidget+".month") +" "+getWidgetValue( iWidget+".day")+" "+ getWidgetValue( iWidget+".year");
else if(!document.getElementsByName(iWidget+".day")[0])
        var dateValue = getWidgetValue( iWidget+".month") +" "+1+" "+ getWidgetValue( iWidget+".year");

//   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(document.getElementsByName( iWidget+".day")[0])
        var fromDateValue = getWidgetValue( iWidget+".day") + " " +getWidgetValue( iWidget+".month") +" "+ getWidgetValue( iWidget+".year");
else




        var fromDateValue = 1 + " " +getWidgetValue( iWidget+".month") +" "+ getWidgetValue( iWidget+".year");

      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,"", "Please complete the date" ] );
             }
          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 == "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 provide your 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,"", "Please Provide numbers only."] );
            }
}

  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,"", "Please provide the duration details" ] );
             }
          return validation_exc_number_format;
        }
}

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

            {         	       
               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 complete the highlighted area(s)" ] );
             }
            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(validation_required[iWidget] == true && value == '')
  //{
  //      return validation_exc_mandatory;

  //}

  // DATATYPE
  //var datatype = validation_widgets[iWidget];
  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 == "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 == "phoneNumberInternational")
		{
		  errorsWithIdsAsKey.push( [iWidget, msg ] );
		  errors.push( [ iWidget,"", validation_mask_messages[ iWidget ] ] );
		  return msg;
		}
                else if(regexp == "AccountID")
                {
		  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 == "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 == "newphone1" || regexp == "newphone2" || regexp == "newphone3")
		    {
			return msg;
		    }
		else if(regexp == "Name" || regexp =="initial")
		    {
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 = document.getElementsByName(iWidget+".day")[0];
        if (dateSubString == "day" && ((dayWidget)&&(getWidgetValue(dateWidget + ".day") == null || getWidgetValue(dateWidget + ".day") == '' || getWidgetValue(dateWidget + ".day") == undefined)) && (getWidgetValue(dateWidget + ".year") == null || getWidgetValue(dateWidget + ".year") == '' || getWidgetValue(dateWidget + ".year") == undefined))

        {

           return null;

        }

        if(dateSubString == "year" && (getWidgetValue(dateWidget + ".year") == null || getWidgetValue(dateWidget + ".year")== '' || getWidgetValue(dateWidget + ".year") == undefined) && ((dayWidget) && (getWidgetValue(dateWidget + ".day") == null || getWidgetValue(dateWidget + ".day") == '' || getWidgetValue(dateWidget + ".day") == undefined)))

        {

           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 )
  {
    return eval( userFunction + "(" + iWidget + ")" );
  }
if(validation_required[iWidget] != true)
  return null;
}

function validation_check_form( iForm )
{
 
  validation_form = iForm != null ? iForm : document.forms[formName];
  //errors = new Array();
  //errorsWithIdsAsKey= new Array();

  var msg;

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

    if(document.getElementById(widget) != null || document.getElementsByName(widget)[0] != 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 ]);
	    }
	 }  
	}
  }

  for(widget in validation_widgets) {
	var temp = getParentSectionDiv(widget);
	var temp_widget;
	//var tempId = getParentTAG(tempWidget,"TD");
	var sectionDiv = document.getElementById(temp);
	if(sectionDiv != null && sectionDiv.style.display !="none"){
	 var tName = document.getElementsByName(widget)[0];
	 if(document.all && (tName == null || tName == undefined))
	 {
	
        var tNames;
	
	tName = document.getElementById(widget);
	if(tName == null || tName == undefined || tName == '')
        {
        tNames=document.getElementsByTagName("input");
        for (var i = 0; i < tNames.length; i++)
        {
           if(tNames[i].getAttribute('name') != null && tNames[i].getAttribute('name') != undefined && tNames[i].getAttribute('name') != '' && tNames[i].getAttribute('name') == widget)
           {
                tName = tNames[i];
           }
        }
        tNames=document.getElementsByTagName("select");
        for (var i = 0; i < tNames.length; i++)
        {
           if(tNames[i].getAttribute('name') != null && tNames[i].getAttribute('name') != undefined && tNames[i].getAttribute('name') != '' && tNames[i].getAttribute('name') == widget)
           {
                tName = tNames[i];
           }
        }
        tNames=document.getElementsByTagName("textarea");

        for (var i = 0; i < tNames.length; i++)
        {
           if(tNames[i].getAttribute('name') != null && tNames[i].getAttribute('name') != undefined && tNames[i].getAttribute('name') != '' && tNames[i].getAttribute('name') == widget)
           {
                tName = tNames[i];
           }
        }
	}
       }
	 if((document.getElementById(widget) != null && document.getElementById(widget) != undefined) || (tName != null && tName != undefined))
	 {
          if(document.getElementById(widget) != null && document.getElementById(widget) != undefined)
          {
                temp_widget = document.getElementById(widget);
          }	  
	  else if(document.getElementsByName(widget)[0] != null && document.getElementsByName(widget)[0] != undefined)
	  {
		temp_widget = document.getElementsByName(widget)[0];
          }
          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 ] ] );
                }
            }			
		//else if(msg == validation_exc_mask_format || msg == validation_exc_number_format)
		//{
		//  errorsWithIdsAsKey.push( [widget, msg ] );
                //  errors.push( [ validation_widgetsI18N[ widget ],"", validation_datatype_messages[ widget ] ] );
		//}
		//else if(msg == validation_exc_regexp)
		//{
                //  errorsWithIdsAsKey.push( [widget, msg ] );
                //  errors.push( [ validation_widgetsI18N[ widget ],"", validation_mask_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;
}
 function form_submit(arg)
{

   formName = arg;
   validation_form = document.forms[formName];
   var form = document.forms[formName];
   errors = new Array();
   errorsWithIdsAsKey=new Array();
   refreshErrorDivs();

   refreshStyles(form);

   
   if( !validation_show_errors( validation_check_form( form ) ) ) 
   {
      return false;	
   }
   else
   {
	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";

//  if(validation_mask_messages["common"] != null && validation_mask_messages["common"] != undefined)
//  {
//      document.getElementById("errors-page").innerHTML= validation_mask_messages["common"];
//  }
//  else
//  {
//      document.getElementById("errors-page").innerHTML= "<b>Please complete the fields highlighted below.</b>";
//  }
   // document.getElementById("errors-page").innerHTML=;
//  document.getElementById("errors-page").className = "page-errors";
//  ShowContent('errors-page');		

  //var msg="<b>Please complete the fields highlighted below.</b>";  
  var msgCommon="";
  var msg="";
  var msgOnDiv="";
  var specificMsg="";
  var specificContent="";
  var sectionNameSubscript="errors-section-1";
  var msgCtr = 0;
  var specificMsgCtr = 0;
  for( var i = 0; i < errorsWithIdsAsKey.length; ++i )
  {
	
//   var temp = getParentDiv(errorsWithIdsAsKey[i][0]);
  // var temp = document.getElementById(sectionNameSubscript);
   var firstElement = document.getElementsByName(errorsWithIdsAsKey[i][0])[0];
   
    if(firstElement == null || firstElement =='')
    {
	
	firstElement = document.getElementById(errorsWithIdsAsKey[i][0]);	   
	if(document.all && (firstElement == undefined || firstElement == '' ))
	{





        if(document.all)
        {

        var tNames;
	tName = document.getElementById(widget);
	if(tName == null || tName == undefined || tName == '')
	{
        tNames=document.getElementsByTagName("input");
        for (var j = 0; j < tNames.length; j++)
        {
           if(tNames[j].getAttribute('name') != null && tNames[j].getAttribute('name') != undefined && tNames[j].getAttribute('name') != '' && tNames[j].getAttribute('name') == errorsWithIdsAsKey[i][0])
           {
                firstElement = tNames[j];
           }
        }
        tNames=document.getElementsByTagName("select");
        for (var j = 0; j < tNames.length; j++)
        {
           if(tNames[j].getAttribute('name') != null && tNames[j].getAttribute('name') != undefined && tNames[j].getAttribute('name') != '' && tNames[j].getAttribute('name') == errorsWithIdsAsKey[i][0])
           {
                firstElement = tNames[j];
           }
        }
        tNames=document.getElementsByTagName("textarea");

        for (var j = 0; j < tNames.length; j++)
        {
           if(tNames[j].getAttribute('name') != null && tNames[j].getAttribute('name') != undefined && tNames[j].getAttribute('name') != '' && tNames[j].getAttribute('name') == errorsWithIdsAsKey[i][0])
           {
                firstElement = tNames[j];
           }
        }
        }
     }








	}
        
    }
   if(firstElement == null)
   {
	return true;
   }
//    var widget = errorsWithIdsAsKey[i][0];
    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)
    {
       //msgCtr++;
       msg = errors[j][1];
    }
    if(errors[j][2] != undefined && errors[j][2] != '' && errors[j][2] != null)
    {
       //specificMsgCtr++;
       specificMsg = errors[j][2];
    }
    }
    }
    if(!form_Check)
    {
  	 highlight(firstElement,msg,specificMsg);
    }
   //if(temp != sectionNameSubscript){
   //     var sectionName=sectionNameSubscript;
       // if(iErrors.length == 1 && msg != undefined && msg != '' && msg != null)
	//{
   //     document.getElementById(sectionName).innerHTML=msgOnDiv;
   //     document.getElementById(sectionName).className = "section-errors";
   //     ShowContent(sectionName);
	//}
   //     msgOnDiv="";
   //         msg="";
//	specificMsg="";
//        sectionNameSubscript=temp;
//    }

//    if(i < errors.length)
//    {
//    var widget = errorsWithIdsAsKey[i][0];
//    for(j=0;j< errors.length;++j)
//    {
//    if(widget == errors[j][0])
//    {
//    if(errors[j][1] != undefined && errors[j][1] != '' && errors[j][1] != null)
//    {
//       msgCtr++;
//       msg += "<br>" +  errors[j][1];
//    }
//    if(errors[j][2] != undefined && errors[j][2] != '' && errors[j][2] != null)
//    {
//       specificMsgCtr++;
//       specificMsg = specificMsg + "<br/>" + errors[j][2];
//    }
//    }
//    }
//    if(msgCtr == 1)
//       msgOnDiv = msg + specificMsg;
//    else
//       msgOnDiv = specificMsg;	
//    }
  
}
//  if(msgCtr > 1 || specificMsgCtr > 1)
//  {
//    var check=false;
//    msgCommon="";
    if(!form_Check){
    if(validation_mask_messages["common"] != null && validation_mask_messages["common"] != undefined)
    {
      document.getElementById("errors-page").innerHTML= validation_mask_messages["common"];
    }
    else
    {
      document.getElementById("errors-page").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>";
       }

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

//  }
//  else
//  {
//    msgCommon = msg;
//    HideContent('errors-page');
//  }
    
    sectionName=sectionNameSubscript;
    //msgOnDiv = msgOnDiv + specificMsg;
    //document.getElementById(sectionName).innerHTML=msgOnDiv;
    //document.getElementById(sectionName).className = "section-errors";
    //ShowContent(sectionName);

  return false;
}

//param:tagName
//function to retreive the immediate parent DIV with "id" attribute starting with "errors-section-xxx"
function getParentDiv(idValue){
	//var errorSection;
	//if(document.getElementById(idValue)!=null)
        //{
	//        errorSection = "errors-section-" + formName;
	//	var id=document.getElementById(idValue);
	//	if(id != null){
	//		return id;
	//	}
	//}
	//else
	//	return "errors-page";

        if(document.getElementById(idValue)!=null && document.getElementById(idValue).parentNode.tagName=="DIV" )
        {
		if(document.getElementById(idValue).parentNode.getAttribute("id") != null && document.getElementById(idValue).parentNode.getAttribute("id") != undefined && document.getElementById(idValue).parentNode.getAttribute("id") != '')
		{
                var id=document.getElementById(idValue).parentNode.getAttribute("id");
		
                if(id.substring(0,14)=="errors-section")
		{
                    return id;
                }
		}
        }

        var node;
        if(document.all)
        {

        var tNames;
        tNames=document.getElementsByTagName("input");
        for (var i = 0; i < tNames.length; i++)
        {
         if(tNames[i].getAttribute('name') != null && tNames[i].getAttribute('name') != undefined && tNames[i].getAttribute('name') != '' && tNames[i].getAttribute('name') == idValue)
           {
                node = tNames[i];
           }
        }
        tNames=document.getElementsByTagName("select");
        for (var i = 0; i < tNames.length; i++)
        {
         if(tNames[i].getAttribute('name') != null && tNames[i].getAttribute('name') != undefined && tNames[i].getAttribute('name') != '' && tNames[i].getAttribute('name') == idValue)
           {
                node = tNames[i];
           }
        }
        tNames=document.getElementsByTagName("textarea");

        for (var i = 0; i < tNames.length; i++)
        {
         if(tNames[i].getAttribute('name') != null && tNames[i].getAttribute('name') != undefined && tNames[i].getAttribute('name') != '' && tNames[i].getAttribute('name') == idValue)
           {
                node = tNames[i];
           }
        }
        }
        else
        {
            node = document.getElementsByName(idValue)[0];
        }

                node = document.getElementsByName(idValue)[0];
	        if (node == null && node == undefined)
		{
			node = document.getElementById(idValue);
		}
                while(node != null && node != undefined)
                {
                     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;
	
	if(idValue != null && idValue != undefined)
	{
	if(idValue.parentNode.getAttribute('class') != null && idValue.parentNode.getAttribute('class') != undefined)
	{
	  cname = idValue.parentNode.className;
	}
        if(idValue != null && idValue.parentNode.tagName == tag && cname != null && cname != undefined && cname.indexOf(userClass) >= 0) {
                return idValue.parentNode;
	}
        else
        {
		node = idValue.parentNode;
                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)
		{
		// && node.tagName == tag && cName != null && cName != undefined && cName.indexOf("label") > 0)
		
                   return node;
                }
                else
                        return null;
        }
       
    }
}



//param:tagName
//function to retreive the immediate parent DIV with "id" attribute starting with "errors-section-xxx"
function getParentSectionDiv(idValue)
{
        if(document.getElementById(idValue)!=null && document.getElementById(idValue).parentNode.tagName=="DIV")
        {
		if(document.getElementById(idValue).parentNode.getAttribute("id") != null && document.getElementById(idValue).parentNode.getAttribute("id") != undefined && document.getElementById(idValue).parentNode.getAttribute("id") != '')
		{
                var id=document.getElementById(idValue).parentNode.getAttribute("id");
				if(id.substring(0,7)=="section"){
                 	       	    return id;
                		}
		}
        }

	var node;
	if(document.all)
	{

	var tNames;
	tNames=document.getElementsByTagName("input");
        for (var i = 0; i < tNames.length; i++)
        {
           if(tNames[i].getAttribute('name') != null && tNames[i].getAttribute('name') != undefined && tNames[i].getAttribute('name') != '' && tNames[i].getAttribute('name') == idValue)
           {
                node = tNames[i];
           }
        }
	tNames=document.getElementsByTagName("select");
        for (var i = 0; i < tNames.length; i++)
        {
           if(tNames[i].getAttribute('name') != null && tNames[i].getAttribute('name') != undefined && tNames[i].getAttribute('name') != '' && tNames[i].getAttribute('name') == idValue)
           {
                node = tNames[i];
           }
        }
        tNames=document.getElementsByTagName("textarea");

	for (var i = 0; i < tNames.length; i++)
	{
	   if(tNames[i].getAttribute('name') != null && tNames[i].getAttribute('name') != undefined && tNames[i].getAttribute('name') != '' && tNames[i].getAttribute('name') == idValue)
	   {
		node = tNames[i];
	   }
	}
	}
	else
	{
	    node = document.getElementsByName(idValue)[0];
	}

	if (node == null || node == undefined)
	{
		node = document.getElementById(idValue);
	} 	
	while(node != null && node != undefined)
        {
              if(node.tagName == "DIV" && node.getAttribute("id") != null && node.getAttribute("id").substring(0,7)=="section")
	      {
                   break;
	      }
              else
              {
                   node = node.parentNode;
              }         

            //   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,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)
        {
           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");
                if(pList[i].getAttribute("class") != null && pList[i].getAttribute("class") != '' && pList[i].getAttribute("class") != undefined && pList[i].getAttribute("class") == "error"){
			var parentElement = getParentTAG(pList[i],"DIV","element");
                        parentElement.removeChild(pList[i]);
			pList= document.getElementsByTagName("P");
			i=0;
                }
if(pList[i].getAttribute("class") == null)
{
  if(pList[i].getAttribute("className") != null && pList[i].getAttribute("className") != '' && pList[i].getAttribute("className") != undefined && pList[i].getAttribute("className") == "error"){
                        var parentElement = getParentTAG(pList[i],"DIV","element");
                        parentElement.removeChild(pList[i]);
                        pList= document.getElementsByTagName("P");
                        i=0;
                }
    }	
  }
}

//function getApplyValidation() {
//        var applyValidation = document.getElementById("applyValidation");
//        return applyValidation.value;
//}

function setErrorFocus(){
     var reExp = new RegExp(/\berror\b/);
     for (var f = 0; (formnode = document.getElementsByTagName('form').item(f)); f++){
        for (var i = 0; (node = formnode.getElementsByTagName('div').item(i)); i++) {
          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;
               }
           }
        }
    }
}

function highlight(firstElement,msg,specificMsg)
{
        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";
	    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)
		    document.getElementById("errors-page").innerHTML=genMsg;
                ShowContent("errors-page");
	}
        else {
	    if(argc > 2)
                document.getElementById("errors-page").className = "payment-errors";
	    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)
		    document.getElementById(errorDivId).innerHTML=genMsg;
		ShowContent(errorDivId);
	}
}

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('.');

  //if(selectedNode=='-1') {
  // Add ".1" to the parent Node
  //selectNode = selectNode+".1";
  //}

  // 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();
}
