/*Tecknosfera DBNET S.L.
	Element: LIB PROTOS
	Programed by: francisco_javier_martinez AT hotmail DOT com
	To : Tecknosfera DBNET S.L.
*/


// "Clase LIB_PROTOS "
function LIB_PROTOS_object(theNavigator)
{
	var casos = false;
	// *******************************************************************************************************
	// ********* LIST Functions ******************************************************************************
	// *******************************************************************************************************
	
	this.go_to = function (theAction, objReferer)
	{
		var theForm = LIB_PROTOS.findForm (objReferer);
		
		// comprobamos si es una accion de eliminar
		if (theAction.match("eliminar") || theAction.match("erase") || theAction.match("cerrar"))
		{
			if (theAction.match("eliminar") || theAction.match("erase"))
			{
				accion = "eliminar";
			}
			else
			{
				if (theAction.match("cerrar"))
				{
					accion = "cerrar";
				}
			}			
	
			// pedimos confirmacion
			if (confirm("¿Está seguro de que desea "+accion+"?"))
			{
				LIB_PROTOS.setAction(theAction, theForm);
				LIB_PROTOS.send_form(theForm);
			}
		}
		else
		{
			LIB_PROTOS.setAction(theAction, theForm);
			LIB_PROTOS.send_form(theForm);
		}
	}

	this.setAction = function (theAction, theForm)
	{
		theForm.action = theAction;
		return(true);
	}

	this.send_form = function (theForm)
	{
		theForm.submit();
	}

	this.order_form = function (field, order, objReferer)
	{
		var theForm = LIB_PROTOS.findForm (objReferer);
		// editamos los campos
		theForm["order_field"].value = field;
		theForm["order_order"].value = order;
		
		LIB_PROTOS.send_form(theForm);
	}

	this.reload_page = function (page_index, page_elements, objReferer)
	{
		var theForm = LIB_PROTOS.findForm (objReferer);
		theForm["page_index"].value = page_index;
		theForm["page_elements"].value = page_elements;
		
		LIB_PROTOS.send_form(theForm);
		
		return(true);
	}
	
	// Función para encontrar el Formulario que contiene el elemento que estamos pulsando
	this.findForm = function (objReferer)
	{
		var theForm = document.forms[0]; // Predefinimos un formulario
		// Si hay un objeto de referencia...
		if (objReferer)
		{
			var elem = objReferer
			while (elem.parentNode && elem.tagName.toLowerCase() != "form")
			{
				elem = elem.parentNode;
				// alert (elem + "    " + elem.tagName + "     " + elem.name);
			}
			if (elem.tagName && elem.tagName.toLowerCase() == "form")
			{
				theForm = elem;
			}
			else
			{
				alert ("Al PAGINADOR debe contenerlo un Formulario");
			}
		}
		
		return (theForm);
	}
}

// Creamos un objeto de la clase LIB_PROTOS
var LIB_PROTOS = new LIB_PROTOS_object();

