//<!--

    function Redirect()
    {
		document.location.href='AbbinaImm.aspx?IDArt=' + aspnetForm._ctl0_ContentPlaceHolder2_IDArt.value + '&IDImm=-1';
		document.location.target='_self';
		return false;

	}

	function ControllaInteri(txtI)
	{
		ControllaDigit(txtI);
		
		if(event.returnValue != false)
		{
			var kc = event.keyCode;
			if (
				kc == 107 ||              //* + tastierino numerico
				kc == 109 ||              //* - tastierino numerico
				kc == 110 ||              //* , tastierino numerico
				kc == 187 ||              //* +
				kc == 188 ||              //* ,
				kc == 189)                //* - 
			{
				event.returnValue = false;
			}
		}
	}
	
	function ControllaDecimal(txtI)
	{
		ControllaDigitDecimal(txtI);
		
		if(event.returnValue != false)
		{
			var kc = event.keyCode;
			if (
				kc == 107 ||              //* + tastierino numerico
				kc == 109 ||              //* - tastierino numerico
				kc == 187 ||              //* +
				kc == 189)                //* - 
			{
				event.returnValue = false;
			}
		}
	}
	
	// Retrieve the value of the cookie with the specified name.
	function GetCookie(sName)
	{
		// cookies are separated by semicolons
		var aCookie = document.cookie.split("; ");
		for (var i=0; i < aCookie.length; i++)
		{
			// a name/value pair (a crumb) is separated by an equal sign
			var aCrumb = aCookie[i].split("=");
			if (sName == aCrumb[0]) 
			return unescape(aCrumb[1]);
		}

		// a cookie with the requested name does not exist
		return null;
	}
	
	// Delete the cookie with the specified name.
	function DelCookie(sName, sValue)
	{
		document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 1999 23:59:59 GMT;";
	}
	
	function SetCookie(sName, sValue)
	{
		date = new Date();
		document.cookie = sName + "=" + escape(sValue); // + "; expires=" + date.toGMTString();
		//alert(document.cookie);
	}

	function AzzeraCookie()
	{
		var NomeSessione = "ASP.NET_SessionId";
		
		SetCookie(NomeSessione, "mmmm");
		var Valore = GetCookie(NomeSessione);
		DelCookie(NomeSessione, Valore);
		Valore = GetCookie(NomeSessione);
		alert(Valore);
	}

	function SettaFocus()
	{
		document.frmInput.StringaRic.focus();
	}
	
	function CallLinkCategorieDivisioni(IDCategorie, IDDivisione, Azione)
	{
		var Propaga;
		
		if(document.frmSeleziona.checkPropaga.checked)
			Propaga = '1';
		else
			Propaga = '0';
		
		document.location = 'ga_LinkCategorieDivisioni.aspx?IDDivisione=' + IDDivisione + '&Azione=' + Azione + '&checkPropaga=' + Propaga + '&IDCategorie=' + IDCategorie;
	}
	
	function CallLinkCategorieProfili(IDCategorie, IDProfilo, Azione)
	{
		var Propaga;
		
		if(document.frmSeleziona.checkPropaga.checked)
			Propaga = '1';
		else
			Propaga = '0';
		
		document.location = 'ga_LinkCategorieProfili.aspx?IDProfilo=' + IDProfilo + '&Azione=' + Azione + '&checkPropaga=' + Propaga + '&IDCategorie=' + IDCategorie;
	}
	
	function ImpostaTipologie(Nome, Valore)
	{
		var bImposta = true;
		
		if(document.frmInput.TipOrgAU != null && Nome != 'TipOrgAU' && document.frmInput.TipOrgAU.value != '')
		{
			bImposta = false;
		}
		if(document.frmInput.TipOrgVW != null && Nome != 'TipOrgVW' && document.frmInput.TipOrgVW.value != '')
		{
			bImposta = false;
		}
		if(document.frmInput.TipOrgSE != null && Nome != 'TipOrgSE' && document.frmInput.TipOrgSE.value != '')
		{
			bImposta = false;
		}
		
		if(document.frmInput.TipOrgSK != null && Nome != 'TipOrgSK' && document.frmInput.TipOrgSK.value != '')
		{
			bImposta = false;
		}
		if(document.frmInput.TipOrgVIC != null && Nome != 'TipOrgVIC' && document.frmInput.TipOrgVIC.value != '')
		{
			bImposta = false;
		}
		
		if(bImposta == true)
		{
			if(document.frmInput.TipOrgAU != null)
				document.frmInput.TipOrgAU.value = Valore;
			if(document.frmInput.TipOrgVW != null)
				document.frmInput.TipOrgVW.value = Valore;
			if(document.frmInput.TipOrgSE != null)
				document.frmInput.TipOrgSE.value = Valore;
			if(document.frmInput.TipOrgSK != null)
				document.frmInput.TipOrgSK.value = Valore;
			if(document.frmInput.TipOrgAU != null)
				document.frmInput.TipOrgVIC.value = Valore;
		}
	}
	
	//trova un valore in una sequenza di valori separati da ,
	function CSVFind(CommaSepString, Value)
	{	
		try{		
		if (CommaSepString == Value || //controllo se la stringa contiene solo il valore cercato
				(CommaSepString.length > Value.length && ( //controllo la lunghezza sia superiore al valore cercato (se fosse uguale, non potrebbe essere nella stringa)
				CommaSepString.substring(0, Value.length+1) == Value+"," || //cerco all' inizio della stringa
				CommaSepString.substring(CommaSepString.length - Value.length-1,CommaSepString.length) == ","+Value || //cerco alla fine della stringa
				CommaSepString.indexOf(","+Value+",") > -1)  ) )		//cerco in mezzo
				return true;
			else
				return false;			
		}catch (e)
		{
			return false;
		}
	}
		

	
	function ControlloUtenti()
	{
		var varNome = document.frmUtente.txtNome.value;
		var varLogin = document.frmUtente.txtLogin.value;
		var varIDProfiloDealer = document.frmUtente.IDProfiloDealer.value;
		var varselProfilo = document.frmUtente.selProfilo.value;
		var varAnull = "";
				
		if(document.frmUtente.txtNome.value == '')
		{
			alert('Organizzato deve essere inserito.')
			document.frmUtente.txtNome.focus();
			return;
		}
		
		if(document.frmUtente.selProfilo.value == '')
		{
			alert('Il profilo deve essere inserito.')
			document.frmUtente.selProfilo.focus();
			return;
		}
		
		if(document.frmUtente.txtLogin.value == '')
		{
			alert('Il login deve essere inserito.')
			document.frmUtente.txtLogin.focus();
			return;
		}
		//Giovanni. Utilizzo il Trova poichč il varIDProfiloDealer
		//potrebbe contenere pił profili separati da virgola.
		//vecchio = if (varIDProfiloDealer == varselProfilo) 
		if (CSVFind(varIDProfiloDealer, varselProfilo)) 
		{
			varAnull = ConfermaUtenteDealerNonNumerico(varNome, varLogin);
		}
		
		if (varAnull == "") {
			document.frmUtente.action = "ga_Utenti.aspx";
			document.frmUtente.submit();
		}
		else {
			document.frmUtente.txtNome.focus();
		}
	}	
	

	function SelezionaTutto(c)
	{
		var i = 1;
		
		var max = document.frmSeleziona.all.length;
		
		for(i=0; i < max; i++)
		{
			var o = document.frmSeleziona.item(i);
			
			if(o != null)
			{
				if(o.name.substring(0,3) == 'chk')
				{
					o.checked = c.checked;
				}
			}
		}
	}

	function isdigit(c) 
	{
		return ((c <= "9") && (c >= "0")) || c == "." || c == ",";
	}
	
	function isNumber(valore) 
	{
		for (i = 0; i < valore.length; i++)
		{
			if (!isdigit(valore.charAt(i)))
				return false;
		}
		
		return true;
	}
	
	function ControllaData(data)
	{
		if(data != '' && isDate(data) == false)
		{
			alert('Data non valida. La data deve essere inserita nel formato gg/mm/aaaa');
			event.returnValue = false;
		}
	}
		
	function ControllaDigit(txtI) 
	{
		var kc = event.keyCode;
	
		if (kc >= 96 && kc <=105) {    		//* Tastierino numerico
			kc -= 48;
		}

		var di = (
				kc == 39 ||					//* Tasti cursore
				kc == 37 ||
				(kc >=48 && kc <=57) ||     //* Numeri
				kc == 9 ||                  //* Tab
				kc == 35 ||                 //* Fine
				kc == 36 ||                 //* Inizio
				kc == 8 ||               
				kc == ',' ||               
				kc == 107 ||                //* + tastierino numerico
				kc == 109 ||                //* - tastierino numerico
				kc == 187 ||                //* +
				kc == 188 ||                //* ,
				kc == 189 ||                //* - 
				kc == 46                    //* Delete
			);
		    
		if (! di) {
			event.returnValue = false;
		} 
	}
	
	function ControllaDigitDecimal(txtI) 
	{
		var kc = event.keyCode;
	
		if (kc >= 96 && kc <=105) {    		//* Tastierino numerico
			kc -= 48;
		}

		var di = (
				kc == 39 ||					//* Tasti cursore
				kc == 37 ||
				(kc >=48 && kc <=57) ||     //* Numeri
				kc == 9 ||                  //* Tab
				kc == 35 ||                 //* Fine
				kc == 36 ||                 //* Inizio
				kc == 8 ||               
				kc == ',' ||               
				kc == 107 ||                //* + tastierino numerico
				kc == 109 ||                //* - tastierino numerico
				kc == 187 ||                //* +
				kc == 188 ||                //* ,
				kc == 189 ||                //* - 
				kc == 46                    //* Delete
			);
		
		if (kc == 190 || kc == 188)
		    di = true;
		    
		if (! di) {
			event.returnValue = false;
		} 
	}
	
	function ControllaDigitNoNegativi(txtI)
	{
		ControllaDigit(txtI);
		
		if(event.returnValue != true)
		{
			var kc = event.keyCode;
			if (kc == 189) //* -
			{
				event.returnValue = false;
			}
		}

	}
	
	function ControllaInteri(txtI)
	{
		ControllaDigit(txtI);
		
		if(event.returnValue != true)
		{
			var kc = event.keyCode;
			if (kc == '.' || kc == ',' ||
				kc == 107 ||              //* + tastierino numerico
				kc == 109 ||              //* - tastierino numerico
				kc == 187 ||              //* +
				kc == 188 ||              //* ,
				kc == 189)                //* - 
			{
				event.returnValue = false;
			}
		}
	}
	
	function Valida()
	{
		var ris = window.confirm("Eseguire la validazione dei dati?");
		if (ris)
		{
			document.frmAzione.action = "g_DatiTrasmissioni.aspx";
			document.frmAzione.submit();
		}
	}
	
	function Validazione()
	{
		var ris = window.confirm("Aumentare il numero massimo di validazioni?");
		if (ris)
		{
			document.frmAzione.Azione.value = 2;
			document.frmAzione.action = "ga_DatiTrasmissioni.aspx";
			document.frmAzione.submit();
		}
	}
	
	function ForzaEsitoValidazione(Esito)
	{
		var ris = window.confirm("Forzare l'esito della validazione?");
		if (ris)
		{
			document.frmAzione.action = "ga_DatiTrasmissioni.aspx";
		
			if(Esito == "0")
			{
				document.frmAzione.Azione.value = "3";
			}
			else
			{
				document.frmAzione.Azione.value = "4";
			}
			
			document.frmAzione.submit();
		}
	}
	
	function replaceAll( str, from, to ) 
	{
		var idx = str.indexOf( from );


		while ( idx > -1 ) {
			str = str.replace( from, to ); 
			idx = str.indexOf( from );
		}

		return str;
	}
	
	function toEuro(str) 
	{
		index = str.indexOf(".");
		if (index < 0) str = str + ".00";
		else {
		str = str.substring(0, index + 3);
		if (str.length < (index + 3)) str += "0";
		}
		return str.replace(".",",");
	}
	
	function CalcolaSomma(txtI)
	{
		var valore = txtI.value;
		var ss ;
		var ss1;
		var i = 0;
		var y = 0;
		var somma = 0;
		
		valore = replaceAll(valore,",",".");
		valore = replaceAll(valore," ","");
		var ss = valore.split("+");
		
		for (i = 0 ; i < ss.length ; i++)
		{
			ss1 = ss[i].split("-");
		
			if (ss1.length > 0)
			{
				for (y = 0 ; y < ss1.length ; y++)
				{
					if (y == 0)
					{
						if (ss1[y] != "")
							somma += parseFloat(ss1[y]);
					}
					else
						somma -= parseFloat(ss1[y]);
				}
			}
			else if (ss[i] != "")
				somma += parseFloat(ss[i]);
		}
		
		txtI.value = somma;
		txtI.value = toEuro(txtI.value);
		
		if (txtI.value.length > 13)
		{
			alert("Input dati non corretti\nLimite massimo superato.");
			event.returnValue = false;
		}
	}
		
	function apriDettaglio(CdConc) 
	{
		window.open("DettaglioRating.aspx?CdConc=" + CdConc + "&Anno=" + document.frmRicerca.ricAnno.value,"_self");
	}
	
	function CambiaClass(nomeID)
	{
		document.all[nomeID].className = "rigaSel";
	}
	
	function rollon(itemName) 
	{
		if (itemName.tagName == "TR") 
		{
			itemName.className = "totale";
			itemName.style.cursor = "hand";
		} 
		window.event.cancelBubble = true;
	}

	function rolloff(itemName,nomeClasse) 
	{
		if (itemName.tagName == "TR") 
		{
			itemName.className = nomeClasse;
			itemName.style.cursor = "";
		} 
		window.event.cancelBubble = true;
	}	
	

//-->


