// JavaScript Document
imgsrc=new Array(); 
imgsrc[0]='./jpg/p_inicio1.gif';	
imgsrc[1]='./jpg/a_inicio1.gif';
imgsrc[2]='./jpg/p_quees1.gif';
imgsrc[3]='./jpg/a_quees1.gif';
imgsrc[4]='./jpg/p_experiencias1.gif';
imgsrc[5]='./jpg/a_experiencias1.gif';
imgsrc[6]='./jpg/p_documentos1.gif';
imgsrc[7]='./jpg/a_documentos1.gif';
imgsrc[8]='./jpg/p_banco1.gif';
imgsrc[9]='./jpg/a_banco1.gif';
imgsrc[10]='./jpg/p_contacto1.gif';
imgsrc[11]='./jpg/a_contacto1.gif';
img =new Array();
for (i=0; i< imgsrc.length; i++) {
	img[i]=new Image();
	img[i].src=imgsrc[i];
}
var ocultar;
var retardo;
function change(number, picture) {
	document.getElementById(picture).src=img[number].src;
}
function anadeEventos(event, elemId, func) {
 	elem = document.getElementById(elemId);
    if (elem.addEventListener){  
        elem.addEventListener(event,func,false);
	}
    else if (elem.attachEvent) { // IE DOM
         var r = elem.attachEvent("on"+event, func);
		return r;
    }
    else{
		throw 'No es posible aņadir evento';
	}
}

function detectarNav() {
	 if (navigator.appName == "Microsoft Internet Explorer")
		return "IE";
	else{
		return "FIREFOX";
	}
}

function wopen(url, name, w, h){
	w += 32;
	h += 96;
	wleft = (screen.width - w) / 2;
	wtop = (screen.height - h) / 2;
	var win = window.open(url,
	name,
	'width=' + w + ', height=' + h + ', ' +
	'left=' + wleft + ', top=' + wtop + ', ' +
	'location=no, menubar=no, ' +
	'status=no, toolbar=no, scrollbars=yes, resizable=no');
	// Just in case width and height are ignored
	win.resizeTo(w, h);
	// Just in case left and top are ignored
	win.moveTo(wleft, wtop);
	win.focus();
}
function oculta_ayuda(){
	ocultar = document.getElementById("capaAyuda");
	clearTimeout(retardo);
	retardo = setTimeout("xHide('" + ocultar + "')",1000);
}

function muestra_retarda(){
	document.getElementById("capaAyuda").style.visibility = "visible";
	clearTimeout(retardo);
} 
function xHide(e) {
  	document.getElementById("capaAyuda").style.visibility='hidden';
}

function nl2br(str) {
   return str.replace(/\n/g,"<br>");
}
function limiteTextarea(que,cuanto){
	var v=que.value;
	if(v.length>cuanto){
		que.value=v.substring(0,cuanto);
		alert('El limite de caracteres es: ' + cuanto);
		return false;
	}
	return true;
}
function lTrim(sStr){
	while (sStr.charAt(0) == " ") 
		sStr = sStr.substr(1, sStr.length - 1);
		return sStr;
}
function rTrim(sStr){
	while (sStr.charAt(sStr.length - 1) == " ") 
		sStr = sStr.substr(0, sStr.length - 1);
		return sStr;
}	
function allTrim(sStr){
	return rTrim(lTrim(sStr));
}

function anyoBisiesto(anyo){
/**
* si el aņo introducido es de dos cifras lo pasamos al periodo de 1900. Ejemplo: 25 > 1925
*/
	if (anyo < 100){
		var fin = anyo + 1900;
	}
	else{
		var fin = anyo ;
	}
/*
* primera condicion: si el resto de dividir el aņo entre 4 no es cero > el aņo no es bisiesto
* es decir, obtenemos aņo modulo 4, teniendo que cumplirse anyo mod(4)=0 para bisiesto
*/
	if (fin % 4 != 0){
		return false;
	}
	else{
		if (fin % 100 == 0){
			/**
			* si el aņo es divisible por 4 y por 100 y divisible por 400 > es bisiesto
			*/
			if (fin % 400 == 0){
				return true;
			}
			/**
			* si es divisible por 4 y por 100 pero no lo es por 400 > no es bisiesto
			*/
			else{
				return false;
			}
		}
		/**
		* si es divisible por 4 y no es divisible por 100 > el aņo es bisiesto
		*/
		else{
			return true;
		}
	}
}
/**
* funcion principal de validacion de la fecha
* argumento fecha > cadena de texto de la fecha introducida por el usuario
*/
function validarFecha(fechacad ){
	/**
	* obtenemos la fecha introducida y la separamos en dia, mes y aņo
	*/
	
	var dia=fechacad.split("-")[0];
	var mes=fechacad.split("-")[1];
	var anyo=fechacad.split("-")[2];
	var febrero = 28;
	if( (isNaN(dia)==true) || (isNaN(mes)==true) || (isNaN(anyo)==true) ){
		return false;
	}
	if(anyoBisiesto(anyo)){
		febrero=29;
	}
	
	/**
	* si el mes introducido es negativo, 0 o mayor que 12 > alertamos y detenemos ejecucion
	*/
	if ((mes<1) || (mes>12)){
		return false;
	}
	/**
	* si el mes introducido es febrero y el dia es mayor que el correspondiente
	* al aņo introducido > alertamos y detenemos ejecucion
	*/
	if ((mes==2) && ((dia<1) || (dia>febrero))){
		return false;
	}
	/**
	* si el mes introducido es de 31 dias y el dia introducido es mayor de 31 > alertamos y detenemos ejecucion
	*/
	if (((mes==1) || (mes==3) || (mes==5) || (mes==7) || (mes==8) || (mes==10) || (mes==12)) && ((dia<1) || (dia>31))){
		return false;
	}
	/**
	* si el mes introducido es de 30 dias y el dia introducido es mayor de 301 > alertamos y detenemos ejecucion
	*/
	if (((mes==4) || (mes==6) || (mes==9) || (mes==11)) && ((dia<1) || (dia>30))){
		return false;
	}
	/**
	* si el mes aņo introducido es menor que 1900 o mayor que 2010 > alertamos y detenemos ejecucion
	* NOTA: estos valores son a eleccion vuestra, y no constituyen por si solos fecha erronea
	*/
	if ((anyo<1900) || (anyo>2050)){
		return false;
	}
	return true;
} 

function seleccionar(combo, elemento) {
   var cantidad = combo.length;
   for (i = 0; i < cantidad; i++) {
      if (combo[i].value == elemento) {
         combo[i].selected = true;
      }   
   }
}

function arreglaTexto(texto){
	return unescape(texto.replace(/\+/gi," "));
}
function activaFormularioBusqueda(formu){
	if(formu.cpais.checked){
		formu.pais.disabled=false;
	}
	else{
		formu.pais.disabled = true;
	}
	
	if(formu.cMateria.checked){
		formu.Materia.disabled=false;
	}
	else{
		formu.Materia.disabled = true;
	}
	
	if(formu.csubmateria.checked){
		formu.SubMateria.disabled=false;
	}
	else{
		formu.SubMateria.disabled = true;
	}
}
function radioActiva(formu){
	if(formu.rad[0].checked==true){
		formu.elements[1].disabled=false;
		formu.elements[3].disabled=true;
		formu.elements[5].disabled=true;
		formu.elements[5].value = "";
		formu.elements[3].value = "";
	}
	else if(formu.rad[1].checked==true){
		formu.elements[1].disabled=true;
		formu.elements[3].disabled=false;
		formu.elements[5].disabled=true;
		formu.elements[1].value = "";
		formu.elements[5].value = "";
	}
	else if(formu.rad[2].checked==true){
		formu.elements[1].disabled=true;
		formu.elements[3].disabled=true;
		formu.elements[5].disabled=false;
		formu.elements[1].value = "";
		formu.elements[3].value = "";
	}
}
function subeimagen(f){
	document.getElementById('formularioUpload').innerHTML="<img align='left' src='../images/loading.gif'>";
	f.submit();
}
function resultadoUpload(estado, file, nfinal, tamanio){
	
	if (estado == 0){
		var mensaje = 'Foto Enviada Correctamente';
		document.formuInstitucion.nimagen.value=nfinal;
		document.formuInstitucion.noriginal.value=file;
		document.formuInstitucion.tamanio.value=tamanio;
		
		mensaje+='<br>Copie la siguiente direccion para vincular esta imagen<br>';
		mensaje+='<span id = "ruta" name = "ruta" style=\'font-size:13px\'>http://www.programaregionalandino.org/imgInstitucion/'+nfinal+'</span>';
	}
	if (estado == 1)
		var mensaje = 'Error 1 ! - El Archivo no llego al servidor';
	if (estado == 2)
		var mensaje = 'Error 2 ! - Formato Erroneo.';
	if (estado == 3)
		var mensaje = 'Error 3 ! - No se pudo copiar Archivo.';
		
		
	document.getElementById('formularioUpload').innerHTML=mensaje;
	
}

function subirResultado(estado, file, nfinal, tamanio){
	
	if (estado == 0){ 
		var mensaje = 'Foto Enviada Correctamente';
		document.fneditarInstitucion.nimagen.value=nfinal;
		document.fneditarInstitucion.noriginal.value=file;
		document.fneditarInstitucion.tamanio.value=tamanio;
		
		mensaje+='<br>Copie la siguiente direccion para vincular esta imagen<br>';
		mensaje+='<span id = "ruta" name = "ruta" style=\'font-size:13px\'>http://www.programaregionalandino.org/imgInstitucion/'+nfinal+'</span>';
	}
	if (estado == 1)
		var mensaje = 'Error 1 ! - El Archivo no llego al servidor';
	if (estado == 2)
		var mensaje = 'Error 2 ! - Formato Erroneo.';
	if (estado == 3)
		var mensaje = 'Error 3 ! - No se pudo copiar Archivo.';
		
		
	document.getElementById('formularioUpload').innerHTML=mensaje;
	
}