	//Mascaras para CEP e Telefone (e outros)
	function formatar(src, mask) {
      var i = src.value.length;
      var saida = mask.substring(0,1);
      var texto = mask.substring(i)
      if (texto.substring(0,1) != saida) {
        src.value += texto.substring(0,1);
      }
    }


	//Formatação do campo monetario
    function FormataValor(campo,tammax,teclapres) {
    var tecla = teclapres.keyCode;
    vr = document.cadastro[campo].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 = tam - 1; }
    if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
    if ( tam <= 2 ){
      document.cadastro[campo].value = vr; }
    if ( (tam > 2) && (tam <= 5) ){
      document.cadastro[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ); }
    if ( (tam >= 6) && (tam <= 8) ){
      document.cadastro[campo].value = vr.substr( 0, tam - 5 ) + '' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
    if ( (tam >= 9) && (tam <= 11) ){
      document.cadastro[campo].value = vr.substr( 0, tam - 8 ) + '' + vr.substr( tam - 8, 3 ) + '' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
    if ( (tam >= 12) && (tam <= 14) ){
      document.cadastro[campo].value = vr.substr( 0, tam - 11 ) + '' + vr.substr( tam - 11, 3 ) + '' + vr.substr( tam - 8, 3 ) + '' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ); }
    if ( (tam >= 15) && (tam <= 17) ){
      document.cadastro[campo].value = vr.substr( 0, tam - 14 ) + '' + vr.substr( tam - 14, 3 ) + '' + vr.substr( tam - 11, 3 ) + '' + vr.substr( tam - 8, 3 ) + '' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam );}
    }
    }


	//Checkboxes ao questionar se o cliente possui contrato
	function Hab (checkbox) {
	  if (checkbox.checked) {
			document.cadastro.vlrcontrato.disabled = false;
			document.cadastro.qtdehoras.disabled = false;
			/*document.cadastro.comissionado.disabled = false;*/
			document.cadastro.comissao.disabled = false;
			document.cadastro.datainicial.disabled = false;
			document.cadastro.iniciocontrato.disabled = false;
			document.cadastro.vlrcontrato.focus();
	  } else {
			document.cadastro.vlrcontrato.disabled = true;
			document.cadastro.qtdehoras.disabled = true;
			/*document.cadastro.comissionado.disabled = true;*/
			document.cadastro.comissao.disabled = true;
			document.cadastro.datainicial.disabled = true;
			document.cadastro.iniciocontrato.disabled = true;
	  }
	}

	//CADCHA - Atualização do campo "equipamento"
	function carregar(){ 
		Combo1 = document.cadastro.cliente; //ALTERE AQUI PARA SEU FORM E 1º SELECT 
		Combo2 = document.cadastro.computador; //ALTERE AQUI PARA SEU FORM E 2º SELECT 
		Texto3 = document.cadastro.origem;
		var url; 
		url = 'cadcha_remoto.php?idcli='+Combo1[Combo1.selectedIndex].value+'&origem='+Texto3.value;
		Combo2.options.length = 0; 
		addItem(Combo2,"Aguarde... Carregando","",false,Combo2.length) 
		myIframe.location = url; 
		Combo2.focus()
	}
	function inicia(){ 
		local1 = new Array(); 
		var maximo1, i; 
		local1 = myIframe.loc;
        situacao1 = myIframe.situacao;
		/*cliente_telefone = myIframe.telefone;
		cliente_emails = myIframe.emails;
		cliente_origem = myIframe.origem;*/
		maximo1 = local1.length; 
		Combo2.options.length = 0; 
		addItem(Combo2,'Outro','Outro',false,Combo2.length); 
		for (i=0;i<maximo1;i++){
			addItem(Combo2,local1[i][1],local1[i][0],false,Combo2.length); 
		} 
		document.getElementById("descricao_equipamento").innerHTML = "&nbsp;&nbsp;";
        document.getElementById("situacao_cliente").innerHTML = situacao1 + "&nbsp;&nbsp;";
		/*if(cliente_origem == "A") {
			document.getElementById("cliente_telefone").innerHTML=cliente_telefone;
			document.getElementById("cliente_emails").innerHTML=cliente_emails;
		}*/
	} 
	function addItem(obj,strText,strValue,blSel,intPos){
		var newOpt,i,ArTemp,selIndex;
		selIndex = (blSel)?intPos:obj.selectedIndex;
		newOpt = new Option(strText,strValue);
		Len = obj.options.length+1
		if (intPos > Len) return
			obj.options.length = Len
		if (intPos != Len) {
		  ArTemp = new Array();
		  for(i=intPos;i<obj.options.length-1;i++)
			   ArTemp[i] = Array(obj.options[i].text,obj.options[i].value);
		  for(i=intPos+1;i<Len;i++)
			   obj.options[i] = new Option(ArTemp[i-1][0],ArTemp[i-1][1]);
		 }
		 obj.options[intPos] = newOpt;  
		 if (selIndex > intPos)  
			  obj.selectedIndex = selIndex+1;  
		 else if (selIndex == intPos)   
			  obj.selectedIndex = intPos;  
	}

	//Valida formulário
	function checkdataCados() {
	  with(document.cadastro) {	
	    if (cobranca.value == "0") {
		  alert("Favor selecionar o tipo de cobrança e preencher os dados!");
		  cobranca.focus();
		  return false; }
		if (desc.value == "") {
		  alert("Favor preencher a descrição!");
		  desc.focus();
		  return false; }
        submit();
	  }
    }
	function checkdataReos() {
	  with(document.cadastro) {	
	    if (datainicial.value == "") {
		  alert("Favor digitar a data inicial!");
		  datainicial.focus();
		  return false; }
        submit();
	  }
    }
