// Documento JavaScript
// Esta función cargará las paginas (sea cual sea su extension
var loadstatustext="<img src='images/loading.gif' width='16' height='16' border='0' /> Cargando contenido..."
function loadAJAX(url, id_contenedor, method, func, param1, param2){
	var objAJAX = false
	if (window.XMLHttpRequest) {// Si es Mozilla, Safari etc
		objAJAX = new XMLHttpRequest()
	} else if (window.ActiveXObject) {// pero si es IE
		try {// en caso que sea una versión nueva
			objAJAX = new ActiveXObject("Msxml2.XMLHTTP")
		} catch (e){// en caso que sea una versión antigua
			try{ objAJAX = new ActiveXObject("Microsoft.XMLHTTP") } catch (e){} 
		}
	} else {
		document.getElementById(id_contenedor).innerHTML="Su Browser (navegador) no soporta esta función.";return false
	}
	if (objAJAX) {
		document.getElementById(id_contenedor).innerHTML=loadstatustext
		objAJAX.onreadystatechange=function(){ showAJAX(objAJAX, id_contenedor, func, param1,param2) }
		objAJAX.open(method.toUpperCase(), url, true)
		objAJAX.send(null)
	} else {
		document.getElementById(id_contenedor).innerHTML="Error :"+objAJAX.readyState ;return false
	}
}

// todo es correcto y ha llegado el momento de poner la información requerida en su sitio en la pagina xhtml
function showAJAX(objAJAX, id_contenedor, func, param1,param2){
	// A continuacion comprobamos el codigo de respuesta HTTP del servidor en caso de ser correcta seria 200 (OK)
	// Si hacemos una prueba local no es necesario
	     if (objAJAX.readyState == 0) { /* 0: sin inicializar */ }// primermo comprobamos el estado de la respuesta
	else if (objAJAX.readyState == 1) { /* 1 : cargandose */     }
	else if (objAJAX.readyState == 2) { /* 2 : cargado */        }
	else if (objAJAX.readyState == 3) { /* 3 : interactivo */    }
	else if (objAJAX.readyState == 4) {/* 4 : completa */ 	// A continuacion comprobamos el codigo de respuesta HTTP del servidor en caso de ser correcta seria 200 (OK) Si hacemos una prueba local no es necesario
	//	if (objAJAX.status==200 || window.location.href.indexOf("http")==-1)){//
		if (objAJAX.status==200 || objAJAX.status == 0) {
			if (id_contenedor)document.getElementById(id_contenedor).innerHTML=objAJAX.responseText;
			TOGGLE.start();
			if (func){loadXMLDoc(param1,param2)}//else{MostrarNota(false)}/* Oculto el menu desplegado*/
		} else { // not 200 OK
			     if (objAJAX.status == 201){ alert(" Created ") }
			else if (objAJAX.status == 204){ alert(" No Content ") }
			else if (objAJAX.status == 205){ alert(" Reset Content ") }
			else if (objAJAX.status == 206){ alert(" Partial Content ") }
			else if (objAJAX.status == 400){ alert(" Bad Request ") }
			else if (objAJAX.status == 401){ alert(" Unauthorized ") }
			else if (objAJAX.status == 403){ alert(" Forbidden ") }
			else if (objAJAX.status == 404){ alert(" Not Found ") }
			else if (objAJAX.status == 405){ alert(" Method Not Allowed ") }
			else if (objAJAX.status == 406){ alert(" Not Acceptable ") }
			else if (objAJAX.status == 407){ alert(" Proxy Authentication Required ") }
			else if (objAJAX.status == 408){ alert(" Request Timeout ") }
			else if (objAJAX.status == 411){ alert(" Length Required ") }
			else if (objAJAX.status == 413){ alert(" Requested Entity Too Large ") }
			else if (objAJAX.status == 414){ alert(" Requested URL Too Long ") }
			else if (objAJAX.status == 415){ alert(" Unsupported Media Type ") }
			else if (objAJAX.status == 500){ alert(" Internal Server Error ") }
			else if (objAJAX.status == 501){ alert(" Not Implemented ") }
			else if (objAJAX.status == 502){ alert(" Bad Gateway ") }
			else if (objAJAX.status == 503){ alert(" Service Unavailable ") }
			else if (objAJAX.status == 504){ alert(" Gateway Timeout ") }
			else if (objAJAX.status == 505){ alert(" HTTP Version Not Supported ") }
			else                       { alert(" Error desconocido :"+objAJAX.status) }
		}
	}
}

/*************************************************************************************************************************
// functionTOGGLE.js
// from: http://www.mssti.com
**************************************************************************************************************************/

// ==============================================================================================================================
// UNOBTRUSIVE TOGGLE SECTIONS SCRIPT: TOGGLE v1.0
// (c)2004 Sergi Meseguer http://zigotica.com/ under CC license: http://creativecommons.org/licenses/by-sa/2.0/
// Requires EXTRAS namespace (extras.js in this folder)
// Just set htmlclass to element to be hidden/shown and it'll make a link from the previous element
// ==============================================================================================================================

TOGGLE = {
	// edit text to append before linkable element
	showtxt : "> ",
	hidetxt : "< ",
	// edit html class name
	htmlclass : "toggle",
	// you should not need to edit past this point
	// ======================================================
	start : function(){ 
		var togglers = EXTRAS.getElementsByClass(TOGGLE.htmlclass);
		for (var i = 0; i < togglers.length; i++) {
			var box = togglers[i].previousSibling;
			//fix for Moz and line break/tab, etc:
			if(typeof box.innerHTML != "string") box = box.previousSibling; 
			var cont = togglers[i];
			//avoids currentStyle/computedStyle:
			cont.style.display = "block"; 
			TOGGLE.prepare(box,cont);
		}
	},
	
	prepare : function(box,cont){ 
		var origtxt = box.innerHTML;
		cont.style.display = "none";
		box.innerHTML = TOGGLE.showtxt+origtxt;
		box.onclick = function(){
			TOGGLE.run(box,cont,origtxt);
		}
		// fix for IE5.x cursor property:
		if(navigator.appVersion.indexOf("MSIE 5") > -1 && !window.opera) box.style.cursor = "hand";
		else box.style.cursor = "pointer";
	},
	
	run : function(box,cont,origtxt) { 
		if(cont.style.display == "block") {
			cont.style.display = "none";
			box.innerHTML = TOGGLE.showtxt+origtxt;
		}
		else {
			cont.style.display = "block";
			box.innerHTML = TOGGLE.hidetxt+origtxt;
		}
	}
}

EXTRAS = {

	// Event listener by Scott Andrew (www.scottandrew.com):
	addEvent : function(obj, evType, fn, useCapture){
		if (obj.addEventListener){
			obj.addEventListener(evType, fn, useCapture);
			return true;
		} 
		else if (obj.attachEvent){
			var r = obj.attachEvent("on"+evType, fn);
			return r;
		} 
		else {//; alert('false')
			return false;
		}
	}, 
	
	// Method adapted from Dan Pupius (pupius.co.uk):
	getElementsByClass : function(className,node) {
		if(!node) node=document;
		var refTags = document.all ? node.all : node.getElementsByTagName("*");
		var retVal = new Array();
		for(var z=0;z<refTags.length;z++) {
			if(refTags[z].className == className) 
			retVal.push(refTags[z]);
		}
		return retVal; 
	},
	
	// removes whitespace-only text node children
	cleanWhitespace: function(element) {
		element = $(element);
		var node = element.firstChild;
		while (node) {
			var nextNode = node.nextSibling;
			if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
			element.removeChild(node);
			node = nextNode;
		}
		return element;
	}
}

