// JavaScript Document

var ruta;
var sens = 1;


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 MM_openBrWindow(theURL,winName,features) { //v2.0
  window.name='windowOpener';
  window.open(theURL,winName,features);
}

function confirmation(elemento, base, query) {
	   	if (confirm("Es tu sur de vouloir effacer cet élément? Tu ne pourras pas le récupérer."))
       	window.location = base+".php"+query ;
}

function correo(usuario,dominio,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+"?subject="+asunto+"&body="+cuerpo;
}

function vercorreo(usuario,dominio) { //v1.0
document.getElementById("correo").innerHTML = "<a href=\"javascript:correo('"+usuario+"','"+dominio+"')\">"+usuario+"|@|"+dominio;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+'.\n'; }
  } if (errors) alert('Los campos siguientes son obligatorios:\n'+errors);
  document.MM_returnValue = (errors == '');
}

function insertar(fichero) {
	window.opener.document.getElementById('txtUrl').value = fichero;
	window.close();
}

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);');
                } else document.getElementById("aviso").innerHTML = "<img src='../../img/loading.gif' />";
		}

		xmlHttpReq.send(strSubmit);
}

function getXY(obj){
        var curleft = curtop = 0;
		if (obj.offsetParent) {
			do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
			} while (obj = obj.offsetParent);
		}
		return [curleft,curtop];
}

function editRuta(rta) {
	window.location.href = "palma.php?mod=editTxtRuta&id="+rta;
}

function fichRta(rta,AR) {
	ruta = rta;
	sens = AR;
	if (readCookie("lang")>0) var lang=readCookie("lang"); else var lang=4;
	xmlhttpPost("getFichRta", "sendero="+rta+"&lang="+lang+"&sens="+AR, "verFichRta");
}

function verFichRta(txt) {
	document.getElementById("fichRtaCont").innerHTML = txt;
	document.getElementById("fichRta").style.display = "block";
	document.getElementById("espera").style.display = "none";
	document.getElementById("texto").style.display = "none";
	document.getElementById("aviso").innerHTML = "";
}

function hideFichRta() {
	document.getElementById("fichRta").style.display = "none";
	document.getElementById("texto").style.display = "block";
}

function editFichRta() {
	window.location.href = "palma.php?mod=editFichRuta&id="+ruta;
}

function nivels(rta) {
	document.getElementById("nivelsRtaCont").innerHTML = "<img src='http://de-la-gomera.es/lapalma/profils/ruta"+rta+".png' />";
	document.getElementById("nivelsRta").style.display = "block";
	document.getElementById("texto").style.display = "none";
	ruta = rta;
	document.getElementById("espera").style.display = "none";
}

function hideNivelsRta() {
	document.getElementById("nivelsRta").style.display = "none";
	document.getElementById("texto").style.display = "block";
}

function modifFich(t,o) {
	var msg = document.getElementById(t+"-"+o).innerHTML;
	document.getElementById(t+"-0").value = msg;
	document.getElementById("t-"+t).value = o;
	document.getElementById("bt-"+t).value = "Modifier";
}

function delFich(t,o,s) {
	if (confirm("Es tu sur de vouloir effacer le texte de ce point?/n/nCe point s'effacera dans toutes les langues./n/nTu ne pourras pas le récupérer.")) location.href = "admin/delFich.php?t="+t+"&o="+o+"&s="+s;
}

function inverse() {
	sens = (sens*-1);
	fichRta(ruta,sens);
}

function subFich(t,o,s) {
	location.href = "admin/subFichRta.php?t="+t+"&o="+o+"&s="+s;
}

function fullRta(path) {
	window.open(path,"rtaExtFull","fullscreen=yes,scrollbars=auto");
}

function createCookie(name, value,days) {
	if (days) {
 		var date = new Date();
 		date.setTime(date.getTime()+(days*24*60*60*1000));
 		var expires = "; expires="+date.toGMTString();
	} else var expires = ";";
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var cookies = document.cookie.split(';');
	for(var i = 0; i < cookies.length;i++) {
 		var cookie = cookies[i];
 		while (cookie.charAt(0) == ' ') {
  		cookie = cookie.substring(1, cookie.length);
 		}
 		if (cookie.indexOf(nameEQ) == 0) {
  		return cookie.substring(nameEQ.length, cookie.length);
 		}
	}
return null;
}

function delCookie(name) {
	createCookie(name, "", -1);
}

function imprimir() {
	if (readCookie("lang")>0) var lang=readCookie("lang"); else var lang=4;
	window.open("admin/print.php?sendero="+ruta+"&sens="+sens+"&lang="+lang);
}

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

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

