// JavaScript Document

function correu(buzon) {
var res = "";
for (var n = 0; n < buzon.length; n++)
res += String.fromCharCode(buzon.charCodeAt(n));
if (res.indexOf('@') < 0)
res = res + '@' + 'ispa.es';
location = "mail" + "to:" + res;
}

function abrir_ventana(href,target,ancho,alto){

    var izquierda = (screen.availWidth - ancho) / 2;
    var arriba = (screen.availHeight - alto) / 2; 
	ventana=window.open(href , target , "fullscreen=0 , toolbar=0 , location=1 , status=0 , menubar=0 , scrollbars=1 , resizable=0 , width="+ancho+" , height="+alto+" , left=" + izquierda + " , top=" + arriba , false);
}

function entra() //es pel formulari de login
{
	createCookie("val",document.f.idioma.value,30);
	document.f.submit();
	return true;
}
function createCookie(name,value,days)
{
	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+"="+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;
}

/*hack per IE6 que no enten que l'element LI pugui tenir una propietat d'estil :hover*/
/* Hem d'aprofundir en el nivell de LIs fins que arribem als pares dels quals s'ha d'aplicar la propietat over*/
startList = function() {
if (document.all&&document.getElementById) 
{
	navRoot = document.getElementById("nav");
	for (i=0; i<navRoot.childNodes.length; i++) 
	{
		node = navRoot.childNodes[i];
		//alert(node.innerText);
		if (node.nodeName=="LI") 
		{
			navLI = node;
			for (j=0; j<navLI.childNodes.length; j++) 
			{
				node = navLI.childNodes[j];
				if (node.nodeName=="UL") 
				{
					navUL = node;
					for (k=0; k<navUL.childNodes.length; k++) 
					{
						node = navUL.childNodes[k];
						if (node.nodeName=="LI") 
						{
					
							node.onmouseover=function() 
							{
								this.className+=" over";
							}
							node.onmouseout=function() 
							{
								this.className=this.className.replace(" over", "");
							}
						}
					}

				}
			}
	   }
  	}
	/*creo també el hack per ie en un element concret, no ho faig servir perň es com a exemple*/
	ad = document.getElementById("ad_psico");
	ad.onmouseover=function() 
							{
								this.className+=" over";
							}
							ad.onmouseout=function() 
							{
								this.className=this.className.replace(" over", "");
							}
 }
 
//incloc la lectura de cookies aqui
var galeta=readCookie("val");
if (document.getElementById("idioma"))//el form de login no apareix sempre i s'ha de verificar que existeixi
{
	if (galeta=="ca")
		document.forms.f.idioma.options[1].selected=true;
	else
		document.forms.f.idioma.options[0].selected=true;
}

}
window.onload=startList;

function getReturnData( data , statusCode ) {
			 	if( statusCode != AJForm.STATUS['SUCCESS'] ) {
			 	 //AJFORM failed. Submit form normally.
				 return true;
			 	}
				else
				{
					alert(data);
					//document.getElementById('form1').innerHTML = data;
					document.form1.reset();
				}
}
