
/*--------------------*/
/* Movimentos Img     */
/*--------------------*/




/*--------------------*/
/* Select all         */
/*--------------------*/
function select_all(obj){
	obj.focus();
	obj.select();
}

/*--------------------*/
/* Funções de Valid   */
/*--------------------*/

function checkField(field){
  if (field.value==null||field.value==""){field.focus(); return false;}else{return true;}
}

function checkText(field){
  if (field.value==null||field.value==""){return false;}else{return true;}
}


function checkEmail(myForm) {
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(myForm.value)){
		return (true);
	}
	myForm.focus();
	return (false);
}

function checkData(myForm){
	myForm.value = myForm.value.replace(/\D*\.*\-*\/*/g,'');
	var express = new RegExp('^([0-9]{8})$','');
	if (express.test(myForm.value)){
		return (true);
	}
	myForm.focus();
	return (false);
}

function checkDataHora(myForm){
	myForm.value = myForm.value.replace(/\D*\.*\-*\/*/g,'');
	var express = new RegExp('^([0-9]{14})$','');
	if (express.test(myForm.value)){
		return (true);
	}
	myForm.focus();
	return (false);
}

function checkNum(myForm,dig){
	var express = new RegExp("^([0-9]{"+dig+"})$",'');
	if (express.test(myForm.value)){
		return (true);
	}
	myForm.focus();
	return (false);
}

function checkCPF(cpf){
	erro = new String;
	cpf.value = cpf.value.replace(/\D*\.*\-*/g,'');

	if (cpf.value.length == 11){       
		var nonNumbers = /\D/;
        
		if (nonNumbers.test(cpf.value)){
			erro = "A verificacao de CPF suporta apenas números!"; 
		}else{
			if (cpf.value == "00000000000" || cpf.value == "11111111111" || cpf.value == "22222222222" || cpf.value == "33333333333" || cpf.value == "44444444444" || cpf.value == "55555555555" || cpf.value == "66666666666" || cpf.value == "77777777777" || cpf.value == "88888888888" || cpf.value == "99999999999") {
				erro = "Número de CPF inválido!"
			}

			var a = [];
			var b = new Number;
			var c = 11;
			
			for (i=0; i<11; i++){
				a[i] = cpf.value.charAt(i);
				if (i < 9) b += (a[i] * --c);
			}
			
			if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
			
			b = 0;
			c = 11;
			
			for (y=0; y<10; y++) b += (a[y] * c--);
			
			if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
			if ((cpf.value.charAt(9) != a[9]) || (cpf.value.charAt(10) != a[10])){
				erro = "Número de CPF inválido.";
			}
		}
	}else{
		if(cpf.value.length == 0){cpf.focus(); return false;}else{erro = "Número de CPF inválido.";}
	}
	
	if (erro.length > 0) {
		cpf.focus();
		return false;
	}
	return true;    
 }
	
	
function checkFone(phone){
	var phone2 = /^(\({0,1}\d{2,3}\){0,1})(\s{0,1}|\-{0,1}|\.{0,1})\d{1,2}(\s{0,1}|\-{0,1}|\.{0,1})\d{2}(\s{0,1}|\-{0,1}|\.{0,1})\d{2}(\s{0,1}|\-{0,1}|\.{0,1})\d{2}$/; 

	if (phone.value.match(phone2)) {
		phone.value = phone.value.replace(/\D*/g,'');
   		return true;
 	} else {
		phone.focus();
 		return false;
 	}
}

function checkCEP(cep){
	erro = new String;
	cep.value = cep.value.replace(/\D*/g,'');

	if (cep.value.length == 8){       
		var nonNumbers = /\D/;
        if (nonNumbers.test(cep.value)){
			erro = "A verificacao de cep suporta apenas números!"; 
		}
	}else{
		if(cep.value.length == 0){return false;}else{erro = "Número de cep inválido.";}
	}
	if (erro.length > 0) {
		cep.focus();
		return false;
	}
	return true;    
 }
	
	
/*--------------------*/
/* Coleta Endereço    */
/*--------------------*/


function coletaCep(cep){
	var num = cep.value.replace(/\D*\.*\-*/g,'');
	$.ajax({
		type: 'GET',
		url: 'inc/buscarendereco.php',
		data: 'cep='+num,
		success: function(response){
			response = unescape(response);
			var response = response.split("||");
			$('#endereco').val(response[0]);
			$('#bairro').val(response[1]);
			$('#cidade').val(response[2]);
			$('#estado').val(response[3]);
			if(response[0]!=''){$('#num').focus();}
		}
	});
}
	

/*--------------------*/
/* Select all         */
/*--------------------*/
	function select_all(obj){
		obj.focus();
		obj.select();
	}

	function select_all_del(obj){
		obj.focus();
		obj.value = '';
	}

	function obj_hide(obj){
		$.obj.hide();
	}

/*--------------------*/
/* Controla Tamanho   */
/*--------------------*/

function tamanho(texto,lim){
	var y = true;
	var tam = texto.value.length;
	if (tam>lim){
		alert("Você inseriu muitos caracteres: " + tam +
			"\nInsira no máximo: "+lim);
		texto.focus();
		y = false;
	}
}


