var DOMhelp={
	// CSS classes
	hidingClass:'.hide', // Hide elements
	showingClass:'.show', // Show elements
	

	// Find the last sibling of the current node
	lastSibling:function(node)
	{
		var tempObj=node.parentNode.lastChild;
		while(tempObj.nodeType!=1 && tempObj.previousSibling!=null)
		{
			tempObj=tempObj.previousSibling;
		}
		return (tempObj.nodeType==1)?tempObj:false;
	},
	// Find the first sibling of the current node
	firstSibling:function(node)
	{
		var tempObj=node.parentNode.firstChild;
		while(tempObj.nodeType!=1 && tempObj.nextSibling!=null)
		{
			tempObj=tempObj.nextSibling;
		}
		return (tempObj.nodeType==1)?tempObj:false;
	},
	// Retrieve the content of the first text node sibling of the current node
	getText:function(node)
	{
		if(!node.hasChildNodes()){return false;}
		var reg=/^\s+$/;
		var tempObj=node.firstChild;
		while(tempObj.nodeType!=3 && tempObj.nextSibling!=null || reg.test(tempObj.nodeValue))
		{
			tempObj=tempObj.nextSibling;
		}
		return tempObj.nodeType==3?tempObj.nodeValue:false;
	},
	// Set the content of the first text node sibling of the current node
	setText:function(node,txt)
	{
		if(!node.hasChildNodes()){return false;}
		var reg=/^\s+$/;
		var tempObj=node.firstChild;
		while(tempObj.nodeType!=3 && tempObj.nextSibling!=null || reg.test(tempObj.nodeValue))	{
			tempObj=tempObj.nextSibling;
		}
		if(tempObj.nodeType==3) {
			tempObj.nodeValue=txt
		} else {
			return false;
		}
	},
	// Create a new link containing the given text
	createLink:function(to,txt)
	{
		var tempObj=document.createElement('a');
		tempObj.appendChild(document.createTextNode(txt));
		tempObj.setAttribute('href',to);
		return tempObj;
	},
	// Create a new element containing the given text
	createTextElm:function(elm,txt)
	{
		var tempObj=document.createElement(elm);
		tempObj.appendChild(document.createTextNode(txt));
		return tempObj;
	},
	// Find the next or previous sibling that is an element
	// and not a text node or line break
	closestSibling:function(node,direction)
	{
		var tempObj;
		if(direction==-1 && node.previousSibling!=null)	{
			tempObj=node.previousSibling;
			while(tempObj.nodeType!=1 && tempObj.previousSibling!=null)	{
				tempObj=tempObj.previousSibling;
			}
		}
		else if(direction==1 && node.nextSibling!=null)	{
			tempObj=node.nextSibling;
			while(tempObj.nodeType!=1 && tempObj.nextSibling!=null)	{
				tempObj=tempObj.nextSibling;
			}
		}
		return tempObj.nodeType==1?tempObj:false;
	},
	// Simulate a debugging console to avoid the need for alerts
	initDebug:function()
	{
		if(DOMhelp.debug){DOMhelp.stopDebug();}
		DOMhelp.debug=document.createElement('div');
		DOMhelp.debug.setAttribute('id',DOMhelp.debugWindowId);
		document.body.insertBefore(DOMhelp.debug,document.body.firstChild);
	},
	setDebug:function(bug)
	{
		if(!DOMhelp.debug){DOMhelp.initDebug();}
		DOMhelp.debug.innerHTML+=bug+'\n';
	},	
	stopDebug:function()
	{
		if(DOMhelp.debug)	{
			DOMhelp.debug.parentNode.removeChild(DOMhelp.debug);
			DOMhelp.debug=null;
		}
	},
	//
	//	• a 		is the action that has to be taken and has the following options:
	//		• swap 		replaces one class with another.
	//		• add 		adds a new class.
	//		• remove 	removes a class.
	//		• check 	tests whether the class is already applied or not.
	//	• o 		is the object you want to add classes to or remove classes from.
	//	• c1 and c2 are the class names—c2 is only needed when the action is swap.
	cssjs:function(a,o,c1,c2){
		switch (a){
			case 'swap':
				if(!DOMhelp.cssjs('check',o,c1)){
					o.className = c1;
				} else {
					o.className = c2;
				}
			break;
			case 'add':
			if(!DOMhelp.cssjs('check',o,c1)){
				o.className+=o.className?' '+c1:c1;
			}
			break;
			case 'remove':
				var rep=o.className.match(' '+c1)?' '+c1:c1;
				o.className=o.className.replace(rep,'');
			break;
			case 'check':
				var found=false;
				var temparray=o.className.split(' ');
				for(var i=0; i<temparray.length; i++){
					if(temparray[i]==c1){ found=true; }
				}
				return found;
			break;
		}
	},
	
	getstyle:function()
	{
	  var i;
	  var j;
	  var mycssrules;
	  var myStyle;
	  for (i=0; i< document.styleSheets.length; i++)
	  {
		  if (document.layer)
			mycssrules = document.styleSheets[i].cssRules;
		  else
			mycssrules = document.styleSheets[i].rules;
		 for (j=0; j <  mycssrules.length; j++)
		  {
			myStyle = mycssrules[j].style;
			var fFamily = myStyle.fontFamily;
			var fSize = myStyle.fontSize;
			var fStyle = myStyle.fontStyle;
			alert("Style for: " + mycssrules[j].selectorText + 
				  "\nfamily :" + fFamily +
				  "\nsize: " + fSize + 
				  "\nstyle: " + fStyle);
		 }
	  }
	},
	
	setActiveStyleSheet:function(title) {
	  var i, a, main;
	  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
		// se verifica que sea una liga a una hoja de estilo ("...style..." y que además sea de tipografía ("font...")
		if(a.getAttribute("rel").indexOf("style") != -1)  {
		  a.disabled = true;
		  if(a.getAttribute("title") == title) a.disabled = false;
		}
	  }
	},
	
	// Método para obtener, de forma correcta según el navegador, una instancia del objeto XMLHTTP.
	getHTTPObject:function(){ 
		 var xmlhttp = null;
		 //Internet Explorer
		 try {
		 	xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
		 }
		 catch (e) {
		  	try {
		   		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		  	}
		  	catch (e) {
		   		xmlhttp = null;
		  	}
		 }
		 //Mozilla y Safari
		 if ((xmlhttp == null) && (typeof XMLHttpRequest != 'undefined')) {
		  	try {
		   		xmlhttp = new XMLHttpRequest();
		  	}
		  	catch (e) {
		  		xmlhttp = null;
		  	}
		 }
		 return xmlhttp;
	},
	
	// Función para reemplazar el contenido de un elemento con id=tagid por el contenido en el documento HTML 
	// cuya URL se debe espeficiar en contentURI
	replaceTagContents:function(tagId, contentURI){
		//Instanciamos el objeto de solicitud HTTP
		var xmlhttp = DOMhelp.getHTTPObject();
		if (xmlhttp != null) {
			//Establecemos el verbo y el URL
			xmlhttp.open("GET", contentURI, false);
			//Enviamos la solicitud. El código se bloquea hasta que se recibe la respuesta.
			xmlhttp.send(null);
			//Actualizamos el panel con la nueva cita
			document.getElementById(tagId).innerHTML = xmlhttp.responseText;
		} 
		//Reiniciamos el temporizador
		//timerID = window.setTimeout('UpdateQuotes()', 10000);
	},
	
	deleteTagContents:function(tagId){
		document.getElementById(tagId).innerHTML = "";
	},

	checkPageMode:function(){
		//Si el documento tiene el parámetro "mode=print" entonces se cambian los estilos de layers y tipografías para el modo de impresión
		if (document.URL.match("mode=print")){
			DOMhelp.setActiveLayerFontStyleSheets("layer-print","font-print");
			DOMhelp.clearHeaderNavbarFooter();
		}
	}
}