
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function eliminar(id){
var answer = confirm("esta seguro que desea eliminar el registro?")
if (answer){
document.getElementById(id).submit();
}
else{
	alert("El registro no ha sido borrado");
}
	}
	
function validar_cambios(id){
var answer = confirm("¿Está seguro que desea aplicar los cambios?")
if (answer){
document.getElementById(id).submit();
}
else{
	alert("Los cambios no se han aplicado");
}
	}
	
function aceptaRedirige(direccion){
var answer = confirm("¿Está seguro que desea aplicar los cambios?")
if (answer){
document.location.href=direccion;
		   }
else{
	alert("Los cambios no se han aplicado");
	}
}	
		function detalles(id){
											document.getElementById(id).submit();
																}
		function validar(id){
											document.getElementById(id).submit();
																}
		function detalles_usuario(id){
											document.getElementById(id).submit();
																}

			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_validateForm() {
												 //v4.0
												  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
												  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
												    if (val) { nm=val.name; if ((val=val.value)!="") {
												      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
												        if (p<1 || p==(val.length-1)) errors+='- '+nm+' debe contener una direccion email valida.\n';
												      } else if (test!='R') { num = parseFloat(val);
												        if (isNaN(val)) errors+='- '+nm+' debe contener un numero.\n';
												        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
												          min=test.substring(8,p); max=test.substring(p+1);
												          if (num<min || max<num) errors+='- '+nm+' debe contener un numero entre '+min+' y '+max+'.\n';
												    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' es un campo obligatorio.\n'; }
												  }
												   if (errors) alert('Los siguientes errores sucedieron:\n'+errors);
												  document.MM_returnValue = (errors == '');
												}

												function textCounter(field, countfield, maxlimit) {
												if (field.value.length > maxlimit) // if too long...trim it!
												field.value = field.value.substring(0, maxlimit);
												// otherwise, update 'characters left' counter
												else
												countfield.value = maxlimit - field.value.length;
												}
												function seleccionar_todo(){
														   for (i=0;i<document.f1.elements.length;i++)
														      if(document.f1.elements[i].type == "checkbox")
														         document.f1.elements[i].checked=1
														}
														function enviar (que){
															texto="detalles.php?"+que;
															document.getElementById("f1").action=texto;
															document.getElementById("f1").submit(window.open('', 'ventanaForm', 'width=550,height=580,resizable,scrollbars=yes,status=1'));
															}
						function funcion(){
				foto=document.getElementById('fotos');
				//alert (foto.value);
				formu=document.getElementById('formu');
				formu.innerHTML="";
				var i = 0;

				for (i=0;i<foto.value;i++){
					nombre="foto"+i;
					formu.innerHTML+='<tr><td><input name = '+nombre+' size=18 type="file" maxlength="100000"></td></tr>';
				}
				}
//calendar

var oldLink = null;
// code to change the active stylesheet
function setActiveStyleSheet(link, title) {
  var i, a, main;
  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;
    }
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  link.style.fontWeight = 'bold';
  return false;
}

// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
  if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3"))
    // if we add this call we close the calendar on single-click.
    // just to exemplify both cases, we are using this only for the 1st
    // and the 3rd field, while 2nd and 4th will still require double-click.
    cal.callCloseHandler();
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks on the "Close" button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  _dynarch_popupCalendar = null;
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id, format, showsTime, showsOtherMonths) {
  var el = document.getElementById(id);
  if (_dynarch_popupCalendar != null) {
    // we already have some calendar created
    _dynarch_popupCalendar.hide();                 // so we hide it first.
  } else {
    // first-time call, create the calendar.
    var cal = new Calendar(1, null, selected, closeHandler);
    // uncomment the following line to hide the week numbers
    // cal.weekNumbers = false;
    if (typeof showsTime == "string") {
      cal.showsTime = true;
      cal.time24 = (showsTime == "24");
    }
    if (showsOtherMonths) {
      cal.showsOtherMonths = true;
    }
    _dynarch_popupCalendar = cal;                  // remember it in the global var
    cal.setRange(1900, 2070);        // min/max year allowed.
    cal.create();
  }
  _dynarch_popupCalendar.setDateFormat(format);    // set the specified date format
  _dynarch_popupCalendar.parseDate(el.value);      // try to parse the text in field
  _dynarch_popupCalendar.sel = el;                 // inform it what input field we use

  // the reference element that we pass to showAtElement is the button that
  // triggers the calendar.  In this example we align the calendar bottom-right
  // to the button.
  _dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");        // show the calendar

  return false;
}

var MINUTE = 60 * 1000;
var HOUR = 60 * MINUTE;
var DAY = 24 * HOUR;
var WEEK = 7 * DAY;

// If this handler returns true then the "date" given as
// parameter will be disabled.  In this example we enable
// only days within a range of 10 days from the current
// date.
// You can use the functions date.getFullYear() -- returns the year
// as 4 digit number, date.getMonth() -- returns the month as 0..11,
// and date.getDate() -- returns the date of the month as 1..31, to
// make heavy calculations here.  However, beware that this function
// should be very fast, as it is called for each day in a month when
// the calendar is (re)constructed.
function isDisabled(date) {
  var today = new Date();
  return (Math.abs(date.getTime() - today.getTime()) / DAY) > 10;
}

function flatSelected(cal, date) {
  var el = document.getElementById("preview");
  el.innerHTML = date;
}

function showFlatCalendar() {
  var parent = document.getElementById("display");

  // construct a calendar giving only the "selected" handler.
  var cal = new Calendar(0, null, flatSelected);

  // hide week numbers
  cal.weekNumbers = false;

  // We want some dates to be disabled; see function isDisabled above
  cal.setDisabledHandler(isDisabled);
  cal.setDateFormat("%A, %B %e");

  // this call must be the last as it might use data initialized above; if
  // we specify a parent, as opposite to the "showCalendar" function above,
  // then we create a flat calendar -- not popup.  Hidden, though, but...
  cal.create(parent);

  // ... we can show it here.
  cal.show();
}
//FIN CALENDAR
//xajax

 function autoFormAssign($id, $value)
 {
     $obj = document.getElementById($id);
     switch($obj.tagName.toLowerCase()) //tolower
     {
         case 'input':
         case 'textarea': //added text area
         switch($obj.type)
         {
             case 'checkbox':
             if ($value) $obj.checked = true;
             break;
             case 'radio':
             $radios = document.getElementsByName($id);
             for($i in $radios)
             {
                 $radio = $radios[$i];
                 if ($radio.value == $value)
                 $radio.checked = true;
                 else
                 $radio.checked = false;
             }
             break;
             default:
             $obj.value = $value;
         }
         break;
         case 'select':
         for ($i=0;$i<$obj.options.length;$i++)
         if ($obj.options[$i].value == $value) //added the value
         $obj.options[$i].selected = true;
         break;
     }
 }

normalSize = 12;
maxSize = 24;
minSize = 8;
step = 2;

function AgrandarCapa(id)
{
var elm = document.getElementById(id);
if (elm.currentStyle)
{
var fontSize = elm.currentStyle.fontSize;
}
else if (window.getComputedStyle){
var stl = document.defaultView.getComputedStyle(elm,null);
var fontSize = stl.getPropertyValue("font-size");
}
numFuente=parseInt(fontSize.substr(0,2));
	if(numFuente != '')
	{
		actualSize = numFuente;
	}
	else
	{
		actualSize = normalSize;
	}
	if (actualSize + step > maxSize){
	newSize=actualSize;
	}
	else if(actualSize + step < maxSize){
	newSize=actualSize + step;
	}


	document.getElementById(id).style.fontSize = newSize+'px';

}


function AchicarCapa(id)
{
var elm = document.getElementById(id);
if (elm.currentStyle)
{
var fontSize = elm.currentStyle.fontSize;
}
else if (window.getComputedStyle){
var stl = document.defaultView.getComputedStyle(elm,null);
var fontSize = stl.getPropertyValue("font-size");
}
numFuente=parseInt(fontSize.substr(0,2));
	if(numFuente != '')
	{
		actualSize = numFuente;
	}
	else
	{
		actualSize = normalSize;
	}
	if (actualSize - step < minSize){
	newSize=actualSize;
	}
	else if(actualSize - step > minSize){
	newSize=actualSize - step;
	}


	document.getElementById(id).style.fontSize = newSize+'px';
}

function Agrandar(plantilla)
{
	switch(plantilla)
	{
		case 'noticia' :
							AgrandarCapa('noticiaDetalleSubtitulo');
							AgrandarCapa('noticiaDetalleTexto');
							break;
							
		case 'nueva' :
							AgrandarCapa('titular');
							AgrandarCapa('entradilla');
							AgrandarCapa('cuerpo');
							AgrandarCapa('fecha');
							break;
							
	}
}

function Achicar(plantilla)
{
	switch(plantilla)
	{
		case 'noticia' :
							AchicarCapa('noticiaDetalleSubtitulo');
							AchicarCapa('noticiaDetalleTexto');
							break;
		
		case 'nueva' :
							AchicarCapa('titular');
							AchicarCapa('entradilla');
							AchicarCapa('cuerpo');
							AchicarCapa('fecha');
							break;
	}
}

function Prueba(id)
{
var stl = document.defaultView.getComputedStyle(document.getElementById('noticiaDetalleTexto'),'');
var fontSize = stl.getPropertyValue('font-size');
alert(fontSize);
}

//FECHA EN FRANCES Y ARABE


// &#1575;&#1593;&#1583;&#1575;&#1583; &#1593;&#1576;&#1583;&#1575;&#1604;&#1593;&#1586;&#1610;&#1586; &#1585;&#1580;&#1576;
//abdelaziz_info@yahoo.fr
infonavi = navigator.appName;
infoversi = parseInt(navigator.appVersion);
if ( (infonavi == "Netscape" && infoversi >= 3) ||
(infonavi == "Microsoft Internet Explorer" && infoversi >= 4)) compati = "true";
else compat = "false";
///////////////////////arabe date
function la_date_arabe(){
if (compati == "true") {
var info1=new Date();
var ardatjour=info1.getDay();
var ardatmois=info1.getMonth();
var ardate=info1.getDate();
var arannee=info1.getFullYear();
var arsemaine=new Array('&#1604;&#1571;&#1581;&#1583;','&#1575;&#1604;&#1573;&#1579;&#1606;&#1610;&#1606;','&#1575;&#1604;&#1579;&#1604;&#1575;&#1579;&#1575;&#1569;','&#1575;&#1604;&#1571;&#1585;&#1576;&#1593;&#1575;&#1569;','&#1575;&#1604;&#1582;&#1605;&#1610;&#1587;','&#1575;&#1604;&#1580;&#1605;&#1593;&#1577;','&#1575;&#1604;&#1587;&#1576;&#1578;');
var arjour=arsemaine[ardatjour];
var armoisnom=new Array('&#1580;&#1575;&#1606;&#1601;&#1610;','&#1601;&#1610;&#1601;&#1585;&#1610;','&#1605;&#1575;&#1585;&#1587;','&#1571;&#1601;&#1585;&#1610;&#1604;','&#1605;&#1575;&#1610;','&#1580;&#1608;&#1575;&#1606;','&#1580;&#1608;&#1610;&#1604;&#1610;&#1577;','&#1571;&#1608;&#1578;','&#1587;&#1576;&#1578;&#1605;&#1576;&#1585;','&#1571;&#1603;&#1578;&#1608;&#1576;&#1585;','&#1606;&#1608;&#1601;&#1605;&#1576;&#1585;','&#1583;&#1610;&#1587;&#1605;&#1576;&#1585;');
var armois=armoisnom[ardatmois];
var infotxtr=arjour+'&#1548; '+ardate+' '+armois+' '+arannee;
document.write(infotxtr);}}

//////////////////////fran?ais date

function display_todays_date(){
if (compati == "true") {
var info2 = new Date();
var frdatejour=info2.getDay();
var frdatemois=info2.getMonth();
var frdate=info2.getDate();
var frannee=info2.getFullYear();
var frsemaine = new Array('Dimanche','Lundi','Mardi','Mercredi','Jeudi','Vendredi','Samedi');
var frjour = frsemaine[frdatejour];
var frmoisnom = new Array('Janvier','F&egrave;vrier','Mars','Avril','Mai','Juin','Juillet','Ao&ucirc;t','Septembre','Octobre','Novembre','D&eacute;cembre');
var frmois = frmoisnom[frdatemois];
var infotextfr=frjour+', '+frdate+' '+frmois+' '+frannee;
document.write(infotextfr);}}

//FIN FECHA FRANCES

//HORA

function mueveReloj(){
    momentoActual = new Date()
    hora = momentoActual.getHours()
    minuto = momentoActual.getMinutes()
    segundo = momentoActual.getSeconds()

    str_segundo = new String (segundo)
    if (str_segundo.length == 1)
       segundo = "0" + segundo;

    str_minuto = new String (minuto)
    if (str_minuto.length == 1)
       minuto = "0" + minuto;

    str_hora = new String (hora)
    if (str_hora.length == 1)
       hora = "0" + hora;

    horaImprimible = hora + ":" + minuto + ":" + segundo;
	document.getElementById('reloj').innerHTML=horaImprimible;
    setTimeout("mueveReloj()",1000);
}

//////
function url(menu){
url = menu;
document.location.href=url;
}

function activar(nombre){
document.getElementById(nombre).disabled=false;
}
function desactivar(nombre){
document.getElementById(nombre).disabled=true;
}

function fecha(){
var now = new Date()
var dia = now.getDay()
var mes = now.getMonth()
var fecha
if(dia==0){
fecha="Domingo, ";
}else if(dia==1){
fecha="Lunes, ";
}else if(dia==2){
fecha="Martes, ";
}else if(dia==3){
fecha="Miércoles, ";
}else if(dia==4){
fecha="Jueves, ";
}else if(dia==5){
fecha="Viernes, ";
}else{
fecha="Sábado, ";
}
fecha = fecha + now.getDate() + " de "
//El nombre del mes
if(mes==0){
fecha=fecha + "Enero"
}else if(mes==1){
fecha=fecha + "Febrero"
}else if(mes==2){
fecha=fecha + "Marzo"
}else if(mes==3){
fecha=fecha + "Abril"
}else if(mes==4){
fecha=fecha + "Mayo"
}else if(mes==5){
fecha=fecha + "Junio"
}else if(mes==6){
fecha=fecha + "Julio"
}else if(mes==7){
fecha=fecha + "Agosto"
}else if(mes==8){
fecha=fecha + "Septiembre"
}else if(mes==9){
fecha=fecha + "Octubre"
}else if(mes==10){
fecha=fecha + "Noviembre"
}else{
fecha=fecha + "Diciembre"
}
fecha = fecha + " de " + now.getFullYear()
return fecha
}

function mueveReloj(){
    momentoActual = new Date()
    hora = momentoActual.getHours()
    minuto = momentoActual.getMinutes()
    segundo = momentoActual.getSeconds()

    str_minuto = new String (minuto)
    if (str_minuto.length == 1)
       minuto = "0" + minuto

    str_hora = new String (hora)
    if (str_hora.length == 1)
       hora = "0" + hora

    horaImprimible = hora + " : " + minuto

   document.form_reloj.reloj.value = horaImprimible
	//document.getElementById(reloj).writeHTML("hola");
    setTimeout("mueveReloj()",1000)
}

function aparece_div(id, valor){
if (valor==0){
desp=document.getElementById(id);
desp.style.height='250px';
document.getElementById('ID_REGION').disabled=false;
desp.style.visibility='visible';
new Effect.SlideDown(desp);	
}
else{
desp=document.getElementById(id);
new Effect.SlideUp(desp);
document.getElementById('ID_REGION').disabled=true;
}
}

function comprueba_extension(formulario, archivo) {
   extensiones_permitidas = new Array(".gif", ".jpg", ".png");
   mierror = "";
   if (!archivo) {
      //Si no tengo archivo, es que no se ha seleccionado un archivo en el formulario
       mierror = "No has seleccionado ningún archivo";
   }else{
      //recupero la extensión de este nombre de archivo
      extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase();
      //alert (extension);
      //compruebo si la extensión está entre las permitidas
      permitida = false;
      for (var i = 0; i < extensiones_permitidas.length; i++) {
         if (extensiones_permitidas[i] == extension) {
         permitida = true;
         break;
         }
      }
      if (!permitida) {
         mierror = "Comprueba la extensión de los archivos a subir. \nSólo se pueden subir archivos con extensiones: " + extensiones_permitidas.join();
       }else{
          //submito!
         formulario.submit();
         return 1;
       }
   }
   //si estoy aqui es que no se ha podido submitir
   alert (mierror);
   return 0;
} 

function fechamov(valor){

Element.show(document.getElementById('fecha_movimiento'));
mov=document.getElementById('titulo_fecha_movimiento');
titmov=document.getElementById('titfmovim');
hidden=document.getElementById('fmovhidden');
if (valor=='ID_CAT[]'){
traduccion="Categoria";
}
else if (valor=="SITUACION"){
traduccion="Situaci&oacute;n";
}
else if (valor=="ID_CENTRO[]"){
traduccion="Centro";
}
else if (valor=="MINUSVALIA"){
traduccion="Minusvalia";
}
else if (valor=="ID_DESPLAZAMIENTO[]"){
traduccion="Desplazamiento";
}
else if (valor=="id_titulacion[]"){
traduccion="Formaci&oacute;n";
}
else if (valor=="id[]"){
traduccion="Titulaci&oacute;n";
}
else if (valor=="TIPO_JORNADA"){
traduccion="Tipo de Jornada";
}
titmov.innerHTML="Recuerda cambiar la fecha de movimiento del cambio realizado en "+traduccion;
hidden.value=valor;

//modificar un hidden previamente creado, con el nombre del campo al que sirve fecha

}

//igualar altura de columnas
function altura(){
		al = new Array();
		max = 0;
		try{
			if(document.getElementById){
				for(i=0;i<arguments.length;i++){
					if(document.getElementById(arguments[i]))
						al[i] = document.getElementById(arguments[i]).clientHeight;
				}
				max = mayor(al);
				if(max > 0){
					for(i=0;i<arguments.length;i++){
						if(document.getElementById(arguments[i]))
							document.getElementById(arguments[i]).style.height = max + 'px';
					}
				}
			}
		
		}
		catch (exc) {
			alert("Se ha producido un error en la carga del CSS. La página seguirá operativa pero algo más lenta.");
			throw exc;
		}
	}
	function mayor(datos){
		salida = 0;
		for(i=0;i<datos.length;i++){
			if(parseInt(datos[i]) > salida)
				salida = datos[i];
		}
		return salida;
		}
	function grita(lala){
	alert (lala);
	}
	


function valida_formulario_correo(){
	
	 var errors='';

    if (document.form1.nombre.value.length==0){
       errors+='- Nombre.\n';
    }
	if (document.form1.apellidos.value.length==0){
       errors+='- Apellidos\n';
    }
	if (document.form1.dni.value.length==0){
       errors+='- DNI\n';
    }
	
	
	if (document.form1.id_centro_trabajo.value==0){
       errors+='- Centro de Trabajo\n';
    }
	
	
	/*
	if (document.form1.direccion.value.length==0){
       errors+='- Dirección\n';
    }
	if (document.form1.cp.value.length==0){
       errors+='- Código Postal\n';
    }
	if (document.form1.id_provincia.value==0){
       errors+='- Provincia\n';
    }
	if (document.form1.telefono.value.length==0){
       errors+='- Teléfono\n';
    }
	*/
	
	
	
	if (document.form1.ID_CAT.value.length==0){
       errors+='- Categoria\n';
    }
	
	/*
	if (document.form1.departamento.value.length==0){
       errors+='- Departamento\n';
    }
	
	if (document.form1.responsable.value.length==0){
       errors+='- Responsable\n';
    }
	*/
	
	
	
	
	if (errors) {
		alert('Los siguientes campos son obligatorios:\n'+errors);
	}else{
		document.form1.submit();	
	}

}




function mostrar_ocultar(nombreCapa){

	if (document.getElementById('ID_CENTRO').value=="11") {
		document.getElementById(nombreCapa).style.display= "block";
	}else{
		document.getElementById(nombreCapa).style.display= "none";
		document.getElementById('input_departamento').value= "";
	}
}



function solo_numeros(e) {
  tecla = (document.dni) ? e.keyCode : e.which;
  if (tecla < 45 || tecla > 57) return false;
  else
  return true;
}