// JavaScript Document
	function valor_informativo(texto, campo, evento){
		//onBlur="valor_informativo(' Empresa de manutenção', this, 'b');" onfocus="valor_informativo(' Empresa de manutenção', this, 'f');"
		if ((campo.value == texto) && (evento == 'f')){
			campo.value='';
		} else {
			if ((campo.value == '') && (evento == 'b')) {
				campo.value=texto;
			}
		}
	}

// JavaScript Document
	function isNum( caractere ) 
	{ 
		var strValidos = "0123456789" 
		if ( strValidos.indexOf( caractere ) == -1 ) 
			return false; 
		return true; 
	}
	
	function isValid(valor)
	{
		//alert("valido: "+valor);
		var LEFT = 37;
		var RIGHT = 39;
		var HOM = 36;
		var END = 35;
//		var DEL = 46;
		var INS = 45;
		var CAPS = 20;
		var SHIFT = 16;
		var BACKSPACE = 8;
		var TAB = 0;
		if ((valor == LEFT) || (valor == RIGHT) || (valor == HOM) || (valor == END) || (valor == INS) || (valor == CAPS) || (valor == SHIFT) || (valor == BACKSPACE) || (valor == TAB))
			return(true);
		return(false);
	}

	function limpa_campoNum(valor)
	{
		t = valor.length;
		novovalor='';
		for(i=0; i<=t-1; i++)
		{
			if (isNum(valor.charAt(i)))
			{
				novovalor += valor.charAt(i);
			}
		}
		return(novovalor);
	}
	function mascara_cpf(campo, event)
  	{
		var key; 
		var tecla;
		if(navigator.appName.indexOf("Netscape")!= -1) 
			tecla= event.which; 
		else 
			tecla= event.keyCode;
		key = String.fromCharCode(tecla);

		if ( (isNum(key)) || (isValid(tecla)) )
		{
			if (isNum(key)){
				return(iteracao_cpf(campo));
			} else {
					return(true);
			}
		}
		else
		{
			return(false);
		}
	}
	function iteracao_cpf(campo){
		cpf = limpa_campoNum(campo.value);
		t = cpf.length;
		if (t > 11)
			t = 11;
		novocpf = "";
		for(i=0; i<=t-1; i++)
		{
			if (i==3)
				novocpf+=".";
			if (i==6)
				novocpf+=".";
			if (i==9)
				novocpf+="-";
			novocpf+=cpf.charAt(i);
		}
		campo.value = novocpf;
		return(true);
	}





	function mascara_cnpj(campo, event)
  	{
		var key; 
		var tecla;
		if(navigator.appName.indexOf("Netscape")!= -1) 
			tecla= event.which; 
		else 
			tecla= event.keyCode;
		key = String.fromCharCode(tecla);

		if ( (isNum(key)) || (isValid(tecla)) )
		{
			if (isNum(key)){
				return(iteracao_cnpj(campo));
			} else {
					return(true);
			}
			
		}
		else
		{
			return(false);
		}
	}
	function iteracao_cnpj(campo){
		cnpj = limpa_campoNum(campo.value);
		t = cnpj.length;
		//alert(t);
		if (t > 14)
			t = 14;
		novocnpj = "";
		for(i=0; i<=t-1; i++)
		{
			novocnpj+=cnpj.charAt(i);
			if (i==1)
				novocnpj+=".";
			if (i==4)
				novocnpj+=".";
			if (i==7)
				novocnpj+="/";
			if (i==11)
				novocnpj+="-";
		}
		campo.value = novocnpj;
		return(true);
	}


	function mascara_peso(campo, event)
  	{
		var key; 
		var tecla;
		if(navigator.appName.indexOf("Netscape")!= -1) 
			tecla= event.which; 
		else 
			tecla= event.keyCode;
		key = String.fromCharCode(tecla);
		if ((isNum(key)) || (isValid(tecla)) )
		{
			if (isNum(key)){
				return(iteracao_peso(campo));
			} else {
					return(true);
			}
		}
		else
		{
			return(false);
		}
	} 
	function iteracao_peso(campo){
		peso = limpa_campoNum(campo.value);
		t = peso.length;
		a = t;
		//if (tecla == 0)
		a--;
		novopeso = "";
		for(i=0; i<=t-1; i++)
		{
			novopeso+=peso.charAt(i);
			if (i==a-2)
				novopeso+=",";
			if (i==a-5)
				novopeso+=".";
			if (i==a-8)
				novopeso+=".";
			if (i==a-11)
				novopeso+=".";
			if (i==a-14)
				novopeso+=".";
			if (i==a-17)
				novopeso+=".";
			if (i==a-20)
				novopeso+=".";
		}
		campo.value = novopeso;
		return(true);
	}


	function mascara_preco(campo, event)
  	{
		var key; 
		var tecla;
		if(navigator.appName.indexOf("Netscape")!= -1) 
			tecla= event.which; 
		else 
			tecla= event.keyCode;
		key = String.fromCharCode(tecla);

		if ((isNum(key)) || (isValid(tecla)) )
		{
			if (isNum(key)){
				return(iteracao_preco(campo));
			} else {
					return(true);
			}
		}
		else
		{
			return(false);
		}
	}
	
	function iteracao_preco(campo){
		preco = limpa_campoNum(campo.value);
		t = preco.length;
		a = t;
		//if (tecla == 0)
		a--;
		novopreco = "";
		for(i=0; i<=t-1; i++)
		{
			novopreco+=preco.charAt(i);
			if (i==a-1)
				novopreco+=",";
			if (i==a-4)
				novopreco+=".";
			if (i==a-7)
				novopreco+=".";
			if (i==a-10)
				novopreco+=".";
			if (i==a-13)
				novopreco+=".";
			if (i==a-16)
				novopreco+=".";
			if (i==a-19)
				novopreco+=".";
		}
		campo.value = novopreco;
		return(true);
	}
	
	
	function mascara_data(campo, event)
  	{
		var key; 
		var tecla;
		if(navigator.appName.indexOf("Netscape")!= -1) 
			tecla= event.which; 
		else 
			tecla= event.keyCode;
		key = String.fromCharCode(tecla);

		if ( (isNum(key)) || (isValid(tecla)) )
		{
			if (isNum(key)){
				return(iteracao_data(campo));
			} else {
					return(true);
			}
			
		}
		else
		{
			return(false);
		}
	} 
	
	function iteracao_data(campo){
		data = limpa_campoNum(campo.value);
		t = data.length;
		if (t > 8)
			t = 8;
		novodata = "";
		for(i=0; i<=t-1; i++)
		{
			if (i==2)
				novodata+="/";
			if (i==4)
				novodata+="/";
			novodata+=data.charAt(i);
		}

		campo.value = novodata;
		return(true);
	}

	function mascara_data_hora(campo, event)
  	{
		var key; 
		var tecla;
		if(navigator.appName.indexOf("Netscape")!= -1) 
			tecla= event.which; 
		else 
			tecla= event.keyCode;
		key = String.fromCharCode(tecla);

		if ( (isNum(key)) || (isValid(tecla)) )
		{
			if (isNum(key)){
				return(iteracao_data_hora(campo));
			} else {
					return(true);
			}
			
		}
		else
		{
			return(false);
		}
	} 

	function iteracao_data_hora(campo){
		data_hora = limpa_campoNum(campo.value);
		t = data_hora.length;
		if (t > 12)
			t = 12;
		novodata_hora = "";
		for(i=0; i<=t-1; i++)
		{
			if (i==2)
				novodata_hora+="/";
			if (i==4)
				novodata_hora+="/";
			if (i==8)
				novodata_hora+=" ";
			if (i==10)
				novodata_hora+=":";

			novodata_hora+=data_hora.charAt(i);
		}

		campo.value = novodata_hora;
		return(true);
	}
	
	function mascara_hora(campo, event)
  	{
		var key; 
		var tecla;
		if(navigator.appName.indexOf("Netscape")!= -1) 
			tecla= event.which; 
		else 
			tecla= event.keyCode;
		key = String.fromCharCode(tecla);

		if ( (isNum(key)) || (isValid(tecla)) )
		{
			if (isNum(key)){
				return(iteracao_hora(campo));
			} else {
					return(true);
			}
			
		}
		else
		{
			return(false);
		}
	} 

	function iteracao_hora(campo){
		hora = limpa_campoNum(campo.value);
		t = hora.length;
		if (t > 4)
			t = 4;
		novohora = "";
		for(i=0; i<=t-1; i++)
		{
			if (i==2)
				novohora+=":";
			novohora+=hora.charAt(i);
		}
		campo.value = novohora;
		return(true);
	}

	

	function mascara_cep(campo, event)
  	{
		var key; 
		var tecla;
		if(navigator.appName.indexOf("Netscape")!= -1) 
			tecla= event.which; 
		else 
			tecla= event.keyCode;
		key = String.fromCharCode(tecla);
		var r = true;

		if ( (isNum(key)) || (isValid(tecla)) )
		{
			if (isNum(key)){
				return(iteracao_cep(campo));
			} else {
					return(true);
			}
		}
		else
		{
			r = false;
		}
		return(r);

	}
	
	function iteracao_cep(campo){
		cep = limpa_campoNum(campo.value);
		t = cep.length;
		if (t > 8)
			t = 8;
		novocep = "";
		for(i=0; i<=t-1; i++)
		{
			if (i==5)
				novocep+="-";
			novocep+=cep.charAt(i);
		}
		campo.value = novocep;
		return(true);
	}
	
function mascara_int(campo, event)
  	{
		var key; 
		var tecla;
		if(navigator.appName.indexOf("Netscape")!= -1) 
			tecla= event.which; 
		else 
			tecla= event.keyCode;
		key = String.fromCharCode(tecla);
		//alert(isValid(tecla));
		if ( ( isNum(key) ) || ( isValid(tecla) ) )
		{
			return(true);
		} else {
			return(false);
		}

	}


	function mascara_telefone(campo, event, tipo)
  	{
		var key; 
		var tecla;
		if(navigator.appName.indexOf("Netscape")!= -1) 
			tecla= event.which; 
		else 
			tecla= event.keyCode;
		key = String.fromCharCode(tecla);
		var r = true;

		if ( (isNum(key)) || (isValid(tecla)) )
		{
			telefone = limpa_campoNum(campo.value);
			t = telefone.length;
			switch (tipo) {
			case "fixo":
				tmax = 9;
				pos_traco = 5;
				break;
			case "celular":
				tmax = 10;
				pos_traco = 6;
				break;
			}
			if (t > tmax)
				t = tmax;
			novotelefone = "";
			for(i=0; i<=t-1; i++)
			{
				if (i==0)
					novotelefone+="(";
				if (i==2)
					novotelefone+=") ";
				if (i==pos_traco)
					novotelefone+="-";
				novotelefone+=telefone.charAt(i);
			}
			campo.value = novotelefone;
		}
		else
		{
			r = false;
		}
		return(r);

	}
