  // width máximo das imagens da função de preview
var maxWidth=150;
  // height máximo das imagens
var maxHeight=150;
  // extensões de arquivo válidos
var fileTypes=["gif","jpg","jpeg"];

//var outImage="previewField";
  // imagem a mostrar quando a imagem for inválida
var defaultPic="../images/SPACER.gif";

/***** NÃO EDITAR OS ITENS ABAIXO *****/

function preview(what, where){
  local = where;
  var source=what.value;
  var ext=source.substring(source.lastIndexOf(".")+1,source.length).toLowerCase();
  for (var i=0; i<fileTypes.length; i++) if (fileTypes[i]==ext) break;
  globalPic=new Image();
  if (i<fileTypes.length) globalPic.src=source;
  else {
    globalPic.src=defaultPic;
    alert("Você selecionou um arquivo inválido\nPor favor carregue uma imagem com as seguinte extensões:\n"+fileTypes.join(", "));
	}
 setTimeout("applyChanges(local)",200);
}
var globalPic;
function applyChanges(where){
  //var field=document.getElementById(outImage);
  var field=document.getElementById(where);
  var x=parseInt(globalPic.width);
  var y=parseInt(globalPic.height);
  if (x>maxWidth) {
    y*=maxWidth/x;
    x=maxWidth;
  }
  if (y>maxHeight) {
    x*=maxHeight/y;
    y=maxHeight;
  }
  field.style.display=(x<1 || y<1)?"none":"";
  field.src=globalPic.src;
  field.width=x;
  field.height=y;
}
// Confirmação de Exclusão

function ConfirmaExclusao(pagina, what, nome){
	if(confirm("Você tem certeza que deseja excluir " + what + ": " + nome+ "?")){
		window.location = pagina
		}
}

//--------------------------------------------------------------------
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//---------------- Validação dos Formulários -------------------------------
function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) {test=args[i+2]; val=MM_findObj(args[i]);  
	if (val) { nm=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- O campo '+nm+' deve conter um endereço de email válido.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- O campo '+nm+' deve conter apenas números.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- O campo '+nm+' deve conter um número entre '+min+' e '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- O campo '+nm+' é obrigatório.\n'; }
  } if (errors) alert('Ocorreu o(s) seguinte(s) erro(s):\n'+errors);
  document.MM_returnValue = (errors == '');
}
//---------------------------------------------------------------------------------
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
//----------------------------------------------------------------------------------------------------
//onKeyPress="return txtBoxFormat(this, '##.###-###', event);"
//------------------- Máscaras do TextBox ------------------------------------------------------------
//----------------------------------------------------------------------------------------------------
function txtBoxFormat(objeto, sMask, evtKeyPress) {
	var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

	if ( document.all ) { // Internet Explorer
		nTecla = evtKeyPress.keyCode;
	} //if
	else { // Nestcape
		nTecla = evtKeyPress.which;
	}

	sValue = objeto.value;

	// Limpa todos os caracteres de formatação que
	// já estiverem no campo.
	sValue = sValue.toString().replace( ":", "" );
	sValue = sValue.toString().replace( ":", "" );
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( "-", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( ".", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "/", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( "(", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( ")", "" );
	sValue = sValue.toString().replace( " ", "" );
	sValue = sValue.toString().replace( " ", "" );
	fldLen = sValue.length;
	mskLen = sMask.length;
	
	i = 0;
	nCount = 0;
	sCod = "";
	mskLen = fldLen;
	
	while ( i <= mskLen ) {
		bolMask = ((sMask.charAt(i) == ":") || (sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
		bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " "))

		if ( bolMask ) {
			sCod += sMask.charAt(i);
			mskLen++;
		} //if
		else {
			sCod += sValue.charAt(nCount);
			nCount++;
		} //Fim do else
		i++;
	} //Fim do while

	objeto.value = sCod;

	if ( nTecla != 8 ) { // backspace
		if ( sMask.charAt(i-1) == "9" ) { // apenas números...
			return ((nTecla > 47) && (nTecla < 58));
		} // números de 0 a 9
		else { // qualquer caracter...
			return true;
		} //Fim do else
	} //if
	else {
		return true;
	} //Fim do else
}
//----------------------------------------------------------------------------------------------------
//--------------- Preenche endereço na página cad_cli.asp --------------------------------------------
//----------------------------------------------------------------------------------------------------

function preenche_endereco(){
	var url;
	url = 'endereco.asp?cep='+document.frm.cep.value;
	myIframe.location = url;
	MM_showHideLayers('carregando','','show')
}
function campos_endereco2(endereco, bairro, cidade, estado){
	document.frm.endereco.value = endereco;
	document.frm.bairro.value = bairro;
	document.frm.cidade.value = cidade;
	document.frm.estado.value = estado;
	document.frm.numero.value == "";
	document.frm.numero.focus();
	MM_showHideLayers('carregando','','hide')
}
function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
//----------------------------------------------------------------------------------------------------
//----------------------------------- Janela Pop UP --------------------------------------------------
// javascript: popUp('Cnpjreva_Solicitacao.asp',660,400)
//----------------------------------------------------------------------------------------------------
function popUp(URL,larg,alt) {
var esquerda = ((screen.width - larg)/2);
var topo = ((screen.height - alt)/2);
var day = new Date();
var id = day.getTime();
var tam1 = larg;
var ext1 = alt;

eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width="+tam1+",height="+ext1+",left ="+esquerda+",top ="+topo+"');");
}
function popUp2(URL,larg,alt) {
var esquerda = ((screen.width - larg)/2);
var topo = ((screen.height - alt)/2);
var day = new Date();
var id = day.getTime();
var tam1 = larg;
var ext1 = alt;

eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width="+tam1+",height="+ext1+",left ="+esquerda+",top ="+topo+"');");
}
//----------------------------------------------------------------------------------------------------
//----------------------------------- Campos pag CheckList --------------------------------------------------
// javascript: insereCampos(nome_div, this.value)
//----------------------------------------------------------------------------------------------------
function insereCampos(nome_div, tipo_dep){
	if (tipo_dep == "") {
		if (document.getElementById) {
			tags = "";
			document.getElementById(nome_div).innerHTML = tags;
		} else if (document.all) {
			tags = "";
			document.getElementById(nome_div).innerHTML = tags;		
			} else if(document.layers) {
			tags = "";
			document.getElementById(nome_div).innerHTML = tags;
		}
	}		
	if (tipo_dep == 1) {
		if (document.getElementById) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='MISTA'>MISTA</option>"
			tags = tags + "<option value='NOMINATIVA'>NOMINATIVA</option>"
			tags = tags + "<option value='FIGURATIVA'>FIGURATIVA</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;
		} else if (document.all) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='MISTA'>MISTA</option>"
			tags = tags + "<option value='NOMINATIVA'>NOMINATIVA</option>"
			tags = tags + "<option value='FIGURATIVA'>FIGURATIVA</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;		
			} else if(document.layers) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='MISTA'>MISTA</option>"
			tags = tags + "<option value='NOMINATIVA'>NOMINATIVA</option>"
			tags = tags + "<option value='FIGURATIVA'>FIGURATIVA</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;
		}
	}
	if (tipo_dep == 2) {
		if (document.getElementById) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='ESCOLA DE BELAS ARTES'>ESCOLA DE BELAS ARTES</option>"
			tags = tags + "<option value='FUNDAÇÃO BIBLIOTECA'>FUNDAÇÃO BIBLIOTECA</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;
		} else if (document.all) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='ESCOLA DE BELAS ARTES'>ESCOLA DE BELAS ARTES</option>"
			tags = tags + "<option value='FUNDAÇÃO BIBLIOTECA'>FUNDAÇÃO BIBLIOTECA</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;		
			} else if(document.layers) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='ESCOLA DE BELAS ARTES'>ESCOLA DE BELAS ARTES</option>"
			tags = tags + "<option value='FUNDAÇÃO BIBLIOTECA'>FUNDAÇÃO BIBLIOTECA</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;
		}
	}
	if (tipo_dep == 3) {
		if (document.getElementById) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='PATENTE DE INVENÇÃO'>PATENTE DE INVENÇÃO</option>"
			tags = tags + "<option value='MODELO DE UTILIDADE'>MODELO DE UTILIDADE</option>"
			tags = tags + "<option value='DESENHO INDUSTRIAL'>DESENHO INDUSTRIAL</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;
		} else if (document.all) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='PATENTE DE INVENÇÃO'>PATENTE DE INVENÇÃO</option>"
			tags = tags + "<option value='MODELO DE UTILIDADE'>MODELO DE UTILIDADE</option>"
			tags = tags + "<option value='DESENHO INDUSTRIAL'>DESENHO INDUSTRIAL</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;		
			} else if(document.layers) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='PATENTE DE INVENÇÃO'>PATENTE DE INVENÇÃO</option>"
			tags = tags + "<option value='MODELO DE UTILIDADE'>MODELO DE UTILIDADE</option>"
			tags = tags + "<option value='DESENHO INDUSTRIAL'>DESENHO INDUSTRIAL</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;
		}
	}
  if (tipo_dep == 4) {
		if (document.getElementById) {
			document.getElementById(nome_div).innerHTML = "<input type='text' class='form' name='subtipo_deposito' value='SEM SUBTIPO' disabled='disabled'/>";
		} else if (document.all) {
			document.getElementById(nome_div).innerHTML = "<input type='text' class='form' name='subtipo_deposito' value='SEM SUBTIPO' disabled='disabled'/>";
			} else if(document.layers) {
			document.getElementById(nome_div).innerHTML = "<input type='text' class='form' name='subtipo_deposito' value='SEM SUBTIPO' disabled='disabled'/>";
		}
	}
	if (tipo_dep == 5) {
		if (document.getElementById) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='PEDIDO'>PEDIDO</option>"
			tags = tags + "<option value='REGISTRO'>REGISTRO</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;
		} else if (document.all) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='PEDIDO'>PEDIDO</option>"
			tags = tags + "<option value='REGISTRO'>REGISTRO</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;		
			} else if(document.layers) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='PEDIDO'>PEDIDO</option>"
			tags = tags + "<option value='REGISTRO'>REGISTRO</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;
		}
	}
	if (tipo_dep == 6) {
		if (document.getElementById) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='PATENTE DE INVENÇÃO'>PATENTE DE INVENÇÃO</option>"
			tags = tags + "<option value='MODELO DE UTILIDADE'>MODELO DE UTILIDADE</option>"
			tags = tags + "<option value='DESENHO INDUSTRIAL'>DESENHO INDUSTRIAL</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;
		} else if (document.all) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='PATENTE DE INVENÇÃO'>PATENTE DE INVENÇÃO</option>"
			tags = tags + "<option value='MODELO DE UTILIDADE'>MODELO DE UTILIDADE</option>"
			tags = tags + "<option value='DESENHO INDUSTRIAL'>DESENHO INDUSTRIAL</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;		
			} else if(document.layers) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--- SELECIONE ---</option>";
			tags = tags + "<option value='PATENTE DE INVENÇÃO'>PATENTE DE INVENÇÃO</option>"
			tags = tags + "<option value='MODELO DE UTILIDADE'>MODELO DE UTILIDADE</option>"
			tags = tags + "<option value='DESENHO INDUSTRIAL'>DESENHO INDUSTRIAL</option>"
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;
		}
	}

}
//----------------------------------------------------------------------------------------------------
//----------------------------------- Campos pag Documentos --------------------------------------------------
// javascript: insereCampos(nome_div, this.value)
//----------------------------------------------------------------------------------------------------
function insereCampos5(nome_div, tipo_dep){
	if (tipo_dep == "") {
		if (document.getElementById) {
			tags = "";
			document.getElementById(nome_div).innerHTML = tags;
		} else if (document.all) {
			tags = "";
			document.getElementById(nome_div).innerHTML = tags;		
			} else if(document.layers) {
			tags = "";
			document.getElementById(nome_div).innerHTML = tags;
		}
	}		
	if (tipo_dep == "Nacional") {
		if (document.getElementById) {
			tags = "<input type='text' class='form' name='classe' size='12' maxlength='11'/>";
			document.getElementById(nome_div).innerHTML = tags;
		} else if (document.all) {
			tags = "<input type='text' class='form' name='classe' size='12' maxlength='11'/>";
			document.getElementById(nome_div).innerHTML = tags;		
			} else if(document.layers) {
			tags = "<input type='text' class='form' name='classe' size='12' maxlength='11'/>";
			document.getElementById(nome_div).innerHTML = tags;
		}
	}
	if (tipo_dep == "NCL(7)") {
		if (document.getElementById) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--</option>";
			for (i=1;i<43;i++){
				tags = tags + "<option value='"+ i + "'>"+ i + "</option>"
			}
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;
		} else if (document.all) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--</option>";
			for (i=1;i<43;i++){
				tags = tags + "<option value='"+ i + "'>"+ i + "</option>"
			}
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;		
			} else if(document.layers) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--</option>";
			for (i=1;i<43;i++){
				tags = tags + "<option value='"+ i + "'>"+ i + "</option>"
			}
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;
		}
	}
	if (tipo_dep == "NCL(8)") {
		if (document.getElementById) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--</option>";
			for (i=1;i<46;i++){
				tags = tags + "<option value='"+ i + "'>"+ i + "</option>"
			}
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;
		} else if (document.all) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--</option>";
			for (i=1;i<46;i++){
				tags = tags + "<option value='"+ i + "'>"+ i + "</option>"
			}
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;		
			} else if(document.layers) {
			tags = "<select class='form' name='subtipo_deposito'>";
			tags = tags + "<option value=''>--</option>";
			for (i=1;i<46;i++){
				tags = tags + "<option value='"+ i + "'>"+ i + "</option>"
			}
			tags = tags + "</select>"
			document.getElementById(nome_div).innerHTML = tags;
		}
	}
}
//----------------------------------------------------------------------------------------------------
//-------------------------------------CAMPOS PÁGINA DE CADASTRO DE CLIENTE---------------------------
//----------------------------------------------------------------------------------------------------
function insereCampos2(nome_div, tipo_dep){
	if (tipo_dep == "") {
		if (document.getElementById) {
			tags = "";
			document.getElementById(nome_div).innerHTML = tags;
		} else if (document.all) {
			tags = "";
			document.getElementById(nome_div).innerHTML = tags;		
			} else if(document.layers) {
			tags = "";
			document.getElementById(nome_div).innerHTML = tags;
		}
	}
	if (tipo_dep == 0) {
		mascara = "txtBoxFormat('cpf_cnpj','###.###.###-##', event);";
		if (document.getElementById) {
			tags = "<input name='cpf_cnpj' type='text' class='form' id='cpf_cnpj' onkeypress=" + eval(mascara) + " size='18' maxlength='18'>";
			document.getElementById(nome_div).innerHTML = tags;
		} else if (document.all) {
			tags = "<input name='cpf_cnpj' type='text' class='form' id='cpf_cnpj' onkeypress=" + eval(mascara) + " size='18' maxlength='18'>";
			document.getElementById(nome_div).innerHTML = tags;		
			} else if(document.layers) {
			tags = "<input name='cpf_cnpj' type='text' class='form' id='cpf_cnpj' onkeypress=" + eval(mascara) + " size='18' maxlength='18'>";
			document.getElementById(nome_div).innerHTML = tags;
		}
	}
		if (tipo_dep == 1) {
		mascara = eval("txtBoxFormat('cpf_cnpj','###.###.###-##', event);");
		if (document.getElementById) {
			tags = "<input name='cpf_cnpj' type='text' class='form' id='cpf_cnpj' onkeypress=" + mascara + " size='22' maxlength='18'>";
			document.getElementById(nome_div).innerHTML = tags;
		} else if (document.all) {
			tags = "<input name='cpf_cnpj' type='text' class='form' id='cpf_cnpj' onkeypress=" + mascara + " size='22' maxlength='18'>";
			document.getElementById(nome_div).innerHTML = tags;		
			} else if(document.layers) {
			tags = "<input name='cpf_cnpj' type='text' class='form' id='cpf_cnpj' onkeypress=" + mascara + " size='22' maxlength='18'>";
			document.getElementById(nome_div).innerHTML = tags;
		}
	}
}
//----------------------------------------------------------------------------------------------------
//----------------------------------------COMBO DE ESTADOS E CIDADES----------------------------------
//----------------------------------------------------------------------------------------------------

function carregar(){
var url;
url = '../include/pagina.asp?uf='+document.frm.txt_estado[document.frm.txt_estado.selectedIndex].value;
document.frm.txt_cidade.options.length = 0;
addItem(document.frm.txt_cidade,"AGUARDE... CARREGANDO","",false,document.frm.txt_cidade.length)
myIframe.location = url;
}
function inicia(){
local = new Array();
var maximo, i, campo;
local = myIframe.a;
campo = document.frm.txt_cidade;
local = myIframe.a;
maximo = local.length;
document.frm.txt_cidade.options.length = 0;
addItem(campo,"SELECIONE","",false,campo.length);
for (i=0;i<maximo;i++){
  addItem(campo,local[i][1],local[i][0],false,campo.length);
}
}
//----------------------------------------------------------------------------------------------------
//----------------------------------------PREENCHIMENTO DE SUBS E CLIENTES----------------------------
//----------------------------------------------------------------------------------------------------

function carregar1(){
var url;
url = '../include/sub_franquea.asp?grupo='+document.frm.grupo[document.frm.grupo.selectedIndex].value;
document.frm.subfranqueado.options.length = 0;
addItem(document.frm.subfranqueado,"AGUARDE... CARREGANDO","",false,document.frm.subfranqueado.length)
myIframe.location = url;
}
function inicia1(){
local = new Array();
var maximo, i, campo;
local = myIframe.a;
campo = document.frm.subfranqueado;
local = myIframe.a;
maximo = local.length;
document.frm.subfranqueado.options.length = 0;
addItem(campo,"SELECIONE","",false,campo.length);
for (i=0;i<maximo;i++){
  addItem(campo,local[i][1],local[i][0],false,campo.length);
}
}
/* ---------------------------------------------------------------------------------- */
function carregar2(){
var url;
url = '../include/sub_franquea2.asp?grupo='+document.frm.cod_grupo[document.frm.cod_grupo.selectedIndex].value;
url2 = '../include/tlmk.asp?grupo='+document.frm.cod_grupo[document.frm.cod_grupo.selectedIndex].value;
url3 = '../include/cliente.asp?grupo='+document.frm.cod_grupo[document.frm.cod_grupo.selectedIndex].value;
document.frm.cod_sub.options.length = 0;
document.frm.tlmk.options.length = 0;
document.frm.cnpj_cpf.options.length = 0;
addItem(document.frm.cod_sub,"AGUARDE... CARREGANDO","",false,document.frm.cod_sub.length)
addItem(document.frm.tlmk,"AGUARDE... CARREGANDO","",false,document.frm.tlmk.length)
addItem(document.frm.cnpj_cpf,"AGUARDE... CARREGANDO","",false,document.frm.cnpj_cpf.length)
myIframe.location = url;
myIframe2.location = url2;
myIframe3.location = url3;
}
function inicia2(campo, maximo, canto){
local = new Array();
var maximo, i, campo;
local = document.frames[canto].a; 
//alert(local);
campo = document.getElementById(campo);
//local = myIframe3.a;
//maximo = local.length;
//document.frm.subfranqueado.options.length = 0;
campo.options.length = 0;
addItem(campo,"SELECIONE","",false,campo.length);
for (i=0;i<maximo;i++){
  addItem(campo,local[i][1],local[i][0],false,campo.length);
}
}
/*---------------------------------------------------- */
function carregar4(){
var url;
url = '../include/sub_franquea2.asp?grupo='+document.frm.cod_grupo[document.frm.cod_grupo.selectedIndex].value;
//url2 = '../include/tlmk.asp?grupo='+document.frm.cod_grupo[document.frm.cod_grupo.selectedIndex].value;
url3 = '../include/cliente.asp?grupo='+document.frm.cod_grupo[document.frm.cod_grupo.selectedIndex].value;
document.frm.cod_sub.options.length = 0;
//document.frm.tlmk.options.length = 0;
document.frm.cnpj_cpf.options.length = 0;
addItem(document.frm.cod_sub,"AGUARDE... CARREGANDO","",false,document.frm.cod_sub.length)
//addItem(document.frm.tlmk,"AGUARDE... CARREGANDO","",false,document.frm.tlmk.length)
addItem(document.frm.cnpj_cpf,"AGUARDE... CARREGANDO","",false,document.frm.cnpj_cpf.length)
myIframe.location = url;
//myIframe2.location = url2;
myIframe3.location = url3;
}
function inicia4(campo, maximo, canto){
local = new Array();
var maximo, i, campo;
local = document.frames[canto].a; 
//alert(local);
campo = document.getElementById(campo);
//local = myIframe3.a;
//maximo = local.length;
//document.frm.subfranqueado.options.length = 0;
campo.options.length = 0;
addItem(campo,"SELECIONE","",false,campo.length);
for (i=0;i<maximo;i++){
  addItem(campo,local[i][1],local[i][0],false,campo.length);
}
}

/*---------------------------------------------------- */
function carregar3(){
if (document.frm.cod_os.value == ""){
	alert('Você deve preencher o campo com o Código da O.S.!');
	} else {
	var url;
	url = '../include/marcas_parecer.asp?cod_os='+document.frm.cod_os.value;
	document.frm.seq_marca.options.length = 0;
	addItem(document.frm.seq_marca,"AGUARDE... CARREGANDO","",false,document.frm.seq_marca.length)
	myIframe.location = url;
	}
}
function inicia3(){
local = new Array();
var maximo, i, campo;
local = myIframe.a;
campo = document.frm.seq_marca;
local = myIframe.a;
maximo = local.length;
document.frm.seq_marca.options.length = 0;
if (local == ""){ 
	addItem(campo,"MARCAS NÃO ENCONTRADAS","",false,campo.length);
	} else {
		addItem(campo,"SELECIONE","",false,campo.length);
		for (i=0;i<maximo;i++){
		  addItem(campo,local[i][1],local[i][0],false,campo.length);
		}
	}
}
/*-------------------------------------------------------- */
function carregar5(){
var url;
url = '../include/os_proposta.asp?cnpj_cpf='+document.frm.cnpj_cpf[document.frm.cnpj_cpf.selectedIndex].value;
document.frm.cod_os.options.length = 0;
addItem(document.frm.cod_os,"AGUARDE... CARREGANDO","",false,document.frm.cod_os.length)
myIframe4.location = url;
}
/*---------------------------------------------------- */
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; 
} 
//----------------------------------------------------------------------------------------------------
//------------------------------------MASCARA DE CPF/CNPJ E VALIDAÇÃO---------------------------------
//----------------------------------------------------------------------------------------------------
function FormataCPF(Campo, teclapres){
	var tecla = teclapres.keyCode;
	
	var vr = new String(Campo.value);
	vr = vr.replace(".", "");
	vr = vr.replace(".", "");
	vr = vr.replace("/", "");
	vr = vr.replace("-", "");
	vr = vr.replace(" ", "");

	tam = vr.length + 1;
	
        if (document.frm.tipo[0].checked == true)
        {
	        if (tecla != 9 && tecla != 8 && tecla != 13){
		        if (tam > 3 && tam < 7)
			        Campo.value = vr.substr(0, 3) + '.' + vr.substr(3, tam);
		        if (tam >= 7 && tam <10)
			        Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,tam-6);
		        if (tam >= 10 && tam < 12)
			        Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
		        if (tam >= 12)
			        Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,1);
	        }
        }
        else
        {  if (document.frm.tipo[1].checked == true)
              {
	        if (tecla != 9 && tecla != 8 && tecla != 13){
		        if (tam > 2 && tam < 6)
			        Campo.value = vr.substr(0, 2) + '.' + vr.substr(2, tam);
		        if (tam >= 6 && tam < 9)
			        Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,tam-5);
		        if (tam >= 9 && tam < 13)
			        Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,tam-8);
		        if (tam >= 13 && tam < 15)
			        Campo.value = vr.substr(0,2) + '.' + vr.substr(2,3) + '.' + vr.substr(5,3) + '/' + vr.substr(8,4)+ '-' + vr.substr(12,tam-12);
	        }
              }
        }
}

// VALIDAÇÃO DO CNPJ / CPF // 

function TestaNI(cNI){
	var NI, iTipo
        
		if (document.frm.tipo[0].checked == true){
			if (LimpaCampo(cNI.value,10) == "00000000000" || LimpaCampo(cNI.value,10) == "11111111111" || LimpaCampo(cNI.value,10) == "22222222222" || LimpaCampo(cNI.value,10) == "33333333333" || LimpaCampo(cNI.value,10) == "44444444444" || LimpaCampo(cNI.value,10) == "55555555555" || LimpaCampo(cNI.value,10) == "66666666666" || LimpaCampo(cNI.value,10) == "77777777777" || LimpaCampo(cNI.value,10) == "88888888888" || LimpaCampo(cNI.value,10) == "99999999999"){
                 iTipo = 3;
               } else {
                iTipo = 2;
			 }
        }
		
		if (document.frm.tipo[1].checked == true){
            if (LimpaCampo(cNI.value,10) == "00000000000000" || LimpaCampo(cNI.value,10) == "11111111111111" || LimpaCampo(cNI.value,10) == "22222222222222" || LimpaCampo(cNI.value,10) == "33333333333333" || LimpaCampo(cNI.value,10) == "44444444444444" || LimpaCampo(cNI.value,10) == "55555555555555" || LimpaCampo(cNI.value,10) == "66666666666666" || LimpaCampo(cNI.value,10) == "77777777777777" || LimpaCampo(cNI.value,10) == "88888888888888" || LimpaCampo(cNI.value,10) == "99999999999999"){
                 iTipo = 3;
               } else {
				iTipo = 1;
			}
        }
	
	NI = LimpaCampo(cNI.value,10);
	
	switch (iTipo) {
		case 1:
			if (NI.length != 14){
				alert('O número do CNPJ informado está incorreto');
				cNI.value = "";
				cNI.focus();
				return false;
			}

			if (NI.substr(12,2) != CalcularDV(NI.substr(0,12), 9)){
				alert('O número do CNPJ informado está incorreto');
				cNI.value = "";
				cNI.focus();
				return false;
			}
			break;

		 case 2:
			if (NI.length != 11){
				alert('O número do CPF informado está incorreto');
				cNI.value = "";
				cNI.focus();
				return false;
			}
			if (NI.substr(9,2) != CalcularDV(NI.substr(0,9), 11)){
				alert('O número do CPF informado está incorreto');
				cNI.value = "";
				cNI.focus();
				return false;
			}
			break;
		
			case 3:
				alert('O número do CPF/CNPJ informado está incorreto');
				cNI.value = "";
				cNI.focus();
				return false;			
			break;
			
		default:
			return false;
	}
	return true;	
}

function LimpaCampo(sValor,iBase){
	var tam = sValor.length
	var saida = new String
	for (i=0;i<tam;i++)
		if (!isNaN(parseInt(sValor.substr(i,1),iBase)))
			saida = saida + String(sValor.substr(i,1));
	return (saida);		
	}
	
function CalcularDV(sCampo, iPeso){
	
	var iTamCampo;
	var iPosicao, iDigito;
	var iSoma1 = 0;
	var iSoma2=0;
	var iDV1, iDV2;
		
	iTamCampo = sCampo.length;

	for (iPosicao=1; iPosicao<=iTamCampo; iPosicao++){
		iDigito = sCampo.substr(iPosicao-1, 1);
		iSoma1 = parseInt(iSoma1,10) + parseInt((iDigito * Calcular_Peso(iTamCampo - iPosicao, iPeso)),10);
		iSoma2 = parseInt(iSoma2,10) + parseInt((iDigito * Calcular_Peso(iTamCampo - iPosicao + 1, iPeso)),10);
		}

	iDV1 = 11 - (iSoma1 % 11);
	if (iDV1 > 9)
		iDV1 = 0;

	iSoma2 = iSoma2 + (iDV1 * 2);
	iDV2 = 11 - (iSoma2 % 11);
	if (iDV2 > 9)
		iDV2 = 0;

	Ret = (parseInt(iDV1 * 10,10) + parseInt(iDV2));

	Ret = "0" + Ret;
	Ret = Ret.substr(Ret.length - 2,Ret.length);
		
	return(Ret);
}
function Calcular_Peso(iPosicao, iPeso){

	//Pesos
	//CPF 11
	//CNPJ 9
	return (iPosicao % (iPeso - 1)) + 2;
	}
	
//----------------------------------------------------------------------------------------------------
// --------- onKeyPress="return(currencyFormat(this,'.',',',event))" ------------------
function currencyFormat(objTextBox, SeparadorMilesimo, SeparadorDecimal, e){
    var sep = 0;
    var key = '';
    var i = j = 0;
    var len = len2 = 0;
    var strCheck = '0123456789';
    var aux = aux2 = '';
    var whichCode = (window.Event) ? e.which : e.keyCode;
    if (whichCode == 13) return true;
    key = String.fromCharCode(whichCode); // Valor para o código da Chave
    if (strCheck.indexOf(key) == -1) return false; // Chave inválida
    len = objTextBox.value.length;
    for(i = 0; i < len; i++)
        if ((objTextBox.value.charAt(i) != '0') && (objTextBox.value.charAt(i) != SeparadorDecimal)) break;
    aux = '';
    for(; i < len; i++)
        if (strCheck.indexOf(objTextBox.value.charAt(i))!=-1) aux += objTextBox.value.charAt(i);
    aux += key;
    len = aux.length;
    if (len == 0) objTextBox.value = '';
    if (len == 1) objTextBox.value = '0'+ SeparadorDecimal + '0' + aux;
    if (len == 2) objTextBox.value = '0'+ SeparadorDecimal + aux;
    if (len > 2) {
        aux2 = '';
        for (j = 0, i = len - 3; i >= 0; i--) {
            if (j == 3) {
                aux2 += SeparadorMilesimo;
                j = 0;
            }
            aux2 += aux.charAt(i);
            j++;
        }
        objTextBox.value = '';
        len2 = aux2.length;
        for (i = len2 - 1; i >= 0; i--)
        objTextBox.value += aux2.charAt(i);
        objTextBox.value += SeparadorDecimal + aux.substr(len - 2, len);
    }
    return false;
}


//  End -->
