val = new Array()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 extraer_val(nombre){	arr1 = val[nombre]	cad1 = arr1.split(";")	for (j=0;j<cad1.length;j++){		arr2 = cad1[j].split(":")		aux[arr2[0]]=arr2[1]	}// next	if (aux["titulo"]=="" || aux["titulo"]==null){		aux["titulo"]=nombre	}// end if
	}// end functionfunction validar_condicion(nombre,valor){	campo = valor	r_condicion = aux["condicion"]	if (aux["msgerror"]!="" && aux["msgerror"]!=null){		mensaje = aux["msgerror"]	}else{		mensaje = "El valor del campo "+aux["titulo"]+" debe cumplir la condicion: "+r_condicion	}// end if
	if (!eval(r_condicion)){		return false	}// end if
	return true}// end functionfunction validar_ext(control_x,control_x){	alert(control_x)	alert(valor_x)}//end functionfunction validar_rangos(nombre,valor){
	var activar_msj_def = true;	tipo_rango = parseInt(aux["rango"])	if (tipo_rango<1 || tipo_rango>9){		return true	}// endif
	r_minimo = parseInt(aux["min"])	r_maximo = parseInt(aux["max"])
	r_comodin_a = parseInt(aux["cmda"])	r_comodin_b = parseInt(aux["cmdb"])	r_valor = parseInt(valor)

	if(aux["mostrar"]!=null){
		activar_msj_def = false;
		mensaje = aux["mostrar"];
	}else{		mensaje = "El valor del campo "+aux["titulo"]+" "	}
	/*rango 1:>= y <=; 2:>=; 3:<=; 4:> y <; 5:>; 6:<; 7:<= o >=; 8:< o >;*/
	switch (tipo_rango){		case 1:			r_condicion = " r_valor >= r_minimo && r_valor <= r_maximo "			if(activar_msj_def)
				mensaje += "debe estar entre " + r_minimo + " y " + r_maximo			break		case 2:				r_condicion = " r_valor >= r_minimo "
			if(activar_msj_def)				mensaje += "debe ser mayor o igual que " + r_minimo			break		case 3:			r_condicion = " r_valor <= r_maximo "
			if(activar_msj_def)				mensaje += "debe ser menor o igual que " + r_maximo			break		case 4:				r_condicion = " r_valor > r_minimo && r_valor < r_maximo "			if(activar_msj_def)				
				mensaje += "debe ser mayor que " + r_minimo + " y menor que " + r_maximo			break		case 5:				r_condicion = " r_valor > r_minimo "
			if(activar_msj_def)				mensaje += "debe ser mayor que " + r_minimo			break		case 6:			r_condicion = " r_valor < r_maximo "			if(activar_msj_def)
				mensaje += "debe ser menor que " + r_maximo			break		case 7:			r_condicion = " r_valor <= r_minimo || r_valor >= r_maximo "			if(activar_msj_def)
				mensaje += "debe menor o igual que " + r_minimo + " o mayor o igual que " + r_maximo										break		case 8:			r_condicion = " r_valor < r_minimo || r_valor > r_maximo "			if(activar_msj_def)
				mensaje += "debe menor que " + r_minimo + " o mayor que " + r_maximo										break
		case 9:			//r_condicion = " (r_valor >= r_minimo && r_valor <= r_maximo && r_valor != r_comodin_a) "			
			r_condicion = " (r_valor == r_comodin_a || r_valor == r_comodin_b) || (r_valor >= r_minimo && r_valor <= r_maximo && r_valor) "			
			//alert(r_condicion)
			if(activar_msj_def)
				mensaje += "debe menor que " + r_minimo + " o mayor que " + r_maximo										break	}// end switch
	if (!eval(r_condicion)){		return false	}// end if
	return true
}// end functionfunction validar_campos(control){	this.eval_exp = eval_exp	this.no_vacio = no_vacio	this.fecha = new obj_fecha	function no_vacio(valor_x){		re = /.+/		var matchArray = re.exec(valor_x)		//alert (matchArray)
		if (matchArray){			return true		}// end if
		return false	}// 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
			tipo_x = control.type	valor_x = control.value	tipo_x = (tipo_x=="textarea" || tipo_x=="hidden" || tipo_x=="password")?"text":tipo_x	aux = new Array()
	switch(tipo_x){	case "text":		if (val[control.name]!="" && val[control.name]!=null){			//Extraer Valores
			extraer_val(control.name)
			var activar_msj_def = true;
			if(aux["mostrar"]!="" && aux["mostrar"]!=null && aux["mostrar"]!="undefined"){
				activar_msj_def = false;
				mensaje = aux["mostrar"];
			}else{				mensaje = "El valor del campo "+aux["titulo"]+" "			}
						if (aux["obligatorio"]=="si" && (!this.no_vacio(valor_x))){				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" es obligatorio"				return false			}//end if

			if (aux["fecha"]=="si" && (this.no_vacio(valor_x)) && !this.fecha.validar(valor_x)){				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" debe ser una Fecha válida"				return false			}// end if			if (aux["email"]=="si" && (!this.eval_exp("^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$",valor_x))){				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" debe ser una Dirección de Correo válida"				return false			}// end if
			if (aux["rif"]=="si" /*&& (!this.eval_exp("^[JV]-[0-9]{1,8}(-[0-9]){0,1}$",valor_x))*/){				//var re = /^[J]+(\.[0-9])*{5,10}$/
				//^[JV]-[0-9]{1,8}(-[0-9]){0,1}$				//var re = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]{2,200}\.[a-zA-Z]{2,6}$/				var re = /^[EJVejv]+-([\d]+)(-[\w])?$/				var matchArray = re.exec(valor_x)
				if (!matchArray){					if(activar_msj_def)
						mensaje = "El campo "+aux["titulo"]+" debe ser un R.I.F válido"					return false				}// end if			
			}// end if		
			if (aux["alfabetico"]=="si" && (!this.eval_exp("^([ A-ZñÑáéíóúÁÉÍÓÚ ]+)$",valor_x))){					if(activar_msj_def)
						mensaje = "El campo "+aux["titulo"]+" debe ser Alfabético"				return false			}// end if			//if (aux["alfanumerico"]=="si" && (!this.eval_exp("^([ \\w]+)$",valor_x))){
			if(aux["alfanumerico"]=="si" && (!this.eval_exp("^([ A-Z0-9a-zñÑáéíóúÁÉÍÓÚ,._-]+)$",valor_x))){
				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" debe ser Alfanumérico"				return false			}// end if			
			
			if(aux["clave"]=="si" && (!this.eval_exp("^([ A-Z0-9a-z+._#,*&%$@/\\-]+)$",valor_x))){
				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" no es una contraseña válida"				return false			}// end if
			
			if(aux["usuario"]=="si" && (!this.eval_exp("^([ A-Z0-9A-Z._-]+)$",valor_x))){
				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" no es una contraseña válida"				return false			}// end if
			
			if(aux["direccion"]=="si" && (!this.eval_exp("^([() A-Z0-9a-zñÑáéíóúÁÉÍÓÚ,#;._-]+)$",valor_x))){
				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" debe ser Alfanumérico"				return false			}// end if
			
			if (aux["isbn"]=="si" && (!this.eval_exp("^[0-9]{1,5}-[0-9]{1,7}-[0-9]{1,6}-[0-9xX]$",valor_x))){				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+"La estructura del ISBN introducido no coincide con el estandar ISBN\n\nEjemplo: 0-8436-1072-7"
				/*\n\n El estÃÂÃÂ¡ndar indica esta estructura:
				\nde 1 a 5 nÃÂÃÂºmeros\nguiÃÂÃÂ³n
				\nde 1 a 7 nÃÂÃÂºmeros\nguiÃÂÃÂ³n
				\nde 1 a 6 nÃÂÃÂºmeros\nguiÃÂÃÂ³n
				\ndÃÂÃÂ­gito de control. de 0 a 9 o \"X\" si el dÃÂÃÂ­gito es 10
				\nLa longitud total debe ser de 10 dÃÂÃÂ­gitos, mÃÂÃÂ¡s los tres guiones.*/				return false			}// end if
			
			if (aux["numerico"]=="si" && (!this.eval_exp("^[-]?\\d*\\.?\\d*$",valor_x))){				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" debe ser numérico"				return false			}// end if
	
			if (aux["decimal"]=="si" && (!this.eval_exp("^[-]?\\d*\,?\\d*$",valor_x))){				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" debe ser Decimal"				return false			}// end if
	
			if (aux["numerico2"]=="si" && (!this.eval_exp("[0-9]",valor_x))){				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" debe ser numérico"				return false			}// end if			if (aux["entero"]=="si" && (!this.eval_exp("^[-]?\\d*$",valor_x))){				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" debe ser un número entero"				return false			}// end if			if (aux["positivo"]=="si" && (!this.eval_exp("^\\d*\\.?\\d*$",valor_x))){				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" debe ser un número positivo"				return false				}// end if			if (aux["nocero"]=="si" && !isNaN(valor_x) && valor_x==0 && valor_x.length!=0){				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" debe ser un número distinto de cero"				return false			}// end if			if (aux["mayorcero"]=="si" && !isNaN(valor_x) && valor_x<=0 && valor_x.length!=0){				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" debe ser un número mayor de cero"				return false			}// end if			if (aux["hora"]=="si" && (!this.eval_exp("^(1|01|2|02|3|03|4|04|5|05|6|06|7|07|8|08|9|09|10|11|12)\:([0-5]0|[0-5][1-9])",valor_x))){				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" debe ser una Hora válida"				return false			}// end if			if (aux["sin_espacio"]=="si" && (this.eval_exp("[ ]+",valor_x))){				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" no debe tener espacios en blanco"				return false			}// end if

			if (aux["telefono"]=="si" && (!this.eval_exp("^([0-9]{3,4}-?)?[0-9]{7}$",valor_x))){
				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" no es un número válido Ej. 0212-555555";				return false			}// end if
			
			if (aux["telefonos"]=="si" && (!this.eval_exp("^([0-9]{3,4}-[0-9]{7};{0,1}){0,3}$",valor_x))){
				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" no es un número válido Ej. 0212-555555";				return false			}// end if
			
			if (aux["min_caracteres"]=="si" && strlen(valor_x)<5){
				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" no es un número válido Ej. 0212-555555";				return false			}// end if
						
			if (aux["consulta"]=="si" && (!this.eval_exp("(select)",valor_x))){				/*var cadena = new String(valor_x);				var lista = cadena.substr(0,6);				alert(lista)*/				//if(lista != "select"){				if(activar_msj_def)
					mensaje = "El campo "+aux["titulo"]+" debe ser una consulta SQL"				return false				//}//end if			}// end if
						/*if (aux["url"]=="si" && (this.eval_exp("http://([\w-]\.)+[\w-](/[\w- \./?%=]*)?",valor_x))){				mensaje = "El campo "+aux["titulo"]+" debe ser un url válido"				return false			}// end if*/			/*	
			if (aux["extension"]=="si" && valor_x.length!=0 && validar_ext(control,valor_x)){				mensaje = "El campo "+aux["titulo"]+" debe ser un número mayor de cero"				return false			}// end if
			*/			if (aux["rango"]!="" && aux["rango"]!=null){				return validar_rangos(control.name,valor_x)			}// end if
						if (aux["condicion"]!="" && aux["condicion"]!=null){				return validar_condicion(control.name,valor_x)			}// end if		}// end if		break	case "select-one":
		if (val[control.name]!="" && val[control.name]!=null){			extraer_val(control.name)
			var activar_msj_def = true;
			if(aux["mostrar"]!="" && aux["mostrar"]!=null && aux["mostrar"]!="undefined"){
				activar_msj_def = false;
				mensaje = aux["mostrar"];
			}else{				mensaje = "El valor del campo "+aux["titulo"]+" "			}			if (aux["obligatorio"]=="si" && (valor_x=="" || valor_x==null)){				if(activar_msj_def)
				mensaje = "El campo "+aux["titulo"]+" es Obligatorio"				return false						}// end if

			if (aux["rango"]!="" && aux["rango"]!=null){				return validar_rangos(control.name,valor_x)			}// end if		}// end if	break	}// end switch	return true}// end functionfunction validar_form(form_x){	n_ele = form_x.elements.length	for (i=0;i<n_ele;i++){		if (!validar_campos(form_x.elements[i])){			alert (mensaje)			nombre_x = form_x.elements[i].name			if (aux["fecha"]=="si" && aux["tipo"]=="combos"){				nombre_x = form_x.elements[i].name+"_dia_aux"			}else{				if (aux["tipo"]=="calendario"){					nombre_x = form_x.elements[i].name+"_aux"				}else{					if (aux["hora"]=="si" && aux["tipo"]=="combos"){						nombre_x = form_x.elements[i].name+"_h_aux"					}// end if				}// end if			}// end if			form_x.elements[nombre_x].focus()			if (form_x.elements[nombre_x].type=="text")				form_x.elements[nombre_x].select()			return false		}// end if	}// next	return true}// end function