

function goHome()
{
	window.location.href = "/ES";
}

function gotoUrl(urlToGoTo)
{
	window.location.href = urlToGoTo;
}


var lastMnuOppened = null;

function hideMnuSel()
{
		if(lastMnuOppened )
		{
			if(lastMnuOppened.className != "upBtnSelected")
			{
				lastMnuOppened.style.color = "white";
				lastMnuOppened.style.backgroundColor = "#CC0033";
				if(document.getElementById("N" + lastMnuOppened.id))
				{	
					document.getElementById("N" + lastMnuOppened.id).style.borderLeft = "solid 1px white";
				}
			}
			
			document.getElementById("DD:" + lastMnuOppened.id).style.visibility =  "hidden";
			lastMnuOppened=null;
		}
}

function gotoPage(sdir)
{
	window.location.href = "/ES/" + sdir ;
}

function showMenu(element)
{
	if(element!=lastMnuOppened)
	{
		hideMnuSel();
	
		element.style.backgroundColor = "white";
		element.style.color = "#CC0033";
		
		if(document.getElementById("N" + element.id))
		{	
			document.getElementById("N" + element.id).style.borderLeft = "none 1px transparent";
		}
		document.getElementById("DD:" + element.id).style.visibility =  "visible";
		
		lastMnuOppened = element;	
	}
}

function unHightLight(object)
{
	if(object.className != "subElementSelected")
	{
		object.style.color = "white";
		object.style.backgroundColor = "#CC0033";	
	}
}

function hightLight(object)
{
	object.style.color = "#CC0033";
	object.style.backgroundColor = "white";	
}

function autoHideMnu(e)
{
	if(lastMnuOppened )
	{
		if (IE) { 
			tempX = event.clientX + document.body.scrollLeft
			tempY = event.clientY + document.body.scrollTop
		} else {  
			tempX = e.pageX
			tempY = e.pageY
		}  
		
		if (tempX < 0){tempX = 0}
		if (tempY < 0){tempY = 0} 
		
		if (tempX < findPosX(lastMnuOppened))
		{
	
			hideMnuSel();
		} else  {
			if (tempX > (findPosX(lastMnuOppened) + document.getElementById("DD:" + lastMnuOppened.id).offsetWidth))
			{
				hideMnuSel();
			} else {
				if (tempY > (findPosY(lastMnuOppened) + document.getElementById("DD:" + lastMnuOppened.id).offsetHeight) + lastMnuOppened.offsetHeight)
				{
					hideMnuSel();
				} else {
					if (tempY < 20)
					{
						hideMnuSel();
					}
				}
			}
			
		}
		
	}
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function SelPag(obj)
{
	obj.style.color = "#CCCCCC";
	obj.style.backgroundColor = "#CC0033";	
}

function UnSelPag(obj)
{
	obj.style.color = "#999999";
	obj.style.backgroundColor = "white";	
}

var IE = document.all?true:false

if (!IE) document.captureEvents(Event.MOUSEMOVE)

document.onmousemove = autoHideMnu;

var tempX;
var tempY;


function ShowAutor(authorID)
{
	document.getElementById("authorID").value == authorID;
	document.getElementById("form").action = "/ES/Autores/AutoresRepresentados/IndiceDeAutores_" + authorID;
	document.getElementById("form").submit();
}

function tumbOver(object)
{
	object.style.color= "#CC0000";
	object.style.borderColor = "#CC0000";	
}


function tumbOut(object)
{
	object.style.color= "#666666";	
	object.style.borderColor = "#FFFFFF";
}

function ShowAlf(currentKey)
{
	document.getElementById("currentKey").value = currentKey;	
	document.getElementById("form").action = "/ES/Autores/AutoresRepresentados/IndiceDeAutores";
	document.getElementById("form").submit();
}

function setAltLang(key)
{
	document.getElementById("altLang").value = key;	
	document.getElementById("form").submit();
}

function DoSearch()
{
	if(document.getElementById("buscar").value != "")
	{
		document.getElementById("form").action = "/ES/Resultados";
		document.getElementById("form").submit();
	}
}

function SendForm(requiredFields)
{
	var AllOK = true;
	var lst = requiredFields.split('|');
	for(cnt=0;cnt<lst.length;cnt++)
	{
		if(lst[cnt].length>0)
		{
			if(document.getElementById(lst[cnt]).value=="")
			{
				alert("Es necesario cumplimentar este campo");				
				document.getElementById(lst[cnt]).focus();
				return false;
			}
			if (lst[cnt].indexOf("mail") > -1)
			{
				if(!validate(document.getElementById(lst[cnt]).value))
				{
					document.getElementById(lst[cnt]).focus();
					return false;
				}
			}
		}

	}	
	
	document.getElementById("formAction").value = "send";
	document.getElementById("form").submit();
}

function validate(strEmail)
{
	validRegExp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;

	if (strEmail.search(validRegExp) == -1) 
	{
		alert('Dirección de correo electrónico incorrecta.');
		return false;
	} 
	
	return true;
}



function LoginBi()
{
	if(document.getElementById("usuario").value != "")
	{
		if(document.getElementById("password").value != "")
		{
			document.getElementById("formAction").value ="Login";
			document.getElementById("form").action = "http://www.bi.vegap.es/Sesion";
			document.getElementById("form").submit();
		} else {
			alert("Es necesario introducir la contraseña.");
			document.getElementById("password").focus();
		}
	} else {
		alert("Es necesario introducir el nombre de usuario.");
		document.getElementById("usuario").focus();
	}
	
}



function NextStepForm(requiredFields)
{
	var AllOK = true;
	var lst = requiredFields.split('|');
	for(cnt=0;cnt<lst.length;cnt++)
	{
		if(lst[cnt].length>0)
		{
			if(document.getElementById(lst[cnt]).value=="")
			{
				alert("Es necesario cumplimentar este campo");				
				document.getElementById(lst[cnt]).focus();
				return false;
			}
			if (lst[cnt].indexOf("mail") > -1)
			{
				if(!validate(document.getElementById(lst[cnt]).value))
				{
					document.getElementById(lst[cnt]).focus();
					return false;
				}
			}
		}

	}	
	
	document.getElementById("formAction").value = "NextStepForm";
	document.getElementById("form").submit();
}

function NextStepForm2()
{
	if(document.getElementById("SOPORTE_E").checked || document.getElementById("SOPORTE_A").checked || document.getElementById("SOPORTE_S").checked || document.getElementById("SOPORTE_R").checked || document.getElementById("SOPORTE_M").checked || document.getElementById("SOPORTE_U").checked)
	{
		document.getElementById("formAction").value = "NextStepForm2";
		document.getElementById("form").submit();
	} else {
		alert("Es necesario seleccionar al menos un uso");
	}
}

function NextStepForm3()
{
	document.getElementById("formAction").value = "NextStepForm3";
	document.getElementById("form").submit();
}

function onLegalAccept(element)
{	
	if(element.checked)
	{
		document.getElementById("mailBtn").disabled = "";
	} else {
		document.getElementById("mailBtn").disabled = "disabled";
	}
}