function obj_fecha(){
	this.dia
	this.mes
	this.ano
	this.fecha
	this.patron_entrada = "d/m/Y"
	this.patron_salida = "Ymd"
	this.dia_hoy
	this.mes_hoy
	this.ano_hoy
	this.antes_es_2000 = 30

	this.trim = trim
	this.remplazar = remplazar
	this.validar = validar
	this.mostrar_fecha = mostrar_fecha
	
	function trim(cad_x){
		var re = /^\s+/i
		var matchArray = re.exec(cad_x)
		if (matchArray){
			cad_x = cad_x.replace(re, "");
		}// end if
		var re = / +$/i
		var matchArray = re.exec(cad_x)
		if (matchArray){
			cad_x = cad_x.replace(re, "");
		}// end if
		return cad_x
	}// end function	
	function remplazar(cad_x,patron,valor){
		while(match = patron.exec(cad_x)){
			cad_x = cad_x.replace(patron,valor)
		}// end while
		return cad_x
	}// end function
	function hoy(){
		var fecha_aux = new Date()
		this.dia = fecha_aux.getDate()
		this.mes = fecha_aux.getMonth()+1
		this.ano = fecha_aux.getFullYear()		
	}// end function

	function mostrar_fecha(fecha_x,patron_y){
		patron_y = patron_y || this.patron_salida
		if (this.fecha = this.validar(fecha_x)){
			dia = "00"+parseInt(this.dia,10);
			dia = dia.substr(dia.length-2) 
			mes = "00"+parseInt(this.mes,10); 
			mes = mes.substr(mes.length-2)
			ano = parseInt(this.ano,10); 
			ano2 = "00"+parseInt(this.ano,10); 
			ano2 = ano2.substr(ano2.length-2)
	
			fecha = remplazar(patron_y,/Y/,ano)
			fecha = remplazar(fecha,/y/,ano2)
			fecha = remplazar(fecha,/m/,mes)
			fecha = remplazar(fecha,/d/,dia)
			return fecha
		}else{
			return ""
		}// end if
	}// end function
	
	function validar(fecha_x,patron_x){
		patron_x = patron_x || this.patron_entrada
		fecha_x = this.remplazar(fecha_x,/\b-\b/,"\/")
		patron_x = this.remplazar(patron_x,/\b-\b/,"\/")
		valor_x = this.trim(fecha_x)
		patron = patron_x
		var re2=/^ $/
		patron = this.remplazar(patron,/\by\b/,"[0-9]{1,2}")
		patron = this.remplazar(patron,/\bY\b/,"[0-9]{1,4}")
		patron = this.remplazar(patron,/\bm\b/,"[0-9]{1,2}")
		patron = this.remplazar(patron,/\bd\b/,"[0-9]{1,2}")
		re2.compile("^"+patron+"$","i")	
		if(!(m = re2.exec(valor_x))){
			return false
		}// end if

		var re_anno = /\bY\b/	
		if(m=re_anno.exec(patron_x)){
			patron = patron_x
			patron = this.remplazar(patron,/\bY\b/,"([0-9]{1,4})")
			patron = this.remplazar(patron,/\by\b/,"[0-9]{1,2}")
			patron = this.remplazar(patron,/\bm\b/,"[0-9]{1,2}")
			patron = this.remplazar(patron,/\bd\b/,"[0-9]{1,2}")
			re2.compile("^"+patron+"$","i")	
			if(m = re2.exec(valor_x)){
				anno=m[1]
			}// end if
		}else{	
			patron = patron_x
			patron = this.remplazar(patron,/\by\b/,"([0-9]{1,2})")
			patron = this.remplazar(patron,/\bm\b/,"[0-9]{1,2}")
			patron = this.remplazar(patron,/\bd\b/,"[0-9]{1,2}")
			re2.compile("^"+patron+"$","i")	
			if(m = re2.exec(valor_x)){
				anno=m[1]
			}// end if
		}// end if
		anno=parseInt(anno,10)
		if(anno<100){
			if(anno>=this.antes_es_2000){
				anno = anno+1900
			}else{
				anno = anno+2000
			}// end if
		}// end if
		patron = patron_x
		patron = this.remplazar(patron,/\bY\b/,"[0-9]{1,4}")
		patron = this.remplazar(patron,/\by\b/,"[0-9]{1,2}")
		patron = this.remplazar(patron,/\bm\b/,"([0-9]{1,2})")
		patron = this.remplazar(patron,/\bd\b/,"[0-9]{1,2}")
		re2.compile("^"+patron+"$","i")	
		if(m = re2.exec(valor_x)){
			mes=parseInt(m[1],10)
		}// end if
		patron = patron_x
		patron = this.remplazar(patron,/\bY\b/,"[0-9]{1,4}")
		patron = this.remplazar(patron,/\by\b/,"[0-9]{1,2}")
		patron = this.remplazar(patron,/\bm\b/,"[0-9]{1,2}")
		patron = this.remplazar(patron,/\bd\b/,"([0-9]{1,2})")
		re2.compile("^"+patron+"$","i")	
		if(m = re2.exec(valor_x)){
			dia=parseInt(m[1],10)
		}// end if
		var fecha_aux = new Date(anno,mes-1,dia)
		dia_c = fecha_aux.getDate()
		mes_c = fecha_aux.getMonth()+1
		ano_c = fecha_aux.getFullYear()
		this.dia = dia
		this.mes = mes
		this.ano = anno
		if(dia==dia_c && mes == mes_c && anno == ano_c){
			return true
		}else{
			return false
		}// end if
	}// end function	
}// end class
function validar(){
	this.mensaje = ""
	this.msg_obligatorio = "El campo #campo# es obligatorio"
	this.msg_long_min = "El nro de caracteres del campo #campo# no debe ser menor que"
	this.msg_long_max = "El nro de caracteres del campo #campo# no debe ser mayor que"
	this.msg_alfabetico = "El campo #campo# solo debe tener caracteres alfabéticos"
	this.msg_sin_espacio = "El campo #campo# no debe tener espacio en blancos"
	this.msg_numerico = "El campo #campo# debe ser un valor numérico"
	this.msg_entero = "El campo #campo# debe ser un número entero"
	this.msg_positivo = "El campo #campo# debe ser un número positivo"
	this.msg_email = "El campo #campo# no es una dirección de correo válida"
	this.msg_fecha = "El campo #campo# no es una fecha válida"
	this.msg_mayor = "El campo #campo# debe ser mayor que "
	this.msg_menor = "El campo #campo# debe ser menor que "
	this.msg_mayor_igual = "El campo #campo# debe ser mayor o igual que "
	this.msg_menor_igual = "El campo #campo# debe ser menor o igual que "
	this.msg_imayor = "El Nro de Items del campo #campo# debe ser mayor que "
	this.msg_imenor = "El Nro de Items del campo #campo# debe ser menor que "
	this.msg_imayor_igual = "El Nro de Items del campo #campo# debe ser mayor o igual que "
	this.msg_imenor_igual = "El Nro de Items del campo #campo# debe ser menor o igual que "
	this.msg_exp = "El campo #campo# no coincide con el patrón"
	this.msg_condicion = "El campo #campo# no coincide con la condicion"
	this.patron = "#campo#"
	this.form
	this.campo
	this.prop
	this.extraer_val = extraer_val
	this.validar_campo = validar_campo
	this.ejecutar = ejecutar
	this.msg_error = msg_error
	this.eval_exp = eval_exp
	this.trim = trim
	this.no_vacio = no_vacio
	this.mostrar_error = mostrar_error
	this.remplazar = remplazar
	this.validar = validar
	this.val_condicion = val_condicion
	this.fecha = new obj_fecha
	function val_condicion(r_condicion,valor){
		if (!eval(r_condicion)){
			return false
		}// end if	
		return true
	}// end function	
	function trim(cad_x){
		var re = /^\s+/i
		var matchArray = re.exec(cad_x)
		if (matchArray){
			cad_x = cad_x.replace(re, "");
		}// end if
		var re = / +$/i
		var matchArray = re.exec(cad_x)
		if (matchArray){
			cad_x = cad_x.replace(re, "");
		}// end if
		return cad_x
	}// end function	
	function remplazar(cad_x,patron,valor){
		while(match = patron.exec(cad_x)){
			cad_x = cad_x.replace(patron,valor)
		}// end while
		return cad_x
	}// end function	
	function no_vacio(valor_x){
		re = /.+/
		var matchArray = re.exec(valor_x)
		if (matchArray){
			return true
		}// end if
		return false
	}// end function
	function extraer_val(nombre){
		arr1 = this.campo[nombre]
		cad1 = arr1.split(";")
		for (j=0;j<cad1.length;j++){
			arr2 = cad1[j].split(":")
			this.prop[arr2[0]]=arr2[1]		
		}// next
		if (this.prop["titulo"]=="" || this.prop["titulo"]==null){
			this.prop["titulo"]=nombre
		}// end if
	}// end function
	function eval_exp(patron_x,valor_x){
		if (this.no_vacio(valor_x)){
			var re = eval("/"+patron_x+"/i")
			var matchArray = re.exec(valor_x)
			if (matchArray){
				return true
			}else{
				return false
			}// end if
		}// end if
		return true
	}// end function

	function msg_error(msg_x,valor_y){
		var re = eval("/"+this.patron+"/i")
		var matchArray = re.exec(msg_x)
		if (matchArray){
			msg_x = msg_x.replace(re, valor_y);
		}// end if
		return msg_x
	}// end function 	
	function validar_campo(control){
		tipo_x = control.type
		valor_x = this.trim(control.value)
		tipo_x = (tipo_x=="textarea" || tipo_x=="hidden" || tipo_x=="password")?"text":tipo_x
		this.prop = new Array()
		switch(tipo_x){
		case "text":
			if (this.campo[control.name]!="" && this.campo[control.name]!=null){
				this.extraer_val(control.name)
				if (this.prop["obligatorio"]=="si" && (!this.no_vacio(valor_x))){
					if(this.prop["msg_obligatorio"]==null || this.prop["msg_obligatorio"]==""){
						this.prop["msg_obligatorio"] = this.msg_obligatorio
					}// end if
					this.mensaje = this.msg_error(this.prop["msg_obligatorio"],this.prop["titulo"])
					return false
				}// end if

				if (this.prop["long_min"]!= null && valor_x.length < this.prop["long_min"]){
					if(this.prop["msg_long_min"]==null || this.prop["msg_long_min"]==""){
						this.prop["msg_long_min"] = this.msg_long_min
					}// end if
					this.mensaje = this.msg_error(this.prop["msg_long_min"],this.prop["titulo"])
					return false
				}// end if

				if (this.prop["long_max"]!= null && valor_x.length > this.prop["long_max"]){
					if(this.prop["msg_long_max"]==null || this.prop["msg_long_max"]==""){
						this.prop["msg_long_max"] = this.msg_long_max
					}// end if
					this.mensaje = this.msg_error(this.prop["msg_long_max"],this.prop["titulo"])
					return false
				}// end if


				if (this.prop["alfabetico"]=="si" && (!this.eval_exp("^([ A-ZáéíóúÁÉÍÓÚñÑ]+)$",valor_x))){
					if(this.prop["msg_alfabetico"]==null || this.prop["msg_alfabetico"]==""){
						this.prop["msg_alfabetico"] = this.msg_alfabetico
					}// end if
					this.mensaje = this.msg_error(this.prop["msg_alfabetico"],this.prop["titulo"])
					return false
				}// end if
				if (this.prop["sin_espacio"]=="si" && (this.eval_exp("[ ]+",valor_x))){
					if(this.prop["msg_sin_espacio"]==null || this.prop["msg_sin_espacio"]==""){
						this.prop["msg_sin_espacio"] = this.msg_sin_espacio
					}// end if
					this.mensaje = this.msg_error(this.prop["msg_sin_espacio"],this.prop["titulo"])
					return false
				}// end if
				if (this.prop["numerico"]=="si" && (!this.eval_exp("^[-]?\\d*\\.?\\d*$",valor_x))){
					if(this.prop["msg_numerico"]==null || this.prop["msg_numerico"]==""){
						this.prop["msg_numerico"] = this.msg_numerico
					}// end if
					this.mensaje = this.msg_error(this.prop["msg_numerico"],this.prop["titulo"])
					return false
				}// end if
				if (this.prop["entero"]=="si" && (!this.eval_exp("^[-]?\\d*$",valor_x))){
					if(this.prop["msg_entero"]==null || this.prop["msg_entero"]==""){
						this.prop["msg_entero"] = this.msg_entero
					}// end if
					this.mensaje = this.msg_error(this.prop["msg_entero"],this.prop["titulo"])
					return false
				}// end if
				if (this.prop["positivo"]=="si" && (!this.eval_exp("^\\d*\\.?\\d*$",valor_x))){
					if(this.prop["msg_positivo"]==null || this.prop["msg_positivo"]==""){
						this.prop["msg_positivo"] = this.msg_positivo
					}// end if
					this.mensaje = this.msg_error(this.prop["msg_positivo"],this.prop["titulo"])
					return false
				}// end if
				if (this.prop["email"]=="si" && (!this.eval_exp("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$",valor_x))){
					if(this.prop["msg_email"]==null || this.prop["msg_email"]==""){
						this.prop["msg_email"] = this.msg_email
					}// end if
					this.mensaje = this.msg_error(this.prop["msg_email"],this.prop["titulo"])
					return false
				}// end if
				if (this.prop["fecha"]=="si" && (this.no_vacio(valor_x)) && !this.fecha.validar(valor_x)){
					if(this.prop["msg_fecha"]==null || this.prop["msg_fecha"]==""){
						this.prop["msg_fecha"] = this.msg_fecha
					}// end if
					this.mensaje = this.msg_error(this.prop["msg_fecha"],this.prop["titulo"])
					return false
				}// end if

				if (this.prop["exp"]!=null && (!this.eval_exp(this.prop["exp"],valor_x))){
					if(this.prop["msg_exp"]==null || this.prop["msg_exp"]==""){
						this.prop["msg_exp"] = this.msg_exp
					}// end if
					this.mensaje = this.msg_error(this.prop["msg_exp"],this.prop["titulo"])
					return false
				}// end if
				
				if (this.prop["condicion"]!= null && this.prop["condicion"]!= "" && !this.val_condicion(this.prop["condicion"],valor_x)){
					if(this.prop["msg_condicion"]==null || this.prop["msg_condicion"]==""){
						this.prop["msg_condicion"] = this.msg_condicion
					}// end if
					this.mensaje = this.msg_error(this.prop["msg_condicion"],this.prop["titulo"])
					return false
				}// end if



				if(this.prop["items"]!=null && this.prop["items"]=="si"){
					if(this.prop["item_separador"]!=null && this.prop["item_separador"]!=""){
						item_separador = this.prop["item_separador"]
					}else{
						item_separador = ";"
					}// end if
					if(valor_x!="" && valor_x!=null){
						valor_y = valor_x.split(item_separador).length	
					}else{
						valor_y = 0 
					}// end if
				}else{
					valor_y = valor_x	
				}// end if
				if(this.prop["mayor"]!=null && this.prop["mayor"]!=""){
					if(parseInt(valor_y,10) <= parseInt(this.prop["mayor"],10)){
						this.mensaje = this.msg_error(this.msg_mayor,this.prop["titulo"])+this.prop["mayor"]
						return false
					}// end if
				}// end if

				if(this.prop["menor"]!=null && this.prop["menor"]!=""){
					if(parseInt(valor_y,10) >= parseInt(this.prop["menor"],10)){
						this.mensaje = this.msg_error(this.msg_menor,this.prop["titulo"])+this.prop["menor"]
						return false
					}// end if
				}// end if
				if(this.prop["mayor_igual"]!=null && this.prop["mayor_igual"]!=""){
					if(parseInt(valor_y,10) < parseInt(this.prop["mayor_igual"],10)){
						this.mensaje = this.msg_error(this.msg_mayor_igual,this.prop["titulo"])+this.prop["mayor_igual"]
						return false
					}// end if
				}// end if

				if(this.prop["menor_igual"]!=null && this.prop["menor_igual"]!=""){
					if(parseInt(valor_y,10) > parseInt(this.prop["menor_igual"],10)){
						this.mensaje = this.msg_error(this.msg_menor_igual,this.prop["titulo"])+this.prop["menor_igual"]
						return false
					}// end if
				}// end if
			}// end if
			break;
		case "select-one":
			if (this.campo[control.name]!="" && this.campo[control.name]!=null){
				this.extraer_val(control.name)
				if (this.prop["obligatorio"]=="si" && (valor_x=="" || valor_x==null || valor_x==this.prop["nulo"])){
					this.mensaje = "El campo "+this.prop["titulo"]+" es obligatorio"
					return false
				}// end if
			}// end if
			if (this.prop["condicion"]!= null && this.prop["condicion"]!= "" && !this.val_condicion(this.prop["condicion"],valor_x)){
				if(this.prop["msg_condicion"]==null || this.prop["msg_condicion"]==""){
					this.prop["msg_condicion"] = this.msg_condicion
				}// end if
				this.mensaje = this.msg_error(this.prop["msg_condicion"],this.prop["titulo"])
				return false
			}// end if
			break
		}// end switch
		return true
	}// end if
	function ejecutar(f){
		this.n_ele = f.elements.length
		for(i=0;i<this.n_ele;i++){
			ele_y = f.elements[i]
			if(!this.mostrar_error(ele_y))
				return false
		}// next
		return true
	}// end function
	function mostrar_error(ele){
		if(!ele.disabled && !this.validar_campo(ele)){
			if (ele.type!="hidden")
				ele.focus()
			if (ele.type=="text")
				ele.select()
			if (this.prop["msg_error"]!=null && this.prop["email"]!="")
				alert(this.prop["msg_error"])
			else
				alert(this.mensaje)
			return false
		}// end if
		return true
	}// end function
}// end class
var val = new validar()
val.campo = new Array()