// JavaScript Document

function replace(texto,s1,s2)
{
	return texto.split(s1).join(s2);
}

function cambiaImagen(imagen, tipo)
{
	var nomimagen=new String();
	nomimagen=imagen.src;
	if (tipo==0)
	{
		nomimagen=replace(nomimagen, ".jpg", "_sel.jpg");
	}
	else
	{
		nomimagen=replace(nomimagen, "_sel.jpg", ".jpg");
	}
	
	imagen.src=nomimagen;
}

function cambiaImagenGIF(imagen, tipo)
{
	var nomimagen=new String();
	nomimagen=imagen.src;
	if (tipo==0)
	{
		nomimagen=replace(nomimagen, ".gif", "_sel.gif");
	}
	else
	{
		nomimagen=replace(nomimagen, "_sel.gif", ".gif");
	}
	
	imagen.src=nomimagen;
}

function getOffsetLeft (el) {
  var ol = el.offsetLeft;
  while ((el = el.offsetParent) != null)
    ol += el.offsetLeft;
  return ol;
}
function getOffsetTop (el) {
  var ot = el.offsetTop;
  while((el = el.offsetParent) != null)
   ot += el.offsetTop;
  return ot;
}

var capas=new Array(4);
var posiciones=new Array(4);
var estados=new Array(4);

capas[0]="floatqs";
posiciones[0]="posqs";
estados[0]=0;
capas[1]="floatop";
posiciones[1]="posop";
estados[1]=0;
capas[2]="floatis";
posiciones[2]="posis";
estados[2]=0;
capas[3]="floatep";
posiciones[3]="posep";
estados[3]=0;

function mostrarOcultar(capa)
{
	for (i=0; i<capas.length; i++)
	{
		if (i==capa)
		{
			if (estados[i]==0)
			{
				document.getElementById(capas[i]).style.visibility="visible";
				document.getElementById(capas[i]).style.display="block";
				document.getElementById(capas[i]).style.left=getOffsetLeft(document.getElementById(posiciones[i]))+"px";
				document.getElementById(capas[i]).style.top=(getOffsetTop(document.getElementById(posiciones[i]))-document.getElementById(capas[i]).offsetHeight)+"px";
				estados[i]=1;
			}
			else
			{
				document.getElementById(capas[i]).style.visibility="hidden";
				document.getElementById(capas[i]).style.display="none";
				estados[i]=0;
			}
		}
		else
		{
			if (estados[i]==1)
			{
				document.getElementById(capas[i]).style.visibility="hidden";
				document.getElementById(capas[i]).style.display="none";
				estados[i]=0;
			}
		}
	}
}

function ponerFlash (archivoSWF, ancho, alto, textonoembed)
{ 
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="pelicula" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + ancho + '" height="' + alto + '">'); 
	document.write('<param name="movie" value="' + archivoSWF + '" />'); 
	document.write('<param name="quality" value="high" />'); 
	document.write('<param name="wmode" value="transparent" />'); 
	document.write('<embed src="' + archivoSWF + '" width="' + ancho + '" height="' + alto + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" wmode="transparent"></embed>'); 
	document.write('<noembed>' + textonoembed + '</noembed>');
	document.write('</object>'); 
}

function trim(texto)
{
	var longitud=texto.length;
	var i;
	var j;
	
	if (texto=="undefined")
	{
		return "";
	}
	for (i=0; i<longitud; i++){
		if (texto.substring(i,i+1)!==" "){
			break;
		}
	}
	for (j=longitud; j>0; j--){
		if (texto.substring(j-1,j)!==" "){
			break;
		}
	}
	if (j==0) {
		texto = "";
	}else{
		texto = texto.substring(i,j);
	}
	return texto;
}

function check_email (email) 
{
	// Por defecto, se entiende que la dirección de e-mail es correcta

	// 1 - Que la dirección contenga únicamente caracteres válidos
	allowed_chars = new Array ("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ".", "@", "_", "-");
	for (i = 0; i < email.length; i++) 
	{
		comparations = 0;
		for (j = 0; j < allowed_chars.length; j++) 
		{
			if ((email.charAt (i) != allowed_chars [j]) && (email.charAt (i) != allowed_chars [j].toUpperCase()))
			{
				comparations++;
			} 
			else 
			{
				break;
			}
		}
		if (comparations == allowed_chars.length) 
		{
			return (false);
		}
	}
	delete allowed_chars;

	
	// 2 - Comprobación de uso de una única arroba
	count_arrobas = 0;
	for (i = 0; i < email.length; i++) 
	{
		if (email.charAt (i) == '@') 
		{
			count_arrobas++;
		}
	}
	if (count_arrobas != 1) 
	{
		return (false);
	}
	

	// 3 - Comprobación de dominios
	haypunto=false
	for (i = email.length-5; i < email.length-2; i++) 
	{
		if (email.charAt (i) == '.') 
		{
			haypunto=true;
		}
	}
	if (haypunto)
	{
		return (true);
	}
	else
	{
		return(false);
	}
}

function mostrarProyecto(codPr)
{
	for (i=1; i<=3; i++)
	{
		if (i==codPr)
		{
			document.getElementById("proyecto" + i).style.visibility="visible";
			document.getElementById("proyecto" + i).style.display="block";
			document.getElementById("imgproyecto" + i).src="img/bt_proyecto" + i + "_sel.jpg"
		}
		else
		{
			document.getElementById("proyecto" + i).style.visibility="hidden";
			document.getElementById("proyecto" + i).style.display="none";
			document.getElementById("imgproyecto" + i).src="img/bt_proyecto" + i + ".jpg"
		}
	}
}

function enviaDatos()
{
	document.getElementById("formdatos").submit();
}

function altaCurriculum()
{
	if (trim(document.getElementById("nestudios1").value)==1)
	{
		alert ("Debe seleccionar nivel de estudios");
		document.getElementById("nestudios1").focus();
		return;
	}	
	if (trim(document.getElementById("destudios1").value)=="")
	{
		alert ("Debe introducir la descripcion del nivel de estudios");
		document.getElementById("destudios1").focus();
		return;
	}
	if (trim(document.getElementById("festudios1").value)=="")
	{
		alert ("Debe introducir la fecha del nivel de estudios");
		document.getElementById("festudios1").focus();
		return;
	}
	if (trim(document.getElementById("nestudios2").value)!=1)
	{
		if (trim(document.getElementById("destudios1").value)=="")
		{
			alert ("Debe introducir la descripcion del nivel de estudios");
			document.getElementById("destudios1").focus();
			return;
		}
		if (trim(document.getElementById("festudios1").value)=="")
		{
			alert ("Debe introducir la fecha del nivel de estudios");
			document.getElementById("festudios1").focus();
			return;
		}
	}
	if (trim(document.getElementById("nestudios3").value)!=1)
	{
		if (trim(document.getElementById("destudios3").value)=="")
		{
			alert ("Debe introducir la descripcion del nivel de estudios");
			document.getElementById("destudios3").focus();
			return;
		}
		if (trim(document.getElementById("festudios3").value)=="")
		{
			alert ("Debe introducir la fecha del nivel de estudios");
			document.getElementById("festudios3").focus();
			return;
		}	
	
	}
	document.formcurriculum.submit();
}

