//Detección navegador
if (navigator.appName == "Netscape") {
  		document.write("<link rel='stylesheet' href='/css/firefox.css' type='text/css'>");
}
if (navigator.appName == "Microsoft Internet Explorer") {
  		var a = new Array;
  		a = navigator.appVersion.split(";");

  		if (a[1].indexOf ("MSIE 6") == 1) {
    		document.write("<link rel='stylesheet' href='/css/ie6.css' type='text/css'>");
  		} else {
    		document.write("<link rel='stylesheet' href='/css/ie6.css' type='text/css'>");
  		}
}

//Ajax:
var http = createRequestObject();
var httpPost = createRequestObject();

function createRequestObject() {
	var ro;
	var browser = navigator.appName;

	if(browser == "Microsoft Internet Explorer"){
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else{
		ro = new XMLHttpRequest();
	}
	return ro;
}  

function cambio_foto() {
try {
				if (document.getElementById("cargando").style.visibility == "hidden") {
					document.getElementById("cargando").style.visibility = "visible";
				}
				setTimeout("rula(0)",3000);
	} catch (exception) {}
}
function rula(opcion) {
try {
                var http = createRequestObject();
				if (document.getElementById("foto1").style.visibility == 'hidden') {
				  var div = "foto1";
				  var div2 = "foto2";
				  var new_f = "f1";
				  var old_f = "f2";
				} else {
				  var div = "foto2";
				  var div2 = "foto1";
				  var new_f = "f2";
				  var old_f = "f1";
				}
				http.open("get", 'http://www.coaateeef.org/carrusel.asp?var='+div+'&opcion='+opcion);
                http.onreadystatechange = function () {  
                        if(http.readyState == 4){  
           
                                if (http.responseText) {
										var resp = http.responseText;

										document.getElementById("cargando").style.visibility = "hidden";
										document.getElementById(div).innerHTML = resp;
																			
										document.getElementById(div).style.visibility = "visible";
										opacity(new_f, 0, 100, 1000);
										opacity(old_f, 100, 0, 1000);
										setTimeout("oculta('"+div2+"')",1000); 										
                                }
                        } 
                };
                http.send(null);
	} catch (exception) {} 
}

function fotos_portada(id) {
	document.getElementById('fotos_portada').innerHTML = "<img src='img/cargando.gif' width='80' height='80' >";

                var http = createRequestObject();
				http.open("get", 'http://www.coaateeef.org/fotos_portada.asp?id='+id);
                http.onreadystatechange = function () {  
                        if(http.readyState == 4){             
                                if (http.responseText) {
										var resp = http.responseText;
										document.getElementById('fotos_portada').innerHTML = resp;
  										document.getElementById('foto').src = "http://www.coaateeef.org/img/blanco.jpg"; //RECORDA MODIFICAR-HO!!!!!!!										
                                }
                        } 
                };
                http.send(null);  
}

function banners(id) {

	document.getElementById('banners').innerHTML = "<img src='img/cargando.gif' width='80' height='80' >";

                var http = createRequestObject();
				http.open("get", 'http://www.coaateeef.org/banners.asp?id='+id);
                http.onreadystatechange = function () {  
                        if(http.readyState == 4){             
                                if (http.responseText) {
										var resp = http.responseText;
										document.getElementById('banners').innerHTML = resp;
  										document.getElementById('banner').src = "http://www.coaateeef.org/img/blanco.jpg"; //RECORDA MODIFICAR-HO!!!!!!!										
                                }
                        } 
                };
                http.send(null);  
}

function actualiza_menu(id,tipo,idioma,operacion,menu,destino,orden,padre) {
	if (operacion == -2) {
		if (!confirm("Se eliminarán este registro y todos los contenidos en su interior. ¿Está segur@?")) {
			return;
		}
	}
	document.getElementById(tipo).innerHTML = "<img src='img/cargando.gif' width='80' height='80' >";
                var http = createRequestObject();
				if (document.getElementById("id").value == "") {
					http.open("get", 'http://www.coaateeef.org/menu.asp?id='+id+'&tipo='+tipo+'&idioma='+idioma+'&operacion='+operacion+"&menu="+menu+"&destino="+destino+"&orden="+orden+"&padre="+padre);
				} else {
					http.open("get", 'http://www.coaateeef.org/menu.asp?id='+id+'&tipo='+tipo+'&idioma='+idioma+'&operacion='+document.getElementById("id").value+"&menu="+menu+"&destino="+destino+"&orden="+orden+"&padre="+padre);
				}
                http.onreadystatechange = function () {  
                        if(http.readyState == 4){             
                                if (http.responseText) {
										var resp = http.responseText;
										document.getElementById(tipo).innerHTML = resp;
                                }
                        } 
                };
                http.send(null);  
	document.getElementById("id").value = "";
	document.getElementById("idioma").value = "";
	document.getElementById("menu").value = "";
	document.getElementById("link").value = "";
	document.getElementById("padre").value = "0";
	document.getElementById("orden").value = "0";
}


//Javascript
var posicion
var anterior
var actual
var espera
var posicionado = new Array();


function tempo_off(id,z) {
  if (posicion != id) {
   	if (posicion == -1) {
	  if (espera == false) {
	    pasada = false;
 		for (a=0;a<posicionado.length;a++) {
   				document.getElementById(posicionado[a]).style.visibility = "hidden";
				pasada = true;
 		}
		if (pasada == true) {
   		  for (a=0;a<z;a++) {
		    try {
   				document.getElementById(a).className = "menu_padre";
		    } catch(e) {}
   		  }
		}
	  } else {
    			setTimeout("tempo_off('"+id+"','"+z+"')",500);
	  } 
	}  else {
		pasada = false;
 		for (a=0;a<posicionado.length;a++) {
			if (document.getElementById(posicionado[a]).className == String(id) && anterior != actual ) {
   					document.getElementById(posicionado[a]).style.visibility = "hidden";
					pasada = true;
			}
 		}
		if (pasada == true)	{
 			for (a=0;a<z;a++) {
				try {
					document.getElementById(a).className = "menu_padre";
				} catch(e) {}
			}
		}
		
	    if (espera == true) {
    			setTimeout("tempo_off('"+id+"','"+z+"')",500);
	  	} 
		
	}
  }
}

function comprueba_fecha(fecha)
{
	if (fecha == "fecha" ) {
		var f=document.getElementById("fecha").value
	re=/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]$/
	if(f.length==0 || !re.exec(f))
	{
		alert("La fecha no tiene formato correcto.")
		return
	}

	var d = new Date()
	d.setFullYear(f.substring(6,10), 
		f.substring(3,5)-1,
			f.substring(0,2))

	if(d.getMonth() != f.substring(3,5)-1 
		|| d.getDate() != f.substring(0,2))
	{
		alert("Fecha no válida.")
		return
	}
		document.forms("form_agenda").submit();


	} else {

		var f = document.getElementById("fecha1").value
			re=/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]$/
	if(f.length==0 || !re.exec(f))
	{
		alert("La fecha no tiene formato correcto.")
		return
	}

	var d = new Date()
	d.setFullYear(f.substring(6,10), 
		f.substring(3,5)-1,
			f.substring(0,2))

	if(d.getMonth() != f.substring(3,5)-1 
		|| d.getDate() != f.substring(0,2))
	{
		alert("Fecha no válida.")
		return
	}


		var f = document.getElementById("fecha2").value
			re=/^[0-9][0-9]\/[0-9][0-9]\/[0-9][0-9][0-9][0-9]$/
	if(f.length==0 || !re.exec(f))
	{
		alert("La fecha no tiene formato correcto.")
		return
	}

	var d = new Date()
	d.setFullYear(f.substring(6,10), 
		f.substring(3,5)-1,
			f.substring(0,2))

	if(d.getMonth() != f.substring(3,5)-1 
		|| d.getDate() != f.substring(0,2))
	{
		alert("Fecha no válida.")
		return
	}

		document.forms("visado").submit();
	}
}

function apaga(id,z) {
   	setTimeout("tempo_off('"+id+"','"+z+"')",500);
}
function alumbra(id,z,i) {
		pasada = false
 		for (a=0;a<posicionado.length;a++) {
			if (document.getElementById(posicionado[a]).className == String(id) ) {
   				document.getElementById(posicionado[a]).style.visibility = "visible";
				pasada = true;
			} 
 		}
		if (pasada == true) {
 		for (a=0;a<z;a++) {
		  try {
			if (document.getElementById(String(a)).className == "menu_padre" && document.getElementById(String(a)).id != String(i) ) {
				document.getElementById(String(a)).className = "apagado";
			} 
		  } catch(e) {  }
 		}		
		}
}

function envia_banner() {
  document.forms("form_banner").action = "http://www.coaateeef.org/upload_banner.asp?tipo_banner="+document.getElementById("tipo_banner").value+"&destino_banner="+document.getElementById("link2").value;
  document.forms("form_banner").submit();
}
function visualiza_foto(foto) {
  document.getElementById('foto').src = "http://www.coaateeef.org/fotos/"+foto;
}
function visualiza_banner(banner) {
  document.getElementById('banner').src = "http://www.coaateeef.org/banners/"+banner;
}

function modifica_menu(id,tipo,idioma,destino,menu,padre,orden) {
	document.getElementById("id").value = id;
	document.getElementById("idioma").value = idioma;
	document.getElementById("tipo").value = tipo;
	document.getElementById("menu").value = menu;
	document.getElementById("link").value = destino;
	document.getElementById("padre").value = padre;
	document.getElementById("orden").value = orden;
}

function solo_numeros(e) {
var tecla = window.event.keyCode;
if (tecla != 8 && tecla != 95) {
if (tecla < 48 || tecla > 57) {
		window.event.keyCode=0;
}
}
}  
function muestra_menu(tipo,ruta,lang){
  window.open (ruta+"paginas.asp?lng="+lang+"&tp="+tipo+"&ambito="+document.getElementById("tipo").value,"paginas","height=400,width=500"); 
}
function validar(e) { 
var tecla = window.event.keyCode;
if (tecla != 8 && tecla != 95) {
if (tecla < 48 || tecla > 57) {
  if (tecla < 97 || tecla > 122) {
    if (tecla < 65 || tecla > 90) {
		window.event.keyCode=0;
    }
  }
}
}
}  
function pon_url(ruta){
if (document.getElementById('file_name').value!='') {
  document.getElementById('url').value =  ruta+'index.asp?pag='+document.getElementById('file_name').value;
} else {
  document.getElementById('url').value =  ruta+'index.asp?pag=nueva_pagina';
}
}

function oculta(capa) {
  document.getElementById(capa).style.visibility = "hidden";
}
function temporiza(pagina) {
	timer = setInterval("cambio_foto()", 15000);
	if (pagina == 'resumen') {
		document.getElementById('tempo_resumen').style.visibility = 'hidden';
	}
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function shiftOpacity(id, millisec) {
	//if an element is invisible, make it visible, else make it ivisible
	if(document.getElementById(id).style.opacity == 0) {
		opacity(id, 0, 100, millisec);
	} else {
		opacity(id, 100, 0, millisec);
	}
}

function blendimage(divid, imageid, imagefile, millisec) {
	var speed = Math.round(millisec / 100);
	var timer = 0;
	
	//set the current image as background
	document.getElementById(divid).style.backgroundImage = "url(" + document.getElementById(imageid).src + ")";
	
	//make image transparent
	changeOpac(0, imageid);
	
	//make new image
	document.getElementById(imageid).src = imagefile;

	//fade in image
	for(i = 0; i <= 100; i++) {
		setTimeout("changeOpac(" + i + ",'" + imageid + "')",(timer * speed));
		timer++;
	}
}

function currentOpac(id, opacEnd, millisec) {
	//standard opacity is 100
	var currentOpac = 100;
	
	//if the element has an opacity set, get it
	if(document.getElementById(id).style.opacity < 100) {
		currentOpac = document.getElementById(id).style.opacity * 100;
	}

	//call for the function that changes the opacity
	opacity(id, currentOpac, opacEnd, millisec)
}
