
// ------------------------------------------ VARIABILI GLOBALI ------------------------------------------------
var FIELD_SEPARATOR = "|";
var controls_delete_message = "Eliminare le informazioni selezionate ?";
var DEL_MESSAGE = "Attenzione!\nEliminare il record?"
// ------------------------------------- FINE VARIABILI GLOBALI ------------------------------------------------

//Apri in una nuova finestra un'immagine
//	@min   - percorso da img e nome immagine da visualizzare
//		     es. ../../../../img/museo/max/ex_voto_max/1.jpg
//	@tit   - Didascalia da visualizzare
//	urlCss - percorso da style da utilizzare
//		     es. ../../../../
function openImgage(min, tit, urlCss) {
	var i1 = new Image;
	i1.src = min;
	var html = '<html>\n<head>\n<title>listaincontro.it</title>\n'
	         + '<link rel=stylesheet type="text/css" href="'+urlCss+'styles/style.css" /></head>\n'
			 + '<body leftmargin=0 marginwidth=0 topmargin=0 marginheight=0 '
			 + 'onLoad="window.resizeTo(document.imageTest.width+50,document.imageTest.height+150)>\n'
			 + '<center><br /><img src="'+min+'" border=0 name=imageTest" />'
			 + '<br /><br /><font class="Testo">'+tit+'</font><br /><a href="javascript:window.close();" class="Link">Chiudi</A></center>\n'
			 + '</body>\n</html>';
	
	popupImage = window.open('','_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0');
	popupImage.document.open();
	popupImage.document.write(html);
	popupImage.document.close();
}



/*
* Trim
*/
/*
function TRIM(value) {
	re = /\%20+/g;
	value = value.replace(re,"");
	return value;
}
*/
/*
* Per settere la pagina come homepage
*/
function homepage() {
	if(document.all)
		document.body.style.behavior = 'url(#default#homepage)';
	
	document.body.setHomePage('http://www.listaincontro.it');
}

/*
* recupera il giorno attuale
*/
function Giorno() {
	var d, day, x;
	var x = new Array("domenica", "lunedì", "martedì");
	var x = x.concat("mercoledì","giovedì", "venerdì");
	var x = x.concat("sabato");
	d = new Date();
	day = d.getDay();
	return(s = x[day]);
}

/*
* recupera il mese attuale
*/
function Mese() {
	var d, mese, x;
	var x = new Array("Gennaio", "Febbraio", "Marzo", "Aprile");
	var x = x.concat("Maggio", "Giugno", "Luglio", "Agosto");
	var x = x.concat("Settembre", "Ottobre", "Novembre", "Dicembre");
	d = new Date();
	mese = d.getMonth();
	return(s = x[mese]);
}



/*
* Mostra la data odierna
*/
function VisualizzaOggi() {
	var d, s, y;
	d = new Date();
	s = Giorno() + " "
	s += d.getDate() + " ";
	s += Mese() + " ";

	y = d.getYear();

	if (y.toString().length == 2){
		y = "20" + y;
	} else if (y.toString().length < 4){
		y = 1900 + parseInt(y, 10) ;
	}

	s += y;
	return(s);
}

/*
* controlla se un valore e' numerico
*/
function isNumeric(value) {
	if(isNaN(value)) return false;
	else return true;
}

/**
* Viene richiamata con l'evento onLoad della pagina.
* Visualizza il messaggio di errore proveniente da un datalet.
* esempio: showMessage(errore, deleteMessage, 'update', '');
*/
function showMessage(dlMsg, delMsg, dataOp, extLoad) {
	//settaggio variabili globali
	//if(delMsg != "") controls_delete_message = delMsg;

	//visualizzazione messaggio proveniente dal datalet
	if(extLoad != "") {
		eval(extLoad);
	}

	if(dlMsg != ""){
		alert(dlMsg);
		return;
	}

	//visualizzazione messaggio operazione effettuata
	var msgOk = "";
	if(dataOp == "insert") msgOk = "Inserimento effettuato";
	if(dataOp == "delete") msgOk = "Eliminazione effettuata";
	if(dataOp == "update") msgOk = "Modifica effettuata";
	if(msgOk != "") alert(msgOk);
}


document.write('<scr'+'ipt language="Java'+'Scr'+'ipt" src="sniffer'+'.js"></scr'+'ipt>');


function showGallery(url) {
    window.open(url,'_blank','toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0');
}



function CheckLength(obj, max_length){
	return true;
}

// ------------------------------------------ POPUP COMUNI --------------------
function openComuni(frm, id, desc){
	var pr = frm.elements("Prov").value;
	if (pr == ""){
		window.alert("Attenzione!\nE' necessario scegliere una provincia!");
		return;
	}

	frm.elements(id).value = "";
	frm.elements(desc).value = "";

	var winStyle = 'toolbar=0,location=0,directories=0,'
	             + 'menuBar=0,scrollbars=0,resizable=0';

	var obj_id = frm.name + ".elements('" + id + "')";
	var obj_desc = frm.name + ".elements('" + desc + "')";

	window.open("openComuni.asp?prov="+pr+"&retid="+obj_id+"&retdesc="+obj_desc,'_blank', winStyle);
}

// ---------------------------------- FINE POPUP COMUNI -----------------------

// ------------------------------------------ POPUP IMMAGINI --------------------
function openImmagini(frm, elem, path){
	frm.elements(elem).value = "";

	var winStyle = 'toolbar=0,location=0,directories=0,'
	             + 'menuBar=0,scrollbars=1,resizable=0';

	var obj_elem = frm.name + ".elements('" + elem + "')";

	window.open("imagesList.asp?path="+path+"&ret="+obj_elem,'_blank', winStyle);
	//window.open("openImmagini.asp?path="+path+"&ret="+obj_elem,'_blank', winStyle);
}
// ------------------------------------ FINE POPUP IMMAGINI ---------------------


// ------------------------------------------ STATISTICHE HITS--------------------
function openStatisticheHits(tb, obj, txt){
	if (obj.value == ""){
		window.alert("Attenzione!\nE' necessario scegliere "+txt+"!");
		return;
	}

	document.location.href='HitsBannerDet.asp?tb='+tb+'&txt='+txt
}

// ---------------------------------- FINE STATISTICHE HITS-----------------------

// ------------------------------------------ POPUP EVENTI --------------------

function openEvento(frm, id, desc){
	var cm = frm.elements("fkComuni").value;
	if (cm == ""){
		window.alert("Attenzione!\nE' necessario scegliere un provincia!");
		return;
	}

	frm.elements(id).value = "";
	frm.elements(desc).value = "";

	var winStyle = 'toolbar=0,location=0,directories=0,'
	             + 'menuBar=0,scrollbars=0,resizable=0';

	var obj_id = frm.name + ".elements('" + id + "')";
	var obj_desc = frm.name + ".elements('" + desc + "')";

	window.open("openEventi.asp?fkComuni="+cm+"&retid="+obj_id+"&retdesc="+obj_desc,'_blank', winStyle);
}
// ------------------------------------ FINE POPUP EVENTI ---------------------

    function chiudi_finestra() {
        window.onunload = " ";
        window.close();
    }

	/*
		checkDel mediante conferma esegue un link per eliminare un record
		@pg String: Nome tabella
		@id Integer: id del record da eliminare
	*/
	function checkDel(pg, id){
		var fnz = document.forms[0].funz.value;
		if (window.confirm(DEL_MESSAGE)){
			document.location.href = pg+"Lst.asp?op=K&id="+id+"&funz="+fnz;
		}
	}

	/*
		checkDel mediante conferma esegue un link per eliminare un record
		@pg String: Nome tabella
		@id Integer: id del record da eliminare
		@par String: querystring
	*/
	function checkDelParam(pg, id, par){
		if (window.confirm(DEL_MESSAGE)){
			document.location.href = pg+"Lst.asp?op=K&id="+id+"&"+par;
		}
	}

	/*
		checkDel mediante conferma esegue un link per eliminare un record
		@pg String: Nome tabella
		@id Integer: id del record da eliminare
		@par String: querystring
	*/
	function checkDelParamPers(pg, id, par){
		if (window.confirm(DEL_MESSAGE)){
			document.location.href = pg+".asp?op=K&id="+id+"&"+par;
		}
	}

	/*
		checkDel mediante conferma esegue un link per eliminare un record
		@pg String: Nome tabella
		@id Integer: id del record da eliminare
		@par String: querystring
	*/
	function checkDelParamMsg(pg, id, par, msg){
		var sMsg = msg;
		if (msg == null){
			sMsg = DEL_MESSAGE;
		} else if (msg == "") {
			sMsg = DEL_MESSAGE;
		}

		if (window.confirm(sMsg)){
			document.location.href = pg+".asp?op=K&id="+id+"&"+par;
		}
	}

// --------------------------------------------------------------
function openWindowList(page, frm, id, desc, mand){
	
	var fnz = document.forms[0].funz.value;
//	eval("document."+frm+"."+id+".value = '';");
//	eval("document."+frm+"."+desc+".value = '';");
	var arrMand;
	var sKey = '';
	var sDescFilter = '';
	if (mand != '')	{
		arrMand = mand.split("|");
		if (eval("document."+frm+"."+arrMand[0]+".value == '';")){
			window.alert("Attenzione!\n"+arrMand[1]+": campo obbligatorio.");
			return;
		} else {
			eval("sKey = document."+frm+"."+arrMand[0]+".value;");
		}
	}

	
	eval("sDescFilter = document."+frm+"."+desc+".value;")
	//eval("document.getElementById(\""+id+"\").value = '';");
	//eval("document.getElementById(\""+desc+"\").value = '';");

	var winStyle = 'toolbar=0,location=0,directories=0,'
	             + 'menuBar=0,scrollbars=1,resizable=0';

	var winQuery = "?frm="+frm+"&id="+id+"&desc="+sDescFilter+"&key="+sKey+"&funz="+fnz;

	window.open(page+".asp"+winQuery,'_blank', winStyle);
}
// ---------------------------------------------------------
function clearFields(frm, fields){
	if (fields != ''){
		var arrFlds = fields.split("|");
		for (var i=0; i<arrFlds.length; i++){
			eval("document."+frm+"."+arrFlds[i]+".value = '';")
		}
	}
}
// ---------------------------------------------------------

/* Path contenente le immagini */
function openCartella(sNomeCartella, frm, tipo){

	eval("document."+frm+"."+sNomeCartella+".value == '';");

	//frmCreaGallary
	var sPath = "popup_web_directory.asp?sRetFrmName=" + frm
			  + "&sRetCartella=" + sNomeCartella + "&sTipo="+tipo;

	var winStyle = 'toolbar=0,location=0,directories=0,'
				 + 'menuBar=0,scrollbars=1,resizable=0';

	window.open(sPath,'_blank',winStyle);
}
// ---------------------------------------------------------


/* Verifica delle password nella registrazione */
function check_pwds(){
	var sPwd1 = document.forms[0].TEXT_PASSWORD.value;
	var sPwd2 = document.forms[0].TEXT_PASSWORD2.value;

	if ((sPwd1 == "") ||(sPwd2 == "")){
		return "Bisogna indicare le password!"
	}

	if ((sPwd1 != sPwd2)){
		return "Le password non sono uguali!"
	}

	return null;

}

function del_disabled(){
	window.alert("Attenzione!\nUtente non abilitato alla cancellazione");
}

/**********************************************************************/
/**************** UPLOAD                                       ********/
/**********************************************************************/
function setPathUpload(frm_name, nome_catella){
alert();
//	eval("document."+frm_name+".action = document."+frm_name+".action+'&catella="+nome_catella+"';")
}

/**
* Viene richiamata con l'evento onLoad della pagina.
* Visualizza il messaggio 
* esempio: message('ciao');
*/
function message(str) {
	if (trim(str) != ""){
		var new_str = str.replace("<br />","\n");
		if (trim(new_str) != ""){
			window.alert(new_str);
		}
	}
}


/**  
*  
*  Javascript trim, ltrim, rtrim  
*  http://www.webtoolkit.info/  
*  
*  
**/  
  
function trim(str, chars) {   
    return ltrim(rtrim(str, chars), chars);   
}   
  
function ltrim(str, chars) {   
    chars = chars || "\\s";   
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");   
}   
  
function rtrim(str, chars) {   
    chars = chars || "\\s";   
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");   
}

/*
Sostituisce in una stringa(stringa) un carattere specificato(Chr1), con un altro(Chr2).
Ritorna la stringa modificata.
*/
function SOSTCHARACTER(Chr1,Chr2,stringa){
  for (r=0; r < stringa.toString().length ; r++ ){
    stringa = stringa.toString().replace(Chr1,Chr2);
  }
  return stringa;
}
function ctrlNewsletter() {
	var f = document.mailing

	if (f.emailaddress.value.length < 8) {
		window.alert("E' necessario inserire un indirizzo E-Mail valido.")
		f.emailaddress.focus();
		return false;
	}

	if (f.emailaddress.value.indexOf("@") == -1) {
		window.alert("E' necessario inserire un indirizzo E-Mail valido.")
		f.emailaddress.focus();
		return false;
	}

	if (f.emailaddress.value.indexOf(".") == -1) {
		window.alert("E' necessario inserire un indirizzo E-Mail valido.")
		f.emailaddress.focus();
		return false;
	}

	return true;
}

function news_email(idNews) {
	var finestra = window.open("news_email.asp?idNews="+idNews, "finestrainfo", "width=450, height=250, toolbar=0, status=0");
}

function news_print(idNews) {
	var finestra = window.open("news_print.asp?idNews="+idNews, "finestrainfo", "width=640, height=480, toolbar=0, status=0");
}

function newsletter_preview(objForm) {

	/******* INIZIO WYSIWYG editor  ***************************/
	var n = "TEXT_CONTENUTO";
	var doc = document.getElementById(n); 

	doc.value = document.getElementById("wysiwyg" + n).contentWindow.document.body.innerHTML; 

	if (doc.value == "<br>" || doc.value == "<br />" || doc.value == ""){ 
		window.alert("Attenzione!\nInserire il contenuto!!!"); 
		return;
	}

	/******* fine WYSIWYG editor  ***************************/


	var qs = "?1=1";
	qs += "&fr=" + objForm.elements["TEXT_EMAIL_SENDER"].value;
	qs += "&ob=" + objForm.elements["TEXT_TITOLO"].value;
	qs += "&ms=" + escape(doc.value);
//	qs += "&ms=" + objForm.elements["TEXT_CONTENUTO"].value;
	
	var finestra = window.open("MailinglistPrv.asp"+qs, "finestrainfo", "width=640, height=480, toolbar=0, status=0");
}

/********************************************************************************/
/********************* INIZIO POPUP MENU-MODULI       ***************************/
/********************************************************************************/

	/*
		setUrlParamFromPopUp
		@objText : oggetto html di tipo text
		@val : stringa
		Recupero il valore del parametro e lo aggiungo
		setta il valore di objText

	*/
	function setUrlParamFromPopUp(objText, val){
		if (objText == undefined){
			window.alert("objText non è definito!");
			return;
		}
		//Controllo se val è il primo elemento vuoto
		if (val == ""){
			return;
		}

		//Creo un array
		var arrModVal = val.split("|");
		//window.alert(arrModVal.length);
		if (arrModVal.length < 2){
			window.alert("arrModVal non è valido");
			return;
		}

		var arrTestSwitch = arrModVal[1].split("/");
		var sTestSwitch = arrTestSwitch[arrTestSwitch.length-1];
		//alert("sTestSwitch: "+sTestSwitch);

		switch (sTestSwitch){
			case  "content.asp":openContenutoStatico(objText.name);break;
			case  "section.asp":openSection(objText.name);break;
			case  "pgalleryCat.asp":openPGalleryCat(objText.name);break;
			case  "newsDet.asp":openNews(objText.name);break;
			case  "categories.asp":openCategorie(objText.name);break;
			case  "download.asp":openCatDownloads(objText.name);break;
			
			default : window.alert("Attenzione!\nNon abilitato per questa scelta."); 
		}
	}


	function openNews(objTextName){
		var winStyle = 'toolbar=0,location=0,directories=0,'
					 + 'menuBar=0,scrollbars=0,resizable=0,width=800;height=600';

		//Verifico se non è stato già valorizzato
		var sTestTextValue = document.getElementById(objTextName).value;
		if (sTestTextValue.substr(sTestTextValue.length-1,1) != "="){
			var pos = sTestTextValue.lastIndexOf("=");
			sTestTextValue = sTestTextValue.substr(0, pos+1);
			document.getElementById(objTextName).value = sTestTextValue;
		}
		
		var obj_desc = "document.getElementById('" + objTextName + "')";

		window.open("MenuNewsPopUp.asp?retid="+obj_desc,'_blank', winStyle);
	}


	function openPGalleryCat(objTextName){
		var winStyle = 'toolbar=0,location=0,directories=0,'
					 + 'menuBar=0,scrollbars=0,resizable=0,width=800;height=600';

		//Verifico se non è stato già valorizzato
		var sTestTextValue = document.getElementById(objTextName).value;
		if (sTestTextValue.substr(sTestTextValue.length-1,1) != "="){
			var pos = sTestTextValue.lastIndexOf("=");
			sTestTextValue = sTestTextValue.substr(0, pos+1);
			document.getElementById(objTextName).value = sTestTextValue;
		}
		
		var obj_desc = "document.getElementById('" + objTextName + "')";

		window.open("MenuAlbumImgCatPopUp.asp?retid="+obj_desc,'_blank', winStyle);
	}


	function openSection(objTextName){
		var winStyle = 'toolbar=0,location=0,directories=0,'
					 + 'menuBar=0,scrollbars=0,resizable=0,width=800;height=600';

		//Verifico se non è stato già valorizzato
		var sTestTextValue = document.getElementById(objTextName).value;
		if (sTestTextValue.substr(sTestTextValue.length-1,1) != "="){
			var pos = sTestTextValue.lastIndexOf("=");
			sTestTextValue = sTestTextValue.substr(0, pos+1);
			document.getElementById(objTextName).value = sTestTextValue;
		}
		
		var obj_desc = "document.getElementById('" + objTextName + "')";

		window.open("MenuSezioniPopUp.asp?retid="+obj_desc,'_blank', winStyle);
	}


	function openCategorie(objTextName){
		var winStyle = 'toolbar=0,location=0,directories=0,'
					 + 'menuBar=0,scrollbars=0,resizable=0,width=800;height=600';

		//Verifico se non è stato già valorizzato
		var sTestTextValue = document.getElementById(objTextName).value;
		if (sTestTextValue.substr(sTestTextValue.length-1,1) != "="){
			var pos = sTestTextValue.lastIndexOf("=");
			sTestTextValue = sTestTextValue.substr(0, pos+1);
			document.getElementById(objTextName).value = sTestTextValue;
		}
		
		var obj_desc = "document.getElementById('" + objTextName + "')";

		window.open("MenuCategoriePopUp.asp?retid="+obj_desc,'_blank', winStyle);
	}


	function openContenutoStatico(objTextName){
	/*
		var pr = frm.elements("Prov").value;
		if (pr == ""){
			window.alert("Attenzione!\nE' necessario scegliere una provincia!");
			return;
		}
	*/

		var winStyle = 'toolbar=0,location=0,directories=0,'
					 + 'menuBar=0,scrollbars=0,resizable=0,width=800;height=600';

		//Verifico se non è stato già valorizzato
		var sTestTextValue = document.getElementById(objTextName).value;
		if (sTestTextValue.substr(sTestTextValue.length-1,1) != "="){
			var pos = sTestTextValue.lastIndexOf("=");
			sTestTextValue = sTestTextValue.substr(0, pos+1);
			document.getElementById(objTextName).value = sTestTextValue;
		}
		
		var obj_desc = "document.getElementById('" + objTextName + "')";

		window.open("MenuContenutiPopUp.asp?retid="+obj_desc,'_blank', winStyle);
	}

	/*
		setComboModulo
		@objSelect : oggetto html di tipo select
		@val : stringa
		Al caricamento della pagina in base a val
		setta il valore della combo objSelect

	*/
	function setComboModulo(objSelect, val){
		if (objSelect == undefined){
			window.alert("objSelect: non è definito!")
			return;
		}
		//Scorro gli elementi della combo objSelect e se la prima parte  
		// delvalore corrisponde al valore passato val la setto
		for(i=0;i<objSelect.length;i++){
			if (objSelect.options[i].value.substr(0,val.length) == val){
				objSelect.options[i].selected=true;
				//alert(objSelect.options[i].value);
				break;
			}
		}
	}

	/*
		setUrlByModulo
		@objText : oggetto html di tipo text
		@val : stringa
		Al variare del valore della combo Moduli 
		setta il valore di objText
	*/
	function setUrlByModulo(objText, val){
		if (objText == undefined){
			window.alert("objText non è definito!");
			return;
		}
		//Controllo se val è il primo elemento vuoto
		if (val == ""){
			objText.readOnly = false;
			objText.value = "";
			return;
		}
		//Blocco la text
		objText.readOnly = true;

		//Creo un array
		var arrModVal = val.split("|");
		//window.alert(arrModVal.length);
		if (arrModVal.length < 2){
			window.alert("arrModVal non è valido");
			return;
		}

		objText.value = arrModVal[1];

		if (arrModVal[2] != ""){
			objText.value += "?"+arrModVal[2]+"=";
		}
	}


	function openCatDownloads(objTextName){
		var winStyle = 'toolbar=0,location=0,directories=0,'
					 + 'menuBar=0,scrollbars=0,resizable=0,width=800;height=600';

		//Verifico se non è stato già valorizzato
		var sTestTextValue = document.getElementById(objTextName).value;
		if (sTestTextValue.substr(sTestTextValue.length-1,1) != "="){
			var pos = sTestTextValue.lastIndexOf("=");
			sTestTextValue = sTestTextValue.substr(0, pos+1);
			document.getElementById(objTextName).value = sTestTextValue;
		}
		
		var obj_desc = "document.getElementById('" + objTextName + "')";

		window.open("MenuCatDownloadsPopUp.asp?retid="+obj_desc,'_blank', winStyle);
	}

/********************************************************************************/
/*********************   FINE POPUP MENU-MODULI       ***************************/
/********************************************************************************/



/* ********************************************** */
function check_filetype(id){
	var filename = document.getElementById(id).value;

	if (trim(filename.toString()).length == 0){
		return "Specificato il file per l'upload!"
	}

	return null;

}