		function apri( targetId ){
				target = document.getElementById( targetId );
						target.style.display = "block";
						Fat.fade_element(targetId, 60, 1500, "#FFFF99");
		}
		
		function chiudi( targetId ){
				target = document.getElementById( targetId );
						target.style.display = "none";
						
		}

function caricaCitta(x)
{
	var prov = document.getElementById(x);
	var cvalue = prov[prov.selectedIndex].value;

	var mydata = 'ajax_enabled=1&ajax_cerca_citta=1&ajax_prov=' + cvalue;
	ajax = new sack('classes/include/annunci.php');
	ajax.element = 'ricerca_imm_citta';
	ajax.method = 'POST';
	Fat.fade_element("ricerca_imm_citta", 60, 1500, "#FFFF99");
	ajax.runAJAX(mydata);

}

function caricaCitta_mod(x,y)
{
	var prov = document.getElementById(x);
	var cvalue = prov[prov.selectedIndex].value;

	var mydata = 'ajax_enabled=1&ajax_cerca_citta=1&ajax_prov=' + cvalue + '&ajax_citta=' + y;
	ajax = new sack('classes/include/annunci.php');
	ajax.element = 'ricerca_imm_citta';
	ajax.method = 'POST';
	Fat.fade_element("ricerca_imm_citta", 60, 1500, "#FFFF99");
	ajax.runAJAX(mydata);
	
}

function enableProvExt()
{
	var provincia = document.getElementById('provincia');
	var cvalue = provincia[provincia.selectedIndex].value;
	
	var prov_ext = document.getElementById("provincia_ext");

	// se � selezionata la casella "Nessuna delle precedenti" --> Abilito il campo "provincia_ext"
	if (cvalue=="nessuna")
	{
		prov_ext.disabled = false;
		prov_ext.focus();
	}
	// se invece non � selezionata --> disabilito la casella
	else 
	{
		prov_ext.disabled = true;
	}
	return true;
}

function enablePubblicita()
{
	var checkedButton = "";
	for (var i in document.aggiunta_articolo.canale) {
		if (document.aggiunta_articolo.canale[i].checked=="1") {
			checkedButton=document.aggiunta_articolo.canale[i].value
		}
	}
	
	// var pubblicita = document.getElementById("pubblicita");

	// se � selezionata la casella "Portale" --> Disabilito il campo "pubblicita"
	if (checkedButton=="4")
	{
		document.aggiunta_articolo.pubblicita[0].disabled = true;
		document.aggiunta_articolo.pubblicita[1].disabled = true;

	}
	// se invece non � selezionata --> disabilito la casella
	else 
	{
		document.aggiunta_articolo.pubblicita[0].disabled = false;
		document.aggiunta_articolo.pubblicita[1].disabled = false;
	}
	return true;
}

function disablePubblicita()
{
	document.getElementById("pubblicita-spazio-out-1").disabled = true;
	document.getElementById("pubblicita-spazio-out-2").disabled = true;
	document.getElementById("pubblicita-spazio-out-3").disabled = true;
	
	document.getElementById("pubblicita-piccola-out-1").disabled = true;
	document.getElementById("pubblicita-piccola-out-2").disabled = true;
	document.getElementById("pubblicita-piccola-out-3").disabled = true;
	
	document.getElementById("canale-out-1").disabled = true;
	document.getElementById("canale-out-2").disabled = true;
	document.getElementById("canale-out-3").disabled = true;
	document.getElementById("canale-web").disabled = true;
	
	document.getElementById("pubblicita-spazio-out-1").checked = false;
	document.getElementById("pubblicita-spazio-out-2").checked = false;
	document.getElementById("pubblicita-spazio-out-3").checked = false;
	
	document.getElementById("pubblicita-piccola-out-1").checked = false;
	document.getElementById("pubblicita-piccola-out-2").checked = false;
	document.getElementById("pubblicita-piccola-out-3").checked = false;
	
	document.getElementById("canale-out-1").checked = false;
	document.getElementById("canale-out-2").checked = false;
	document.getElementById("canale-out-3").checked = false;
	document.getElementById("canale-web").checked = false;
}

function caricaCittaImp(x)
{
	var prov = document.getElementById(x);
	var cvalue = prov[prov.selectedIndex].value;

	var mydata = 'ajax_enabled=1&ajax_cerca_citta=1&ajax_prov=' + cvalue;
	ajax = new sack('classes/include/annunci.php');
	ajax.element = 'ricerca_imp_citta';
	ajax.method = 'POST';
	Fat.fade_element("ricerca_imp_citta", 60, 1500, "#FFFF99");
	ajax.runAJAX(mydata);
	
}

function enableCittaExt()
{
	var citta = document.getElementById("citta");
	var cvalue = citta[citta.selectedIndex].value;
	var citta_ext = document.getElementById("citta_ext");

	// se � selezionata la casella "Nessuna delle precedenti" --> Abilito il campo "provincia_ext"
	if (cvalue=="nessuna")
	{
		citta_ext.disabled = false;
		citta_ext.focus();

	}
	// se invece non � selezionata --> disabilito la casella
	else 
	{
		citta_ext.disabled = true;
	}
	return true;
}

function caricaTipologiePrivati(x)
{
	var tipo = document.getElementById(x);
	var cvalue = tipo[tipo.selectedIndex].value;

	var mydata = 'ajax_enabled=1&ajax_cerca_tipo_privato=1&ajax_tipo=' + cvalue;
	ajax = new sack('classes/include/annunci.php');
	ajax.element = 'imm_tipo';
	ajax.method = 'POST';
	Fat.fade_element("tipologia", 60, 1500, "#FFFF99");
	ajax.runAJAX(mydata);
}

function caricaTipologiePrivati_mod(x,y)
{
	var tipo = document.getElementById(x);
	var cvalue = tipo[tipo.selectedIndex].value;

	var mydata = 'ajax_enabled=1&ajax_cerca_tipo_privato=1&ajax_tipo=' + cvalue + '&ajax_tipologia=' + y;
	ajax = new sack('classes/include/annunci.php');
	ajax.element = 'imm_tipo';
	ajax.method = 'POST';
	Fat.fade_element("tipologia", 60, 1500, "#FFFF99");
	ajax.runAJAX(mydata);
}

function caricaTipologieImprese(x)	
{
	var tipo = document.getElementById(x);
	var cvalue = tipo[tipo.selectedIndex].value;

	var mydata = 'ajax_enabled=1&ajax_cerca_tipo_imprese=1&ajax_tipo=' + cvalue;
	ajax = new sack('classes/include/annunci.php');
	ajax.element = 'imp_tipo';
	ajax.method = 'POST';
	Fat.fade_element("ricerca_imp_tipo", 60, 1500, "#FFFF99");
	ajax.runAJAX(mydata);
}


function cancellaAnnuncio(x)
{
	
	var mydata = 'ajax_enabled=1&ajax_annuncio='+ x;
	ajax = new sack('classes/include/annunci.del.php');
	ajax.element = 'annuncio-'+x;
	ajax.method = 'POST';
	ajax.onCompletion = function() 
						{ 
							Effect.Fade(document.getElementById('annuncio-'+x)); 
						}
	ajax.runAJAX(mydata);
}

function cambiastatoAnnuncio(x)
{
	var status = document.getElementById('attivo-'+x);
	var status_txt = document.getElementById('status_txt-'+x); // Scritta nel bottone
	var stato_txt = document.getElementById('stato_txt-'+x);  // Scritta nel testo
	
	var mydata = 'ajax_enabled=1&ajax_annuncio='+ x;
	ajax = new sack('classes/include/annunci.modstato.php');
	ajax.method = 'POST';
	ajax.runAJAX(mydata);
	if (status.value == "0") 
	{		
		status_txt.innerHTML = "disattiva";
		stato_txt.innerHTML = "Attivo";
		status.value = "1";
	} else {
		status_txt.innerHTML = "attiva";
		stato_txt.innerHTML = "Disattivo";
		status.value = "0";
	}
}

function spostaDatiAnnuncio(id)
{

	document.getElementById('idofferta').value = id;
	document.getElementById('attivo').value =  document.getElementById('attivo-'+id).value;
	document.getElementById('proposto').value = document.getElementById('proposto-'+id).value;
	caricaTipologiePrivati_mod('proposto',document.getElementById('tipologia-'+id).value);

	//document.getElementById('tipologia').value = document.getElementById('tipologia-'+id).value;

	document.getElementById('provincia').value = document.getElementById('prov-'+id).value;
	caricaCitta_mod('provincia',document.getElementById('citta-'+id).value);
	document.getElementById('testo').value = document.getElementById('testo-'+id).value;
	document.getElementById('mq').value = document.getElementById('mq-'+id).value;
	document.getElementById('prezzo').value = document.getElementById('prezzo-'+id).value;

	var anteprima_img = document.getElementById("img_attuale");
	var actual_img = document.getElementById("img-"+id).value;
	
	if (actual_img != "") 
	{
		anteprima_img.innerHTML = "<a href='#' onClick=\"PopIt('Anteprima Immagine Attuale','Anteprima Immagine Attuale','" + actual_img + "',440,302); return false;\" title='visualizza immagine attuale ' style='line-height: 12px'>Immagine Attuale &gt;&gt;<img src='images/foto.gif' alt='visualizza immagine ingrandita' border='0' /></a><input name='immagine_old' type='hidden' id='immagine_old' value='" + actual_img + "' />"; 
	}

	var provenienza = document.getElementById('provenienza-'+id).value;

	// disabilito tutti i canali e ne azzero il valore
	disablePubblicita();
	
	// attivo solo il canale interessato
	document.getElementById('canale-'+provenienza).checked = true;	

	// in base al valore della pubblicit� attivo o meno le checkbox
	if (provenienza != 'web')
	{
		if (document.getElementById('pubblicita-'+id).value == 3) 
		{
				document.getElementById('pubblicita-spazio-'+provenienza).checked = true;
				document.getElementById('pubblicita-piccola-'+provenienza).checked = true;
		}
		if (document.getElementById('pubblicita-'+id).value == 2) 
		{
				document.getElementById('pubblicita-spazio-'+provenienza).checked = false;
				document.getElementById('pubblicita-piccola-'+provenienza).checked = true;
		}
		if (document.getElementById('pubblicita-'+id).value == 1) 
		{
				document.getElementById('pubblicita-spazio-'+provenienza).checked = true;
				document.getElementById('pubblicita-piccola-'+provenienza).checked = false;
		}
	}
}

function popupfoto(img)
{
	window.open("images/immobili/"+img,null,"height=200,width=400,status=no,toolbar=no,menubar=no,location=no");
}

function PopIt(label, msg, URLE, Wdim, Hdim){  
	var s1 = "<html><head><title>" + label + "</title>" + 
		 "<script language='javascript'>" +
		 "   var arrTemp=self.location.href.split('?');" +
		 "   var picUrl = (arrTemp.length>0)?arrTemp[1]:'';" +
		 "   var NS = (navigator.appName=='Netscape')?true:false;" +
		 "   function FitPic() {" +
		 "      iWidth = (NS)?window.innerWidth:document.body.clientWidth;" +
		 "      iHeight = (NS)?window.innerHeight:document.body.clientHeight;" +
		 "      iWidth = document.images[0].width - iWidth;" +
		 "      iHeight = document.images[0].height - iHeight;" +
		 "      window.resizeBy(iWidth, iHeight);" +
		 "      self.focus();" +
		 "    };" +
		 "</script>" +
	"<style type=\"text/css\" media=\"screen\">"+
	"<!-- "+
	"@import url(\"/css/popup.css\"); "+
	"-->"+
	"</style></head><body onload='FitPic();' topmargin='0' marginheight='0' leftmargin='0' marginwidth='0'>"
	var s2 = "<div class=\"popup-immagine\"><img src=\"/images/immobili/" + URLE + "\" alt=\""+ label +"\" onClick=\"self.close()\">"
	var s3 = "<form><input type=\"button\" value=\"Chiudi\" onClick=\"self.close()\"></form>"
	var s4 = "</div></body></html>"  
	var dimens = "\"\",\"popDialog\",\"height=" + Hdim +",width=" + Wdim + ",scrollbars=no,resizable=yes\"" 
	popup = window.open("","popDialog","height="+Hdim+",width="+Wdim+",scrollbars=no,resizable=yes")  
	popup.document.write(s1+s2+s4)  
	popup.document.close()
}
