function createCookie(name, value, days,divId) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"=@italimar@"+value+expires+"; path=/";
	viewAllCookies(divId,1);
}
function viewAllCookies(divId,visibility) {
	//if(visibility==undefined)visibility=1;
	visibility=parseInt(visibility);
	//alert(visibility);
	var e = document.getElementById(divId);
	var tmp='';
	var ca = document.cookie.split(';');
	//alert(document.cookie);
	s="";
	var check=0;
	tmp+="<div id=\"dummy0\">";
	for(var i=0; i < ca.length; i++) {
		if(ca[i].indexOf('@italimar@')>0){
			s=ca[i];
			//alert(s);
			a=s.split('=');
			tmp+="<div id=\"fcontainerRow\">";
			tmp+="<div id=\"fleft\">";
			aa=a[1].split('|');
			//alert(aa[0]);
			var language=aa[0];
			language=language.substr(10,12);
			region=aa[1];
			if(region.length>15)region=region.substr(0,15)+" ...";
			regionSlug=unescape(aa[4]);
			accommodation=unescape(aa[2]);
			if(accommodation.length>30)accommodation=accommodation.substr(0,36)+" ...";
			accommodationSlug=aa[3];
			tmp+="<div id=\"fleft0\">";
			tmp+=region;
			tmp+="</div>";
			tmp+="<div id=\"fleft1\">";
			tmp+="<a href=\" /"+language+"/"+regionSlug+"/"+accommodationSlug+"/ \">";
			tmp+=accommodation;
			tmp+="</a>";
			tmp+="</div>";
			tmp+="</div>";
			tmp+="<div id=\"fright\">";
			tmp+="<a href=\"javascript:eraseCookie('"+a[0]+"','"+divId+"');\"><img src=\"/img/favorites-delete.gif\" border=\"0\"></a>";
			tmp+="</div>";
			tmp+="</div>";
			check=1;
		}
	}
	tmp+="<div id=\"shadow\"></div>";
	tmp+="</div>";
	if(i==0) hideDiv(divId);
	if(visibility==1){
		e.style.display='block';
		if(document.getElementById('iconlistFavorites1'))f=document.getElementById('iconlistFavorites1');
		f.style.backgroundColor='#faf8ee';
		showDiv(divId,tmp);
	}
	else{
		if(e.style.display=='block'){
			hideDiv(divId);
			if(document.getElementById('iconlistFavorites1'))f=document.getElementById('iconlistFavorites1');
			f.style.backgroundColor='#eFE8C7';
			if(document.getElementById('categoria'))document.getElementById('categoria').style.display='block';
		}else{
			if(check>0){
				if(document.getElementById('iconlistFavorites1'))f=document.getElementById('iconlistFavorites1');
				f.style.backgroundColor='#fff';
				if(document.getElementById('categoria'))document.getElementById('categoria').style.display='none';
				showDiv(divId,tmp);
			}
		}

		/*
		if(i>1){
			if(e.style.display=='block'){
				hideDiv(divId);
				if(document.getElementById('iconlistFavorites'))f=document.getElementById('iconlistFavorites');
				f.style.backgroundColor='#EFE8C7';
				if(document.getElementById('categoria'))document.getElementById('categoria').style.display='block';
			}else{
				if(check>0){
					if(document.getElementById('iconlistFavorites'))f=document.getElementById('iconlistFavorites');
					f.style.backgroundColor='#faf8ee';
					if(document.getElementById('categoria'))document.getElementById('categoria').style.display='none';
					showDiv(divId,tmp);
				}
			}
		}
		*/
	}
}
function showDiv(divId,s){
	var e = document.getElementById(divId);
	// visibility block
	e.style.display='block';
	e.innerHTML=s;
}
function hideDiv(divId){
	var e = document.getElementById(divId);
	// visibility block
	e.style.display='none';
}

function eraseCookie(name,divId) {
	createCookie(name, "", -1,divId);

	check=0;
	var ca = document.cookie.split(';');
	for(var i=1; i < ca.length; i++) {
		if(document.cookie.indexOf('@italimar@')>0)check=1;
	}
	//alert(check);
	viewAllCookies(divId,check);
}


function readCookie(name) {
	var ca = document.cookie.split(';');
	var nameEQ = name + "=";
	for(var i=0; i < ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
	return "";
}

/*** Temporary text filler function. Remove when deploying template. ***/
function orderByPrice(i,f){
	f.f_orderByPrice.value=i;
	f.submit();
	return 0;
}
var gibberish=["This is just some filler text", "Welcome to Dynamic Drive CSS Library", "Demo content nothing to read here"]
function filltext(words){
	for (var i=0; i<words; i++)
		document.write(gibberish[Math.floor(Math.random()*3)]+" ")
}
function resetfunction(){
	document.filterform.reset.value=1;
	document.filterform.submit();
	return 0;
}
function whatBrowser() {
	var tmp="";
	/*
	tmp+=navigator.appName;
	tmp+="\n";
	tmp+=navigator.appVersion;
	tmp+="\n";
	tmp+=navigator.appCodeName;
	tmp+="\n";
	*/
	tmp+=navigator.userAgent;
	alert(tmp);
}
/** funzioni per il rollover - mappa link **/
function rolloverLinkIn(mappa,rolloverClass){
		document.getElementById(mappa).className=rolloverClass;
}
function rolloverLinkOut(mappa,startClass){
		document.getElementById(mappa).className=startClass;
}
/*
 * Modal popup
 */
function revealModal(divID,divHide1,divHide2,divHide3) {
	window.onscroll = function () { document.getElementById(divID).style.top = document.body.scrollTop;};
	if (navigator.appName == "Microsoft Internet Explorer"){
		document.getElementsByTagName("html")[0].style.overflow="hidden";
	}else{
		document.body.style.overflow="hidden";
	}
	document.getElementById(divHide1).style.display = "none";
	document.getElementById(divHide2).style.display = "none";
	document.getElementById(divHide3).style.display = "none";
	document.getElementById(divID).style.display = "block";
	document.getElementById(divID).style.top = document.body.scrollTop;
	document.getElementById(divID).style.zIndex = 0;
}

function hideModal(divID,divHide1,divHide2,divHide3) {
	if (navigator.appName == "Microsoft Internet Explorer"){
		document.getElementsByTagName("html")[0].style.overflow="auto";
	}else{
		document.body.style.overflow="visible";
	}
	document.getElementById(divID).style.display = "none";
	document.getElementById(divHide1).style.display = "block";
	document.getElementById(divHide2).style.display = "block";
	document.getElementById(divHide3).style.display = "block";
}
function changeStyle(id,classe){
	var element=document.getElementById(id);
	//Si associa la classe corrispondente
	element.className=classe;
}
function showhide2(str,attivo,stridicon) {
	//str contiene tutti gli elementi da nascondere o da mostrare
	if(str.length>0){
		var tmp2='block';
		if(attivo==0) tmp2='none';
		var arr=str.split(",");
		if(attivo==undefined){
			var tmp=document.getElementById(arr[0]).style.display;
			if(tmp=='block')tmp2='none';
		}
		for(var i=0;i<arr.length;i++){
			document.getElementById(arr[i]).style.display=tmp2;
		}
	}
}
function changeaction(f,url){
	var str2=f.f_str.value.replace(/ /g,'-');
	f.action=escape(url+"/-"+str2);
	f.action=(url+"/-"+str2);
	f.submit();
	return 0;
}
function listaselezionati(f,nameogg){
	var s="null";
	var t="";
	for(var i=0; i<f.elements.length;i++)
	{
		var e = f.elements[i];
		if(e.name=='f_'+nameogg && e.checked){
			t+=e.value + ";";
		}
	}
	if(t!="")s=t;
	return s;
}
function costruiscifgeneralPosition(f){
	f.f_generalPosition2.value=listaselezionati(f,"generalPosition");
}
function costruiscifgeneralAccommodationTipology(f){
	f.f_generalAccommodationTipology2.value=listaselezionati(f,"generalAccommodationTipology");
}
function costruiscifservizi_icone2(f){
	f.f_servizi_icone2.value=listaselezionati(f,"servizi_icone");
}
