
//Preenchimento CEP
function getEndereco() {

   // Se o campo CEP não estiver vazio
if($.trim($("#cep").val()) != ""){
/*Para conectar no serviço e executar o json, precisamos usar a função
getScript do jQuery, o getScript e o dataType:"jsonp" conseguem fazer o cross-domain,
os outros dataTypes não possibilitam esta interação entre domínios diferentes Estou
chamando a url do serviço passando o parâmetro "formato=javascript" e o CEP digitado no
formulário http://cep.republicavirtual.com.br/web_cep.php?formato=javascript&cep="+$("#cep").val()*/

$.getScript("http://cep.republicavirtual.com.br/web_cep.php?formato=javascript&cep="+$("#cep").val(), function(){
// o getScript dá um eval no script, então é só ler!
//Se o resultado for igual a 1
//se o tipo de logradouro for direfente de nulo
					
if (resultadoCEP["tipo_logradouro"] != '') {
	if (resultadoCEP["resultado"]) {
	// troca o valor dos elementos
$("#endereco").val(unescape(resultadoCEP["tipo_logradouro"]) + " " + unescape(resultadoCEP["logradouro"]));
$("#bairro").val(unescape(resultadoCEP["bairro"]));
$("#cidade").val(unescape(resultadoCEP["cidade"]));
$("#estado").val(unescape(resultadoCEP["uf"]));
//dá o foco no numero
$("#numero").focus();
		}
					
	}	
					
    });
 }
}



			function MM_openBrWindow(theURL,winName,features) { //v2.0
			window.open(theURL,winName,features);
			}

			function DisplayInfo(pagina,janela,w,h,scrolling) {
			 if (!scrolling) { scrolling="auto" } resultado = window.open(pagina,janela,"width="+w+",height="+h+",scrollbars="+scrolling+",toolbar=no,location=no,status=yes,menubar=yes,resizable=yes,left=5,top=5")
			}

			function imprimir(id) {
			 DisplayInfo("imprimir.php?id="+id,"imprimir",600,500,"yes","no");
			}

			function artigos (cid) {
				 location.replace('$config[site]artigos.php?in=lista&cid='+cid);
			}
			
			function DisplayInfo(pagina,janela,w,h,scrolling) {
			 if (!scrolling) { scrolling="auto" } resultado = window.open(pagina,janela,"width="+w+",height="+h+",scrollbars="+scrolling+",toolbar=no,location=no,status=yes,menubar=yes,resizable=yes,left=5,top=5")
			}
	
	
			function boldThis(from) { 
				strSelection = document.selection.createRange().text 
				if (strSelection == "") { 
				return false; 
				} 
				else document.selection.createRange().text = "<b>" + strSelection 
				+ "</b>" 
				return;
			}
			
			function italicThis(from) { 
				strSelection = document.selection.createRange().text 
				if (strSelection == "") { 
				return false; 
				} 
				else document.selection.createRange().text = "<i>" + strSelection 
				+ "</i>" 
				return;
			}
			
			function underlineThis(from) { 
				strSelection = document.selection.createRange().text 
				if (strSelection == "") { 
				return false; 
				} 
				else document.selection.createRange().text = "<u>" + strSelection 
				+ "</u>" 
				return;
			}
			
			function changecolor(t) { 
				strSelection = document.selection.createRange().text 
				if (strSelection == "") { 
				return false; 
				} 
				else document.selection.createRange().text = "<font" + " color" +"=" +t+">" + strSelection 
				+ "</font>" 
				return;
			}
			
			function changesize(t) { 
				strSelection = document.selection.createRange().text 
				if (strSelection == "") { 
				return false; 
				} 
				else document.selection.createRange().text = "<font" + " class" +"=" +t+">" + strSelection 
				+ "</font>" 
				return;
			}

			function nbspThis(from) { 
				strSelection = document.selection.createRange().text 
				if (strSelection == "") { 
				alert("Selecione um caracter.."); 
				} 
				else document.selection.createRange().text = "&nbsp; &nbsp; " 
				return;
			}
			
			function produtos (tipo,id,cid) {
			  if(tipo == '1') {
				 location.replace('$config[site]admin/?on=produtos&in=novo_prod&cid='+cid);
			  } else {
				 location.replace('$config[site]admin/?on=produtos&in=editar_produto&id='+id+'&cid='+cid);
			  }
			}

		    function clearall (form) {
				form.reset();
		    }
