var mensaje_exp = '';

function validar_campos_exp(control,tipo,campo,oblig,msj,cant,rango_x,min_x,max_x,cmda,cmdb){

	this.eval_exp = eval_exp;	this.no_vacio = no_vacio;
	this.no_vacio = expresiones;
	this.validar_rangos = validar_rangos;
	control_x = document.getElementById(control);
	valor_x = control_x.value;
	//control_x.className = 'forminput';

	//if(control_x.type == 'radio'){
		//alert(control_x.name)
		//var r = document.getElementsByName(control_x.name);
		//alert(r.item +' '+control_x)
		//for(i=0;i<r.length;i++){
			//alert(r.checked)
			//if(control_x.checked){
				
			//}//end if
		//}
		//var isFromGroup = (r.lastIndexOf(groupname) + groupname.length ) == r.length;
		//alert(isFromGroup)
		/*if(!control_x.checked){
			if(msj==null || msj == ''){
				mensaje_exp += "<div style='padding-left:60px' class='mensaje_error'>El campo "+campo+" es obligatorio</div>";
			}else{
				mensaje_exp +=	"<div style='padding-left:60px' class='mensaje_error'>"+msj+"</div>";		
			}//end if
			control_x.className = 'obligatorio';
			control_x.focus();
			return true;
		}//end if*/
	//}else{
		if(oblig=='1'){
			if(!no_vacio(valor_x)){
				if(msj==null || msj == ''){
					mensaje_exp += "<div style='padding-left:60px' class='mensaje_error'>El campo "+campo+" es obligatorio</div>";
				}else{
					mensaje_exp +=	"<div style='padding-left:60px' class='mensaje_error'>"+msj+"</div>";		
				}
				//alert(control_x.name)
				control_x.className = 'obligatorio';
				control_x.focus();
				return true;			}// end if
		}//end if
	
		if(oblig=='2'){
			if(valor_x<=0){
				if(msj==null || msj ==''){
					mensaje_exp += "<div style='padding-left:60px' class='mensaje_error'>El campo "+campo+" es obligatorio</div>";
				}else{
					mensaje_exp +=	"<div style='padding-left:60px' class='mensaje_error'>"+msj+"</div>";		
				}
				//control_x.nodeType;	
				control_x.className = 'obligatorio';
				control_x.focus();
				return true;			}// end if
		}//end if
	//}
	if(!isNaN(cant)){
		if((valor_x.length)<parseInt(cant)){
			//if(tipo!=7){
				mensaje_exp += "<div style='padding-left:60px' class='mensaje_error'>El campo "+campo+" debe tener mínimo "+cant+" caracteres</div>";
			//}else{
				//mensaje_exp +=	"<div style='padding-left:60px' class='mensaje_error'>"+msj+"</div>";
			//}//end if
			control_x.className = 'obligatorio';
			control_x.focus();
			cant = null;
			return true;
		}//end if
	}//end if
	
	if(rango_x != null && rango_x != 'undefined'){
		if(validar_rangos(valor_x,rango_x,min_x,max_x,campo,cmda,cmdb)){
			control_x.className = 'obligatorio';
			control_x.focus();
			return true;
		}//end if
	}//end if

	if(no_vacio(valor_x)){
		if((!eval_exp(expresiones(tipo),valor_x))){
			mensaje_exp += "<div style='padding-left:60px' class='mensaje_error'>El campo "+campo+" no es válido</div>";
			control_x.className = 'obligatorio';
			control_x.focus();
			return true;
		}else{
			control_x.className = 'forminput';		
		}// end if
	}

	function no_vacio(valor_x){		re = /.+/		var matchArray = re.exec(valor_x)
		if (matchArray){			return true		}// end if
		return false	}// end function	
	function eval_exp(patron_x,valor_x){		if (no_vacio(valor_x)){			var re = eval("/"+patron_x+"/i")			var matchArray = re.exec(valor_x)			if (matchArray){
				//control_x.className = 'obligatorio';
				//control_x.focus();				return true			}else{				return false			}// end if				}else{
			control_x.focus();
			control_x.className = 'obligatorio';
		}// end if
		return true			}// end function
	
	function expresiones(tipo){
		if(tipo!=null){
			var tipo_exp = new Array();
			tipo_exp[1] = "^[-]?\\d*\\.?\\d*$";
			tipo_exp[2] = "^[\\w-\\.]+@([\\w-]+\\.)+[\\w-]{2,4}$";
			tipo_exp[3] = "^([ a-zA-ZñÑáéíóúÁÉÍÓÚ ]+)$";
			tipo_exp[4] = "^[JVjv]-[0-9]{1,8}(-[0-9]){0,1}$";
			tipo_exp[5] = "^([ a-z0-9A-Z+.,_#%$*&@/\\-]+)$";
			tipo_exp[6] = "^([ a-zA-Z0-9]+)$";
			tipo_exp[7] = "^([0-9]+)$";
			tipo_exp[8] = "^[-]?\\d*$";
			tipo_exp[9] = "^([ a-zA-Z0-9 /ÁÉÍÓÚáéíóúñÑ]+)$";
			return tipo_exp[tipo];
		}//end if
	}//end if
	
	function validar_rangos(valor_x,rango,min,max,campo_x,cmda,cmdb){		var r_condicion = null;
		var mensaje = null;
		tipo_rango = parseInt(rango);		if (tipo_rango<1 || tipo_rango>9){			return false;		}// endif
			r_minimo = parseInt(min);		r_maximo = parseInt(max);
		r_comodin_a = parseInt(cmda)		r_comodin_b = parseInt(cmdb)
		r_valor = parseInt(valor_x)

		var mensaje = "El valor del campo "+campo_x+" "
		/*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 "
				mensaje += "debe estar entre " + r_minimo + " y " + r_maximo				break			case 2:					r_condicion = " r_valor >= r_minimo "				mensaje += "debe ser mayor o igual que " + r_minimo				break			case 3:				r_condicion = " r_valor <= r_maximo "				mensaje += "debe ser menor o igual que " + r_maximo				break			case 4:					r_condicion = " r_valor > r_minimo && r_valor < r_maximo "			
				mensaje += "debe ser mayor que " + r_minimo + " y menor que " + r_maximo				break			case 5:				r_condicion = " r_valor > r_minimo "				mensaje += "debe ser mayor que " + r_minimo				break			case 6:				r_condicion = " r_valor < r_maximo "
				mensaje += "debe ser menor que " + r_maximo				break			case 7:				r_condicion = " r_valor <= r_minimo || r_valor >= r_maximo "
				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 "
				mensaje += "debe menor que " + r_minimo + " o mayor que " + r_maximo											break
			case 9:
				r_condicion = " (r_valor == r_comodin_a || r_valor == r_comodin_b) || (r_valor >= r_minimo && r_valor <= r_maximo && r_valor) "
				mensaje += "debe menor que " + r_minimo + " o mayor que " + r_maximo											break		}// end switch

		if (!eval(r_condicion)){
			mensaje_exp += "<div style='padding-left:60px' class='mensaje_error'>"+mensaje+"</div>";
			return true		}// end if
		return false
	}// end function
	return false;
}// end function