// JavaScript Document

if (!Array.prototype.indexOf) {
	  Array.prototype.indexOf = function(elt) {
		var len = this.length;
		var from = Number(arguments[1]) || 0;
		from = (from < 0)
			 ? Math.ceil(from)
			 : Math.floor(from);
		if (from < 0)
		  from += len;	

		for (; from < len; from++) {
		  if (from in this &&
			  this[from] === elt)
			return from;
		}
		return -1;
	  };
}

function show(obj) {
	document.getElementById(obj).style.display="block";
}

function hide(obj) {
	document.getElementById(obj).style.display="none";
}

function vercorreo(usuario,dominio,ext) {
	document.getElementById("correo").innerHTML = "<a href='ma"+"il"+"to:"+usuario+"@"+dominio+"."+ext+"'>"+usuario+"@"+dominio+"."+ext+"</a>";
}

function isEmail(string) {
	if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true;
	else {
		alert("La dirección de correo electrónico no es válida.");
		return false;
	}
}

function confirmation(url,txt) {
	   	if (confirm(txt)) window.location = url ;
}

function favoritos() {
	window.sidebar.addPanel('mptodos','http://mptodos.org','mptodos');
   if (window.sidebar)
   {
   window.sidebar.addPanel("mptodos", "http://mptodos.org","Montaña para todos");
   }
   else if( document.all )
   {
   window.external.AddFavorite("http://mptodos.org", "mptodos");
   }
   else
        {
   return true;
   }
}

function xmlhttpPost(strURL, strSubmit, strResultFunc) {

        var xmlHttpReq = false;
        
        // Mozilla/Safari
        if (window.XMLHttpRequest) {
                xmlHttpReq = new XMLHttpRequest();
        }
        // IE
		else if (window.ActiveXObject) { // Internet Explorer 
		   try {
					xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
				} catch (e) {
					xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
				}
        }
     	xmlHttpReq.open('POST', "/jx/"+strURL+".php", true);
        xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xmlHttpReq.onreadystatechange = function() {
                if (xmlHttpReq.readyState == 4) {
					eval(strResultFunc + '(xmlHttpReq.responseText);');
				}
		}
		xmlHttpReq.send(strSubmit);
}

function publicado(r) {
	var retour = r.split("|");
	var iconId = "iconPub"+(retour[1]*1);
	document.getElementById(iconId).src = "/img/icons/pub"+retour[0]+".gif";
	if (retour[0]==0) document.getElementById(iconId).title = "Suspender la publicación del artículo";
	else document.getElementById(iconId).title = "Publicar el artículo";
}

function setCalendar(txt) {
	document.getElementById("calendar").innerHTML = "<select name='acti' id='acti'>"+txt+"</select>";
}

function nouveau() {
	if (document.info.nuevo.checked) show('inscription');
	else hide('inscription');
}

function borrar(i,t) {
	if (confirm("¿Esta seguro de querer borrar este documento?"))
		location.href = "index.php?mod=listaArti&del="+i+"&tipo="+t;
}

function addArtList(p,m) {
	getTF(400);
	if (p==7) location.href = "index.php?mod=edit&id=0&p="+p+"&m="+m;
	else document.getElementById("tfcont").innerHTML = "<p>&nbsp;</p><p align='center'><a href='index.php?mod=edit&id=0&p="+p+"&m="+m+"' class='button2' style='font-size:14px;'>&nbsp;Crear un nuevo artículo&nbsp;</a></p><p align='center'><a href='#' onclick='getListArt("+p+",0)' class='button2' style='font-size:14px;'>&nbsp;Buscarlo en el servidor&nbsp;</a></p><p>&nbsp;</p>";
}

function getListArt(p,t,ad) {
	document.getElementById("tfcont").innerHTML = "<img src='/img/loading.gif' style='margin:25px 0 0 100px' />";
	getTF(650);
	var str = "p="+p+"&tipo="+t;
	if (ad) str += "&ad="+ad;
	xmlhttpPost("panel_articulos", str, "setResult");
}

function delArt(i,p) {
	if (confirm("Vas a borrar definitivamente este artículo.No se puede recuperar.\nSi quiere solamente quitarlo de un listado sin borrarlo utilice el icono anterior a este efecto.\n\n¿Esta seguro de querer borrar este artículo?")) {
		location.href = "index.php?mod=txtGen&del="+i+"&id="+p;
	}
}

function quitArt(i,p) {
	if (confirm("Vas a quitar este artículo de un listado, no se borrará el artículo.\nSi quiere borrarlo definitivamente utilice el icono siguiente a este efecto.\n\n¿Esta seguro de querer quitar este artículo del listado?")) {
		location.href = "index.php?mod=txtGen&adList=-"+p+"&art="+i;
	}
}

function getTF(w,t) {
	var o = document.getElementById("tf").style;
	o.display = "block";
	o.left = ((screen.width-w)/2) + "px";
	if (!t) t = 5;
	o.top = t + "px";
	o.width = w + "px";
}

function insertar(i,p,ad) {
	if (ad) {
		location.href = "index.php?mod=edit&ad="+ad+"&i="+i;
	} else location.href = "index.php?adList="+p+"&art="+i;
}

function setResult(result) {
	document.getElementById('tfcont').innerHTML = result;
	
}

function setNewPag(o) {
	var obj = document.frmMenus;
	obj.idx.value = o.id;
	obj.submit();
}

function getMsg(i,x) {
	getTF(x,10);
	xmlhttpPost("txtGen", "id="+i, "setResult");
}

function delDoc(f,t) {
	if (confirm("¿Esta seguro de querer borrar este artículo?")) location.href = "index.php?mod=listDoc&tipo="+t+"&del="+f;
}

function sendBol(i) {
	if (confirm("Va a publicar este boletín. Lo recibirán todos los usuarios registrados para recibirlo.\n\n¿Estas de acuerdo?")) {
		getTF(350);
		document.getElementById("tfcont").innerHTML = "<p>&nbsp;</p><p align='center'>Espere: puede tardar un poco</p><p>&nbsp;</p>";
		location.href = "index.php?mod=boletin&id="+i;
	}
}

function guardar() {
	aviso = false;
	var hoy = new Date();
	hoy = Math.floor(hoy.getTime()/86400000);
	if (Math.floor(document.frm.caduc.value/86400)==hoy && confirm("La fecha de fin de activida es la de hoy, si no cambia la fecha mañana estará en los archivos de actividades realizadas.\n\nPulse aceptar para volver y cambiar la fecha.\nPulse cancelar para seguir registrando el artículo.")) return;

	document.frm.submit();
}
