var cssAumento = false;
var cssReduccion = false;
var cssMin = 0;
var cssMax = 5;
var cssCurrent = false;

function holaMundo(){
alert("Hola Mundo");
}

function favoritos(){
   if ((navigator.appName=="Microsoft Internet Explorer") &&
         (parseInt(navigator.appVersion)>=4)) {
      var url="http://www.cun.es/";
      var titulo="Clinica Universitaria de Navarra";
      window.external.AddFavorite(url,titulo);
   } else {
      if(navigator.appName == "Netscape")
         alert("Presione Crtl+D para agregar este sitio en sus Bookmarks");
   }
}

function setNextStyle() {
    next = (cssCurrent * 1 ) + 1;
    if ( next <= cssMax ) {
        setActiveStyleSheet('tamano'+next);
    }
}
function setPrevStyle() {
    prev = cssCurrent - 1;
    if ( prev >= cssMin ) {
        setActiveStyleSheet('tamano'+prev);
    }
}


function setActiveStyleSheet(title) {
    var i, a, main;
    if ( cssAumento == false && cssReduccion == false ) {
        if ( title == 'tamano4' || title == 'tamano2' || title == 'tamano3' ) {
            cssAumento = 'tamano4';
            cssReduccion = 'tamano2';
    //     alert('1024');
        } else {
            cssAumento = 'tamano2';
            cssReduccion = 'tamano0';
    //     alert('800');
        }
    }
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
            a.disabled = true;
            if(a.getAttribute("title") == title) {
                a.disabled = false;
            }
        }
    }
    tmp=title.split('tamano');
    cssCurrent = tmp[1];
}

function getActiveStyleSheet() {
    var i, a;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
    }
    return null;
}

function getPreferredStyleSheet() {
  var i, a;
    for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
        if(a.getAttribute("rel").indexOf("style") != -1
        && a.getAttribute("rel").indexOf("alt") == -1
        && a.getAttribute("title")
        ) return a.getAttribute("title");
    }
    return null;
}

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
window.onload = function(e) {
    var cookie = readCookie("style");
    if ( cookie && cookie != 'blanco' && cookie != null) {
        setActiveStyleSheet(cookie);
    } else {

        if ( screen.availWidth >= 1024 ) {
         setActiveStyleSheet('tamano3');
        } else {
         setActiveStyleSheet('tamano1');
        }
    }
}

window.onunload = function(e) {
    var title = getActiveStyleSheet();
    createCookie("style", title, 1);
}


function chkFormularioConsulta () {
	var emailFilter=/^.+@.+\..{2,3}$/;
	if ( document.getElementById('noespaciente').checked === false  && document.getElementById('espaciente').checked  === false) {
		alert('Por favor, seleccione si es paciente o no.'); return false;
	}
	if ( document.getElementById('actual-nombre').value === "" ) {
		alert('Por favor, introduzca su nombre.'); return false;
	}
	if ( document.getElementById('actual-apellidos').value === "" ) {
		alert('Por favor, introduzca sus apellidos.'); return false;
	}
	if ( document.getElementById('actual-motivo').value === "" ) {
		alert('Por favor, introduzca el motivo de esta consulta.'); return false;
	}
	if ( document.getElementById('actual-responsable').value !== "" ) {
		if ( document.getElementById('actual-vinculo').value === "" ) {
			alert('Por favor, introduzca el vinculo del responsable familiar.'); return false;
		}
	}
	if ( document.getElementById('portelefono').checked ) {
		if ( document.getElementById('actual-telefono').value === "" ) {
			alert('Por favor, introduzca su teléfono.'); return false;
		}
		if ( document.getElementById('actual-telefono').value.length < '9' ) {
			alert('Por favor, verifique su teléfono.'); return false;
		}
	} else if ( document.getElementById('poremail').checked ) {
		if ( document.getElementById('actual-email').value === "" ) {
			alert('Por favor, introduzca su email.'); return false;
		}
		if ( emailFilter.test(document.getElementById('actual-email').value) === false ) {
			alert('Por favor, introduzca su email correctamente.'); return false;
		}
		if ( document.getElementById('actual-email').value != document.getElementById('actual-emailconfirm').value ) {
			alert('Por favor, confirme su email.'); return false;
		}
	} else if ( document.getElementById('pordomicilio').checked ) {
		if ( document.getElementById('actual-direccion').value === "" ) {
			alert('Por favor, introduzca su dirección.'); return false;
		}
		if ( document.getElementById('actual-codigopostal').value === "" ) {
			alert('Por favor, introduzca su código postal.'); return false;
		}
		if ( document.getElementById('actual-localidad').value === "" ) {
			alert('Por favor, introduzca su localidad.'); return false;
		}
		if ( document.getElementById('actual-provincia').value === "" ) {
			alert('Por favor, introduzca su provincia.'); return false;
		}
		if ( document.getElementById('actual-pais').value === "" ) {
			alert('Por favor, introduzca su país.'); return false;
		}
	}

	if ( document.getElementById('actual-email').value != "" ) {
		if ( emailFilter.test(document.getElementById('actual-email').value) === false ) {
			alert('Por favor, introduzca su email correctamente.'); return false;
		}
		if ( document.getElementById('actual-email').value != document.getElementById('actual-emailconfirm').value ) {
			alert('Por favor, confirme su email.'); return false;
		}
	}

	document.getElementById('enviar').value = 'Enviando...';
	document.getElementById('enviar').disabled = true;
	return true;
}

function chkFormularioMasInfo () {
	var emailFilter=/^.+@.+\..{2,3}$/;
	if ( document.getElementById('nombre').value == "" ) {
		alert('Por favor, introduzca su nombre.'); return false;
	}
	if ( document.getElementById('apellidos').value == "" ) {
		alert('Por favor, introduzca sus apellidos.'); return false;
	}

   if ( document.getElementById('portelefono').checked ) {
		if ( document.getElementById('telefono').value == "" ) {
			alert('Por favor, introduzca su teléfono.'); return false;
		}
		if ( document.getElementById('telefono').value.length < '9' ) {
			alert('Por favor, verifique su teléfono.'); return false;
		}

	} else if ( document.getElementById('poremail').checked ) {
		if ( document.getElementById('email').value === "" ) {
			alert('Por favor, introduzca su email.'); return false;
		}
		if ( emailFilter.test(document.getElementById('email').value) === false ) {
			alert('Por favor, introduzca su email correctamente.'); return false;
		}
		if ( document.getElementById('email').value != document.getElementById('emailconfirm').value ) {
			alert('Por favor, confirme su email.'); return false;
		}
	} else if ( document.getElementById('pordomicilio').checked  ) {
		if ( document.getElementById('direccion').value == "" ) {
			alert('Por favor, introduzca su dirección.'); return false;
		} else 	if ( document.getElementById('codigopostal').value == "" ) {
			alert('Por favor, introduzca su código postal.'); return false;
		} else 	if ( document.getElementById('localidad').value == "" ) {
			alert('Por favor, introduzca su localidad.'); return false;
		} else 	if ( document.getElementById('provincia').value == "" ) {
			alert('Por favor, introduzca su provincia.'); return false;
		} else 	if ( document.getElementById('pais').value == "" ) {
			alert('Por favor, introduzca su país.'); return false;
		}
	}

	if ( document.getElementById('email').value != "" ) {
		if ( emailFilter.test(document.getElementById('email').value) === false ) {
			alert('Por favor, introduzca su email correctamente.'); return false;
		}
		if ( document.getElementById('email').value != document.getElementById('emailconfirm').value ) {
			alert('Por favor, confirme su email.'); return false;
		}
	}

	if ( document.getElementById('tema').value == "" ) {
		alert('Por favor, introduzca el tema de su consulta.'); return false;
	}
	document.getElementById('enviar').value = 'Enviando...';
	document.getElementById('enviar').disabled = true;
	return true;
}


function chkFormularioMasInfoXXX () {
	if ( document.getElementById('nombre').value == "" ) {
		alert('Por favor, introduzca su nombre.'); return false;
	}
	if ( document.getElementById('apellidos').value == "" ) {
		alert('Por favor, introduzca sus apellidos.'); return false;
	}

/*
	if ( document.getElementById('poremail').checked ) {
		if ( document.getElementById('email').value == "" ) {
			alert('Por favor, introduzca su email.'); return false;
		} else if ( document.getElementById('email').value != document.getElementById('emailconfirm').value ) {
			alert('Por favor, confirme su email.'); return false;
		}

	} else
*/
   if ( document.getElementById('portelefono').checked ) {
		if ( document.getElementById('telefono').value == "" ) {
			alert('Por favor, introduzca su teléfono.'); return false;
		}
	} else if ( document.getElementById('pordomicilio').checked  ) {
		if ( document.getElementById('direccion').value == "" ) {
			alert('Por favor, introduzca su dirección.'); return false;
		} else 	if ( document.getElementById('codigopostal').value == "" ) {
			alert('Por favor, introduzca su código postal.'); return false;
		} else 	if ( document.getElementById('localidad').value == "" ) {
			alert('Por favor, introduzca su localidad.'); return false;
		} else 	if ( document.getElementById('provincia').value == "" ) {
			alert('Por favor, introduzca su provincia.'); return false;
		} else 	if ( document.getElementById('pais').value == "" ) {
			alert('Por favor, introduzca su país.'); return false;
		}
	} else {
		alert('Por favor, seleccione una forma de contacto');
		return false;
	}

	if ( document.getElementById('email').value == "" ) {
		alert('Por favor, introduzca su email.'); return false;
	} else if ( document.getElementById('email').value != document.getElementById('emailconfirm').value ) {
		alert('Por favor, confirme su email.'); return false;
	}

	if ( document.getElementById('tema').value == "" ) {
		alert('Por favor, introduzca el tema de su consulta.'); return false;
	}

	return true;
}

function chkFormularioBecarios () {
	if ( document.getElementById('pasaporte').value == "" ) {
		alert('Por favor, introduzca su pasaporte o DNI.'); return false;
	}
	if ( document.getElementById('nombre').value == "" ) {
		alert('Por favor, introduzca su nombre.'); return false;
	}
	if ( document.getElementById('apellido1').value == "" ) {
		alert('Por favor, introduzca su primer apellido.'); return false;
	}

	if ( document.getElementById('nacionalidad').value == "" ) {
		alert('Por favor, introduzca su nacionalidad.'); return false;
	}

	if ( document.getElementById('pais').value == "") {
		alert('Por favor, introduzca su país.'); return false;
	}
	if ( document.getElementById('seguromedico').value == "siseguro") {
		if ( document.getElementById('segurocia').value == "") {
			alert('Por favor, introduzca la compañía de seguros.'); return false;
		}
	}

	return true;
}

function chkFormularioAsociados () {
	if ( document.getElementById('nif').value == "" ) {
		alert('Por favor, introduzca su pasaporte o DNI.'); return false;
	}
	if ( document.getElementById('nombre').value == "" ) {
		alert('Por favor, introduzca su nombre.'); return false;
	}
	if ( document.getElementById('apel1').value == "" ) {
		alert('Por favor, introduzca su primer apellido.'); return false;
	}
	return true;
}

var DHTML = (document.getElementById || document.all || document.layers);

// Utilizo la propiedad display del style, y no la visibility ya que queremos
// que el espacio se "compacte" al ocultar la capa
//
// Obtenido a partir del menú lateral de: http://www.quirksmode.org/
//
// Para reutilizarlo atención al fixIEBug, requiere una capa con id defeatIEBug
// en la página, aunque no he comprobado si es necesario

function showDiv(name){

	if (!DHTML) return;

	if (name){
		document.getElementById(name).style.display = 'block';
	}
	fixIEBug();
}

function hideDiv(name){
	if (!DHTML) return;

	if (name){
		document.getElementById(name).style.display = 'none';
	}
	fixIEBug();
}

function showHideDiv(name){
	if (!DHTML) return;

	if (name){
		var x = getObjSytle(name);
		x.display = x.display=='none'?'block':'none';
	}
	fixIEBug();
}

function getObjSytle(name){

  if (document.getElementById){

    return document.getElementById(name).style;
  }
  else if (document.all){
    return document.all[name].style;
  }
  else if (document.layers){
    return document.layers[name];
  }
  else return false;
}

function fixIEBug()
{
	/* Defeat IE6 fixed bug by opening and closing the last div */
	var x = document.getElementById('defeatIEBug');
	var currentStyle = x.style.display;
	var newStyle = (currentStyle == 'none') ? 'block' : 'none';
	x.style.display = newStyle;
	x.style.display = currentStyle;
}


var http = false;
var cargado=0;
var select=false;

function JScreateRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}
function fullDepartamentos(id,uid) {
    select = id;
    http = JScreateRequestObject();
    var url="/fileadmin/template/sub/th_mailformplus/actual-departamento.php";
    if(cargado==0) {
	http.open("get", url);
	http.onreadystatechange = JShandleResponse;
	http.send(null);
    }
}

function fullCombi(id,uid) {
    select = id;
    http = JScreateRequestObject();
    var url="/fileadmin/template/sub/th_mailformplus/" + select + ".php?uid=" + uid;
    if(cargado==0) {
    http.open("get", url);
    http.onreadystatechange = JShandleResponse;
    http.send(null);
    }
}

function JSrellenaCombo(pos,title,uid) {
    if(uid==0) {
     var title = "\t     " + title.toUpperCase();
    }
    document.getElementById(select).options[pos]= new Option(title,uid);
}

function JShandleResponse() {
    if (http.readyState ==  1){
        document.getElementById(select).options[0].text= "Cargando...";
    }
    if(http.readyState == 4){
        var response = http.responseText;
        var separa=response.split("[]");
        var title=new Array();
        var uid=new Array();
	document.getElementById(select).options.length = 0
        for(var x=0; x < separa.length; x++) {
           var sp=separa[x].split("-");
            title[x]=sp[0];
            uid[x]=sp[1];
            if ( title[x] != '' ) {
            JSrellenaCombo(x + 1,title[x],uid[x]);
            }
        }

            if ( select != 'actual-medico' ) {
                document.getElementById(select).options[0].text= "";
            }else {
                document.getElementById(select).options[0].text= "no tengo prioridad";
           }

    }
}


function sndReq() {
    http = JScreateRequestObject();
    var uid="";
    var url="/fileadmin/template/sub/tt_news/respuesta.php?uid=" + uid;

    if(cargado==0) {
    http.open("get", url);
    http.onreadystatechange = handleResponse;
    http.send(null);
    }
}



function rellenaCombo(pos,title,uid) {
    if(uid==0) {
     var title = "\t     " + title.toUpperCase();
    }
    document.getElementById("departamentos").options[pos]= new Option(title,uid);
}


function sendUrl() {
    var seleccion=document.getElementById("departamentos").value;
    document.getElementById("categorias").action="/index.php?id=" + seleccion;
    if(seleccion!=0) {
        // document.getElementById("categorias").submit();
      window.location.href="/index.php?id=" + seleccion;
    }
}

function handleResponse() {
    if (http.readyState ==  1){
        document.getElementById("departamentos").options[0].text= "Cargando...";
    }
    if(http.readyState == 4){
        var response = http.responseText;
        var separa=response.split("[]");
        var title=new Array();
        var uid=new Array();

          for(var x=0; x < separa.length; x++) {
           var sp=separa[x].split("-");
            title[x]=sp[0];
            uid[x]=sp[1];
            rellenaCombo(x + 1,title[x],uid[x])
                  }
        document.getElementById("departamentos").options[0].text= "seleccione un departamento";
              cargado=1;

        }
}



function validarPolitica(formulario) {
   if (formulario.politica.checked == true)
      return true;
   else
      alert("Para registrarse, debe aceptar la política de Privacidad");
      return false;
}

function MM_validateForm() { //v4.0
	// Comprobación de datos obligatorios
	var flag=0;
	var str_error='Errores:\n';
	var strEdad=document.formulario.txtEdad.value;

	if (strEdad == '') {
		flag=1;
		str_error += '- La edad es obligatoria\n';
	} else {
		if (isNaN(strEdad)) {
			flag=1;
			str_error += '- La edad debe ser un valor numerico\n';
		} else {
			if (strEdad < 1 || strEdad >100) {
				flag=1;
				str_error +='- Edad debe contener un numero entre 1 y 100.\n';
			}
		}
	}
	if (flag) {
		alert(str_error);
		//window.location = "http://www.cun.es/index.php?id=23855"
		return false;
	}
	else {
		// RecuperaciÛn resto de datos
		strFumador=document.formulario.fumador.options[document.formulario.fumador.selectedIndex].value;
		strSexo=document.formulario.sexo.options[document.formulario.sexo.selectedIndex].value;
		strPaciente=document.formulario.paciente.options[document.formulario.paciente.selectedIndex].value;
		strColon=document.formulario.colon.options[document.formulario.colon.selectedIndex].value;
		strMama=document.formulario.mama.options[document.formulario.mama.selectedIndex].value;
		// Output de la p·gina generada seg™n criterios seleccionados
		escribir(strFumador,strEdad,strSexo,strPaciente,strColon,strMama);
                return true;
	}
}

function escribir2(fumador,edad,sexo,paciente,colon,mama){

	document.write("<html><head><title></title></head>");

	document.write("<script language='JavaScript' type='text/JavaScript'>");

	document.write("function imprimir() {");
	document.write("    window.self.print();");
	document.write("}");

	document.write("function Solicitud(){");
	document.write("    location.href='index.php?id=23877';");
	document.write("}");

	document.write("</script");
	document.write(">");

	document.write("<body bgcolor='#FFFFFF'><form>");
	document.write("<font face='Verdana, Arial, Helvetica, sans-serif' size='2'>");
	document.write("Los diferentes pasos a realizar en su chequeo son: <br><br></font>");

	document.write("<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' '>");
   	document.write("Analítica básica."+"<br></font></b>");
	document.write("<font face='Verdana, Arial, Helvetica, sans-serif' size='1' >");
	document.write("VSG."+"<br>");
	document.write("Glucosa."+"<br>");
	document.write("Creatinina."+"<br>");
	document.write("Acido úrico."+"<br>");
	document.write("HDL-LDL-triglicéridos."+"<br>");
	document.write("SGPT."+"<br>");
	document.write("GGT."+"<br>");
	document.write("F. alcalina."+"<br>");
	document.write("Calcio."+"<br>");
	document.write("TSH."+"<br>");
	document.write("Hierro y Capacidad total de fijación."+"<br>");
	document.write("Orina A y S."+"<br><br></font>");
	document.write("<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' >");
   	document.write("Valoración de riesgo cardiovascular."+"<br><br>");
	document.write("Electrocardiograma."+"<br><br>");
	document.write("Radiología."+"<br></font></b>");
	document.write("<font face='Verdana, Arial, Helvetica, sans-serif' size='1' >");
	document.write("Ecografía abdominal y vascular."+"<br>");
	document.write("RX de tórax PA y L."+"<br><br></font>");

	if (fumador=="si"){
		document.write("<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' >");
   		document.write("Espirometría simple."+"<br><br>");
		if (edad>40) {
			document.write("TAC torácico helicoidal."+"<br><br>");
		}
		document.write("</b></font>");
	}

	if (edad>50) {
		document.write("<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1'>");
   		document.write("Proteinograma."+"<br><br>");
		document.write("Colonoscopia."+"<br><br>");
		if (sexo=="hombre"){
			document.write("PSA."+"<br><br>");
		}
		document.write("</b></font>");
	}

	if (edad>40) {
		document.write("<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1'>");
		if (sexo=="mujer"){
			document.write("Mamografía."+"<br><br>");
		}
		document.write("</b></font>");
	}

	if (paciente=="si") {
		document.write("<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1'>");
		document.write("Ecocardiograma."+"<br><br>");
		document.write("Albúmina en orina."+"<br><br>");
		document.write("Creatinina en orina."+"<br><br>");
		document.write("</b></font>");
	}

	if (colon=="si") {
		document.write("<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#990033'>");
		document.write("Colonoscopia."+"<br><br>");
		document.write("</b></font>");
	}

	if (mama=="si") {
		document.write("<b><font face='Verdana, Arial, Helvetica, sans-serif' size='1' color='#990033'>");
		if (sexo=="mujer"){
			document.write("MamografÌa."+"<br><br>");
		}
		document.write("</b></font>");
	}

	document.write("<table width='80%' border='0' align='center'>");
    document.write("<tr>");
    document.write("<td align=center width='28%'>");
    document.write("<input type='button' name='Submit1' value='Imprimir' onClick='imprimir()'>");
    document.write("</td>");
    document.write("<td align='center' width='33%'>");
    document.write("<input type='button' name='Submit2' value='Solicitar Chequeo' onClick='Solicitud()'>");
    document.write("</td>");
    //document.write("<td align='center' width='39%'>");
    //document.write("<input type='button' name='Submit3' value='Cerrar' onClick='Cerrar()'>");
    //document.write("</td>");
    document.write("</tr>");
    document.write("</table>");
	document.write("</form></body></html>");
	document.close();

}


function escribir(fumador,edad,sexo,paciente,colon,mama){

html = '<h5>Analítica Básica</h5>';
html += '<ul>';
html += '<li>VSG.</li>';
html += '<li>Glucosa.</li>';
html += '<li>Creatinina.</li>';
html += '<li>Acido úrico.</li>';
html += '<li>HDL-LDL-triglicéridos.</li>';
html += '<li>SGPT.</li>';
html += '<li>GGT.</li>';

html += '<li>F. alcalina.</li>';
html += '<li>Calcio.</li>';
html += '<li>TSH.</li>';
html += '<li>Hierro y Capacidad total de fijación.</li>';
html += '<li>Orina A y S.</li>';
html += '</ul>';

html += '<h5>Valoración de riesgo cardiovascular</h5>';

html += '<h5>Electrocardiograma</h5>';

html += '<h5>Radiología</h5>';
html += '<ul>';
html += '<li>Ecografía abdominal y vascular.</li>';
html += '<li>RX de tórax PA y L.</li>';
html += '</ul>';

if (fumador=="si"){
	html += '<h5>Espirometría simple.</h5>';
	if (edad>40) {
		html += '<h5>TAC torácico helicoidal.</h5>';
	}
}

if (edad>50) {
	html += '<h5>Proteinograma.</h5>';
	html += '<h5>Colonoscopia.</h5>';
	if (sexo=="hombre"){
		html += '<h5>PSA.</h5>';
	}
}

if (edad>40 && sexo=="mujer") {
	html += '<h5>Mamografía.</h5>';
}

if (paciente=="si") {
	html += '<h5>Ecocardiograma.</h5>';
	html += '<h5>Albúmina en orina.</h5>';
	html += '<h5>Creatinina en orina.</h5>';
}

if (colon=="si") {
	html += '<h5>Colonoscopia.</h5>';
}

if (mama=="si" && sexo == "mujer") {
	html += '<h5>MamografÌa.</h5>';
}



html += '<form action="" id="form-basico">';
html += '<fieldset>';
html += '<legend class="chequeo">&nbsp;</legend>';
html += '<p class="botonera"><span><input type="button" onclick="javascript:print();" value="Imprimir" class="boton"/></span>';
html += '<span><input type="button" value="Solicitar chequeo" onclick="javascript:location.href=\'http://www.cun.es/index.php?id=23877\';return false" class="boton anadir"/></span>';
html += '</fieldset>';
html += '</form>';

document.getElementById('contenidoCambiar').innerHTML = html;
}

function check_email(e) {

	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

	for(i=0; i < e.length ;i++){
		if(ok.indexOf(e.charAt(i))<0){
			return (false);
		}
	}
	if (document.images) {
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) {
			return (false);
		}
	}
	return (true);
}

function MM_validateForm2(form) {
	var flag=0;
	var str_error = 'Datos obligatorios:\n';

	if (form.txtNombre.value == '') {
		flag=1;
		str_error += '- Nombre y Apellidos\n';
	}
	if (form.txtDir.value == '') {
		flag=1;
		str_error += '- DirecciÛn\n';
	}
	if (form.txtTel.value == '') {
		flag=1;
		str_error += '- TelÈfono\n';
	}
	if (form.txtEmail.value == '') {
		flag=1;
		str_error += '- E-mail\n';
	} else {
		// e-mail correcto?
		if (check_email(form.txtEmail.value)) {
			flag=1;
			str_error += '- La dirección de correo electrónico parece incorrecta\n';
		}
	}

	if (flag) {
		alert(str_error);
		return;
	}
	//location.href='fmreply.htm';
        str_enviado = "Su formulario ha sido procesado correctamente.\nEn unos días nos pondremos en contacto con Vd.\n\nGracias por utilizar este servicio.";
        //alert(str_enviado);
	form.submit();
}

/**
 * phone number is a number
*/
function isNumberKey(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode > 31 && (charCode < 48 || charCode > 57)) return false;
	return true;
}
/**
 * show/hide span
*/
function showSpan(name){
	if (!DHTML) return;
	if (name){ document.getElementById(name).style.display='inline'; }
	fixIEBug();
}

function hideSpan(name){
	if (!DHTML) return;
	if (name){ document.getElementById(name).style.display = 'none'; }
	fixIEBug();
}

function showContact(type){
	if (type == 'tel1'){
		showSpan('tel');
		hideSpan('em');
		hideSpan('em2');
		hideSpan('dom1');
		hideSpan('dom2');
		hideSpan('dom3');
		hideSpan('dom4');
		hideSpan('dom5');
	}
	if (type == 'email1'){
		hideSpan('tel');
		showSpan('em');
		showSpan('em2');
		hideSpan('dom1');
		hideSpan('dom2');
		hideSpan('dom3');
		hideSpan('dom4');
		hideSpan('dom5');
	}
	if (type == 'domicilio1'){
		hideSpan('tel');
		hideSpan('em');
		hideSpan('em2');
		showSpan('dom1');
		showSpan('dom2');
		showSpan('dom3');
		showSpan('dom4');
		showSpan('dom5');
	}
}

function chkFormularioSugerencias() {
	var emailFilter=/^.+@.+\..{2,3}$/;

   if ( document.getElementById('otros').checked ) {
		if ( document.getElementById('otrosdesc').value == "" ) {
			alert('Por favor, especifique el motivo de su estancia.'); return false;
		}
	}

	if ( document.getElementById('sugerencia').value == "" ) {
		alert('Por favor, introduzca su sugerencia.'); return false;
	}

	if ( document.getElementById('email').value != "" ) {
		if ( emailFilter.test(document.getElementById('email').value) === false ) {
			alert('Por favor, introduzca su email correctamente.'); return false;
		}
		if ( document.getElementById('email').value != document.getElementById('emailconfirm').value ) {
			alert('Por favor, confirme su email.'); return false;
		}
	}

	document.getElementById('enviar').value = 'Enviando...';
	document.getElementById('enviar').disabled = true;
	return true;
}

function chkFormularioTestimonios() {
	var emailFilter=/^.+@.+\..{2,3}$/;

	if ( document.getElementById('nombre').value == "" ) {
		alert('Por favor, introduzca su nombre.'); return false;
	}
	if ( document.getElementById('apellidos').value == "" ) {
		alert('Por favor, introduzca sus apellidos.'); return false;
	}
	if (document.getElementById('email').value == "") {
		alert('Por favor, introduzca su email.'); return false;
	}
	if ( document.getElementById('email').value != "" ) {
		if ( emailFilter.test(document.getElementById('email').value) === false ) {
			alert('Por favor, introduzca su email correctamente.'); return false;
		}
		if ( document.getElementById('email').value != document.getElementById('emailconfirm').value ) {
			alert('Por favor, confirme su email.'); return false;
		}
	}
	if ( document.getElementById('testimonio').value == "" ) {
		alert('Por favor, introduzca su testimonio.'); return false;
	}

	document.getElementById('enviar').value = 'Enviando...';
	document.getElementById('enviar').disabled = true;
	return true;
}

function getPathologies(id){
	jQuery("#tx-medicaltrials-pi1-pathology").load(document.location + "?tx_medicaltrials_pi1[department]=" + id + " #tx-medicaltrials-pi1-pathology option",{},function(){
		jQuery("#tx-medicaltrials-pi1-pathology").val("");
	});
}


jQuery(document).ready(function(){
	$.datepicker.regional['es'] = {
		clearText: 'Borra',
		clearStatus: 'Borra fecha actual',
		closeText: 'Cerrar',
		closeStatus: 'Cerrar sin guardar',
		prevText: '<Ant',
		prevBigText: '<<',
		prevStatus: 'Mostrar mes anterior',
		prevBigStatus: 'Mostrar año anterior',
		nextText: 'Sig>',
		nextBigText: '>>',
		nextStatus: 'Mostrar mes siguiente',
		nextBigStatus: 'Mostrar año siguiente',
		currentText: 'Hoy',
		currentStatus: 'Mostrar mes actual',
		monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio', 'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
		monthNamesShort: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'],
		monthStatus: 'Seleccionar otro mes',
		yearStatus: 'Seleccionar otro año',
		weekHeader: 'Sm',
		weekStatus: 'Semana del año',
		dayNames: ['Domingo', 'Lunes', 'Martes', 'Miércoles', 'Jueves', 'Viernes', 'Sábado'],
		dayNamesShort: ['Dom', 'Lun', 'Mar', 'Mié', 'Jue', 'Vie', 'Sáb'],
		dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','Sá'],
		dayStatus: 'Set DD as first week day',
		dateStatus: 'Select D, M d',
		dateFormat: 'dd/mm/yy',
		firstDay: 1,
		initStatus: 'Seleccionar fecha',
		isRTL: false
	};
	$.datepicker.setDefaults($.datepicker.regional['es']);
	$("#tx-o5publications-pi11-publidate").datepicker({
			changeMonth: true,
			changeYear: true,
			maxDate: '+0d',
			dateFormat: 'dd-mm-yy',
			onSelect: function(dateText, inst){
				$("#tx-o5publications-pi11-publidate2").datepicker("option","minDate",$("#tx-o5publications-pi11-publidate").datepicker("getDate"));
			},
			firstDay: 1});

	$("#tx-o5publications-pi11-publidate2").datepicker({
		changeMonth: true,
		changeYear: true,
		maxDate: '+0d',
		dateFormat: 'dd-mm-yy',
		onSelect: function(dateText, inst){
			$("#tx-o5publications-pi11-publidate").datepicker("option","maxDate",$("#tx-o5publications-pi11-publidate2").datepicker("getDate"));
		},
		firstDay: 1});

});