/**
		//campos com valor default 0 ou '' e que precisam ser selecionados.
		add_not_zero(nomecampo, descricaonome) 
		//campos com valor que nao podem ficar vazios.
		add_not_null(nomecampo, descricaonome) 
		//campos com valor num?rico.
		add_integer(nomecampo, descricaonome) 
		//campos texto com tamanhos entre minimo e maximo inclusives.
		add_varchar(nomecampo, minimo,maximo,descricaonome) 
		//campos radio ou checkbox em q ao menos 1 opcao deve ser selecionada.
		add_checkbox_any(nomecampo, descricaonome) 		
		
			
*/	
  function add_checkbox_any(nome, campo){
			this.v_nome[this.n]=nome;
			this.v_tipo[this.n]='CK';
			this.v_min[this.n]=1;
			this.v_campo[this.n]=campo;
			this.v_max[this.n++]=1;	  	
  }



   function add_varchar (nome,  min, max, campo){
			this.v_nome[this.n]=nome;
			this.v_tipo[this.n]='V';
			this.v_min[this.n]=min;
			this.v_campo[this.n]=campo;
			this.v_max[this.n++]=max;			
		}
		
  function add_not_null (nome, campo){
			this.v_nome[this.n]=nome;
			this.v_tipo[this.n]='V';
			this.v_min[this.n]=1;
			this.v_campo[this.n]=campo;
			this.v_max[this.n++]=10000;		
		}	
  function add_not_zero (nome, campo){
			this.v_nome[this.n]=nome;
			this.v_tipo[this.n]='X';
			this.v_min[this.n]=1;
			this.v_campo[this.n]=campo;
			this.v_max[this.n++]=10000;		
		}			
  function add_integer (nome, campo){
			this.v_nome[this.n]=nome;
			this.v_tipo[this.n]='I';
			this.v_min[this.n]=0;
			this.v_campo[this.n]=campo;
			this.v_max[this.n++]=100000;		
		}				


		function v_varchar (txt, x){
			
			if (txt.length < this.v_min[x]){
				if (this.v_min[x] == 1)
					return "Campo "+this.v_campo[x]+" deve ser preenchido\n";
				return "Campo "+this.v_campo[x]+" precisa ter no minimo "+this.v_min[x]+" caracteres\n";
			}
			if (txt.length > this.v_max[x])
				return "Campo "+this.v_campo[x]+" precisa ter no maximo "+this.v_max[x]+" caracteres\n";
			return "";
		}

		function v_integer (txt, x){
			var reDigits = /^\d+$/;
			if (!reDigits.test(txt))
				return "Campo "+this.v_campo[x]+" precisa ter valor inteiro\n";
			return "";
		}

		function v_x (txt, x){
			if (txt == '0' || txt == '')
				return "Campo "+this.v_campo[x]+" precisa ser selecionado\n";
			return "";
		}		

		function v_ckbox (txt, x){
			var no=0; 
			var i=0;
			while(i<txt.length){
	    		if ( txt[i].checked ) {
					no=1;
	 			}
	 			i++;
	 		} 				
			if (no==0)
				return "Campo "+this.v_campo[x]+" precisa ser selecionado\n";
			return "";
		}		
				
/*		function validate (){
			var erro='';
			
			for(var i=0;i<this.n; i++){
				var tmp = erro;
				if (this.v_tipo[i]=='V'){
					erro += this.v_varchar(document.getElementsByName(this.v_nome[i]).item(0).value, i);
				}
				if (this.v_tipo[i]=='I'){
					erro += this.v_integer(document.getElementsByName(this.v_nome[i]).item(0).value, i);								
				}
				if (this.v_tipo[i]=='X'){
					erro += this.v_x(document.getElementsByName(this.v_nome[i]).item(0).value, i);								
				}
				if (this.v_tipo[i]=='CK'){
					erro += this.v_ckbox(document.getElementsByName(this.v_nome[i]), i);								
				}
				
				var cord = "black";
				if (tmp != erro){ cord='red';}
				var objs = document.getElementsByName(this.v_nome[i]);
				for (var k=0; k<objs.length; k++){
					if (this.v_nome[i]=='acdSexo') alert('');
					objs.item(k).style.borderColor=cord;
				}
				
			}
			if (erro != ''){
				alert(erro);
				return false;
			}	
			return true;		
		}	*/
		
	function validate (){
			var erro='';
			
			for(var i=0;i<this.n; i++){
				var tmp = erro;
				if (this.v_tipo[i]=='V'){
					erro += this.v_varchar(document.getElementsByName(this.v_nome[i]).item(0).value, i);
				}
				if (this.v_tipo[i]=='I'){
					erro += this.v_integer(document.getElementsByName(this.v_nome[i]).item(0).value, i);								
				}
				if (this.v_tipo[i]=='X'){
					erro += this.v_x(document.getElementsByName(this.v_nome[i]).item(0).value, i);								
				}
				if (this.v_tipo[i]=='CK'){
					erro += this.v_ckbox(document.getElementsByName(this.v_nome[i]), i);								
				}
				
				var cord = "black";
				if (tmp != erro){ cord='red';}
				var objs = document.getElementsByName(this.v_nome[i]);
				for (var k=0; k<objs.length; k++){
					if (this.v_nome[i]=='acdSexo') alert('');
					objs.item(k).style.borderColor=cord;
				}
				
			}
			if (erro != ''){
				alert(erro);
				return false;
			}	
			return true;		
		}		
		
		
	


	function validation(){

		this.v_nome  =  new Array(100);
		this.v_tipo  =  new Array(100);
		this.v_min   =  new Array(100);
		this.v_max   =  new Array(100);
		this.v_campo =  new Array(100);
		
		this.n=0;
		
		this.add_checkbox_any = add_checkbox_any;
		this.add_varchar =add_varchar;
		this.add_not_null =add_not_null;
		this.add_not_zero =add_not_zero;		
		this.add_integer =add_integer;
		this.v_varchar = v_varchar;
		this.v_integer = v_integer;
		this.v_ckbox = v_ckbox;
		this.v_x = v_x;


		this.validate = validate;		
		
	}