sel_op = 0;
sel_dom = 0;
sel_ut = 0;
sel_cat = 0;
sel_avv = 0;
div_padre = '';
liv_padre=0;
posizione=0;


var evUtente = 12;
var evCategoria = 14;
var evRisposta = 13;

var SHEEBOO_scambio = new Object();
/**
* Se true parte la riga debugger, altrimenti non viene eseguita.
*/
var debugging = true;

var SHEEBOO_scambio = new Object();
SHEEBOO_scambio['categoria_in_modifica'] = '';
/**
 * @sdoc funzioni.sdoc
 */

/**
 * Mostra il box delle categorie inserite.
 * @id showinsertcats
 *
 */
function showinsertcats(){
document.getElementById('insertCatBox').style.display='none';
if(document.getElementById('myop1').value!='' && document.getElementById('myop2').value!='')
{
document.getElementById('goinsertcat1').style.visibility='hidden';
document.getElementById('goinsertcat2').style.visibility='visible';
}
else
{
if(document.getElementById('myop1').value!='')
{
document.getElementById('goinsertcat1').style.visibility='visible';
document.getElementById('goinsertcat2').style.visibility='hidden';
}
else
{
document.getElementById('goinsertcat1').style.visibility='hidden';
document.getElementById('goinsertcat2').style.visibility='hidden';
document.getElementById('insertCatBox').style.display='block';
}
}
}
function showInsertBox()
{
if(dcheckCampoEstesoocument.getElementById('insertCatBox').style.display!='none')
{
document.getElementById('insertCatBox').style.display='none';
return;
}
document.getElementById('insertCatBox').style.display='block';
}

function conta(){
  var lenMax=500
  var mm = document.dx.corpo;
  var chars=document.dx.corpo.value.length;
  left = eval(lenMax - chars);
  if (left <= "-1")
  {
    var dif = eval(chars - lenMax);
    var value = mm.value.substr(0,chars-dif);
    mm.value = value;
    var left = "0";
  }
  document.dx.quanti.value=left;
}

function allarga()
{
  document.dx.corpo.style.width = '100%';
  document.dx.corpo.style.height ='100%';
}

function SelAll (form)
{
  var nb;
  var sel;

  if (eval('sel_' + form + ' == 0')) {
    eval('sel_' + form + ' = 1');
    sel=1;
  } else {
    eval('sel_' + form + ' = 0');
    sel=0;
  }

  nb = document.forms[form].elements.length;
  for (var i=0;i<nb;i++)
  {
    var e = document.forms[form].elements[i];
    e.checked = sel;
  }
}

function insSelcat(catlevel,catPosition,catId,divId,op1,op2,percorso)
{
  var fine;
  var c=0;
  while(fine!='yes')
  {
    if(document.getElementById(catlevel+'cat'+c))
      document.getElementById(catlevel+'cat'+c).style.backgroundColor='';
    else
      fine='yes';

    ++c;
  }
  document.getElementById('insertCatBox').style.display='none';
  document.getElementById(catlevel+'catNEW').style.backgroundColor='#ccc';

  document.getElementById(catlevel+'cat'+catPosition).style.backgroundColor='#9dd2a5';

  if(catlevel==1)
  {
    selectedCats[0]=catlevel+'cat'+catPosition;
    selectedCats[1]='';
    selectedCats[2]='';
    rsconnect(divId,'POST','ajax_control.php','op1='+op1+'&catLevel='+catlevel+'&aggiornaCat='+catId+'&divId='+divId,'')
    document.getElementById('thirdcat').innerHTML='';
    document.getElementById('myop1').value=op1;
    document.getElementById('myop2').value='';
    document.getElementById('namesubcat').innerHTML=op1;
    document.getElementById('myHiddenCat').value=catId;
    document.getElementById('goinsertcat1').style.visibility='visible';
    document.getElementById('goinsertcat2').style.visibility='hidden';
  }

  if(catlevel==2)
  {

    document.getElementById(selectedCats[0]).style.backgroundColor='#cccccc';
    selectedCats[1]=catlevel+'cat'+catPosition;
    selectedCats[2]='';
    document.getElementById('myop1').value=op1;
    document.getElementById('myop2').value=op2;
    rsconnect(divId,'POST','ajax_control.php','op1='+op1+'&op2='+op2+'&catLevel='+catlevel+'&aggiornaCat='+catId+'&divId='+divId,'')
    document.getElementById('namesubcat').innerHTML=op1 + '/' + op2;
    document.getElementById('myHiddenCat').value=catId;
    document.getElementById('goinsertcat2').style.visibility='visible';
    document.getElementById('goinsertcat1').style.visibility='hidden';
  }

  if(catlevel==3)
  {
    document.getElementById('myop1').value=op1;
    document.getElementById('myop2').value=op2;
    document.getElementById(selectedCats[1]).style.backgroundColor='#cccccc';
    selectedCats[2]=catlevel+'cat'+catPosition;
    //document.getElementById('namesubcat').innerHTML=percorso;
    document.getElementById('myHiddenCat').value=catId;
		document.getElementById('goinsertcat2').style.visibility='visible';
		document.getElementById('goinsertcat1').style.visibility='hidden';
  }

  document.getElementById('inputnsubcat').value='';
  document.getElementById('nsubcatDiv').style.display='block';
  document.getElementById('nsubcatDiv2').style.display='block';
  return false;
}

function insNewcat(catlevel,nameCat)
{
  var fine;
  var c=0;
  while(fine!='yes')
  {
    if(document.getElementById(catlevel+'cat'+c))
      document.getElementById(catlevel+'cat'+c).style.backgroundColor='';
    else
      fine='yes';

    ++c;
  }
  document.getElementById('insertCatBox').style.display='none';

  document.getElementById(catlevel+'catNEW').style.backgroundColor='#9dd2a5';

  if(catlevel==1)
  {
    selectedCats[0]='';
    selectedCats[1]='';
    selectedCats[2]='';
    document.getElementById('thirdcat').innerHTML='';
    document.getElementById('myop1').value='';
    document.getElementById('myop2').value='';
    document.getElementById('namesubcat').innerHTML='';
    document.getElementById('myHiddenCat').value='';
    document.getElementById('goinsertcat1').style.visibility='visible';
    document.getElementById('goinsertcat2').style.visibility='hidden';
  }

  if(catlevel==2)
  {

    document.getElementById(selectedCats[0]).style.backgroundColor='#cccccc';
    selectedCats[1]='';
    selectedCats[2]='';
    document.getElementById('myop1').value='';
    document.getElementById('myop2').value='';
    document.getElementById('namesubcat').innerHTML='';
    document.getElementById('myHiddenCat').value='';
    document.getElementById('goinsertcat2').style.visibility='visible';
    document.getElementById('goinsertcat1').style.visibility='hidden';
  }

  if(catlevel==3)
  {
    document.getElementById('myop1').value=op1;
    document.getElementById('myop2').value=op2;
    document.getElementById(selectedCats[1]).style.backgroundColor='#cccccc';
    selectedCats[2]='';
    //document.getElementById('namesubcat').innerHTML=percorso;
    document.getElementById('myHiddenCat').value='';
	document.getElementById('goinsertcat2').style.visibility='visible';
	document.getElementById('goinsertcat1').style.visibility='hidden';
  }

  document.getElementById('inputnsubcat').value='';
  document.getElementById('nsubcatDiv').style.display='block';
  document.getElementById('nsubcatDiv2').style.display='block';
  return false;
}


function addNewCat ( catLevel, catPadre, nomecampo, divPadre, divId )
{
	caspita=eval('document.logregpost.'+nomecampo+'.value');
	if(caspita=='')
		return false;

	div_padre=divPadre;
	liv_padre=catLevel-1;

    rsconnect(divId,'POST','ajax_control.php','op1=newCat&catLevel='+catLevel+'&catPadre='+catPadre+'&catName='+escape(caspita),'');
}

function showCats(idDiv,myCat,level)
{
  if(typeof(cats)=='undefined')
  return false;
  var myHtml='';
  var mycats=cats[level][myCat];

  if(typeof(myTimeout)!='undefined')
  {
    clearTimeout(myTimeout);
    delete myTimeout;
  }

  for(i in mycats)
  {
    if(myHtml!='')
      myHtml+=' | ';

    myHtml+='<span nowrap><a href="index.php?op1='+myCat+'&op2='+mycats[i]+'">'+mycats[i]+'</a></span>';
  }

  if(myHtml!='')
  {
    document.getElementById(idDiv).innerHTML=myHtml;
    document.getElementById(idDiv).style.display='block';
  }
  else
  {
    document.getElementById(idDiv).innerHTML='';
    document.getElementById(idDiv).style.display='none';
  }
}

function removeCats(idDiv,idCat)
{
  if(typeof(oldDivCats)=='undefined')
  return false;
  if(typeof(myTimeout)=='undefined')
    myTimeout=setTimeout('removeCats(\''+idDiv+'\',\''+idCat+'\')',1500);
  else
  {
    delete myTimeout;
    if(oldDivCats=='')
    {
      document.getElementById(idDiv).innerHTML='';
      document.getElementById(idDiv).style.display='none';
    }
    else
    {
      document.getElementById(idDiv).innerHTML=oldDivCats;
      document.getElementById(idDiv).style.display='block';
    }
  }
}

function freezeCats()
{
  if(typeof(myTimeout)!='undefined')
  {
    clearTimeout(myTimeout);
    delete myTimeout;
  }
}

function rsconnect(myId,tipo,myUrl,myVars,myReferer)
{
  rsconnection=false;
  try
  {
    rsconnection=new XMLHttpRequest();	//mozilla, firefox, safari, netscape
  }
  catch(e)			//microsoft recente
  {
    try
    {
      rsconnection=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)			//microsoft vecchio
    {
      try
      {
	rsconnection=new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch(e)			//altrimenti
      {
	rsconnection=false;
      }
    }
  }

  ajaxContainer=myId;
  if(!rsconnection)
    return;

  rsconnection.onreadystatechange=rscontrol;
  rsconnection.open(tipo, myUrl, true);
  rsconnection.setRequestHeader('Content-Type','application/x-www-form-urlencoded;');

  //No necesario, pero de otro modo adios al referer....
  if(myReferer!='')
    rsconnection.setRequestHeader("Referer",myReferer);
  //null en el caso de peticion GET
  if(tipo == 'POST')
    rsconnection.send(myVars);
  else
    rsconnection.send(null);
}

function rscontrol ()
{
  if(rsconnection.readyState!=4) {
	  if(ajaxContainer.length)
		document.getElementById (ajaxContainer).innerHTML='';
  }
  else
  {
    if(rsconnection.status!=200)
	  if(ajaxContainer.length)
		 document.getElementById(ajaxContainer).innerHTML='';
    else
	  if(ajaxContainer.length)
	     document.getElementById(ajaxContainer).innerHTML='';

    var myHtml = rsconnection.responseText;

	////alert('HTML'+myHtml+" DP "+div_padre);

	myPezzi = myHtml.split("");
	  if(ajaxContainer.length)
	document.getElementById(ajaxContainer).innerHTML = myPezzi[0];
	if(myPezzi[1].length)
		document.getElementById(div_padre).innerHTML = myPezzi[1];
	if(myPezzi[2].length) {
		document.logregpost.id_cat.value = myPezzi[2];
		////alert('categoria '+document.logregpost.id_cat.value);
	}

	if(myPezzi[3].length) {
		if(liv_padre==0)
		 selectedCats[0]=myPezzi[3];
		else if(liv_padre==1)
		 selectedCats[1]=myPezzi[3];
		else if(liv_padre==2)
		 selectedCats[2]=myPezzi[3];
	}
  }
}

function pairControl(myid,id1,id2,nomecampo,caso1,caso2)
{

  document.getElementById(id1+'check').innerHTML='';
  document.getElementById(id2+'check').innerHTML='';

//   if(caso1!='')
//   {
//     if(myid==id1)
//     {
//       if(document.getElementById(id1).value.length < caso1)
// 	document.getElementById (id1+'check').innerHTML='Lunghezza minima '+caso1+' caratteri';
//       else if(document.getElementById (id1).value.length > caso2)
//         document.getElementById(id1+'check').innerHTML='Lunghezza massima '+caso2+' caratteri';
//       else
// 	document.getElementById(id1+'check').innerHTML='';
//     }
//   }

  if(nomecampo=='Email')
  {
    filtro=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    if(!filtro.test(document.getElementById(id1).value) && document.getElementById(id1).value!= '')
      document.getElementById(id1+'check').innerHTML='KO'; //nomecampo+' errata'
//     else
//       document.getElementById(id1+'check').innerHTML='';
  }

  if(myid==id2)
  {
    if(document.getElementById(id1).value!=document.getElementById(id2).value && document.getElementById(id2).value!='')
      document.getElementById(id2+'check').innerHTML='KO <>'; //nomecampo+' non coincidenti'
//     else
//       document.getElementById(id2+'check').innerHTML='';

   if(!filtro.test(document.getElementById(id2).value) && document.getElementById(id2).value!= '')
      document.getElementById(id2+'check').innerHTML='KO'; //nomecampo+' errata'
//     else
//       document.getElementById(id2+'check').innerHTML='';
  }

  if (nomecampo=='Password')
  {
	if(document.getElementById(id1).value.length < caso1)
 	  document.getElementById (id1+'check').innerHTML='KO';
        else if(document.getElementById (id1).value.length > caso2)
          document.getElementById(id1+'check').innerHTML='KO';
  }

}

function checkmail(div,email)
{
    filtro=/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;

    if(!filtro.test(email) && email!= '')
      document.getElementById(div).innerHTML='KO'; //Email errata
    else
      document.getElementById(div).innerHTML='';
}

function clearfield(field)
{
  field.value = '';
  return true;
}

function update_child(where,idPadre) {
	// create new script element and set its relative URL (including ID argument)
	script = document.createElement( 'script' );
	script.src = 'http://bardosheeboo.caroo.it/external_sheeboo.php?where=' + where + '&idPadre=' + idPadre;
	// attach (load) script element to document head
	document.getElementsByTagName( 'head' )[0].appendChild( script );
}

function proponi(where, openclose) {
//alert(where);
	if (openclose == 1)
	{
		document.getElementById('1catNEW'+where).style.display='none';
		document.getElementById('newCatIns'+where).style.display='list-item';
		if (where == 0 )
		{
			document.getElementById('mysecondcat').style.display = 'none';
			document.getElementById('mythirdcat').style.display = 'none';
		}
		if (where == 1 )
		{
			document.getElementById('mythirdcat').style.display = 'none';
		}
	}
	else
	{
		document.getElementById('1catNEW'+where).style.display='list-item';
		document.getElementById('newCatIns'+where).style.display='none';
	}

}

function saveCats(){// Salvo le eventuali categorie scritte ma non inviate
	var propCat0 = document.getElementById('propCat0');
	var propCat1 = document.getElementById('propCat1');
	var propCat2 = document.getElementById('propCat2');
	if ((propCat0 != undefined) && (propCat0.value != ''))
	{
		document.getElementById('hiddenCat1').value = propCat0.value;
	}

	if ((propCat1 != undefined) && (propCat1.value != ''))
	{
		document.getElementById('hiddenCat2').value = propCat1.value;
	}

	if ((propCat2 != undefined) && (propCat2.value != ''))
	{
		document.getElementById('hiddenCat3').value = propCat2.value;
	}
}

	function nascondiPreview(){
		document.getElementById('goPreview').style.display = 'block';
		document.getElementById('div_preview').style.display = 'none';
	}
	jsloaded='yes';


	function toggleBox(szDivID, iState) // 1 visible, 0 hidden
	{
		//alert("toggleBox - "+ szDivID+" -- "+  iState   );
		if(document.layers)	   //NN4
		{
//alert("toggleBox2 - "+ szDivID+" -- "+  iState   );
		obj.style.display = iState ? "none" : "block";
		}
		else if(document.getElementById)	  //gecko(NN6) + IE 5+
		{
//alert("toggleBox3 - "+ szDivID+" -- "+  iState   );
			var obj = document.getElementById(szDivID);
			/*obj.innerHTML = "pippone";*/
			//alert(obj);
			obj.style.display = iState ? "none" : "block";
		}
		else if(document.all)	// IE 4
		{
//alert("toggleBox4 - "+ szDivID+" -- "+  iState   );
			obj.style.display = iState ? "none" : "block";
		}
	}


	/**
	* Include un file JS all'interno della sezione <head>
	*/
	function includeJsHead (fileJS) {
		if (typeof(fileJS) == 'string') {
			var srcFileJS = fileJS.indexOf('http://') == 0 ? fileJS : '/includes/' + fileJS;
			//srcFileJS = '/includes/'+fileJS;
			var scriptJS = document.createElement('script');
			scriptJS.setAttribute('src', srcFileJS);
			scriptJS.setAttribute('type', 'text/javascript');
			document.getElementsByTagName('head')[0].appendChild(scriptJS);
			return true;
		} else {
				//alert('il parametro passato alla funzione include non �una stringa');
				return false;
		  }
	}
	/**
	* Alias di includeJsHead
	*/
	function include(fileJS) {
		return includeJsHead(fileJs);
	}

	/**
	@public
	@brief Include nella pagina un php che genera un js e lo appende nel tag <head>
	@param url Percorso del file da includere

	Alias di include()
	*/
	function callPhpScript(url) {

		include(url);
	}

function Len(StrToLen)
{
    return StrToLen.length;
}

/**
* @brief Sblocca il form controllando via Ajax che il codice � corretto.
* 'bottone_submit','captcha','input type'
* @param string il div da mostrare
* @param il div da nascondere
* @param il codice inserito dall'utente
*/
var divMostrare;
var divNascondere;
//var codice;

var sbloccaCaptchaVar;
var sbloccaCaptchaFunctionToCall;
function sbloccaCaptcha(_divMostrare,_divNascondere,_codice,funzione)
{

	if (SHEEBOO_scambio['bloccaInvia'] === undefined && SHEEBOO_scambio['bloccaInvia'] == null) {
		SHEEBOO_scambio['bloccaInvia'] = true;
	} else  {
	  		if (SHEEBOO_scambio['bloccaInvia'] == true) return true;
	  		SHEEBOO_scambio['bloccaInvia'] = true;
	  }
	SHEEBOO_scambio['blockInvia'] = true;
	sbloccaCaptchaVar  = false;
	divMostrare = _divMostrare;
	divNascondere = _divNascondere;
	sbloccaCaptchaFunctionToCall = funzione;
	var page = 'admin/captcha/check.php';
	var pars = 'code='+$(_codice).value;
	SHEEBOO_ajax(page,pars,'resSbloccaCaptcha');
}


function resSbloccaCaptcha(res)
{

	SHEEBOO_scambio['bloccaInvia'] = false;
	if (res.responseText == 0 || res.responseText == 'false') {
		$(divMostrare).style.display='block';
		$(divNascondere).style.display='none';
		sbloccaCaptchaVar = true;
		if (sbloccaCaptchaFunctionToCall != 'undefined' && sbloccaCaptchaFunctionToCall != '') {
			eval(sbloccaCaptchaFunctionToCall);
		}
	} else {
			var dati = {msg : 'Codice di controllo non corretto.', nrMsg: SHEEBOO_scambio['nrMsg'],colore:'red'};
			SHEEBOO_mostraMsgBox(dati);
			sbloccaCaptchaVar=false;
	}
}

/**
* Mi restituisce il contenuto delle sessioni sul server.
* E' solo una funzione di test/debug. Non serve all'interno di sheeboo.
*/
function _tmp1()
 {
 var page = 'tmp/session.php';
			var pars = '';
		SHEEBOO_ajax(page,pars,'res_tmp1');
 }

function res_tmp1(res) {
 	alert(res.responseText);
 }

/**
* @brief mostra il div passato
* @brief setta nomeDiv con il div mostrato.
*/
var nomeDiv = "";
function mostraDiv(div) {
	//alert("mostraDiv("+div+")");
	if($(SHEEBOO_scambio['nomediv'])!=undefined && $(SHEEBOO_scambio['nomediv'])!=null) $(SHEEBOO_scambio['nomediv']).hide();
	$(div).style.display = "block";
	//Element.toggle(div);
	//alert("esco da mostraDiv: "+div);
	SHEEBOO_scambio['nomediv'] = div;
}

function SHEEBOO_mostraDivHelp(div) {
	//debugger;
	if (SHEEBOO_scambio['divHelp'] !== undefined && SHEEBOO_scambio['divHelp'] != null) {
		$(SHEEBOO_scambio['divHelp']).hide();
		Event.stopObserving(document,'click',function(e) {if (Event.element(e).nodeName == "IMG") return false;SHEEBOO_nascondiDivHelp(div);});
	}

	SHEEBOO_scambio['divHelp'] = div;
	$(div).setStyle({display:'block'});
	SHEEBOO_scambio['primoClick'] = 0;
	Event.observe(document,'click',function(e) {if (Event.element(e).nodeName == "IMG") return false;SHEEBOO_nascondiDivHelp(div);});
}

function SHEEBOO_nascondiDivHelp(div) {
//	debugger;
	Event.stopObserving(document,'click',function(e) {if (Event.element(e).nodeName == "IMG") return false;SHEEBOO_nascondiDivHelp(div);});
	SHEEBOO_scambio['divHelp'] = null;
	$(div).hide();
}

function nascondiDiv(div) {
	$(div).style.display = "none";
	//nomeDiv = "";
	//alert("Esco da nascondiDiv");
}
function SHEEBOO_mostraDivRosso(div) {
	$('box-rosso-sheeboo').hide();
	$(div).setStyle({display:'block'});
}
function SHEEBOO_mostraDivRosso2(div) {
	$('box-rosso-login').hide();
	$(div).setStyle({display:'block'});
}
function SHEEBOO_mostraDivLogon(div) {
	//alert(div);
	$(div).style.display = "block";
	$('emaillogin').focus();
	//Effect.SlideDown('logon-new', {duration:2});
	//setTimeout("SHEEBOO_nascondiDivLogon('"+div+"')",30000);
}


function SHEEBOO_nascondiDivLogon(div) {
	$(div).style.display = "none";
	//new Effect.SlideUp(div);
}

function SHEEBOO_nascondiDiv(div) {
	$(div).setStyle({display:'none'});
    if ($('colonna-dx')) $('colonna-dx').setOpacity(1);
}
var props = new Array(
        'clientHeight',
        'clientWidth',
        'scrollHeight',
        'scrollWidth',
        'scrollLeft',
        'scrollTop',
        'offsetHeight',
        'offsetWidth'
);
function createTable()
{
		//alert("dentro createTable");
        var printstring1 = '';
        var printstring2 = '';
        for (var i=0; i<props.length;i++)
        {
                printstring1 += props[i] + ' = ' + document.body[props[i]] + '\n';
                printstring2 += props[i] + ' = ' + document.documentElement[props[i]] + '\n';
        }
        //document.getElementById('writeroot').innerHTML = printstring;
        alert("document.body: \n\n"+printstring1+"\n\ndocument.documentElement:\n\n"+printstring2);
}

/**
* Questa funzione gestisce gli errori.
* fa una chiamata AJAX per recuperare il messaggio da visualizzare.
* In questo modo posso gestire lingue e template
* FORSE NON SERVE A NULLA
*/
function mostraErrore() {
}

/**
* Fa l'URLEncode di un url. Ma puo' essere usato su un po' tutto.
*/
function URLEncode(url)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = url;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '"
                        + ch
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function ajaxsheeboo(page,pars,zboncomplete) {
    // handling of remote ajax proxy for use in sheeboo integration enviroments
    if (typeof(use_ajax_proxy) != "undefined" && true == use_ajax_proxy) {
        var url = urlsite + 'sheeboo/ajax-remoto.php';
        // escaping parameters to pass to page
        pars = '?pars='+ escape(pars) + '&page=' + escape(page);
    } else {
        var url = urlsite+page;
    }
//    alert(url+pars);
			var myAjax = new Ajax.Request( url, { 	method: 'GET',
							parameters: pars,
							onComplete: function (transport) { //alert('completato: ' + url);
																check = 'if (window.'+zboncomplete+') { var i = 0; } else { alert("la funzione '+zboncomplete+' non esiste!!!!");  var i = -1;} ';
																//if (!eval('window.'+zbonclompete)) {
																//	alert("la funzione '+zboncomplete+' non eisste!!!!");
																//	return false;
																//}
																//alert(check);
																eval (check);
																if (i == -1) return false;
																//alert("sto per eseguire: "+zboncomplete);
																f = zboncomplete+'(transport)';
																//alert(f);
																eval(f);
										},
							onFailure: SHEEBOO_ajaxReportError//,
							//onLoading: SHEEBOO_ajaxMostraGif,
							//onLoaded: SHEEBOO_ajaxNascondiGif
			});

}

function zbonclomplete(r) {
alert("dentro zboncomplete");
}

function SHEEBOO_ajaxReportError(request)
        {
                alert('Sorry. There was an error.');
                alert(request);
        }

function SHEEBOO_ajax(page,pars,oncomplete) {
	return ajaxsheeboo(page,pars,oncomplete);
}

function SHEEBOO_ajaxMostraGif(res) {

	var l = (document.body.scrollWidth/2) + "px";
    //var h = (document.body.scrollHeight/2) + "px";

	var t = document.body.scrollTop + document.documentElement.scrollTop + 50;
    t += "px";
    var z = 1000;
	$('spinner').setStyle({top:t, left:l, position:'absolute',zIndex:z, display:'block'})
}

function SHEEBOO_ajaxNascondiGif(res) {
	$('spinner').hide();
}

function SHEEBOO_returnFalse() {
	return false;
}

function SHEEBOO_arrayToJSON(arr) {

}

function isAlien(a) {
   return isObject(a) && typeof a.constructor != 'function';
}

function isArray(v) {
     return v && typeof v === 'object' && typeof v.length === 'number' &&
	          !(v.propertyIsEnumerable('length'));
}

function isBoolean(a) {
    return typeof a == 'boolean';
}

function isEmpty(o) {
    var i, v;
    if (isObject(o)) {
        for (i in o) {
            v = o[i];
            if (isUndefined(v) && isFunction(v)) {
                return false;
            }
        }
    }
    return true;
}

function isFunction(a) {
    return typeof a == 'function';
}

function isNull(a) {
    return a === null;
}

function isNumber(a) {
    return typeof a == 'number' && isFinite(a);
}

function isObject(a) {
    return (a && typeof a == 'object') || isFunction(a);
}

function isString(a) {
    return typeof a == 'string';
}

function isUndefined(a) {
    return typeof a == 'undefined';
}

function SHEEBOO_debug(msg) {
	if (SHEEBOO_scambio['debug'] == true) $('debug').innerHTML += msg+'<br>\n';
}

function SHEEBOO_doblur(data) {
		//alert(div);
		//debugger;
		SHEEBOO_scambio['doblur'] = 1;
		if ($('SHEEBOO_blur') === undefined || $('SHEEBOO_blur') == null) {
			createDivChild('SHEEBOO_blur','contenuto');
        } else {
            $('SHEEBOO_blur').setStyle({display:'block',zIndex:1500});
        }
		//$('SHEEBOO_blur').innerHTML = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
		Event.observe(document,'mousewheel',SHEEBOO_resizeBackground2);
		Event.observe(document, "DOMMouseScroll", SHEEBOO_resizeBackground2); // Firefox
		//if ((data !== undefinded && data != null ) && (data.noesc === undefined || data.noesc == null || data.noesc == false))	 {
			//Event.observe('SHEEBOO_blur','click',function (e) { var ret = SHEEBOO_dounblur(e); if (ret == true && (data.funzione !== undefined && data.funzione != null)) eval(data.funzione);});
			//Event.observe(document, 'keypress', function (e) { var ret = SHEEBOO_checkESC(e); if (ret == true && (data.funzione !== undefined && data.funzione != null)) eval(data.funzione);});
		//}

        if ($('SHEEBOO_blur') !== undefined && $('SHEEBOO_blur') != null) {
            Event.observe('SHEEBOO_blur','click',SHEEBOO_dounblur);
            SHEEBOO_resizeBackground2();
        }
		Event.observe(document, 'keypress', SHEEBOO_checkESC);
}

function SHEEBOO_dounblur() {
		if (SHEEBOO_scambio['doblur'] === undefined || SHEEBOO_scambio['doblur'] == 0) return true;
		SHEEBOO_scambio['doblur'] = 0;
		Event.stopObserving(document,'mousewheel',SHEEBOO_resizeBackground2);
		Event.stopObserving(document, "DOMMouseScroll", SHEEBOO_resizeBackground2); // Firefox
		Event.stopObserving(document, 'keypress', SHEEBOO_checkESC);
        if ($('SHEEBOO_blur') !== undefined && $('SHEEBOO_blur') != null) {
            Event.stopObserving('SHEEBOO_blur','click',SHEEBOO_dounblur2);
            $('SHEEBOO_blur').hide();
        }
      	SHEEBOO_checkESC();
}

function createTable()
{
	var printstring1 = '';
	var printstring2 = '';
	for (var i=0; i<props.length;i++)
	{
		printstring1 += props[i] + ' = ' + document.body[props[i]] + '\n';
		printstring2 += props[i] + ' = ' + document.documentElement[props[i]] + '\n';
	}

	//document.getElementById('writeroot').innerHTML = printstring;
	alert("document.body: \n\n"+printstring1+"\n\ndocument.documentElement:\n\n"+printstring2);
}

//Event.observe('wheel
Object.extend(Event, {
        wheel:function (event){
                var delta = 0;
                if (!event) event = window.event;
                if (event.wheelDelta) {
                        delta = event.wheelDelta/120;
                        if (window.opera) delta = -delta;
                } else if (event.detail) { delta = -event.detail/3;     }
                return Math.round(delta); //Safari Round
        }
});

function SHEEBOO_resizeBackground(div) {
	el = document.getElementById(div);
	/*var parent = false;
	while (parent != true)
	{
		if (el.parentNode != null) el = el.parentNode;
		else parent = true;
	}
	alert("uscito");
	*/
	//createTable();
//	alert(al);
//	alert(al.style.offsetHeight);
	//el.style.width = Math.max(Math.max((window.innerWidth) ? (window.innerWidth) : 0,document.documentElement.clientWidth),document.body.clientWidth);
	//el.style.height = Math.max(Math.max((window.outerHeight) ? (window.outerHeight) : 0,document.documentElement.clientHeight),document.body.clientHeight);
	el.style.height = document.documentElement.scrollHeight+document.documentElement.scrollTop;
	var h = document.body.scrollHeight+(document.body.scrollTop*2);
    if ($('SHEEBOO_blur') !== undefined && $('SHEEBOO_blur') != null) {
        $('SHEEBOO_blur').setStyle({height: h});
    }
	el.style.width = document.documentElement.offsetWidth;
	//document.getElementById('debug').innerHTML='w x h: '+el.style.width+' x '+el.style.height+'<br>window.inner: '+window.innerWidth+' x '+window.innerHeight+'<br>document.body: '+document.body.clientWidth+' x '+document.body.clientHeight+'<br>documentElement: '+document.documentElement.clientWidth+' x '+document.documentElement.clientHeight;
	//dump(el.style);
}

function SHEEBOO_resizeBackground2(){
	//createTable();
	var h = document.body.scrollHeight;
	h = h + "px";
	var w = document.body.scrollWidth;
	w = w + "px";
	if ($('SHEEBOO_blur') !== undefined && $('SHEEBOO_blur') != null) {
		$('SHEEBOO_blur').setStyle({height: h,width:w});
	}
}
function createDivChild(divChild,divPadre) {
	var newdiv=document.createElement("div");
	newdiv.id = divChild;
    var tmp = document.getElementById(divPadre);
    if (tmp != null) document.getElementById(divPadre).appendChild(newdiv);
}

function SHEEBOO_removeDivChild(divChild) {
	document.removeChild(divChild);
}

SHEEBOO_scambio['nrMsg'] = 0;
function SHEEBOO_mostraMsg(msg,timeout) {
	if (SHEEBOO_scambio['nrMsg'] == 0)  {
		createDivChild('div_msg','SHEEBOO');
	}
	var top = document.body['scrollTop']+20;
	top += 'px';
	$('div_msg').setStyle({top:top});
	SHEEBOO_scambio['nrMsg']++;
	createDivChild('div_msg'+SHEEBOO_scambio['nrMsg'],'div_msg');
	$('div_msg'+SHEEBOO_scambio['nrMsg']).setStyle({display : 'block', backgroundColor: 'red'});
	$('div_msg'+SHEEBOO_scambio['nrMsg']).update(msg);
	if (timeout == undefined || timeout == true) {/*alert('setto timeout tempo');*/ setTimeout("SHEEBOO_nascondiMsg("+SHEEBOO_scambio['nrMsg']+")",1500);}
	return SHEEBOO_scambio['nrMsg'];
}

/**
* mostra un div di messaggio per l'utente
* @param array i dati che servono
* i dati devono essere almeno 'msg'.
* In aggiunta si puo' utilizzare 'timeout' (true/false) per indicare se si vuole far scomparire il messaggio dopo 1500 ms.
* In aggiunta si puo' utilizzare 'colore' per settare il colore di sfondo del div.
*	top per il top
* 	left
* 	nrMsg per indicare quale dive gia' presente fare l'update senza crearne uno nuovo.
*/
function SHEEBOO_mostraMsg2(dati) {
//alert(dati['top']+" -- "+dati['msg']);
	if (dati['time'] == undefined) {var time = 1500;}
		else { var time = dati['time'];}
	if (dati['nrMsg'] != undefined && dati['nrMsg'] > 0) {
		var nrMsg = dati['nrMsg'];
		if (dati['colore'] != undefined) {
			//Devo cambiare il colore di sfondo
			$('div_msg'+dati['nrMsg']).setStyle({backgroundColor:dati['colore']});
		}
		$('div_msg'+dati['nrMsg']).innerHTML += dati['msg'];
		if (dati['timeout'] == undefined || dati['timeout'] == true) {
			setTimeout("SHEEBOO_nascondiMsg("+nrMsg+")",time);
		}
		return SHEEBOO_scambio['nrMsg'];
	}
	createDivChild('div_msg','colonna-centrale');
	//if ($('div_msg') == undefined) createDivChild('div_msg','colonna-sx');
	if (dati['colore'] == undefined) dati['colore'] = 'red';
	//if (dati['top'] == undefined) { var top = document.documentElement.scrollTop + document.body['scrollTop']+20; top += 'px';
	//}
	//	else { var top  = parseInt(dati['top'])+20; top +="px"; }
	var top = document.documentElement.scrollTop + document.body['scrollTop']+20; top += 'px';
	if (dati['left'] == undefined) {var left = "100px"}
		else { var left = parseInt(dati['left']); left += 'px';}
	if (dati['z'] == undefined) {var z = 998} else { var z = parseInt(dati['z']);}
	//alert("top: "+top+" -- left: "+left+" -- z: "+z);
	$('div_msg').setStyle({top:top,zIndex:z,left:left,position: 'absolute'});
	SHEEBOO_scambio['nrMsg']++;
	createDivChild('div_msg'+SHEEBOO_scambio['nrMsg'],'div_msg');
	$('div_msg'+SHEEBOO_scambio['nrMsg']).setStyle({display : 'block', backgroundColor: dati['colore']});
	$('div_msg'+SHEEBOO_scambio['nrMsg']).update(dati['msg']);
	var quale = SHEEBOO_scambio['nrMsg'];
	if (dati['timeout'] == undefined || dati['timeout'] == true) {
			setTimeout("SHEEBOO_nascondiMsg("+quale+")",time);
	}
	if (dati['funzione'] != undefined) {
		SHEEBOO_scambio['funzione_'+SHEEBOO_scambio['nrMsg']] = dati['funzione'];
	}
	return SHEEBOO_scambio['nrMsg'];
}
/*function SHEEBOO_mostraMsg2(msg,timeout) {
	if (SHEEBOO_scambio['nrMsg'] == 0)  {
    	createDivChild('div_msg','listaCategorie');
    	$('div_msg').setStyle({display : 'block'});
	}
	SHEEBOO_scambio['nrMsg']++;

	if (SHEEBOO_scambio['nrMsg'] == 11) SHEEBOO_scambio['nrMsg'] = 1;
	if ($('div_msg'+SHEEBOO_scambio['nrMsg']) == undefined) {
		createDivChild('div_msg'+SHEEBOO_scambio['nrMsg'],'div_msg');
	}

	$('div_msg'+SHEEBOO_scambio['nrMsg']).update(msg);
	$('div_msg'+SHEEBOO_scambio['nrMsg']).setStyle({display : 'block'});
	if (timeout == undefined || timeout == true) setTimeout("SHEEBOO_amministrazioneNascondiMsg("+SHEEBOO_scambio['nrMsg']+")",1500);
	return SHEEBOO_scambio['nrMsg'];
}
*/
function SHEEBOO_nascondiMsg(nr,ok) {
	if (nr == undefined) return false;
	if (ok == undefined) { setTimeout('SHEEBOO_nascondiMsg('+nr+',1)',500); return false;}
	$('div_msg'+nr).setStyle({display: 'none'});
	if (SHEEBOO_scambio['funzione_'+nr] != undefined || SHEEBOO_scambio['funzione_'+nr] != '') {
		var funzione = SHEEBOO_scambio['funzione_'+nr];
		SHEEBOO_scambio['funzione_'+nr] = '';
		eval(funzione);
	}
}

function SHEEBOO_genToggle(div) {
	var i;

	i = Element.getStyle(div,'display');
	if (i == null || i == 'block') {
									$(div).setStyle({display: 'none'});
	} else {
			$(div).setStyle({display: 'block'});


	  }

}

function createDivMsg() {
	createDivChild('div_msg','SHEEBOO');
}

/**
* Per effettuare il login da parte dell'utente quando si � all'interno di una pagina
* si � deciso di scurire la pagina e far apparire un div di richiesta login e password.
* @param string funzioneDaRichiamare � la funzione da richiamare quando il login va a buon fine.
*/
function SHEEBOO_createSetBlurLogin() {
	//alert($('SHEEBOO_blur'));
	if ($('SHEEBOO_blurLogin') === undefined || $('SHEEBOO_blurLogin') == null) {
		createDivChild('SHEEBOO_blurLogin','SHEEBOO');
		if ($('SHEEBOO_blur') === undefined || $('SHEEBOO_blur') == null) {
            var z = 10000;
		} else {
            var z = $('SHEEBOO_blur').getStyle('zIndex')+1;
        }
		var top = document.body['scrollTop']+50;
		top += 'px';
		var width = '1000px';
		var height = '700px';
		var left = '100px';
		$('SHEEBOO_blurLogin').setStyle({display: 'none', padding: '20px 20px 20px 20px',zIndex: z, backgroundColor:'white',top:top,width: width,height:height,position:'absolute',left:left,filter:'alpha(opacity=100)', MozOpacity: 100, opacity: 100});
	}
}
function SHEEBOO_blurLogin(funzioneDaRichiamare) {
	SHEEBOO_loadJS('nuovoUtente.js');
	SHEEBOO_loadJS('addOpinione.js');
	SHEEBOO_scambio['funzioneDaRichiamare'] = funzioneDaRichiamare;
	if ($('SHEEBOO_blur') !== undefined && $('SHEEBOO_blur') != null) {
        createDivChild('SHEEBOO_blur','SHEEBOO');
    }
	//SHEEBOO_doblur('SHEEBOO_blur');
	SHEEBOO_resizeBackground2();

    SHEEBOO_doblur('SHEEBOO_blur');

	if ($('SHEEBOO_blurLogin') == undefined) SHEEBOO_createSetBlurLogin();
/*	var z = $('SHEEBOO_blur').getStyle('zIndex')+1;
	var top = document.body['scrollTop']+50;
	top += 'px';
	var width = '1000px';
	var height = '700px';
	var left = '100px';
	$('SHEEBOO_blurLogin').setStyle({display: 'none', padding: '20px 20px 20px 20px',zIndex: z, backgroundColor:'white',top:top,width: width,height:height,position:'absolute',left:left,filter:'alpha(opacity=100)', MozOpacity: 100, opacity: 100});
*/
	//$('div_msg').setStyle({});

/*	$('SHEEBOO_blur').setStyle({display:'block'});
	$('SHEEBOO_blur').update('');
	Event.observe(document,'scroll',SHEEBOO_resizeBackground2);
	Event.observe(document,'mousewheel',SHEEBOO_resizeBackground2);
	Event.observe(document, "DOMMouseScroll", SHEEBOO_resizeBackground2); // Firefox
	Event.observe('SHEEBOO_blur','click',SHEEBOO_dounblur2);
	Event.observe(document, 'keypress', SHEEBOO_checkESC);
*/
	page = 'admin/getFormLogin.php';
	pars = '';
	SHEEBOO_ajax(page,pars,'SHEEBOO_blurLoginAjax');
	if (SHEEBOO_scambio['checkESC'] === undefined) SHEEBOO_scambio['checkESC'] = new Array();
	SHEEBOO_scambio['checkESC'][0] = 'SHEEBOO_blurLogin';

}

function SHEEBOO_checkESC(event) {
//alert(event.keyCode+"--"+Event.KEY_ESC);

	if (SHEEBOO_scambio['checkESC'] === undefined) var n = 0;
	else var n = SHEEBOO_scambio['checkESC'].size();
	if (event !== undefined) {
		if (event.keyCode == Event.KEY_ESC)  {
			SHEEBOO_dounblur(event);
			//dump(SHEEBOO_scambio['checkESC']);

			for (var i = 0;i<n;i++) {
				var div = SHEEBOO_scambio['checkESC'][i];
				if ($(div) !== undefined && $(div) != null)  $(div).setStyle({display:'none'});
			}
			SHEEBOO_scambio['checkESC'].clear();
			return true;
		} else return false;

	} else { for (var i = 0;i<n;i++) {
				var div = SHEEBOO_scambio['checkESC'][i];
				//alert(div)
				if ($(div) !== undefined && $(div) != null) $(div).setStyle({display:'none'});
			 }
			 //alert(SHEEBOO_scambio['checkESC']);
			 if (SHEEBOO_scambio['checkESC'] !== undefined) SHEEBOO_scambio['checkESC'].clear();
			 return true;
	  }
}

function SHEEBOO_dounblur2(event) {
	//alert("click");
	//dump(Event.element(event));
    if ($('SHEEBOO_blur') !== undefined && $('SHEEBOO_blur') != null) {
        Event.stopObserving('SHEEBOO_blur','click',SHEEBOO_dounblur2);
    }
	Event.stopObserving(document, 'keypress', SHEEBOO_checkESC);
	if ($('SHEEBOO_blurLogin') === undefined || $('SHEEBOO_blurLogin') == null) {
        $('SHEEBOO_blurLogin').setStyle({display:'none'});
    }
    if ($('SHEEBOO_blur') !== undefined && $('SHEEBOO_blur') != null) {
        $('SHEEBOO_blur').setStyle({display:'none'});
    }
	//Event.stop;
//	SHEEBOO_removeDivChild('SHEEBOO_blurLogin');
//	SHEEBOO_removeDivChild('SHEEBOO_blur');
}

function SHEEBOO_blurLoginAjax(res) {
	z = $('SHEEBOO_blurLogin').getStyle('z-Index')+1;
	res = eval("("+res.responseText+")");
	$('SHEEBOO_blurLogin').update(res['output']);
	//Effect.BlindDown('SHEEBOO_blurLogin');
	//alert(z);
	$('SHEEBOO_blurLogin').setStyle({display: 'block',zIndex:z});
	if (sbloccaCaptchaVar !== undefined) {
		var res = new Object;
		sbloccaCaptchaFunctionToCall = '';
		res.responseText = 0;
		resSbloccaCaptcha(res);
		return true;
	}
}

function SHEEBOO_loadJS(file) {
   var head = document.getElementsByTagName("head")[0];
   script = document.createElement('script');
   script.id = file;
   script.type = 'text/javascript';
   script.src = site+"/js/"+file;
   head.appendChild(script)
}

function SHEEBOO_reloadPage(add,id) {
  //if (id === undefined) {
  //  setTimeout('SHEEBOO_reloadPage('+add+',1)',500);
  //}
  //else {
  	  if (add == undefined) {
  	  	add = '';
  	  	divisorio = '';
  	  } else {
		  	  if (location.search != '') {
  	  				var divisorio = '&';
  	  		  } else {
  	  					var divisorio = '?';
  	   		    }
  	    }

      var url = 'http://'+location.host+location.pathname+location.search+divisorio+add;
      window.location = url;
  //}
}



/**
* Rimanda il browser alla pagina specificata.
* @param string page la pagina da ricaricare senza http://dominio/
*/
function SHEEBOO_goToPage(page) {
/*    if (typeof(use_ajax_proxy) != "undefined" && true == use_ajax_proxy) {
        var url = window.location.href;
        url = url.replace('#','');
    } else { */
        if (page === undefined || page == null) {
            var page = '';
        }
        var url='http://'+location.host+"/"+page;
//    }
    window.location = url;
}


function SHEEBOO_tmpAzzeraLetture() {
	page = 'tmp/azzeraLetture.php';
	pars = '';
	SHEEBOO_ajax(page,pars,'SHEEBOO_tmpAzzeraLettureAjax');
}

function SHEEBOO_tmpAzzeraLettureAjax(res) {
	return true;
}

function SHEEBOO_accessoSoloAdmin() {
	SHEEBOO_scambio['funzioneDaEseguireDopoLogin'] = 'window.location="/"';
	if (SHEEBOO_scambio['accessoSoloAdmin'] === undefined ||SHEEBOO_scambio['accessoSoloAdmin'] == null) {
		SHEEBOO_scambio['accessoSoloAdmin'] = 1;
		return true;
	}
	window.location='/';

}

function SHEEBOO_AjaxVuoto(res) {

	return true;
}

function SHEEBOO_getElementsByClassName(oElm, strTagName, oClassNames){
    var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
    var arrReturnElements = new Array();
    var arrRegExpClassNames = new Array();
    if(typeof oClassNames == "object"){
        for(var i=0; i<oClassNames.length; i++){
            arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames[i].replace(/\-/g, "\\-") + "(\\s|$)"));
        }
    }
    else{
        arrRegExpClassNames.push(new RegExp("(^|\\s)" + oClassNames.replace(/\-/g, "\\-") + "(\\s|$)"));
    }
    var oElement;
    var bMatchesAll;
    for(var j=0; j<arrElements.length; j++){
        oElement = arrElements[j];
        bMatchesAll = true;
        for(var k=0; k<arrRegExpClassNames.length; k++){
            if(!arrRegExpClassNames[k].test(oElement.className)){
                bMatchesAll = false;
                break;
            }
        }
        if(bMatchesAll){
            arrReturnElements.push(oElement);
        }
    }
    return (arrReturnElements)
}

/**
* Mostra il box dei messaggi
* dati � un array formato da:
* msg: il messaggio
* left: la posizione left (opzionale)
* top: la posizione top (opzione)
* reload: se la pagina deve essere ricarica dopo la pressione dell'ok
* reloadCosa: la pagina web dove andare (opzionale)
*
* In automatico viene creato un div sottostante trasparente, ma che non consente all'utente di premere altro se non l'ok del box.
*/

function resendActiveCode(email_user){
	page = 'admin/sendActiveCodeAjax.php';
	pars = 'email='+encodeURIComponent(email_user);
	SHEEBOO_ajax(page,pars,'SHEEBOO_sendActiveCodeAjax');


}
function SHEEBOO_sendActiveCodeAjax(res){
	res = eval("("+res.responseText+")");
	res.msg = res['output'];
	SHEEBOO_mostraMsgBox(res);
}
function SHEEBOO_mostraMsgBox(dati) {
	if (dati.top === undefined) {
		if (window.innerHeight){
		//navegadores basados en mozilla
		espacio_pagina = self.innerHeight/2;
		}else{
		//Navegadores basados en IExplorer, es que no tengo innerheight
		//espacio_pagina = document.body.clientHeight/2;
		espacio_pagina = document.body.scrollWidth/3;
		}
		  dati.top = document.documentElement.scrollTop + (espacio_pagina) ;
		  dati.top += "px";
	}
    if (dati.left === undefined) dati.left = "0px";
    if (dati.z === undefined) dati.z = 2000;
    //Creo un div appena sotto il box cosi' non si puo' premere da nessun'altra parte.
    var zDiv = dati.z -1;
    $('avviso').setStyle({position:'absolute',left:dati.left,top:dati.top,zIndex:dati.z,display:'block'});
    if (dati.noButton == true) {dati.msg+="<span id='img-caricamento'><img src='http://www.sheeboo.com/template/standard/images/indicator_snake.gif'></span>";}
    $('testo-avviso').update(dati.msg);
    //$('avviso').show();
    if (dati.reload !== undefined && dati.reload == true){
			$('avviso-img').onClick= function() {SHEEBOO_reloadPage();};
			SHEEBOO_scambio['reloadAfterBox'] = true;
     }
    if (dati.goToPage !== undefined) {
    		SHEEBOO_scambio['goToPage'] = dati.goToPage;
    		$('avviso-img').onClick= function() {SHEEBOO_goToPage(dati.goToPage);};
			SHEEBOO_scambio['reloadAfterBox'] = true;
    }
	//debugger;
    if (dati.noButton !== undefined && dati.noButton == true) {
    	$('bottone-avviso').hide();
    } else $('bottone-avviso').show();
	if (dati.timeout !== undefined) {
		setTimeout('SHEEBOO_nascondiMsgBox()',1000);
	}
	if (dati.okFunzione !== undefined) {
		//alert(dati.okFunzione);
		$('avviso-img').onclick= function() { eval(dati.okFunzione);};
	} else {
        $('avviso-img').onclick= function() { SHEEBOO_nascondiMsgBox();};
    }
	if (dati.annullaFunzione !== undefined) {
		$('bottone-avviso-annulla').show();
		$('avviso-img-annulla').onclick = function() { eval(dati.annullaFunzione);};
		//var img = document.getElementById('avviso-img-annulla');
		//img.onclick = function() {alert("pippo");};
//
//		$('avviso-img-annulla').onclick=function() {alert("pippo");};
	} else {
        $('bottone-avviso-annulla').hide();
        $('avviso-img-annulla').onclick = '';
    }
	//SHEEBOO_chiudiAvviso();
	return true;
}

function SHEEBOO_nascondiMsgBox() {
	SHEEBOO_scambio['bloccahref'] = false;
	SHEEBOO_chiudiAvviso();
}

function SHEEBOO_chiudiAvviso() {
	if ($('avviso') !== undefined){
		SHEEBOO_genToggle('avviso');
	}
	//alert($('divRiempimento'));
	//if ($('divRiempimento') !== undefined && $('divRiempimento') != null) $('divRiempimento').hide();
	if (SHEEBOO_scambio['reloadAfterBox'] !== undefined && SHEEBOO_scambio['reloadAfterBox'] == true) {
		if (SHEEBOO_scambio['goToPage'] !== undefined && SHEEBOO_scambio['goToPage'] != '') {
			SHEEBOO_goToPage(SHEEBOO_scambio['goToPage']);
			SHEEBOO_scambio['goToPage'] = '';
		} else SHEEBOO_reloadPage();

	}
}

function SHEEBOO_settaBookmark(idu,cosa,idop) {
	page = 'admin/settaBookmark.php';
	pars = 'idu='+idu+'&cosa='+cosa+'&idop='+idop;
	SHEEBOO_Ajax(page,pars,'SHEEBOO_settaBookmarkAjax');
}

function SHEEBOO_settaBookmarkAjax(res) {
	//Se res['val'] == 0 allora cambio la icona in giallo se icona = 1, altrimenti setto quella bianca perche' � un unset del bookmark.
	//Setto ancora lo stesso script perche' cosi' al prossimo richiamo unsetto il bookmark.
	//Mostro il messaggio di operazione effettuata.
}

function SHEEBOO_cancellaOp(cosa,tipo) {
	var dati = { msg: LANG_CANCELLA_OPINIONE_OK,noButton:false,okFunzione:'SHEEBOO_deleteOp('+cosa+','+tipo+')',annullaFunzione:'SHEEBOO_nascondiMsgBox()' };
	SHEEBOO_mostraMsgBox(dati);
}
function SHEEBOO_deleteOp(cosa,tipo){
	page = 'admin/addNoOpinioneCategoria.php';
	pars = 'tipo='+tipo+'&cosa='+cosa;
	SHEEBOO_ajax(page,pars,'SHEEBOO_cancellaOpAjax');
	SHEEBOO_scambio['opinioneDel'] = cosa;
}

function SHEEBOO_cancellaOpAjax(res) {
	SHEEBOO_nascondiMsgBox();
	res = eval("("+res.responseText+")");
	if (res['val'] >= 0) {
		var reload = true;
		SHEEBOO_goToPage();
	} else {
		var reload = false;
		}
	return true;
}

function SHEEBOO_mostraTooltip(tool) {
	if (SHEEBOO_scambio['tooltip'] !== undefined && SHEEBOO_scambio['tooltip'] != null) {
		$(SHEEBOO_scambio['tooltip']).hide();
	}
	if (tool != ''){
	SHEEBOO_scambio.tooltip = tool;
	$(SHEEBOO_scambio['tooltip']).show();
	}
}

function SHEEBOO_vediCorpoOldTrend() {
	$('SHEEBOO_oldAnteprima').hide();
	$('SHEEBOO_oldCorpo').show();
}

function SHEEBOO_vediAnteprimaOldTrend() {
	$('SHEEBOO_oldCorpo').hide();
	$('SHEEBOO_oldAnteprima').show();

}
memoryIdOMenu="over0";
function SHEEBOO_orizontalMenu(id,num){
//if (id  == '-1'){
//$(memoryIdOMenu).setStyle({background:'#8FB51B url('+nome_template+'/images/bg_categorie_left.gif) no-repeat left top',color:'#fff',lineHeight:'28px'});
//$("a"+memoryIdOMenu).setStyle({background:'url('+nome_template+'/images/linea_cat_vert.gif) no-repeat right top',color:'#fff',lineHeight:'28px'})
//$("cat"+memoryIdOMenu).setStyle({height:'25px'});
// return;
// }
//alert("Sei su "+id);
var i = 0;
for (;i<num;i++){
	if (($("over"+i) != undefined) && ($("over"+i).value != '')) {
	$("over"+i).setStyle({background :'transparent',color:'#000',lineHeight:'35px'});
	$("aover"+i).setStyle({background :'transparent',color:'#000',lineHeight:'35px'});
	if (($("catover"+i) != undefined) && ($("catover"+i).value != ''))$("catover"+i).hide();
						}
}
$("cat"+memoryIdOMenu).hide();
$(memoryIdOMenu).setStyle({background :'transparent',color:'#000',lineHeight:'35px'});
$("a"+memoryIdOMenu).setStyle({background :'transparent',color:'#000',lineHeight:'35px'});

$("cat"+id).show();
$(id).setStyle({background:'#8FB51B url('+nome_template+'/images/bg_categorie_left.gif) no-repeat left top',color:'#fff',lineHeight:'28px'});
$("a"+id).setStyle({background:'url('+nome_template+'/images/linea_cat_vert.gif) no-repeat right top',color:'#fff',lineHeight:'28px'})

$("cat"+id).setStyle({height:'25px'});
memoryIdOMenu=id;
}


memoryIdOMenu2=-1;

function SHEEBOO_orizontalMenu2(id,MPosition){
if ((memoryIdOMenu2 == id)||((id==MPosition)&&(memoryIdOMenu2==-1))) return;
$("over"+id).setStyle({background:'#fff',color:'#7AA300'});
$("catover"+id).show();
if (memoryIdOMenu2 == -1){
    	$("over"+MPosition).setStyle({background :'transparent',color:'#000'});
		$("catover"+MPosition).hide();
		memoryIdOMenu2=id;
		}
		else {
			$("over"+memoryIdOMenu2).setStyle({background :'transparent',color:'#000'});
			$("catover"+memoryIdOMenu2).hide();
			memoryIdOMenu2=id;
			}



}


/**
* Creo la funzione trim
*/
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, '');
};

/**
* Controlla che il campo di ricerca contenga qualche cosa prima di essere inviato
*/
function SHEEBOO_checkSerpText() {
	//debugger;
	//alert(filtroSerp.test($('SHEEBOO_serp').value.trim()));
	if (!filtroSerp.test($('SHEEBOO_serp').value.trim())) {
		//var dati = { msg: LANG_CARATTERI_NON_VALIDI};
		SHEEBOO_MostraMsgBox(dati);
		alert(LANG_CARATTERI_NON_VALIDI);
		return false;
	}
	if ($('SHEEBOO_serp').value.trim() == '') return false;
	return true;
}
// controllo per capire se il browser è safari
var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror')) browser = "Konqueror";
else if (checkIt('safari')) browser = "Safari"
else if (checkIt('omniweb')) browser = "OmniWeb"
else if (checkIt('opera')) browser = "Opera"
else if (checkIt('webtv')) browser = "WebTV";
else if (checkIt('icab')) browser = "iCab"
else if (checkIt('msie')) browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
    browser = "Netscape Navigator"
    version = detect.charAt(8);
}
else browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

function checkIt(string)
{
    place = detect.indexOf(string) + 1;
    thestring = string;
    return place;
}

function settaMenu(cat){
	for(i=0;;i++){
		if ($('over'+i)!=undefined && $('over'+i)!=null){
		
		}
		else return;
	
	}

}

// functions to use when requestiong an externa serch
function SHEEBOO_serp(s,p,o,ext) {
    if (p === undefined || p == null) {
        p = '1';
    }
    if (ext === undefined || ext == null) {
        ext = '0';
    }
	var url = 'serp/opinions.htm';
	var pars = 's='+URLEncode(s)+'&p='+p+'&o='+o+'&ext='+ext;
	SHEEBOO_ajax(url,pars,'SHEEBOO_serpAjax');
}

function SHEEBOO_serpAjax(res) {
    $('SHEEBOO_Serp').update(res.responseText);
}
