/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/*	<MAIN SCRIPTS>																							*/
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/

	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------DETECCION DE INTERNET EXPLORER COMO NAVEGADOR CLIENTE.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		// Presencia del sting "MSIE" en la propiedad navigator.userAgent.
	var ie = navigator.userAgent.indexOf("MSIE");
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/	
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------FUNCION $ = getElementByID
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function $() {
	  var elements = new Array();
	
	  for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
		  element = document.getElementById(element);
	
		if (arguments.length == 1)
		  return element;
	
		elements.push(element);
	  }
	
	  return elements;
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------ADD EVENT HANDLER.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function addEventHandler(oElement, sEvent, fFunction, bCapture){
			// SI LA VARIABLE ie ES DIFERENTE DE -1, Y SI EXISTE window.event EL NAVEGADOR ES INTERNET EXPLORER.
		if(ie != -1 && typeof(window.event) != "undefined"){
			oElement.attachEvent("on" + sEvent, fFunction);
			
			// PARA LOS NAVEGADORES DOM LEVEL 2.
		}else{
			oElement.addEventListener(sEvent, fFunction, bCapture)
		}
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------REMOVE ADD EVENT HANDLER.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function removeEventHandler(oElement, sEvent, fFunction, bCapture){
		if(ie != -1 && typeof(window.event) != "undefined"){
			oElement.detachEvent("on" + sEvent, fFunction);
		}else{
			oElement.removeEventListener(sEvent, fFunction, bCapture)
		}
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------GET EVENT TARGET.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function getEventTarget(evt){
		if(ie != -1 && window.event != null){
			return window.event.srcElement;
		}else{
			return evt.target;
		}
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------STOP EVENT.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function stopEvent(evt){
		if(ie != -1){
			window.event.cancelBubble = true;
		}else{
			evt.stopPropagation();
		}
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------FUNCION QUE CREA LA INSTANCIA DE XMLHttpRequest.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
			// Función que crea la instancia de XMLHttpRequest.
	function getXMLHTTPRequest(){
			// En caso de que el navegador utilize el motor de Netscape
			// el objeto XMLHttpRequest está incluido en el DOM de JavaScript.
		try{req=new XMLHttpRequest();}
			// Si la operación de instanciación falla,
			// maneja el error intentando crear la instancia
			// para las versiones de MS Internet Explorer:
		catch(err1){
				// En caso de que sea una versión anterior.
			try{req=new ActiveXObject("Msxml2.XMLHTTP");}
			catch(err2){
					// Sintaxis para las nuevas versiones:
				try{req=new ActiveXObject("Microsoft.XMLHTTP");}
					// Si vuelve a fallar, 
					// devuelve falso como valor de la variable que debía contener la instancia.
				catch(err3){
					req=false;
					alert('NO HAY OBJETO XMLHttpRequest!');
				}	
			}	
		}
			// Si alguna de las anteriores tuvo éxito,
			// la nueva instancia estará almacenada en la variable req,
			// de la que ahora devuelve el valor.
		return req;
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------VARIABLE QUE ALMACENA LA INSTANCIA DEL OBJETO XMLHttpRequest.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		// Almacena el resultado de invocar a la función en una variable "http".
	var http=getXMLHTTPRequest();
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------VARIABLE QUE ALMACENARA EL ID DEL ARTICULO A MODIFICAR.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	var articleToModify = 0;
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------VARIABLE QUE ALMACENARA EL NOMBRE DE LA FILA DE LA TABLA A ELIMINAR.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	var rowToDelete = "";
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------VARIABLE QUE ALMACENARA EL NOMBRE DE LA CELDA CON EL LINK ELIMINAR.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	var currentAnchorDelete = "";	
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------VARIABLE QUE ALMACENARA EL NOMBRE DE LA CELDA CON EL ATRIBUTO 'PUBLIC'.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	var currentAttribPublic = "";
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------VARIABLE QUE ALMACENARA EL NOMBRE DE LA CELDA CON FECHA DE PUBLICACION.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	var currentDatePublished = "";
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------VARIABLE QUE ALMACENARA EL NOMBRE DE LA CELDA CON EL LINK 'PUBLICAR / OCULTAR'.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	var currentAnchorPublish = "";
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------FUNCION PARA ELIMINAR UN ARTICULO.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function deleteArticle(articleID){
			// Modifica el valor de la variable global, que almacena el id del articulo a modificar.
		articleToModify = articleID;
			// Obtiene el identificador de la fila de la tabla a eliminar.
		rowToDelete = "rowArticle" + articleToModify + "";
			// Obtiene el identificador de la casilla donde está el link "ELIMINAR" para el artículo actual.
		currentAnchorDelete = "delete" + articleToModify + "";
			// Obtiene el parámetro adicional, correspondiente al string de fecha y hora.
		var cdata = getStringDate();
			// URL DEL SCRIPT DEL SERVIDOR.
		var scriptURL = "../scripts/publishDelete.php";
			// URL DEL SCRIPT CON LOS PARAMETROS $_GET AGREGADOS.
		var modalURL = scriptURL + "?action=delete&article=" + articleID + "&cdata=" + cdata;
			// PETICION EN CONCRETO AL SERVIDOR.
		http.open("GET", modalURL, true);
			// INDICA LA FUNCION A UTILIZAR AL MOMENTO DE CAMBIAR EL VALOR DE LA PROPIEDAD READYSTATE.
		http.onreadystatechange = responseDelete;
			// COMO SE USA EL METODO GET, SE LE PASA AL METODO SEND EL ARGUMENTO NULL.
		http.send(null);
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------FUNCION DE RESPUESTA A LA ELIMINACION DE UN ARTICULO.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function responseDelete(){		
		if(http.readyState == 4){
			if(http.status == 200){		
					// Obtiene el resultado de los nodos XML.
				var serverResponse = http.responseXML.getElementsByTagName("deleted")[0].childNodes[0].nodeValue;
				var resultsQty = http.responseXML.getElementsByTagName("qty")[0].childNodes[0].nodeValue;
					// Si la respuesta del servidor indica que la consulta tuvo éxito.
				if(serverResponse == "OK"){
						// Actualiza los datos en el encabezado.
					$("headline").innerHTML = "<h4>" + resultsQty + " Art&iacute;culo(s) en la base de datos.</h4>";
						// Elimina la fila de la tabla.
					$(rowToDelete).parentNode.removeChild($(rowToDelete));
					articleToModify = 0;
					rowToDelete = 0;
					// Si la respuesta fue un fallo en la consulta.
				}else{
						// Muestra el fallo en el encabezado.
					$("headline").innerHTML = "<h4>NO SE HA PODIDO EFECTUAR TU PETICION.</h4>";
				}
			}
			// Mientras tanto, muestra la imagen en el link que recibió el evento.
		}else{
			$(currentAnchorDelete).innerHTML = "<img src='../images/balls49.gif' />";
		}
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------FUNCION PARA PUBLICAR UN ARTICULO.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function publishArticle(articleID){
			// Modifica el valor de la variable global, que almacena el id del articulo a modificar.
		articleToModify = articleID;
			// Obtiene el identificador para el atributo 'public' para el artículo actual.
		currentAttribPublic = "public" + articleToModify + "";
			// Obtiene el identificador de la casilla donde está el link "PUBLICAR / OCULTAR" para el artículo actual.
		currentAnchorPublish = "publish" + articleToModify + "";
			// Obtiene el identificador de la casilla donde está la fecha de publicación para el artículo actual.
		currentDatePublished = "published" + articleToModify + "";
			// Obtiene el parámetro adicional, correspondiente al string de fecha y hora.
		var cdata = getStringDate();
			// URL DEL SCRIPT DEL SERVIDOR.
		var scriptURL = "../scripts/publishDelete.php";		
			// URL DEL SCRIPT CON LOS PARAMETROS $_GET AGREGADOS.
		var modalURL = scriptURL + "?action=publish&article=" + articleID + "&cdata=" + cdata;
			// PETICION EN CONCRETO AL SERVIDOR.
		http.open("GET", modalURL, true);
			// INDICA LA FUNCION A UTILIZAR AL MOMENTO DE CAMBIAR EL VALOR DE LA PROPIEDAD READYSTATE.
		http.onreadystatechange = responsePublish;
			// COMO SE USA EL METODO GET, SE LE PASA AL METODO SEND EL ARGUMENTO NULL.
		http.send(null);
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------FUNCION DE RESPUESTA A LA PUBLICACION DE UN ARTICULO.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function responsePublish(){		
		if(http.readyState == 4){
			if(http.status == 200){		
					// Obtiene la respuesta del servidor referente al atributo 'public' del artículo.
				var publicAttribute = http.responseXML.getElementsByTagName("public")[0].childNodes[0].nodeValue;
					// Obtiene la respuesta del servidor referente al atributo 'public' del artículo.
				var publishedDate = http.responseXML.getElementsByTagName("published")[0].childNodes[0].nodeValue;
					// Traduce al formato de la tabla el string de fecha devuelto por la base de datos.
				var sDate = getDateParagraph(publishedDate);
					// Si la respuesta del servidor indica que la consulta tuvo éxito.
				if(publicAttribute != "FAILED"){
					$(currentAttribPublic).innerHTML = "<img src='../images/signPublic.jpg' />";//"<b>SI</b>";
					$(currentDatePublished).innerHTML = sDate;
					$(currentAnchorPublish).innerHTML = "<a href=\"#\" onclick=\"hideArticle('" + articleToModify + "')\">OCULTAR</a>";
					currentAttribPublic = "";
					currentDatePublished = "";
					currentAnchorPublish = "";
				}else{
						// Muestra el fallo en el encabezado.
					$("headline").innerHTML = "<h4>NO SE HA PODIDO EFECTUAR TU PETICION.</h4>";
				}
			}
			// Mientras tanto, muestra la imagen en el link que recibió el evento.
		}else{			
			$(currentAnchorPublish).innerHTML = "<img src='../images/balls49.gif' />";
		}
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------FUNCION PARA OCULTAR UN ARTICULO.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function hideArticle(articleID){
			// Modifica el valor de la variable global, que almacena el id del articulo a modificar.
		articleToModify = articleID;
			// Obtiene el identificador para el atributo 'public' para el artículo actual.
		currentAttribPublic = "public" + articleToModify + "";
			// Obtiene el identificador de la casilla donde está la fecha de publicación para el artículo actual.
		currentDatePublished = "published" + articleToModify + "";
			// Obtiene el identificador de la casilla donde está el link "PUBLICAR / OCULTAR" para el artículo actual.
		currentAnchorPublish = "publish" + articleToModify + "";
			// Obtiene el parámetro adicional, correspondiente al string de fecha y hora.
		var cdata = getStringDate();
			// URL DEL SCRIPT DEL SERVIDOR.
		var scriptURL = "../scripts/publishDelete.php";
			// URL DEL SCRIPT CON LOS PARAMETROS $_GET AGREGADOS.
		var modalURL = scriptURL + "?action=hide&article=" + articleID + "&cdata=" + cdata;
			// PETICION EN CONCRETO AL SERVIDOR.
		http.open("GET", modalURL, true);
			// INDICA LA FUNCION A UTILIZAR AL MOMENTO DE CAMBIAR EL VALOR DE LA PROPIEDAD READYSTATE.
		http.onreadystatechange = responseHide;
			// COMO SE USA EL METODO GET, SE LE PASA AL METODO SEND EL ARGUMENTO NULL.
		http.send(null);
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------FUNCION DE RESPUESTA AL OCULTAR UN ARTICULO.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function responseHide(){		
		if(http.readyState == 4){
			if(http.status == 200){		
					// Obtiene la respuesta del servidor referente al atributo 'public' del artículo.
				var publicAttribute = http.responseXML.getElementsByTagName("public")[0].childNodes[0].nodeValue;
				if(publicAttribute == "NO" && publicAttribute != "FAILED"){
					$(currentAttribPublic).innerHTML = "<img src='../images/signPrivate.jpg' />";//"<b>NO</b>";
					$(currentDatePublished).innerHTML = "<img src='../images/signPrivate.jpg' />";//"<b>X</b>";
					$(currentAnchorPublish).innerHTML = "<a href=\"#\" onclick=\"publishArticle('" + articleToModify + "')\">PUBLICAR</a>";
					currentAttribPublic = "";
					currentDatePublished = "";
					currentAnchorPublish = "";
				}else{
						// Muestra el fallo en el encabezado.
					$("headline").innerHTML = "<h4>NO SE HA PODIDO EFECTUAR TU PETICION.</h4>";
				}
			}
			// Mientras tanto, muestra la imagen en el link que recibió el evento.
		}else{
			$(currentAnchorPublish).innerHTML = "<img src='../images/balls49.gif' />";
		}
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------FUNCION QUE DEVUELVE UN STRING DE FECHA Y HORA COMPLETO "YYYYMMDDHHMMSS".
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function getStringDate(){
			// Crea instancia del objeto Date, con la hora actual.
		var currentDate = new Date();
			// Número original de Año.
		var origYear = currentDate.getFullYear();
			// Número original de mes (del 0 al 11).
		var origMonth = (currentDate.getMonth() + 1);
			// Número original de día (del 1 al 31).
		var origDate = currentDate.getDate();
			// Número original correspondiente a la hora.
		var origHour = currentDate.getHours();
			// Número original correspondiente a los minutos.
		var origMinutes = currentDate.getMinutes();
			// Número original correspondiente a los segundos.
		var origSeconds = currentDate.getSeconds();
			// Strings correspondientes al año, mes, día, hora, minutos, y segundos.
		var currentStringYear = currentDate.getFullYear() + "";
		var currentStringMonth = "";
		var currentStringDate = "";
		var currentStringHours = "";
		var currentStringMinutes = "";
		var currentStringSeconds = "";
			// Puebla el string correspondiente al mes.
		if(origMonth < 10){
			currentStringMonth = "0" + origMonth + "";
		}else{
			currentStringMonth = origMonth + "";
		}		
			// Puebla el string correspondiente al día del mes.
		if(origDate < 10){
			currentStringDate = "0" + origDate + "";
		}else{
			currentStringDate = origDate + "";
		}
			// Puebla el string correspondiente a la hora.
		if(origHour < 10){
			currentStringHours = "0" + origHour + "";
		}else{
			currentStringHours = origHour + "";
		}
			// Puebla el string correspondiente a los minutos.
		if(origMinutes < 10){
			currentStringMinutes = "0" + origMinutes + "";
		}else{
			currentStringMinutes = origMinutes + "";
		}
			// Puebla el string correspondiente a los segundos.
		if(origSeconds < 10){
			currentStringSeconds = "0" + origSeconds + "";
		}else{
			currentStringSeconds = origSeconds + "";
		}		
			// Crea el string que concatena los strings anteriores.
		var stringTimeReturn = currentStringYear + currentStringMonth + currentStringDate + currentStringHours + currentStringMinutes + currentStringSeconds;
			// Devuelve el string creado.
		return(stringTimeReturn);			
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------FUNCION QUE DEVUELVE EL TEXTO PARA INSERTAR EN LA CELDA PUBLISHED A PARTIR DEL STRING.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function getDateParagraph(stringToFormat){
		var stringYear = "";
		var stringMonth = "";
		var stringDate = "";
		var stringMiddle = "<hr />";
		var stringHourMin = "";
		var stringFinal = " Hs.";
		for(var i=0; i<4; i++){
			stringYear += stringToFormat.charAt(i);
		}
		for(var j=5; j<7; j++){
			stringMonth += stringToFormat.charAt(j);
		}
		for(var k=8; k<10; k++){
			stringDate += stringToFormat.charAt(k);
		}
		for(var l=11; l<16; l++){
			stringHourMin += stringToFormat.charAt(l);
		}
		var finalString = stringDate + "/" + stringMonth + "/" + stringYear + stringMiddle + stringHourMin + stringFinal;
		return(finalString);
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------FUNCION QUE CAMBIA LA INFORMACION EN EL FORMULARIO, EN LO REFERENTE A LA IMAGEN ASOCIADA.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function changeImageLink(){
			// Cambia el párrafo en el formulario, para indicar que el artículo no tiene imagen asociada.
		$("labelImage").innerHTML = "";
		$("labelImage").innerHTML += "<p class='imageP'>"
								  + "El art&iacute;culo no tiene una imagen asociada."
								  + "<br />"
								  + "Puede seleccionar una imagen pulsando el bot&oacute;n."
								  + "</p>";
			// Cambia el valor del campo oculto,
			// para indicar que se ha borrado la imagen originalmente asociada.
		$("deletedImage").value = "true";
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------FUNCIONES Y GESTORES ESPECIFICOS PARA GESTION DE TABLAS.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		//-------------FUNCION QUE ASIGNA UNA REGLA DE ESTILO DIFERENTE A LAS FILAS PARES E IMPARES DE LA TABLA.
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		function stripeTable(oTable){	
			var table = $(oTable);
			var tBody = table.getElementsByTagName("tbody")[0];
			var aTRs = tBody.getElementsByTagName("tr");
			for(var i = 0; i < aTRs.length; i++){
					// Si al dividir por 2 el contador se obtiene un módulo 1,
					// se aplica la clase "noun" (impar). Si no, la clase double (par).
				aTRs[i].className = (i % 2 == 1) ? "noun" : "double";
			}
		}
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		//-------------FUNCION QUE AÑADE GESTORES PARA EVENTOS DEL MOUSE SOBRE LAS FILAS DEL BODY DE LA TABLA.
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		function hiliteTable(oTable){
				// OBTIENE LA REFERENCIA A LA TABLA.
			var table = $(oTable);
				// SELECCIONA EL BODY DE LA TABLA.
			var tBody = table.getElementsByTagName("tbody")[0];
			
				// OBTIENE EL ARRAY DE FILAS DENTRO DEL BODY DE LA TABLA.
			var aTRs = tBody.getElementsByTagName("tr");
				// ASIGNA GESTORES DE EVENTOS PARA CADA UNA DE LAS FILAS DEL BODY DE LA TABA.
			for(var i = 0; i < aTRs.length; i++){
				addEventHandler(aTRs[i], "mouseover", rowOver, false);
				addEventHandler(aTRs[i], "mouseout", rowOut, false);
				addEventHandler(aTRs[i], "click", rowDown, false);		
			}
		}
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		//-------------GESTORES PARA EVENTOS DEL MOUSE SOBRE LAS FILAS DEL <TBODY> DE LA TABLA.
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
			/*///////////////////////////////////////////*/
			// FUNCION GESTORA DEL EVENTO MOUSEOVER.
			/*///////////////////////////////////////////*/
		function rowOver(evt){
				// EL EVENTO SE ORIGINA EN LA CELDA POR LO TANTO, SE ASIGNA LA VAR TARGET AL PARENT-NODE (FILA).
			var target = getEventTarget(evt).parentNode;
				// Referencia al tbody.
			var tBody = target.parentNode;
				// Referencia a la tabla en sí.
			var table = tBody.parentNode;
				// ASIGNA PROPIEDADES, MIENTRAS LA FILA NO SE ENCUENTRE RESALTADA.
			if(target.id != table.currentHilitedRow){
				table.currentOverRow = target.id;
				target.style.backgroundColor = "#df0";
			}
			return false;
		}
			/*///////////////////////////////////////////*/
			// FUNCION GESTORA DEL EVENTO MOUSEOUT.
			/*///////////////////////////////////////////*/
		function rowOut(evt){
				// EL EVENTO SE ORIGINA EN LA CELDA POR LO TANTO, SE ASIGNA LA VAR TARGET AL PARENT-NODE (FILA).
			var target = getEventTarget(evt).parentNode;
				// Referencia al tbody.
			var tBody = target.parentNode;
				// Referencia a la tabla en sí.
			var table = tBody.parentNode;
				// QUITA VALORES A LAS PROPIEDADES, MIENTRAS LA FILA NO SE ENCUENTRE RESALTADA.
			if(target.id != table.currentHilitedRow){
				target.style.backgroundColor = "";
			}
			return false;
		}
			/*///////////////////////////////////////////*/
			// FUNCION GESTORA DEL EVENTO CLICK.
			/*///////////////////////////////////////////*/
		function rowDown(evt){
				// EL EVENTO SE ORIGINA EN LA CELDA POR LO TANTO, SE ASIGNA LA VAR TARGET AL PARENT-NODE (FILA).
			var target = getEventTarget(evt).parentNode;
				// Referencia al tbody.
			var tBody = target.parentNode;
				// Referencia a la tabla en sí.
			var table = tBody.parentNode;
				// SI ACTUALMENTE UNA FILA RESALTADA, LE QUITA VALOR A SUS PROPIEDADES.
			if(table.currentHilitedRow != null){
				$(table.currentHilitedRow).style.backgroundColor = "";
				$(table.currentHilitedRow).style.color = "";
					// SI LA FILA RESALTADA ES LA QUE RECIBE EL EVENTO CLICK,
					// SETEA COMO NULL LA FILA ACUTALMENTE RESALTADA, Y RETORNA.
				if(table.currentHilitedRow == target.id){
					table.currentHilitedRow = null;
					return false;
				}
					// SI HABIENDO UNA FILA RESALTADA, 
					// LA FILA QUE RECIBE EL EVENTO CLICK ES LA FILA QUE RECIBIO EL EVENTO MOUSEOVER,
					// NEUTRALIZA LOS VALORES DE LAS PROPIEDADES ASIGNADOS POR EL EVENTO MOUSEOVER.
				if(table.currentOverRow == target.id){
					$(table.currentOverRow).style.backgroundColor = "";
					$(table.currentOverRow).style.color = "";
				}
			}
				// UNA VEZ NEUTRALIZADO CUALQUIER EVENTO ANTERIOR, ASIGNA VALORES A LAS PROPIEDADES.
			table.currentHilitedRow = target.id;
			target.style.backgroundColor = "#00ccff";
			target.style.color = "#000";
			return false;
		}
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		//-------------FUNCION QUE REGISTRA EVENTOS CLICK PARA LAS CABECERAS.
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		function registerSortTable(oTable){
				// Referencia a la tabla a travez de la id.
			var table = $(oTable);
				// thead.
			var tHead = table.getElementsByTagName("thead")[0];
				// Array de cabeceras (<th>) dentro de <thead>.
			var aTHs = tHead.getElementsByTagName("th");
			
			for(var i=0; i<aTHs.length; i++){
					// ID de la cabecera.
				var columnID = aTHs[i].id;
					// Primer elemento dentro de la cabecera (anchor)
				var anchorID = $(columnID).firstChild.id;			
					// Añade un gestor de evento para cada columna.
				addEventHandler($(columnID), "click", sortTable, false);
			}
		}	
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		//-------------FUNCION QUE GESTIONA EL EVENTO CLICK SOBRE LAS CABECERAS DE LA TABLA.
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		function sortTable(evt){
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			// OBTIENE REFERENCIAS A LA CELDA CABECERA DONDE SE ORIGINA EL EVENTO.		
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
				// EL EVENTO SE ORIGINA EN EL ANCHOR DE LA CABECERA POR LO TANTO, LA CELDA CABECERA ES EL PARENT NODE.
			var th = getEventTarget(evt).parentNode;
				// REFERENCIA AL ID DE LA CELDA CABECERA.
			var thID = th.id;
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			// OBTIENE REFERENCIAS LA TABLA EN SI.		
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/			
				// El parentNode de <th> es la fila <tr>, el siguiente es <thead>, y el siguiente es <table>
			var table = $(thID).parentNode.parentNode.parentNode;
			var tableID = $(thID).parentNode.parentNode.parentNode.id;
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/	
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			// OBTIENE Y SETEA EL NUMERO DE COLUMNA POR LA QUE ORDENAR LA TABLA.
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
				// El prefijo utilizado para identificar las cabeceras,
				// contiene el nombre (id) de la tabla,
				// seguido del prefijo "th".
				// Por lo tanto, agregando 2 al largo del id de tabla, 
				// se obtiene el número a quitar del id de la cabecera th.
			var prefixLength = tableID.length + 2;
				// OBTIENE EL NUMERO DE COLUMNA POR LA QUE ORDENAR LA TABLA.
			var colNumber = thID.substring(prefixLength);
				// SETEA LA PROPIEDAD DE LA TABLA.
			table.sortColumn = colNumber;
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			// OBTIENE REFERENCIAS AL TBODY, Y UN ARRAY CON LAS FILAS INCLUIDAS.
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
				// SELECCIONA EL BODY DE LA TABLA.
			var tBody = table.getElementsByTagName("tbody")[0];
				// OBTIENE EL ARRAY DE FILAS DENTRO DEL BODY DE LA TABLA.
			var aTRs = tBody.getElementsByTagName("tr");
				// Cantidad de filas en la tabla.
			var rowsQty = aTRs.length;
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			// OBTIENE EL SENTIDO (DIRECCION) EN QUE SE DEBEN ORDERNAR LOS VALORES DE LA COLUMNA.
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			table.sortDirection = getSortDirection(table, colNumber);
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			// ORDENA LAS FILAS DEL <TBODY>.
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
				// Array para contener las filas ordenadas de la tabla.
			var aSortedRows = new Array(rowsQty);
			
				// Clona cada fila y la inserta como parte del nuevo array.
			for(var i=0; i<rowsQty; i++){ 
				aSortedRows[i] = aTRs[i].cloneNode(true); 
					// Añade a cada fila en el array un elemento asociativo, refiriendo a la tabla.
				aSortedRows[i]["table"] = table;
			}
			
				// Aplica el método de array "sort", pasando como argumento la función que ordena las filas.
			aSortedRows.sort(sortRows);
			
				// Una vez ordenado el array, remueve el elemento <tbody> de la tabla.
			table.removeChild(tBody);
			
				// Crea un nuevo elemento <tbody>.
			newBody = document.createElement("tbody");
			
				// Añade al nuevo <tbody> las filas del array ya ordenado.
			for(var j=0; j<rowsQty; j++){ newBody.appendChild(aSortedRows[j]); }
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			// AÑADE EL NUEVO TBODY A LA TABLA.
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
				// Añade el nuevo <tbody> a la tabla.
			table.appendChild(newBody);
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			// RESTAURA ESTILOS ALTERNADOS EN LAS FILAS DE LA TABLA.
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
				// Re-asigna estilos para alternar efecto visual de filas.
			stripeTable(table);
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			// RESTAURA GESTORES DE EVENTOS DEL MOUSE SOBRE LAS FILAS DE LA TABLA.
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
				// Re-asignar los eventos del mouse en Internet Explorer, 
				// provocaría que se ejecutaran varias veces los eventos a partir de aquí.
				// Por lo tanto sólo se reasignan los eventos si se trata de un navegador DOM-LEVEL 2.
			if(ie < 0){
				hiliteTable(table);
			}
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
			/*/////////////////////////////////////////////////////////////////////////////////////////////*/
		}
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		//-------------FUNCION QUE OBTIENE LA DIRECCION EN LA CUAL SE DEBEN ORDENAR LAS FILAS DE LA TABLA.
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		function getSortDirection(table, colNumber){
				// Si la tabla ya se encuentra ordenada según los valores de la columna, 
				// invierte el criterio de orden.
				// En caso contrario, indica orden ascendente.
			if(table.sortColumn == colNumber){
				if(table.sortDirection == "asc"){
					return "desc";	
				}else{
					return "asc";
				}
			}else{
				return "asc";
			}
		}
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		//-------------FUNCION UTILIZADA PARA ORDENAR LAS FILAS DE LA TABLA SEGUN UNA DIRECCION.
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		function sortRows(elementA, elementB){
			var table = $(elementA["table"]);
			var sortColumn = table.sortColumn;
			var sortDirection = table.sortDirection;
				// Cada argumento corresponde a una fila del array de filas clonadas.
				// Obtiene las celdas de la columna pulsada, para cada elemento-fila.
			var value1 = elementA.getElementsByTagName("td")[sortColumn];
			var value2 = elementB.getElementsByTagName("td")[sortColumn];
				// Obtiene los valores del texto dentro de las celdas.
			var textValue1 = value1.firstChild.data;
			var textValue2 = value2.firstChild.data;
			//************************************************************************************************//
			// COMPRUEBA SI EL VALOR NO ES UN NUMERO, Y ORDENA SEGUN EL CASO.
			//************************************************************************************************//
			//************************************************************************************************//
				//--------------->SI EL VALOR ES UN NUMBERO.
			if(Number(textValue1)){
				if(Number(textValue1) > Number(textValue2)){
					if(sortDirection == "asc"){
						return -1;
					}else{
						return 1;
					}
				}else if(Number(textValue1) < Number(textValue2)){
					if(sortDirection == "asc"){
						return 1;
					}else{
						return -1;
					}
				}
				//--------------->SI EL VALOR ES UN STRING DE TEXTO.
			}else{			
					// Ordena las filas según el valor de texto obtenido.
					// SI EL PRIMER VALOR ES MAYOR QUE EL SEGUNDO.
				if(textValue1 > textValue2){
						// EN CASO DE QUE EL ORDEN DESEADO SEA ASCENDENTE.
					if(sortDirection == "asc"){
						return -1;
						// SI EL ORDEN ES DESCENDENTE.
					}else{
						return 1;
					}
					// SI EL PRIMER VALOR ES MENOR QUE EL SEGUNDO.
				}else if(textValue1 < textValue2){
						// SI LA DIRECCION ES ASCENDENTE.
					if(sortDirection == "asc"){
						return 1;
						// SI LA DIRECCION ES DESCENDENTE.
					}else{
						return -1;
					}
					// SI LOS VALORES SON EQUIVALENTES.
				}else{
					return 0;
				}			
			}
			//************************************************************************************************//
			//************************************************************************************************//
		}
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		//-------------FUNCION QUE ASIGNA UN ID A CADA CELDA DE LA CABECERA Y A CADA FILA DEL CUERPO DE LA TABLA.
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		function initTable(oTable){
			/////////////////////////////////////////////////////////
			// REFERENCIAS A LOS ELEMENTOS DE LA TABLA.
			/////////////////////////////////////////////////////////
			/////////////////////////////////////////////////////////
				// Referencia a la tabla por id.
			var table = $(oTable);
				// Referencia a <thead>
			var tHead = table.getElementsByTagName("thead")[0];
				// Referencia a <tbody>
			var tBody = table.getElementsByTagName("tbody")[0];
				// Array de cabeceras (<th>) dentro de <thead>.
			var aTHs = tHead.getElementsByTagName("th");
				// Array de filas dentro de <tbody>
			var aTRs = tBody.getElementsByTagName("tr");
			/////////////////////////////////////////////////////////
			/////////////////////////////////////////////////////////
			// ASIGNA ID A CADA ELEMENTO DE LA TABLA.
			/////////////////////////////////////////////////////////
			/////////////////////////////////////////////////////////
				// Asigna id a cada celda <th> dentro de <thead>
			for(var i=0; i<aTHs.length; i++){ aTHs[i].id = oTable + "th" + i; }
				// Asigna id a cada fila <tr> dentro de <tbody>.
			for(var j=0; j<aTRs.length; j++){ aTRs[j].id = oTable + "tr" + j; }
			/////////////////////////////////////////////////////////
			/////////////////////////////////////////////////////////
			// ASIGNA NUEVAS PROPIEDADES A LA TABLA.
			/////////////////////////////////////////////////////////
			/////////////////////////////////////////////////////////
				// Añade atributos globales a la tabla.
			table.setAttribute("currentHilitedRow", null);
			table.setAttribute("currentOverRow", null);
			table.setAttribute("sortColumn" , null);
			table.setAttribute("sortDirection", "asc");
			/////////////////////////////////////////////////////////
			/////////////////////////////////////////////////////////
			// INVOCA LAS FUNCIONES.
			/////////////////////////////////////////////////////////
			/////////////////////////////////////////////////////////
			stripeTable(oTable);
			hiliteTable(oTable);
			registerSortTable(oTable);
			/////////////////////////////////////////////////////////
			/////////////////////////////////////////////////////////
		}
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
		/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	//-------------FUNCIONES Y GESTORES ESPECIFICOS PARA LA GESTION DEL ACORDEON EN LA PAGINA DE LOGS.
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	function registerLogLinks(){
		if($("tableLogin")){
			initTable("tableLogin");
			addEventHandler($("linkLogin"), "click", expandLogin, false);
		}
		if($("tableIntrussion")){
			initTable("tableIntrussion");
			addEventHandler($("linkIntrussion"), "click", expandIntrussion, false);
		}
	}	
		// VARIABLES BOOLEAN INDICANDO EL ESTADO DE APERTURA DE CADA ELEMENTO DEL ACORDEON.
	var expLogin = false;
	var expIntrussion = false;	
		// FUNCIONES GESTORAS DEL EVENTO CLICK PARA CADA ELEMENTO DEL ACORDEON.
	function expandLogin(){
		if(expLogin == false){
			$("loginLogDiv").style.display = "block"; 
			$("linkLogin").innerHTML = "&lt;&lt; REGISTRO DE SESIONES";
			$("linkLogin").className = "linkActive";
			expLogin = true;
		}else{
			$("loginLogDiv").style.display = "none";
			$("linkLogin").innerHTML = "&gt;&gt; REGISTRO DE SESIONES";
			$("linkLogin").className = "linkLogs";
			expLogin = false;
		}
	}
	function expandIntrussion(){
		if(expIntrussion == false){
			$("intrussionLogDiv").style.display = "block"; 
			$("linkIntrussion").innerHTML = "&lt;&lt; REGSITRO DE INTRUSIONES";
			$("linkIntrussion").className = "linkActive";
			expIntrussion = true;
		}else{
			$("intrussionLogDiv").style.display = "none"; 
			$("linkIntrussion").innerHTML = "&gt;&gt; REGSITRO DE INTRUSIONES";
			$("linkIntrussion").className = "linkLogs";
			expIntrussion = false;
		}
	}
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
	
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/
/*	</MAIN SCRIPTS>																							*/
/*//////////////////////////////////////////////////////////////////////////////////////////////////////////*/