function contachar(obj) {
	var nchar=0;
	nchar = obj.value.length;
	document.getElementById("formEditor").nabs.value=nchar;
}

function caricainfodl(urlimg,l,t){
      var el1 = document.getElementById("barraimg");

            if (el1) {
            el1.style.display = '';
            }

	liveReq = false;
	
	if (window.XMLHttpRequest) {
		liveReq = new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		liveReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	if (liveReq && liveReq.readyState < 4) {
		liveReq.abort();
	}
	liveReq.onreadystatechange = function () {
		if (liveReq.readyState == 4) {
			if (liveReq.status == 200) {

		document.getElementById("barraimg").innerHTML = liveReq.responseText;

			} 
			document.body.style.cursor = 'default';
		}
	}
	document.body.style.cursor = 'wait';
        var url = 'http://www.isresardegna.it/index.php?xsl=809&s=16&v=9&c=4083&nodesc=1&urlimg=' + urlimg + '&l=' + l + '&t=' + t;
        //alert(url);
	liveReq.open("GET", url);
	liveReq.send(null);
	return false;
}


function PopupCentrataNg(posizione,notizia,w,h,ng,cat) {
        window.open("http://www.isresardegna.it/index.php?xsl=546&s=16&v=9&c="+cat+"&notizia="+notizia+"&pic="+posizione+"&ng="+ng,"","width=" + w + ",height=" + h + ",top=60 , left=60, status=no, menubar=no, toolbar=no scrollbar=no");
        return false;
}

function PopupCentrata(posizione,notizia,w,h,cat) {
	window.open("http://www.isresardegna.it/index.php?xsl=546&s=16&v=9&c="+cat+"&notizia="+notizia+"&pic="+posizione,"","width=" + w + ",height=" + h + ",top=60 , left=60, status=no, menubar=no, toolbar=no scrollbar=no");
	return false;
}

function temporizza(immagine,news,cat){
	window.location.href = "http://www.isresardegna.it/index.php?xsl=546&s=16&v=9&c="+cat+"&slide=1&notizia="+news+"&pic="+immagine;
}

function temporizza2(immagine,news,ng,cat){
        window.location.href = "http://www.isresardegna.it/index.php?xsl=546&s=16&v=9&c="+cat+"&slide=1&notizia="+news+"&pic="+immagine+"&ng="+ng;
}

function sendmail(subject){
	window.location.href = "mailto:?subject="+escape(subject)+"&body="+escape(window.location);
	return false;
}
function intercetta() {
	for (var i=0; i<document.links.length; i++) {
		if (document.links[i].rel=="blank") {
			document.links[i].target="_blank";
			document.links[i].title = document.links[i].title+" (apertura in nuova finestra)";
		}
	}
}
addEvent(window,'load',intercetta);
/*window.onload = intercetta;*/
function addEvent(obj, evType, fn){ 
	if (obj.addEventListener){ 
		obj.addEventListener(evType, fn, false); 
		return true; 
	} else if (obj.attachEvent){ 
		var r = obj.attachEvent("on"+evType, fn); 
		return r; 
	} else { 
		return false; 
	} 
}
function openPopUp(url, larghezza, altezza){
	var location=url;
	if (location!=''){
		var DispWin;
		DispWin=window.open(location, '','toolbar=no, "NewWin", status=yes,resizable=yes,,scrollbars=yes, width='+larghezza+', height='+altezza+',  top=1, left=1');
		DispWin.focus();
	}
	return false;
}

function stoperror(){return true;}

window.onerror=stoperror;

function getCookie(NameOfCookie){
	// Prima controlliamo se c'ÃƒÂ¨ un cookie memorizzato.
	// Altrimenti la lunghezza del document.cookie sarebbe zero.
	if (document.cookie.length > 0) {
		// Poi controlliamo se il nome del cookie ÃƒÂ¨ conservato nell'oggetto
		// "document.cookie"della pagina
		
		// Siccome ÃƒÂ¨ possibile inserire piÃƒÂ¹ di un cookie su una
		// singola pagina, ÃƒÂ¨ possibile che il nostro cookie
		// non sia presente, anche se l'oggetto "document.cookie"
		// non ÃƒÂ¨ solo un testo vuoto.
		// Se il nome del nostro cookie non ÃƒÂ¨ presente, verrÃƒ  memorizzato il valore -1
		// nella variabile chiamata "begin".
		
		begin = document.cookie.indexOf(NameOfCookie+"=");
		if (begin != -1) {
			// Il nostro cookie e' presente.
			// Il valore memorizzato nel cookie viene rimandato dalla funzione.
			begin += NameOfCookie.length+1;
			end = document.cookie.indexOf(";", begin);
			if (end == -1)
				end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end)); 
		}
	}
	return null;
	// Il nostro cookie non era presente.
	// Il valore "null" viene rimandato dalla funzione.
}
function SetCookie (name, value) {
	var todayDate = largeExpDate = new Date ();
	largeExpDate.setTime(todayDate.getTime() + 365 * 24 * 3600 * 1000);
	document.cookie = name+'='+escape(value)+'; expires=' + largeExpDate.toGMTString();
}
function s3d_openPopUp(url, larghezza, altezza){
	if (url!=''){
		var DispWin;
		var winl = (screen.width-larghezza)/2;
		var wint = (screen.height-altezza)/2;
		if (winl < 0) winl = 0;
		if (wint < 0) wint = 0;
		DispWin=window.open(url, '','toolbar=no,"NewWin",status=yes,resizable=yes,scrollbars=no,width='+larghezza+',height='+altezza+',top='+wint+',left='+winl);
		DispWin.focus();
	}
	return false;
}
/*
function Check_s3d(url,idcat) {
*/
/*
	if (getCookie("check_s3d") == null) {
		s3d_openPopUp("http://www.sardegnaturismo.it/index.php?xsl=74&s=1&v=9&w=0&nodesc=1&c="+idcat+"&url="+escape(url),530,100);
	}
	else
		window.location.href = url;
*/
/*
	s3d_openPopUp("http://www.sardegnaturismo.it/xml/check_s3d.php?idcat="+idcat+"&url="+escape(url),530,100);
	return false;
}
*/
function Check_s3d(url,idcat) {
	s3d_openPopUp("http://www.sardegna3d.it/xml/check_s3d.php?idcat="+idcat+"&url="+escape(url),530,100);
	return false;
}



function  cambiaComboStrutture(combocom,s,c,aslhost)
{
  liveReq3 = false;
  if (window.XMLHttpRequest)
  {
      liveReq3 = new XMLHttpRequest();
  }
  else if (window.ActiveXObject)
  {
      liveReq3 = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (liveReq3 && liveReq3.readyState < 4)
  {
      liveReq3.abort();
  }
  var combodis = document.getElementById("iddistretto");
  liveReq3.onreadystatechange = liveReq3Fun;
  var url41 = aslhost + "/index.php?xsl=41&s=" + s + "&v=9&c=" + c + "&nodesc=2&com=" + combocom.options[combocom.options.selectedIndex].value + "&dis=" + combodis.options[combodis.options.selectedIndex].value;
  // alert(url41);						  
  liveReq3.open("GET",url41 );
  liveReq3.send(null);
  return false;
}
            
function liveReq3Fun()
{
    if (liveReq3.readyState == 4)
    {
        var divstrutture = document.getElementById("div-strutture");
        divstrutture.innerHTML = liveReq3.responseText;
    }
}
            
            
function ottieniDistretto(combocom,s,c,aslhost)
{
  cambiaComboStrutture(combocom,s,c,aslhost);
  if(combocom.options[combocom.options.selectedIndex].value == '') return false;
  liveReq2 = false;
  if (window.XMLHttpRequest)
  {
      liveReq2 = new XMLHttpRequest();
  }
  else if (window.ActiveXObject)
  {
      liveReq2 = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (liveReq2 && liveReq2.readyState < 4)
  {
    liveReq2.abort();
  }
						  
  liveReq2.onreadystatechange = liveReq2Fun;
  liveReq2.open("GET", aslhost + "/index.php?xsl=40&s=" + s + "&v=9&c=" + c + "&nodesc=2&com=" + combocom.options[combocom.options.selectedIndex].value);
  liveReq2.send(null);
  return false;
}
					  
function liveReq2Fun()
{
    if (liveReq2.readyState == 4)
    {
        var divdistretti = document.getElementById("div-distretti");
        divdistretti.innerHTML = liveReq2.responseText;
    }
}
					  
function CambiaComuniAjax(cmp,s,c,aslhost)
{
    //alert(s + '-' + c + '-' + aslhost)    					
    cambiaComboStrutture(cmp,s,c,aslhost);
    liveReq = false;
						  
						  
    if (window.XMLHttpRequest)
    {
      liveReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        liveReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (liveReq && liveReq.readyState < 4)
    {
        liveReq.abort();
    }
    liveReq.onreadystatechange = liveReqCambiaComuni;
    liveReq.open("GET", aslhost + "/index.php?xsl=39&s=" + s + "&v=9&c=" + c + "&nodesc=2&dis="+cmp.options[cmp.options.selectedIndex].value);
    liveReq.send(null);
    //document.getElementById("locform").disabled=true;
    return false;
}
					  
function liveReqCambiaComuni()
{
    if (liveReq.readyState == 4)
    {
      //var cmp = document.getElementById("locform");
      //cmp.disabled=false;
      var cmp = document.getElementById("div-comuni");
      cmp.innerHTML = liveReq.responseText;
    }
}

function CambiaStato(posizione) {
        var el = document.getElementById('divn_'+posizione);
	var el2 = document.getElementById('divs_'+posizione);
	el.style.display = 'none';
	el2.style.display = '';

        for (i=1; i<=10; i++) {
              if (posizione != i) {
                var ela = document.getElementById('divn_'+i);
                var ela2 = document.getElementById('divs_'+i);
                if (ela) {
                ela.style.display = '';
                }
                if (ela2) {
                ela2.style.display = '';
                }
              }
            }

	return true;
}
