// SARENET

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function leapto(form) {
var myindex=form.dest.selectedIndex
parent.location.href=(form.dest.options[myindex].value);
}

function getPermission() {
	return window.confirm("Desea enviar esta informacion?")
}

function CSURLPopupShow(formName, popupName, target) {
var popup = document[formName].elements[popupName];
window.open(popup.options[popup.selectedIndex].value, target);
popup.selectedIndex = 0;
}

function FrontPage_Form1_Validator(theForm)
{

  if (theForm.telef.value == "")
  {
    alert("Escriba un valor para el campo \"Número de Teléfono\".");
    theForm.telef.focus();
    return (false);
  }

  if (theForm.telef.value.length < 9)
  {
    alert("Escriba por lo menos 9 caracteres en el campo \"Número de Teléfono\".");
    theForm.telef.focus();
    return (false);
  }

  if (theForm.telef.value.length > 9)
  {
    alert("Escriba como máximo 9 caracteres en el campo \"Número de Teléfono\".");
    theForm.telef.focus();
    return (false);
  }

  var checkOK = "0123456789-";
  var checkStr = theForm.telef.value;
  var allValid = true;
  var decPoints = 0;
  var allNum = "";
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
    allNum += ch;
  }
  if (!allValid)
  {
    alert("Escriba sólo dígito caracteres en el campo \"Número de Teléfono\".");
    theForm.telef.focus();
    return (false);
  }
  return (true);
}

function selecciona () {
	var mid = document.enlaces.categorias.value;
	window.document.enlaces.action='enlaces.php?id_enlace='+mid+'';
	window.document.enlaces.submit();
}

function cambia_orden (ord) {
	f=window.document.formulario;
	var mid = document.formulario.categorias.value;
	if (ord==1) {
			f.action='biblioteca.php?id_biblioteca='+mid+'';
			f.submit();
	}
	if (ord==2) {
			f.action='documentacion.php?id_documentacion='+mid+'';
			f.submit();
	}
	if (ord==3) {
			f.action='hemeroteca.php?id_hemeroteca='+mid+'';
			f.submit();
	}
}


function cambia_orden2(ord) {
	f=window.document.formulario;
	var mid = document.formulario.categorias.value;
	if (ord==1) {
			f.action='librosgratis.php?id_biblioteca='+mid+'';
			f.submit();
	}
}

function cambia_biblioteca () {
	var mid = document.formulario.categorias.value;
	window.document.formulario.action='biblioteca.php?id_biblioteca='+mid+'';
	window.document.formulario.submit();
}

function cambia_hemeroteca () {
	var mid = document.formulario.categorias.value;
	window.document.formulario.action='hemeroteca.php?id_hemeroteca='+mid+'';
	window.document.formulario.submit();
}		

function cambia_documentacion () {
	var mid = document.formulario.categorias.value;
	window.document.formulario.action='documentacion.php?id_documentacion='+mid+'';
	window.document.formulario.submit();
}	

function cambia_plantas () {
	var mid = document.letras.plantas.value;
	window.document.letras.action='vademecum_plantas_ficha.php?remedio='+mid+'';
	window.document.letras.submit();
}	

function cambia_buscador (miletra) {
	
	if(document.buscador.tipo.value==1){
		window.document.buscador.action='vademecum_plantas_letra.php?letra='+miletra+'';
		window.document.buscador.submit();
	}
	if(document.buscador.tipo.value==2){
		window.document.buscador.action='vademecum_plantas_letra_cientifico.php?letra='+miletra+'';
		window.document.buscador.submit();
	}
	
}

function cambia_simples () {
	var mid = document.letras_simples.plantas_simples.value;
	window.document.letras_simples.action='presentaciones_simples_ficha.php?remedio='+mid+'';
	window.document.letras_simples.submit();
}	

function cambia_busca_simples (miletra) {
	
	if(document.buscador_simples.tipo_simples.value==1){
		window.document.buscador_simples.action='presentaciones_simples_letra.php?letra='+miletra+'';
		window.document.buscador_simples.submit();
	}
	if(document.buscador_simples.tipo_simples.value==2){
		window.document.buscador_simples.action='presentaciones_simples_letra_cientifico.php?letra='+miletra+'';
		window.document.buscador_simples.submit();
	}
	
}

function cambia_compuestas () {
	var mid = document.letras_compuestas.plantas_compuestas.value;
	window.document.letras_compuestas.action='presentaciones_compuestas_ficha.php?presentacion='+mid+'';
	window.document.letras_compuestas.submit();
}	

function cambia_busca_compuestas (miletra) {	
		window.document.buscador_compuestas.action='presentaciones_compuestas_letra.php?letra='+miletra+'';
		window.document.buscador_compuestas.submit();
}




function cambia_magistrales () {
	var mid = document.letras_magistrales.plantas_magistrales.value;
	window.document.letras_magistrales.action='formulas_magistrales_ficha.php?formula='+mid+'';
	window.document.letras_magistrales.submit();
}	

function cambia_busca_magistrales (miletra) {
	
	if(document.buscador_magistrales.tipo_magistrales.value==1){
		window.document.buscador_magistrales.action='formulas_magistrales_letra.php?letra='+miletra+'';
		window.document.buscador_magistrales.submit();
	}
	if(document.buscador_magistrales.tipo_magistrales.value==2){
		window.document.buscador_magistrales.action='formulas_magistrales_aparato.php?letra='+miletra+'';
		window.document.buscador_magistrales.submit();
	}
	
}

function salta_aparatos(){
	window.document.buscador_magistrales.action='formulas_magistrales_aparato.php';
	window.document.buscador_magistrales.submit();
}

function cambia_aparatos () {
	var mid = document.aparatos.nombres.value;
	window.document.aparatos.action='formulas_magistrales_aparato.php?codigo_aparato='+mid+'';
	window.document.aparatos.submit();
}	

function cambia_laboratorios () {
	var mid = document.laboratorios.nombre_lab.value;
	window.document.laboratorios.action='laboratorios_ficha.php?codigo_laboratorio='+mid+'';
	window.document.laboratorios.submit();
}	

//Saco estas variables para cuando hacen el submit
var sumatorio_acciones = 0;
var sumatorio_indicaciones = 0;
function aniado_buscador (sel) {
	
	if(sel.name == "condiciones"){
		window.document.buscador.operadores.value += document.buscador.condiciones.value+'|';
	}	
	if(sel.name == "acciones" || sel.name== "indicaciones"){
		window.document.buscador.orden.value += sel.name+'|';
	}else{
		window.document.buscador.orden.value += document.buscador.condiciones.value+'|';
	}
	
	if (sel.name == "acciones") {
		window.document.buscador.ides_acc.value += sel.options[sel.selectedIndex].id+'|';
		sumatorio_acciones++;
	}
	if (sel.name == "indicaciones") {
		window.document.buscador.ides_indic.value += sel.options[sel.selectedIndex].id+'|';
		sumatorio_indicaciones++;
	}

	window.document.buscador.seleccionado.value += sel.options[sel.selectedIndex].text+' ';
	sel.selectedIndex = 0;
	
}	

//NOTA JORGE (31/10/2006)
//Las opciones permitidas son las siguientes:
//Que todos los operadores sean iguales. Osea todo AND, todo OR o todo NOT
//Una combinación de dos operadores y tres acciones/indicaciones. Osea AND/NOT OR/NOT AND/OR 
//Más posibilidades son un lio de programación e incluso de concepto de buscador

function busco(){

	var total_operadores = document.buscador.operadores.value;
	if(total_operadores.indexOf('AND') != -1 && total_operadores.indexOf('OR') == -1 && total_operadores.indexOf('NOT') == -1){
		//window.alert('Me vale. Es todo AND');	
		window.document.buscador.action='buscador_resultados.php';
		window.document.buscador.submit();
	}else{
		if(total_operadores.indexOf('OR') != -1 && total_operadores.indexOf('AND') == -1 && total_operadores.indexOf('NOT') == -1){
			//window.alert('Me vale. Es todo OR');		
			window.document.buscador.action='buscador_resultados.php';
			window.document.buscador.submit();
		}else{	
			if(total_operadores.indexOf('NOT') != -1 && total_operadores.indexOf('OR') == -1 && total_operadores.indexOf('AND') == -1){
				//window.alert('Me vale. Es todo NOT');
				
				window.document.buscador.action='buscador_resultados.php';
				window.document.buscador.submit();
			}else{
				if(total_operadores == 'NOT|AND|' || total_operadores == 'AND|NOT|' || total_operadores == 'NOT|OR|' || total_operadores == 'OR|NOT|' || total_operadores == 'AND|OR|' || total_operadores == 'OR|AND|'){
					//window.alert('Esta opción también vale');
					window.document.buscador.action='buscador_resultados.php';
					window.document.buscador.submit();
				}else{
					if((sumatorio_acciones == 1 && sumatorio_indicaciones == 0) || (sumatorio_acciones == 0 && sumatorio_indicaciones == 1)){
						//window.alert('Hay solo una acción o una sola indicacion, me vale!!!');
						window.document.buscador.action='buscador_simple.php';
						window.document.buscador.submit();
						}else{
							window.alert('Opción de búsqueda no permitida. Máximo 2 operadores diferentes y 3 componentes');

						}
					}
			}
		}
	}

}

function borro(){
	document.buscador.seleccionado.value = "";
	document.buscador.operadores.value = "";
	document.buscador.ides_acc.value = "";
	document.buscador.ides_indic.value = "";
	document.buscador.orden.value = "";

	/*window.alert(document.buscador.seleccionado.value);
	window.alert(document.buscador.operadores.value);*/
}

function valido_usuario(){
	window.document.validacion.submit();

}

function esMail(email) {
	if (email.indexOf("@",1) == -1)  {
	return (false);
	}else {
		if (email.indexOf("@")<2 || email.indexOf(".",email.indexOf("@")+2 || email.indexOf(".")<(email.length - 2) ) == -1){
		return false;
		}
	}
return true;
}


function Comprueba_registro() {
	var noadmitidos = document.registrar.direccion.value;
	if(noadmitidos.indexOf('[URL=') != -1 || noadmitidos.indexOf('[url=') != -1){
		alert("El campo dirección no es correcto");
      document.registrar.direccion.focus();
      return false;		
	}
	

 
 	if (document.registrar.login.value=='') {
    		alert("Debe rellenar el campo Usuario");
            document.registrar.login.focus();
            return false;
    }

 	if (document.registrar.login.value.length < 3 || document.registrar.login.value.length > 10) {
    		alert("El usuario debe tener entre 3 y 10 caracteres");
            document.registrar.login.focus();
            return false;
    }

    
 	if (document.registrar.password.value=='') {
    		alert("Debe rellenar el campo Contraseña");
            document.registrar.password.focus();
            return false;
    }    
 	if (document.registrar.password.value.length < 3 || document.registrar.password.value.length > 10) {
    		alert("La contraseña debe tener entre 3 y 10 caracteres");
            document.registrar.password.focus();
            return false;
    }
    
 	if (document.registrar.password.value != document.registrar.repite_password.value) {
 		alert('La contraseña y su repetición no coinciden');
      return false; 		
 	}   
 	
 	if (document.registrar.pregunta.value=='') {
    		alert("Debe rellenar el campo Pregunta secreta");
            document.registrar.pregunta.focus();
            return false;
    }  

 	if (document.registrar.respuesta.value=='') {
    		alert("Debe rellenar el campo Respuesta secreta");
            document.registrar.respuesta.focus();
            return false;
    }     
    	
 	if (document.registrar.apellidos.value=='') {
    		alert("Debe rellenar el campo Apellidos");
            document.registrar.apellido1.focus();
            return false;
    }
	if (document.registrar.nombre.value=='') {
    		alert("Debe rellenar el campo Nombre");
            document.registrar.apellido2.focus();
            return false;
    }   
	if (document.registrar.dni.value=='') {
    		alert("Debe rellenar el campo DNI");
            document.registrar.dni.focus();
            return false;
    }
	if (document.registrar.email.value=='') {
    		alert("Debe rellenar el campo E-mail");
            document.registrar.email.focus();
            return false;
    }
	if (document.registrar.direccion.value=='') {
    		alert("Debe rellenar el campo Dirección");
            document.registrar.direccion.focus();
            return false;
    }   
	if (document.registrar.poblacion.value=='') {
    		alert("Debe rellenar el campo Población");
            document.registrar.poblacion.focus();
            return false;
    }    
	if (document.registrar.cp.value=='') {
    		alert("Debe rellenar el campo Código Postal");
            document.registrar.cp.focus();
            return false;
    }       
	if (document.registrar.profesion.value=='') {
    		alert("Debe rellenar el campo Profesión");
            document.registrar.profesion.focus();
            return false;
    }  

	//chequeamos el email. llamamos a la funcion esMail
	if (!esMail(document.registrar.email.value)) {
		alert("La dirección de e-mail no es válida.");
		document.registrar.email.select();
		document.registrar.email.focus();
		return false; 
   }
	
	if (document.registrar.condiciones.checked==false) {
    		alert("Debes aceptar las condiciones generales");
         return false;
    }   
    
    
    document.registrar.submit();
}

function condiciones_registro() {
	  window.open('/registro/pop_condiciones.php','nueva','scrollbars=no,width=570,height=400');
}
function recordar_contrasenia() {
	  window.open('/registro/pop_recordar.php','nueva','scrollbars=no,width=200,height=200');
}

function ir_aparatos(){
	if(document.buscador_magistrales.tipo_magistrales.value==1){
	window.document.buscador_magistrales.action='formulas_magistrales.php';
	window.document.buscador_magistrales.submit();		
	}
	if(document.buscador_magistrales.tipo_magistrales.value==2){
	window.document.buscador_magistrales.action='formulas_magistrales_aparato.php';
	window.document.buscador_magistrales.submit();		
	}
}

function abre_desgloses(revista,numero) {
	  window.open('/revista/pop_revista_desglose.php?rev='+revista+'&num='+numero+'','nueva','scrollbars=yes,width=650,height=700');
}

function Comprueba_contactar(revista,numero) {
var malos = document.contactar.consulta.value;
	if(malos.indexOf('[URL=') != -1 || malos.indexOf('[url=') != -1){
		alert("El campo consulta no es correcto");
      document.contactar.consulta.focus();
      return false;		
	}else{
	javascript:document.contactar.submit();
	}
}

function abrir_foto(cod) {
	  window.open('/vademecum/ver_foto.php?cod='+cod+'','nueva','scrollbars=yes,width=300,height=350');
}

function abrir_foto_comp(cod) {
	  window.open('/vademecum/ver_foto_comp.php?cod='+cod+'','nueva','scrollbars=yes,width=300,height=350');
}
function buscador_portada() {
	 if(document.buscador_global.texto.value==""){
	  	alert("Debe introducir un término de búsqueda");
	  	return false;
	}else{
		document.buscador_global.submit();
	}
}