var dom = document.getElementById ? true:false;
var ns = navigator.appName.indexOf("Netscape")!=-1 ? true:false;
var ns4 = document.layers ? true:false;
var ie4 = document.all ? true:false;
var mac = navigator.appVersion.indexOf("Mac")!=-1 ? true:false;

function preload(imgObj,imgSrc) {
	eval(imgObj+" = new Image()");
	eval(imgObj+".src = '"+imgSrc+"'");
}

function changeImg(imgObj,imgSrc) {
	if (navigator.appVersion >= "3") {
		var imatge = eval(imgSrc+".src");
		document.images[imgObj].src = imatge;
	}
}

function canviarImatge(id,com) {
	if (id!=opcio_activa) {
		changeImg("imatge_"+id,"imatge_"+id+"_"+com);
	}
}

function canviarOpcio(opcio,subopcio,subsubopcio) {
	window.location = "http://www.empordagolf.com/index.php?l="+l+"&opcio="+opcio+"&subopcio="+subopcio+"&subsubopcio="+subsubopcio;
}

function mostrarFotosTorneig(id) {
	if (document.getElementById("fotos_"+id).style.display=="none") {
		window.location = "#torneig_"+id;
		document.getElementById("fotos_"+id).style.display = "";
		if (document.getElementById("thumbs_"+id).innerHTML=="") {
			document.getElementById("thumbs_"+id).innerHTML = "<p style=\"line-height: 0px;\">"+links_fotos[id]+"</p>";
			visionarFotoTorneig(primera_foto[id],id);
		}
	} else {
		document.getElementById("fotos_"+id).style.display = "none";
	}
}

function visionarFotoTorneig(foto,id) {
	document.getElementById("visor_"+id).innerHTML = '<img src="torneigs/fotos/g/'+foto+'_'+id+'.jpg" width="559" height="379" alt="" />';
}

function visionarFoto(id,carpeta) {
	document.getElementById('visor_album').innerHTML = '<img src="imatges/'+carpeta+'/g/'+id+'.jpg" alt="" />';
}

function visionarFotoCompeticions(id,visor) {
	document.getElementById('visor_album_'+visor).innerHTML = '<img src="imatges/competicions/g/'+id+'.jpg" width="559" height="372" alt="" />';
}

function visionarFotoResidencial(id) {
	document.getElementById('visor_album').innerHTML = '<img src="imatges/residencial/'+id+'.jpg" width="559" height="234" alt="" />';
}

function visionarFotoHotel(id) {
	document.getElementById('visor_album').innerHTML = '<img src="imatges/hotel/'+id+'.jpg" width="559" alt="" />';
}

function obrirHtmlWindow(url,titol) {
	titol = "<span class=\"blanc\">"+titol+"</span>";
	if (dom) {
		document.getElementById('dwindowtitol').innerHTML = titol;
	} else if (ie4) {
		dwindowtitol.innerHTML = titol;
	}
	loadwindow(url,260,300);
}

function canviarApartament(id) {
	if (id>0) {
		text = maxim+" "+nombre_persones[id]+" "+persones;
	} else {
		text = "";
	}
	document.getElementById('personess').innerHTML = text;
}

var y, x;
function mouseMove(e) {
	y = (ns)? e.pageY : event.y+document.body.scrollTop;
	x = (ns)? e.pageX : event.x+document.body.scrollLeft;
	return true;
}

function mostrarDia(dia) {
	document.getElementById('visor').innerHTML = "<table style=\"width: 200px;\">"+dies[dia]+"</table>";
	document.getElementById('visor').style.left = (x-100)+"px";
	document.getElementById('visor').style.top = (y-10)+"px";
	document.getElementById('visor').style.visibility = "visible";
}

function init() {
	if (opcio_activa!=0) {
		document.getElementById('fake').style.borderTop = "1px solid #656364";
	}
	if (opcio_activa<=11) {
		changeImg("imatge_"+opcio_activa,"imatge_"+opcio_activa+"_on");
	}
	if (document.all) for (var i in document.links) document.links[i].onfocus = document.links[i].blur;
	document.onmousemove = mouseMove;
}

function canviarIdioma(l) {
	saveCookie('habitat_emporda_l',l,360);
	window.location = "http://www.empordagolf.com/index.php?l="+l+"&opcio="+opcio_activa+"&subopcio="+subopcio_activa;
}

function mostrarTab(id) {
	var tab = document.getElementById("tab_"+id+"Div");
	if (tab.style.display=="none") {
		tab.style.display = "";
	} else {
		tab.style.display = "none";
	}
}

function saveCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else {
		expires = "";
	}
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name+"=";
	var ca = document.cookie.split(';');
	for(var i=0;i<ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function deleteCookie(name) {
	saveCookie(name,"",-1);
}

function obrirPopUp(url,nom,ww,hh,xx,yy,toolbarx,directoriesx,statusbarx,scrollbarsx,menubarx) {
	eval(nom+"=window.open('"+url+"','"+nom+"','toolbar="+toolbarx+",directories="+directoriesx+",status="+statusbarx+",scrollbars="+scrollbarsx+",menubar="+menubarx+",width="+ww+",height="+hh+",left="+xx+",top="+yy+",x="+xx+",posy="+yy+"')");
}

preload("imatge_es_on","../gbanner/_EPO/es_on.gif");
preload("imatge_es_off","../gbanner/_EPO/es_off.gif");
preload("imatge_ca_on","../gbanner/_EPO/ca_on.gif");
preload("imatge_ca_off","../gbanner/_EPO/ca_off.gif");
preload("imatge_en_on","../gbanner/_EPO/en_on.gif");
preload("imatge_en_off","../gbanner/_EPO/en_off.gif");
preload("imatge_fr_on","../gbanner/_EPO/fr_on.gif");
preload("imatge_fr_off","../gbanner/_EPO/fr_off.gif");

var compte_mapa = 1;
function ampliarMapa(com) {
	if (com=='menys') {
		compte_mapa -= 1;
		if (compte_mapa<1) {
			compte_mapa = 1;
		}
	} else {
		compte_mapa += 1;
		if (compte_mapa>7) {
			compte_mapa = 7;
		}
	}
	changeImg('imatge_mapa','mapa_'+compte_mapa);
}

function canviarTemporada(id) {
	document.getElementById('alta').style.display = "none";
	document.getElementById('mitja').style.display = "none";
	document.getElementById('baixa').style.display = "none";
	document.getElementById(id).style.display = "";
}
