// JavaScript Document
// Array para definir las posiciones de los submenús
  var separa_submenu=new Array();
  separa_submenu[0]=31;
  separa_submenu[1]=129;
  separa_submenu[2]=200;
  separa_submenu[3]=424;
  separa_submenu[4]=552;
  separa_submenu[5]=441;
  var total_menus=separa_submenu.length;
  var menu_activo=0;

function imag_cabecera(indice, idioma){
 var direccion=location.toString();
 direccion=direccion.split('/')[direccion.split('/').length-1];
 direccion=direccion.split('.')[0];
 if (direccion==''){direccion='index';}
 // Función llamada desde menup(), excepto desde el index, mapa y aviso
  var cabeceras=new Array();
  cabeceras[0]='index';
  cabeceras[1]='empresa';
  cabeceras[2]='servicios';
  cabeceras[3]='DMC_'+idioma;
  cabeceras[4]='congresos';
  cabeceras[5]='contacto';
  cabeceras[6]='usuarios';
  if (document.getElementById('imagen')){
 	document.getElementById('imagen').style.backgroundImage='url(img/cabecera_'+cabeceras[indice]+'.jpg)';
  }
}  
  
function menup(celda,estado,idioma){
  var imag_reposo='url(img/fondo_menu_cla.jpg)';
  var imag_activo='url(img/fondo_menu_osc.jpg)';
  var color_reposo='#838383';
  var color_activo='#FFFFFF';
if (document.getElementById(celda)){
  var indice_celda=Number(celda.split('_')[1]);
  var celda=document.getElementById(celda);
  if (document.getElementById('imagen')){
if ((menu_activo==0)&&(document.getElementById('imagen').style.backgroundImage=='')){
 imag_cabecera(indice_celda,idioma);
}
}

if (estado==1){
  for (i=1;i<=total_menus;i++){
   if (document.getElementById('menup_'+i)){
    document.getElementById('menup_'+i).style.color=color_reposo;
	document.getElementById('menup_'+i).style.backgroundImage=imag_reposo;
   }
  }
 celda.style.backgroundImage=imag_activo;
 celda.style.color=color_activo;
 var ancho_submenu=550;
 if (indice_celda==1){ancho_submenu=650;  }
 if (indice_celda==2){ancho_submenu=700;  }
 if (indice_celda==3){ancho_submenu=770;  }
 if (indice_celda==5){ancho_submenu=170;  }
 if (indice_celda>5){ancho_submenu=330;  }
 if (indice_celda==4){ancho_submenu=280; }
 if (indice_celda==5){ancho_submenu=280; }
  submenu(indice_celda,separa_submenu[indice_celda-1],ancho_submenu);
  menu_activo=indice_celda;

 }
//  if (indice_celda>=4){ancho_submenu=170;}
if (estado==0){
celda.style.backgroundImage=imag_reposo;
celda.style.color=color_reposo;
}
}
else{
  for (i=1;i<=total_menus;i++){
   if (document.getElementById('menup_'+i)){
    document.getElementById('menup_'+i).style.color=color_reposo;
	document.getElementById('menup_'+i).style.backgroundImage=imag_reposo;
	document.getElementById('submenu_'+i).style.visibility='hidden';
   }
  }
}
}

function submenu(activo,izquierda,ancho)
{
 for (i=1;i<=total_menus;i++){
  if (document.getElementById('submenu_'+i)){
     document.getElementById('submenu_'+i).style.visibility='hidden';
  }
 }
 document.getElementById('contenedor_submenu').style.width=ancho+'px';  
 document.getElementById('contenedor_submenu').style.left=izquierda+'px'; 
 if (document.getElementById('submenu_'+activo)){document.getElementById('submenu_'+activo).style.visibility='visible';}  
}

function favoritos(idioma_form){
window.status='';
var enlace='http://www.orzancongres.com';
var titulo='Orzán Congres';
var mensaje_ult='Presione CONTROL+T para añadir la web a Favoritos ...';
  switch(idioma_form){
  	case 'GA':
		mensaje_ult='Presione CONTROL+T para engadir a web a Favoritos ...';
	break
	case 'IN':
		mensaje_ult='Push CONTROL+T to add the web to Bookmarks ...';
	break
  }
if (window.sidebar){
 window.sidebar.addPanel(titulo,enlace,'');
}
else{
 if ((document.all)&&(navigator.userAgent.toLowerCase().indexOf('opera')==-1)){
   window.external.AddFavorite(enlace,titulo);
 }
 else{
  if (navigator.userAgent.toLowerCase().indexOf('opera')!=-1){
  alert(mensaje_ult);
  }
  else{
  alert(mensaje_ult);
  }
 }
}
}

function valida(nombre_form,idioma_form){
var obligatorios=new Array();
var alt_campo='';
var nombre_campo='';
var campo='';
var lista_campos=0; //para indicar si se saca la lista de campos en el alert
var errores=0;
var primer_vacio=null;
var mensaje_error='Los siguientes campos son obligatorios:   \n\n';
if (idioma_form=='GA'){mensaje_error='Os seguintes campos son obrigatorios:   \n\n';}
if (idioma_form=='IN'){mensaje_error='Following data are required:   \n\n';}
 if (nombre_form=='form_registro'){ 
  obligatorios[0]=0;
  obligatorios[1]=1;
  mensaje_error='Indique un usuario y una contraseña ... ';
  if (idioma_form=='GA'){mensaje_error='Indique un usuario e un contrasinal ... ';}
  if (idioma_form=='IN'){mensaje_error='An user name and password are required ... ';}
  lista_campos=0;
 }
 if (nombre_form=='form_contacto'){ 
  obligatorios[0]=0;
  obligatorios[1]=1;
  obligatorios[2]=4;
  obligatorios[3]=5;
  lista_campos=1;
 }
 if (nombre_form=='form_presupuesto'){ 
  /*obligatorios[0]=0;
  obligatorios[1]=1;
  obligatorios[7]=7;
  obligatorios[8]=8;*/
  lista_campos=1;
 }

 if (nombre_form=='form_alta'){ 
  obligatorios[0]=0;
  obligatorios[1]=1;
  obligatorios[2]=2;
  obligatorios[3]=3;
  obligatorios[4]=4;
  obligatorios[5]=5;
  obligatorios[6]=6;
  obligatorios[7]=8;
  obligatorios[8]=9;
  obligatorios[9]=10;
  obligatorios[10]=11;
  obligatorios[11]=12;
  obligatorios[12]=15;
  obligatorios[13]=16;
  obligatorios[14]=17;
  lista_campos=1;
 }
 if (nombre_form=='form_abstracts'){ 
  obligatorios[0]=0;
  obligatorios[1]=1;
  obligatorios[2]=2;
  obligatorios[3]=3;
  obligatorios[4]=4;
  lista_campos=1;
 }
 
 for (i=0;i<obligatorios.length;i++){
   if (document.forms[nombre_form].elements[obligatorios[i]]){
      campo=document.forms[nombre_form].elements[obligatorios[i]].value;
	  alt_campo='';
	  //nombre_campo=document.forms[nombre_form].elements[obligatorios[i]].name;
	  if (document.forms[nombre_form].elements[obligatorios[i]].alt){
	  	alt_campo=document.forms[nombre_form].elements[obligatorios[i]].alt.toLowerCase();
	  }
	  if (alt_campo==''){
	  	alt_campo=document.forms[nombre_form].elements[obligatorios[i]].name.toLowerCase();
	  }
      if (campo==''){
	    if (primer_vacio==null){primer_vacio=i;}
	    errores=1;
		   if (lista_campos==1){
		   		if (alt_campo=='direccion'){alt_campo='dirección';}
				if (alt_campo=='telefono'){alt_campo='teléfono';}
				if (alt_campo=='contrasena'){alt_campo='contraseña';}
				if ((alt_campo!='nif')&&(alt_campo!='tin')){
			 		nombre_campo=alt_campo.charAt(0).toUpperCase()+alt_campo.substr(1).toLowerCase();
				}
				else{
					nombre_campo=alt_campo.toUpperCase();;
				}
		     mensaje_error+='-  '+nombre_campo+'\n';
		   }
	    }
   }
 }
 
 if (errores==1){ 
  alert(mensaje_error+'\n');
  if (!isNaN(primer_vacio)){document.forms[nombre_form].elements[primer_vacio].focus();}
 }
 else{
  if (document.forms[nombre_form].action!=''){
   document.forms[nombre_form].submit();
  }
 }
 
}

function buscador(idioma_form)
{
var nombre_form='form_buscador';
var alerta='El término de búsqueda ha de ser de 3 caracteres como mínimo ...  ';
 if((document.forms[nombre_form].elements[0].value!='')&&(document.forms[nombre_form].elements[0].value.length>2)){
  document.forms[nombre_form].action='buscador.asp';
  document.forms[nombre_form].submit();
 }
 else{
  switch(idioma_form){
  	case 'GA':
		alerta='O termo de búsqueda ten que ser de 3 caracteres como mínimo ...  ';
	break
	case 'IN':
		alerta='The search term must be at least 3 characters long ...  ';
	break
  }
  alert(alerta);
  document.forms[nombre_form].elements[0].focus();
 }
}

function ventana(seccion,ide,datos)
{
  if (seccion!=''){
    if (seccion=='programa'){
	 var ancho=600;
	 var alto=450;
	 var destino='programa_congreso.asp?id='+ide;
	 if (datos!=''){destino+=datos;}
	}
	window.open(destino,'','width='+ancho+',height='+alto+',top=0,left=0,directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
  }
}

function SoloNum(evt){
	var nav4 = window.Event ? true : false;
	var key = nav4 ? evt.which : evt.keyCode;	
	return (key <= 13 || (key >= 48 && key <= 57));
}

function ValidoBoletin(){
	if (document.forms["frmBoletines"].elements["email"].value.length < 6 || document.forms["frmBoletines"].elements["email"].value=="Email"){
		alert("El Email debe ser correcto.");
		document.forms["frmBoletines"].elements["email"].focus();
		return false;
	}
	/* Verificar si el email tiene el formato user@dominio. */
	var emailPat=/^(.+)@(.+)$/
	var emailStr = document.getElementById("email").value
	if (!emailStr.match(emailPat)) {
		alert("El campo Email parece incorrecto (compruebe @ y .'s)")
		document.getElementById("email").focus();
		return false
	}
	if (document.forms["frmBoletines"].elements["nombre"].value=="Nombre" ||  document.forms["frmBoletines"].elements["nombre"].value.length<3) {
			alert("El Nombre debe tener al menos 3 caracteres.");
			document.forms["frmBoletines"].elements["nombre"].focus();
			return false;
	}
	if (!document.forms["frmBoletines"].elements["lopd"].checked) {
			alert("Es necesario aceptar las Condiciones de Uso y la Política de Privacidad.");
			document.forms["frmBoletines"].elements["lopd"].focus();
			return false;
	}
	else
		return true;
}

function BorrarBoletin(campo){
	document.forms["frmBoletines"].elements[campo].value="";
}
function ventanaAENOR()
{	
	var ancho=500;
	var alto=400;
	var winl = (screen.width-ancho)/2;
	var wint = (screen.height-alto)/2;
	var destino='aenor.html';
	window.open(destino,'','width='+ancho+',height='+alto+',top='+wint+',left='+winl+',directories=no,location=no,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
}
function CambiaComilla(){
//Propsito:	Substuir la comilla simple por el acento.
//Efectos:		Si se pulsa la comilla['] se reemplazar por el acento[].
	if (event.keyCode==39){
		event.keyCode=180;
	}
}

function CambiaComillaPegado(NombreForm){
	//Propsito:	Substuir la comilla simple por el acento cuando pegan en todos los campos del formulario.
	//Efectos:		Si se pega la comilla['] se reemplazar por el acento[].
	
		var iNumCampos = document.forms[NombreForm].length-1
		for (i=0;i<=iNumCampos;i++)
		{
			if (document.forms[NombreForm].elements[i].type!="select-multiple"){
				sTexto=document.forms[NombreForm].elements[i].value;
				while (sTexto.search("'") != -1){
					sTexto=sTexto.replace("'", "");
					}
				while (sTexto.search('"') != -1){
					sTexto=sTexto.replace('"', '');
					}
				//alert(document.forms[formulario].elements[i].name)
				document.forms[NombreForm].elements[i].value=sTexto;
			}
			
		}
	
}
function ValidoAcceso(NombreForm,TxtEmail) {
	CambiaComillaPegado(NombreForm);
	var i;
	var sFormulario=document.forms[NombreForm];
	var validado = true;
	for (i=0; i<= sFormulario.length-1; i++){
	  if (sFormulario.elements[i].attributes["validationmsg"]){
		if (sFormulario.elements[i].attributes["validationmsg"].value != "" && sFormulario.elements[i].style.visibility != "hidden"){
			switch (sFormulario.elements[i].type) {  
				case "select-multiple" :  
					if (sFormulario.elements[i].options.length =="0"){
						alert(sFormulario.elements[i].attributes["validationmsg"].value);
						sFormulario.elements[i].focus();
						return false;
					}
					break;
				case "textarea" :  
					if (sFormulario.elements[i].value.length > sFormulario.elements[i].maxlength){validado=false;}
					if (sFormulario.elements[i].value.length == "0" ){validado=false;}
					if (validado==false){
						alert(sFormulario.elements[i].attributes["validationmsg"].value);
						return false;
					}
					break;
				default :  
					if (sFormulario.elements[i].type !="image" && sFormulario.elements[i].type !="select-multiple" &&
					 sFormulario.elements[i].type !="textarea" && sFormulario.elements[i].type !="checkbox" && 
					 sFormulario.elements[i].type !="radio" && sFormulario.elements[i].attributes["validationmsg"].value != "0" && 
					 sFormulario.elements[i].attributes["validationmsg"] != "undefined" && sFormulario.elements[i].disabled == false && 
					 (sFormulario.elements[i].value =="" || sFormulario.elements[i].value =="0" )){
						alert(sFormulario.elements[i].attributes["validationmsg"].value);
						sFormulario.elements[i].focus();
						return false;
					}
					break;
			}  
			if (sFormulario.elements[i].minlength){
				if (sFormulario.elements[i].value.length < sFormulario.elements[i].minlength){validado=false;}
			}
			if (validado==false){
				alert(sFormulario.elements[i].attributes["validationmsg"].value);
				sFormulario.elements[i].focus();
				return false;
			}
		 }
	  }
	}
	if (TxtEmail!=""){
		/* Verificar si el email tiene el formato user@dominio. */
		var emailPat=/^(.+)@(.+)$/
	
		var emailStr = document.getElementById(TxtEmail).value
		
		if (!emailStr.match(emailPat)) {
			alert("El campo Email parece incorrecto (compruebe @ y .'s)")
			document.getElementById(TxtEmail).focus();
			return false
		}
	}

	return true
}
