// JavaScript Document

function activa(activa){
	var activa=activa;	
	switch (activa){
		case 'congreso':
			document.getElementById('pes_con').className="pestana_on_con";
			document.getElementById('pes_soc').className="pestana_off";	
			document.getElementById('pes_tec').className="pestana_off";
			document.getElementById('pes_gey').className="pestana_off";
			
			document.getElementById('menu_con2').style.display="none";
			document.getElementById('menu_con').style.display="block";
			document.getElementById('menu_soc').style.display="none";
			document.getElementById('menu_tec').style.display="none";
			document.getElementById('menu_gey').style.display="none";
			break;
		case 'sociedad':						
			document.getElementById('pes_con').className="pestana_off";
			document.getElementById('pes_soc').className="pestana_on_soc";	
			document.getElementById('pes_tec').className="pestana_off";
			document.getElementById('pes_gey').className="pestana_off";
			
			document.getElementById('menu_con2').style.display="none";
			document.getElementById('menu_con').style.display="none";
			document.getElementById('menu_soc').style.display="block";
			document.getElementById('menu_tec').style.display="none";
			document.getElementById('menu_gey').style.display="none";
			break;			
		case 'tecnologia':				
			document.getElementById('pes_con').className="pestana_off";
			document.getElementById('pes_soc').className="pestana_off";	
			document.getElementById('pes_tec').className="pestana_on_tec";
			document.getElementById('pes_gey').className="pestana_off";
			
			document.getElementById('menu_con2').style.display="none";
			document.getElementById('menu_con').style.display="none";
			document.getElementById('menu_soc').style.display="none";
			document.getElementById('menu_tec').style.display="block";
			document.getElementById('menu_gey').style.display="none";
			break;			
		case 'geyseco':			
			document.getElementById('pes_con').className="pestana_off";
			document.getElementById('pes_soc').className="pestana_off";	
			document.getElementById('pes_tec').className="pestana_off";
			document.getElementById('pes_gey').className="pestana_on_gey";
			
			document.getElementById('menu_con2').style.display="none";
			document.getElementById('menu_con').style.display="none";
			document.getElementById('menu_soc').style.display="none";
			document.getElementById('menu_tec').style.display="none";
			document.getElementById('menu_gey').style.display="block";
			break;			
	}
	activa = activa.substr(0,3);
	document.getElementById('menu_'+activa).style.display="block";
	document.getElementById('linea_con').className='linea_'+activa;
	document.getElementById('linea_soc').className='linea_'+activa;
	document.getElementById('linea_tec').className='linea_'+activa;
	document.getElementById('linea_gey').className='linea_'+activa;

	document.getElementById('linea_vacio_1').className='linea_'+activa;
	document.getElementById('linea_vacio_2').className='linea_'+activa;
	document.getElementById('linea_vacio_3').className='linea_'+activa;
	
}




function enviar_formulario (xxx){
	formulario=document.getElementById(xxx);
	valor= comprobar_campos(formulario,0);
	if (valor) formulario.submit();
}

function verifica_mail(t_mail)
{
	if ((t_mail.lastIndexOf(" ")!=-1) || (t_mail.lastIndexOf("@")==-1) || (t_mail.lastIndexOf(".")<=(t_mail.lastIndexOf("@")+1)) || (t_mail.lastIndexOf(".")==(t_mail.length-1))) return false;
		else return true;
}

function comprobar_campos(formulario, check)
{
	for (var i=0;i<formulario.elements.length;i++)
	{
		var e = formulario.elements[i],bvar;
		var valor;
		//alert(e.id);
		
		if ((e.id=="requerido-Nombre Usuario")){
			re = /^[a-zA-Z0-9\s]*$/
					
			if (!re.test(e.value)){
				alert("Solo se admiten letras sin acentuar y numeros");
				e.focus();
				return false;
			}
		}
		valor=e.id.split("-");
			if (valor[0]=="requerido")
			{
				
				if (e.value=="")
				{
					if ((valor[1]=="Otro")||(valor[1]=="Otra"))
					{
						if (valor[1]=="Otro"){	
							if (formulario.direccion_tipo.value==4)
							{
								alert(valor[1]+": no puede estar vacio");
								e.focus();
								return false;
							}
						}
						if (valor[1]=="Otra"){	
							if (formulario.user_extra.value==4)
							{
								alert("Centro de Trabajo no puede estar vacio");
								e.focus();
								return false;
							}
						}
					}else{
						alert(text_campo+valor[1]+text_vacio);
						if ((e.dato!='textarea')&&(e.type!='hidden')) e.focus();
						return false;
					}
				}
				//alert (e.type);
				if (e.type=="select-one")
				{
					//alert(e.selectedIndex);
					var indice = e.selectedIndex;
					if ((e.options[indice].value =="")||(e.options[indice].value =="0"))
					{
						alert(text_campo+valor[1]+text_vacio);
						return false;
					}
				}
				if (valor[1]=="Email")
				{
					if (!verifica_mail(e.value))
					{
						alert(text_mail);
						e.focus();
						return false;
					}		
				}
				//Codigo que comprueba centro trabajo
				/*if (valor[1]=="direccion_centro"){
					dir =document.getElementById('direccion_tipo').value;
					
				}*/
			}
		
	
		
		if (e.name=="user_pass_TXT")
		{
			//alert("user_pass_TXT:" + e.value + " / repass:" + formulario.repass.value);
			if (e.value!=formulario.repass.value)
			{
				alert(text_pass);
				if (e.dato!='textarea')
				{
					formulario.repass.value="";
					formulario.repass.focus();
				}
				return false;
			}
		}
	}
	
	//Comprovar tipo de dato
	if (check==1)
	{
		if (!verifica_check(formulario))
		{
			alert(text_mail);
			return false;
		}
	}
	return true;

}


