function popmodalWindow(url, larghezza, altezza, dati){
	width = Math.min(screen.width, larghezza);
	height = Math.min(screen.height, altezza);
	tipobrowser = getbrowser();
	/*
	if (window.showModalDialog) {
		var myText = showModalDialog(url,dati,' dialogWidth:' + width + 'px; dialogHeight:' + height + 'px; resizable:yes; status:yes');
	}else{
		*/
		MM_openBrWindow(url,'','width=' + width + ',height=' + height + ',resizable=yes');
	//}
}
function popWindow(url, larghezza, altezza, dati){
	width = Math.min(screen.width, larghezza);
	height = Math.min(screen.height, altezza);
	tipobrowser = getbrowser();
	/*
	if (window.showModalDialog) {
		var myText = showModalDialog(url,dati,' dialogWidth:' + width + 'px; dialogHeight:' + height + 'px; resizable:yes; status:yes');
	}else{
		*/
		MM_openBrWindow(url,'','width=' + width + ',height=' + height + ',resizable=yes');
	//}
}

function str2date(str, formato){
	var t = str.split("/");
	if (t.length != 3) t = str.split("-");
	if (t.length != 3) t = str.split(" ");
	if (t.length != 3) return -1;
	if (!t[0] > 0) return -1;
	if (!t[1] > 0) return -2;
	if (!t[2] > 0) return -3;
	
	if (t[2]<1902 || t[2]>2037) return -3;
	switch(formato){
		case 'm':
			return (t[1]);
		break;
		case 'Y':
			return (t[2]);
		break;
		default:
			return (t[2] + '-' + t[1] + '-' + t[0]);
		break;
	}
}



function getbrowser(){
	agt = navigator.userAgent.toLowerCase();
	is_ie	   = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
	is_opera  = (agt.indexOf("opera") != -1);
	is_mac	   = (agt.indexOf("mac") != -1);
	is_mac_ie = (is_ie && is_mac);
	is_win_ie = (is_ie && !is_mac);
	is_gecko  = (navigator.product == "Gecko");
	if (is_opera){
		return "opera";
	}else if (is_gecko){
		return "Gecko";
	}else if (is_win_ie){
		return "win_ie";
	}else if (is_mac_ie){
		return "mac_ie";
	}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
// Example: obj = findObj("image1");
function findObj(theObj, theDoc){
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}

//altera un xml sostituendo i caratteri per impedire il parsing
function xml_altera(stringa){
	re = /</g;             //Create regular expression pattern.
	stringa = stringa.replace(re, '«');
	re = />/g;             //Create regular expression pattern.
	stringa = stringa.replace(re, '»');
	re = /&/g;             //Create regular expression pattern.
	stringa = stringa.replace(re, '§');
	return(stringa);
}

//ripristina un xml sostituendo i caratteri
/*
function xml_ripristina(stringa){
	stringa = new String(stringa);
	re = /«/g;             //Create regular expression pattern.
	stringa = stringa.replace(re, '<');
	re = /»/g;             //Create regular expression pattern.
	stringa = stringa.replace(re, '>');
	re = /§/g;             //Create regular expression pattern.
	stringa = stringa.replace(re, '&');
	return(stringa);
}
*/
function vaiapagina(id_pagine){
	window.location.href = 'index.php?id_pagine=' + id_pagine;
}

//
tx_attesa = '<img src="../img/ico/loading.gif" width="200" height="15" alt="" align="absmiddle"> Invio richiesta al server.<br>Attendere';
mostra_tooltip = false;
arr_tooltips = new Array();
arr_tooltips_titolo = new Array();
function cambia_tooltip(){
		arr_tooltips = new Array();
		arr_tooltips_titolo = new Array();
		mostra_tooltip = !( mostra_tooltip);
		ck_tooltip = findObj("tooltip");
		ck_tooltip.checked = mostra_tooltip;
}

function help_tooltip(tx_mnemonico, forzato){
	if(mostra_tooltip || forzato){
		if (arr_tooltips[tx_mnemonico]){
			overlib(arr_tooltips[tx_mnemonico],CAPTION,arr_tooltips_titolo[tx_mnemonico],CLOSETEXT, 'Chiudi',STICKY, MOUSEOFF);//
		}else{
			overlib("Invio richiesta al server.<br>Attendere",STICKY, MOUSEOFF);//
			jsrsPOST = true;
			jsrsExecute("../inc/jsrs.php", help_tooltip_Callback, "help_tooltip",tx_mnemonico);
		}
	}
}
function help_tooltip_Callback(returnstring){
	//leggoi dati ricevuti
	returnstring = xml_ripristina(returnstring);
	xmlrec = new Recordset(returnstring);
	xmlrec.moveFirst();
	num_righe = xmlrec.countRecords();
	nd();
	if(num_righe > 0){
		xmlrec.moveTo(0);
		tx_mnemonico = xmlrec.getField('mnemonico');
		tx_titolo = xmlrec.getField('titolo');
		tx = xmlrec.getField('tx');
		arr_tooltips[tx_mnemonico] = tx;
		arr_tooltips_titolo[tx_mnemonico] = tx_titolo;
		overlib(tx,CAPTION,tx_titolo,CLOSETEXT, 'Chiudi',STICKY, MOUSEOFF);//
	}else{
		tx = "Guida non disponibile.";
		overlib(tx,STICKY, MOUSEOFF);//
	}
	//alert(returnstring);
	returnstring = "";
}

function addEvent(obj, evType, fn){ 
	if (obj.addEventListener) { obj.addEventListener(evType, fn, true); return true; } 
	else if (obj.attachEvent) {  var r = obj.attachEvent("on"+evType, fn);  return r;  } 
	else {  return false; } 
}

function set_innerHTML(passedArgsObj){
	/* defaults */
	args = { div:'', tx:'' };
	/* override the defaults if necessary */
	for (var argName in passedArgsObj) {
	args[argName] = passedArgsObj[argName];
	}	
	
	if(global_divs[args.div]){
		global_divs[args.div].innerHTML = args.tx;
		return true;
	}
	return false;
}

/* -----------------------------------------------------------------------------------
------- Trim(), LTrim(), RTrim() -----------------------------------------------------
-------
------- Metodi per l'oggetto String, restituiscono la stringa cui sono applicati
------- senza spazi iniziali e/o finali:
-------
------- str_a = stringa.Trim();
------- str_a contiene il valore di stringa senza spazi iniziali ne' finali
-------
------- str_a = stringa.LTrim();
------- str_a contiene il valore di stringa senza spazi iniziali
-------
------- str_a = stringa.RTrim();
------- str_a contiene il valore di stringa senza spazi finali
-------
------- N.B.
------- [\s] nelle RegExp contiene sia gli spazi che i ritorni a capo, avanzamento riga
------- tabulatore, tabulatore verticale. Tutti questi caratteri, se presenti, verranno
------- eliminati.
------- --- */
String.prototype.Trim=function(){
	return this.replace(/\s+$|^\s+/g,"");
} 
String.prototype.RTrim=function(){
	return this.replace(/\s+$/,"");
};   
String.prototype.LTrim=function(){
	return this.replace(/^\s+/,"");
} 
/* ----------------------------------------------------------------------------------- */


String.prototype.addSlashes=function(){
	//return this.replace(/'/gi,"\'");
	
	s = this.replace(/'/gi,"\\'");
	return s;
}
String.prototype.pad = function(l, s, t){
	return s || (s = " "), (l -= this.length) > 0 ? (s = new Array(Math.ceil(l / s.length)
		+ 1).join(s)).substr(0, t = !t ? l : t == 1 ? 0 : Math.ceil(l / 2))
		+ this + s.substr(0, l - t) : this;
};

function apri_finestra(theURL,Desc) { 
features='scrollbars=no,width=612,height=450';
  window.open('gallery_view.php?img=' + theURL + '&did=' + Desc,'',features);
}

function cms_encrypt(str, key){
	key = key || '';
	//return(xxtea_encrypt(str, key));
	return str;
}


function cms_decrypt(str, key){
	key = key || '';
	//return(xxtea_decrypt(str, key));
	return str;
}

var last="";
var rot13map;

function rot13init()
{
  var map = new Array();
  var s   = "abcdefghijklmnopqrstuvwxyz";
  
  for (i=0; i<s.length; i++)
    map[s.charAt(i)]			= s.charAt((i+13)%26);
  for (i=0; i<s.length; i++)
    map[s.charAt(i).toUpperCase()]	= s.charAt((i+13)%26).toUpperCase();
  return map;
}

function rot13(a) {
  if (!rot13map) rot13map=rot13init();
  s = "";
  for (i=0; i<a.length; i++)
    {
      var b = a.charAt(i);

      s	+= (b>='A' && b<='Z' || b>='a' && b<='z' ? rot13map[b] : b);
    }
  return s;
}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (
aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
}

function isPari(numero){
	resto = numero % 2;
	return (resto > 0) ? false : true;	
}
function preloadImages()
{
  if(document.images)
  {
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;
    
    for(i=0; i<args.length; i++)
    {
      if (args[i].indexOf("#")!=0)
      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }
}

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}
