

Validate.implement('validate_extra', {
				
		email: function(el){
			this.valid = true; this.msg = 0;
			var regEmail = /^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/;
			if(el.value.toUpperCase().match(regEmail)){
				this.valid = true;
			}else{
				this.valid = false;
				this.msg = ('Insira um Email válido');
			}
			return {valid: this.valid, msg: this.msg}
		},
		
		
		
		num: function(el) {
			this.valid = true; this.msg = 0;
			var regNum = /^-{0,1}\d+$/;
			if(el.value.match(regNum)){
				this.valid = true;
			}else{
				this.valid = false;
				this.msg = ('Insira um número válido');
			}
			return {valid: this.valid, msg: this.msg}
		},		
		
		
		data: function(el) {
			data = el.value;
			this.valid=true; this.msg=0;
			if (data == "hoje" || data == "HOJE") {
				n = new Date();
				if (n.getDate() < 10) dia = "0"+n.getDate(); else dia = n.getDate();
				if ((n.getMonth()+1) < 10) mes = "0"+(n.getMonth()+1); else mes = (n.getMonth()+1);
				data = (dia)+(mes)+(n.getUTCFullYear());
			}
			data = data.replace(/\D/g,"");
			if (data.length == 4) {now = new Date(); data = data + now.getUTCFullYear();}
			if (data.length == 6) {
				ano = data.substr(-2);
				if (ano > 30) data = data.replace(/(\d{4})(\d)/,"$1"+"19"+"$2");
				else data = data.replace(/(\d{4})(\d)/,"$1"+"20"+"$2");
			}
			data = data.replace(/(\d{2})(\d)/,"$1/$2");
			data = data.replace(/(\d{2})(\d)/,"$1/$2");
			var vetor = data.split("/");
			this.valid = true;
			var regData = /(0[1-9]|[12][0-9]|3[01])\/(0[1-9]|1[012])\/[12][0-9]{3}/;
				if (!data.match(regData)) this.valid = false;
				if (((vetor[1] == 4) || (vetor[1] == 6) || (vetor[1] == 9) || (vetor[1] == 11)) && (vetor[0] > 30 )) this.valid = false;
				if (vetor[1] == 2){
					 if ((vetor[0] > 28) && ((vetor[2] % 4 ) != 0)) this.valid = false;
					 if ((vetor[0] > 29) && ((vetor[2] % 4 ) == 0)) this.valid = false;
				}
				if (this.valid) el.value = data;
				else this.msg = ('Insira uma data válida');
			return {valid: this.valid, msg: this.msg}
		},




		hora: function(el){
			var horario = new Date();
			var regHora = /^([0-1][0-9]|[2][0-3])([0-5][0-9])$/;
			var regHora2 = /^([0-1][0-9]|[2][0-3]):([0-5][0-9])$/;
			this.valid = true; this.msg= 0;

			if (el.value.length == 3) {el.value = '0' + el.value.replace(/(\d{1})(\d{2})/,"$1:$2");}
			if (el.value.length == 2) {el.value = el.value + ':00';}
			if (el.value.length == 1) {el.value = '0' + el.value + ':00';}
			if (el.value.length == 4) {el.value = el.value.replace(/(\d{2})(\d{2})/, "$1:$2");}

			hora = el.value;
			if ((!hora.match(regHora)) && (!hora.match(regHora2))) {this.valid=false; this.msg=('O horário precisa ser no formato normal ou militar');}
			return {valid: this.valid, msg: this.msg}
		},	



		tam: function(el){
			var tamanho = 0;
			this.valid = true; this.msg = 0;
			el.getProperty('class').split(' ').each(function(el){
				if (el.match(/tam_*/)){
					tamanho = el.replace(/tam_(\d)$/,"$1")
				};
			});

			if (el.value.length < tamanho) {this.valid=false;this.msg=('Este campo precisa de no mínimo '+tamanho+' dígitos');}

			return {valid: this.valid, msg: this.msg}
		},




		eq: function(el){
			var equalizar = 0;
			this.valid = true; this.msg =0;
			el.getProperty('class').split(' ').each(function(el){
				if (el.match(/equal_*/)){	
					equalizar = el.replace(/equal_(\w+)$/, "$1");
				};
			});	

			if (el.value != $(equalizar).value) {this.valid=false;this.msg=('A confirmação não confere');}
			
			return {valid: this.valid, msg: this.msg}
		},



		din: function(el){
			this.valid=true; this.msg=0;
			var regDin = /^([0-9]{1,3}.([0-9]{3}.)*[0-9]{3}|[0-9]+)(,[0-9]{1,2})$/;
			var din = el.value;
			
			if (!din.match(/,/)) din = din+',00';
			else if (din.match(/,[0-9]$/)) din = din+'0';
			din = din.replace(/\./g,'');
			

			if(din.match(regDin)){
				din = din.split(',');
				real = din[0];
				centavo = din[1];
				
				
				for(cont = real.length; (cont -= 3) >= 1;)
					real = real.substr(0, cont) + "." + real.substr(cont);
				
				el.value = real+','+centavo;

				
				this.valid = true;
			}else{
				this.valid = false;
				this.msg = ('Insira um valor em Reais válido');
			}
			return {valid: this.valid, msg: this.msg}
			
		},




		cpf: function(el){
			this.valid=true; this.msg=0;
			var s=el.value.replace(/\D/g,"");
			if (s.length==11){
				s=s.replace(/(\d{3})(\d)/,"$1.$2");
				s=s.replace(/(\d{3})(\d)/,"$1.$2");
				s=s.replace(/(\d{3})(\d)/,"$1-$2");
				el.value=s;
			}else{
				this.valid = false; 				
			}
			
			if (this.valid==false) this.msg = ('O CPF digitado é inválido'); 
		   return {valid: this.valid, msg: this.msg}
		},


		moost: function(el){
			this.valid = true; this.msg=0;
			if (el.value.replace(/(<([^>]+)>)/ig,'').replace(/&nbsp;/gi,'') == ''){
				this.valid = false;
				this.msg = ('Item Obrigatório');
			}
			return {valid: this.valid, msg: this.msg}
		}



});

