// 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;
	  };
}

var cat = 0; //variable que determina el area del menú donde estamos

function ajoutFicha(base) {
	window.location = base+"?mod=edit&id=0&cat="+cat;
}

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 correo(usuario,dominio,ext,asunto,cuerpo) {
	if (typeof cuerpo == 'undefined') cuerpo = '';
	if (typeof asunto == 'undefined' || asunto == '') asunto = escape("Demande d'information pour La Culedus");
	window.location.href = "ma"+"il"+"to:"+usuario+"@"+dominio+"."+ext+"?subject="+asunto+"&body="+cuerpo;
}

function validar() {
	var args = validar.arguments;
	var err = "";
	for (i=0; i<(args.length-1); i+=2) {
		var val = document.frm.elements[args[i]].value;
		var test = args[i+1];
		var campo = args[i];
		if (campo=='email') {
			if (checkEmail(false)) err += "La dirección de correo no es correcta!\n\r";
		}
		if (test=='R' && val=='') {
			err += "El campo "+campo+" no puede ser vacío\n\r";
		}
		
	}
	if (err!="") {
		alert(err);
		return false;
	} else return true;
}

function checkEmail(aviso) {
	var str = document.frm.email.value;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (!filter.test(str)) {
		if (aviso) alert("La dirección de email no es correcta!");
		else 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(retour) {
	var iconId = "iconPub"+idmsg;
	document.getElementById(iconId).src = "/img/icons/pub"+retour+".gif";
	if (retour==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');
}