var zone_selected=new Array();

function cambia_categoria(obj,multi){
	var id = obj.id.substr(11);
	with (window.document) {
		getElementById("divRaggio").style.display='none';
		//3 = CATEGORIA_VACANZE , 4 = CATEGORIA_STANZE
		if (id==3 || id==4){
			getElementById("idContratto1").style.display='none';
			getElementById("divZ").style.display='none';
			if (id==4){
				getElementById("divContratto").style.display='none';
				getElementById("divC").style.display='none';
			}
			else{
				getElementById("divContratto").style.display='block';
				getElementById("divC").style.display='block';
			}
			dati.idContratto[1].checked=true;
			dati.selectPrezzoMinimo.selectedIndex=0;
			dati.selectPrezzoMassimo.selectedIndex=0;
 			xajax_getAjaxFascePrezzoPagIndex(dati.idContratto[1].value);
 			getElementById("divPrezzo").style.display='none';
			getElementById("divCittaDirette").style.display = 'none';
			getElementById("linkDirettiCitta").style.display = 'none';
		}
		else{
			getElementById("divC").style.display='block';
			getElementById("divZ").style.display='block';
			getElementById("divContratto").style.display='block';
 			getElementById("idContratto1").style.display='block';
			getElementById("divPrezzo").style.display='block';
			getElementById("divCittaDirette").style.display = 'block';
			getElementById("linkDirettiCitta").style.display = 'block';
		}
		var tabId = document.getElementById("dati").idCategoria;
		for (var ix=0;ix<=maxCategoria;ix++){
			if (getElementById("idCategoria"+ix)){
				getElementById("idCategoria"+ix).className='';
			}
		}
		if (multi == true)
			getElementById("idCategoria"+id).className='here';
		else
			getElementById("idCategoria"+id).className='selected';
		tabId.value=id;
		dati.idRegione.selectedIndex=0;
		xajax_getAjaxProvincePagIndex("");
		if (dati.idProvincia) 
			dati.idProvincia.selectedIndex=0;
		if (dati.idTipologia)
			dati.idTipologia.selectedIndex=0;
	}
}

function enableBack(ricerca){
	var oDiv = document.getElementById("div_back");
	if( document.getElementById("divCittaDirette") != null){
		var oDivCitta = document.getElementById("divCittaDirette");
		var oLinkCitta = document.getElementById("linkDirettiCitta");
		var oShowLinkCitta = document.getElementById("showLinkDirettiCitta");
	}
	var oHref = document.getElementById("href_back");
	if (window.document.dati.idRegione.value){
		if(window.document.dati.idProvincia.value){
			if( document.getElementById("divCittaDirette") != null){
				oLinkCitta.style.display = "none";
				oDivCitta.style.display = "none";
				oShowLinkCitta.style.display="none";
			}
			if (window.document.dati.idComune.value) {
				// Sono nel comune
				if(document.getElementById("divZ").style.display == "block" && document.getElementById("divRaggio").style.display=="none"){
					oHref.onclick = function(){ xajax_getAjaxComuniPagIndex('', window.document.dati.idRegione.value,ricerca); return false; };
					oHref.innerHTML="<img style =\"vertical-align: top;margin-top:1px;\" src=\"/img2/precedente.gif\"/> " + window.document.dati.idRegione.options[window.document.dati.idRegione.selectedIndex].text;
				}
			} else {
				// Sono nella provincia
				oHref.onclick = function(){ xajax_getAjaxProvincePagIndex('',ricerca); return false;};
				oHref.innerHTML="<img style =\"vertical-align: top;margin-top:1px;\" src=\"/img2/precedente.gif\"/>  Ελλάδα";
			}
		}else {
			// Sono nella regione
			oHref.onclick = function(){ xajax_getAjaxProvincePagIndex('',ricerca); return false;};
			oHref.innerHTML="<img style =\"vertical-align: top;margin-top:1px;\" src=\"/img2/precedente.gif\"/>  Ελλάδα";
		}
	}else{
		// Sono nella nazione
		oHref.innerHTML="";
		if( document.getElementById("divCittaDirette") != null) {
			if (document.getElementById("idContratto1").style.display != "none") {
				oDivCitta.style.display = "";
				oLinkCitta.style.display = "";
			}
		}
	}
}

function hideShowLinkCitta(){
	if(window.document.dati.idRegione.value){
		var newDiv = document.getElementById("showLinkDirettiCitta");
		var oDiv = document.getElementById("linkDirettiCitta");
		var childDiv = oDiv.childNodes;
		var numShowCitta = 0;
		svuota_cointainer(newDiv);
		for (var i=0; i< childDiv.length ; i++){
			if( childDiv[i].id.indexOf("link_" + window.document.dati.idRegione.value) > -1 ){
				if(numShowCitta){
					var oSpan = document.createElement("span");
					oSpan.innerHTML +=", ";
					newDiv.appendChild(oSpan);
				}
				var oHref = document.createElement("a");
				oHref.setAttribute("href","#");
				oHref.setAttribute("id","show_"+ childDiv[i].id);
				oHref.setAttribute("style", "font-size:11px; color:#1E4B80; font-weight:bold;");
				oHref.innerHTML += childDiv[i].innerHTML;
				
				oHref.setAttribute("onclick",childDiv[i].getAttribute("onclick"));
				newDiv.appendChild(oHref);
				numShowCitta++;
			}
		}
		if (numShowCitta>0 && window.document.dati.idProvincia.value=="") {
		// Cartina della regione Attica o Macedonia
			document.getElementById("divCittaDirette").style.display = "block";
			document.getElementById("linkDirettiCitta").style.display = "none";
			document.getElementById("showLinkDirettiCitta").style.display = "block";
		} else {
		// Tutte le altre regioni e province e la sezione vacanze
			document.getElementById("divCittaDirette").style.display = "none";
			document.getElementById("linkDirettiCitta").style.display = "none";
			document.getElementById("showLinkDirettiCitta").style.display = "none";
		}
	} else {
	// Cartina della nazione
		document.getElementById("divCittaDirette").style.display = "block";
		document.getElementById("linkDirettiCitta").style.display = "block";
		document.getElementById("showLinkDirettiCitta").style.display = "none";
	}
}

function changeImage (region) {
	var ShowItem = document.getElementById("div_regioni");
	ShowItem.style.backgroundImage = 'url(/img2/cartine' + multilingua_path + '/' + region + '_selected.gif)';
	return true;
}

function hideImage (region) {
	var ShowItem = document.getElementById("div_regioni");
	ShowItem.style.backgroundImage = 'url(/img2/cartine' + multilingua_path + '/transparent.gif)';
	return true;
}

function changeImageProv (provincia) {
	var oDiv = document.getElementById("div_provincie");
	oDiv.style.backgroundImage = 'url(/img2/cartine' + multilingua_path + '/' + window.document.dati.idRegione.value + '/select_' + provincia + '.gif)';		
}

function hideImageProv (provincia) {
	var oDiv = document.getElementById("div_provincie");
	oDiv.style.backgroundImage = 'url(/img2/cartine' + multilingua_path + '/transparent.gif)';	
}

function changeImageZone (zona) {
	var oDiv = document.getElementById("div_zone");
	oDiv.style.backgroundImage = 'url(/img2/cartine' + multilingua_path + '/' + window.document.dati.idRegione.value + '/' + window.document.dati.idComune.value +'/map_zona_' + zona + '.gif)';
}

function hideImageZone() {
	var oDiv = document.getElementById("div_zone");
	oDiv.style.backgroundImage = 'url(/img2/cartine' + multilingua_path + '/transparent.gif)';	
}

function selectZona(citta, zone) {
	url_map = "/img2/cartine" + multilingua_path + "/" + window.document.dati.idRegione.value + "/" + citta + "/map_zona_";
	var oCointainer = document.getElementById("zone_container");
	var browser = navigator.userAgent.toLowerCase();
	if ( browser && browser.indexOf("msie")!=-1){
		oCointainer.style.position ="relative";
		if ( browser.indexOf("msie 8")==-1) {
			oCointainer.style.left = "-135px";
		}
	}

	var new_selected=new Array();
	var flag=0;
	svuota_cointainer(oCointainer);
	if (zone_selected.length != 0 ){
		for (i=0,j=0; i< zone_selected.length ;i++){
			if (zone_selected[i] != zone){
				new_selected[j] = zone_selected[i];
				createDivMap(oCointainer, new_selected[j], url_map); 
				j++;
			} else { flag=1; } 
		}
		if (!flag){ 
			new_selected[zone_selected.length] = zone;
			createDivMap(oCointainer, zone, url_map);
		}
		zone_selected=new_selected;
	}else { 
			zone_selected[0] = zone;
			createDivMap(oCointainer, zone, url_map);
	}
	return true;
}

function selectProvincia(provincia) {
	var oContainer = document.getElementById("provincie_container");
	var oDivChild = document.createElement("div");
	var oImg = document.createElement("img");
	var browser = navigator.userAgent.toLowerCase();
	if ( browser && browser.indexOf("msie")!=-1){
		oContainer.style.position ="relative";
		if ( browser.indexOf("msie 8")==-1) {
			oContainer.style.left = "-135px";
		}
	}

	svuota_cointainer(oContainer);
	
	oDivChild.style.position="absolute";
	oDivChild.id = provincia;
	oImg.src ='/img2/cartine' + multilingua_path + '/' + window.document.dati.idRegione.value + "/select_" + provincia + ".gif";
	oImg.useMap="#Map";
	oImg.border="0";
	oDivChild.appendChild(oImg);
	oContainer.appendChild(oDivChild);
	
	var oArea = document.getElementById("_map_" + provincia);
	oArea.removeAttribute("shape");
}

function createDivMap (oCointainer, id_zona, url_map){
	var oDiv = document.createElement("div");
    var oImg = document.createElement("img");
	
	oDiv.id = "map_zona_" + id_zona;		
	oDiv.style.position = "absolute";	
	oImg.src = url_map + id_zona + ".gif";
	oImg.useMap = "#Map";
	oImg.border="0";
	oDiv.appendChild(oImg);

	oCointainer.appendChild(oDiv);
}

function svuota_cointainer(oCointainer){
	while (oCointainer.hasChildNodes())
		oCointainer.removeChild(oCointainer.firstChild);	
}	
	
function enableTooltip(id_zona){
	var oDiv = document.getElementById("tooltip_div");
	var oArea = document.getElementById(id_zona);

	titolo = oArea.getAttribute("alt");
	if (titolo.length > 90) {
		titolo1 = titolo.substring(0,90);
		var regex = /,[^,]*$/;
		titolo = titolo1.replace(regex, ", ...");
	}
	if (titolo != "" && oDiv){
		oArea.removeAttribute("title");
		oDiv.innerHTML = titolo;
	}
}
	
function disableTooltip(){
	var oDiv = document.getElementById("tooltip_div");
	if(oDiv && oDiv.hasChildNodes())
		oDiv.removeChild(oDiv.firstChild);
}

function preloadImageNazione(){
        if (!document.getElementById("regioni"))
                return (null);
        var oMapRegioni = document.getElementById("regioni");
        var aoAreaRegioni = oMapRegioni.getElementsByTagName('area');
        var imageLoad = new Image();
        for (var i = 0; i < aoAreaRegioni.length; i++){
                if (!aoAreaRegioni[i])
                        continue;
                var sPathImg = '/img2/cartine' + multilingua_path + '/' + aoAreaRegioni[i].id.substring(5) + "_selected.gif";
                imageLoad.src = sPathImg;
        }

}

function preloadImageProvincie(regione, image){
		var imageLoad = new Image();
		imageLoad.src = "/img2/cartine" + multilingua_path + "/" + regione + "/select_prov_" + image + ".gif";
}

function preloadImageZone(comune, image){
		var imageLoad = new Image();
		imageLoad.src = "/img2/cartine" + multilingua_path + "/" + window.document.dati.idRegione.value + "/" + comune + "/map_zona_" + image + ".gif";
}

function deselezioneCheckbox(zona) {
	var chks = document.forms[0].idZona;
	for (var i=0;i<chks.length;i++) {
		if (chks[i].value != zona) {
			if (chks[i].checked)
				chks[i].checked = false;
		}
	}
	document.getElementById('zone_descrizione').value = zona;
}