

     function openpopup(apri, stile) {
        window.open(apri, "", stile);
     }
 
	
	
	/*
		Testa se la lunghezza del testo contenuto sia uguale
		a quella passata e passa il fuoco all'elemento successivo
	*/
	
	function changeFocus(InputObj, InputLen) {
		if (InputObj.value.length == InputLen) {
			var i;
			for (i = 0; i < InputObj.form.length; i++)
				if (InputObj.form.elements[i].name == InputObj.name)
					break;
	
			i += 1;
			if (i < InputObj.form.length)
				InputObj.form.elements[i].focus();
		}
	}


	/*
		Testa se la lunghezza del testo contenuto sia uguale
		a quella passata e passa il fuoco all'elemento corrente + offset
	*/
	
	function changeFocusOffset (InputObj, InputLen, offset) {
		if (InputObj.value.length == InputLen) {
			var i;
			for (i = 0; i < InputObj.form.length; i++)
				if (InputObj.form.elements[i].name == InputObj.name)
					break;
	
			i += offset;
			if (i < InputObj.form.length)
				InputObj.form.elements[i].focus();
		}
	}      

	function getFormElement (obj, offset) {
			var i;
			
			for (i = 0; i < obj.form.length; i++)
				
				if (obj.form.elements[i].name == obj.name)
					break;
			i += offset;

			if (i < obj.form.length)
				return obj.form.elements[i];
	}   

	function enableRadioOffset (InputObj, offset) {
			var i;
			for (i = 0; i < InputObj.form.length; i++)
				if (InputObj.form.elements[i].name == InputObj.name)
					break;
	
			i += offset;
			//alert(InputObj.form.elements[i].name);
			if (i < InputObj.form.length)
				InputObj.form.elements[i].checked = true;
	} 	  
	
	function adjustCF(filedCF) {
		var result = "";
		var value = "";
		var format = "LLLLLLNNLNNLNONL";
		var c, f;
		value = filedCF.value.toUpperCase();
		if (value.length == format.toString().length) {
			for (var i=0 ; i< format.length; i++) {
				c = "" + value.substring(i, i+1);
				f = "" + format.substring(i, i+1);
				if (f=="L" && c == "0") c = "O"
				if (f=="L" && c == "1") c = "I"
				if (f=="N" && c == "O") c = "0"
				if (f=="N" && c == "I") c = "1"
				result += c;
				
			}
			//alert(result);
		} else {
			result = filedCF.value;
		}
		return result;
	}	  
	  
	  function adjustDate(myDate) {
                if (isNumeric(myDate)) {
                        //alert('Non sono stati inseriti i separatori');
                        if (myDate.toString().length == 6) {
                                var date = new Date();
                                myDate = myDate.toString();
                                myDate = myDate.substr(0,2) + '/' + myDate.substr(2,2)+'/'+((parseInt('20'+myDate.substr(4,2)) > (parseInt(date.getFullYear())+10))?'19':'20')+myDate.substr(4,2);                                
                                //myDate = parseDate(myDate, Array('dd','mm','yy'));
                                //myDate = formatDate(myDate, parseDateFormat(getLocaleInfo("shortDate")));
                        } else if (myDate.length == 8){
                                myDate = myDate.substr(0,2) + '/'+myDate.substr(2,2)+'/'+myDate.substr(4,4);                            
                                //myDate = parseDate(myDate, Array('dd','mm','yyyy'));
                                //myDate = formatDate(myDate, parseDateFormat(getLocaleInfo("shortDate")));
                        } else {
                                alert('Formato data non Corretto!');
                        }
                } else {
                                                // Corregge giorno e mese
                        if (isNumeric(myDate.substr(0,1)) && !isNumeric(myDate.substr(1,1))) {
                                                        //giorno con una cifra: "1/"
                                                        myDate = '0'+myDate;
                                                }
                        if ( isNumeric(myDate.substr(3,1)) && !isNumeric(myDate.substr(4,1)) ) {
                                                        //mese con una cifra: "01/1/06"
                                                        myDate =  myDate.substr(0,3)+'0'+myDate.substr(3,myDate.length-3);
                                                }

                        //Sostituisce tutti i separatori con '/'
                        if (myDate.toString().length == 8 && isNumeric(myDate.substr(0,2)+myDate.substr(3,2)+myDate.substr(6,2))) {
                               //Formato 01ç01ç06
                                                            var date = new Date();
                                myDate = myDate.substr(0,2) + '/'+myDate.substr(3,2)+'/'+((parseInt('20'+myDate.substr(6,2))> (date.getFullYear()+10))?'19':'20')+myDate.substr(6,2);                                
                        } else if (myDate.length == 10 && isNumeric(myDate.substr(0,2)+myDate.substr(3,2)+myDate.substr(6,4))){
                               //Formato 01ç01ç2006
                                myDate = myDate.substr(0,2) + '/'+myDate.substr(3,2)+'/'+myDate.substr(6,4);                            
                        } else {
                                alert('Formato data non Corretto!');
                        }
                }
                //alert(myDate);
                return myDate;
        }

	  function adjustTime(value) {
		  	var sep = '.';
			var err=0;
			var myDate = value;
                if (isNumeric(myDate)) {
					//alert('Non sono stati inseriti i separatori');
					if (myDate.toString().length == 3) {
							myDate = '0'+myDate.substr(0,1) + sep + myDate.substr(1,2);                                
					} else if (myDate.length == 4){
							myDate = myDate.substr(0,2) + sep + myDate.substr(2,2);                                
					} else {
							err=1;
					}
                } else {
					// Corregge l'ora
					if (myDate.toString().length == 4 && isNumeric(myDate.substr(0,1)) && !isNumeric(myDate.substr(1,1))) {
							//ora con una cifra: "9:"
							myDate = '0'+myDate;
					}
                }
 
				//Sostituisce tutti i separatori con ':'
				if (myDate.toString().length == 5 && isNumeric(myDate.substr(0,2)+myDate.substr(3,2))) {
				var h = myDate.substr(0,2);
					var n = myDate.substr(3,2);
					//verifica la correttezza dell'orario
					if (parseInt(h)<24 && parseInt(n)<60 && parseInt(h)>=0 && parseInt(n)>=0 ) {
						myDate = h + sep + n;
					} else {
						err=1;
					}
				}
				//alert(myDate);
				if (err==0) {
					return myDate;
				} else {
					alert('Formato data non Corretto!');
					return value;
				}

		 }


        function checkFieldDate(field) {
                var d;
                d = adjustDate(field.value);
                if (d != "") field.value = d;
        }
        
		function checkFieldTime(field) {
                var d;
                d = adjustTime(field.value);
                if (d != "") field.value = d;
        }
//*****************************
//Funzione che verifica che il campo in input sia numerico.
//Da richiamare su onchange affinché funzioni sia su Netscape
//che Explorer.
//*****************************

function isNumeric (value){
	var valid = "0123456789";
	var ok = "yes";
	var temp;
	for (var i=0; i<value.length; i++) {
			temp = "" + value.substring(i, i+1);
			if (valid.indexOf(temp) == "-1")
					ok = "no";
	}
	if (ok == "no") {
			return false;
	}
	return true;
}
		
function isFieldNumeric (field){
	if (!isNumeric(field.value)) {
		alert("Valore non valido! Per questo campo sono ammessi solo numeri!");
		field.focus();
		field.select();
		return false;
   	}
	return true;
}


		
//*****************************
//Funzione che verifica che il campo in input sia numerico con segno.
//Da richiamare su onchange affinché funzioni sia su Netscape
//che Explorer.
//*****************************

function isDigitWithSign(field, divisa){
	var valid = "";
	var ok = "yes";
	var temp;
	var begin;

	if (divisa.toUpperCase() == "ITL")
		valid = "0123456789";
	else
		valid = "0123456789,";

   	if ( (field.value.substring(0, 1) == "+" ) || (field.value.substring(0, 1) == "-" ) ) begin = 1;
   	else  begin = 0;

	for (var i=begin; i<field.value.length; i++) {
		temp = "" + field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = "no";
	}
	if (ok == "no") {
		if (divisa.toUpperCase() == "ITL")
			alert("Valore non valido! Per questo campo sono ammessi solo numeri con segno e senza virgola!");
		else
			alert("Valore non valido! Per questo campo sono ammessi solo numeri con segno!");

		field.focus();
		field.select();
		return false;
   	}
	return true;
}





//*****************************
//Funzione che verifica che la STRINGA in input sia alfabetico.
//Da richiamare su onchange affinché funzioni sia su Netscape
//che Explorer.
//*****************************

function isLetter (stringa){
	var valid = "abcdefghilmnopqrstuvzwyjkxABCDEFGHILMNOPQRSTUVZWYJKX";
	var ok = "yes";
	var temp;
	for (var i=0; i<stringa.length; i++) {
		temp = "" + stringa.substring(i, i+1);
		if (valid.indexOf(temp) == "-1")
			ok = "no";
	}
	if (ok == "no") {
		return false;
   	}
	return true;
}

//*****************************
//Funzione che verifica che il campo in input sia alfabetico.
//Da richiamare su onchange affinché funzioni sia su Netscape
//che Explorer.
//*****************************

function letter (field){
	var valid = "abcdefghilmnopqrstuvzwyjkxABCDEFGHILMNOPQRSTUVZWYJKX";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") {
			ok = "no";
		}
	}
	if (ok == "no") {
	    alert("Valore non valido! Per questo campo sono ammesse solo lettere!");
		field.focus();
		field.select();
		return false;
   	}
	return true;
}

//*****************************
//Funzione che verifica che il campo in input sia alfabetico o con spazi.
//Da richiamare su onchange affinché funzioni sia su Netscape
//che Explorer.
//*****************************

function letterWithSpace (field){
        var valid = "abcdefghilmnopqrstuvzwyjkx'ABCDEFGHILMNOPQRSTUVZWYJKX";
	var ok = "yes";
	var temp;
	for (var i=0; i<field.value.length; i++) {
		temp = field.value.substring(i, i+1);
		if (valid.indexOf(temp) == "-1") {
			if (temp != " ")
   {
				ok = "no";
   }
		}
	}
	if (ok == "no") {
	    alert("Valore non valido! Per questo campo sono ammesse solo lettere!");
		field.focus();
		field.select();
		return false;
   	}
	return true;
}


//*****************************
//Funzione che verifica se un campo in input e' vuoto.
//Da richiamare su onchange affinché funzioni sia su Netscape
//che Explorer.
//*****************************


function isEmpty (field)
{  	if (field.value.length == 0)
		return true;
   	else
		return false;
}


//*******************************************************************
//Funzione che verifica che la data (gg,mm,aa) in input sia corretta.
//*******************************************************************

function verificaData (ggObj, mmObj, aaObj, dataObj ){

	var gg = togliSpazi(ggObj);
	var mm = togliSpazi(mmObj);
	var aa = togliSpazi(aaObj);
	var date = new String("");
        if(!((gg == "") && (mm == "") && (aa == ""))) {
                if( !(gg == "") && !(mm == "") && !(aa == "") ) {
			if(gg.length == 1) {
				ggObj.value = "0" + gg;
				gg = ggObj.value;
			}
			if(mm.length == 1) {
				mmObj.value = "0" + mm;
				mm = mmObj.value;
			}
			if(aa.length == 4) {
				dataObj.value = gg + "/" + mm + "/" + aa;
				if (!(chkdate(dataObj))) return false;
			}
			else return false;

		}
		else return false;

	}
	return true;
}

//*******************************************************************
//Funzione che verifica che la data in input sia corretta.
//*******************************************************************

function checkdate(objName) {
	var datefield = objName;
	if (chkdate(objName) == false) {
		datefield.select();
		alert("Data non valida. Inserire data valida.");
		datefield.focus();
		return false;
	}
	else {
		return true;
	}
}

function UCase(obj)
{
	var valore = new String (obj.value);
	obj.value = valore.toUpperCase();
	return true;
}


//Controlla se un valore numerico è zero
function isZero(obj){
	var num = obj.value;
	if ((num == "0")||(num == "0,00")||(num == ""))
		return true;
	else
		return false;
}

//Toglie gli spazi a destra del campo
function togliSpazi(obj){
	var appoggio = new String(obj.value);
	var ciclo = true;
	var lunghezza = new Number(appoggio.length);
	while (ciclo == true){
		ciclo = false;
		lunghezza = new Number(appoggio.length);
		temp = appoggio.substring(lunghezza-1,lunghezza);
		if (temp == " ")
		{
			appoggio = appoggio.substring(0,lunghezza-1);
			ciclo = true;
		}
	}
	obj.value = appoggio;
	return appoggio;
}

//Inserita da Fabio Pileri 2008.03.10
function cambiaCSS(file_scelto) {
   var elenco = document.getElementsByTagName("link");
   var tagstile;
   for (n=0;n<elenco.length;n++) if(elenco[n].media=="screen") tagstile = elenco[n];
   tagstile.href = file_scelto;
   
   setCookie("oloCMScss", file_scelto, 30)
}

function caricaCSS(file_scelto) {
	cambiaCSS(getCookie('oloCMScss'));
}

function setCookie(sNome, sValore, iGiorni) {
	var dtOggi = new Date()
	var dtExpires = new Date()
	dtExpires.setTime
	(dtOggi.getTime() + 24 * iGiorni * 3600000)
	document.cookie = sNome + "=" + escape(sValore) + "; expires=" + dtExpires.toGMTString();
}

// restituisce il valore del cookie sNome
function getCookie(sNome) {
	// genera un array di coppie "Nome = Valore" // NOTA: i cookies sono separati da ';'
	var asCookies = document.cookie.split("; ");
	// ciclo su tutti i cookies
	for (var iCnt = 0; iCnt < asCookies.length; iCnt++) {
		// leggo singolo cookie "Nome = Valore"
		var asCookie = asCookies[iCnt].split("=");
		if (sNome == asCookie[0]) { 
			return (unescape(asCookie[1]));
		}
	}

	// SE non esiste il cookie richiesto
	return("");
}

function delCookie(sNome) {
	setCookie(sNome, "");
}

//caricaCSS();

function bookmarksite(title, url){
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "")
}
