
	//FUNÇÕES PARA FORMATAR VALOR
	//---------------------------------------------------------------------
	function FormataValor(objeto,teclapres,tammax,decimais) 
	{
		var tecla			= teclapres.keyCode;
		var tamanhoObjeto	= objeto.value.length;
		if ((tecla == 8) && (tamanhoObjeto == tammax))
		{
			tamanhoObjeto = tamanhoObjeto - 1 ;
		}
		if (( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ) && ((tamanhoObjeto+1) <= tammax))
		{
			vr	= objeto.value;
			vr	= vr.replace( "/", "" );
			vr	= vr.replace( "/", "" );
			vr	= vr.replace( ",", "" );
			vr	= vr.replace( ".", "" );
			vr	= vr.replace( ".", "" );
			vr	= vr.replace( ".", "" );
			vr	= vr.replace( ".", "" );
			tam	= vr.length;
			if (tam < tammax && tecla != 8)
			{
				tam = vr.length + 1 ;
			}
			if ((tecla == 8) && (tam > 1))
			{
				tam = tam - 1 ;
				vr = objeto.value;
				vr = vr.replace( "/", "" );
				vr = vr.replace( "/", "" );
				vr = vr.replace( ",", "" );
				vr = vr.replace( ".", "" );
				vr = vr.replace( ".", "" );
				vr = vr.replace( ".", "" );
				vr = vr.replace( ".", "" );
			}
			if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 )
			{
				if (decimais > 0)
				{
					if ( (tam <= decimais) )
					{ 
						objeto.value = ("0," + vr) ;
					}
					if( (tam == (decimais + 1)) && (tecla == 8))
					{
						objeto.value = vr.substr( 0, (tam - decimais)) + ',' + vr.substr( tam - (decimais), tam ) ;	
					}
					if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) == "0"))
					{
						objeto.value = vr.substr( 1, (tam - (decimais+1))) + ',' + vr.substr( tam - (decimais), tam ) ;
					}
					if ( (tam > (decimais + 1)) && (tam <= (decimais + 3)) &&  ((vr.substr(0,1)) != "0"))
					{
						objeto.value = vr.substr( 0, tam - decimais ) + ',' + vr.substr( tam - decimais, tam ) ; 
					}
					if ( (tam >= (decimais + 4)) && (tam <= (decimais + 6)) )
					{
						objeto.value = vr.substr( 0, tam - (decimais + 3) ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
					}
					if ( (tam >= (decimais + 7)) && (tam <= (decimais + 9)) )
					{
						objeto.value = vr.substr( 0, tam - (decimais + 6) ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
					}
					if ( (tam >= (decimais + 10)) && (tam <= (decimais + 12)) )
					{
						objeto.value = vr.substr( 0, tam - (decimais + 9) ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
					}
					if ( (tam >= (decimais + 13)) && (tam <= (decimais + 15)) )
					{
						objeto.value = vr.substr( 0, tam - (decimais + 12) ) + '.' + vr.substr( tam - (decimais + 12), 3 ) + '.' + vr.substr( tam - (decimais + 9), 3 ) + '.' + vr.substr( tam - (decimais + 6), 3 ) + '.' + vr.substr( tam - (decimais + 3), 3 ) + ',' + vr.substr( tam - decimais, tam ) ;
					}
				}
				else if(decimais == 0)
				{
					if ( tam <= 3 )
					{ 
						objeto.value = vr ;
					}
					if ( (tam >= 4) && (tam <= 6) )
					{
						if(tecla == 8)
						{
							objeto.value = vr.substr(0, tam);
							window.event.cancelBubble = true;
							window.event.returnValue = false;
						}
						objeto.value = vr.substr(0, tam - 3) + '.' + vr.substr( tam - 3, 3 ); 
					}
					if ( (tam >= 7) && (tam <= 9) )
					{
						if(tecla == 8)
						{
							objeto.value = vr.substr(0, tam);
							window.event.cancelBubble = true;
							window.event.returnValue = false;
						}
						objeto.value = vr.substr( 0, tam - 6 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
					}
					if ( (tam >= 10) && (tam <= 12) )
					{
						if(tecla == 8)
						{
							objeto.value = vr.substr(0, tam);
							window.event.cancelBubble = true;
							window.event.returnValue = false;
						}
						objeto.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ); 
					}
	
					if ( (tam >= 13) && (tam <= 15) )
					{
						if(tecla == 8)
						{
							objeto.value = vr.substr(0, tam);
							window.event.cancelBubble = true;
							window.event.returnValue = false;
						}
						objeto.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '.' + vr.substr( tam - 6, 3 ) + '.' + vr.substr( tam - 3, 3 ) ;
					}			
				}
			}
		}
		else if((window.event.keyCode != 8) && (window.event.keyCode != 9) && (window.event.keyCode != 13) && (window.event.keyCode != 35) && (window.event.keyCode != 36) && (window.event.keyCode != 46))
			{
				window.event.cancelBubble = true;
				window.event.returnValue = false;
			}
	}

	//FUNÇÕES PARA MUDAR DIV
	//---------------------------------------------------------------------
	function get$() {
		var elements = new Array();
		for (var i = 0; i < arguments.length; i++) {
			var element = arguments[i];
			if (typeof element == 'string')
				element = document.getElementById(element);
			if (arguments.length == 1)
				return element;
			elements.push(element);
		}
		return elements;
	}
	
	function mudarDiv(element) {
		var e = get$(element);
		if (e) {
			e.style.display = ((e.style.display != 'block') ? 'block' : 'none');
		}
	}
	
	function MostrarDiv(nomeDiv) {
	document.getElementById(nomeDiv).style.display="block";
	}
	
	function EsconderDiv(nomeDiv) {
	document.getElementById(nomeDiv).style.display="none";
	}
	
	
	//FUNÇÕES PARA VALIDAR FORMULÁRIO
	//---------------------------------------------------------------------
	function verifica_form(form) {
	var passed = false;
	var ok = false
	var campo
	for (i = 0; i < form.length; i++) {
	  campo = form[i].name;
	  if (form[i].getAttribute("df_verificar") == "sim") {
		if (form[i].type == "text"  | form[i].type == "textarea" | form[i].type == "select-one") {
		  if (form[i].value == "" | form[i].value == "http://") {
			form[campo].className='campo_alerta'
			form[campo].focus();
			alert("Preencha corretamente o campo em destaque!");
			return passed;
			stop;
		  }
		}
		else if (form[i].type == "radio") {
		  for (x = 0; x < form[campo].length; x++) {
			ok = false;
			if (form[campo][x].checked) {
			  ok = true;
			  break;
			}
		  }
		  if (ok == false) {
			form[campo][0].focus();
			form[campo][0].select();
			alert("Informe uma das opcões");
			return passed;
			stop;
		  }
		}
		var msg = ""
		if (form[campo].getAttribute("df_validar") == "cpf") msg = checa_cpf(form[campo].value);
		if (form[campo].getAttribute("df_validar") == "cnpj") msg = checa_cnpj(form[campo].value);
		if (form[campo].getAttribute("df_validar") == "cpf_cnpj") {
		  msg = checa_cpf(form[campo].value);
		  if (msg != "") msg = checa_cnpj(form[campo].value);
		}
		if (form[campo].getAttribute("df_validar") == "email") msg = checa_email(form[campo].value);
		if (form[campo].getAttribute("df_validar") == "numerico") msg = checa_numerico(form[campo].value);
		if (msg != "") {
		  if (form[campo].getAttribute("df_validar") == "cpf_cnpj") msg = "informe corretamente o número do CPF ou CNPJ";
		  form[campo].className='campo_alerta'
		  form[campo].focus();
		  form[campo].select();
		  alert(msg);
		  return passed;
		  stop;
		}
	  }
	}
	passed = true;
	return passed;
	}
	
	function desabilita_cor(campo) {
	campo.className='campos_formulario'
	}
	
	function checa_numerico(String) {
	var mensagem = "Este campo aceita somente números"
	var msg = "";
	if (isNaN(String)) msg = mensagem;
	return msg;
	}
	
	function checa_email(campo) {
	var mensagem = "Informe corretamente o email"
	var msg = "";
	var email = campo.match(/(\w+)@(.+)\.(\w+)$/);
	if (email == null){
	  msg = mensagem;
	  }
	return msg;
	}
	
	function mascara_data(data){ 
	var mydata = ''; 
	mydata = mydata + data; 
	if (mydata.length == 2){ 
	mydata = mydata + '/'; 
	} 
	if (mydata.length == 5){ 
	mydata = mydata + '/'; 
	} 
	return mydata; 
	} 
	
	function verifica_data(data) { 
	if (data.value != "") {
	dia = (data.value.substring(0,2));
	mes = (data.value.substring(3,5)); 
	ano = (data.value.substring(6,10)); 
	situacao = ""; 
	if ((dia < 01)||(dia < 01 || dia > 30) && (  mes == 04 || mes == 06 || mes == 09 || mes == 11 ) || dia > 31) { 
	situacao = "falsa"; 
	} 
	if (mes < 01 || mes > 12 ) { 
	situacao = "falsa"; 
	}
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) { 
	situacao = "falsa"; 
	} 
	if (situacao == "falsa") { 
	data.focus();
	data.select();
	alert("Data inválida!"); 
	}
	} 
	}

