	/*
		Abre popup no centro	
	*/
	function abreCentro(pagina,nomeJanela,largura,altura) {
			
			var width = screen.width;
			var height = screen.height;
			
			var x = (width / 2) - (largura / 2);
			var y = (height / 2) - (altura / 2);
		window.open(pagina,nomeJanela,'width='+largura+ ',height='+altura+ ',left = '+x+',top='+y+',scrollbars=yes,resizable=no,menubar=no');
	}

	/*
		funcao de validação de email
	*/
	function validaEmail(email)
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (filter.test(email)) return true;
		else return false;
	}
	
	/*
		funcao de validação de data
	*/
	function validaData(data){
		
		var reDate = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/\d{4}$/;
		
		if (reDate.test(data))
			return true;
		else
			return false;
	}
	
	/*
		funcao de validação de hora
	*/
	function validaHora(hora){
		
		var reTime = /^([0-1]\d|2[0-3]):[0-5]\d$/;
		
		if (reTime.test(hora))
			return true;
		else
			return false;
	}
	
	
	/*
		função para remover espaços no inicio e fim da string
	*/
	function trim(str)
	{
		return str.replace(/^\s*|\s*$/g,"");
	}

	/*
		função restringeTeclas
		registringe as teclas digitadas num campo ao tipo especificado
		chamar essa função sempre com eventos onKey(Press|Down|Up)
		
		parametros
		-----------------------------------------------------------------
		obj 		->	objeto que sofreu a ação
		tipo		->	tipo que será seguido (numeros, letrasMaiusculas, letrasMinusculas)
		
	*/


	function restringeTeclas (obj,tipo) {
		 //var caract = new RegExp(/^[0-9 . , /]+$/i); //Para aceitar mais caracteres.
		if (tipo == 'numeros')
			var caract = new RegExp(/^[0-9]+$/i); 
		if (tipo == 'letrasMaisculas')
			var caract = new RegExp(/^[A-Z]+$/i); 
		if (tipo == 'letrasMinusculas')
			var caract = new RegExp(/^[a-z]+$/i);
		var caract = caract.test(String.fromCharCode(event.keyCode));
		if(!caract){
			event.keyCode=0;
		 	return;
		}
	}
	
	/*
		função validaFormato
		valida uma string com base em um padrão ER
		
		parametros
		-----------------------------------------------------------------
		valor 		->	valor a ser validado
		tipo		->	tipo que será seguido (numeros, letrasMaiusculas, letrasMinusculas)
		
	*/

	function validaFormato (valor,tipo) {
		var tipos = new Array();
		tipos['hora'] = new RegExp(/^([01][0-9]|2[0-3]):([0-5][0-9])/); 
		tipos['dataBr'] = new RegExp(/^([0][1-9]|[12][0-9]|3[0-1])\/([0][1-9]|[1][0-2])\/([0-9]{4})/);
		tipos['cnpj'] = new RegExp(/^[0-9]{2}\.[0-9]{3}\.[0-9]{3}\/[0-9]{4}-[0-9]{2}/);		
		if (tipos[tipo] != null) {
			var teste = tipos[tipo].test(valor);
			if (teste)
				return true;
			else
				return false;
		}
	}

	//formatar nº com casas decimais
	function formataNumero(obj)	{
		if (obj != null) {
			var numero = obj.value;
			// tira as marcas de formacao
			numero = numero.replace(",","");

			while (numero.lastIndexOf("\.") != '-1')
				numero = numero.replace("\.","");

			// formata o numero
			var tamanho = numero.length;
			var aux = "";
			var j = 1;			
			for (x = 0; x <= tamanho ; x++) {
				var pos = tamanho-x;
				if (x == 3)
					aux = numero.charAt(pos) + ',' + aux;
				else {
					if (x >= 3) {
						if (j == 3) {
							aux = numero.charAt(pos) + '.' + aux;
							j = 1;
						} else {
							aux = numero.charAt(pos) + aux;
							j++;							
						}
					} else
						aux = numero.charAt(pos) + aux;
				}
			}
			obj.value = aux;
		}
	} 	

function format(value,format)
{
	value = value.replace(/\D/g,"");
	var result="";
	
	if(format.length < value.length)
		return value;
	
	for(i=0,j=0;(i<format.length)&&(j<value.length);i++)
	{
		var ch = format.charAt(i);
		if(ch == '#')
		{
			result += value.charAt(j++);
			continue;
		}
		result += ch;
	}
	return result;
}