<!--
//****************************************************************************
//******** Tutte le funzioni JavaScript utilizzate all'interno del sito ******
//****************************************************************************

// BEGIN Trimma una stringa di testo
function trimma(StrToTrim)
{
    // CONTROLLA CHE IL VALORE IN INPUT SIA DI TIPO STRING
    if (typeof StrToTrim != "string"){
        return StrToTrim;
    }

    // CATTURA IL PRIMO CARATTERE DELLA STRINGA PER CONTROLLARE CHE NON SIA UNO SPAZIO VUOTO
    var StrBlank = StrToTrim.substring(0, 1);

    // ELIMINA LO SPAZIO VUOTO DALLA PRIMA POSIZIONE DELLA STRINGA
    while (StrBlank == " "){
        StrToTrim = StrToTrim.substring(1, StrToTrim.length);
        StrBlank = StrToTrim.substring(0, 1);
    }

    // CATTURA L'ULTIMO CARATTERE DELLA STRINGA PER CONTROLLARE CHE NON SIA UNO SPAZIO VUOTO
    StrBlank = StrToTrim.substring(StrToTrim.length - 1, StrToTrim.length);

    // ELIMINA LO SPAZIO VUOTO DALL'ULTIMA POSIZIONE DELLA STRINGA
    while (StrBlank == " "){
        StrToTrim = StrToTrim.substring(0, StrToTrim.length-1);
        StrBlank = StrToTrim.substring(StrToTrim.length-1, StrToTrim.length);
    }

    // ELIMINA POTENZIALI SPAZI VUOTI MULTIPLI ALL'INIZIO ED ALLA FINE DI UNA STRINGA
    while (StrToTrim.indexOf("  ") != -1){
        StrToTrim = StrToTrim.substring(0, StrToTrim.indexOf("  "));
        StrToTrim += StrToTrim.substring(StrToTrim.indexOf("  ") + 1, StrToTrim.length);
    }

    // RESTITUISCE IL VALORE FINALE SENZA SPAZI VUOTI DI CONTORNO
    return StrToTrim;
}
// END Trimma una stringa di testo


// BEGIN Apertura nuova finestra in POPUP
function NewWindow(mypage,myname,w,h,scroll){
	var win = null;
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+(h*1.1)+',width='+(w*1.1)+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=yes';
	win = window.open(mypage,myname,settings)
}
// END Apertura nuova finestra in POPUP


// BEGIN invio messaggi privati	
function send_msgpvt(){
	alert("Funzionalità al momento inattiva!");
}
// END invio messaggi privati


// BEGIN Aggiunta di testo ad una textarea
function add_text(instext) {
    var mess = document.getElementById("textarea");
	//IE support
	if (document.selection) {
		mess.focus();
		sel      = document.selection.createRange();
		sel.text = instext + sel.text;
		document.modulo.focus();
	}
	//MOZILLA/NETSCAPE support
	else if (mess.selectionStart || mess.selectionStart == "0") {
		var startPos = mess.selectionStart;
		var endPos 	 = mess.selectionEnd;
		var chaine 	 = mess.value;

		mess.value   = chaine.substring(0, startPos) + instext + chaine.substring(startPos, chaine.length);

		mess.selectionStart = startPos + instext.length;
		mess.selectionEnd 	= endPos + instext.length;
		mess.focus();
	} else {
		mess.value += instext;
		mess.focus();
	}
}
// END Aggiunta di testo ad una textarea


/// BEGIN Apre/Chiude l'oggetto con l'ID passato
function fn_open_close_obj(o_obj, s_statoiniziale){
	var o_objclose = document.getElementById(o_obj);
	if (!o_objclose) {
		return false;
	}
	var o_dis_style = o_objclose.style.display;

	if (o_dis_style == ""){
		if (s_statoiniziale == "block"){
			o_objclose.style.display = "none";
			return true;
		}else{
			o_objclose.style.display = "block";
			return true;
		}
	}else if(o_dis_style == "block"){
		o_objclose.style.display = "none";
		return true;
	}else{
		o_objclose.style.display = "block";
		return true;	
	}
}
// END Apre/Chiude l'oggetto con l'ID passato


// BEGIN Apre/Chiude l'oggetto con l'ID passato
function fn_open_close(o_obj){
	fn_open_close_obj(o_obj, 'block');
}
// END Apre/Chiude l'oggetto con l'ID passato

// BEGIN Apre/Chiude il menù ridimensionando il content
function fn_open_closemenu(o_obj1, o_obj2, marginOrig){
	var o_objclose1 = document.getElementById(o_obj1);
	var o_objclose2 = document.getElementById(o_obj2);
	if (o_objclose1.style.display == "none"){
		o_objclose1.style.display = "block";	
		if ((getCookie('RSM_MenuPosition')=="RIGHT") || (getCookie('RSM_MenuPosition') == null)){
			o_objclose2.style.margin = " 0 " + marginOrig + " 0 0";
		}else{
			o_objclose2.style.margin = " 0 0 0 " + marginOrig;
		}
		return true;
	}else{
		o_objclose1.style.display = "none";
		o_objclose2.style.margin = "0 auto";				
		return true;
	}
}
// END Apre/Chiude il menù ridimensionando il content


// BEGIN Gestione Cookies
function getCookie(NameOfCookie){
	if (document.cookie.length > 0) {             
	    begin = document.cookie.indexOf(NameOfCookie+"=");      
    	if (begin != -1) {          
    		begin += NameOfCookie.length+1;      
      		end = document.cookie.indexOf(";", begin);
      		if (end == -1) end = document.cookie.length;
        	return unescape(document.cookie.substring(begin, end));
    	}
  	}
	return null;
}

function setCookie(NameOfCookie, value, expiredays) {
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + "=" + escape(value) + ";path=/" +
	((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}

function delCookie (NameOfCookie) {
  if (getCookie(NameOfCookie)) {
    document.cookie = NameOfCookie + "=" +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
// END Gestione Cookies


// BEGIN Switch posizione Menù
function switch_menu(){

	if ((getCookie('RSM_MenuPosition') == null) || (getCookie('RSM_MenuPosition')=="RIGHT")){
		setCookie('RSM_MenuPosition','LEFT',1000);
	}else{
		delCookie('RSM_MenuPosition');
		setCookie('RSM_MenuPosition','RIGHT',1000);
	}
	location.reload();
}
// END Switch posizione Menù


// BEGIN restituisce la risoluzione in larghezza, impostata sul monitor dell'utente
function fn_videoResolution() {
	var wide = screen.width;
	return wide;
}
// END restituisce la risoluzione in larghezza, impostata sul monitor dell'utente


// BEGIN modifica lo sfondo e il colore dei caratteri dell'oggetto
function fn_change_CharBackg_Color(obj, char_color, bkg_color) {
	obj.style.color 	 = char_color;
	obj.style.background = bkg_color;

	// cambio colore a tutti i tag a appartenenti all'oggetto cui sto cambiando i colori
	var Tag_A = obj.getElementsByTagName("a");
	for (i=0; i < Tag_A.length; i++){
		Tag_A.item(i).style.color = char_color;
	}

	return true;
}
// END modifica lo sfondo e il colore dei caratteri dell'oggetto


// BEGIN Funzione utilizzata da Ajax, per ricavare il tipo di browser che si sta utilizzando
function RicavaBrowser(QualeBrowser)
{
    if (navigator.userAgent.indexOf("MSIE") != (-1))
    {
        var Classe = "Msxml2.XMLHTTP";
        if (navigator.appVersion.indexOf("MSIE 5.5") != (-1));
        {
            Classe = "Microsoft.XMLHTTP";
        } 
        try
        {
            OggettoXMLHTTP = new ActiveXObject(Classe);
            OggettoXMLHTTP.onreadystatechange = QualeBrowser;
            return OggettoXMLHTTP;
        }
        catch(e)
        {
            alert("Errore: l'ActiveX non verrà eseguito!");
        }
    }
    else if (navigator.userAgent.indexOf("Mozilla") != (-1))
    {
        OggettoXMLHTTP = new XMLHttpRequest();
        OggettoXMLHTTP.onload = QualeBrowser;
        OggettoXMLHTTP.onerror = QualeBrowser;
        return OggettoXMLHTTP;
    }
    else
    {
        alert("La richiesta non funziona con altri browser!");
    }
}
// END Funzione utilizzata da Ajax, per ricavare il tipo di browser che si sta utilizzando

//****************************************************************************/
//-->