//    ||( | )||
// _____/||
// ( )  \|| for trysteromobile

// ------------------
//  Initialize fields
// ------------------
 
validationsArray=new Array();
controlIds = new Object();

// General validation function
// Needs an array of validation objects validationsArray
// A validation object has the structure:
// { 
//      wid : 'field_id'                // id of the html control to validate 
//      fun : 'validation_function'     // name of the js validation function
//      par : 'parameter'               // function parameter (optional or "")
//      msg : 'error_message'           // message on failed validation
//      btnY : 'flag'                   // flag=[0|1] whether to display yes button
//      btnN : 'flag'                   // ...no button
//      btnR : 'flag'                   // ...retry button
//      btnA : 'flag'                   // ...abort button
//      def :  'button_name'            // default button name
//      han :  'handling_function'      // name of the user response handling function
//  } 

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

function validateControls()
{
    var valid=true;
    // first, we put all widget backgrounds to white
    for (var k=0; k<validationsArray.length; k++)
    {
        var checkObj=validationsArray[k];
        var widget=getControl(checkObj.wid);
        if (widget!=null && widget!=undefined)
            if (widget.disabled!=null && (widget.readOnly!=null || widget.type == 'select-one') && !widget.disabled==true && !widget.readOnly==true)
            //Modify by Bruno Vasile
            //date 19/02/2010
            //for fix white background button on clink Avanti
            if (widget.type != 'submit')
                widget.style.backgroundColor = "white";
    }
    
    for (var k=0; k<validationsArray.length; k++)
    {        
        var checkObj=validationsArray[k];
       
        if (checkObj.han=="")
            checkObj.han="signalError";
        
        var widget=getControl(checkObj.wid);
        
        if (checkObj.wid!="NOFIELD" && (widget==null || widget==undefined))
            continue;
        
        if (widget!=null && widget!=undefined)
            if (widget.disabled==true || widget.readOnly==true)
                continue;
            
        if (checkObj.par!="")
        {
            valid=valid && eval(checkObj.fun+"(\""+checkObj.wid+"\", \""+checkObj.par+"\");");
        }
        else
            valid=valid && eval(checkObj.fun+"(\""+checkObj.wid+"\");");

        if (!valid)
        {
            valid=eval(checkObj.han+"('"+checkObj.wid+"', checkObj)");
        }
        if (!valid)
        {
            if (widget!=null && widget!=undefined)
                widget.style.backgroundColor = "#ffffaa";
            return false;
        }
    }
    return true;
}

// shows a blocking error message
function signalError(wid, checkObj)
{
    if (checkObj.msg.trim()=="")
        checkObj.msg="Attenzione! &nbsp Errore nella compilazione del modulo.";
    displayError(checkObj.msg);
}

// object to check whether form values have been modified
// the method go returns true if any modified value is found
function check_formModified()
{
    var values=new Object();
    for (var id in controlIds)
        values[id]=getControl(id).value;
    
    this.go=function() {
        var result=false;
        for (var id in controlIds)
        {
            if (getControl(id).value!=values[id])
            {
                result=true;
                break;
            }
        }
        return result;
    };
}

//
function concat_target()
{
    var target=document.forms[0].TARGET.value;
    var separator;
    if(target.indexOf("?")>0)
        separator="&";
    else
        separator="?";
    document.forms[0].TARGET.value=target+separator+"uid="+ EncodeBase64(document.getElementById("USER").value);
    
    
   
}



// checks that the specified field is not empty
function check_notEmpty(elementId)
{
    var element=getControl(elementId);
    var value=element.value;
    var enable=true;
    if(element.disabled)
        enable=false;
    else
        enable=true;
    if (value.trim()=="" && enable)
    {
        return false;
    }
    return true;
}

// checks whether a listbox has a value
function check_selected(elementId)
{
    var element = getControl(elementId);
    var index = element.selectedIndex;
    
    if (element.options[index].value.trim()==""  || index == 0)
        return false;
       
    return true;
}

//Check if a field as an invalid value
function check_notEqual(elementId, invalidValue)
{
    var element=getControl(elementId);
    var value=element.value;
    if (value==invalidValue)
        return false;
    return true;
}

// checks that the specified field's content has value less than val
function check_minValue(elementId, val)
{    
  var element=getControl(elementId);
   var num=element.value;
   if(num*1>=val*1)
        return true;    
    return false;
}

// checks that the specified field's content has value more than val
function check_maxValue(elementId, val)
{    
  var element=getControl(elementId);
   var num=element.value;
   if(num*1<=val*1)
        return true;    
    return false;
}

// checks if a check box is selected
function check_checked(elementId)
{
     
     var element1 = getControl(elementId);
     if(element1.checked)
        return true;
     return false;
}
function check_checked_rbl(elementId)
{
    var cont=0;
    var element=getControl(elementId +"_"+cont);
    
    while(element!=null)
    {
        if(element.checked==true)
            return true;
        cont=cont+1;
        element=   getControl(elementId +"_"+cont);
    }
    return false;

}
  function check_setUpperCase(elementId)
{
     var element = getControl(elementId);
     element.value=element.value.toUpperCase();
     return true;
}

// checks if a check box isn't checked
function check_notChecked(elementId)
{
     return !check_checked(elementId);
}

// checks if one of two check box is selected
function check_CheckBox(elementId,par)
{
     var element1 = getControl(elementId);
     var element2 = getControl(par);
     if(element1.checked || element2.checked)
        return true;
        
     return false;
}

// array initialization: executed at startup
checkbox_groups=new Object();

function setRadioCheckbox(id, click)
{
    var chk=document.getElementById(id);
    
    if (click==null)
        click=false;
        
    var group=checkbox_groups[id];
    
    // if the checkbox doesn't belong to a group, we just change its status
    if (group==null || group==undefined)
    {
        if (!click)
        {
            //chk.checked=!chk.checked;
            chk.click();
        }
    }
    
    // otherwise, we uncheck all the group's checkboxes and then check it
    else
    {
        for (var k in checkbox_groups)
            if (checkbox_groups[k]==group && k!=id)
                document.getElementById(k).checked=false;
        chk.checked=true;
    }
    
    // then we call an onchange function if assigned
    if (!(chk.onchange==null || chk.onchange==undefined)) 
        chk.onchange();
}

// chek if type contract is Prepaid
function check_BarcodeAppendValue(elementid,par)
{
      
     var text=getControl(elementid);
     
     if(text.value.length==17)
        text.value=par+text.value;
     return true;
}

function check_ckb_text(elementId,par)
{
        var TextBox = getControl(elementId);
        var ckb=getControl(par);
        var ckbvalue = ckb.selected; 
        var txtvalue=TextBox.value;
        var txtnotempty=false;
     
       if (txtvalue.trim()=="")
         txtnotempty=false;
        else 
         txtnotempty=true;
        if(ckbvalue && (!txtnotempty))                     
                return false;
                
        return true;

}

// checks password's format
function check_pwdFormat(elementId)
{
//[\u00C0-\u00F6\u00F8-\u00FF] -> caratteri accentati

    var re=/^[^<>/\\*'\"#&%|=?()~;+\- \u00C0-\u00F6\u00F8-\u00FF]+$/;
	return _check_re(elementId, re);
}

// generic regular expression check (private)
function _check_re(element, re)
{
    var str=getControl(element).value;
    if(str.trim()=="")
        return true;
    
    var m = str.match(re);
	if (m == null)
		return false;
	return true;
}

// check identical passwords
function check_confirmPwd(elementId, par)
{
	var pwd1=getControl(elementId).value;
    var pwd2=getControl(par).value;
	return (pwd1==pwd2);
}

// checks that the specified field contains a specific number in the fisrt position 
function check_first_number(elementId,par)
{
    var element=getControl(elementId);
    var inputStr=element.value;
	
	var c=inputStr.charAt(0);
	
	if (c != par)
	{
		return false;
	}
	return true;
}

// checks that the specified field contains numeric data
function check_numeric(elementId)
{
	var re = /^[0-9]+$/;
	return _check_re(elementId, re);
}

// allows just alphanumeric chars and space
function check_alphanum(element)
{
	var re = /^[a-zA-Z0-9'. ]+$/;
    return _check_re(element, re);
}

function check_zipcode(element)
{
    return true;
}

// checks for generic phone numbers
function check_phoneNumber(elementId)
{
    if (getControl(elementId).value.substr(0, 2)=="00")
        return false;
    var re = /^(\+([0-9]){1,2}){0,1}([0-9]){6,}$/
    return _check_re(elementId, re);   
}

// checks for cellular phone numbers
function check_cellPhoneNumber(elementId)
{
        var re = /^([+]39)?(3)([\d]{8,9})$/;
	    //var re = /^([+]39)?((38[{8,9}|0])|(34[{6-9}|0|3])|(36[6|8|0])|(33[{3-9}|0])|(32[{8,9}|0|3])|(37[{7}])|(39[{0-3}]))([\d]{6,8})$/
        return _check_re(elementId, re);   
}

// checks that the specified field contains text
function check_name(elementId)
{      
    //Bruno Vasile 27/04/2010
    //aggiunta del trattino sul campo nome durante la registrazione
    //Start
  	var re = /^[a-zA-Z'\- ]+$/;
  	//End
	return _check_re(elementId, re);
}

// checks that the specified field contains a valid email address
function check_email(elementId)
{
    var re = /^([a-zA-Z0-9_\-])+(\.([a-zA-Z0-9_\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*))$/;
	return _check_re(elementId, re);
}

// checks that the specified field's content has length less or equal than len
function check_minLength(elementId, len)
{
    len=len*1;
    var element=getControl(elementId);
    if (element.value.length>=len)
	    return true;
	return false;
}

// checks that the specified field's content has length more  than len
function check_maxLength(elementId, len)
{
    len=len*1;
    var element=getControl(elementId);
    if (element.value.length<=len)
	    return true;
	return false;
}

// checks that the specified field's content has length exactly equal to len
// len can contain more than one length separated by , (example: 11,16)
function check_exactLength(elementId, len)
{
    var lenArr=len.split(',');
    var element=getControl(elementId);
    var ok=false;
    
    for (k=0; k<lenArr.length; k++)
    {
        len=lenArr[k]*1;
        ok=ok || (element.value.length==len);
	}
	return ok;
}

//checks whether the specified field's content is null or has length exactly equal to len
function check_nullOrMaxLength(elementId,len)
{
    len=len*1;
    var element = getControl(elementId);
    if(element.value!=""&&element.value.length>len)
    {
        return false;
    }
    return true;
}

// rounds the field's content to two decimals
function check_twodecs(elementId) {
    var element=getControl(elementId);
    element.value=Math.round(element.value*100)/100;
	return true;
}

// validates a string against a regular expression
// after replacing the tag /bsl/ with \
function check_regExp(elementId, param) {
    while (param.replace("/bsl/", "\\")!=param)
        param=param.replace("/bsl/", "\\");
    var element=getControl(elementId);

    return _check_re(elementId, param);
}

function check_day(elementId)
{
    var element=getControl(elementId);
    if(!(element.value*1 >= 1 && element.value <= 31))
        return false;
    if (element.value.length < 2)
        element.value = "0" + element.value;
        
    return true;
}

function check_date_2(elementId, par)
{
    par = par.split("##");
    var day = getControl(elementId).value;
     if(day*1 >= 1 && day <= 31)
         if (day.length < 2)
            getControl(elementId).value = "0" + day;
        
    var month = getControl(par[0]).value;
    var year = getControl(par[1]).value;
    if(day.trim() == "" && month == "" && year == "")
    {
        return true;
    }
    var date = new Date(year, month-1, day);
    if(date.getDate() != (day*1))
        return false

    return true;
}

function check_dateInterval(elementId, par)
{
    par = par.split("##");
    var dayFrom = getControl(elementId).value;
    var monthFrom = getControl(par[0]).value;
    var yearFrom = getControl(par[1]).value;
    var dayTo = getControl(par[2]).value;
    var monthTo = getControl(par[3]).value;
    var yearTo = getControl(par[4]).value;
    var dateFrom = new Date(yearFrom, monthFrom - 1, dayFrom);
    var dateTo = new Date(yearTo, monthTo - 1, dayTo);
    if(dateFrom.getTime() > dateTo.getTime())
        return false;
    return true;
}

// check date - checks the correctness of a date
// the date must be in the format g[g]/m[m]/aa[aa]
function check_date(elementId)
{
    var element=getControl(elementId);
    var exp=element.value.split("/");
    if (exp.length!=3)
        return false;
    var data=new Date(exp[2]*1, exp[1]*1-1, exp[0]*1);
    if (data.getDate()!=exp[0]*1 || 
        data.getMonth() != exp[1]*1-1 ||
        data.getFullYear() != exp[2]*1)
        return false;
    return true;
}

function check_dateOrZero(elementId)
{
    var value=getControl(elementId).value;
    return (value.trim()=="" || value=="00/00/0000" || check_date(elementId));
}

function check_eighteen(elementId)
{
    var element=getControl(elementId);
    var exp=element.value.split("/");
    var date18=new Date(exp[2]*1+18, exp[1]*1-1, exp[0]*1);
    var today=new Date;
    if (date18>today)
        return false;
    return true;
}

function check_dateNotNull(elementId)
{
    var element=getControl(elementId);
    if (element.value.trim()=="" || element.value=="00/00/0000")
        return false;
    return true;
}

function check_dateNotPast(elementId)
{
    var mnpMinTime = 3;
    var element=getControl(elementId);
    if (element.value.trim()=="" || element.value=="00/00/0000")
        return true;
    var exp=element.value.split("/");
    var data=new Date(exp[2]*1, exp[1]*1-1, exp[0]*1);
    var dataOra=new Date();
    //var dataOggi=new Date(dataOra.getFullYear, dataOra.getMonth, dataOra.getDate);
    dataOra.setDate(dataOra.getDate() + mnpMinTime);
    if (Date.parse(data) < Date.parse(dataOra))
        return false;
    return true; 
}


// Verifies the formal correctness of a fiscal code
function check_cf(elementId) {
    var element=getControl(elementId);
	var cf=element.value;
	var validi, i, s, set1, set2, setpari, setdisp;
	if( cf == '' )  return '';
	cf = cf.toUpperCase();
	if( cf.length != 16 )
		return false;
	validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	for( i = 0; i < 16; i++ ){
		if( validi.indexOf( cf.charAt(i) ) == -1 )
			return false;
	}
	set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
	s = 0;
	for( i = 1; i <= 13; i += 2 )
		s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	for( i = 0; i <= 14; i += 2 )
		s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
	if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
		return false
    element.value=cf;
	return cf;
}

// checks the matching between the fiscal code given and the anagraphic data
// param is a string containing:
// nameId, surnameId, dateId, sexId, townId, cfId separated by ##
// the date control must contain a date in the format gg/mm/aaaa
function check_cfMatching(elementId, param) {
    param=param.split("##");
    
    var surname=getControl(param[0]).value;
    var name=getControl(param[1]).value;
    var sex=getControl(param[2]).value;
    var date=getControl(param[3]).value;
    var country=getControl(param[4]).value;
    var town=getControl(param[5]).value;
    var cf=getControl(param[6]).value;
    
    if (town.trim()=="")
        town=country;
    
    date=date.split("/");
    
    var cfC=CalcolaCodiceFiscale(name, surname, date[0], date[1], date[2], sex, town);
    
    // alert(cfC);
    
    if (cfC.toUpperCase()!=cf.toUpperCase())
        return false;
    return true;
}

function check_CFPIVA(elementId, param)
{
    return (check_cf(elementId) || check_PIVA(elementId));
}

function check_PIVA(elementId, param)
{
    var element=getControl(elementId);
	var pi=element.value;

    if( pi == '' )  return '';
    if( pi.length != 11 )
        return false;
    
    var validi = "0123456789";
    for(var i = 0; i < 11; i++ )
    {
        if( validi.indexOf( pi.charAt(i) ) == -1 )
            return false;
    }
    
    var s = 0;
    for(var i = 0; i <= 9; i += 2 )
        s += pi.charCodeAt(i) - '0'.charCodeAt(0);
        
    for(var i = 1; i <= 9; i += 2 )
    {
        var c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
        if( c > 9 )  c = c - 9;
        s += c;
    }
    
    if(( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0))
        return false;
        
    return true;
}

// -----------------------------
// FISCAL CODE GENERATION
// Function for the generation of the fiscal code
function CalcolaCodiceFiscale(Nome, Cognome, GiornoNascita, MeseNascita, AnnoNascita, Sesso, Comune) 
{
      ComuneCalcolato=Comune;
      rc = CalcolaCognome(Cognome);
	  rn = CalcolaNome(Nome)
	  rN = CalcolaNascita(GiornoNascita, MeseNascita, AnnoNascita, Sesso);

      var cf = rc+rn+rN+ComuneCalcolato;

      cf += CalcolaK(cf);
      return cf;
}

function CalcolaCognome(Cognome)
{
   var code = "";
   code = GetConsonanti(Cognome);
   if (code.length >= 3)
      code = code.substring(0, 3);
   else
   {
      code += GetVocali(Cognome).substring(0, 3 - code.length)
      if (code.length < 3)
         for (i = code.length; i < 3; i++)
            code += "X";
   }
   return code;
}

function CalcolaNome(Nome)
{
   var code = "";
   cons = GetConsonanti(Nome);
   if (cons.length > 3)
      code = cons.substring(0, 1) + cons.substring(2, 3) + cons.substring(3, 4);
   else if (cons.length == 3)
      code = cons;
   else
   {
      code = cons + GetVocali(Nome).substring(0, 3 - cons.length);
      if (code.length < 3)
         for (i = code.length; i < 3; i++)
            code += "X";
   }
   return code;
}

function GetConsonanti(Stringa)
{
   var consonanti =  "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ";
   var cns = "";
   for (i = 0; i < Stringa.length; i++)
      if (consonanti.indexOf(Stringa.substring(i, i + 1)) != -1)
         cns += Stringa.substring(i, i + 1);
   return cns.toUpperCase();
}

function GetVocali(Stringa)
{
   var consonanti =  "bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ";
   var voc = "";
   for (i = 0; i < Stringa.length; i++)
      if (consonanti.indexOf(Stringa.substring(i, i + 1)) == -1 && Stringa.substring(i, i + 1) != " ")
         voc += Stringa.substring(i, i + 1);
   return voc.toUpperCase();
}

function CalcolaNascita(Giorno, Mese, Anno, Sesso)
{
   var code = "";
   var mesi="ABCDEHLMPRST";
   Mese=mesi.charAt(Mese*1-1);
   code += Anno.substring(2, 4) + Mese;
   if (Sesso == "M")
      code += Giorno;
   else
      code += parseInt(40, 10) + parseInt(Giorno, 10);
   return code;
}

function CalcolaK(Stringa)
{
   var somma = 0, k;
   var arrPari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var arrDispari = new Array(
      Array(0,1),
      Array(1,0),
      Array(2,5),
      Array(3,7),
      Array(4,9),
      Array(5,13),
      Array(6,15),
      Array(7,17),
      Array(8,19),
      Array(9,21),
      Array("A",1),
      Array("B",0),
      Array("C",5),
      Array("D",7),
      Array("E",9),
      Array("F",13),
      Array("G",15),
      Array("H",17),
      Array("I",19),
      Array("J",21),
      Array("K",2),
      Array("L",4),
      Array("M",18),
      Array("N",20),
      Array("O",11),
      Array("P",3),
      Array("Q",6),
      Array("R",8),
      Array("S",12),
      Array("T",14),
      Array("U",16),
      Array("V",10),
      Array("W",22),
      Array("X",25),
      Array("Y",24),
      Array("Z",23)
   );
   for (i = 0; i < Stringa.length; i += 2)
   {
      for (j = 0; j < arrDispari.length; j++)
      {
         if (Stringa.substring(i, i + 1).toUpperCase() == arrDispari[j][0])
         {
            somma += parseInt(arrDispari[j][1], 10);
            break;
         }
      }
   }
   for (i = 1; i < Stringa.length; i += 2)
   {
      if (isNaN(Stringa.substring(i, i + 1)))
         somma += parseInt(arrPari.indexOf(Stringa.substring(i, i + 1)), 10);
      else
         somma += parseInt(Stringa.substring(i, i + 1), 10);
   }
   k = somma % 26;
   k = arrPari.charAt(k);
   return k;
}

function getControl(id)
{
    var obj=document.getElementById(id);
    if (obj!=null)
        return obj;
   
   if (controlIds[id] != null && controlIds[id] != undefined )
   {
     return document.getElementById(controlIds[id]);
   }
    
   return null;
}

//temporarly modified for test purpose (added 26 and 27 october)
var feste={"1/1":1, "6/1":1, "25/4":1, "1/5":1, "2/6":1, "15/8":1, "1/11":1, "16/11":1, "17/11":1, "18/11":1, "19/11":1, "20/11":1, "8/12":1, "25/12":1, "26/12":1};
feste[CalcEasterDate()]=1;

function isWorkingDay(date)
{
    var isWorking=true;
    if (date.getDay()==0 || date.getDay()==6)
        isWorking=false;
    
    var daymonth=date.getDate()+"/"+(date.getMonth()*1+1);
	if (feste[daymonth]!=undefined)
	    isWorking=false;
	    
	return isWorking;   
}

// warning: easter date is always that of the current year
function CalcNWorkingDays(num)
{
    //temporarly modified for test purpose (added 26 and 27 october)
	var feste={"1/1":1, "6/1":1, "25/4":1, "1/5":1, "2/6":1, "15/8":1, "1/11":1, "16/11":1, "17/11":1, "18/11":1, "19/11":1, "20/11":1, "8/12":1, "25/12":1, "26/12":1};
	feste[CalcEasterDate()]=1;
	var oggi=new Date();
	var count=0;
	while (count<num)
	{
		oggi.setDate(oggi.getDate()+1);
		var date=oggi.getDate()+"/"+(oggi.getMonth()*1+1);
		if (oggi.getDay()!=0 && oggi.getDay()!=6 && feste[date]==undefined)
			count++;
	}
	return oggi;
}

function CalcEasterDate()
{
	var a; var b; var c;
	var Y = new Date().getFullYear();
	var d; var e;
	var M; var N;
	var giorno;
	var mese;

	// we can assume year is always less than 2099
	M = 24;
	N = 5;
	   
	a = Y % 19;
	b = Y % 4;
	c = Y % 7;
	d = ((19*a) + M) % 30
	e = ((2*b) + (4*c) + (6*d) + N) % 7;

	if (d + e < 10)
	{
	    giorno = d+e+22;
	    mese = 3;
	} else {
	    giorno = d+e-9;
	    mese = 4;
	}

	if (giorno==26 && mese==4)
	{
	    giorno = 19;
	    mese = 4;
	}

	if (giorno==25 && mese==4 && d==28 && e==6 && a>10)
	{
		giorno=18;
		mese=4;
	}
	var pasqua=new Date(Y, mese-1, giorno);
	pasqua.setDate(pasqua.getDate()+1);
	return pasqua.getDate()+"/"+(pasqua.getMonth()*1+1);
}

function check_NullOrMinLength(elementId,par)
{
    if(check_notEmpty(elementId))
    {
        return check_minLength(elementId,par);
    }
    else
        return true;
}
var thisevent;
var isDivOpen = false;
var _comeOn= false;
var leavemessage='';
var leavemessage2='';
function hidediv() 
{ 
    if (document.getElementById)
    { // DOM3 = IE5, NS6 
        document.getElementById('hideShow').style.visibility = 'hidden'; 
    } 
    else 
    { 
        if (document.layers) 
        { // Netscape 4 
            document.hideShow.visibility = 'hidden'; 
        } 
        else 
        { // IE 4 
            document.all.hideShow.style.visibility = 'hidden'; 
        } 
    } 
    thisevent.onclick ="";
    isDivOpen = false;
    $('*').unbind();
    comeOn(true);
    if(thisevent.nodeName == 'A')
    { return window.location=thisevent.href;
    }else
        return thisevent.click();
} 

function showdiv(evento) 
{ 
    
    if(!isDivOpen)
    {    
        thisevent=evento;   
        pageScroll();
        if (document.getElementById) 
        { // DOM3 = IE5, NS6 
            document.getElementById('hideShow').style.visibility = 'visible'; 
            document.getElementById('hideShow').style.width=WindowScrollWidth()+"px";
            document.getElementById('hideShow').style.height=WindowScrollHeight()+"px";
        } 
        else 
        { 
            if (document.layers) 
            { // Netscape 4 
                document.hideShow.visibility = 'visible'; 
                document.hideShow.style.width=WindowScrollWidth()+"px";
                document.hideShow.style.height=WindowScrollHeight()+"px";
            } 
            else 
            { // IE 4 
                document.all.hideShow.style.visibility = 'visible'; 
                document.all.hideShow.style.width=WindowScrollWidth()+"px";
                document.all.hideShow.style.height=WindowScrollHeight()+"px";
                
            } 
       } 
       isDivOpen = true;
       displayLeaveMwessage();
    }
    return false;    
}

function pageScroll() 
{
  window.scroll(0,0); // horizontal and vertical scroll increments
  
}

function WindowHeight() 
{
  var myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
   
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
   
    myHeight = document.body.clientHeight;
  }
 
 return myHeight;
} 

function WindowWidth() 
{
  var myWidth = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    
  }
  return myWidth;
  
} 

function WindowScrollWidth() 
{
    var pageWidth = 0;
    if( window.innerHeight && window.scrollMaxY ) // Firefox 
    {
        pageWidth = window.innerWidth + window.scrollMaxX;
        
    } else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
    {
        pageWidth = document.body.scrollWidth;
        
    }
    else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    { 
        pageWidth = document.body.offsetWidth + document.body.offsetLeft; 
        
    }
    return pageWidth;
}

function WindowScrollHeight()
{
    var pageHeight = 0;
    if( window.innerHeight && window.scrollMaxY ) // Firefox 
    {
       
        pageHeight = window.innerHeight + window.scrollMaxY;
    } else if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
    {
       
        pageHeight = document.body.scrollHeight;
    }
    else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    { 
        
        pageHeight = document.body.offsetHeight + document.body.offsetTop; 
    }
    return pageHeight;
}

function displayLeaveMwessage()
{
    var thiselement= null;
    if (document.getElementById) 
        { // DOM3 = IE5, NS6 
            thiselement = document.getElementById('hideShow');
            
        } 
        else 
        { 
            if (document.layers) 
            { // Netscape 4 
               thiselement = document.hideShow; 
            } 
            else 
            { // IE 4 
                 thiselement = document.all.hideShow; 
            } 
       } 
       var myhtml=thiselement.innerHTML;
      
        thiselement.innerHTML = "<div style='visibility:visible;position:absolute;  top:400px;  left:50%;  width:300px;  height:200px; margin:-150px 0 0 -100px;  z-index:1100;  background-color:#E6EFF6;  border:1px solid #004c99; color:#004c99;'><table style='width:300px;  height:200px;'><tr><td align='center'>"+ 
        leavemessage2+"</td></tr><tr><td align='center'>"+ myhtml +"</td></tr></table></div>";
}


function comeOn(flag)
{
    _comeOn = flag;
}

function closeIt()
{
    if (!_comeOn)
        {
          return leavemessage;
        }
        
}
function goNext()
{
    comeOn(true);
    return _comeOn;
}

function VAsFunction(event)
{
    if(event.target.parentNode.id != 'Simply_zip_href')
    { 
     return showdiv(this);
    }
}