
// IR_### ###############################################################################################################################
// IR_### FUNZIONI DI UTILITA' GENERALE
// IR_### ###############################################################################################################################

//LERO
function IR_Exceptions()
{
    for (i = 0; i < document.forms[0].elements.length; i++)
        if (document.forms[0].elements[i].type == "hidden" && document.forms[0].elements[i].name == "EXCEPTION_CAUGHT")
            return true;

    return false;
}

//LERO
function IR_Submitted(IR_LocalNomeForm)
{
    for (i = 0; i < document.forms[IR_LocalNomeForm].elements.length; i++)
        if (document.forms[IR_LocalNomeForm].elements[i].type == "hidden" && document.forms[IR_LocalNomeForm].elements[i].name == "FORM_SUBMITTED")
            return document.forms[IR_LocalNomeForm].elements[i].value != "";

    return false;
}

//LERO
function IR_InitializeWindow(document, window, enableMouseRightButton)
{
    if (!enableMouseRightButton)
    {
        if (document.layers)
            window.captureEvents(Event.MOUSEDOWN);

        window.onmousedown = IR_DisableRightButton;
        document.onmousedown = IR_DisableRightButton;
    }
}


//LERO
function IR_DisableRightButton()
{
	if (event)
	{
     	if (event.button == 2 || event.button == 3)
     	{
        	alert("Tasto destro disabilitato");
        	return false;
        }
    }
    else if (e)
	{
    	if (e.which == 2 || e.which == 3)
    	{
	        return false;
		}
	}
        
    return true;
}

//MIR
function IR_PopupAlreadyOpened(IR_popupVar)
{
	return (!IR_popupVar.closed && IR_popupVar.location);
}

//MIR
function IR_CheckLengthTextArea(objTextArea,maxchars)
{    
    var chars = objTextArea.value;    
    if (chars.length > maxchars)
    {
        objTextArea.value=chars.substr(0,maxchars);
        alert('Raggiunto il limite dei caratteri consentiti per questo campo');        
    }
}

function IR_ControllaDataPolScaduta(IR_dScadPol,IR_dEffetto)
{
    var IR_nDay=0;
    var IR_Ret=false;
    //IR_### data sistema
    var IR_cDataSistema=IR_GetTodayDateAsString();
    var IR_nDayDiff;


	    // IR_###  Data sistema inferiore o uguale a quella di scadenza polizza
	    // IR_###  giro per avere il numero di giorni di differenza
		IR_nDay = IR_GetDayDiffTwoDate(IR_cDataSistema,IR_dEffetto);
		if (IR_nDay > 15)
            IR_Ret = false;
		else
		{
		    if (IR_nDay == 0)
		    {
		        IR_nDay = IR_GetDayDiffTwoDate(IR_dEffetto,IR_cDataSistema);
		        if(IR_nDay ==0)
		        {
		            //IR_### le date sono uguali
		            //IR_### controllo data scadenza polizza
		            IR_nDay = IR_GetDayDiffTwoDate(IR_dScadPol,IR_dEffetto);
		            if(IR_nDay ==0)
		                IR_Ret=false;
		            else
		                IR_Ret=true;
		        }
		        else
		        {
		            //IR_### date effetto>data sistema
		            if(IR_nDay >30)
		                IR_Ret=false;
		            else
                    {
                        IR_nDay = IR_GetDayDiffTwoDate(IR_dScadPol,IR_dEffetto);
    		            if(IR_nDay ==0)
    		                IR_Ret=false;
    		            else
    		                IR_Ret=true;
                    }
		        }
		    }

        }
   return  IR_Ret;
}

/**
  * Restitusce la data formattata in gg/mm/aaaa.
  * @param IR_dData Data in Stringa
  * @return IR_cStringa Data formattata in Stringa
  * <BR><B>Es di utilizzo:</B> IR_FormatData('28-05-2004');
  * <BR>&nbsp;&nbsp;&nbsp;Il risultato è: IR_cStringa = '28/05/2004'
  */
function IR_FormatData(IR_dData)
{
    var IR_MSGDATA="la data deve essere espressa nel formato GG/MM/AAAA";
    var IR_ANNO_QUATTRO_CIFRE="l'Anno deve avere 4 cifre";
    var IR_ANNO_MINIMO="L'anno non può essere inferiore al 1900";
    var IR_nLen=IR_dData.length;
    var IR_cCarattere="";
    var IR_cStringa="";
    var IR_messaggioErrore=null;
    var IR_cSubString="";
    var IR_nIndice=-1;
    var IR_cPrimaSubString="";
    var IR_cSottoString="";
 
    if (IR_dData!="")
    {
        for (var i=0;i<IR_nLen;i++)
        {
            IR_cCarattere=IR_dData.charAt(i);
            if (IR_cCarattere=="-")
                IR_cCarattere=IR_cCarattere.replace("-","/");
            IR_cStringa=IR_cStringa+IR_cCarattere;
        }
        IR_nIndice = IR_cStringa.indexOf("/");
        if ((IR_nIndice==-1)|| (IR_nIndice==0))
        {        
        	if(IR_cStringa.length == 8)
        	{
	        	IR_cPrimaSubString = IR_cStringa.substring(0,2);
			    IR_cSubString      = IR_cStringa.substring(2,4);
        		IR_cSottoString    = IR_cStringa.substring(4,8);
        	
				IR_cStringa = IR_cPrimaSubString + "/" + IR_cSubString + "/" + IR_cSottoString;
        	}
        	else
        	{        
	            IR_messaggioErrore=IR_MSGDATA;
    	        alert(IR_messaggioErrore);
        	    IR_cStringa="";
            }
        }
        if (IR_messaggioErrore==null)
        {
            if (IR_nIndice==(1)) IR_cStringa = '0'+IR_cStringa
            IR_cPrimaSubString = IR_cStringa.substring(3,IR_cStringa.length)
            IR_cSottoString=IR_cStringa.substring(0,3)
            IR_nIndice = IR_cPrimaSubString.indexOf("/");
            if ((IR_nIndice==-1)|| (IR_nIndice==0))
            {
                IR_messaggioErrore=IR_MSGDATA;
                alert(IR_messaggioErrore);
                IR_cStringa="";
            }
            if (IR_nIndice==(1)) IR_cStringa =
                IR_cSottoString+'0'+IR_cPrimaSubString
            if (IR_messaggioErrore==null)
            {
                IR_nIndice = IR_cStringa.lastIndexOf("/");
                if ((IR_nIndice==-1)|| (IR_nIndice==2))
                {
                    IR_messaggioErrore=IR_MSGDATA;
                    alert(IR_messaggioErrore);
                    IR_cStringa="";
                }
                if (IR_messaggioErrore==null)
                {
                    if (IR_nIndice==(4)) IR_cStringa =
                        IR_cStringa.substring(0,3)+'0'+IR_cStringa.substring(3);
                    IR_nIndice = IR_cStringa.lastIndexOf("/");
                    if(IR_cStringa.length<10)
                    {
                        IR_messaggioErrore=IR_ANNO_QUATTRO_CIFRE;
                        IR_cStringa="";
                        alert(IR_messaggioErrore);
                    }
                    if (IR_messaggioErrore==null)
                    {
                        if(IR_cStringa.length==10)
                        {
                            IR_cAnno=IR_cStringa.substring(IR_cStringa.length-4)
                            if (IR_cAnno<1900)
                            {
                                IR_messaggioErrore=IR_ANNO_MINIMO;
                                IR_cStringa="";
                                alert(IR_messaggioErrore);
 
                            }
                        }
                        if (IR_messaggioErrore==null)
                        {
                            var IR_bDataValida=IR_IsValidDate(IR_cStringa)
                            if (IR_bDataValida==false)
                            {
                              alert("Data non valida.");
                              IR_cStringa="";
                            }
                        }
                    }
                }
            }
        }
    }
    return IR_cStringa;
}

function IR_GetDifferenzaDateAssic(IR_d1,IR_d2)
{
	var lunghezza1 = IR_d1.length;
    var IR_nYY1 = Number(IR_d1.substring(lunghezza1-4, lunghezza1)); //IR_d1.substr(6,5));

    var indicePrimad1 = IR_d1.indexOf("/");
    var giorno = IR_d1.substring(0, indicePrimad1);
    var sub = IR_d1.substring(indicePrimad1+1, lunghezza1);

    var indiceSecondad1 = sub.indexOf("/");
    var mese = sub.substring(0, indiceSecondad1);
    var IR_nMM1 = Number(mese); //IR_d1.substr(3,2));
    var IR_nDD1 = Number(giorno);//IR_d1.substr(0,2));

    //alert("giorno e mese uno "+ giorno + " " + mese);

	var lunghezza2 = IR_d2.length;
    var IR_nYY2 = Number(IR_d2.substring(lunghezza2-4, lunghezza2)); //IR_d2.substr(6,5));

    var indicePrimad2 = IR_d2.indexOf("/");
    var giorno2 = IR_d2.substring(0, indicePrimad2);
    var sub2 = IR_d2.substring(indicePrimad2+1, lunghezza2);

    var indiceSecondad2 = sub2.indexOf("/");
    var mese2 = sub2.substring(0, indiceSecondad2);

    var IR_nMM2 = Number(mese2); //IR_d2.substr(3,2));
    var IR_nDD2 = Number(giorno2); //IR_d2.substr(0,2));
    //alert("giorno e mese due "+ giorno2 + " " + mese2);

    if (IR_nDD1 > 30)
        IR_nDD1 = 30;

    if (IR_nDD2 > 30)
        IR_nDD2 = 30;

    var IR_dYY = IR_nYY1 - IR_nYY2;

    var IR_dMM = IR_nMM1 - IR_nMM2;
    if (IR_dMM < 0)
    {
        IR_dYY--;
        IR_dMM += 12;
    }

    var IR_dDD = IR_nDD1 - IR_nDD2;

    if (IR_dDD < 0)
    {
        IR_dMM--;
        IR_dDD += 30;
    }

    return 360 * IR_dYY + 30 * IR_dMM + IR_dDD;
}

/**
  * Formatta il campo data e ne controlla la validità.
  * Restituisce true in caso di data corretta, false altrimenti
  * @param IR_oField Elemento data
  * @return IR_Ret Booleano
  */
function IR_ControllaData(IR_oField) 
{
    var IR_Ret = true;
    if (IR_oField.value != "")
    {
        var IR_cStringaFormattata = IR_FormatData(IR_oField.value);
        IR_Ret = IR_IsValidDate(IR_cStringaFormattata);
        if (IR_Ret) 
        	IR_oField.value = IR_cStringaFormattata;
       	else
        {
            //IR_oField.value="";
	        IR_oField.select()
	        IR_oField.focus();
	      	//setTimeout(function(){IR_oField.focus();IR_oField.select();},10)
        }
    }
    return IR_Ret;
}

function IR_InsertPuntiMigliaia(sNumero, sGroupingSep)
{
	dp = (sNumero.indexOf(sGroupingSep) != -1) ? sNumero.substring(0,sNumero.indexOf(sGroupingSep)).length : sNumero.length;
	for (i = dp-3; i > 0; i -= 3)
		if (sNumero.substring(0,i)!='-')
			sNumero = sNumero.substring(0,i) + sGroupingSep + sNumero.substr(i);
	sNumero = sNumero.replace(/-,/,'-');
	return sNumero;
}

function IR_TrimLeadingZeroes(str)
{
	str = IR_Trim(str);
	
	if (str.length > 0)
		while(str.charAt(0) == '0')
			str = str.substring(1);
		
	return str != "" ? str : "0";
}

function IR_TrimTrailingZeroes(str, nDecimals)
{
	if (str.length > 0)
		while(str.charAt(str.length - 1) == '0')
			str = str.substring(0, str.length - 1);

	var i;
	for (i = str.length; i < nDecimals; i++)
		str += '0';

	return str;
}



// verifica della lunghezza del campo fattore rispetto al formato impostato su PassProdotti
// Restituisce 0 in caso di successo
// Restituisce -1 in caso di superamento della lunghezza massima globale
// Restituisce -2 in caso di superamento della lunghezza massima dei decimali
function IR_VerificaLunghezza(IR_valore, sDecimalSep, sGroupingSep, nNumDecimaliFmt, nMaxLengthFmt)
{
	if (IR_valore.length > 0)
	{
	    var cntSegnoMeno   = IR_ContaIstanzeChar(IR_valore, '-');
	    var cntSepDecimali = IR_ContaIstanzeChar(IR_valore, sDecimalSep); 
	    var cntSepMigliaia = IR_ContaIstanzeChar(IR_valore, sGroupingSep);
		var posSepMigliaia = -1;
		var posSepDecimali = -1;
		var parteIntera	   = IR_valore;
        var parteDecimale  = '';			

		if(sGroupingSep.length > 0)
			posSepMigliaia = IR_valore.indexOf(sGroupingSep, 0);
		if(sDecimalSep.length > 0)
			posSepDecimali = IR_valore.indexOf(sDecimalSep, 0);		
			  
		if(posSepDecimali > -1)
		{
		    parteIntera   = IR_valore.substring(0, posSepDecimali);
			parteDecimale = IR_valore.substring(posSepDecimali + 1, IR_valore.length);
		}
		if(sGroupingSep != '')		
            parteIntera = replaceChar(parteIntera, sGroupingSep, '');

        var lunghParteIntera   = parteIntera.length;
        var lunghParteDecimale = parteDecimale.length;        

		/*
    	alert('DEBUG : \n' +
    	      '[cntSegnoMeno=' + cntSegnoMeno + ']\n' +
    	      '[cntSepDecimali=' + cntSepDecimali + ']\n' +
    	      '[cntSepMigliaia=' + cntSepMigliaia + ']\n' + 
    	      '[posSepMigliaia=' + posSepMigliaia + ']\n' +
    		  '[posSepDecimali=' + posSepDecimali + ']\n' +
    		  '[parteIntera=' + parteIntera + ']\n' +
			  '[parteDecimale=' + parteDecimale + ']\n' +
    		  '[len(parteIntera)=' + lunghParteIntera + ']\n' +
			  '[len(parteDecimale)=' + lunghParteDecimale + ']\n' +
    		  '[FMT len TOTALE=' + nMaxLengthFmt + ']\n' +
			  '[FMT len parte decimale=' + nNumDecimaliFmt + ']\n'
			  );
		*/

		if(nMaxLengthFmt > 0) // se diverso da UNLIMITED_LENGTH..
            if ( (lunghParteIntera + lunghParteDecimale) > nMaxLengthFmt )
				return -1;

		if(nNumDecimaliFmt > 0) // se il formato prevede decimali.. 
            if ( lunghParteDecimale > nNumDecimaliFmt )
            	return -2;
    }
    
    return 0;
}

function IR_FormatCampoNumerico3(IR_oField, sDecimalSep, sGroupingSep)
{
	return IR_FormatCampoNumerico7(IR_oField, sDecimalSep, sGroupingSep, false, 0, -1, 0);
}

function IR_FormatCampoNumerico4(IR_oField, sDecimalSep, sGroupingSep, bNegativoAmmesso)
{
	return IR_FormatCampoNumerico7(IR_oField, sDecimalSep, sGroupingSep, bNegativoAmmesso, 0, -1, 0);
}

function IR_FormatCampoNumerico6(IR_oField, sDecimalSep, sGroupingSep, nNumDecimaliFmt, nMaxLengthFmt, nPadSize)
{
	return IR_FormatCampoNumerico7(IR_oField, sDecimalSep, sGroupingSep, false, nNumDecimaliFmt, nMaxLengthFmt, nPadSize);
}

function IR_FormatCampoNumerico7(IR_oField, sDecimalSep, sGroupingSep, bNegativoAmmesso, nNumDecimaliFmt, nMaxLengthFmt, nPadSize)
{
  	var baseString = IR_oField.value;
  	if(IR_IsValidString(IR_oField.value, 0, IR_oField.value.length, NUMERO_INTERO + '-' + sDecimalSep + sGroupingSep))
  	{
      	if (bNegativoAmmesso || baseString.indexOf("-", 0) == -1)
      	{
	    	var pos = baseString.indexOf("-", 0);
	    	if (baseString.indexOf("-", pos + 1) == -1)
	    	{
				if (sDecimalSep != '')
				{
			    	var pos = baseString.indexOf(sDecimalSep, 0);
			    	if (baseString.indexOf(sDecimalSep, pos + 1) == -1)
			    	{
						if (baseString.length > 0)
						{
							if (baseString.substring(baseString.length - 1) == sDecimalSep)
								baseString = baseString.substring(0, baseString.length - 1);
				
				         	var sParts = (replaceChar(baseString, sGroupingSep, '')).split(sDecimalSep);
	
			         		var sLeft = IR_TrimLeadingZeroes(sParts[0]);
			         		var sRight = IR_TrimTrailingZeroes(sParts.length > 1 ? sParts[1] : '', nNumDecimaliFmt);
	
							if (sGroupingSep != '')
							{
				          		if (sRight.length > 0)
					              	IR_oField.value = IR_InsertPuntiMigliaia(sLeft, sGroupingSep) + sDecimalSep + sRight;
					          	else
					              	IR_oField.value = IR_InsertPuntiMigliaia(sLeft, sGroupingSep);
					        }
					        else
					        {
				          		if (sRight.length > 0)
					              	IR_oField.value = sLeft + sDecimalSep + sRight;
					          	else if (nNumDecimaliFmt > 0)
					              	IR_oField.value = sLeft + sDecimalSep + IR_PadZeroes('', nNumDecimaliFmt);
					          	else
					              	IR_oField.value = sLeft;
					        }
					        
					        var nResVerifica = IR_VerificaLunghezza(IR_oField.value, sDecimalSep, sGroupingSep, nNumDecimaliFmt, nMaxLengthFmt);
							if(nResVerifica != 0)
							{
								if(nResVerifica == -1)
									alert('Lunghezza non ammessa (massima lunghezza consentita : ' + nMaxLengthFmt + ' cifre)');
								if(nResVerifica == -2)
									alert('Eccesso di cifre decimali (massimo consentito : ' + nNumDecimaliFmt + ' cifre decimali)');
							
						        IR_oField.select();
						        IR_oField.focus();								
							}
	
							IR_oField.value = IR_PadZeroes(IR_oField.value, nPadSize);
				       	}
				  	}
				  	else
				  	{
				      	alert('valore non ammesso');
				      	//IR_oField.value="";
				        //IR_oField.select()
				        IR_oField.focus();
				      	//setTimeout(function(){IR_oField.focus();IR_oField.select();},10)
				  	}
				}
				else
				{
					if (baseString.length > 0)
					{
			         	var sLeft = IR_TrimLeadingZeroes(replaceChar(baseString, sGroupingSep, ''));
						
						if (sGroupingSep != '')
			              	IR_oField.value = IR_InsertPuntiMigliaia(sLeft, sGroupingSep);
				        else
			              	IR_oField.value = sLeft;
			              	
				        var nResVerifica = IR_VerificaLunghezza(IR_oField.value, sDecimalSep, sGroupingSep, nNumDecimaliFmt, nMaxLengthFmt);
						if(nResVerifica != 0)
						{
							if(nResVerifica == -1)
								alert('lunghezza non ammessa (massimo consentito : ' + nMaxLengthFmt + ' cifre)');
							if(nResVerifica == -2)
								alert('lunghezza non ammessa (massimo consentito : ' + nNumDecimaliFmt + ' cifre decimali)');
						
					        IR_oField.select();
					        IR_oField.focus();								
						}

						IR_oField.value = IR_PadZeroes(IR_oField.value, nPadSize);
			        }
				}
		  	}
		  	else
		  	{
		      	alert('valore non ammesso');
		      	//IR_oField.value="";
		        //IR_oField.select()
		        IR_oField.focus();
		      	//setTimeout(function(){IR_oField.focus();IR_oField.select();},10)
		  	}
      	}
      	else
      	{
          	alert('valore negativo non ammesso');
          	//IR_oField.value="";
	        //IR_oField.select()
            IR_oField.focus();
          	//setTimeout(function(){IR_oField.focus();IR_oField.select();},10)
      	}
  	}
  	else
  	{
      	alert('valore non ammesso');
      	//IR_oField.value="";
        //IR_oField.select()
        IR_oField.focus();
      	//setTimeout(function(){IR_oField.focus();IR_oField.select();},10)
  	}
}

function IR_PadZeroes(IR_Value, IR_Count)
{
	padding = '';
	
	for (i = IR_Value.length; i < IR_Count; i++)
		padding += '0';
	
	return padding + IR_Value;
}

function IR_FormatCampoData(IR_cCampoData)
{
    var IR_cDataRilascio=IR_getValore(IR_cCampoData);
    IR_cDataRilascio=IR_FormatData(IR_cDataRilascio);
    return IR_cDataRilascio;
}

//IR_### Controlla la validità dell'anno; in caso positivo la funzione restituisce true, false in caso contrario.

function IR_IsAnno(IR_Campo) {
    var IR_value = document.forms[IR_LocalNomeForm].elements[IR_Campo].value;
    var IR_RisAnno = IR_checkIntero("Anno",IR_value);
    if(IR_value!='') {
       if(IR_RisAnno==null){
            if(IR_value.length==4) {
                if (Number(IR_value)< 1900) {
                    alert("L'anno non può essere inferiore al 1900");
                    document.forms[IR_LocalNomeForm].elements[IR_Campo].value="";
    		        document.forms[IR_LocalNomeForm].elements[IR_Campo].focus();
    		        IR_checkAll(IR_LocalNomeForm,false);
    		        return false;
                }
            }
            else {
                alert("L'anno deve avere quattro cifre ");
                document.forms[IR_LocalNomeForm].elements[IR_Campo].value="";
    	        document.forms[IR_LocalNomeForm].elements[IR_Campo].focus();
    	        IR_checkAll(IR_LocalNomeForm,false);
    	        return false;
              }
       }
       else {
            alert("L'anno deve essere un intero");
    		document.forms[IR_LocalNomeForm].elements[IR_Campo].value="";
    		document.forms[IR_LocalNomeForm].elements[IR_Campo].focus();
    		IR_checkAll(IR_LocalNomeForm,false);
    		return false;
     }
    }
    IR_checkAll(IR_LocalNomeForm,false);
    return true;
}

//IR_### Controlla la validità del mese; in caso positivo la funzione restituisce true, false in caso contrario.

function IR_IsMese(IR_Campo) {
    IR_checkAll(IR_LocalNomeForm,false);
    var IR_value = document.forms[IR_LocalNomeForm].elements[IR_Campo].value;
    var IR_RisMese = IR_checkIntero("Mese",IR_value);
    if(IR_value!='') {
       if(IR_RisMese==null){
            if ((IR_value.length < 2) && (IR_value.length > 0) && (IR_RisMese==null) && (IR_value < 13)&& (IR_value != "0")) {
    			IR_value = '0' + IR_value;
    			document.forms[IR_LocalNomeForm].elements[IR_Campo].value = IR_value ;
    			return true;
        	}
        	else {
    			if ((IR_value > 12) || (IR_value < 1)) {
    				alert("Mese non corretto");
    				document.forms[IR_LocalNomeForm].elements[IR_Campo].value="";
    				document.forms[IR_LocalNomeForm].elements[IR_Campo].focus();
    				return false;
    			}
        	}
       }
       else {
            alert("Il mese deve essere un intero");
    		document.forms[IR_LocalNomeForm].elements[IR_Campo].value="";
    	    document.forms[IR_LocalNomeForm].elements[IR_Campo].focus();
    		return false;
       }
       IR_checkAll(IR_LocalNomeForm,false);
    }
    return true;
}


function IR_stampaSpazi(IR_spazi)
{

    var IR_cStringaDiSpazi="";
    for ( var i= 0; i<IR_spazi; i++)
    {
        IR_cStringaDiSpazi=IR_cStringaDiSpazi+'&nbsp;';
    }
    return IR_cStringaDiSpazi;
}


function IR_FillaNumeroContratto(IR_nMaxLen,IR_nLen)
{

    IR_nDiff=IR_nMaxLen-IR_nLen;
    var IR_cStringa="";
    var i;

    for (i=0;i<IR_nDiff;i++){
        IR_cStringa=IR_cStringa+'0';
    }

    return IR_cStringa;

}


// IR_### IR_getParameter : restituisce il valore di un parametro passato sulla URL

function P(stringa) { document.write(stringa); }

function IR_getParameter(parameter) {
     qs = location.search;
     //IR_### .toLowerCase();
     if (qs.indexOf(parameter+"=")==(-1)) return null;
     start = qs.indexOf(parameter) + parameter.length + 1;
     valore = '';
     for ( i=start; ( (c=qs.charAt(i)) && (i<location.search.length) ); i++) {
         if (c=='&') break; else valore = valore + c;
         }
     //IR_### for
     return valore;
     }
     //IR_### function getParameter(..)

// IR_### IR_centra : centra e ridimensiona la finesrta

function IR_centra() {
    var screenWidth = screen.width;
    var screenHeight = screen.height;
    var parameterWidth = IR_getParameter('width');
    var parameterHeight = IR_getParameter('height');

    if (parameterWidth!=null && parameterHeight!=null) {
        if (parameterWidth.length>0 && parameterHeight.length>0) {
            window.resizeTo(parameterWidth,parameterHeight);
            }
        //IR_### if
        }
    //IR_### if
    var width = window.outerWidth;
    var height = window.outerHeight;
    window.screenX = (screenWidth-width)/2;
    window.screenY = (screenHeight-height)/2;
    }
    //IR_### centraEDaiFuoco


//IR_### Il valore all'interno di un campo viene formattato in maiuscolo

function IR_toUpperCase(IR_cForm,IR_cNomeCampo)
{
    var IR_cVal = document.forms[IR_cForm].elements[IR_cNomeCampo].value;

    if (IR_cVal.length > 0)
        document.forms[IR_cForm].elements[IR_cNomeCampo].value = IR_cVal.toUpperCase();
 }


//IR_### Il valore all'interno di un campo viene formattato in minuscolo

function IR_toLowerCase(IR_cForm,IR_cNomeCampo)
{
    var IR_cVal = document.forms[IR_cForm].elements[IR_cNomeCampo].value;

    if (IR_cVal.length > 0)
        document.forms[IR_cForm].elements[IR_cNomeCampo].value = IR_cVal.toLowerCase();
 }


//IR_### Abilito tutti i campi della FORM passatami in input
 function IR_EnableAllFields(IR_cForm)
{
    var IR_cVal = document.forms[IR_cForm].elements
    var IR_iIndex = 0;

    for (IR_iIndex = 0; IR_iIndex < IR_cVal.length; IR_iIndex++ )
        IR_cVal[IR_iIndex].disabled=false;
 }

//IR_### Disabilito tutti i campi della FORM passatami in input
 function IR_DisableAllFields(IR_cForm)
{
    var IR_cVal = document.forms[IR_cForm].elements
    var IR_iIndex = 0;

    for (IR_iIndex = 0; IR_iIndex < IR_cVal.length; IR_iIndex++ )
        IR_cVal[IR_iIndex].disabled=true;
 }

// IR_### restituisce la proprietà richiesta
function getProperty(key) {
    for (var i=0; i<RGICollection.length; i++)
    {
        if (RGICollection[i][0]==key)
        {

            var IR_Ret=RGICollection[i][1]
            if(typeof(IR_Ret)=="string")
             IR_Ret=IR_Ret.replace("&#39;","'");
            return IR_Ret;
        }

    }
    return null;
}
// IR_### getProperty

// IR_### imposta la proprietà specificata
function setProperty(key, value)
{
    for (var i=0; i<RGICollection.length; i++)
    {
      if (RGICollection[i][0]==key)
          RGICollection[i][1]=value;
    }
}

function IR_GetRadioButtonSelectedItemIndex(IR_oRadioButton)
{
	var IR_x;
	var IR_nIndex = -1;

	if(IR_oRadioButton.length == null)
	{
		if(IR_oRadioButton.checked == true)
			IR_nIndex = IR_x;
	}
	else
	{
		for(IR_x = 0; IR_x < IR_oRadioButton.length; IR_x++)
		{
			if(IR_oRadioButton[IR_x].checked == true)
				IR_nIndex = IR_x;
		}
	}

	return IR_nIndex;
}

function IR_GetRadioButtonSelectedItemValue(IR_oRadioButton)
{
	var IR_x;
	var IR_cValue = '';


	if(IR_oRadioButton.length == null)
	{
		if(IR_oRadioButton.checked == true)
			IR_cValue = IR_oRadioButton.value;
	}
	else
	{
		for(IR_x = 0; IR_x < IR_oRadioButton.length; IR_x++)
		{
			if(IR_oRadioButton[IR_x].checked == true)
				IR_cValue = IR_oRadioButton[IR_x].value;
		}
	}

	return IR_cValue;
}


// IR_### Restituisce il valore di un cookie, per esempio getCookieValue("cookie1") restituisce valore1 nella stringa
// IR_### di tutti i cookie disponibili: cookie0=valore0;cookie1=valore1;cookie2=valore2;...;cookieN=valoreN;
function IR_getCookieValue(IR_name)
{
    var IR_allCookies = document.cookie;
    var IR_label = IR_name+"=";
    for (var i=0; i<IR_allCookies.length; i++)
    {
         var j = i + IR_label.length;
         if (IR_allCookies.substring(i,j) == IR_label)
         {
            var IR_endPosition = IR_allCookies.indexOf(";",j)
            if (IR_endPosition==(-1)) IR_endPosition=IR_allCookies.length;
            return unescape(IR_allCookies.substring(j,IR_endPosition));
         }
    }
    return "";
}

// IR_### Imposta il valore di un cookie, per esempio setCookieValue("cookie1","value1") inserisce/aggiorna la stringa
// IR_### di tutti i cookie disponibili: cookie0=valore0;cookie1=valore1;cookie2=valore2;...;cookieN=valoreN;
function IR_setCookieValue(IR_name,IR_value)
{
    document.cookie = IR_name+"="+escape(IR_value);
}

//IR_###prelevo il value selezionato dalla combo
function IR_GetComboBoxSelectedItemValue(IR_oComboBox)
{
		var IR_cValue ="";
		if(IR_oComboBox.selectedIndex != -1)
		{
			IR_cValue = IR_oComboBox.options[IR_oComboBox.selectedIndex].value;
		}
		return IR_cValue;
}

function IR_GetComboBoxSelectedItemText(IR_oComboBox)
{
	var IR_cValue ="";
	if(IR_oComboBox.selectedIndex != -1)
	{
		IR_cValue = IR_oComboBox.options[IR_oComboBox.selectedIndex].text;
	}
	return IR_cValue;
}
//IR_### formattazione del VALORE
function IR_PreparaPrimoCarattereMaiuscoloLoc(IR_cForm, IR_cNomeCampo)
{
    var IR_nCompleta;
    var IR_sCarattere;
    var IR_cSalvaCarattere;
    var IR_cTemp = "";
    var IR_cComodo;
    var IR_CCampo=IR_cNomeCampo;
    IR_CCampo =IR_LeftTrimExtended(IR_CCampo,0);

    var i=0;
    var Len=IR_CCampo.length;

    for(i=0;i<Len;i++)
    {
        if(i==0)
        {
            IR_cTemp=IR_CCampo.charAt(i);
            IR_cTemp=IR_cTemp.toUpperCase();
        }
        else
        {
            IR_cComodo=IR_CCampo.charAt(i);
            if ((IR_CCampo.charAt(i-1)==" ")&& (IR_CCampo.charAt(i)== " "))
            {
                //IR_### salta
            }
            else
            {

                if ((IR_CCampo.charAt(i-1)=="'") || (IR_CCampo.charAt(i-1)==" ") || (IR_CCampo.charAt(i-1)=="."))
                {

                        IR_cTemp=IR_cTemp+IR_cComodo.toUpperCase();
                }
                else
                {
                        IR_cTemp=IR_cTemp+IR_cComodo.toLowerCase();
                }
            }

        }

    }
    return IR_cTemp;

}

//IR_### formattazione del campo
function IR_PreparaPrimoCarattereMaiuscolo(IR_cForm, IR_cNomeCampo)
{

    var IR_nCompleta;
    var IR_sCarattere;
    var IR_cSalvaCarattere;
    var IR_cTemp = "";
    var IR_cComodo;
    var IR_CCampo=document.forms[IR_cForm].elements[IR_cNomeCampo].value;

    IR_CCampo =IR_LeftTrimExtended(IR_CCampo,0);

    var i=0;
    var Len=IR_CCampo.length;

    for(i=0;i<Len;i++)
    {
        if(i==0)
        {
            IR_cTemp=IR_CCampo.charAt(i);
            IR_cTemp=IR_cTemp.toUpperCase();
        }
        else
        {
            IR_cComodo=IR_CCampo.charAt(i);

            if ((IR_CCampo.charAt(i-1)==" ")&& (IR_CCampo.charAt(i)== " "))
            {
            }
            else
            {

                if ((IR_CCampo.charAt(i-1)=="'") || (IR_CCampo.charAt(i-1)==" ") || (IR_CCampo.charAt(i-1)=="."))
                {

                    IR_cTemp=IR_cTemp+IR_cComodo.toUpperCase();

                }
                else
                {
                    IR_cTemp=IR_cTemp+IR_cComodo.toLowerCase();
                }
            }

        }

    }
    document.forms[IR_cForm].elements[IR_cNomeCampo].value=IR_cTemp;

}

function IR_FormattaPrimoCarattereMaiuscolo(IR_cNomeCampo)
{
  IR_cNomeCampo = IR_cNomeCampo.toLowerCase();
	var IR_char = IR_cNomeCampo.substring(0,1).toUpperCase();
	IR_cNomeCampo = IR_char + IR_cNomeCampo.substring(1,IR_cNomeCampo.length);
	return IR_cNomeCampo;
}

//IR_###9/05/2001
function IR_ModificaStatoItem(IR_FormName, IR_FieldName, IR_ValueStatus)
{
		var IR_ret;
		var IR_NameFieldStatus = "";

//IR_### alert("modifica stato in : " + IR_ValueStatus);

		IR_NameFieldStatus = "CKIMGSTATO_" + IR_FieldName;

		IR_ret = IR_UpdateStatus(IR_FormName, IR_NameFieldStatus , IR_ValueStatus);

		return(IR_ret);
}


//IR_### La chiave Allestimento è così composta:
//IR_###    - 6 caratteri per identificare il codice allestimento
//IR_###    - 4 caratteri per identificare l'anno di registrazione
//IR_###    - 2 caratteri per identificare il mese di registrazione
//IR_###
//IR_### Es:
//IR_###    IR_setKeyAllestimento("000001", 1999, 10)
//IR_### La Key restituita sarà una stringa così composta:
//IR_###    "000001199910"
function IR_setKeyAllestimento(IR_cCodAllestimento, IR_nAnnoReg, IR_nMeseReg)
{
    var IR_Key = IR_cCodAllestimento + IR_nAnnoReg;
    if (IR_nMeseReg.length==1)
        IR_Key = IR_Key + "0" + IR_nMeseReg;
    else
        IR_Key = IR_Key + IR_nMeseReg;
    return IR_Key;
}

function IR_getCodAllestimentoFromKeyAllestimento(IR_Key)
{

    var IR_Rit = "";

    IR_Key=IR_Trim(IR_Key);

    if (IR_Key.length!=12)
        alert("Chiave Allestimento " + IR_Key + " non valida.");
    else
        IR_Rit = IR_Key.substr(0,6);

    return IR_Rit;
}

function IR_getAnnoRegFromKeyAllestimento(IR_Key)
{

    var IR_Rit = "";

    IR_Key=IR_Trim(IR_Key);

    if (IR_Key.length!=12)
        alert("Chiave Allestimento " + IR_Key + " non valida.");
    else
        IR_Rit = IR_Key.substr(6,4);

    return IR_Rit;
}

function IR_getMeseRegFromKeyAllestimento(IR_Key)
{
    var IR_Rit = "";

    IR_Key=IR_Trim(IR_Key);

    if (IR_Key.length!=12)
        alert("Chiave Allestimento " + IR_Key + " non valida.");
    else
        IR_Rit = IR_Key.substr(10,2);

    return IR_Rit;
}


function IR_AllFieldsEmpty(IR_FormName)
	{
		var IR_Name;
		var IR_NameFieldPrefix;
		var x;

		for(x = 0; x < document.forms[IR_FormName].length; x++)
		{
		    if(document.forms[IR_FormName].elements[x].type != 'hidden')
		    {
			    IR_Name = document.forms[IR_FormName].elements[x].name;
			    IR_NameFieldPrefix = IR_Name.substr(0, 5);


//IR_### alert("IR_Name, Prefix, type : " + IR_Name + " , " + IR_NameFieldPrefix + " , " + document.forms[IR_FormName].elements[x].type);

			    if(IR_NameFieldPrefix != 'CKIMG')
			    {

				    if((IR_Trim(document.forms[IR_FormName].elements[IR_Name].value)) != "")
				    {
//IR_### alert(IR_Name + "=" + IR_Trim(document.forms[IR_FormName].elements[IR_Name].value));
					    IR_Ret = false;
					    break;
				    }
			    }
		    }
		}

		return IR_Ret;
}


function IR_ControllaAttestatoDiRischio()
{

    var bVisualizza=false;
    var IR_ValoreProvenienza = IR_getValore('RGI_ABBREVIAZIONE_PROVENIENZA');
    if (getProperty('RGI_SOSTITUZIONE')!=null)
    {
        if(getProperty('RGI_SOSTITUZIONE')!="0")
        {
            if((getProperty('RGI_SOSTITUZIONE')==IR_constNSostScSsCv)||(getProperty('RGI_SOSTITUZIONE')==IR_constNSostCsSc))
            {
                if ((IR_ValoreProvenienza !="")&&(IR_ValoreProvenienza !='0'))
                {
                    bVisualizza=true;
                    return bVisualizza;
                 }
            }
            else
            {
                bVisualizza=false;
                return bVisualizza;
            }
        }
    }

    if ((IR_ValoreProvenienza =="")||(IR_ValoreProvenienza =='0'))
        return bVisualizza;
     else
        return true;

}


function IR_EsisteAttestatoDiRischio()
{

    var bVisualizza=false;
    var IR_ClasseBM = IR_getValore('PeatrNclassebmass');

    if ((IR_ClasseBM !="") && (Number(IR_ClasseBM) > 0 ))
        return true;
     else
        return false;

}


function IR_ControllaContraente()
{
    var bVisualizza;

    var IR_Cognome = getProperty('RGI_CONTRAENTE_COGNOME');
    var IR_Denominazione = getProperty('RGI_CONTRAENTE_DENOMINAZIONE');

    if ((IR_Cognome != null)&&(IR_Cognome != ""))
    {
        if(IR_Cognome == "")  bVisualizza = true;
        else  bVisualizza = false;
    }
    else
    {
        if ((IR_Denominazione != null) && (IR_Denominazione != ""))
        {
            if(IR_Denominazione == "") bVisualizza = true;
            else  bVisualizza = false;
        }
        else  bVisualizza = true;
    }

    return  bVisualizza;
}

function IR_ControlliEsecuzioneHistoryBack() {
    IR_ControlliEsecuzioneHistoryBack(true);
    }

function IR_ControlliEsecuzioneHistoryBack(IR_ShowAlert) {
    var COOKIE_NAME = 'Counter';
    var cookie = IR_getCookieValue(COOKIE_NAME);
    var pageNumber = Number(getProperty(COOKIE_NAME));
    if (cookie!=null) {
        var counter = Number(cookie);
        if ((counter>pageNumber)&&(pageNumber>1)) {
            alert('Non puoi utilizzare il tasto "INDIETRO" del browser!\r\n\r\nL\'operazione in corso è stata annullata,\r\nsei costretto a ricominciare da capo.');
            document.location.href=IR_getMenuLink();
            }
        //IR_### if
        }
       //IR_### if
    IR_setCookieValue(COOKIE_NAME,pageNumber);
    if (IR_ShowAlert) {
        var msg = getProperty('RGIAlert');
        if (msg!=null) alert(msg);
        }
    }
    //IR_### IR_ControlliEsecuzioneHistoryBack

function HistoryBack(numero) {
    var COOKIE_NAME = 'Counter';
    var richiesta = Number(numero);
    if (richiesta>(-1)) {
        alert('APPLICATION ERROR: numero deve essere minore di 0 in "HistoryBack()!"');
        return;
        }
       //IR_### if
    var cookie = IR_getCookieValue(COOKIE_NAME);
    if (cookie!=null) {
        var counter = Number(cookie);
        IR_setCookieValue(COOKIE_NAME,(counter+richiesta));
        }
        //IR_### if
    if (richiesta==(-1))
        history.back();
        else
        history.back(richiesta);
}
//IR_### HistoryBack()

//IR_### formattazione del campo
function IR_FormattaStringa(input) {
    var IR_nCompleta;
    var IR_sCarattere;
    var IR_cSalvaCarattere;
    var IR_cTemp = "";
    var IR_cComodo;
    var IR_CCampo = input;
    IR_CCampo =IR_LeftTrimExtended(IR_CCampo,0);
    var i=0;
    var Len=IR_CCampo.length;
    IR_CCampo = IR_CCampo.replace("&#39;","'");

    for(i=0;i<Len;i++) {
        if(i==0)
        {
            IR_cTemp=IR_CCampo.charAt(i);
            IR_cTemp=IR_cTemp.toUpperCase();
        }
        else
        {
            IR_cComodo=IR_CCampo.charAt(i);

                if ((IR_CCampo.charAt(i-1)==" ")&& (IR_CCampo.charAt(i)== " "))
                {
                }
                else
                {
                    if ((IR_CCampo.charAt(i-1)=="'") || (IR_CCampo.charAt(i-1)==" ") || (IR_CCampo.charAt(i-1)=="."))

                    {
                            IR_cTemp=IR_cTemp+IR_cComodo.toUpperCase();
                    }
                    else
                    {
                            IR_cTemp=IR_cTemp+IR_cComodo.toLowerCase();
                    }
                }

        }

    }
    return IR_cTemp;
}


function IR_getDescrStato(IR_nStato)
{
var IR_Zombie = "Zombie "
var IR_Proposta = "Proposta "
var IR_Polizza = "Polizza "
var IR_PropostaAnonima ="PropostaAnonima"
if (IR_nStato == IR_constSDNumPolizza) return IR_Polizza;
if (IR_nStato == IR_constSDNumProposta) return IR_Proposta;
if (IR_nStato == IR_constSDNumPropostaAnonima) return IR_PropostaAnonima;
if (IR_nStato == IR_constSDNumZombie) return IR_Zombie;
return "Errore";
}


function IR_getDescrStatoDettagliato(IR_nStatoDettagliato) {
    switch (IR_nStatoDettagliato)
    {
        case IR_constSDProposta:
            return IR_constSDDescrProposta;

        case IR_constSDPropostaRichiesta:
            return IR_constSDDescrPropostaRichiesta;

        case IR_constSDPropostaValidata:
            return IR_constSDDescrPropostaValidata;

        case IR_constSDPropostaScaduta:
            return IR_constSDDescrPropostaScaduta;

        case IR_constSDPolizza:
            return IR_constSDDescrPolizza;

        case IR_constSDPolizzaValida:
            return IR_constSDDescrPolizzaValida;

        case IR_constSDPolizzaSospesa:
            return IR_constSDDescrPolizzaSospesa;

        case IR_constSDPolizzaAnnullata:
            return IR_constSDDescrPolizzaAnnullata;

        case IR_constSDPolizzaScaduta:
            return IR_constSDDescrPolizzaScaduta;

        case IR_constSDPolizzaSostituita:
            return IR_constSDDescrPolizzaSostituita;

        case IR_constSDPolizzaAttesaDecorrenza:
            return IR_constSDDescrPolizzaAttesaDecorrenza;

        case IR_constSDPolizzaAttesaCopertura:
            return IR_constSDDescrPolizzaAttesaCopertura;

        case IR_constSDPropostaAnnullata:
            return IR_constSDDescrPropostaAnnullata;

        case IR_constSDPropostaAnonima:
            return IR_constSDDescrPropostaAnonima;

        default:
            return IR_constSDDescrNull;
    }
}


function IR_QueryString(input,property) {
    var queryString ;
    var stringInput;
    var lenproperty;
    var indexNextToken;
    var index;
    var parametro ;
    var value ;
    lenproperty = property.length;


    stringInput = input.toString();
    if (stringInput ==null || stringInput =="?") return 0;
    if (stringInput.indexOf('?')==0)
        queryString=stringInput.substring(1);
    else
        queryString=stringInput;

    index = queryString.indexOf(property);
    index = index + lenproperty + 1;
    if(index!=0)
    {

        indexNextToken = queryString.substring(index).indexOf('&');
        parametro = queryString.substring(index);

        if (indexNextToken > 0)
            value = parametro.substring(0,indexNextToken );
        else
        {
            if (indexNextToken == 0)
             value = null;
            else
             value = parametro.substring(0);
        }
     }
    return value;
}


function IR_ControllaTarga(IR_cTarga)
{

    var IR_Ret;
	var IR_xxTarga;

	IR_xxTarga = IR_cTarga;

	IR_Ret = IR_IsStringOfDigits(IR_xxTarga, 0, 1);
	if(IR_Ret == false)
	{
		IR_Ret = IR_IsStringOfDigits(IR_xxTarga, 1, 2);
		if (IR_Ret == true )
		    return false;
	    else
			return true;
	}
	else
        return false;

    return true;

}


function IR_ConvertiInLire(cNomeCampo)
{

    var IR_cSegno=cNomeCampo.charAt(0);
    cNomeCampo=String(cNomeCampo);
    if (IR_cSegno=="-")
        cNomeCampo=cNomeCampo.substring(1,cNomeCampo.length)

    var IR_cImportoDeformattato;
    var IR_nImportoDeformattato;
    var IR_ImportoLire;
    if ((cNomeCampo!=0)||(cNomeCampo!="")||(cNomeCampo!=null))
    {
        IR_cImportoDeformattato= IR_FormattaImporto(cNomeCampo,2)
        IR_cImportoDeformattato= IR_DeformattaImporto(IR_cImportoDeformattato);
        IR_nImportoDeformattato = IR_ConvertiStringaInImporto(IR_cImportoDeformattato);
        IR_ImportoLire=IR_FormattaImporto(IR_ConvertiImportoInLire(IR_nImportoDeformattato, 0));
    }
    else
        IR_ImportoLire=0;

    if (IR_cSegno=="-")
        IR_ImportoLire=IR_cSegno+IR_ImportoLire;

    return IR_ImportoLire;

}

//IR_### function IR_CAPChanged(IR_oldCap,IR_newCap)
//IR_### {

	//IR_### var IR_oldCap;
	//IR_### var IR_1old;
	//IR_### var IR_2old;
	//IR_### var IR_3old;
	//IR_### var IR_4old;
	//IR_### var IR_5old;
	//IR_### var IR_newCap;
	//IR_### var IR_1new;
	//IR_### var IR_2new;
	//IR_### var IR_3new;
	//IR_### var IR_4new;
	//IR_### var IR_5new;

    //IR_### if ((IR_newCap != IR_oldCap) && (IR_oldCap.length>0))
	//IR_### {
	    //IR_### IR_1new = IR_newCap.charAt(0);
		//IR_### IR_2new = IR_newCap.charAt(1);
		//IR_### IR_3new = IR_newCap.charAt(2);
		//IR_### IR_4new = IR_newCap.charAt(3);
		//IR_### IR_5new = IR_newCap.charAt(4);

		//IR_### IR_1old = IR_oldCap.charAt(0);
		//IR_### IR_2old = IR_oldCap.charAt(1);
		//IR_### IR_3old = IR_oldCap.charAt(2);
		//IR_### IR_4old = IR_oldCap.charAt(3);
		//IR_### IR_5old = IR_oldCap.charAt(4);

		//IR_### if((IR_1old == IR_1new) && (IR_2old == IR_2new) && (IR_3old == IR_3new))
		//IR_### {
		    //IR_### switch (IR_3new)
			//IR_### {
				//IR_### case "1":
				//IR_### case "3":
				//IR_### case "5":
				//IR_### case "7":
				//IR_### case "9":
				    //IR_### document.forms['RGI_FORM_ANAG_PROP2'].elements['IR_CapResOriginale'].value = document.forms['RGI_FORM_ANAG_PROP2'].elements['PaindirizzoCcapRs'].value;
					//IR_### break;
				//IR_### default:
					//IR_### alert ("Il cap non puo' essere modificato ");
					//IR_### document.forms['RGI_FORM_ANAG_PROP2'].elements['PaindirizzoCcapRs'].value = document.forms['RGI_FORM_ANAG_PROP2'].elements['IR_CapResOriginale'].value;
					//IR_### document.forms['RGI_FORM_ANAG_PROP2'].elements['PaindirizzoCcapRs'].focus();
					//IR_### break;
			//IR_### }
        //IR_### }
		//IR_### else
		//IR_### {
		    //IR_### alert ("Il cap non puo' essere modificato ");
			//IR_### document.forms['RGI_FORM_ANAG_PROP2'].elements['PaindirizzoCcapRs'].value = document.forms['RGI_FORM_ANAG_PROP2'].elements['IR_CapResOriginale'].value;
			//IR_### document.forms['RGI_FORM_ANAG_PROP2'].elements['PaindirizzoCcapRs'].focus();
		//IR_### }
    //IR_### }

//IR_### }//IR_CAPChanged



function IR_getDescrEsitoTitolo(IR_nEsito)
{

    switch (Number(IR_nEsito))
    {
        case IR_ETDaEmettere:
            return IR_Descr_ETDaEmettere;

        case IR_ETEmesso:
            return IR_Descr_ETEmesso;

        case IR_ETIncassato:
            return IR_Descr_ETIncassato;

        case IR_ETAnnullato:
            return IR_Descr_ETAnnullato;

        default:
            return "";
    }

}


function IR_getDescrTipoTitolo(IR_nTipo)
{

    switch (Number(IR_nTipo))
    {
        case IR_TTEmissione:
            return IR_Descr_TTEmissione;

        case IR_TTRinnovo:
            return IR_Descr_TTRinnovo;

        case IR_TTQuietanza:
            return IR_Descr_TTQuietanza;

        case IR_TTAnnullamento:
            return IR_Descr_TTAnnullamento;

        case IR_TTSostituzione:
            return IR_Descr_TTSostituzione;

        case IR_TTSospensione:
            return IR_Descr_TTSospensione;

        case IR_TTAppendice:
            return IR_Descr_TTAppendice;

        case IR_TTStorno:
            return IR_Descr_TTStorno;

        default:
            return "";
    }

}

function IR_GetTipoEditing(IR_nOperazione,IR_cValore)
{

    var IR_bReturn=1;

    if(IR_nOperazione==IR_constNSostituzioneSenzaCambioVeicolo)
    {
        if (IR_cValore!="")
            IR_bReturn=2
        else
            IR_bReturn=0
    }

    return IR_bReturn;

}

function IR_CreaCampoNascosto(IR_cNomeCampo,IR_cValue) {
    P('<INPUT type="HIDDEN" name="'+IR_cNomeCampo+'"');
    if((IR_cValue != null )&&(IR_cValue != "" ))
        P(' value="'+IR_cValue +'"');
    P('>');
}

function IR_CreaComboGiorni(IR_cNome, IR_cAddendum,IR_bVuoto)
{
    P('<SELECT name="'+IR_cNome+'" '+IR_cAddendum+'>');
    if (IR_bVuoto==true)
        P('<OPTION value=""></OPTION>');
    P('<OPTION value="01">01</OPTION>');
    P('<OPTION value="02">02</OPTION>');
    P('<OPTION value="03">03</OPTION>');
    P('<OPTION value="04">04</OPTION>');
    P('<OPTION value="05">05</OPTION>');
    P('<OPTION value="06">06</OPTION>');
    P('<OPTION value="07">07</OPTION>');
    P('<OPTION value="08">08</OPTION>');
    P('<OPTION value="09">09</OPTION>');
    P('<OPTION value="10">10</OPTION>');
    P('<OPTION value="11">11</OPTION>');
    P('<OPTION value="12">12</OPTION>');
    P('<OPTION value="13">13</OPTION>');
    P('<OPTION value="14">14</OPTION>');
    P('<OPTION value="15">15</OPTION>');
    P('<OPTION value="16">16</OPTION>');
    P('<OPTION value="17">17</OPTION>');
    P('<OPTION value="18">18</OPTION>');
    P('<OPTION value="19">19</OPTION>');
    P('<OPTION value="20">20</OPTION>');
    P('<OPTION value="21">21</OPTION>');
    P('<OPTION value="22">22</OPTION>');
    P('<OPTION value="23">23</OPTION>');
    P('<OPTION value="24">24</OPTION>');
    P('<OPTION value="25">25</OPTION>');
    P('<OPTION value="26">26</OPTION>');
    P('<OPTION value="27">27</OPTION>');
    P('<OPTION value="28">28</OPTION>');
    P('<OPTION value="29">29</OPTION>');
    P('<OPTION value="30">30</OPTION>');
    P('<OPTION value="31">31</OPTION>');
    P('</SELECT>');

}

function IR_CreaComboMese(IR_cNome, IR_cAddendum,IR_bVuoto)
{
    P('<SELECT name="'+IR_cNome+'" '+IR_cAddendum+'>');
    if (IR_bVuoto==true)
        P('<OPTION value=""></OPTION>');

    P('<OPTION value="01">Gennaio</OPTION>');
    P('<OPTION value="02">Febbraio</OPTION>');
    P('<OPTION value="03">Marzo</OPTION>');
    P('<OPTION value="04">Aprile</OPTION>');
    P('<OPTION value="05">Maggio</OPTION>');
    P('<OPTION value="06">Giugno</OPTION>');
    P('<OPTION value="07">Luglio</OPTION>');
    P('<OPTION value="08">Agosto</OPTION>');
    P('<OPTION value="09">Settembre</OPTION>');
    P('<OPTION value="10">Ottobre</OPTION>');
    P('<OPTION value="11">Novembre</OPTION>');
    P('<OPTION value="12">Dicembre</OPTION>');
    P('</SELECT>');
}


function IR_CreaComboAnno(IR_cNome,IR_nAnni,IR_cAddendum,IR_bVuoto)
{
    P('<SELECT name="'+IR_cNome+'" '+IR_cAddendum+'>');
    var i=0;
    var IR_AnnoCorrente=IR_GetYearFromLong(IR_GetTodayDateAsLong())
    var anno;
    for(i;i<IR_nAnni;i++)
    {
        if ((IR_bVuoto==true)&&(i==0))
            P('<OPTION value=""></OPTION>');
        anno=IR_AnnoCorrente-i;
        P('<OPTION value='+anno+'>'+anno+'</OPTION>');
    }
    P('</SELECT>');
}

function IR_CreaComboAnnoScadPol(IR_cNome,IR_nAnni,IR_cAddendum,IR_bVuoto)
{
    P('<SELECT name="'+IR_cNome+'" '+IR_cAddendum+'>');
    var i=0;
    var IR_AnnoCorrente=IR_GetYearFromLong(IR_GetTodayDateAsLong())
    var anno;
    for(i;i<IR_nAnni;i++)
    {
        if ((IR_bVuoto==true)&&(i==0))
            P('<OPTION value=""></OPTION>');
        anno=IR_AnnoCorrente+i;
        P('<OPTION value='+anno+'>'+anno+'</OPTION>');
    }
    P('</SELECT>');
}

function IR_CreaComboAnnoDataDec(IR_cNome,IR_nAnni,IR_cAddendum,IR_bVuoto)
{
    var IR_Primo=true;
    P('<SELECT name="'+IR_cNome+'" '+IR_cAddendum+'>');
    var i=0;
    var IR_AnnoCorrente=IR_GetYearFromLong(IR_GetTodayDateAsLong())
    var anno;
    for(i;i<IR_nAnni;i++)
    {
        if ((IR_bVuoto==true)&&(i==0))
            P('<OPTION value=""></OPTION>');
        if (IR_Primo==true)
        {
            anno=IR_AnnoCorrente-1;
            IR_Primo=false
        }
        else
            anno=IR_AnnoCorrente+i-1;
        P('<OPTION value='+anno+'>'+anno+'</OPTION>');
    }
    P('</SELECT>');
}

function IR_CreaComboAnnoAvanti(IR_cNome,IR_nAnni,IR_cAddendum,IR_bVuoto)
{
    P('<SELECT name="'+IR_cNome+'" '+IR_cAddendum+'>');
    var i=0;
    var IR_AnnoCorrente=IR_GetYearFromLong(IR_GetTodayDateAsLong())
    var anno;
    for(i;i<IR_nAnni;i++)
    {
        if ((IR_bVuoto==true)&&(i==0))
            P('<OPTION value=""></OPTION>');
        anno=IR_AnnoCorrente+i;
        P('<OPTION value='+anno+'>'+anno+'</OPTION>');
    }
    P('</SELECT>');
}
// IR_modifica dinamicamente la combo dei giorni in base al mese e all'anno, di quest'ultimo viene controllate se è bisestile.
// Chi utilizza questa funzione deve aver creato le combo con questi nomi: Giorno,Mese,Anno
function IR_ModificaItemGiorni(IR_cDay,IR_nMonth,IR_nYear,IR_bVuoto)
{
    var IR_nCounter;
    var IR_objOption;
    var IR_cText;
    var IR_nCorrettore = 0;
    var IR_nElements = document.forms[IR_LocalNomeForm].elements[IR_cDay].length;

    IR_nMaxDays = IR_GetNumberOfDaysInMonth(Number(IR_nMonth),Number(IR_nYear));

    if(IR_bVuoto)
    {
        IR_nCorrettore = 1;
    }

    if((document.forms[IR_LocalNomeForm].elements[IR_cDay].selectedIndex + 1) > IR_nMaxDays)
        document.forms[IR_LocalNomeForm].elements[IR_cDay].selectedIndex = IR_nMaxDays - 1;

    for(IR_nCounter = IR_nMaxDays+IR_nCorrettore; IR_nCounter < IR_nElements; IR_nCounter++)
        document.forms[IR_LocalNomeForm].elements[IR_cDay].removeChild(document.forms[IR_LocalNomeForm].elements[IR_cDay].options[IR_nMaxDays+IR_nCorrettore]);
/*
    if(IR_bVuoto)
    {
        IR_objOption = new Option('', '', false, false);
        document.forms[IR_LocalNomeForm].elements[IR_cDay].options[document.forms[IR_LocalNomeForm].elements[IR_cDay].length] = IR_objOption;
    }
*/
    for(IR_nCounter = IR_nElements+1-IR_nCorrettore; IR_nCounter <= IR_nMaxDays; IR_nCounter++)
    {
        IR_cText = IR_nCounter;

        if(IR_nCounter < 10)
            IR_cText = "0" + IR_cText;

        IR_objOption = new Option(IR_cText, IR_nCounter, false, false);

        document.forms[IR_LocalNomeForm].elements[IR_cDay].options[document.forms[IR_LocalNomeForm].elements[IR_cDay].length] = IR_objOption;
    }

    return 0;
}

// IR_modifica dinamicamente la combo dei giorni in base al mese e all'anno, di quest'ultimo viene controllate se è bisestile.
// Chi utilizza questa funzione deve aver creato le combo con questi nomi: Giorno,Mese,Anno
function IR_ModificaItemGiorniA(IR_cDay,IR_nMonth,IR_nYear)
{
    var IR_nCounter;
    var IR_objOption;
    var IR_cText;
    var IR_nElements = document.forms[IR_LocalNomeForm].elements[IR_cDay].length;

    for(IR_nCounter = 0; IR_nCounter < IR_nElements; IR_nCounter++)
        document.forms[IR_LocalNomeForm].elements[IR_cDay].removeChild(document.forms[IR_LocalNomeForm].elements[IR_cDay].options[0]);

    IR_nMaxDays = IR_GetNumberOfDaysInMonth(Number(IR_nMonth),Number(IR_nYear));

    for(IR_nCounter = 1; IR_nCounter <= IR_nMaxDays; IR_nCounter++)
    {
        IR_cText = IR_nCounter;

        if(IR_nCounter< 10)
            IR_cText = "0" + IR_cText;

        IR_objOption = new Option(IR_cText, IR_nCounter, false, false);

        document.forms[IR_LocalNomeForm].elements[IR_cDay].options[document.forms[IR_LocalNomeForm].elements[IR_cDay].length] = IR_objOption ;
    }

    return 0;
}

//IR_### Per stampare una riga vuota

function IR_RigaVuota( IR_nColSpan ){

    P('	<TR> ');
		P(' <TD	');
		P(' NOWRAP ');
		P(' COLSPAN = '	+ IR_nColSpan);
		P(' ALIGN = "LEFT" ')
		P(' > ');
			P(' &nbsp;');
		P(' </TD> ');
    P('	</TR> ');

}

//IR_### Assegna al campo passato come parametro la data formattata
function IR_GestioneData(IR_obj){

    IR_obj.value=IR_FormatData(IR_obj.value);

}

//IR_### crea il form
function IR_CreaForm( IR_LocalNomeForm , IR_LocalMethod , IR_LocalAction , IR_createHiddenFromFormset){

    P('	<FORM NAME = ' + IR_LocalNomeForm + ' METHOD = ' + IR_LocalMethod + ' ACTION = ' + IR_LocalAction + ' >	');

		if((IR_createHiddenFromFormset != null) && (IR_createHiddenFromFormset == true))
			IR_CreaCampiNscostiFromFormSet();
}

//IR_### Chiude il form
function IR_ChiudiForm(){

    P('	</FORM>	')
}

//IR_### Effettua controlli chiamando la 'IR_checkAll' ed eventuali
//IR_### altri controlli mediante la funzione 'IR_PageCustomTests' definita nella specifica pagina js.
//IR_### In caso di controlli ok viene richiamata la 'IR_Submit' che esegue l'invio dei dati.

function IR_ValidateAndSubmit(IR_LocalNomeForm) {

    var IR_MsgError = null;

    if ( IR_SUBMIT == false ){

        IR_MsgError = IR_checkAll( IR_LocalNomeForm , false );

        if( IR_MsgError != null )
            alert( IR_MsgError );
        else{
			if( IR_PageCustomTests != null )
				IR_MsgError = IR_PageCustomTests( IR_LocalNomeForm );

			if( IR_MsgError != null )
			    alert( IR_MsgError );
			else{
				IR_SUBMIT=true;
				IR_Submit(IR_LocalNomeForm);
            }
        }
    }
    else
        alert( IR_CONST_MSG_RICHIESTA_INVIATA );

}

function IR_Submit(IR_LocalNomeForm)
{
	if (!IR_Exceptions() && !IR_Submitted(IR_LocalNomeForm))
	{
	    for (i = 0; i < document.forms[IR_LocalNomeForm].elements.length; i++)
	        if (document.forms[IR_LocalNomeForm].elements[i].type == "hidden" && document.forms[IR_LocalNomeForm].elements[i].name == "FORM_SUBMITTED")
	            document.forms[IR_LocalNomeForm].elements[i].value = "1";

	    document.forms[IR_LocalNomeForm].submit();
    }
}

//IR_### per la creazione dei bottoni
function IR_CreaBottoni( IR_oBottoni ){

    if ( IR_oBottoni != null )
		disegnaButtonBar( IR_oBottoni );
    else
		P(' <CENTER><B>	' + IR_CONST_MSG_STOP +	' <BR><BR><BR><BR><B><CENTER> ');

}

//IR_### per la creazione dei bottoni a lato
function IR_CreaBottoniALato( IR_oBottoni ){

    if ( IR_oBottoni != null )
		disegnaButtonBarRiga( IR_oBottoni );
    else
		P(' <CENTER><B>	' + IR_CONST_MSG_STOP +	' <BR><BR><BR><BR><B><CENTER> ');

}

//IR_### per la creazione tavola bottoni
function IR_CreaBottoniTavola( IR_oBottoni ){

    if ( IR_oBottoni != null )
		disegnaButtonBarTavola( IR_oBottoni );
    else
		P(' <CENTER><B>	' + IR_CONST_MSG_STOP +	' <BR><BR><BR><BR><B><CENTER> ');

}

//IR_### Mantiene il colore di sfodo grigio disabilitato. Da chiamare dopo ogni IR_checkAll();
function IR_CheckBgColorDisabled(IR_Form) {
    var IR_aElementi = document.forms[IR_Form].elements;

     for (var i=0; i<IR_aElementi.length; i++) {
        var IR_name = IR_aElementi[i];
        var IR_elemento = IR_aElementi[i].disabled;
        if(IR_elemento) {
            IR_name.style.backgroundColor='transparent';
        }
    }
}

// Funzioni usate da Portafoglio
// Gestione data --> IR_cGestioneData
function IR_Formatta(IR_cCampo) {
    IR_checkAll(IR_LocalNomeForm,false);
    var IR_cError=null;
    var IR_cNomeCampo=IR_cCampo;
    var IR_cValue=IR_cCampo.value;
    if (IR_cValue!="")
    {
        var IR_cStringaFormattata=IR_FormatData(IR_cValue);
        IR_cCampo.value=IR_cStringaFormattata;
        var IR_msg = IR_checkData (IR_cNomeCampo, IR_cStringaFormattata);
        if (IR_msg!= null){
            IR_cCampo.value="";
            IR_cCampo.focus();
            return false;
        }
        IR_checkAll(IR_LocalNomeForm,false);
    }
    return true;
}

//Gestione importo --> IR_cGestioneImporto DEFORMATTA
function IR_GestioneDeformattazioneImporto( IR_oImporto ){

	if(IR_oImporto != null){
		if((IR_oImporto.value != "")&&(IR_oImporto.value != 0))
			IR_oImporto.value=IR_DeformattaImporto(IR_oImporto.value);
		else
			IR_oImporto.value="";
	}

}

//Gestione importo --> IR_cGestioneImporto FORMATTA
function IR_GestioneFormattazioneImporto ( IR_oImporto ) {

	if(IR_oImporto != null){
		if((IR_oImporto.value != "")&&(IR_oImporto.value != 0))
			IR_oImporto.value = IR_FormattaImporto(IR_oImporto.value , 2);
		else
			IR_oImporto.value = "";
	}

}

function IR_GestioneFormattazioneImportoConZeri ( IR_oImporto ) {

	if(IR_oImporto != null){
		if(IR_oImporto.value != "")
			IR_oImporto.value = IR_FormattaImporto(IR_oImporto.value , 2);
		else
			IR_oImporto.value = "";
	}

}

function startsWith(string1, string2)
{
	return string1.substring(0, string2.length) == string2;
}

