
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_timelineStop(tmLnName) { //v1.2
  //Copyright 1997, 2000 Macromedia, Inc. All rights reserved.
  if (document.MM_Time == null) MM_initTimelines(); //if *very* 1st time
  if (tmLnName == null)  //stop all
    for (var i=0; i<document.MM_Time.length; i++) document.MM_Time[i].ID = null;
  else document.MM_Time[tmLnName].ID = null; //stop one
}

function P7_Snap() { //v2.62 by PVII
  var x,y,ox,bx,oy,p,tx,a,b,k,d,da,e,el,args=P7_Snap.arguments;a=parseInt(a);
  for (k=0; k<(args.length-3); k+=4)
   if ((g=MM_findObj(args[k]))!=null) {
    el=eval(MM_findObj(args[k+1]));
    a=parseInt(args[k+2]);b=parseInt(args[k+3]);
    x=0;y=0;ox=0;oy=0;p="";tx=1;da="document.all['"+args[k]+"']";
    if(document.getElementById) {
     d="document.getElementsByName('"+args[k]+"')[0]";
     if(!eval(d)) {d="document.getElementById('"+args[k]+"')";if(!eval(d)) {d=da;}}
    }else if(document.all) {d=da;} 
    if (document.all || document.getElementById) {
     while (tx==1) {p+=".offsetParent";
      if(eval(d+p)) {x+=parseInt(eval(d+p+".offsetLeft"));y+=parseInt(eval(d+p+".offsetTop"));
      }else{tx=0;}}
     ox=parseInt(g.offsetLeft);oy=parseInt(g.offsetTop);var tw=x+ox+y+oy;
     if(tw==0 || (navigator.appVersion.indexOf("MSIE 4")>-1 && navigator.appVersion.indexOf("Mac")>-1)) {
      ox=0;oy=0;if(g.style.left){x=parseInt(g.style.left);y=parseInt(g.style.top);
      }else{var w1=parseInt(el.style.width);bx=(a<0)?-5-w1:-10;
      a=(Math.abs(a)<1000)?0:a;b=(Math.abs(b)<1000)?0:b;
      x=document.body.scrollLeft + event.clientX + bx;
      y=document.body.scrollTop + event.clientY;}}
   }else if (document.layers) {x=g.x;y=g.y;var q0=document.layers,dd="";
    for(var s=0;s<q0.length;s++) {dd='document.'+q0[s].name;
     if(eval(dd+'.document.'+args[k])) {x+=eval(dd+'.left');y+=eval(dd+'.top');break;}}}
   if(el) {e=(document.layers)?el:el.style;
   var xx=parseInt(x+ox+a),yy=parseInt(y+oy+b);
   if(navigator.appName=="Netscape" && parseInt(navigator.appVersion)>4){xx+="px";yy+="px";}
   if(navigator.appVersion.indexOf("MSIE 5")>-1 && navigator.appVersion.indexOf("Mac")>-1){
    xx+=parseInt(document.body.leftMargin);yy+=parseInt(document.body.topMargin);
    xx+="px";yy+="px";}e.left=xx;e.top=yy;}}
}
function popup(popupfile,PopupWindow,winheight,winwidth){
	open(popupfile,PopupWindow,"toolbar=no,menubar=no,resizable=yes,height=" + winheight + ",width=" + winwidth + ",scrollbars=no");
}
function popup3(popupfile,PopupWindow,winheight,winwidth){
	open(popupfile,PopupWindow,"toolbar=no,menubar=no,resizable=yes,height=" + winheight + ",width=" + winwidth + ",scrollbars=yes");
}


function popup2(popupfile,PopupWindow,winheight,winwidth){
	open(popupfile,PopupWindow,"toolbar=yes,menubar=yes,resizable=yes,height=" + winheight + ",width=" + winwidth + ",scrollbars=yes");
}

function MM_displayStatusMsg(msgStr) { //v1.0
	  status=msgStr;
	  document.MM_returnValue = true;
	}
	

function esFecha(campoForm){

	if (campoForm.value!="" && !isDate(campoForm.value)){
		alert("Fecha incorrecta en el campo "+campoForm.name+" DD/MM/YYYY");
		campoForm.value="";
		return false;
	}
	return true;

}

function esHora(campoForm){

	if (campoForm.value!="" && !isHour(campoForm.value)){
		alert("Hora incorrecta en el campo "+campoForm.name+" HH:MM:SS" );
		campoForm.value="";
		return false;
	}
	return true;

}
function isDate(dateStr) {

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	var today=new Date();
	fecha_hoy=today.getTime();
	fecha_otra=Date.parse(dateStr);
	//if (fecha_otra<fecha_hoy){
	//	alert("La fecha ha de ser mayor o igual a la actual");	
	//}
	if (matchArray == null) {
	return false;
	}
	
	day = matchArray[1]; // p@rse date into variables
	month = matchArray[3];
	year = matchArray[5];
	
	if (month < 1 || month > 12) { // check month range
	return false;
	}
	
	if (day < 1 || day > 31) {
	return false;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
	alert("El mes "+month+" no tiene 31 dias !")
	return false;
	}
	
	if (month == 2) { // check for february 29th
	var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
	if (day > 29 || (day==29 && !isleap)) {
	alert("Febrero  " + year + " no tiene " + day + " dias!");
	return false;
	}
}
	
	return true; // date is valid
}


function isHour(dateStr) {

	var datePat = /^(\d{1,2})(\:)(\d{1,2})((\:)(\d{1,2})){0,1}$/;
	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
	return false;
	}
	

	return true; // date is valid
}

function esNumero(cadena){
    var ok=1;
    if (cadena.length==0) return true;
    charValidos	= "0123456789.,";
    for(i=0;i<cadena.length && ok==1;i++){
	ok=0;
	if (charValidos.indexOf(cadena.charAt(i))>=0) ok=1;
    }
	
    if (ok==0){
	return false;
     }
     else return true;
}

function fesNumero(campoform){
	if (campoform.value!="" && !esNumero(campoform.value)){
		alert("El campo  "+campoform.name+" ha de ser númerico");
		campoform.value="";
		return false;
	}
	return true;
}


	
function deshabilitar(){// solo para la pagina sesion_curso
	sesion_form.lunes.disabled=true;
	sesion_form.martes.disabled=true;
	sesion_form.miercoles.disabled=true;
	sesion_form.jueves.disabled=true;
	sesion_form.viernes.disabled=true;
	sesion_form.sabado.disabled=true;
	sesion_form.domingo.disabled=true;

}
function habilitar(){// solo para la pagina sesion_curso
	sesion_form.lunes.disabled=false;
	sesion_form.martes.disabled=false;
	sesion_form.miercoles.disabled=false;
	sesion_form.jueves.disabled=false;
	sesion_form.viernes.disabled=false;
	sesion_form.sabado.disabled=false;
	sesion_form.domingo.disabled=false;

}

function comprobar_fecha(){// solo para la pagina sesion_curso
	ano_fin=sesion_form.ano_fin.value;
	ano_ini=sesion_form.ano_inicio.value;
	mes_fin=sesion_form.mes_fin.value;
	mes_ini=sesion_form.mes_inicio.value;
	dia_fin=sesion_form.dia_fin.value;
	dia_ini=sesion_form.dia_inicio.value;
	f_ini=dia_ini+"/"+mes_ini+"/"+ano_ini;
	f_fin=dia_fin+"/"+mes_fin+"/"+ano_fin;
	if(isDate(f_ini)&&isDate(f_fin)){
		if(DateDiff(transfomar_fecha(f_ini),transfomar_fecha(f_fin),"d")<1)deshabilitar(); 
		else habilitar();
	}
}
function comprobar_formulario(mod){// solo para la pagina sesion_curso
	
		
		ano_ini=parseInt(sesion_form.ano_inicio.value);
		mes_ini=parseInt(sesion_form.mes_inicio.value);
		dia_ini=parseInt(sesion_form.dia_inicio.value);
		hora_fin=parseInt(sesion_form.hora_fin.value);
		hora_ini=parseInt(sesion_form.hora_inicio.value);
		min_fin=parseInt(sesion_form.min_fin.value);
		min_ini=parseInt(sesion_form.min_inicio.value);
		
		if (mod==1){
			ano_fin=parseInt(sesion_form.ano_fin.value);
			mes_fin=parseInt(sesion_form.mes_fin.value);
			dia_fin=parseInt(sesion_form.dia_fin.value);
			fecha_fin=dia_fin+"/"+mes_fin+"/"+ano_fin
			if (!isDate(fecha_fin)){
			return false;	
		}
			
		}
		
		fecha_ini=dia_ini+"/"+mes_ini+"/"+ano_ini
		if (!isDate(fecha_ini)){
			return false;	
		}
		
		if ((hora_fin <hora_ini)||(hora_fin ==  hora_ini && min_fin <=min_ini)){
			alert('Error la hora final ha de ser posterior a la inicial');
			return false;
		}
		if (sesion_form.aula.value==0){
			alert('Tiene que introducir una Aula');
			return false;
		}
		if (sesion_form.formador1.value==0 && sesion_form.formador2.value==0){
			alert('Tiene que introducir como mínimo un formador');
			return false;
		}
		if(sesion_form.mat1.value!=0 && sesion_form.cant1.value==""){
					alert('Ha de introducir la cantidad del material 1'+ sesion_form.mat1.value);
					return false;
		}
		if(sesion_form.mat2.value!=0 && sesion_form.cant2.value==""){
					alert('Ha de introducir la cantidad del material 2');
					return false;
		}
		if(sesion_form.mat3.value!=0 && sesion_form.cant3.value==""){
					alert('Ha de introducir la cantidad del material 3');
					return false;
		}
		if(sesion_form.mat4.value!=0 && sesion_form.cant4.value==""){
					alert('Ha de introducir la cantidad del material 4');
					return false;
		}
		return true;
	
}
function transfomar_fecha(fecha){
	ano = fecha.substring(6,10);
	mes = fecha.substring(3,5);
	dia = fecha.substring(0,2);
	fecha2=mes.concat("/").concat(dia).concat("/").concat(ano);
	return fecha2;
	
}


function DateDiff( 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 null ;
    }
	
    // check that an interval parameter was not numeric. 
    if ( interval.charAt == 'undefined' ) {
        // the user specified an incorrect interval, handle the error. 
        alert( intervalMsg ) ;
        return null ;
    }
    
    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 ;
}
	
function MM_initTimelines() { //v4.0
    //MM_initTimelines() Copyright 1997 Macromedia, Inc. All rights reserved.
    var ns = navigator.appName == "Netscape";
    var ns4 = (ns && parseInt(navigator.appVersion) == 4);
    var ns5 = (ns && parseInt(navigator.appVersion) > 4);
    document.MM_Time = new Array(1);
    document.MM_Time[0] = new Array(1);
    document.MM_Time["Timeline1"] = document.MM_Time[0];
    document.MM_Time[0].MM_Name = "Timeline1";
    document.MM_Time[0].fps = 15;
    document.MM_Time[0][0] = new String("behavior");
    document.MM_Time[0][0].frame = 31;
    document.MM_Time[0][0].value = "MM_showHideLayers('Layer1','','hide');MM_timelineStop('Timeline1')";
    document.MM_Time[0].lastFrame = 31;
    for (i=0; i<document.MM_Time.length; i++) {
        document.MM_Time[i].ID = null;
        document.MM_Time[i].curFrame = 0;
        document.MM_Time[i].delay = 1000/document.MM_Time[i].fps;
    }
}

function esemail(texto) { 
var textoStr = texto.toString() // transformo a string todo el campo
var tiene = 0
for(var i = 0;i < texto.length;i++){ // recorro letra por letra
var oneChar = textoStr.charAt(i) 
if (oneChar == "@"){ // busco una arroba en cada letra
tiene = 1 
} 
} if (tiene == 1){ // controlo si existe o no una arroba
return true 
} else { 
alert("El Email no es valido") 
return false 
} 
}


function DiaSemana(fecha) {


year = fecha.substring(6,10);
month = fecha.substring(3,5);
day = fecha.substring(0,2);

var oyear=year

//var dob = " "+ year +", "+month + ",  "+day;
var dob=month+"-"+day+"-"+year;
var thenx = new Date(dob);

var year=thenx.getYear();
if (year<100) year="19" + thenx.getYear();
else year=thenx.getYear();

if (year > 1969) wyear=year;
else {
if (oyear<1900) {
if (oyear>1800) {
wrelyear= (eval(oyear)-1801)%(28);
wyear = wrelyear+1981;
}
else wyear = 1970 
}
else
if (oyear>1900) {wrelyear= (eval(oyear)-1901)%(28); 
wyear= wrelyear+1985
}
else 
if (oyear==1900) {wyear= 1990;
   }              
}
//var dob = " "+ wyear +", "+month + ",  "+day;
var dob=month+"-"+day+"-"+year;
var thenx = new Date(dob);

var theday = thenx.getDay()+1;
var date=thenx.getDate();

var weekday = new Array(6);
weekday[1]="D";
weekday[2]="L";
weekday[3]="M";
weekday[4]="X";
weekday[5]="J";
weekday[6]="V";
weekday[7]="S";
if (day != date) return -1;
else {
dayborn = weekday[theday];
dob = dayborn;
return dob;
   }
}


function calcular_edad(fecha){ 

    //calculo la fecha de hoy 
    hoy=new Date() 
    //alert(hoy) 

    //calculo la fecha que recibo 
    //La descompongo en un array 
    var array_fecha = fecha.split("/") 
    //si el array no tiene tres partes, la fecha es incorrecta 
    if (array_fecha.length!=3) 
       return false 

    //compruebo que los ano, mes, dia son correctos 
    var ano 
    ano = parseInt(array_fecha[2]); 
    if (isNaN(ano)) 
       return false 

    var mes 
    mes = parseInt(array_fecha[1]); 
    if (isNaN(mes)) 
       return false 

    var dia 
    dia = parseInt(array_fecha[0]); 
    if (isNaN(dia)) 
       return false 


    //si el año de la fecha que recibo solo tiene 2 cifras hay que cambiarlo a 4 
    if (ano<=99) 
       ano +=1900 

    //resto los años de las dos fechas 
    edad=hoy.getYear()- ano - 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 (hoy.getMonth() + 1 - mes < 0) //+ 1 porque los meses empiezan en 0 
       return edad 
    if (hoy.getMonth() + 1 - mes > 0) 
       return edad+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 (hoy.getUTCDate() - dia >= 0) 
       return edad + 1 

    return edad 
} 

function cerrar_hijo_top(){
	if (!window.top.opener.closed) {
			window.top.opener.parent.location.reload();
			window.top.opener.parent.focus();
	}
	window.top.close();
}

<!--function cerrar_hijo(){ 	if (!window.opener.closed) { 			window.opener.location.reload(); 			window.opener.focus();	}	window.top.close();}-->


function cerrar_hijo(){
	y=window.top.opener.document.body.scrollTop;
		if (!window.top.opener.closed) {
			window.top.opener.location.reload();
			//setTimeout("window.top.opener.scrollTo(0,y)",500);
			if (y!=0) {
				//window.top.opener.scrollTo(0,y);
				setTimeout("window.top.opener.scrollTo(0,y)",500);		
			 }		
	}
	setTimeout("window.close()",1000);
}



