/************************************************************************
* IBZfield.js											 FECHA: 12-09-2002 *
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
* PROPOSITO : Define los objetos encargados de soportar la operacion	*
*	 general de los formularios en el Framework.
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
* AUTOR: Mauricio Mendez M.											 *
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
* id = "$Id: IBZAction.js,v 1.3 2009/01/19 16:18:56 GOYA\admingoya Exp $"
************************************************************************/

/*-----------------------------------------------------------------------
* DESCRIPCION:
*	 Construye un objeto de tipo Field en un formulario
* PARAMETROS:
*	 parentForm: Formulario al cual pertenece
*	 xmlDocument: Documento XML que define el campo
* RESULTADO:
*	 Construye un nuevo objeto
* PRE:
* POST:
* OJO: 
*-------------------------------------------------------------------- */
function Action( parentForm, xmlDocument, currentWidget )
{
	/********************************************************
			Declaracion de atributos del objeto				*
	*********************************************************/

	this.parentForm = parentForm;
	this.widget = null;
	this.XMLDocument = xmlDocument;
	this.actionId = new String();
	this.name = new String();
	this.security = new String();
	this.sectionTarget = new String();
	this.serverValidation = new String();
	this.requiredFields = new String();
	this.style = new String();
	this.visible = new String();
	this.description = new String();
	this.representation = new String();

	/********************************************************
	*		Declaracion de metodos del objeto				*
	********************************************************/

	//Metodos cargue general de atributos y cambio de estado
	this.LoadProperties = IBZForm_LoadProperties;
	this.ChangeState = IBZForm_ChangeStateAll;
	this.Update = IBZForm_Update;
	//Metodos para correr eventos
	this.clientValidationPre = null;
	this.clientValidationPost = null;
	//Metodo define metodos asociados a los eventos
	this.DefineEvents = IBZAction_DefineEvents;
	this.Validate = IBZAction_Validate;
	//Metodos cambio de estado
	this.Enable = IBZAction_Enable;
	this.Disable = IBZAction_Disable;
	this.Hide = IBZAction_Hide;
	this.Show = IBZAction_Show;

	/********************************************************
	*		Inicializacion del objeto						*
	*********************************************************/

	//Cargue de propiedades
	this.LoadProperties();
	//Cargue de objeto HTML
	if( currentWidget == null )
	{
		this.widget = document.getElementById( this.actionId );
	}
	else
	{
		this.widget = currentWidget;
	}

	if( this.widget == null )
	{
		//El campo no tiene un objeto correspondiente en la interfaz Html
		alert( "La accion " + this.actionId + " no tiene un objeto correspondiente en la interfaz Html" );
	}
	else
	{
		// Se definen los eventos sobre el widget asociado para ejecutar los procesos estandar 
		this.DefineEvents();

		//Cambia las propiedades del objeto segun el DDI
		this.ChangeState();

		//Se adiciona la seccion a las estructuras de datos de control de secciones
		parentForm.actionArray[ parentForm.actionArray.length ] = this;
		parentForm.actionAssocArray[ this.actionId ] = this;
	}
}

/*-----------------------------------------------------------------------
* DESCRIPCION:
*	 Se encarga de disparar los procesos de validacion del campo definidos
*	 a nivel del documento DDF
* PARAMETROS:
* RESULTADO:
*	 Se dispararon los procesos de validacion del campoo
* PRE:
* POST:
* OJO: 
*-------------------------------------------------------------------- */
function IBZAction_Validate()
{
	//Se verifica si el campo tiene un proceso de validacion asociado, para su ejecucion
	if( this.clientValidationPre != null || this.clientValidationPost != null || this.serverValidation == "yes" )
	{
		//Tiene funciones de validacion, se dispara el proceso desde el formulario
		this.parentForm.StartFieldValidation( this );
	}
}

/*-----------------------------------------------------------------------
* DESCRIPCION:
*	 Se encarga de verificar que todos los atributos esten correctamente
*	 diligenciados. 
* PARAMETROS:
* RESULTADO:
*	 Informa si el campo esta correctamente definido
* PRE:
* POST:
* OJO: 
*-------------------------------------------------------------------- */
function IBZAction_DefineEvents()
{
	/********************************************************
	*		Inicializacion de eventos para el objeto		*
	*********************************************************/

	this.widget.onclick = actionValidate;
}

/*-----------------------------------------------------------------------
* DESCRIPCION:
*	 Desactiva la edición del campo, impidiendo que sea modificado por
*	 el usuario desde la interfaz
* PARAMETROS:
*	 None
* RESULTADO:
*	 None
* PRE:
* POST:
* OJO: 
*-------------------------------------------------------------------- */
function IBZAction_Enable()
{
	this.widget.disabled = false;
}

/*-----------------------------------------------------------------------
* DESCRIPCION:
*	 Desactiva la edición del campo, impidiendo que sea modificado por
*	 el usuario desde la interfaz
* PARAMETROS:
*	 None
* RESULTADO:
*	 None
* PRE:
* POST:
* OJO: 
*-------------------------------------------------------------------- */
function IBZAction_Disable()
{
	this.widget.disabled = true;
}

/*-----------------------------------------------------------------------
* DESCRIPCION:
*	 Desactiva la edición del campo, impidiendo que sea modificado por
*	 el usuario desde la interfaz
* PARAMETROS:
*	 None
* RESULTADO:
*	 None
* PRE:
* POST:
* OJO: 
*-------------------------------------------------------------------- */
function IBZAction_Hide()
{
	this.widget.style.display = "none";
}

/*-----------------------------------------------------------------------
* DESCRIPCION:
*	 Desactiva la edición del campo, impidiendo que sea modificado por
*	 el usuario desde la interfaz
* PARAMETROS:
*	 None
* RESULTADO:
*	 None
* PRE:
* POST:
* OJO: 
*-------------------------------------------------------------------- */
function IBZAction_Show()
{
	this.widget.style.display = "";
}


/*-----------------------------------------------------------------------
* DESCRIPCION:
*	 Dispara el proceso de validacion del objeto textField
* PARAMETROS:
*	 none
* RESULTADO:
*	 El campo se valido de acuerdo con el proceso estandar de validacion
* PRE:
* POST:
* OJO: 
*-------------------------------------------------------------------- */
function actionValidate()
{
	var actionObject = null;

	actionObject = window.actionAssocArray[ this.id ]

	return actionObject.Validate();
}

