function overTD(td,color){td.style.cursor='hand';td.bgColor=color;}
function outTD(td,color){td.style.cursor='default';td.bgColor=color;}

function Rollover (ruta,obj){
	obj.src=ruta;
}



//--------------------------Correo
function CCA(Item,tipo) {
		if (Item.checked == true ){
			color= '#F8CCCC'; //seleciona
		}else{
			if (tipo=='tr'){
				color='#FFFFFF';
			}else{
				color='#f5f6f7';
			}			
		}
document.getElementById(tipo+Item.value).style.backgroundColor = color;
document.getElementById('todos').checked=false;
}
function Dellista(campo){
	if (eval("document.fmrenvia." + campo)!=null) eval("document.fmrenvia." + campo+".value='a'");
}

function existe(param,from){
	z=param.search('\\[');
	if (z!=-1){
		aux=param.substring(0, z);
		if (eval("document."+ from +"." +aux)!=null) if (eval("document."+ from +"." +param)!=null) return true; else return false;
	} else if (eval("document."+ from +"." +param)!=null) return true; else return false;
}

function SelectAll(Item,total){
if (Item.checked == true){
		for (i=1;i<=total;i++){
			if(eval("document.getElementById(" + "'tr" +i + "')") != null){
				document.getElementById('tr'+i).style.backgroundColor = '#F8CCCC';
				eval("document.mail.check" +i +".checked=true");
			}else{
				 if(eval("document.getElementById(" + "'tr2" +i + "')") != null){
					document.getElementById('tr2'+i).style.backgroundColor = '#F8CCCC';
					eval("document.mail.check" +i +".checked=true");
				}
			}

		}
}else{
		for (i=1;i<=total;i++){
			 if(eval("document.getElementById(" + "'tr" +i + "')") != null){
				 document.getElementById('tr'+i).style.backgroundColor = '#FFFFFF';
				 eval("document.mail.check" +i +".checked=false");
			}else{
				if(eval("document.getElementById(" + "'tr2" +i + "')") != null){
					document.getElementById('tr2'+i).style.backgroundColor = '#f5f6f7';
					eval("document.mail.check" +i +".checked=false");
				}
			}
			
		}
}
}
//------------------Cadenas
function trim(value){
	while(''+value.charAt(0)==' ')value=value.substring(1,value.length);
	return value;
}

function InStr(n, s1, s2){
	// Devuelve la posición de la primera ocurrencia de s2 en s1
	// Si se especifica n, se empezará a comprobar desde esa posición
	// Sino se especifica, los dos parámetros serán las cadenas
	var numargs=InStr.arguments.length;
	
	if(numargs <3)
		return n.indexOf(s1)+1;
	else
		return s1.indexOf(s2, n)+1;
}
function Mid(s, n, c){
	// Devuelve una cadena desde la posición n, con c caracteres
	// Si c = 0 devolver toda la cadena desde la posición n
	
	var numargs=Mid.arguments.length;
	
	// Si sólo se pasan los dos primeros argumentos
	if(numargs<3)
		c=s.length-n+1;
		
	if(c<1)
		c=s.length-n+1;
	if(n+c >s.length)
		c=s.length-n+1;
	if(n>s.length)
		return "";
		
	return s.substring(n-1,n+c-1);
}

function Len(s){ // Devuelve la longitud de la cadena s
	return s.length;
}
function UCase(s){ // Devuelve la cadena convertida a mayúsculas
	return s.toUpperCase();
}


//-------------------Evas


function salto(quin,x,obj,valor){

	//left = parseInt(window.event.clientX)-2;
	left = (x+200);
	if ((eval("document.fmrdatos." + valor + "[0].checked")==true) && (quin=='ea198' || quin=='ea200' || quin=='ea202' || quin=='ea204' || quin=='ea206' || quin=='ea208' || quin=='ea210' || quin=='ea236')) {
		left = parseInt(window.event.clientX)-2;
	} else if ((eval("document.fmrdatos." + valor + "[1].checked")==true) && (quin=='ea212' || quin=='ea214' || quin=='ea216' || quin=='ea218' || quin=='ea220' || quin=='ea222' || quin=='ea224' || quin=='ea226')) {
		left = parseInt(window.event.clientX)-2;
	}
	document.all[quin].style.left=(left-7);
	obj.value=parseInt((left-x)/2)/10;
}

//-----------------Varias

function esnumero (valor) {
	//Esta función es llamada en el onkeypress y solo deja poner números del 0 al 9 y el valor no puede superar el 10
	var tecla = event.keyCode; //El código de la tecla pulsada
	var teclareal = String.fromCharCode(event.keyCode) //La tecla pulsada
	
	if ((tecla<48 || tecla>57) && tecla!=44 && tecla!=46 && tecla!=68 && tecla!=78 && tecla!=100 && tecla!=110) { //Sino es número ni un punto ni una coma no le dejamos poner ninguna tecla
		event.keyCode=0;
	} else {
		if (tecla==46) {//Si es una coma le ponemos punto
			event.keyCode=44;
		}
		//if (parseFloat(valor + teclareal)>maximo) {//si supera el máximo no le dejamos poner ninguna tecla
		//	event.keyCode=0;
		//}
	}
	//alert(tecla);
}
function esnumeroMAX (valor,maximo) {
	//Esta función es llamada en el onkeypress y solo deja poner números del 0 al 9 y el valor no puede superar el 10
	var tecla = event.keyCode; //El código de la tecla pulsada
	var teclareal = String.fromCharCode(event.keyCode) //La tecla pulsada
	
	if ((tecla<48 || tecla>57) && tecla!=44 && tecla!=46) { //Sino es número ni un punto ni una coma no le dejamos poner ninguna tecla
		event.keyCode=0;
	} else {
		if (tecla==44) {//Si es una coma le ponemos punto
			event.keyCode=46;
		}
		if (parseFloat(valor + teclareal)>maximo) {//si supera el máximo no le dejamos poner ninguna tecla
			event.keyCode=0;
		}
	}
	//alert(tecla);
}

function ventananueva(dir,alto,ancho,nombre)
{
	var ventana;
	ventana=window.open(dir,nombre,"toolbar=no,directories=no,resizable=no,scrollbars=yes,status=no,menubar=no,width="+ancho +",height="+alto);
}

function ventananueva1(dir,alto,ancho,nombre)
{
	var ventana1;
	ventana1=window.open(dir,nombre,"toolbar=no,directories=no,resizable=no,scrollbars=no,status=no,menubar=no,width="+ancho +",height="+alto);
}

function errores(arr,form){
var i=0;

	for (i=0;i<arr.length;i++){	  	
		if (arr[i]!=0){
			if (existe(arr[i],form)) eval("document." +form +"." +arr[i] +".style.backgroundColor = '#F8CCCC';");
		}
	}
}

function ponerr(par,campo){
	var a="";
	if (par.value!='0') a=par.value.replace(",'" + campo +"'","");
	par.value=a+",'" + campo +"'";
}

function quitarerr(par,campo){
	var a="";
	if (par.value!='0') a=par.value.replace(",'" + campo +"'","");
	 par.value=a;
}


function edcontrols(arr,bool,form,disable,borravalue){
var i=0;
	for (i=0;i<arr.length;i++){
		if (existe(arr[i],form)){
			if (bool == true){
					if (eval("document."+form+"."+arr[i] +".selectedIndex")!=null){
						if (borravalue==true) eval("document."+form+"."+arr[i] +".selectedIndex=0;");
						eval("document." +form +"." +arr[i] +".style.backgroundColor = '#f5f6f7';");
						}
					else if (eval("document."+form+"."+arr[i] +".type")=="radio"||eval("document."+form+"."+arr[i] +".type")=="checkbox"){
						if (borravalue==true) eval("document."+form+"."+arr[i] +".checked=false;");
						eval("document." +form +"." +arr[i] +".style.backgroundColor = '#ffffff';");
						}
					else if(eval("document."+form+"."+arr[i] +".value")!=null){
						if (borravalue==true)  eval("document."+form+"."+arr[i] +".value='';");	
						eval("document." +form +"." +arr[i] +".style.backgroundColor = '#f5f6f7';");
						}
				}
				if (disable==true) eval("document."+form+"."+arr[i] +".disabled="+bool+";");
			}
		
	}
}

function disableControls(arr,bool,form){
var i=0;
	for (i=0;i<arr.length;i++){
		if (existe(arr[i],form)==true) eval("document."+form+"."+arr[i] +".disabled="+bool+";");
	}
}


function MultipleOk(arr,form,arr2,bool,disable,borravalue){
var i=0;
var aux=0;
auxArr="";
var j=0;

	for (i=0;i<arr.length;i++){			
			if (eval("document."+form+"."+arr[i] +".selectedIndex")!=null){
				if (eval("document."+form+"."+arr[i] +".selectedIndex")==0) aux++;
				}
			else if (eval("document."+form+"."+arr[i] +".type")=="radio"||eval("document."+form+"."+arr[i] +".type")=="checkbox"){
				 if (eval("document."+form+"."+arr[i] +".checked")==false)  aux++;
				}
			else if(eval("document."+form+"."+arr[i] +".value")!=null){
				 if (eval("document."+form+"."+arr[i] +".value")=='') aux++;	
				}
	}
	
		auxArr="new Array(" //Esto se hace porque no se pasa bien los arrays de funcion a funcion
		for (j=0;j<arr2.length-1;j++){			
			auxArr+="'"+arr2[j]+"',";
		}
		auxArr+="'"+arr2[j]+"')";
		
		if (arr.length==aux) edcontrols(eval(auxArr),bool,form,disable,borravalue); else edcontrols(eval(auxArr),!bool,form,disable,borravalue); // esta vacio Borramos	
}

//--------------------------------------- Fechas
function EsFecha(texto){ //Pasa la fecha a esp y valida si mes ok y 4 digitos ano
var FechaAux,mesAux,diaAux;
	if (Len(texto) > 0) {
		if (InStr(1,texto,'/') !=0) { //Primera /
			diaAux=Mid(texto,1,InStr(1,texto,'/')-1);
			if (InStr(InStr(1,texto,'/')+1,texto,'/')!=0) { //Segunda /
				mesAux=Mid(texto,InStr(1,texto,'/')+1,2);
				if (!isNaN(mesAux) && mesAux!='') { //el mes ok
					if (Len(Mid(texto,InStr(InStr(1,texto,'/')+1,texto,'/')+1,Len(texto)))==4) { //Quatro digitos el año
						 FechaAux=mesAux +'/'+ diaAux +'/' + Mid(texto,InStr(InStr(1,texto,'/')+1,texto,'/')+1,Len(texto));
						 return FechaAux;
					}
				}
			}
		}
	}
	return false;
}

function esHora(texto){	//Formato hh:mm
	var aux=false;
	if (Len(texto) > 0) {
		if (InStr(1,texto,":") !=0){  //:
			if (!isNaN(Mid(texto,1,InStr(1,texto,":")-1))){
				if (parseFloat(Mid(texto,1,InStr(1,texto,":")-1)) <= 23) { 
					if (!isNaN(Mid(texto,InStr(1,texto,":")+1,Len(texto)))) { 
						if ((parseFloat(Mid(texto,InStr(1,texto,":")+1,Len(texto))) <= 59) && InStr(texto,",")==0)  aux=true
				}
			}
		}
	}
  }
return aux;
}

function DiffTiempos(StartDate,StartTiem,StopDate,StopTiem,obj){
	if (esHora(StartTiem) && esHora(StopTiem)) {
		var aux =suycDateDiff(EsFecha(StartDate) +' '+ StartTiem, EsFecha(StopDate) +' '+ StopTiem , "m", false );
		if (aux!=null) obj.value=aux; else obj.value='';
	}
}


//calcular la edad de una persona 
//recibe la fecha como un string en formato español 
//devuelve un entero con la edad. Devuelve false en caso de que la fecha sea incorrecta o mayor que el dia actual 
function Daedad(fecha,fechafin){ 
    //desmontamos por partes la fecha de hoy
	var fhoy = fechafin.split("/");
	//si el array no tiene tres partes, la fecha es incorrecta 
    if (fhoy.length!=3) 
       return ""; 

	//desmontamos por partes la fecha de nacimiento
	var fnaci = fecha.split("/");
    //si el array no tiene tres partes, la fecha es incorrecta 
    if (fnaci.length!=3) 
       return ""; 
 	
    //resto los años de las dos fechas 
    edadd=parseInt(fhoy[2])- parseInt(fnaci[2]) - 1; //-1 porque no se si ha cumplido años ya este año 

    //si resto los meses y me da menor que 0 entonces no ha cumplido años. Si da mayor si ha cumplido 
    if (parseInt(fhoy[1]) - parseInt(fnaci[1]) < 0) //+ 1 porque los meses empiezan en 0 
       return edadd 
    if (parseInt(fhoy[1]) - parseInt(fnaci[1]) > 0) 
       return edadd+1 

    //entonces es que eran iguales. miro los dias 
    //si resto los dias y me da menor que 0 entonces no ha cumplido años. Si da mayor o igual si ha cumplido 
    if (parseInt(fhoy[0]) - parseInt(fnaci[0]) >= 0) 
       return edadd + 1 

    return edadd;
} 

function PoneNull(val1)
{
	if (val1!=null) val1.value="ND";
}

function checkYear(year) { 
return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
}

function leap(valor) {
var year = valor;
var Check1 = parseFloat(year);
for (var i = 0; i < year.length; i++) {
var sLetterCheck1 = year.substring(i, i+1);
if (sLetterCheck1 < "0" || sLetterCheck1 > "9") {

year = valor;
return;
   }
}       
if (year < 1582) {
return "";


return;
}
checkYear(year);
if (!checkYear(year)) return false;
else return true;
}

function girafecha(strdt) {
var mes = strdt.substr(0,2);
var dia= strdt.substr(3,2);
var ano= strdt.substr(6,4);
var dt= dia+'/'+mes+'/'+ano;
return dt;
}

function suycDateDiff(start, end, interval, rounding ) {

    var iOut = 0;
    
    // Create 2 error messages, 1 for each argument. 
    var startMsg = "Check the Start Date and End Date\n"
        startMsg += "must be a valid date format.\n\n"
        startMsg += "Please try again." ;
		
    var intervalMsg = "Sorry the dateAdd function only accepts\n"
        intervalMsg += "d, h, m OR s intervals.\n\n"
        intervalMsg += "Please try again." ;

    var bufferA = Date.parse( start ) ;
    var bufferB = Date.parse( end ) ;
    	
    // check that the start parameter is a valid Date. 
    if ( isNaN (bufferA) || isNaN (bufferB) ) {
        //alert( startMsg ) ;
        return '' ;
    }
	
    // check that an interval parameter was not numeric. 
    if ( interval.charAt == 'undefined' ) {
        // the user specified an incorrect interval, handle the error. 
        //alert( intervalMsg ) ;
        return '' ;
    }
    
    var number = bufferB-bufferA ;
    
    // what kind of add to do? 
    switch (interval.charAt(0))
    {
        case 'd': case 'D': 
            iOut = parseInt(number / 86400000) ;
            if(rounding) iOut += parseInt((number % 86400000)/43200001) ;
            break ;
        case 'h': case 'H':
            iOut = parseInt(number / 3600000 ) ;
            if(rounding) iOut += parseInt((number % 3600000)/1800001) ;
            break ;
        case 'm': case 'M':
            iOut = parseInt(number / 60000 ) ;
            if(rounding) iOut += parseInt((number % 60000)/30001) ;
            break ;
        case 's': case 'S':
            iOut = parseInt(number / 1000 ) ;
            if(rounding) iOut += parseInt((number % 1000)/501) ;
            break ;
        default:
        // If we get to here then the interval parameter
        // didn't meet the d,h,m,s criteria.  Handle
        // the error. 		
        //alert(intervalMsg) ;
        return null ;
    }
    
    return iOut ;
}



//Funciones solo del SEF
function alarma(tipo){
if (tipo=='inc'){
	msg1='Para que el paciente sea incluido en el registro,             \n\n debe cumplir todos los Criterios de Inclusión.';
}else{
	msg1='Para que el paciente sea incluido en el registro,             \n\n no ha de cumplir ningún Criterio de Exclusión';
}
alert(msg1);
}
function Chkvisita0(form){
	//-----------------
	//Visita Selección
	//-----------------
	
	//DIAGNÓSTICO DE LA ENFERMEDAD
	//Tipo de Tumor 
		edcontrols(new Array('a7'),!(form.a6.value=='8'),'fmrdatos',true,true);
    //HISTORIA CLÍNICA
    //Resultado de la evaluación de los siguientes sistemas
		edcontrols(new Array('f2'),!(form.f1.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f4'),!(form.f3.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f6'),!(form.f5.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f8'),!(form.f7.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f10'),!(form.f9.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f12'),!(form.f11.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f14'),!(form.f13.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f16'),!(form.f15.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f18'),!(form.f17.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f20'),!(form.f19.value=='3'),'fmrdatos',true,true);
    //TRATAMIENTO PREVIO CON PREPARADOS DE ERITROPOYETINA
		if (form.h1[0].checked==true){edcontrols(new Array('h2','h8','h14','h20'),false,'fmrdatos',true,true);}else{edcontrols(new Array('h2','h3','h4','h5','h6','h7','h8','h9','h10','h11','h12','h13','h14','h15','h16','h17','h18','h19','h20','h21','h22','h23','h24','h25'),true,'fmrdatos',true,true);}			
		edcontrols(new Array('h3','h4','h5','h6','h7'),!(form.h2.checked),'fmrdatos',true,true);
		edcontrols(new Array('h9','h10','h11','h12','h13'),!(form.h8.checked),'fmrdatos',true,true);
		edcontrols(new Array('h15','h16','h17','h18','h19'),!(form.h14.checked),'fmrdatos',true,true);
		edcontrols(new Array('h21','h22','h23','h24','h25'),!(form.h20.checked),'fmrdatos',true,true);
	//TRANSFUSIONES DE SANGRE
		if (form.i1[0].checked==true){edcontrols(new Array('i2','i6','i10','i14'),false,'fmrdatos',true,true);}else{edcontrols(new Array('i2','i3','i4','i5','i6','i7','i8','i9','i10','i11','i12','i13','i14','i15','i16','i17','i18','i20','i22','i24'),true,'fmrdatos',true,true);}			
		edcontrols(new Array('i3','i4','i5','i18'),!(form.i2.checked),'fmrdatos',true,true);
		edcontrols(new Array('i7','i8','i9','i20'),!(form.i6.checked),'fmrdatos',true,true);
		edcontrols(new Array('i11','i12','i13','i22'),!(form.i10.checked),'fmrdatos',true,true);
		edcontrols(new Array('i15','i16','i17','i24'),!(form.i14.checked),'fmrdatos',true,true);
	//ANALÍTICA EN SANGRE
	//Otro marcador de Hemólisis
		edcontrols(new Array('b31','b32','b33'),!(form.b30.checked),'fmrdatos',true,true);
		edcontrols(new Array('bb32'),!(form.b30.checked),'fmrdatos',true,false);
	//TRATAMIENTO ANTINEOPLÁSICO PREVIO
	//¿Se le ha administrado tratamiento antineoplasico previo al paciente?
		edcontrols(eval(document.fmrdatos.neob.value),!(form.j1[0].checked),'fmrdatos',true,false);	
		//concomitante
		edcontrols(eval(document.fmrdatos.concoa.value),!(form.k1[0].checked),'fmrdatos',true,false);	
}

function Chkvisitadx1(form, nvisita){
	//-----------------
	//Visitas de 1 a 10
	//-----------------

	//alert(nvisita);
	
	//TRATAMIENTO ANTINEOPLÁSICO PREVIO
	//¿Se le ha administrado tratamiento antineoplasico previo al paciente?
	edcontrols(eval(document.fmrdatos.neob.value),!(form.j1[0].checked),'fmrdatos',true,false);	
	
	if(nvisita==10){
		//HISTORIA CLÍNICA
		//Resultado de la evaluación de los siguientes sistemas
		edcontrols(new Array('f2'),!(form.f1.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f4'),!(form.f3.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f6'),!(form.f5.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f8'),!(form.f7.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f10'),!(form.f9.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f12'),!(form.f11.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f14'),!(form.f13.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f16'),!(form.f15.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f18'),!(form.f17.value=='3'),'fmrdatos',true,true);
		edcontrols(new Array('f20'),!(form.f19.value=='3'),'fmrdatos',true,true);
		
		if (form.q1[1].checked==false) edcontrols(new Array('q2','q3'),true,'fmrdatos',true,true);
		edcontrols(new Array('q4'),!(form.q3.value=='6'),'fmrdatos',true,true);
	}
	if(nvisita==1 || nvisita==4 || nvisita==6 || nvisita==8 || nvisita==10){
		//ANALÍTICA EN SANGRE
		//Otro marcador de Hemólisis
		edcontrols(new Array('b31','b32','b33'),!(form.b30.checked),'fmrdatos',true,true);
		edcontrols(new Array('bb32'),!(form.b30.checked),'fmrdatos',true,false);	
	}
		//ADMINISTRACIÓN DE NEORECORMON®
		//Inicio del tratamiento
		if (nvisita==1) {
			if (form.l1[1].checked==false) edcontrols(new Array('l2[0]','l2[1]','l4','l5'),true,'fmrdatos',true,true);
		} else {
			if (form.l1[0].checked==false) edcontrols(new Array('l2[0]','l2[1]','l4','l5'),true,'fmrdatos',true,true);
		}		
		if (form.l2[1].checked==false) edcontrols(new Array('l3'),true,'fmrdatos',true,true);
		edcontrols(new Array('l3'),!(form.l2[1].checked),'fmrdatos',true,true);
		//TRANSFUSIONES DE SANGRE
		if (form.i1[0].checked==true){edcontrols(new Array('i2','i6','i10','i14'),false,'fmrdatos',true,true);}else{edcontrols(new Array('i2','i3','i4','i5','i6','i7','i8','i9','i10','i11','i12','i13','i14','i15','i16','i17','i18','i20','i22','i24'),true,'fmrdatos',true,true);}			
		edcontrols(new Array('i3','i4','i5','i18'),!(form.i2.checked),'fmrdatos',true,true);
		edcontrols(new Array('i7','i8','i9','i20'),!(form.i6.checked),'fmrdatos',true,true);
		edcontrols(new Array('i11','i12','i13','i22'),!(form.i10.checked),'fmrdatos',true,true);
		edcontrols(new Array('i15','i16','i17','i24'),!(form.i14.checked),'fmrdatos',true,true);
		//concomitante
		edcontrols(eval(document.fmrdatos.concoa.value),!(form.k1[0].checked),'fmrdatos',true,false);
		//advsesos
		edcontrols(eval(document.fmrdatos.nadv.value),!(form.m1[0].checked),'fmrdatos',true,false);
}

function Chkvisita18(form){
	//-----------------
	//Visita F-U
	//-----------------
	
	//ACONTECIMIENTOS ADVERSOS
	//¿Sufrió el paciente algún Acontecimiento Adverso en la anterior visita?
	//edcontrols(new Array('a4[0]','a4[1]'),!(form.a3[0].checked),'fmrdatos',true,true);""
	edcontrols(eval(document.fmrdatos.nadv.value),!(form.m1[0].checked),'fmrdatos',true,false);
}


function Chkvisitaconco(form){
	//-------------------------------
	//Visita Medicación Concomitante
	//-------------------------------
	
	//finalizado
	if (existe('a9','fmrdatos')) edcontrols(new Array('a8'),!(form.a9.checked),'fmrdatos',true,true);
}

function Chkvisitaadv(form){
	//-------------------------------
	//Visita Acontecimiento Adverso
	//-------------------------------
	
	//Medidas correctoras (Registrar en página de Medicación Concomitante)
	edcontrols(new Array('a9'),!(form.a8.value=='3'),'fmrdatos',true,true);
	//Desenlace
	edcontrols(new Array('a11'),!(form.a10.value=='4'),'fmrdatos',true,true);
	edcontrols(new Array('a12'),!(form.a10.value=='1'),'fmrdatos',true,true);
}

function Chkvisitatrata(form){
	//-------------------------------
	//Visita TRATAMIENTO ANTINEOPLÁSICO PREVIO
	//-------------------------------
	
	edcontrols(new Array('a3'),!(form.a2.value=='6'),'fmrdatos',true,true);
	//if (existe('a7','fmrdatos')) edcontrols(new Array('a6'),(form.a7.checked),'fmrdatos',true,true);
}

function Chkvisitamedi(form){
	//-------------------------------
	//Visita ANAMNESIS POR APARATOS
	//-------------------------------
	
	edcontrols(new Array('a3'),!(document.fmrdatos.a2.value=='14'),'fmrdatos',true,true);
	if (document.fmrdatos.a7.checked==true) edcontrols(new Array('a6'),true,'fmrdatos',true,true);
}

function saturacion(){
	transferrina=document.fmrdatos.b2.value;
		transferrina=transferrina.replace(",",".");
		transferrina=transferrina.replace(" ","");
	hierro=document.fmrdatos.b6.value;	
		hierro=hierro.replace(",",".");
		hierro=hierro.replace(" ","");
	
	if (document.fmrdatos.b3.value!='0' && document.fmrdatos.b7.value!='0' && !isNaN(hierro) && !isNaN(transferrina) ){
		transferrina=parseFloat(transferrina);
		hierro=parseFloat(hierro);
		if (document.fmrdatos.b7.value=='1') 
			f1=1;
		else if (document.fmrdatos.b7.value=='2') 
			f1=0.1;
		else if (document.fmrdatos.b7.value=='3') 
			f1=100;
		else if (document.fmrdatos.b7.value=='4') 
			f1=0.1791;
			
		if (document.fmrdatos.b3.value=='1') f2=1; else f2=0.01;
		
		document.fmrdatos.b34.value=Math.round((hierro*f1*100)/(transferrina*f2*1.41)*100)/100;
		
		
	}
}

function calchb(){
	hbbas=document.fmrdatos.hbbasal.value;
		hbbas=hbbas.replace(",",".");
		hbbas=hbbas.replace(" ","");
	hb=document.fmrdatos.b8.value;	
		hb=hb.replace(",",".");
		hb=hb.replace(" ","");
		
	if (!isNaN(hbbas) && !isNaN(hb)) document.fmrdatos.o1.value=Math.round((hb-hbbas)*100)/100; else document.fmrdatos.o1.value='';
}
//------------------------Funciones para el Calendario------------------------

var dragapproved=false
var minrestore=0
var initialwidth,initialheight
var ie5=document.all&&document.getElementById
var ns6=document.getElementById&&!document.all

function drag_drop(e){
if (ie5&&dragapproved&&event.button==1){
document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx
document.getElementById("dwindow").style.top=tempy+event.clientY-offsety
}
else if (ns6&&dragapproved){
document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx
document.getElementById("dwindow").style.top=tempy+e.clientY-offsety
}
}

function initializedrag(e){
offsetx=ie5? event.clientX : e.clientX
offsety=ie5? event.clientY : e.clientY
if (ie5)
document.getElementById("saver").style.display=''

tempx=parseInt(document.getElementById("dwindow").style.left)
tempy=parseInt(document.getElementById("dwindow").style.top)

dragapproved=true
document.onmousemove=drag_drop
}


function newCalendar(url,height,width){
if (!ie5&&!ns6){
	var vent;
	vent=window.open(url,"","toolbar=no,directories=no,resizable=no,scrollbars=yes,status=no,menubar=no,width="+width +",height="+height);
	vent.focus();
}else{
	document.getElementById("cframe").src=url;
	document.getElementById("dwindow").style.display='';
	document.getElementById("dwindow").style.width=initialwidth=width;
	document.getElementById("dwindow").style.height=initialheight=height;
	document.getElementById("dwindow").style.left=30;
	document.getElementById("dwindow").style.top=ns6? window.pageYOffset*1+30 : document.body.scrollTop*1+30;
	
	
}
}

function closeit(){
	document.getElementById("dwindow").style.display="none";
}

function CalculoAno(val1,val2,obj)
{
	var aux=val1.substring(val1.length-4);
	if (!isNaN(aux) && aux!='' && val2!=19) obj.value=aux-val2;
	
}


//---------------------

function chkQuerie(tipo){
	var aux="";
	if (tipo=="monitor"){
		if (document.fmrdatos.motivo.value=='0') 
			aux="Debe cumplimentar correctamente el motivo";	
		else if (document.fmrdatos.motivo.value=='3' && document.fmrdatos.otros.value=='')
			aux="Debe cumplimentar correctamente Otros";		
	}else{//investigador
		if (document.fmrdatos.respuesta.value=='0') 
			aux="Debe cumplimentar correctamente la respuesta";	
		else if (document.fmrdatos.respuesta.value=='3' && document.fmrdatos.otrosresp.value=='')
			aux="Debe cumplimentar correctamente Otros";
	}
		
	if (aux=="") return true; else alert(aux);
	return false;
}

function ayudas(nayuda) {
	var aux='';

	if (nayuda=='1') {
		aux = 'Definición WHO. Evidencia gestacional por parámetros clínicos y ultrasonográficos (visualización del SG). Se incluye el embarazo ectópico. La visualización de múltiples SG en una paciente se cuenta como un embarazo clínico. Los embarazos bioquímicos no se consideran gestaciones.';
	} else if (nayuda=='2') {
		aux = 'Se considera fecha de inicio el día en que comienza el tratamiento médico (estímulo o frenado).';
	} else if (nayuda=='3') {
		aux = 'Ciclos iniciados que no llegan a punción.';
	} else if (nayuda=='4') {
		aux = 'Aspiraciones que no llegan a transferencia embrionaria por cualquier causa.';
	} else if (nayuda=='5') {
		aux = 'Total de transferencias de 1,2,3 ó 4 realizadas sin precisar su carácter electivo o no.';
	} else if (nayuda=='6') {
		aux = 'Por favor utilice las definiciones de la WHO para embarazo clínico: evidencia de gestación por parámetros clínicos y ultrasonográficos (visualización ecográfica del saco gestacional). Se incluye el embarazo ectópico. La visualización de múltiples sacos gestacionales en una paciente se cuenta como un embarazo clínico.';
	} else if (nayuda=='7') {
		aux = 'Se considera transferencia electiva de 1 embrión la transferencia de 1 embrión cuando hay más de 1 transferibles.';
	} else if (nayuda=='8') {
		aux = 'Se considera transferencia electiva de 2 embriones la transferencia de 2 embriones cuando hay más de 2 transferibles.';
	} else if (nayuda=='9') {
		//aux = 'La suma debe coincidir con el total de ciclos iniciados en cada apartado (Total ciclos iniciados en fresco: FIV, ICSI, FIV + ICSI, Total descongelaciones, Total de ciclos de donación y Total ciclos DGP).';
		aux = 'La suma debe coincidir con el total de ciclos iniciados de cada apartado (fresco, descongelaciones, donación y DGP).\n\nTotal de ciclos y gestaciones: Valores introducidos por usted en las tablas anteriores';
	} else if (nayuda=='10') {
		aux = 'Pacientes que requieren ingreso hospitalario y/o evacuación de astitis.';
	} else if (nayuda=='11') {
		aux = 'Debe coincidir con las gestaciones reflejadas en los apartados correspondientes (Ciclos en fresco, congelaciones, donación de ovocitos y DGP).';
	} else if (nayuda=='12') {
		aux = 'Valor del número de partes, no de niños en cada uno.';
	} else if (nayuda=='13') {
		aux = 'Se considera transferencia electiva de 3 embriones la transferencia de 3 embriones cuando hay más de 3 transferibles.';
	} else if (nayuda=='14') {
		aux = 'La edad gestacional se obtiene sumando 14 días al número de semanas completas desde la fecundación.';
	} else if (nayuda=='15') {
		aux = 'Incluye ovocitos usados en fresco en ciclos con ovocitos propios, en ciclos de ovodon y en ciclos de DGP';
	} else if (nayuda=='16') {
		aux = 'Incluye ovocitos crioconservados, se hayan utilizado luego o no, en ciclos con ovocitos propios, en ciclos de ovodon y en ciclos de DGP.';
	} else if (nayuda=='17') {
		aux = 'Número de donantes de ovocitos';
	} else if (nayuda=='18') {
		aux = 'En esta tabla no deben incluirse los ciclos de Diagnóstico Genético Preimplantacional.\n\n';
		aux+='Ciclos iniciados: se considera fecha de inicio el día que comienza el tratamiento médico (estímulo o frenado). Los anticonceptivos previos o ecografía en dia 0 sin gonadotropinas o análogos previos, se considera que no ha empezado el ciclo. En caso de ciclo natural se considera inicio cuando se empieza la monitorización.\n\n';
		aux+='Ciclos cancelados: ciclos iniciados que no llegan a punción.\n\n';
		aux+='Total de transferencias: total de transferencias de 1, 2 o 3 realizadas sin precisar su carácter electivo o no.\n\n'
		aux+='Gestaciones: definición WHO. Evidencia gestacional por parámetros clínicos y ultrasonográficos (visualización del SG). Se incluye el embarazo ectópico. La visualización de múltiples SG en una paciente se cuenta como un embarazo clínico. Los embarazos bioquímicos no se consideran gestaciones.';
	} else if (nayuda=='19') {
		aux = 'Transferencia electiva de X embriones: se considera TE de X embriones cuando se dispone de más de X embriones aptos para transferir y solo se transfiere X embriones. Ej. Se considera transferencia electiva de 3 embriones cuando se dispone de más de 3 embriones aptos para transferir y solo se transfieren 3 embriones';
	} else if (nayuda=='20') {
		aux = 'Numero de donantes de ovocitos: Una donante que dona dos veces solo se contabiliza en esta casilla una vez';
	} else if (nayuda=='21') {
		aux = 'Se contabilizará en este apartado los embarazos ectópicos y heterotópicos';
	} else if (nayuda=='22') {
		aux = 'Incluir en esta tabla todos los cilos de IAC, incluir los de parejas serodiscorantes tambien';
	} else if (nayuda=='23') {
		aux = 'Se refiere a partos conocidos pero de los cuales se desconoce en que semana de gestación tuvo lugar el parto. No deben incluirse en esta casilla aquellas gestaciones de las que se desconoce si se produjo parto o no';
	}
	alert(aux);
}

function calcampos (form,arr,camporet) {
	var ret=0;
	var entra=false;
	
	for (i=0;i<arr.length;i++) {
		//alert(arr[i] + " = " + );
		if ((!isNaN(eval("document."+form+"."+arr[i]+".value"))) && (eval("document."+form+"."+arr[i]+".value")!='') && (eval("document."+form+"."+arr[i]+".value")!='ND') && (eval("document."+form+"."+arr[i]+".value")!='nd')) {
			entra=true;
			ret = ret + parseFloat(eval("document."+form+"."+arr[i]+".value"));
		}
	}
	if (entra==true) {
		eval("document."+form+"."+camporet+".value=" + ret);
	} else {
		eval("document."+form+"."+camporet+".value=''");
	}
}

function calcampos1 (form,arr,camporet) {
	var ret=0;
	var entra=false;
	
	if ((!isNaN(eval("document."+form+"."+arr[0]+".value"))) && (eval("document."+form+"."+arr[0]+".value")!='') && (eval("document."+form+"."+arr[0]+".value")!='ND') && (eval("document."+form+"."+arr[0]+".value")!='nd') && (!isNaN(eval("document."+form+"."+arr[1]+".value"))) && (eval("document."+form+"."+arr[1]+".value")!='') && (eval("document."+form+"."+arr[1]+".value")!='ND') && (eval("document."+form+"."+arr[1]+".value")!='nd')) {
		entra=true;
		ret = parseFloat(eval("document."+form+"."+arr[0]+".value")) - parseFloat(eval("document."+form+"."+arr[1]+".value"))
	}
	if (entra==true) {
		eval("document."+form+"."+camporet+".value=" + ret);
	} else {
		eval("document."+form+"."+camporet+".value=''");
	}
}

function asigcampos (form,arr,camporet) {
	for (i=0;i<arr.length;i++) {
		eval("document." + form + "." + arr[i] + ".value='" + eval("document." + form + "." + camporet + ".value") + "';");
	}
}