/**
 *  Copyright (c) 2006 Elvis Navarro Vega ( http://www.unipamplona.edu.co )
 *	@autor: Ing Elvis Navarro Vega
 *  @email: elvisnv@unipamplona.edu.co 
 *	Grupo de Desarrollo Plataforma - Universidad de Pamplona.
 *  Grupo de Trabajo Hermesoft 
 *  Plataforma - Vicerrectoria de Gestion y Desarrollo Tecnologico
 *	Pamplona, Norte de Santander. Colombia.
 *	Mayo del 2007
 *	@descripcion :	framework sobre js para la validacion de los campos de un formulario, 
 *					este framework requiere de la inclusion de hmsgeneral.
 *
 */

hms = window.hms || {} ;

/**
 * Maneja las funciones de validacion de los campos de un formulario.
 * En esta version falta la implementación de la validacion de los check
 * de los options e incrementar la de comparacion a varios parametros
 */
hmsvalidator = hms.validator = new Object () ;
hms.validator.form 	 = null ;
hms.validator.message = null ;

/**
 * inicia el proceso de validacion y devuelve el posible mensaje que se haya capturado
 * @param form, contiene el nombre del formulario que se ha de analizar
 * @return message, cadena de mensaje de error formada, null en caso de que no hayan errores
 */
hms.validator.init = function ( form ) {
	this.message 	= null ;	
	this.form 		= ( typeof form == 'string' ? $( form ) : form ) ;
	var elements	= hms.form.getElements ( form ) ; 
	if ( !this.validateOnlyForm () )
		this.elements ( elements ) ;
	this.validateForm () ;
	return ( this.message ) ;
} ;

/**
 * Recorre cada uno de los elementos del formulario y chequea si debe ser analizado.
 * @param elements, contiene la lista de elementos de un formulario
 */
hms.validator.elements = function ( elements ) {
	for ( var i = 0; i < elements.length; i ++ ) {
		var hmsvalidate = elements [ i ].getAttribute ( 'hmsvalidate' ) ;
		if ( hmsvalidate != null ) {
			hmsvalidate = this.object ( hmsvalidate ) ;
			this.properties ( elements [ i ], hmsvalidate ) ;
		}
	}
} ;

/**
 * Analiza cada una de las propiedades de los elementos del formulario
 * ejecuta la validacion de cada una de ellas e instancia los posibles errores
 * que se puedan presentar.
 * @param object, contiene el elemento del formulario que se desee analizar.
 * @param properties, contiene las propiedades del elemento que se han de validar
 */
hms.validator.properties = function ( object, properties ) {
	var s = $( object.id ).value ; 
	
	for ( var i = 0; i < properties.length; i ++ ) {
		var propertie = properties [ i ] ;
		
		switch ( propertie.type ) {
			case 'required' :
				if ( s.isEmpty () ) 
					this.setInstanceMessage ( object.id, propertie ) ;
				break ;
				
			case 'shared' :
				var shared = propertie.shared ;
				shared [ shared.length ] = object.id ;
				this.processShared ( shared, propertie ) ;
				break ;
				
			case 'integer' :
			case 'flotante' :
				
				if ( ! s.isEmpty () ) {
					var t = propertie.type.substring ( 0, 1 ).toUpperCase() + propertie.type.substring ( 1, propertie.type.length ) ;
					var str	= " if ( ! s.is" + t + " () ) " +
							  "		this.setInstanceMessage ( object.id, propertie ) ;" + 	
							  " else { " +
							  //"		this.compare ( object.id, propertie ) ;" + 
							  "		this.toCompare ( object.id, propertie ) ;" + 
							  "		this.range ( object.id, propertie ) ;" + 
							  //"		this.processRange ( object.id, propertie ) ;" + 
							  "	} " ;
					eval ( str ) ;				  
				}
				break ;
				
			case 'minlength' :
			case 'maxlength' :
				var count = Number ( propertie.count ) ;
				if ( ! s.isEmpty () ) {
					var operator = propertie.type == 'minlength' ? '<' : '>' ;
					var str	= " if ( hms.field.length ( object.id ) " + operator + " count ) { " +
							  "		propertie.message != null ? this.setMessage ( propertie.message ) :" +  
					 		  "				this.setMessage ( '" + propertie.type + "', { hmsid: object.id, hmscount: count } ) ;" +
							  " } " ;
					eval ( str ) ;		  
				}
				break ;
				
			case 'depends' :
				var depends = propertie.depends ;
				if ( s.isEmpty () ) 
					this.processDepends ( object.id, depends, propertie ) ;
				break ;

			case 'list' :
				if ( s.isEmpty () ) 
					propertie.message != null ? this.setMessage ( propertie.message ) :
									this.setMessage ( 'list' ) ;						
				break ;
				
			case 'email' :
				if ( ! s.isEmpty() ) 
					if ( ! s.isEmail() ) 
						this.setInstanceMessage ( object.id, propertie ) ;
				break ;
			
			case 'time' :
				if ( ! s.isEmpty() ) {
					if ( ! s.isTime() ) 	
						this.setInstanceMessage ( object.id, propertie ) ;
					else
						this.toCompare ( object.id, propertie ) ;
					//this.compare ( object.id, propertie ) ;
				}
				break ;

			case 'date' :
				if ( ! s.isEmpty() ) {
					if ( ! s.isDate() )	
						this.setInstanceMessage ( object.id, propertie ) ;
					else {
						if ( ! this.processDate ( $( object.id ).value ) ) 
							this.setInstanceMessage ( object.id, propertie ) ;
						else {
							this.toCompare ( object.id, propertie ) ;	
							//this.compare ( object.id, propertie ) ;
							this.range ( object.id, propertie ) ;
						}
					} 
						
				}
				break ;

			case 'datetime' :
				if ( ! s.isEmpty () ) {
					if ( ! s.isDateTime () ) {	
						this.setInstanceMessage ( object.id, propertie ) ;
					} else {
						var adate = $( object.id ).value.split ( ' ' ) ;
						if ( ! this.processDate ( adate [ 0 ] ) ) {
							propertie.type = 'date' ;
							this.setInstanceMessage ( object.id, propertie ) ;
						} else 
							this.toCompare ( object.id, propertie ) ;
						//this.compare ( object.id, propertie ) ;
					}
				}
				break ;
				
			case 'string' :
				if ( !s.isEmpty () ) {
					if ( !s.isString () )
						this.setInstanceMessage ( object.id, propertie ) ;
					else {
						this.toCompare ( object.id, propertie ) ;
						//this.compare ( object.id, propertie ) ;
					}
				}
				break ;
		}
	}
} ;

/**
 * Verifica que tipo de mensaje se debe instanciar 
 * @param oId, contiene el id del elemento que se esta analizando
 * @param propertie, contiene las propiedades del elemento para la manipulacion de los mensajes
 */
hms.validator.setInstanceMessage = function ( oId, propertie ) {
	propertie.message != null ? this.setMessage ( propertie.message ) :	
									this.setMessage ( propertie.type, { hmsid: oId } ) ;
} ;

/** 
 * Instancia un mensaje a la cadena de mensaje general
 * @param type, contiene el tipo de mensaje que se desea buscar en la lista de mensajes estandares
 * @param attributes, contiene los diferentes valores que se le pueden asignar a la cadena del mensaje
 */
hms.validator.setMessage = function ( type, attributes ) {
	var message = null ;

	if ( type != null )
		eval ( 'message = hms.properties.validation.' + type ) ;
	
	if ( attributes ) {		
		if ( attributes.hmsid )					message = message.replace ( '/**field**/', $( 'lbl.' + attributes.hmsid.substr (4) ).innerHTML ) ;
		if ( attributes.hmsshared )				message = message.replace ( '/**fields**/', attributes.hmsshared ) ;	
		if ( attributes.hmscount )				message = message.replace ( '/**count**/', attributes.hmscount ) ;	
		if ( attributes.hmsmin != null )		message = message.replace ( '/**min**/', attributes.hmsmin ) ;	
		if ( attributes.hmsmax != null )		message = message.replace ( '/**max**/', attributes.hmsmax ) ;
		if ( attributes.hmscompare != null )	message = message.replace ( '/**compare**/', attributes.hmscompare ) ;
	} 

	if ( this.message == null || this.message.indexOf ( message ) == -1 )
		this.message = this.message == null ? message : this.message + '\n\n' + message ;
} ;

/**
 * convierte una cadeba que representa a un objeto en el objeto como tal
 * @param strObject, contiene la cadena a convertir en objeto
 * @return object, contiene el objeto como tal
 */
hms.validator.object = function ( strObject ) {
	return eval ( strObject ) ;
} ;

/**
 * Procesa la validacion de objetos compartidos.
 * @param aShared, contiene el listado de id que son compartidos para validar
 * @aProperties, contiene las propiedades del objeto.
 */
hms.validator.processShared = function ( aShared, aPropertie ) {
	var isEmpty = true ;
	var  strId  = '' ;
	for ( var i = 0; i < aShared.length; i ++ ) {
		strId += $( 'lbl.' + aShared [ i ].substr (4) ).innerHTML + ( i < aShared.length - 1 ? ', ' : '' ) ; 
		var s = $(aShared [ i ]).value ;
		if ( ! s.isEmpty () )
			isEmpty = false ;
	}

	if ( isEmpty ) 
		aPropertie.message != null ? this.setMessage ( aPropertie.message ) :	
									this.setMessage ( aPropertie.type, { hmsshared: strId } ) ;
	
} ;


/**
 * Procesa la validacion de objetos cuando hay dependencia entre ellos.
 * @param oId, contiene id del elemento que se esta analizando
 * @param aDepends, contiene el listado objeto de la cual depende el objeto actual
 * @aProperties, contiene las propiedades del objeto.
 */
hms.validator.processDepends = function ( oId, aDepends, aPropertie ) {
	var element = $( oId ) ;
	var isEmpty = false ;
	var s = '' ;
	
	for ( var i = 0; i < aDepends.length; i ++ ) {
		var oDepends = aDepends [ i ] ;
		
		switch ( oDepends.type ) {
			case 'text' :
				s = $( oDepends.field ).value ;
				if ( ! s.isEmpty () ) 
					isEmpty = true ;
				break ;
				
			case 'checkbox' :
				var chk = $( oDepends.field ) ;
				if ( chk.checked )
					isEmpty = true ;
				break ;
		}
	}

	if ( isEmpty ) {
		aPropertie.type = 'required' ;
		this.setInstanceMessage ( oId, aPropertie ) ;
	}
} ;

/**
 * Ejecuta la validacion de comparacion, verifica si el objeto con el que se desea comparar es diferente de vacio
 * @param oId, contiene id del elemento que se esta analizando
 * @aProperties, contiene las propiedades del objeto.
 */
/* 
hms.validator.compare = function ( oId, propertie ) {
	if ( propertie.compare != null ) {
		var value = new String ( propertie.compare [ 0 ] ) ;
		if ( value.length > 0 ) 
			this.processCompare ( oId, propertie ) ;
	}
} ;
*/

hms.validator.toCompare = function ( oId, propertie ) {
	if ( propertie.compare != null ) {
		var hmscompare	= propertie.compare ;
		var value		= typeof hmscompare.valor == 'object' ? new String ( hmscompare.valor.value ) : new String ( hmscompare.valor ) ;
		if ( !value.isEmpty () )
			this.toProcessCompare ( oId, propertie ) ;		
	}
} ;

hms.validator.toProcessCompare = function ( oId, propertie ) {
	var hmscompare	= propertie.compare ;	
	var value		= typeof hmscompare.valor == 'object' ? new String ( hmscompare.valor.value ) : new String ( hmscompare.valor ) ;
	var operation	= hmscompare.operation ;
	var message		= hmscompare.message ;
	switch ( propertie.type ) {
		case 'integer' :
			if ( value.isInteger () ) {
				if ( this.processOperatorNumber ( $( oId ).value, value, operation ) )  
					message != null ? this.setMessage ( message ) :
										this.toMessageCompare ( oId, propertie ) ;
			} else  
				this.setMessage ( 'integer', { hmsid: hmscompare.valor.id } ) ;
			break ;

		case 'flotante':
			if ( value.isFlotante () ) {
				if ( this.processOperatorNumber ( $( oId ).value, value, operation ) ) 
					message != null ? this.setMessage ( message ) :
										this.toMessageCompare ( oId, propertie ) ;
			} else 
				this.setMessage ( 'flotante', { hmsid: hmscompare.valor.id } ) ;
			break ;
			
		case 'string' :
			if ( value.isString () ) {
				if ( this.processOperatorString ( $( oId ).value, value, operation ) ) 
					message != null ? this.setMessage ( message ) :
										this.toMessageCompare ( oId, propertie ) ;
			} else 
				this.setMessage ( 'string', { hmsid: hmscompare.valor.id } ) ;
			break ;

		case 'time' :
			if ( value.isTime() ) {
				var time_1 = this.convertTime ( $( oId ).value ) ;
				var time_2 = this.convertTime ( value ) ;
				if ( this.processOperatorNumber ( time_1, time_2, operation ) ) 
					message != null ? this.setMessage ( message ) :
										this.toMessageCompare ( oId, propertie ) ;
			} else 
				this.setMessage ( 'time', { hmsid: hmscompare.valor.id } ) ;				
			break ;

		case 'date' :
			if ( value.isDate () ) {
				if ( this.processDate ( value ) ) {
					var date_1 = this.convertDate ( $( oId ).value ) ;
					var date_2 = this.convertDate ( value ) ;
					if ( this.processOperatorNumber ( date_1, date_2, operation ) ) 
						message != null ? this.setMessage ( message ) :
											this.toMessageCompare ( oId, propertie ) ;
				} else 
					this.setMessage ( 'date', { hmsid: hmscompare.valor.id } ) ;				
			} else 
				this.setMessage ( 'date', { hmsid: hmscompare.valor.id } ) ;				
			break ;

		case 'datetime' :
			var adate = $( oId ).value.split ( ' ' ) ;
			if ( value.isDateTime () ) {
				var _adate = value.split ( ' ' ) ;
				if ( this.processDate ( _adate [ 0 ] ) ) {
					var datetime_1 = this.convertDate ( adate [ 0 ] ) + '' + this.convertTime ( adate [ 1 ] ) ;
					var datetime_2 = this.convertDate ( _adate [ 0 ] ) + '' + this.convertTime ( _adate [ 1 ] ) ;
					if ( this.processOperatorNumber ( datetime_1, datetime_2, operation ) ) 
						message != null ? this.setMessage ( message ) :
											this.toMessageCompare ( oId, propertie ) ;
				} else
					this.setMessage ( 'date', { hmsid: hmscompare.valor.id } ) ;		
			} else 
				this.setMessage ( 'datetime', { hmsid: hmscompare.valor.id } ) ;		
			break ;
	}
} ;

hms.validator.toMessageCompare = function ( oId, propertie ) {
	var hmscompare	= propertie.compare ;	
	var msg 		= '' ; 
	switch ( hmscompare.operation ) {
		case '<' 	: msg = 'get' ; break ;
		case '>' 	: msg = 'met' ; break ;
		case '<='	: msg = 'mat' ; break ;
		case '>='	: msg = 'mit' ; break ;
		case '!='	: msg = 'equ' ; break ;
		case '=='	: msg = 'neq' ; break ;
	}

	this.setMessage ( 'compare.' + msg, { hmsid : oId, 
		hmscompare: ( typeof hmscompare.valor == 'object' ? 
			$( 'lbl.' + hmscompare.valor.id.substr (4) ).innerHTML : hmscompare.valor ) } ) ; 
} ;

/**
 * Ejecuta la validacion de comparacion, verifica que tipo de comparacion se ha de ejecutar
 * @param oId, contiene id del elemento que se esta analizando
 * @aProperties, contiene las propiedades del objeto.
 */
/* 
hms.validator.processCompare = function ( oId, aPropertie ) {
	var hmscompare 	= aPropertie.compare ;
	var value  		= new String ( hmscompare [ 0 ] ) ;
	var operation  	= hmscompare [ 1 ] ;
	var message		= hmscompare [ 2 ] ;
	switch ( aPropertie.type ) {
		case 'integer' :
			if ( value.isInteger () ) {
				if ( this.processOperatorNumber ( $( oId ).value, value, operation ) )  
					this.setMessage ( message ) ;
			} else 
				this.setMessage ( 'integer', { hmsid: hmscompare [ 3 ] } ) ;
			break ;
			
		case 'flotante':
			if ( value.isFlotante () ) {
				if ( this.processOperatorNumber ( $( oId ).value, value, operation ) ) 
					this.setMessage ( message ) ;
			} else 
				this.setMessage ( 'flotante', { hmsid: hmscompare [ 3 ] } ) ;
			break ;
			
		case 'string' :
			if ( this.processOperatorString ( $( oId ).value, value, operation ) ) 
				this.setMessage ( message ) ;
			break ;
			
		case 'time' :
			if ( value.isTime() ) {
				var time_1 = this.convertTime ( $( oId ).value ) ;
				var time_2 = this.convertTime ( value ) ;
				if ( this.processOperatorNumber ( time_1, time_2, operation ) ) 
					this.setMessage ( message ) ;
			} else {
				this.setMessage ( 'time', { hmsid: hmscompare [ 3 ] } ) ;				
			}
			break ;
			
		case 'date' :
			if ( value.isDate () ) {
				if ( this.processDate ( value ) ) {
					var date_1 = this.convertDate ( $( oId ).value ) ;
					var date_2 = this.convertDate ( value ) ;
					if ( this.processOperatorNumber ( date_1, date_2, operation ) ) 
						this.setMessage ( message ) ;
				} else {
					this.setMessage ( 'date', { hmsid: hmscompare [ 3 ] } ) ;				
				}
			} else {
				this.setMessage ( 'date', { hmsid: hmscompare [ 3 ] } ) ;				
			}
			break ;
		
		case 'datetime' :
			var adate = $( oId ).value.split ( ' ' ) ;
			if ( value.isDateTime () ) {
				var _adate = value.split ( ' ' ) ;
				if ( this.processDate ( _adate [ 0 ] ) ) {
					var datetime_1 = this.convertDate ( adate [ 0 ] ) + '' + this.convertTime ( adate [ 1 ] ) ;
					var datetime_2 = this.convertDate ( _adate [ 0 ] ) + '' + this.convertTime ( _adate [ 1 ] ) ;
					if ( this.processOperatorNumber ( datetime_1, datetime_2, operation ) ) 
						this.setMessage ( message ) ;
				} else {
					this.setMessage ( 'date', { hmsid: hmscompare [ 3 ] } ) ;		
				}
			} else {
				this.setMessage ( 'datetime', { hmsid: hmscompare [ 3 ] } ) ;		
			}
			break ;
	}
} ;
*/

/**
 * Ejecuta una comparacion de tipo numerico a traves de una operacion
 * @param v1, contiene el primer valor a comparar
 * @param v2, contiene el segundo valor a comparar
 * @operation, contiene la operacion que se debe ejecutar para la comparacion.
 * @return true, si la ejecucion de la operacion es verdadera, false en caso contrario
 */
hms.validator.processOperatorNumber = function ( v1, v2, operation ) {
	return eval ( 'Number (v1) ' + operation + ' Number (v2)' ) ;
} ;


/**
 * Ejecuta una comparacion entre cadenas a traves de una operacion
 * @param v1, contiene el primer valor a comparar
 * @param v2, contiene el segundo valor a comparar
 * @operation, contiene la operacion que se debe ejecutar para la comparacion.
 * @return true, si la ejecucion de la operacion es verdadera, false en caso contrario
 */
hms.validator.processOperatorString = function ( v1, v2, operation ) {
	return eval ( 'v1 ' + operation + ' v2' ) ;
} ;


/**
 * Convierte una cadena de tipo fecha a la fecha que representa y verifica si esa fecha es valida
 * @param strDate, contiene la representacion textual de una fecha
 * @return true si la fecha obtenida es una fecha valida, false en caso contrario
 */
hms.validator.processDate = function ( strDate ) {
	var afecha	= strDate.split ( '-' ) ;
	var fecha 	= new Date ( afecha [ 2 ], afecha [ 1 ] - 1, afecha [ 0 ] );
	if ( fecha.getMonth () != Number ( afecha [ 1 ] - 1 ) )
		return false ;
	return true ;
} ;


/**
 * Convierte una cadena de tipo hora al valor numerico que representa
 * @param strTime, contiene la representacion textual de una hora
 * @return el numero representativo de la hora, por ej.: 20:15:10 devuelve 201510
 */
hms.validator.convertTime = function ( strTime ) {
	var cmpTime = strTime.split ( ':' ) ;
	return Number ( cmpTime [ 0 ] + '' + cmpTime [ 1 ] + '' + cmpTime [ 2 ] ) ;
} ;


/**
 * Convierte una cadena de tipo fecha al valor numerico que representa, tomando el orden año, mes y dia
 * @param strDate, contiene la representacion textual de una fecha
 * @return el numero representativo de la fecha, por ej.: 10-02-2006 devuelve 20060210
 */
hms.validator.convertDate = function ( strDate ) {
	var cmpTime = strDate.split ( '-' ) ;
	return Number ( cmpTime [ 2 ] + '' + cmpTime [ 1 ] + '' + cmpTime [ 0 ] ) ;
} ;


/**
 * Ejecuta la validacion de rango permitido para un numero.
 * @param oId, contiene id del elemento que se esta analizando
 * @propertie, contiene las propiedades del objeto.
 */
/** 
 ** Se ajusto la funcion y se asigno a range.
 ** comentareada el 30 de agosto de 2007, Ing. Elvis
 
hms.validator.processRange = function ( oId, propertie ) {
	if ( propertie.range != null ) {
		if ( this.processOperatorNumber ( $(oId).value, propertie.range[0], '<' ) ||
				this.processOperatorNumber ( $(oId).value, propertie.range[1], '>' )) 
			propertie.message != null ? this.setMessage ( propertie.message ) :	
				this.setMessage ( 'range', { hmsid: oId, hmsmin: propertie.range[0], hmsmax: propertie.range[1] } ) ;
	}
} ;
*/

/**
 * Ejecuta la validacion de rango permitido, teniendo en cuenta si los extremos son incluidos en la comparacion.
 * @param elements, contiene elementos que se necesitan para la validacion
 */
hms.validator.evaluateRange = function ( elements ) {
	if ( elements.includeEnds ) {
		if ( this.processOperatorNumber ( elements.vCurrent, elements.vBegin, '<' ) ||
					this.processOperatorNumber ( elements.vCurrent, elements.vEnd, '>' )) 
				elements.message != null ? this.setMessage ( elements.message ) :	
					this.setMessage ( 'range', { hmsid: elements.id, 
									 			 hmsmin: ( typeof elements.oBegin == 'object' ? $( 'lbl.' + elements.oBegin.id.substr (4) ).innerHTML + ' (' + elements.oBegin.value + ')' : elements.voBegin != null ? elements.voBegin : elements.vBegin ), 
											  	 hmsmax: ( typeof elements.oEnd == 'object' ? $( 'lbl.' + elements.oEnd.id.substr (4) ).innerHTML + ' (' + elements.oEnd.value + ')' : elements.voEnd != null ? elements.voEnd : elements.vEnd ) } ) ;
	} else {
		if ( this.processOperatorNumber ( elements.vCurrent, elements.vBegin, '<=' ) ||
					this.processOperatorNumber ( elements.vCurrent, elements.vEnd, '>=' )) 
				elements.message != null ? this.setMessage ( elements.message ) :	
					this.setMessage ( 'rangeIE', { hmsid: elements.id, 
									 			 hmsmin: ( typeof elements.oBegin == 'object' ? $( 'lbl.' + elements.oBegin.id.substr (4) ).innerHTML + ' (' + elements.oBegin.value + ')' : elements.voBegin != null ? elements.voBegin : elements.vBegin ), 
											  	 hmsmax: ( typeof elements.oEnd == 'object' ? $( 'lbl.' + elements.oEnd.id.substr (4) ).innerHTML + ' (' + elements.oEnd.value + ')' : elements.voEnd != null ? elements.voEnd : elements.vEnd ) } ) ;
	}
} ;


/**
 * verifica el procesamiento de rangos para fechas ...
 * @param oId, contiene id del elemento que se esta analizando
 * @param propertie, contiene las propiedades del objeto.
 * @note , Por ahora solo se aplica a integer, flotante y date. 
 */
hms.validator.range = function ( oId, propertie ) { 
	if ( propertie.range != null ) {
		var hmsrange	= propertie.range ;
		var vBegin		= typeof hmsrange [ 0 ] == 'object' ? new String ( hmsrange [ 0 ].value ) : new String ( hmsrange [ 0 ] ) ;
		var vEnd		= typeof hmsrange [ 1 ] == 'object' ? new String ( hmsrange [ 1 ].value ) : new String ( hmsrange [ 1 ] ) ;
		var iEnds		= hmsrange [ 2 ] ;
		
		if ( !vBegin.isEmpty () && !vEnd.isEmpty () ) {
			switch ( propertie.type ) {
				case 'integer' :
					if ( vBegin.isInteger() ) {
						if ( vEnd.isInteger() ) {
							this.evaluateRange ( { id: oId, vCurrent: $( oId ).value, vBegin: vBegin, vEnd: vEnd, 
													includeEnds: iEnds, message: propertie.message, oBegin: hmsrange [ 0 ], oEnd: hmsrange [ 1 ] } ) ;
						} else 
							this.setMessage ( 'integer', { hmsid: hmsrange [ 1 ].id } ) ;	
					} else 
						this.setMessage ( 'integer', { hmsid: hmsrange [ 0 ].id } ) ;	
					break ;

				case 'flotante' :
					if ( vBegin.isFlotante() ) {
						if ( vEnd.isFlotante() ) {
								this.evaluateRange ( { id: oId, vCurrent: $( oId ).value, vBegin: vBegin, vEnd: vEnd, 
															includeEnds: iEnds, message: propertie.message, oBegin: hmsrange [ 0 ], oEnd: hmsrange [ 1 ] } ) ;
						} else 
							this.setMessage ( 'flotante', { hmsid: hmsrange [ 1 ].id } ) ;	
					} else 
						this.setMessage ( 'flotante', { hmsid: hmsrange [ 0 ].id } ) ;	
					break ;

				case 'date' :
					if ( vBegin.isDate () && this.processDate ( vBegin ) ) {
						if ( vEnd.isDate () && this.processDate ( vEnd ) ) {
								var vdCurrent	= this.convertDate ( $( oId ).value ) ; 
								var vdBegin 	= this.convertDate ( vBegin ) ; 
								var vdEnd 		= this.convertDate ( vEnd ) ; 
								this.evaluateRange ( { id: oId, vCurrent: vdCurrent, vBegin: vdBegin, vEnd: vdEnd, 
															includeEnds: iEnds, message: propertie.message, voBegin: vBegin, voEnd: vEnd, oBegin: hmsrange [ 0 ], oEnd: hmsrange [ 1 ] } ) ;
						} else 
							this.setMessage ( 'date', { hmsid: hmsrange [ 1 ].id } ) ;	
					} else 
						this.setMessage ( 'date', { hmsid: hmsrange [ 0 ].id } ) ;	
					
					break ;
			}
		}
	}
} ;

/**
 * Ejecuta las validaciones relacionadas directamente con el formulario
 * @param form, contiene el nombre del formulario que se desea validar
 */
hms.validator.validateOnlyForm = function () {
	var hmsvalidate = this.form.getAttribute ( 'hmsvalidate' ) ;
	if ( hmsvalidate != null ) {
		hmsvalidate = this.object ( hmsvalidate ) ;		
		for ( var i = 0; i < hmsvalidate.length; i ++ ) {
			var propertie = hmsvalidate [ i ] ;
			switch ( propertie.type ) {		
				case 'onlyform' :
					return ( true ) ;	
					break ;
			}
		}
	}
	return ( false ) ;
} ;
 

hms.validator.validateForm = function () {
	var hmsvalidate = this.form.getAttribute ( 'hmsvalidate' ) ;
	if ( hmsvalidate != null ) {
		hmsvalidate = this.object ( hmsvalidate ) ;		
		this.propertiesForm ( hmsvalidate ) ;
	}

} ;


hms.validator.propertiesForm = function ( properties ) {
	for ( var i = 0; i < properties.length; i ++ ) {
		var propertie = properties [ i ] ;
		switch ( propertie.type ) {		
			case 'option' :
				this.processOption ( propertie ) ;	
				break ;
			
			case 'checkbox' :
				this.processCheckbox ( propertie ) ;	
				break ;
		}
	}
} ;

hms.validator.processOption = function ( propertie ) {
	for ( var i = 0; i < this.form.elements.length; i ++ ) {
		var el = this.form.elements [ i ];
		if ( el.type == 'radio' && el.name == propertie.name ){
			if ( el.checked )
				return ;
		}		
	}
	
	propertie.message != null ? this.setMessage ( propertie.message ) :
			this.setMessage ( 'option' ) ;						
	
} ;

hms.validator.processCheckbox = function ( propertie ) {
	for ( var i = 0; i < this.form.elements.length; i ++ ) {
		var el = this.form.elements [ i ];
		if ( el.type == 'checkbox' && el.name == propertie.name ){
			if ( el.checked )
				return ;
		}		
	}
	
	propertie.message != null ? this.setMessage ( propertie.message ) :
			this.setMessage ( 'checkbox' ) ;						
	
} ;
