function txtValida(oObj1, oObj2, sTrue, sFalse){
	  if (document.getElementById(oObj1).checked){
		  document.getElementById(oObj2).innerHTML = sTrue.toString();
	  }else{
		  document.getElementById(oObj2).innerHTML = sFalse.toString();
	  }
    }
	
String.prototype.Replace = function(s1, s2){
		return this.split(s1).join(s2);
	}
	
	function replaceHtmlSpecialChars(str) {
		var sHtml = str;
		return sHtml.Replace("’","'").Replace("“","\"").Replace("”","\"").Replace("–", "-").Replace("€", "&euro;");
		return sHtml;
	}

// segnalazioni e reclami
	function jsSegnalazioni(ID, sOp){
		if(confirm("Sei sicuro di voler proseguire?")){
		window.location = 'adminSegnalazioniExec.asp?sOp='+sOp+'&amp;id='+ID;
		}
	}
	// segnalazioni e reclami
	function jsSegnalazioniCategorie(ID, sOp){
		if(confirm("Sei sicuro di voler proseguire?")){
		window.location = 'adminSegnalazioniCategorieExec.asp?sOp='+sOp+'&amp;id='+ID;
		}
	}


//**************************************************************
	// SHOW - HIDE OBJECT
	//**************************************************************
	if(document.layers) { var ns4 = true; }
	if(document.all && !document.getElementById) { var ie4 = true; }
	if(document.all && document.getElementById) {var ie5 = true;};
	if(document.addEventListener) {var nn6 = true};
	var undefined, currentElement;
			function showHideElement( element ){
				if (currentElement != undefined) hideObject( currentElement );
				showObject( element );
				if (currentElement == element) {
					hideObject( currentElement );
					element = undefined;
				}
				currentElement = element;
			}
			
			function showObject(obj) {
				var myObj;
				if (ns4) {
					 myObj = document[obj];
					 myObj.visibility = "show";
				}else if (ie4) {
					 myObj = document.all[obj];
					 myObj.style.visibility = "visible";
				} else {
					document.getElementById(obj).style.display = '';
				}
			}
			
			function hideObject(obj) {
				var myObj;
				if (ns4) {
					 myObj = document[obj];
					 myObj.visibility = "hide";
				} else if (ie4) {
					 myObj = document.all[obj];
					 myObj.style.display = "none";
				} else {
					document.getElementById(obj).style.display = 'none';
				}
			}
	
	function JsShowHideObject(obj){
		var myObj;
		if (ns4) {
			 myObj = document[obj];
			 if (myObj.visibility == "show") { myObj.visibility = "hide" }
			  else { myObj.visibility = "show" }
		}else if (ie4) {
			 myObj = document.all[obj];
			 if (myObj.style.visibility == "visible") { myObj.style.visibility = "none" }
			  else { myObj.style.visibility = "visible" }
		} else {
			myObj = document.getElementById(obj);
			 if (myObj.style.display == '') { myObj.style.display = 'none' }
			  else { myObj.style.display = '' }
		}
	}
	//**************************************************************
	// SHOW - HIDE OBJECT
	//**************************************************************



function bgAlternate(oObj, sColor){
		oObj.style.backgroundColor=sColor;
	}

function jsMainMenu(id, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminPages_TreeMainEXEC.asp?sOp='+action+'&amp;id='+id;
	}
}
function jsMenuHoriz(id, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminPages_menuHorizEXEC.asp?sOp='+action+'&amp;id='+id;
	}
}
function jsSubMenu(id, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminPages_TreeSubEXEC.asp?sOp='+action+'&amp;id='+id;
	}
}
function jsPages(id, idPlus, fileType, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminPagesEXEC.asp?sOp='+action+'&amp;id='+id+'&amp;fileType='+fileType+'&amp;idPlus='+idPlus;
	}
}

function jsPagesNew2(id, submitUrl, stato, action){
	if(confirm("Sei sicuro di voler proseguire?")){ 
	window.location = submitUrl+'.asp?sOp='+action+'&amp;id='+id+'&st='+stato;
	}
}

function jsAbilitaMailing(id, submitUrl, stato, mail, action){
	if(confirm("Sei sicuro di voler proseguire?")){ 
	window.location = submitUrl+'.asp?sOp='+action+'&amp;id='+id+'&amp;mail='+mail+'&amp;st='+stato;
	}
}

function jsPagesList(id, idPlus, fileType, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminPagesListEXEC.asp?sOp='+action+'&amp;id='+id+'&amp;fileType='+fileType+'&amp;idPlus='+idPlus;
	}
}
function jsPagesListElements(id, IdElement, idPlus, fileType, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminPagesListElementsEXEC.asp?sOp='+action+'&amp;id='+id+'&amp;fileType='+fileType+'&amp;idPlus='+idPlus+'&amp;IdElement='+IdElement;
	}
}

//lucia 07/09/05 inizio
function jsPagesListServices(id, idPlus, fileType, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminPagesListServicesEXEC.asp?sOp='+action+'&amp;id='+id+'&amp;fileType='+fileType+'&amp;idPlus='+idPlus;
	}
}
function jsPagesListServicesElements(id, IdElement, idPlus, fileType, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminPagesListServicesElementsEXEC.asp?sOp='+action+'&amp;id='+id+'&amp;fileType='+fileType+'&amp;idPlus='+idPlus+'&amp;idElement='+IdElement;
	}
}
//lucia 07/09/05 fine

function jsHome(id, idPlus, fileType, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminHomeEXEC.asp?sOp='+action+'&amp;id='+id+'&amp;fileType='+fileType+'&amp;idPlus='+idPlus;
	}
}
function jsUser(id, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminUsersEXEC.asp?sOp='+action+'&amp;id='+id;
	}
}
function jsFaq(id, idPlus, fileType, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminFaqEXEC.asp?sOp='+action+'&amp;id='+id+'&amp;fileType='+fileType+'&amp;idPlus='+idPlus;
	}
}
function jsNL(id, idPlus, fileType, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminNLEXEC.asp?sOp='+action+'&amp;id='+id+'&amp;fileType='+fileType+'&amp;idPlus='+idPlus;
	}
}
function jsNLSend(id, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminNLSend.asp?sOp='+action+'&amp;id='+id;
	}
}
function jsLink(id, idPlus, fileType, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminLinksEXEC.asp?sOp='+action+'&amp;id='+id+'&amp;fileType='+fileType+'&amp;idPlus='+idPlus;
	}
}
function jsProposal(id, action){
	if(confirm("Sei sicuro di voler proseguire?")){
	window.location = 'adminRequestInfoEXEC.asp?sOp='+action+'&amp;id='+id;
	}
}
/**********************************************************************
   Validazione di una data passata in un unico campo 
***********************************************************************/
function isDateString(dateStr) {
	//var datePat = /^(\d{1,2})(\/)(\d{1,2})(\/)(\d{4})$/;
	var datePat = /^(\d{1,2})(-)(\d{1,2})(-)(\d{4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?
	var TipoDiErrore = '';
    if (matchArray == null) {
		return false;
    }
   day = matchArray[1]; // parse date into variables
   month = matchArray[3]; 
   year = matchArray[5];
    if (month < 1 || month > 12) { // check month range
		return false;
    }
    if (day < 1 || day > 31) {
        return false;
    }
    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        return false;
    }
    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {
            return false;
        }
    }
    return true; // date is valid
}

function DateITAtoISO(dateStr) {
	var datePat = /^(\d{1,2})(-)(\d{1,2})(-)(\d{4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?

	day = matchArray[1]; // parse date into variables
    month = matchArray[3]; 
    year = matchArray[5];
   
    var data = new Date(year+"/"+month+"/"+day);
	
	return (data);
}

function datediff(per,d1,d2) {
   var d = (d2.getTime()-d1.getTime())/1000
   switch(per) {
      case "yyyy": d/=12
      case "m": d*=12*7/365.25
      case "ww": d/=7
      case "d": d/=24
      case "h": d/=60
      case "n": d/=60
   }
   return Math.round(d);
}


/**********************************************************************
   Controllo se campo passato è un anno valido compreso fra 1900 e oggi
***********************************************************************/
function isYear (s) {
		var d;
		d = new Date();
		var yyyy = d.getFullYear()
		if ((notNull(s)) && (notBlank(s)) && (isSize(s, 4)) && (!isNaN(s)) && (isInRange(s, 1900, yyyy)) ) { 
			return true; 
		} else { 
			return false;
		}
}

/*************************************************************
	Controllo del Codice Fiscale - solo a livello di sintassi
**************************************************************/
	function Trim(stringa)
	   {
	   reTrim=/\s+$|^\s+/g;
	   return stringa.replace(reTrim,"");
	   }
	function isCodFisc(cod_fisc)
	   {
	   var re = /^[A-Z]{6}\d{2}[A-Z]\d{2}[A-Z]\d{3}[A-Z]$/;
	   Codice=Trim(cod_fisc.toUpperCase());
		return re.test(Codice)
	   }

/*************************************************************

	varie
	
**************************************************************/

	   
	function confirmLink( sMessage, sUrl ) {
		//alert( sMessage+'\n'+sUrl );
		if (confirm(sMessage)) window.navigate(sUrl);
	}

	function ShowHideElement( sObjectId ) {
		var oObj = document.getElementById(sObjectId);
		if (oObj.style.display=='') { oObj.style.display='none' }
		else { oObj.style.display='' }
	}
	
	function lyChange( sId ) {
		var oNote = document.getElementById('nodo_'+sId);
		if (oNote.style.display=="none") { oNote.style.display='' }
		else { oNote.style.display="none" }
	}
	
	function todayDate(){
	   var d, s = "";          
	   d = new Date();
	   var giorno, mese, anno;
	   giorno = d.getDate();
	   if (giorno.toString().length <= 1) {
		giorno = '0' + giorno;
	   }  
	   mese = d.getMonth() + 1;
	   if (mese.toString().length <= 1) {
		mese = '0' + mese;
	   }  
	   anno = d.getYear();
	   
	   s += giorno + "/";                   
	   s += mese + "/";            
	   s += anno;                         
	   return(s);                               
	}
	
	function calendarOnClick(obj){
		if (notBlank(obj.value)) {
			if (!isDateString(obj.value)) {
				obj.value = todayDate();
			}
		}
	}
	
	// sostituisce , con .
	function replaceComma( obj ){
	   var r, re;                    
	   var ss = obj.value;
	   re = new RegExp(",");
	   obj.value = ss.replace(re, ".");    
	   return(obj.value);                   
	}
	
	function isBoxChecked(obj) {
		if (obj.length != undefined ) {
			for (var i=0; i < obj.length ;i++) {
				if (obj[i].checked) return true;
			}
		} else {
			if (obj.checked) return true;
		}
	}
	
	function moveCheckedValues(obj1, obj2){
		obj2.value = '';
		if (obj1.length != undefined) {
			for (var i=0; i < obj1.length ;i++) {
				if (obj1(i).checked) obj2.value += obj1(i).value + ",";
			}
		} else {
			if (obj1.checked) obj2.value += obj1.value + ",";
		}
	}

	function noHtml(txt) {
		a = txt.indexOf('<');
		b = txt.indexOf('>');
		len = txt.length;
		c = txt.substring(0, a);
		if(b == -1) {
		   b = a;
		}
		d = txt.substring((b + 1), len);
		txt = c + d;
		cont = txt.indexOf('<');
		if (cont != -1) {
		  txt = noHtml(txt);
		}
		return txt;
	 }

	function textCounter(field, countfield, maxlimit) {
	  if (field.value.length > maxlimit) {
		  	field.value = field.value.substring(0, maxlimit);
	  } else {
		  countfield.value = maxlimit - field.value.length;
	  }
	}
	
/* *********************** */

// if two digit year input dates after this year considered 20 century.
	var NUM_CENTYEAR = 30;
	// is time input control required by default
	var BUL_TIMECOMPONENT = false;
	// are year scrolling buttons required by default
	var BUL_YEARSCROLL = true;
	
	var calendars = [];
	var RE_NUM = /^\-?\d+$/;
	var obj_calwindow;
	
	function calendar1(obj_target) {
	
		// assing methods
		this.gen_date = cal_gen_date1;
		this.gen_time = cal_gen_time1;
		this.gen_tsmp = cal_gen_tsmp1;
		this.prs_date = cal_prs_date1;
		this.prs_time = cal_prs_time1;
		this.prs_tsmp = cal_prs_tsmp1;
		this.popup    = cal_popup1;
	
		// validate input parameters
		if (!obj_target)
			return cal_error("Error calling the calendar: no target control specified");
		if (obj_target.value == null)
			return cal_error("Error calling the calendar: parameter specified is not valid tardet control");
		this.target = obj_target;
		this.time_comp = BUL_TIMECOMPONENT;
		this.year_scroll = BUL_YEARSCROLL;
		
		// register in global collections
		this.id = calendars.length;
		calendars[this.id] = this;
	}
	
	function cal_popup1 (str_datetime) {
		this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
		if (!this.dt_current) return;
	
		obj_calwindow = window.open(
			'../scripts/calendar.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
			this.target.name, 'width=200,height='+(this.time_comp ? 205 : 180)+
			',status=no,resizable=no,location=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
		);
		obj_calwindow.opener = window;
		obj_calwindow.focus();
	}
	
	// timestamp generating function
	function cal_gen_tsmp1 (dt_datetime) {
		return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));
	}
	
	// date generating function
	function cal_gen_date1 (dt_datetime) {
		return (
			(dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "-"
			+ (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "-"
			+ dt_datetime.getFullYear()
		);
	}
	// time generating function
	function cal_gen_time1 (dt_datetime) {
		return (
			(dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
			+ (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
			+ (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
		);
	}
	
	// timestamp parsing function
	function cal_prs_tsmp1 (str_datetime) {
		// if no parameter specified return current timestamp
		if (!str_datetime)
			return (new Date());
	
		// if positive integer treat as milliseconds from epoch
		if (RE_NUM.exec(str_datetime))
			return new Date(str_datetime);
			
		// else treat as date in string format
		var arr_datetime = str_datetime.split(' ');
		return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
	}
	
	// date parsing function
	function cal_prs_date1 (str_date) {
	
		var arr_date = str_date.split('-');
	
		if (arr_date.length != 3) return cal_error ("Formato Data non valido: '" + str_date + "'.\nIl Formato accettato è dd-mm-yyyy.");
		if (!arr_date[0]) return cal_error ("Formato Data non valido: '" + str_date + "'.\nSpecificare il giorno del mese.");
		if (!RE_NUM.exec(arr_date[0])) return cal_error ("Giorno del mese non valido: '" + arr_date[0] + "'.\nConsentiti Valori numerici interi.");
		if (!arr_date[1]) return cal_error ("Formato Data non valido: '" + str_date + "'.\nSpecificare il Mese.");
		if (!RE_NUM.exec(arr_date[1])) return cal_error ("Mese non valido: '" + arr_date[1] + "'.\nConsentiti Valori numerici interi.");
		if (!arr_date[2]) return cal_error ("Formato Data non valido: '" + str_date + "'.\nSpecificare l'Anno.");
		if (!RE_NUM.exec(arr_date[2])) return cal_error ("Valore Anno non valido: '" + arr_date[2] + "'.\nConsentiti Valori numerici interi.");
	
		var dt_date = new Date();
		dt_date.setDate(1);
	
		if (arr_date[1] < 1 || arr_date[1] > 12) return cal_error ("Mese non valido: '" + arr_date[1] + "'.\nValori consentiti 01-12.");
		dt_date.setMonth(arr_date[1]-1);
		 
		if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
		dt_date.setFullYear(arr_date[2]);
	
		var dt_numdays = new Date(arr_date[2], arr_date[1], 0);
		dt_date.setDate(arr_date[0]);
		if (dt_date.getMonth() != (arr_date[1]-1)) return cal_error ("Giorno del mese non valido: '" + arr_date[0] + "'.\nValori consentiti 01-"+dt_numdays.getDate()+".");
	
		return (dt_date)
	}
	
	// time parsing function
	function cal_prs_time1 (str_time, dt_date) {
	
		if (!dt_date) return null;
		var arr_time = String(str_time ? str_time : '').split(':');
	
		if (!arr_time[0]) dt_date.setHours(0);
		else if (RE_NUM.exec(arr_time[0])) 
			if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
			else return cal_error ("Indicazione Ora non valida: '" + arr_time[0] + "'.\nValori consentiti 00-23.");
		else return cal_error ("Orario non valido: '" + arr_time[0] + "'.\nConsentiti Valori numerici interi.");
		
		if (!arr_time[1]) dt_date.setMinutes(0);
		else if (RE_NUM.exec(arr_time[1]))
			if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
			else return cal_error ("Indicazione Minuti non valida: '" + arr_time[1] + "'.\nValori consentiti 00-59.");
		else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nConsentiti Valori numerici interi.");
	
		if (!arr_time[2]) dt_date.setSeconds(0);
		else if (RE_NUM.exec(arr_time[2]))
			if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
			else return cal_error ("Indicazione Secondi non valida: '" + arr_time[2] + "'.\nValori consentiti 00-59.");
		else return cal_error ("Indicazione Secondi non valida: '" + arr_time[2] + "'.\nConsentiti Valori numerici interi.");
	
		dt_date.setMilliseconds(0);
		return dt_date;
	}
	
	function cal_error (str_message) {
		alert (str_message);
		return null;
	}

	function isDateString(dateStr) {
		var datePat = /^(\d{1,2})(-)(\d{1,2})(-)(\d{4})$/;
		var matchArray = dateStr.match(datePat); // is the format ok?
	
		if (matchArray == null) {
			return false;
		}
		
	   day = matchArray[1]; // parse date into variables
	   month = matchArray[3]; 
	   year = matchArray[5];
	
		if (month < 1 || month > 12) { // check month range
			return false;
		}
		if (day < 1 || day > 31) {
			return false;
		}
		if ((month==4 || month==6 || month==9 || month==11) && day==31) {
			return false;
		}
		if (month == 2) { // check for february 29th
			var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
			if (day > 29 || (day==29 && !isleap)) {
				return false;
			}
		}
		return true; // date is valid
	}

