// JavaScript Document
<!--

	//Se ha creado la función popup2 que se le manda el nombre de la ventana a abrir y de esta forma dentro de un popup se pueden abrir otros popups.
	
	
	function resultados(id,en) {
    if(document.getElementById(id).style["display"] != "none"){
        document.getElementById(id).style["display"] = "none";
		 document.getElementById(en).className = "";
    } else {
        document.getElementById(id).style["display"] = "";
		 document.getElementById(en).className = "coloren";
    }
}
	
	
		function desplegar(id){
		if(document.getElementById(id).style["display"] == "none"){
			document.getElementById("sugerencias").style["display"] = "none";
			document.getElementById("asistencia").style["display"] = "none";
			document.getElementById(id).style["display"] = "block";
		}else{
			document.getElementById(id).style["display"] = "none";
		}
	}
	function ShowHide(id) {
    if(document.getElementById(id).style["display"] != "none"){
        document.getElementById(id).style["display"] = "none";
    } else {
        document.getElementById(id).style["display"] = "";
    }
}
	
	function bisiesto(year) {
		return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) ? 1 : 0;
	}
	
	function radiovalue(radios) {
		for (i = 0; radio = radios[i]; i++) {
			if (radio.checked) {
				return radio.value;
			}
		}
	}
	
	function in_array(matriz, elemento) {
		var x;
		for (x=0;x < matriz.length;x++) {
			if (matriz[x] == elemento)
				return true;
		}
		return false;
	}
	
	function delitem(array, elemento) {
		var x, result = new Array();
		for (x=0;x < array.length;x++) {
			if (array[x] != elemento)
				result[result.length] = array[x];
		}
		return result;
	}
	
	function str_replace(buscar, sustituir, cadena) {
		var resultado="", x;
		for (x=0;x < cadena.length;x++) {
			if (cadena.substr(x, buscar.length) == buscar) {
				resultado = resultado + sustituir;
				x = x + buscar.length - 1;
			}
			else
				resultado = resultado + cadena.substr(x,1);
		}
		return resultado;
	}
	
	function ltrim(s) {

		// Devuelve una cadena sin los espacios del principio

		var del=" \t\n\r\0\x0B";
		var i=0, j=0;
		
		for (i=0; i <= (s.length - 1); i++) {
			if (del.indexOf(s.substr(i, 1)) == -1) {
				j=i;
				break;
			}
		}
		return s.substr(j);
	}
	
	function rtrim(s) {

		// Quita los espacios en blanco del final de la cadena

		var del=" \t\n\r\0\x0B";
		var i=0, j=0;
		
		for (i = s.length - 1; i >= 0; i--) {
			if (del.indexOf(s.substr(i, 1)) == -1) {
				j=i;
				break;
			}
		}
		return s.substr(0, j + 1);
	}
	
	function trim(s) {

		// Quita los espacios del principio y del final

		var del=" \t\n\r\0\x0B";
		var i=0, j=0, k=s.length;

		for (i=0; i < s.length; i++) {
			if (del.indexOf(s.substr(i, 1)) == -1) {
				j=i;
				break;
			}
		}
		for (i = (s.length - 1); i >= 0; i--) {
			if (del.indexOf(s.substr(i, 1)) == -1) {
				k=i;
				break;
			}
		}
		return s.substr(j, k - j + 1);
	}
	
	function cerofill(elemento, digitos) {
		var relleno, result;
		
		// Nos aseguramos de tenerlo en modo cadena, quitandole cualquier espacio en la conversión.
		
		elemento = elemento.toString();
		elemento = trim(elemento);
		
		// Calculamos los 0 a rellenar, y los ponemos, retornando la cadena resultante.
		
		relleno = digitos - elemento.length;
		
		for (x=0;x < relleno;x++)
			elemento = "0" + elemento;
			
		return elemento;
	}
	
	function is_number(cadena) {
		var primero, ultimo, codigo;
		
		if (cadena == "") return false;

		primero=cadena.indexOf('.');
		ultimo=cadena.lastIndexOf('.');
		
		// Si tiene m&aacute;s de un punto decimal, retornar falso
		
		if (primero > -1 && ultimo > -1 && primero != ultimo)
			return false;
		
		for (x=0;x < cadena.length;x++) {
			codigo=cadena.charCodeAt(x);
			if ((codigo < 48 || codigo > 57) && codigo != 46 && codigo != 44)
				return false;
		}
		
		return true;
	}
	

	function parserInt(number) {
		var x, result = "";
		number=number.toString();

		if (is_number(number)) {
			for (x=0;x < number.length;x++) {
				if (number.substr(x,1) != "0") {
					result = number.substr(x);
					break;
				}
			}
			if (result == "")
				return 0;
			else
				return parseInt(result);
		}
		else
			return 0;
	}

	function mail_check(email) {
		var mail_correcto = 0;
		var term_dom;

		if (email.length >= 6 && email.indexOf("@") >= 0 && email.indexOf("@") == email.lastIndexOf("@") && email.substr(0,1) != "@" && email.substr(email.length - 1, 1) != "@") {
			if (email.indexOf('"') == -1 && email.indexOf("'") == -1 && email.indexOf("\\") == -1 && email.indexOf("\$") == -1 && email.indexOf(" ") == -1) {
				//miro si tiene caracter .
				if (email.indexOf('.') > -1) {
					//obtengo la terminacion del dominio
					term_dom = email.substr(email.lastIndexOf('.') + 1);
					//compruebo que la terminación del dominio sea correcta
					if (term_dom.length > 1 && term_dom.length < 5 && term_dom.indexOf('@') == -1) {
						//compruebo que lo de antes del dominio sea correcto
						antes_dom = email.substr(0,email.length - term_dom.length - 1);
						caracter_ult = antes_dom.substr(antes_dom.length - 1,1);
						if (caracter_ult != "@" && caracter_ult != ".")
							mail_correcto = 1;
					}
				}
			}
		}
		return mail_correcto;
	}
	
	function checkHour(objeto) {
		var hora_inicio = chkHora(objeto.value);
		if (hora_inicio !== false)
			objeto.value = hora_inicio;
		else {
			alert('Debe indicar una hora correcta');
			objeto.value="";
		}
	}
	
	function chkHora(hora) {
		variables = hora.split(':');

		if (variables.length != 2)
			return false;
		else {
			hora = (parserInt(variables[0]) !== false) ? (parserInt(variables[0])) : (-1);
			minutos = (parserInt(variables[1]) !== false) ? (parserInt(variables[1])) : (-1);
			
			if (hora < 0 || hora > 23)
				return false;
			if (minutos < 0 || minutos > 59)
				return false;
		}
		
		if (hora < 10) hora = "0" + hora.toString();
		if (minutos < 10) minutos = "0" + minutos.toString();
		
		return hora + ":" + minutos;
	}
	
	function popup(URL, width, height, nombre)
	{
		if ((height +100) > (window.screen.height)) {
			height = (window.screen.height );
			scrollbars = "yes";
		}
		else
			scrollbars = "no";
		

		controlador=window.open(URL,nombre,"scrollbars=" + scrollbars + ",resizable=no,menubar=no,toolbar=no,width=" + width + ",height=" + height + ",top=" + (window.screen.height/2 - height/2) + ",left=" + (window.screen.width/2 - width/2));
		controlador.focus();
	} 
	
	function popup2(URL, width, height, ventana)
	{
		if (height > (window.screen.height - 100)) {
			height = window.screen.height - 100;
			scrollbars = "yes";
		}
		else
			scrollbars = "no";
		

		controlador=window.open(URL, ventana, "scrollbars=" + scrollbars + ",resizable=no,menubar=no,toolbar=no,width=" + width + ",height=" + height + ",top=" + (window.screen.height/2 - height/2) + ",left=" + (window.screen.width/2 - width/2));
		controlador.focus();
	} 
	
	//elimina las etiquetas HTML convirtiendolo en texto plano.
	function stripHTML(oldString) {
	  oldString=oldString.replace(/<[^>]+>/g,"");
	  oldString=oldString.replace(/\n/g,"");
	  oldString=oldString.replace(/\r/g,"");
	  oldString=oldString.replace(/\t/g,"");
	  return oldString;
	}

// -->
function ShowHide(id) {
    if(document.getElementById(id).style["display"] != "none"){
        document.getElementById(id).style["display"] = "none";
    } else {
        document.getElementById(id).style["display"] = "";
    }
}

function Show(id){
	document.getElementById(id).style["display"] = "";
}

function Hide(id){
	document.getElementById(id).style["display"] = "none";
}

function valida(campo,valor,tipo){
	switch(tipo)
	{
		case 1: 
				if(valor.length<4 || valor=="")
					document.getElementById(campo).className="f_rojo";
				else
					document.getElementById(campo).className="f_verde";	
				break;
		case 2:	
				if(valor=="" || isNaN(valor)!=false)
					document.getElementById(campo).className="f_rojo";
				else
					document.getElementById(campo).className="f_verde";	
				break;	
		case 3:	
				if(mail_check(valor)==0)
					document.getElementById(campo).className="f_rojo";
				else
					document.getElementById(campo).className="f_verde";	
				break;	
		case 4:	
				if(valor==0 || valor=='')
					document.getElementById(campo).className="f_rojo";
				else
					document.getElementById(campo).className="f_verde";	
				break;	
	}	
}

function sinTildes(texto,campo) { 
		texto = texto.replace(".pdf","");
		texto = texto.replace(".jpg","");
		texto = texto.replace(".jpeg","");
		texto = texto.replace(".gif","");
		texto = texto.replace(".PDF","");
		texto = texto.replace(".JPG","");
		texto = texto.replace(".JPEG","");
		texto = texto.replace(".GIF","");
		
		texto = texto.replace(/ /g,"-");
		
		texto = texto.replace(/ñ/g,"n");
		texto = texto.replace(/Ñ/g,"N");
		texto = texto.replace(/&aacute;/g,"a");
		texto = texto.replace(/&aacute;/g,"A");
		texto = texto.replace(/é/g,"e");
		texto = texto.replace(/É/g,"E");
		texto = texto.replace(/í/g,"i");
		texto = texto.replace(/Í/g,"I");
		texto = texto.replace(/ó/g,"o");
		texto = texto.replace(/Ó/g,"O");
		texto = texto.replace(/ú/g,"u");
		texto = texto.replace(/Ú/g,"U");
		
		texto = texto.replace(/[^a-zA-Z0-9\-<>]/g,"-");
		texto = texto.replace(/[\-]+/g,"-");
		texto = texto.replace(/<[^>]*>/g,"-");
		
		//alert(texto);
		document.getElementById(campo).value=texto;
		
	
} 

//[JRamon] Esta función se utiliza para controlar el numero de caracteres que se introducen en un textarea
function check_area(objeto, maxlength) {
	if (objeto.value.length > maxlength){
		objeto.value = objeto.value.substr(0, maxlength);
		alert('El maximo de caracteres es ' + maxlength +' y lo ha superado');
	}	
}
 function cambiaNum(num) {
	var numero = num.value;
     if (!/^([0-9.,])*$/.test(numero)){
		var tam = numero.length;
		 num.value = numero.substring(0,tam-1);
        return false;
     } else { return true; }
}
     function formatNumber(num,prefix){
    	prefix = prefix || '';
    	num +='';
    	var splitStr = num.split('.');
    	var splitLeft = splitStr[0];
    	var splitRight = splitStr.length > 1 ? '.' + splitStr[1] : '';
    	var regx = /(\d+)(\d{3})/;
    	while (regx.test(splitLeft)) {
    		splitLeft = splitLeft.replace(regx, '$1' + ',' + '$2');
    	}
    	return prefix + splitLeft + splitRight;
    }

    function unformatNumber(num) {
    	return num.replace(/([^0-9\.\-])/g,'')*1;
    } 
	
	function cambiarMenuOver(id, desc) {
		document.getElementById(id).style.display='';
		document.getElementById('li_'+id).style.marginTop='0px';
    } 
	
	function cambiarMenuOut (id, desc){
		document.getElementById(id).style.display='none';
		document.getElementById('li_'+id).style.marginTop='27px';
	}
	
	function inputPorDefecto(campo,valor,texto){
		
		campo.value=campo.value==texto?valor:campo.value;
	}
	


