
//************
// IDIOMES
//************

var TimeoutIdiomas=0;
function mostraDivIdiomas()
{
	anulaOcultaDivIdiomas();
	if (document.getElementById("divIdiomas").style.display != "block"){
		document.getElementById("divIdiomas").style.display="block";
	}
}
function ocultaDivIdiomas()
{
	anulaOcultaDivIdiomas();
	TimeoutIdiomas=setTimeout("_ocultaDivIdiomas();",300);
}

function _ocultaDivIdiomas()
{
	document.getElementById("divIdiomas").style.display="none";
}
function anulaOcultaDivIdiomas()
{
	if(TimeoutIdiomas!=0)
	{
		clearTimeout(TimeoutIdiomas);
		TimeoutIdiomas=0;
	}

}



//******************
// EFECTES ALPHA
//******************

function canviaAlpha(idObj, a){
	var obj = document.getElementById(idObj);
	if(obj){
		obj.style.opacity = a;
	 	obj.style.filter = 'alpha(opacity='+ a*100 +')';
	 }
}

var AlphaFade = Array();
function canviaAlphaFade(idObj, aIni, aFi, inc)
{
	if (typeof AlphaFade[idObj] == "undefined") AlphaFade[idObj] = Array();
	AlphaFade[idObj]["obj"] = document.getElementById(idObj);
	if(AlphaFade[idObj]["obj"]) {
		var op = parseFloat(AlphaFade[idObj]["obj"].style.opacity);
		if (!isNaN(op)) {
			aIni = op;
		}
		if (typeof AlphaFade[idObj]["timer"] != "undefined" && AlphaFade[idObj]["timer"] != 0) {
			clearTimeout(AlphaFade[idObj]["timer"]);
		}
		AlphaFade[idObj]["timer"] = 0;
		_canviaAlphaFade(idObj, aIni, aFi, inc);
	}
}
function _canviaAlphaFade(idObj, a, aFi, inc){
	if(AlphaFade[idObj]["obj"]){
		a += inc;
		if (inc > 0 && a > aFi) a = aFi;
		else if (inc < 0 && a < aFi) a = aFi;

		AlphaFade[idObj]["obj"].style.opacity = a;
	 	AlphaFade[idObj]["obj"].style.filter = 'alpha(opacity='+ a*100 +')';
	 	if (a == aFi){
	 		AlphaFade[idObj]["timer"] = 0;
	 	}
	 	else{
		 	clearTimeout(AlphaFade[idObj]["timer"]);
		 	AlphaFade[idObj]["timer"] = setTimeout("_canviaAlphaFade('"+idObj+"', "+a+", "+aFi+", "+inc+");", 50);
		}
	 }
}


//******************************
// SUBMIT RECOMENAR A UN AMIC
//******************************
function onSubmitRecomendar()
{
	alert("aquí s'ha d'enviar un email via AJAX i notifica del resultat");
	return false;
}

function tractaRecommendFriend(xmldoc)
{
	document.getElementById("sending").style.display="none";
	if(xml_unescape(xml_consultaDada(xmldoc.getElementsByTagName("resultat").item(0)))!="OK")
	{
		document.getElementById("resMailError").innerHTML=xml_unescape(xml_consultaDada(xmldoc.getElementsByTagName("resultat").item(0)));
		document.getElementById("resMail").style.display="none";
		document.getElementById("resMailError").style.display="block";
		return;
	}
	var res=xml_unescape(xml_consultaDada(xmldoc.getElementsByTagName("res").item(0)));
	document.getElementById("resMail").innerHTML=res;
	document.getElementById("resMail").style.display="block";
	document.getElementById("resMailError").style.display="none";
	document.getElementById("nomRemitent").value="";
	document.getElementById("emailAmic").value="";
	return 1;
}



//******************************
// TOGGLE BUSCADOR
//******************************
var showed= 1;
var divWidth = 0;
function buscadorHout(elem){

	if (showed==1){
		document.getElementById("fletxa").src=nh+"img/fletxa-amaga-buscador.gif";

	}else{

		document.getElementById("fletxa").src=nh+"img/fletxa-mostra-buscador.gif";
	}

}

function buscadorHover(elem){

	if (showed==1){

		document.getElementById("fletxa").src=nh+"img/"+HOST+"/fletxa-amaga-buscador-hover.png";

	}else{
		document.getElementById("fletxa").src=nh+"img/"+HOST+"/fletxa-mostra-buscador-hover.png";
	}

}

function toggleBuscador()
{
	var fxMorph = new Fx.Morph($('containerBuscadorDiv'),{
			duration: 500,
			transition: 'cubic:in:out'
	});
	if(showed==1)
	{

		document.getElementById("fletxa").src=nh+"img/fletxa-mostra-buscador.gif";

		divWidth = $('containerBuscadorDiv').getStyle('width');

		fxMorph.start({
			'width':0,'opacity':0.4
		});
		showed=0;
	}
	else
	{

		document.getElementById("fletxa").src=nh+"img/fletxa-amaga-buscador.gif";

		fxMorph.start({
			'width':divWidth,
			'opacity':1
		});
		showed=1;
	}
}
