
function prueba(){
	alert("prueba");
}

function ventana(url, titulo, w, h){ 
   var ventana = window.open(""+url+"",""+ titulo + "","Width="+w+",Height="+h+",scrollbars=yes");
}



function isChecked(isitchecked){
   if (isitchecked == true){
      document.adminForm.boxchecked.value++;
   }
   else {
      document.adminForm.boxchecked.value--;
   }
}

function isChecked_not(isitchecked){
   if (isitchecked == true){
      document.adminForm.boxchecked_not.value++;
   }
   else {
      document.adminForm.boxchecked_not.value--;
   }
}

function isChecked_usu(isitchecked){
   if (isitchecked == true){
      document.adminForm.boxchecked_usu.value++;
   }
   else {
      document.adminForm.boxchecked_usu.value--;
   }
}

function checkAll(n){
   var fldName = 'cb';
   var f = document.adminForm;
   var c = f.cball.checked;
   var n2 = 0;
   for (i=0; i < n; i++) {
      cb = eval( 'f.' + fldName + '' + i );
      if (cb) {
         cb.checked = c;
         n2++;
      }
   }
   if (c) {
      document.adminForm.boxchecked.value = n2;
   } else {
      document.adminForm.boxchecked.value = 0;
   }
}

function deleteList(accion){
   if (document.adminForm.boxchecked.value == 0){
      alert('Selecciona por lo menos un usuario a borrar');
   } else {
	   if (confirm('¿Seguro que desea borralo?')){
		  document.adminForm.accion.value = accion;
		  try {
			 document.adminForm.onsubmit();
		  }
		  catch(e){}
		  document.adminForm.submit();
	   }
   }
}

function edit(accion){
   if (document.adminForm.boxchecked.value == 0){
      alert('Selecciona por lo menos un usuario a editar');
   } else{
      document.adminForm.accion.value = accion;
      try {
         document.adminForm.onsubmit();
      }
      catch(e){}
      document.adminForm.submit();
   }
}

function saveempresa(accion, comprobacion){
   
   if (comprobacion){
	  if ( ! eval(comprobacion+"()") ){
		 alert("Error, debe rellenar los campos obligatorios");
	     return false;
	  }
   }
   
   if (ComprobacionesEmpresa() && ComprobacionesUsuario() ){
      document.adminForm.accion.value = accion;
      try {
         document.adminForm.onsubmit();
      }
      catch(e){}
      document.adminForm.submit();
   }
}



function saveusuario(accion,comprobacion){
   if (comprobacion){
	  if ( ! eval(comprobacion+"()") ){
		 alert("Error, debe rellenar los campos obligatorios");
	     return false;
	  }
   }
   if (ComprobacionesUsuario()){
      document.adminForm.accion.value = accion;
      try {
         document.adminForm.onsubmit();
      }
      catch(e){}
      document.adminForm.submit();
   }
}


function buscar(accion){
  document.adminForm.accion.value = accion;
  try {
	 document.adminForm.onsubmit();
  }
  catch(e){}
  document.adminForm.submit();
}

function ComprobacionesUsuario(){

	if (!CompruebaTipoFoto(document.adminForm.foto_usuario.value, 'Foto')){
		return false;
	}
	
	if (document.adminForm.nombre.value.length == 0){
		alert("\"Nombre\" es un campo obligatorio");
		return false;
	}
	if (document.adminForm.apellidos.value.length == 0){
		alert("\"Apellidos\" es un campo obligatorio");
		return false;
	}
	/*
	if (document.adminForm.direccion.value.length == 0){
		alert("\"Dirección\" es un campo obligatorio");
		return false;
	}
	*/
	if (document.adminForm.cp.value.length == 0){
			alert("\"Código postal\" es un campo obligatorio");
			return false;
	}	else {
		if (! /^\d{5}$/.test(document.adminForm.cp.value)){
			alert("El código postal debe contener 5 dígitos.");
			return false;
		}
	}
	if (! /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.adminForm.correo.value)){
		alert("La dirección de email es incorrecta.");
		return false;
	}
	if (document.adminForm.usuarioo.value.length < 4){
		alert("\"Usuario\" debe contener un mínimo de 4 caracteres");
		return false;
	}	
	if ((document.adminForm.tipo) || (document.adminForm.pass2.value.length > 0)){
		if (document.adminForm.pass2.value != document.adminForm.pass2v.value){
			alert("\"Password\" y \"Verificar Password\" deben ser iguales");
			return false;
		}
		if ((document.adminForm.pass2.value.length < 4) || (document.adminForm.pass2.value.length > 10)){
			alert("\"Password\" debe contener entre 4 y 10 caracteres");
			return false;
		}
	}
	return true;
}

function ComprobacionesEmpresa(){
	
	if (!CompruebaTipoFoto(document.adminForm.logo.value, 'Logotipo')){
		return false;
	}
	
	if (document.adminForm.nombrecomercial.value.length == 0){
		alert("\"Nombre Comercial\" es un campo obligatorio");
		return false;  
	}
	if (document.adminForm.nombrelegal.value.length == 0){
		alert("\"Razón Social\" es un campo obligatorio");
		return false;
	}
	if (document.adminForm.NIF.value.length < 9){
		alert("\"NIF\" debe contener un mínimo de 9 caracteres");
		return false;
	}
	if (document.adminForm.tel_empresa.value.length != 9 && document.adminForm.tel_empresa.value.length != 0){ 
		if (! /^\d*$/.test(document.adminForm.tel_empresa.value)){
			alert("Teléfono de la empresa incorrecto.");
			return false;
		} 
		alert("Teléfono debe contener 9 dígitos.");
		return false;
	}
	if (! /^\d*$/.test(document.adminForm.fax_empresa.value)){
		alert("Fax de la empresa incorrecto.");
		return false;
	}	
	
	if (document.adminForm.correo_empresa.value.length != 0){
		if (! /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(document.adminForm.correo_empresa.value)){
			alert("La dirección de email de la empresa es incorrecta.");
			return false;
		}
	}
	return true;
}



function CompruebaRango(){
   	if (document.adminForm.rango.value == 2){
		document.adminForm.sec_form.disabled = false;
		document.adminForm.sec_not.disabled = false;
		document.adminForm.sec_trab.disabled = false;
		document.adminForm.sec_usu.disabled = false;
		document.adminForm.sec_5.disabled = false;
		document.adminForm.sec_6.disabled = false;
		document.adminForm.sec_7.disabled = false;		
		
		if  (document.adminForm.sec_form1){
		   if (document.adminForm.sec_form1.value == "1")
			   document.adminForm.sec_form.checked = true;
			else
			   document.adminForm.sec_form.checked = false;
		}
		else {
			document.adminForm.sec_form.checked = false;
		}
		if  (document.adminForm.sec_not1){
			if  (document.adminForm.sec_not1.value == "1")
				document.adminForm.sec_not.checked = true;
			else
				document.adminForm.sec_not.checked = false;
		}
		else {
			document.adminForm.sec_not.checked = false;
		}	
		if  (document.adminForm.sec_trab1){
			if  (document.adminForm.sec_trab1.value == "1")
				document.adminForm.sec_trab.checked = true;
			else
				document.adminForm.sec_trab.checked = false;
		}
		else{
			document.adminForm.sec_trab.checked = false;
		}	
		if  (document.adminForm.sec_usu1){
			if  (document.adminForm.sec_usu1.value == "1")
				document.adminForm.sec_usu.checked = true;
			else
				document.adminForm.sec_usu.checked = false;
		}
		else{
			document.adminForm.sec_usu.checked = false;
		}
		if  (document.adminForm.sec_51){
			if  (document.adminForm.sec_51.value == "1")
				document.adminForm.sec_5.checked = true;
			else
				document.adminForm.sec_5.checked = false;
		}
		else {
			document.adminForm.sec_5.checked = false;
		}
		if  (document.adminForm.sec_61){
			if  (document.adminForm.sec_61.value == "1")
				document.adminForm.sec_6.checked = true;
			else
				document.adminForm.sec_6.checked = false;
		}
		else {
			document.adminForm.sec_6.checked = false;
		}
		if  (document.adminForm.sec_71){
			if  (document.adminForm.sec_71.value == "1")
				document.adminForm.sec_7.checked = true;
			else
				document.adminForm.sec_7.checked = false;
		}
		else {
			document.adminForm.sec_7.checked = false;
		}
			
	} else {
		if (document.adminForm.sec_form){
			document.adminForm.sec_form.disabled = true;
			document.adminForm.sec_not.disabled = true;
			document.adminForm.sec_trab.disabled = true;
			document.adminForm.sec_usu.disabled = true;
			document.adminForm.sec_5.disabled = true;
			document.adminForm.sec_6.disabled = true;
			document.adminForm.sec_7.disabled = true;		
			switch(document.adminForm.rango.value){
				case "1":
				document.adminForm.sec_form.checked = true;
				document.adminForm.sec_not.checked = true;
				document.adminForm.sec_trab.checked = true;
				document.adminForm.sec_usu.checked = true;
				document.adminForm.sec_5.checked = true;
				document.adminForm.sec_6.checked = true;
				document.adminForm.sec_7.checked = true;			
				break;
				default:
				document.adminForm.sec_form.checked = false;
				document.adminForm.sec_not.checked = false;
				document.adminForm.sec_trab.checked = false;
				document.adminForm.sec_usu.checked = false;
				document.adminForm.sec_5.checked = false;
				document.adminForm.sec_6.checked = false;
				document.adminForm.sec_7.checked = false;			
				break;
			}
		}
		
	}
	if (document.adminForm.rango.value == 4){
		document.getElementById("tipo_med").style.display = "";
	} else {
		document.getElementById("tipo_med").style.display = "none";
	}
	if (document.adminForm.rango.value == 3){
  		document.getElementById("zona_empresa").style.display = "";
	} else {
		document.getElementById("zona_empresa").style.display = "none";
	}
}



function save(accion,comprobacion){
 
  if (comprobacion){
	  if ( ! eval(comprobacion+"()") ){
	     return false;
	  }
  }
  document.adminForm.accion.value = accion;
  try {
     document.adminForm.onsubmit();
  }
  catch(e){}
  document.adminForm.submit();
}



function save2(accion,comprobacion){
 
  if (comprobacion){
	  if ( ! eval(comprobacion+"()") ){
	     return false;
	  }
  }
  document.adminForm2.accion.value = accion;
  try {
     document.adminForm2.onsubmit();
  }
  catch(e){}
  document.adminForm2.submit();
}


function delet(accion,id){
   if (id)
      document.adminForm.id_aux.value = id;
   if (confirm('¿Seguro que desea borralo?')){
   	  document.adminForm.accion.value = accion;
      try {
         document.adminForm.onsubmit();
      }
      catch(e){}
      document.adminForm.submit();
   }
}

function CambiaPais(){
   var cod_esp = document.adminForm.cod_esp.value;
   if (document.adminForm.pais.value == cod_esp){
		document.getElementById("seccion1").style.display = "";
   }
   else {
	   document.getElementById("seccion1").style.display = "none";
   }
}


function CambiaProv(accion){
	document.adminForm.accion.value = accion;
	try {
	   document.adminForm.onsubmit();
	}
	catch(e){}
	document.adminForm.submit();
}


function CompruebaCV(){
   var f = document.adminForm;
   if(f.nif.value.length != "0"){
      if (!CompruebaNIF("nif"))   return false;
   }
   if(document.getElementById("seccion1").style.display == ""){
	    if (f.cod_postal.value.length == 0){
			alert("Es necesario que introduzcas el código postal.");
			return false;
		}	else {
			if (! /^\d{5}$/.test(f.cod_postal.value)){
				alert("El código postal debe contener 5 dígitos.");
				return false;
			}
	   } 
   }
   return true;
      
}

function CompruebaNIF(id_nif) {
		var nif = document.getElementById(id_nif);
		    nif.value = nif.value.toUpperCase();
        var letras = 'TRWAGMYFPDXBNJZSQVHLCKE';
        var letras2 = 'trwagmyfpdxbnjzsqvhlcke';
        var n = nif.value.substring(0,8);
        var numero = n%23;
        var l = nif.value.substring(8,9);
        var ll = letras.substring(numero, numero+1);
        var l2 = letras2.substring(numero, numero+1);
        if ((l != ll) && (l != l2)) {
                alert("Letra del NIF no válida.");
                nif.focus();
				return false;
        }
        var exp_nif = new RegExp ("^[0-9]{8}[A-Z]{1}$");
        var exp_cif = new RegExp ("^[A-Z]{1}[0-9]{8}$");
        if ((!exp_nif.test(nif.value)) && (!exp_cif.test(nif.value))) {
                alert("NIF no válido");
                nif.focus();
				return false;
        }
		return true;
}

function limpiar()	{
	f = document.getElementById("foto");
	nuevoFile = document.createElement("input");
	nuevoFile.id = f.id;
	nuevoFile.type = "file";
	nuevoFile.name = "foto";
	nuevoFile.value = "";
	nuevoFile.onchange = f.onchange;
	nodoPadre = f.parentNode;
	nodoSiguiente = f.nextSibling;
	nodoPadre.removeChild(f);
	(nodoSiguiente == null) ? nodoPadre.appendChild(nuevoFile):
		nodoPadre.insertBefore(nuevoFile, nodoSiguiente);
}

function limpiar2(nombre)	{
	f = document.getElementById(nombre);
	nuevoFile = document.createElement("input");
	nuevoFile.id = f.id;
	nuevoFile.type = "file";
	nuevoFile.name = nombre;
	nuevoFile.value = "";
	nuevoFile.disabled = f.disabled;
	nodoPadre = f.parentNode;
	nodoSiguiente = f.nextSibling;
	nodoPadre.removeChild(f);
	(nodoSiguiente == null) ? nodoPadre.appendChild(nuevoFile):
		nodoPadre.insertBefore(nuevoFile, nodoSiguiente);
}

function CompruebaCampo(caso){
   var tam = document.adminForm.num_est.value;
   var f = document.adminForm;
   if (caso != 'inicio'){
 	   f.especialidad_alt.value="";
	   f.id_especialidad.value="";
   }
   switch (f.id_titulo.value){
	   case "12": case "13": case "15":
	        for ( x = 1; x <= tam; x++){
			   var c = eval( 'f.id_especialidad' + x );
			   c.style.display="none";
			}
	  	 	f.especialidad_alt.style.display="";
			return false;
	   break;
	   default: 
	        for ( x = 1; x <= tam; x++){
			   if (f.id_titulo.value == x){
 			      eval( 'f.id_especialidad' + x +'.style.display=""');
				  if (caso != 'inicio'){
					 eval( 'f.id_especialidad' + x +'.selectedIndex=0');
                  }
			   } else {
 			      eval( 'f.id_especialidad' + x +'.style.display="none"');
			   }
			}
			if (f.id_titulo.value == "0"){
				f.id_especialidad1.style.display="";
			}
	  	 	f.especialidad_alt.style.display="none";	 
			
   }
}

function CompruebaFormulario(){
	var f = document.adminForm;
	if (f.titulo_formulario.value.length == 0){
	   alert("\'Título\' es un campo obligatorio");
	   return false;
	}	
	if (f.id_formulario.value == 0 && f.link_formulario.value.length == 0){
	   alert("Debes añadir un formulario");
	   return false;
	}	
	if (f.seccion_formulario.selectedIndex==0){
	   alert("Seleccione una categoría");
	   return false;
	}	
	return true;
}

function CompruebaPubli(){
	var f = document.adminForm;
	

	
	if (f.nombre_camp.value.length == 0){
	   alert("\'Título de campaña\' es un campo obligatorio");
	   return false;
	}
	if (f.link_camp.value.length == 0){
	   alert("\'Link de campaña\' es un campo obligatorio");
	   return false;
	}	
	
	FechaIni = new Date(f.fecha_ini_anio.value,f.fecha_ini_mes.value-1,f.fecha_ini_dia.value);	 
	FechaFin = new Date(f.fecha_fin_anio.value,f.fecha_fin_mes.value-1,f.fecha_fin_dia.value);	
	if (f.fecha_ini_anio.value != FechaIni.getFullYear() ||  f.fecha_ini_mes.value-1 != FechaIni.getMonth() || f.fecha_ini_dia.value != FechaIni.getDate()){
		alert("Fecha Inicio incorrecta");
		return false;
	}
    if (f.fecha_fin_anio.value != FechaFin.getFullYear() ||  f.fecha_fin_mes.value-1 != FechaFin.getMonth() || f.fecha_fin_dia.value != FechaFin.getDate()){
		alert("Fecha Fin incorrecta");
		return false;
	}
	if (FechaFin-FechaIni < 0 ){
		alert("La Fecha Fin no puede ser menor a la Fecha Inicio") ;
		return false;
	}
	
	if (f.tipo_camp.value == "0"){
	   alert("Seleccione un tipo de banner");
	   return false;
	}	
	

	if (f.id_camp.value == 0 && f.img_camp.value.length == 0 && f.swf_camp.value.length == 0){
	   alert("Debes seleccionar una imagen o flash de campaña");
	   return false;
	}
	if (f.img_camp.value.length != 0 && f.swf_camp.value.length != 0){
	   alert("Debes seleccionar \'solo\' una imagen o flash de campaña");
	   return false;
	}	
	
	return true;
}

function CompruebaEnlace(){
	var f = document.adminForm;
	
	if (f.nombre_enlace.value.length == 0){
	   alert("\'Nombre de enlace\' es un campo obligatorio");
	   return false;
	}
	if (f.link_enlace.value.length == 0){
	   alert("\'Enlace\' es un campo obligatorio");
	   return false;
	}
	return true;
}

function CompruebaCategoria(caso){
   var tam = document.adminForm.num_cat.value;
   var f = document.adminForm;
   if (caso != 'inicio'){
	   f.id_subcategoria_final.value="";
   }
   switch (f.id_categoria.value){
	   default: 
	        for ( x = 0; x <= tam; x++){
			   if (f.id_categoria.value == x){
 			      eval( 'f.id_subcategoria' + x +'.style.display=""');
				  if (caso != 'inicio'){
					 eval( 'f.id_subcategoria' + x +'.selectedIndex=0');
                  }
			   } else {
 			      eval( 'f.id_subcategoria' + x +'.style.display="none"');
			   }
			}
			if (f.id_categoria.value == "0"){
			   	f.id_subcategoria0.style.display="";
			}	
   }
}


function CompruebaCategoria2(caso){
   var tam = document.adminForm.num_cat.value;
   var f = document.adminForm;
   if (caso != 'inicio'){
	   f.id_subcategoria_final2.value="";
   }
   switch (f.id_categoria2.value){
	   default: 
	        for ( x = 0; x <= tam; x++){
			   if (f.id_categoria2.value == x){
 			      eval( 'f.id_subcategoria2' + x +'.style.display=""');
				  if (caso != 'inicio'){
					 eval( 'f.id_subcategoria2' + x +'.selectedIndex=0');
                  }
			   } else {
 			      eval( 'f.id_subcategoria2' + x +'.style.display="none"');
			   }
			}
			if (f.id_categoria2.value == "0"){
			   	f.id_subcategoria20.style.display="";
			}	
   }
}



function EditaCampo(campo, valor){
  eval( 'document.adminForm.' + campo + '.value ="'+valor+'"');
}

function EditCampo(accion, campo, id){
  //alert(campo);
  eval( 'document.adminForm.' + campo + '.value ='+id);
  //alert(id);
  document.adminForm.accion.value = accion;
  try {
     document.adminForm.onsubmit();
  }
  catch(e){}
  document.adminForm.submit();	
}


function EditEstudio(id_estudio){
  document.adminForm.id_estudio.value = id_estudio;
  document.adminForm.accion.value = "editarestudio";
  try {
     document.adminForm.onsubmit();
  }
  catch(e){}
  document.adminForm.submit();
}

function EditExperiencia(id_exp){
  document.adminForm.id_experiencia.value = id_exp;
  document.adminForm.accion.value = "editarexperiencia";
  try {
     document.adminForm.onsubmit();
  }
  catch(e){}
  document.adminForm.submit();
}

function activa_busq(){
   	document.getElementById("secc_busqueda").style.display = "";
  	document.getElementById("text_secc_busqueda").style.display = "none";
}


function activa_tema(limpia){
	if(limpia){
		document.adminForm.numero.value = "";
		document.adminForm.titulo_tema.value = "";
		document.getElementById("contenido_tema").text = "";
		document.adminForm.id_tema.value = "";
		document.adminForm.id_tema_padre.value = "";
		
	}
	if (document.getElementById("no_insert_tema").style.display == "none"){
		document.getElementById("no_insert_tema").style.display = "";
		document.getElementById("insert_tema").style.display = "none";		
	}
	else {
		document.getElementById("no_insert_tema").style.display = "none";
		document.getElementById("insert_tema").style.display = "";
		document.getElementById("insert_material").style.display = "none";
	}  	
}

function activa_material(limpia){
	if(limpia){
		document.adminForm.titulo_material.value = "";
		document.adminForm.descripcion_material.text = "";
		document.adminForm.id_tema.value = "";
		
	}
	if (document.getElementById("insert_material").style.display == "none"){
		document.getElementById("insert_material").style.display = "";
		document.getElementById("no_insert_tema").style.display = "none";
 		document.getElementById("insert_tema").style.display = "none";
		
	}
	else {
		document.getElementById("no_insert_tema").style.display = "";		
		document.getElementById("insert_material").style.display = "none";
	}  	
}


function activa_div(limpia,tipo){
   switch(tipo){
	   
	   case "exp":
		  if (limpia){
			 document.adminForm.fecha_ini_mes_exp.selectedIndex = 0;
			 document.adminForm.fecha_fin_mes_exp.selectedIndex = 0;
			 document.adminForm.fecha_ini_anio_exp.selectedIndex = 0;
			 document.adminForm.fecha_fin_anio_exp.selectedIndex = 0;
			 document.adminForm.fecha_fin_anio_exp.selectedIndex = 0;
			 document.adminForm.id_categoria.selectedIndex = 0;
			 document.adminForm.id_subcategoria_final.value = "";
			 document.adminForm.empresa.value = "";
			 document.adminForm.puesto.value = "";
			 document.adminForm.descripcion.value = "";			 
			 document.adminForm.id_experiencia.value = "";
			 CompruebaCategoria('inicio');
			 
		   }
		   if (document.getElementById("no_insert_exp").style.display == "none"){
				document.getElementById("no_insert_exp").style.display = "";
				document.getElementById("insert_exp").style.display = "none";		
		   }
		   else {
				document.getElementById("no_insert_exp").style.display = "none";
				document.getElementById("insert_est").style.display = "none";
				document.getElementById("no_insert_est").style.display = "";
				document.getElementById("insert_exp").style.display = "";
		   }	   
	   break;
	   
	   
	   case "est":
	   default:
		   if (limpia){
			 document.adminForm.fecha_ini_mes.selectedIndex = 0;
			 document.adminForm.fecha_fin_mes.selectedIndex = 0;
			 document.adminForm.fecha_ini_anio.selectedIndex = 0;
			 document.adminForm.fecha_fin_anio.selectedIndex = 0;
			 document.adminForm.fecha_fin_anio.selectedIndex = 0;
			 document.adminForm.cursando.checked=false;
			 document.adminForm.id_titulo.selectedIndex = 0;
			 document.adminForm.id_especialidad.selectedIndex = 0;
			 document.adminForm.nom_centro.value = "";
			 document.adminForm.id_estudio.value = "";
			 CompruebaCampo(document.adminForm.num_est.value);
			 
		   }
		   if (document.getElementById("no_insert_est").style.display == "none"){
				document.getElementById("no_insert_est").style.display = "";
				document.getElementById("insert_est").style.display = "none";		
		   }
		   else {
				document.getElementById("no_insert_est").style.display = "none";
				document.getElementById("insert_exp").style.display = "none";
				document.getElementById("no_insert_exp").style.display = "";
				document.getElementById("insert_est").style.display = "";
		   }  	
		break;
   }
}


function CambiaEspecialidad(tipo){
   	document.adminForm.id_especialidad.value = document.getElementById(tipo).value;
}

function CambiaCategoria(tipo){
   	document.adminForm.id_subcategoria_final.value = document.getElementById(tipo).value;
}

function CambiaCategoria2(tipo){
   	document.adminForm.id_subcategoria_final2.value = document.getElementById(tipo).value;
}





function faltan(fechaFinal){
	fechaActual = new Date();
	fechaFinal = new Date(fechaFinal);
	diferencia = fechaFinal - fechaActual
	diferenciaSegundos = diferencia /1000
	diferenciaMinutos = diferenciaSegundos/60
	diferenciaHoras = diferenciaMinutos/60
	diferenciaDias = diferenciaHoras/24
	diferenciaHoras2 = parseInt(diferenciaHoras) - (parseInt(diferenciaDias) *24)
	diferenciaMinutos2 = parseInt(diferenciaMinutos) - (parseInt(diferenciaHoras) * 60)
	diferenciaSegundos2 = parseInt(diferenciaSegundos) - (parseInt(diferenciaMinutos) * 60)
	diferenciaDias = parseInt(diferenciaDias)
	if (diferenciaDias < 10 && diferenciaDias > -1){diferenciaDias = "0" + diferenciaDias}
	if(diferenciaHoras2 < 10 && diferenciaHoras2 > -1){diferenciaHoras2 = "0" + diferenciaHoras2}
	if(diferenciaMinutos2 < 10 && diferenciaMinutos2 > -1){diferenciaMinutos2 = "0" + diferenciaMinutos2}
	if(diferenciaSegundos2 < 10 && diferenciaSegundos2 > -1){diferenciaSegundos2 = "0" + diferenciaSegundos2}
	if(diferenciaDias <= 0 && diferenciaHoras2<= 0 && diferenciaMinutos2 <= 0 && diferenciaSegundos2 <= 0)
		{
		diferenciaDias = 0
		diferenciaHoras2 = 0
		diferenciaMinutos2 = 0
		diferenciaSegundos2 = 0
		document.getElementById('tiempo').innerHTML = diferenciaHoras2 + ":" + diferenciaMinutos2 + ":" + diferenciaSegundos2
		}
	else{
	document.getElementById('tiempo').innerHTML = diferenciaHoras2 + ":" + diferenciaMinutos2 + ":" + diferenciaSegundos2
	setTimeout('faltan("'+fechaFinal+'")',1000)
	}
}

function Anclaje(e) {
	document.location.href="#"+e;
}

function Back(){ 
   return window.history.back();	
}





	
/* validador de coloresss */	
// IS FORM VALID
var formValidationMasks = new Array();
formValidationMasks['email'] = /\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/gi;	// Email
formValidationMasks['numeric'] = /^[0-9]+$/gi;	// Numeric
formValidationMasks['zip'] = /^[0-9]{5}\-[0-9]{4}$/gi;	// Numeric

var formElementArray = new Array();

/* These two event functions are from http://ejohn.org/apps/jselect/event.html */

function addEvent( obj, type, fn ) { 
  if ( obj.attachEvent ) { 
    obj['e'+type+fn] = fn; 
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );} 
    obj.attachEvent( 'on'+type, obj[type+fn] ); 
  } else 
    obj.addEventListener( type, fn, false ); 
} 
function removeEvent( obj, type, fn ) { 
  if ( obj.detachEvent ) { 
    obj.detachEvent( 'on'+type, obj[type+fn] ); 
    obj[type+fn] = null; 
  } else 
    obj.removeEventListener( type, fn, false ); 
} 


function validateInput(e,inputObj)
{
	if(!inputObj)inputObj = this;		
	var inputValidates = true;
	
	if(formElementArray[inputObj.name]['required'] && inputObj.tagName=='INPUT' && inputObj.value.length==0)inputValidates = false;
	if(formElementArray[inputObj.name]['required'] && inputObj.tagName=='SELECT' && inputObj.selectedIndex==0){
		inputValidates = false;
	}
	if(formElementArray[inputObj.name]['mask'] && !inputObj.value.match(formValidationMasks[formElementArray[inputObj.name]['mask']]))inputValidates = false;

	if(formElementArray[inputObj.name]['freemask']){
		var tmpMask = formElementArray[inputObj.name]['freemask'];
		tmpMask = tmpMask.replace(/-/g,'\\-');
		tmpMask = tmpMask.replace(/S/g,'[A-Z]');
		tmpMask = tmpMask.replace(/N/g,'[0-9]');
		tmpMask = eval("/^" + tmpMask + "$/gi");
		if(!inputObj.value.match(tmpMask))inputValidates = false
	}	
	
	if(formElementArray[inputObj.name]['regexpPattern']){
		var tmpMask = eval(formElementArray[inputObj.name]['regexpPattern']);
		if(!inputObj.value.match(tmpMask))inputValidates = false
	}
	if(!formElementArray[inputObj.name]['required'] && inputObj.value.length==0 && inputObj.tagName=='INPUT')inputValidates = true;
	
	
	if(inputValidates){
		inputObj.parentNode.className='validInput';
	}else{
		inputObj.parentNode.className='invalidInput'
	}
}

function isFormValid()
{
	var divs = document.getElementsByTagName('DIV');
	for(var no=0;no<divs.length;no++){
		if(divs[no].className=='invalidInput')return false;
	}
	return true;	
}




function initFormValidation()
{
	var inputFields = document.getElementsByTagName('INPUT');
	var selectBoxes = document.getElementsByTagName('SELECT');
	
	var inputs = new Array();
	
	
	for(var no=0;no<inputFields.length;no++){
		inputs[inputs.length] = inputFields[no];
		
	}	
	for(var no=0;no<selectBoxes.length;no++){
		inputs[inputs.length] = selectBoxes[no];
		
	}
	
	for(var no=0;no<inputs.length;no++){
		var className = inputs[no].parentNode.className;
		if(className && className.indexOf('validInput')>=0)continue;			
		var required = inputs[no].getAttribute('required');
		if(!required)required = inputs[no].required;		
		
		var mask = inputs[no].getAttribute('mask');
		if(!mask)mask = inputs[no].mask;
		
		var freemask = inputs[no].getAttribute('freemask');
		if(!freemask)freemask = inputs[no].freemask;
		
		var regexpPattern = inputs[no].getAttribute('regexpPattern');
		if(!regexpPattern)regexpPattern = inputs[no].regexpPattern;
		
		var div = document.createElement('DIV');
		div.className = 'invalidInput';
		inputs[no].parentNode.insertBefore(div,inputs[no]);
		div.appendChild(inputs[no]);
		div.style.width = inputs[no].offsetWidth + 'px';
		
		addEvent(inputs[no],'blur',validateInput);
		addEvent(inputs[no],'change',validateInput);
		addEvent(inputs[no],'paste',validateInput);
		addEvent(inputs[no],'keyup',validateInput);
		
	
		formElementArray[inputs[no].name] = new Array();
		formElementArray[inputs[no].name]['mask'] = mask;
		formElementArray[inputs[no].name]['freemask'] = freemask;
		formElementArray[inputs[no].name]['required'] = required;
		formElementArray[inputs[no].name]['regexpPattern'] = regexpPattern;

		validateInput(false,inputs[no]);
			
	}	
}


function moveDown(optionId)
	{
		var el = document.getElementById('option' + optionId);
		if(el.nextSibling){

			var nextObj = el.nextSibling;

			var inputsNext = nextObj.getElementsByTagName('INPUT');

			var nextOrder = false;
			
			for(var no=0;no<inputsNext.length;no++){
				if(inputsNext[no].id.indexOf('existing_pollOrder')>=0)nextOrder = inputsNext[no];	
			}

			var inputsThis = el.getElementsByTagName('INPUT');
			var thisOrder = false;
			for(var no=0;no<inputsThis.length;no++){
				if(inputsThis[no].id.indexOf('existing_pollOrder')>=0)thisOrder = inputsThis[no];	
			}			
			var tmpValue = nextOrder.value;
			nextOrder.value = thisOrder.value;
			thisOrder.value = tmpValue;
			el.parentNode.insertBefore(el.nextSibling,el);
			
		}
		
	}


function BloqueaFecha(){
   var f = document.adminForm;
   if(f.fecha_lim_det.checked==false){
	   f.fecha_lim_mes.disabled=false;
	   f.fecha_lim_dia.disabled=false;
	   f.fecha_lim_anio.disabled=false;
   } else {
	   f.fecha_lim_mes.disabled=true;
	   f.fecha_lim_dia.disabled=true;
	   f.fecha_lim_anio.disabled=true;
   }	
}

function BloqueaFecha2($tipo){
   var f = document.adminForm;
   switch($tipo){
	   case "ini":
		   if(f.fecha_ini_det.checked==false){
			   f.fecha_ini_mes.disabled=false;
			   f.fecha_ini_dia.disabled=false;
			   f.fecha_ini_anio.disabled=false;
			   f.fecha_ini_hora.disabled=false;
			   f.fecha_ini_min.disabled=false;	   
		   } else {
			   f.fecha_ini_mes.disabled=true;
			   f.fecha_ini_dia.disabled=true;
			   f.fecha_ini_anio.disabled=true;
			   f.fecha_ini_hora.disabled=true;
			   f.fecha_ini_min.disabled=true;	   	   
		   }	
		   break;
       case "fin":
	   		   if(f.fecha_fin_det.checked==false){
			   f.fecha_fin_mes.disabled=false;
			   f.fecha_fin_dia.disabled=false;
			   f.fecha_fin_anio.disabled=false;
			   f.fecha_fin_hora.disabled=false;
			   f.fecha_fin_min.disabled=false;	   
		   } else {
			   f.fecha_fin_mes.disabled=true;
			   f.fecha_fin_dia.disabled=true;
			   f.fecha_fin_anio.disabled=true;
			   f.fecha_fin_hora.disabled=true;
			   f.fecha_fin_min.disabled=true;	   	   
		   }	
		   break;
   }
}

function CompruebaTestimonio(){
	var f = document.adminForm;
	if (f.relacionado.value == 0){
	   alert("Debes escoger una sección");
	   return false;
	}
	return true;
}

/*
function CompruebaEstudio(){
   	var f = document.adminForm;
	if (f.fecha_ini_mes.value == 0 || f.fecha_ini_anio.value == 0){
	   alert("Fecha Inicio no puede ser un campo vacio");
	   return false;
	}
	if (f.id_titulo.value == 0){
	   alert("Debes escoger un título")	;
	   return false;
	}
    if (f.nom_centro.value == ){
	   alert("El campo \"Centro\" no puede ser vacío")	;
	   return false;
	}
	return true;
}*/

function CompruebaVincula(){
   var f = document.adminForm;
   var numemp = 0;
   for (var i=0;i < f.select_empresas.options.length;i++)
   {
	  if (f.select_empresas.options[i].selected)
	  {
		 numemp++;
	  }
   }
   if (numemp == 0){
	   alert("Tiene que haber almenos una empresa seleccionada");
	   return false;
   }
   var numcursos = 0;
   for (var i=0;i < f.select_cursos.options.length;i++)
   {
	  if (f.select_cursos.options[i].selected)
	  {
		 numcursos++;
	  }
   }
   if (numcursos == 0){
	   alert("Tiene que haber almenos un curso seleccionado");
	   return false;
   }
   return true;	
}

function CompruebaOferta2(){
   var f = document.adminForm;
   if (f.titulo_oferta.value==""){
	   alert("El campo título no puede ser vacío");
	   return false;
   }
   
   if (!f.fecha_lim_det.checked){
	   if (f.fecha_lim_dia.value == "0"){
	      alert("Día límite incorrecto");
	      return false;
	   }
	   if (f.fecha_lim_mes.value == "0"){
	      alert("Mes límite incorrecto");
	      return false;
	   }
	   if (f.fecha_lim_anio.value == "0"){
	      alert("Año límite incorrecto");
	      return false;
	   }
	   FechaLim = new Date(f.fecha_lim_anio.value,f.fecha_lim_mes.value-1,f.fecha_lim_dia.value);	 
	
		if (f.fecha_lim_anio.value != FechaLim.getFullYear() ||  f.fecha_lim_mes.value-1 != FechaLim.getMonth() || f.fecha_lim_dia.value != FechaLim.getDate()){
		   alert("Fecha límite incorrecta");
		   return false;
	   }
   }  
   
   
   return true;
}

function CompruebaOferta1(){
   var f = document.adminForm;
   if (f.titulo_oferta.value==""){
	   alert("El campo título no puede ser vacío");
	   return false;
   }
   if (!f.id_empresa.value){
	   alert("Debes escoger una empresa");
	   return false;
   }
   
   if (!f.fecha_lim_det.checked){
	   if (f.fecha_lim_dia.value == "0"){
	      alert("Día límite incorrecto");
	      return false;
	   }
	   if (f.fecha_lim_mes.value == "0"){
	      alert("Mes límite incorrecto");
	      return false;
	   }
	   if (f.fecha_lim_anio.value == "0"){
	      alert("Año límite incorrecto");
	      return false;
	   }	   
   }
   return true;
}

function CompruebaIdioma(){
   var f = document.adminForm;
   if (f.idioma.selectedIndex == ""){
	   alert("Debes escoger un idioma");
	   return false;
   }
   return true;	
}

function CompruebaIdiomaNivel(){
   var f = document.adminForm;
   if (f.idioma.selectedIndex == ""){
	   alert("Debes escoger un idioma");
	   return false;
   }
   if (f.nivel.selectedIndex == ""){
	   alert("Debes escoger el nivel");
	   return false;
   }
   return true;	
}

function CompruebaDatosPuesto(){
   var f = document.adminForm;
   if (f.id_categoria2.selectedIndex == ""){
	   alert("Debes escoger una categoria");
	   return false;
   }
   if (f.id_subcategoria_final2.value == "" || f.id_subcategoria_final2.value == "0"){
	   alert("Debes escoger una subcategoria");
	   return false;
   }
   return true;
}


function CompruebaEstudiosCursos(){
	 var f = document.adminForm;
	 if (f.fecha_ini_mes.value == 0 || f.fecha_ini_anio.value == 0){
		alert("Fecha inicio incorrecta") ;
		return false;
	 }
	 if (f.fecha_fin_mes.value == 0 || f.fecha_fin_anio.value == 0){
		alert("Fecha fin incorrecta") ;
		return false;
	 }
  	 FechaIni = new Date(f.fecha_ini_anio.value,f.fecha_ini_mes.value-1,1);	 
	 FechaFin = new Date(f.fecha_fin_anio.value,f.fecha_fin_mes.value-1,2);
     if (FechaFin-FechaIni < 0 ){
		alert("La Fecha Fin no puede ser menor a la Fecha Inicio") ;
		return false;
	 }
	 if (f.id_titulo.value == 0){
		alert("Debes indicar un titulo / curso");
		return false;
	 }
	 var valor2 = f.id_especialidad.value;
	 if (valor2 == ""){
 		var valor = f.id_titulo.value;
		if (valor != 1 && valor != 5){
			if (valor == 12 || valor == 13 || valor == 15){
				if (f.especialidad_alt.value == ""){
					alert("Debes especificar la especialidad");
		  			return false;	
				}	
			} else {
			   	alert("Debes escoger la especialidad");
	  			return false;
			}
		}
	 }
	 if (f.nom_centro.value == ""){
		alert("Debes escribir el nombre del centro");
		return false;
	 }
	return true;
}

function CompruebaExpProf(){
	var f = document.adminForm;
	if (f.fecha_ini_mes_exp.value == 0 || f.fecha_ini_anio_exp.value == 0){
		alert("Fecha inicio incorrecta") ;
		return false;
	}
	if (f.fecha_fin_mes_exp.value == 0 || f.fecha_fin_anio_exp.value == 0){
		alert("Fecha fin incorrecta") ;
		return false;
	}
  	FechaIni = new Date(f.fecha_ini_anio_exp.value,f.fecha_ini_mes_exp.value-1,1);	 
	FechaFin = new Date(f.fecha_fin_anio_exp.value,f.fecha_fin_mes_exp.value-1,2);
    if (FechaFin-FechaIni < 0 ){
		alert("La Fecha fin no puede ser menor a la Fecha inicio") ;
		return false;
	}
	if (f.puesto.value == ""){
		alert("Debes indicar el puesto");
		return false;
	}
	if (f.empresa.value == ""){
		alert("Debes indicar la empresa");
		return false;
	}
	if ( f.id_categoria.value == 0){
	   	alert("Debes indicar la categoria a la que pertenece el puesto");
		return false;
	}
	if ( f.id_subcategoria_final.value == -1){
	   	alert("Debes indicar la subcategoria a la que pertenece el puesto");
		return false;
	}
	return true;	
}
function CambiaColegiado(){
	var f = document.adminForm;
	if (f.colegiado.value == 'no'){
		document.getElementById("es_colegiado").style.display = "none";
	} else {
		document.getElementById("es_colegiado").style.display = "";
	}
}

function calcula(){
valor = document.getElementById("ord").value;
valor2 = document.getElementById("ord_val").value;
if(valor == valor2){
	valor = valor+"2";
}
EditCampo("listar", "ordenar", "valor");
return false;	
}


function calcula2(){
valor = document.adminForm.ordenar.value;
valor2 = document.adminForm.ordenar2.value;
if(valor == valor2){
	valor = valor+"2";
}
//EditCampo("listar", "ordenar", "valor");
EditaCampo("ordenar", valor);
save('listar');
return false;	
}

function CompruebaTipoPubli(){
	var f = document.adminForm;
	switch (f.tipo_camp.value){
		/*case "2":
		case "3":
		   limpiar2("swf_camp");
		   f.swf_camp.disabled = true;
		   break;
		   */
		default :
		   f.swf_camp.disabled = false;
		   break;		
	}
}

function ActivaDiv(nombre){
	var valor = document.getElementById(nombre).style.display;
	if (valor == "")
	   document.getElementById(nombre).style.display = "none";
	else
	   document.getElementById(nombre).style.display = "";
}

function compruebaFeed(){
   var f = document.adminForm;
   
   if (f.boxchecked_not.value == 0){
	   alert("Debes seleccionar alguna noticia a enviar");
	   return false;
   }
   
      if (f.boxchecked_usu.value == 0){
	   alert("Debes seleccionar al rango de usuarios al que deseas enviar la/s noticia/s");
	   return false;
   }
   
   return true;	
}


function ActivarDiv(num){
	eval("document.getElementById('_div_nombre1_" + num + "').style.display = 'none'; ");
	eval("document.getElementById('_div_url1_" + num + "').style.display = 'none'; ");
	eval("document.getElementById('_div_opcion1_" + num + "').style.display = 'none'; ");
	eval("document.getElementById('_div_nombre2_" + num + "').style.display = ''; ");
	eval("document.getElementById('_div_url2_" + num + "').style.display = ''; ");
	eval("document.getElementById('_div_opcion2_" + num + "').style.display = ''; ");

}

function CompruebaPatrocinador(){
	var f = document.adminForm;
	if (f.nombre_patro.value == ""){
	   alert("'Nombre de patrocinador' es un campo obligatorio");
	   return false;
	}
	if (f.img.value == ""){
	   alert("Escoge la imagen del patrocinador");
	   return false;
	}
	return true;
}

function CompruebaTipoFoto(campo, nombre){
	
	if (campo.length > 0){
		cadena  = campo.split('.');
		formato = cadena[cadena.length - 1];
		formato = formato.toLowerCase();
		formatos_validos = new Array("jpg", "gif", "koa", "jpeg");
		if (!formatos_validos.in_array(formato)){
			alert("El formato " + formato + " del campo '" + nombre + "' no es un formato válido");
			return false;
		}
		return true;
	}
	return true;
	
}

Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}

function todo_der() {
	obj=document.getElementById('sel1');
	while (obj.options.length != 0){
		valor = obj.options[0].value;
		txt=obj.options[0].text;
		obj.options[0] = null;
		obj2=document.getElementById('sel2');
		opc = new Option(txt,valor);
		eval(obj2.options[obj2.options.length]=opc);    
	}

}

function der() {
	obj=document.getElementById('sel1');
	if (obj.selectedIndex==-1) return;
	valor=obj.value;
	txt=obj.options[obj.selectedIndex].text;
	obj.options[obj.selectedIndex]=null;
	obj2=document.getElementById('sel2');
	opc = new Option(txt,valor);
	eval(obj2.options[obj2.options.length]=opc);    
}


function izq() {

	obj=document.getElementById('sel2');
	if (obj.selectedIndex==-1) return;
	valor=obj.value;

	txt=obj.options[obj.selectedIndex].text;
	obj.options[obj.selectedIndex]=null;
	obj2=document.getElementById('sel1');
	opc = new Option(txt,valor);
	eval(obj2.options[obj2.options.length]=opc);    
}


function todo_izq() {
	obj = document.getElementById('sel2');
	while(obj.options.length != 0){
		valor = obj.options[0].value;
		txt = obj.options[0].text;
		obj.options[0] = null;
		obj2 = document.getElementById('sel1');
		opc = new Option(txt,valor);
		eval(obj2.options[obj2.options.length]=opc);
   } 
}


function multipleSelectOnSubmit()
{
	var arrayOfItemsToSelect = new Array();
	fromObj = document.getElementById('sel1');
	toObj = document.getElementById('sel2');	
	arrayOfItemsToSelect[arrayOfItemsToSelect.length] = toObj;

	for(var no=0;no<arrayOfItemsToSelect.length;no++){
		var obj = arrayOfItemsToSelect[no];
		for(var no2=0;no2<obj.options.length;no2++){
			obj.options[no2].selected = true;
		}
	}
}
