// função para aplicar transparencia em imagens PNG para tags IMG no IE6
// uso: dentro da tag IMG -  onload="fixPNG(this.id);"
// PS: A imagem tem q ter um ID
function fixPNG(myImage)
{
	myImage = document.getElementById(myImage);
	if(navigator.appVersion.indexOf("MSIE")!= -1){
    	var temp = navigator.appVersion.split("MSIE");
    	var version = parseFloat(temp[1]);
		if ( (version < 7) && (document.body.filters) )
		{
		   var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
		   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
		   var imgTitle = (myImage.title) ?
						 "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
		   var imgStyle = "display:inline-block;" + myImage.style.cssText
		   var strNewHTML = "<span " + imgID + imgClass + imgTitle
					  + " style=\"" + "width:" + myImage.width
					  + "px; height:" + myImage.height
					  + "px;" + imgStyle + ";"
					  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
					  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
		   myImage.outerHTML = strNewHTML
		}
	}
}

function contarCaracteres(maximo,campo,resultado){
	var total=maximo;
	var obj = document.getElementById(campo);
	var digitado=obj.value.length;
	if(digitado>total){
		alert('Número máximo de caracteres excedido.');
		obj.value=obj.value.slice(0,total) //exibe os primeiros caracteres
	}
	digitado=obj.value.length;
	var restante=total-digitado;
	document.getElementById(resultado).innerHTML=restante.toString() + ' restantes';//exibe o texto na div
}

function MM_findObj(n, d) { //v4.0
  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 && document.getElementById) x=document.getElementById(n); return x;
}

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

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_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_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];}
}

function MM_dmenu(objname) {
  var obj = MM_findObj(objname);
  if(obj && obj.style) obj.style.display = (obj.style.display=="none") ? "" : "none";
}

function MM_dmenuh() {
  var a=MM_dmenuh.arguments;
  for (i=0; i<a.length; i++) {var obj = MM_findObj(a[i]); if(obj && obj.style) obj.style.display = "none"; }
}

function MM_dmenus() {
	var a=MM_dmenus.arguments;
	for (i=0; i<a.length; i++) {var obj = MM_findObj(a[i]); if(obj && obj.style) obj.style.display = ""; }
}

function retira_formato_cpf_cnpj(doc) {
	//retirar os pontos
	while (doc.indexOf(".")!=-1) {
		temp = doc.substr(0,doc.indexOf("."));
		doc = temp+doc.substr(doc.indexOf(".")+1);
	}
	// retira a barra
	if (doc.indexOf("/")!=-1) {
		temp = doc.substr(0,doc.indexOf("/"));
		doc = temp+doc.substr(doc.indexOf("/")+1);
	}

	// retira o traço
	if (doc.indexOf("-")!=-1) {
		temp = doc.substr(0,doc.indexOf("-"));
		doc = temp+doc.substr(doc.indexOf("-")+1);
	}
	//alert (doc);
	return doc;
}


function VerificaCPF(objname) {
	var obj=MM_findObj(objname);
	var i, temp; 
	s = obj.value;
	var zeros = '';

	// Retira a formatação
	s = retira_formato_cpf_cnpj(s);

	// verifica o tamanho
	if (s.length <= 11 && s.length > 0) {
		var tam = (11 - s.length);
		for (i=1;i<=tam;i++)
			zeros="0"+zeros;
		s=zeros+s;
	}
	else {
		return false;
	}
	
	var c = s.substr(0,9); 
	var dv = s.substr(9,2); 
	var d1 = 0; 
	var v = false;
	for (i = 0; i < 9; i++) { 
		d1 += c.charAt(i)*(10-i); 
	} 
	if (d1 == 0){ 
		//alert("CPF Inválido") ;
		//obj.value='';
		//obj.focus();
		v = true; 
		return false; 
	} 
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(0) != d1) { 
		//alert("CPF Inválido") ;
		//obj.value='';
		//obj.focus();
		v = true;
		return false; 
	} 
	
	d1 *= 2; 
	for (i = 0; i < 9; i++) { 
		d1 += c.charAt(i)*(11-i); 
	} 
	d1 = 11 - (d1 % 11); 
	if (d1 > 9) d1 = 0; 
	if (dv.charAt(1) != d1) { 
		//alert("CPF Inválido") ;
		//obj.value='';
		//obj.focus();
		v = true;
		return false; 
	}
	else {
		//obj.value=s;
		//alert("CPF válido") ;
		return true; 
	}

}

function VerificaCNPJ(objname)
{
	var obj=MM_findObj(objname);
	var cnpj = obj.value;
	var zeros = '';
	var tam, sim, soma1;
	
	// retira o zero inicial
	//cnpj = cnpj.substr(1);

	// Retira a formatação
	cnpj = retira_formato_cpf_cnpj(cnpj);

	// verifica o tamanho
	if (cnpj.length <= 14 && cnpj.length > 0) {
		var tam = (14 - cnpj.length);
		for (i=1;i<=tam;i++)
			zeros="0"+zeros;
		cnpj=zeros+cnpj;
		sim=true;
	}
	else {
		sim=false;
	}
	
	if (sim)
	{
			m2 = 2;
			soma1 = 0;
			soma2 = 0;
			for (i=11;i>=0;i--) {
				val = eval(cnpj.charAt(i));
				// alert ("Valor do Val: "+val)
				m1 = m2;
				if (m2 < 9) { m2 = m2+1}
				else {m2 = 2}
				soma1 = soma1 + (val * m1)
				soma2 = soma2 + (val * m2)
			} // fim do for de soma
		
			soma1 = soma1 % 11
			if (soma1 < 2) { d1 = 0}
			else { d1 = 11- soma1}
		
			soma2 = (soma2 + (2 * d1)) % 11
			if (soma2 < 2) { d2 = 0}
			else { d2 = 11- soma2}
			// alert (d1)
			// alert (d2)
			if ((d1==cnpj.charAt(12)) && (d2==cnpj.charAt(13))) { 
				sim=true 
			}
			else {
				sim=false
			}
	}
	if (!sim) {
		//alert("CNPJ Inválido") ;
		//obj.value='';
		//obj.focus();
		return false; 
	}
	else {
		//obj.value=cnpj;
		//alert("CNPJ válido") ;
		return true; 
	}
}


//Verifica o input text sem saber se é CPF ou CNPJ
function VerificaCnpj_Cpf(objname) {
	var obj=MM_findObj(objname);
	var doc_valor = obj.value;
	//alert (doc_valor+" - "+doc_valor.length);
	//var doc = objname; // Nome do campo (tipo do documento)
	var doc_nome="";
	if (doc_valor.length > 13) {
		if (doc_valor.length > 14) {
			doc_nome = "CNPJ";
			doc_valor = VerificaCNPJ(objname);
		} else {
			doc_nome = "CPF";
			doc_valor = VerificaCPF(objname);
		}
	} else {
		doc_valor = false;
		obj.value='';
		alert("Documento deve possuir pelo menos 11 números!");
		obj.focus();
		return false; 
	}
	
	if (doc_valor == false) {
		obj.value='';
		alert(doc_nome+" inválido!");
		obj.focus();
		return false; 
	}
	return true;
}

// Esta máscara só funciona no onChance ou onBlur
function mascara_cpf_cnpj(objname){
	var obj=document.getElementById(objname);
	var zeros = "";
	var doc = obj.value;
	// Retira a formatação
	//doc = retira_formato_cpf_cnpj(doc);
	var tam = doc.length;
	if (tam <= 11) {
		if (tam<11){ // Se o cpf tem menos de 11 algarismos acrescenta zeros
			for (i=0;i<(11-tam);i++) {
				zeros=zeros+'0';
			}
			doc = zeros+doc;
		}
		doc_formatado = doc.substr(0,3)+"."+doc.substr(3,3)+"."+doc.substr(6,3)+"-"+doc.substr(9);
	} else {
		if (tam<14){ // Se o cnpj tem menos de 11 algarismos acrescenta zeros
			for (i=0;i<(14-tam);i++) {
				zeros=zeros+'0';
			}
			doc = zeros+doc;
		}
		doc_formatado = doc.substr(0,2)+"."+doc.substr(2,3)+"."+doc.substr(5,3)+"/"+doc.substr(8,4)+"-"+doc.substr(12);
	}
	obj.value = doc_formatado;
	VerificaCnpj_Cpf(objname);
}

function mascara_cep(objname)
{
	var obj=MM_findObj(objname);
	var cep = obj.value;
    var mycep = '';
    mycep = mycep + cep;
    if (mycep.length == 2) {
        mycep = mycep + '.';
        obj.value = mycep;
    }
    if (mycep.length == 6) {
        mycep = mycep + '-';
        obj.value = mycep;
    }
}

function mascara_tel(objname)
{	// Máscara para colocar parênteses no DDD e traço no número : (xx)xxxx-xxxx
	var obj=MM_findObj(objname);
	var tel = obj.value;
    var mytel = '';
    mytel = mytel + tel;
    if (mytel.length == 2) {
        mytel = '('+ mytel + ')';
        obj.value = mytel;
    }
    if (mytel.length == 8) {
        mytel = mytel + '-';
        obj.value = mytel;
    }
    if (mytel.length == 13) {
    }
}

function mascara_tel2(objname)
{	//Máscara para colocar traço no número : xxxx-xxxx  (Não tem DDD)
	var obj=MM_findObj(objname);
	var tel = obj.value;
    var mytel = '';
    mytel = mytel + tel;

	if (mytel.length == 4) {
        mytel = mytel + '-';
        obj.value = mytel;
    }
    if (mytel.length == 9) {
    }
}

function checa_data (dia,mes,ano) {
// Apenas retorna true ou false
	situacao = "";
	// verifica o dia valido para cada mes
	if ((dia < 1)||(dia < 1 || dia > 30) && (  mes == 4 || mes == 6 || mes == 9 || mes == 11 ) || dia > 31) {
		situacao = "falsa";
	}
	
	// verifica se o mes e valido
	if (mes < 1 || mes > 12 ) {
		situacao = "falsa";
	}
	
	// verifica se e ano bissexto
	if (mes == 2 && ( dia < 1 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) {
		situacao = "falsa";
	}
	
	if (situacao == "falsa") {
		return false;
	} else {
		return true;
	}
} 

function dataBusca(dia,mes,ano){
	dia = document.getElementById(dia);
	mes = document.getElementById(mes);
	ano = document.getElementById(ano);
	if (!checa_data(dia.value,mes.value,ano.value)) {
		alert('Data inválida'); 
		dia.value = "";
		mes.value = "";
		ano.value = "";
		dia.focus();
	}
}

function mascara_cpf(objname)
{
	var obj=MM_findObj(objname);
	var cpf = obj.value;
    var mycpf = '';
    mycpf = mycpf + cpf;
    if (mycpf.length == 3) {
        mycpf = mycpf + '.';
        obj.value = mycpf;
		obj.focus();
    }
    if (mycpf.length == 7) {
        mycpf = mycpf + '.';
        obj.value = mycpf;
		obj.focus();
    }
    if (mycpf.length == 11) {
        mycpf = mycpf + '-';
        obj.value = mycpf;
		obj.focus();
    }
    if (mycpf.length == 14) {
		obj.focus();
    }
}

// função para aceitar apenas letras e números
function letras_num(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode
	if (charCode != 127 && charCode !=8 && charCode !=95) {
		if (charCode < 45 || charCode == 47 || (charCode > 57 && charCode < 64) || (charCode > 90 && charCode < 97) || charCode > 122) {
			return false
		}
	}
	return true;
}

// função para aceitar apenas números
function sonumeros(evt) {
	var charCode = (evt.which) ? evt.which : event.keyCode;
	if (charCode > 31 && (charCode < 48 || charCode > 57)) {
		return false;
	}
	return true;
}

function Limpar(valor, validos) {
	// retira caracteres invalidos da string
	var result = "";
	var aux;
	for (var i=0; i < valor.length; i++) {
		aux = validos.indexOf(valor.substring(i, i+1));
		if (aux>=0) {
			result += aux;
		}
	}
	return result;
}

//Formata número tipo moeda usando o evento onKeyDown

function FormataValor(campo,tammax,teclapres,decimal) {
	var tecla = teclapres.keyCode;
	vr = Limpar(campo.value,"0123456789");
	tam = vr.length;
	dec=decimal
	
	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 <= dec )
			campo.value = vr ;
		
		if ( (tam > dec) && (tam <= 5) )
			campo.value = vr.substr( 0, tam - 2 ) + "," + vr.substr( tam - dec, tam ) ;

		if ( (tam >= 6) && (tam <= 8) )
			campo.value = vr.substr( 0, tam - 5 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ; 

		if ( (tam >= 9) && (tam <= 11) )
			campo.value = vr.substr( 0, tam - 8 ) + "." + vr.substr( tam - 8, 3 ) + "." + vr.substr( tam - 5, 3 ) + "," + vr.substr( tam - dec, tam ) ;

		if ( (tam >= 12) && (tam <= 14) )
			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 - dec, tam ) ; 

		if ( (tam >= 15) && (tam <= 17) )
			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 ) ;
	} 

}

function mascara_cnpj(objname)
{
	var obj=MM_findObj(objname);
	var cnpj = obj.value;
    var mycnpj = '';
    mycnpj = mycnpj + cnpj;
    if (mycnpj.length == 2) {
        mycnpj = mycnpj + '.';
        obj.value = mycnpj;
    }
    if (mycnpj.length == 6) {
        mycnpj = mycnpj + '.';
        obj.value = mycnpj;
    }
    if (mycnpj.length == 10) {
        mycnpj = mycnpj + '/';
        obj.value = mycnpj;
    }
    if (mycnpj.length == 15) {
        mycnpj = mycnpj + '-';
        obj.value = mycnpj;
    }
	if (mycnpj.length == 18) {
		//VerificaCnpj_Cpf(objname);	
    }
}

// Esta máscara só funciona no onChance ou onBlur
function mascara_cpf_cnpj(objname){
	var obj=MM_findObj(objname);
	var zeros = "";
	var doc = obj.value;
	// Retira a formatação
	doc = retira_formato_cpf_cnpj(doc);
	var tam = doc.length;
	if (tam <= 11) {
		if (tam<11){ // Se o cpf tem menos de 11 algarismos acrescenta zeros
			for (i=0;i<(11-tam);i++) {
				zeros=zeros+'0';
			}
			doc = zeros+doc;
		}
		doc_formatado = doc.substr(0,3)+"."+doc.substr(3,3)+"."+doc.substr(6,3)+"-"+doc.substr(9);
	} else {
		if (tam<14){ // Se o cnpj tem menos de 11 algarismos acrescenta zeros
			for (i=0;i<(14-tam);i++) {
				zeros=zeros+'0';
			}
			doc = zeros+doc;
		}
		doc_formatado = doc.substr(0,2)+"."+doc.substr(2,3)+"."+doc.substr(5,3)+"/"+doc.substr(8,4)+"-"+doc.substr(12);
	}
	obj.value = doc_formatado;
	VerificaCnpj_Cpf(objname);
}

function autotab(current,_to){
	var to = document.getElementById(_to);
    if (current.getAttribute && current.value.length==current.getAttribute("maxlength")) {
        to.focus();
		to.select();
    }
}

// Ajax

function doPost(url, content, callback_name) {
	var async_request = false;

	// Mozilla/Safari
	if (window.XMLHttpRequest) {
		async_request = new XMLHttpRequest();
		//async_request.overrideMimeType('text/xml');
	}
	// IE
	else if (window.ActiveXObject)	{
		async_request = new ActiveXObject("Microsoft.XMLHTTP");
	}
	async_request.open('POST', url, true);
	async_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	async_request.onreadystatechange = function() {
		if (async_request.readyState == 4) {
			response_content = async_request.responseText;
			eval(callback_name + '(response_content);');
		}
	}
	async_request.send(content);
}

function convertFormDataToPostContent(form_name) {
	var content_to_submit = '';
	var form_element;
	var last_element_name = '';

	for (i = 0; i < form_name.elements.length; i++)	{
		form_element = form_name.elements[i];
		switch (form_element.type)	{
		// Text fields, hidden form elements
		case 'text':
		case 'hidden':
		case 'password':
		case 'textarea':
		case 'select-one':
			content_to_submit += form_element.name + '=' 
			+ escape(form_element.value) + '&'
			break;

		// Radio buttons
		case 'radio':
			if (form_element.checked) {
				content_to_submit += form_element.name + '=' 
				+ escape(form_element.value) + '&'
			}
			break;

		// Checkboxes
		case 'checkbox':
			if (form_element.checked) {
				// Continuing multiple, same-name checkboxes
				if (form_element.name == last_element_name) {
					// Strip of end ampersand if there is one
					if (content_to_submit.lastIndexOf('&') == 
					content_to_submit.length - 1) {
						content_to_submit = content_to_submit.substr(
						0, content_to_submit.length - 1);
					}
					// Append value as comma-delimited string
					content_to_submit += ',' + escape(form_element.value);
				} else {
					content_to_submit += form_element.name + '=' 
					+ escape(form_element.value);
				}
				content_to_submit += '&';
				last_element_name = form_element.name;
			}
			break;
		}
	}

	// Remove trailing separator
	content_to_submit = content_to_submit.substr(0, content_to_submit.length - 1);
	return content_to_submit;
}

// Fim do Ajax

function checa_mail(objname) {
	var obj=MM_findObj(objname);
	var ok = true;
	var email = obj.value;
	var tamanho = email.length;
	if (tamanho>10){ 
		var arroba = email.indexOf("@"); 
		var ponto = email.indexOf(".",arroba);
		// Tem arroba e ponto no texto ??
		if (arroba<1 || ponto<1 || ponto==(tamanho-1))
			ok = false;
	} else
		ok = false;
	if (!ok) {
		alert("E-mail inválido.");
		obj.value='';
		obj.focus();
		return false;
	} else
		return true;
}

function mascara_data(objname)
{
	var obj=MM_findObj(objname);
	var data = obj.value;
    var mydata = '';
    mydata = mydata + data;
    if (mydata.length == 2) {
        mydata = mydata + '/';
        obj.value = mydata;
    }
    if (mydata.length == 5) {
        mydata = mydata + '/';
        obj.value = mydata;
    }
    if (mydata.length == 10) {
    }
}

function mascara_hora(objname)
{
	var obj=MM_findObj(objname);
	var hora = obj.value;
    var myhora = '';
    myhora = myhora + hora;
    if (myhora.length == 2) {
        myhora = myhora + ':';
        obj.value = myhora;
    }
    if (myhora.length == 5) {
    }
}

function verifica_data (objname) {
	// So funciona para os valores com mascara tipo dd/mm/aaaa ou dd/mm/aa
	var obj=MM_findObj(objname);
	var dia,mes,ano;
	var data = obj.value;
	dia = data.substr(0,2);
	mes = data.substr(3,2);
	ano = data.substr(6);
	situacao = "";
	// verifica o dia valido para cada mes
	if ((dia < 1)||(dia < 1 || dia > 30) && (  mes == 4 || mes == 6 || mes == 9 || mes == 11 ) || dia > 31) {
		situacao = "falsa";
	}
	
	// verifica se o mes e valido
	if (mes < 1 || mes > 12 ) {
		situacao = "falsa";
	}
	
	// verifica se e ano bissexto
	if (mes == 2 && ( dia < 1 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) {
		situacao = "falsa";
	}
	
	if (situacao == "falsa") {
		obj.value='';
		obj.focus();
		alert("Data inválida!");
		return false;
	} else {
		return true;
	}
}

function verifica_hora (objname) {
	// So funciona para os valores com mascara tipo hh:mm
	var obj=MM_findObj(objname);
	var hora, minuto;
	var horas = obj.value;
	hora = parseInt(horas.substr(0,2));
	minuto = parseInt(horas.substr(3));
	// verifica a hora
	if ((hora >=0 && hora<=23) && (minuto >=0 && minuto<=59))
		return true;
	else {
		obj.value='hh:mm';
		obj.focus();
		alert("Hora inválida");
		return false;
	}
} 

function buscar_cep(){
	if(get('campoCEP').value == ''){
		return false;
	}
	get('resultado').innerHTML = "<br><center><font size=1>aguarde, consultando</font><br><img src='/img/loading.gif'></center>";
	get_url('http://cep.republicavirtual.com.br/web_cep.php?formato=javascript&cep='+get('campoCEP').value, 'retorno_cep');
}

function retorno_cep(codigo){
	eval(codigo);
	html_retorno = "<br>";
	switch(resultadoCEP['resultado']){
		case '1':
			html_retorno += "<center><strong>Resultado da busca:</strong> <br><font color=green>"+unescape(resultadoCEP['resultado_txt'])+"</font></center><br><table border=0 align=center>"+
			"<tr><td align=right><b>Tipo de logradouro:</b></td><td>"+	unescape(resultadoCEP['tipo_logradouro'])+"</td></tr>"+
			"<tr><td align=right><b>Logradouro:</b></td><td>"+			unescape(resultadoCEP['logradouro'])+"</td></tr>"+
			"<tr><td align=right><b>Bairro:</b></td><td>"+				unescape(resultadoCEP['bairro'])+"</td></tr>"+
			"<tr><td align=right><b>Logradouro:</b></td><td>"+			unescape(resultadoCEP['cidade'])+"</td></tr>"+
			"<tr><td align=right><b>UF:</b></td><td>"+					unescape(resultadoCEP['uf'])+"</td></tr>"+
			"</table>";
		break;
		
		case '2':
			html_retorno += "<center><strong>Resultado da busca:</strong> <br><font color=green>"+unescape(resultadoCEP['resultado_txt'])+"</font></center><br><table border=0 align=center>"+
			"<tr><td align=right><b>Logradouro:</b></td><td>"+			unescape(resultadoCEP['cidade'])+"</td></tr>"+
			"<tr><td align=right><b>UF:</b></td><td>"+					unescape(resultadoCEP['uf'])+"</td></tr>"+
			"</table>";
		break;
		
		default:
			html_retorno += "<center><strong>Resultado da busca:</strong> <font color=red>"+unescape(resultadoCEP['resultado_txt'])+"</font></center>";
		break;
	}
	get('resultado').innerHTML = html_retorno;
}

function alerta() {
	if (!confirm('Esta operação é irreversível!\nDeseja continuar ?')) return false; 
	return true;
}

function formataCPF(Campo, teclapres){

	if (window.event) {
		var tecla = teclapres.keyCode;
	} else var tecla = teclapres.which;

   var vr = new String(Campo.value);
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace("/", "");
   vr = vr.replace("-", "");

   tam = vr.length + 1;

   
   if (tecla != 9 && tecla != 8){
      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 < 13)
         Campo.value = vr.substr(0,3) + '.' + vr.substr(3,3) + '.' + vr.substr(6,3) + '-' + vr.substr(9,tam-9);
      }
}

function formataCNPJ(Campo, teclapres){

   if(window.event){
    var tecla = teclapres.keyCode;
   }else  tecla = teclapres.which;

   var vr = new String(Campo.value);
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace("/", "");
   vr = vr.replace("-", "");

   tam = vr.length + 1;

   
   if (tecla != 9 && tecla != 8){
      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);
      }
}

function formataCEP(Campo, teclapres){

   if(window.event){
    var tecla = teclapres.keyCode;
   }else  tecla = teclapres.which;

   var vr = new String(Campo.value);
   vr = vr.replace(".", "");
   vr = vr.replace(".", "");
   vr = vr.replace("/", "");
   vr = vr.replace("-", "");

   tam = vr.length + 1;

   
   if (tecla != 9 && tecla != 8){
      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);
   }
}

function formataTel(Campo, teclapres){

   if(window.event){
    var tecla = teclapres.keyCode;
   }else  tecla = teclapres.which;

   var vr = new String(Campo.value);
   vr = vr.replace("(", "");
   vr = vr.replace(")", "");
   vr = vr.replace("-", "");

   tam = vr.length + 1;

   
   if (tecla != 9 && tecla != 8){
      if (tam > 2 && tam < 7)
         Campo.value = '(' + vr.substr(0,2) + ')' + vr.substr(2, tam);
      if (tam >= 7 && tam < 10)
         Campo.value = '(' + vr.substr(0,2) + ')' + vr.substr(2,4) + '-' + vr.substr(6,tam-6);
   }
}

function formataData(Campo, teclapres){

   if(window.event){
    var tecla = teclapres.keyCode;
   }else  tecla = teclapres.which;

   var vr = new String(Campo.value);
   vr = vr.replace("/", "");

   tam = vr.length + 1;

   
   if (tecla != 9 && tecla != 8){
      if (tam > 2 && tam < 5)
         Campo.value = vr.substr(0,2) + '/' + vr.substr(2, tam);
      if (tam >= 5 && tam < 7)
         Campo.value = vr.substr(0,2) + '/' + vr.substr(2,2) + '/' + vr.substr(4,tam-4);
   }
}

function abreMapa() {
	document.getElementById("mapaGoogle").style.display='block';
}

function fechaMapa() {
	document.getElementById("mapaGoogle").style.display='none';
}

this.addEvent = function(obj,type,fn){
	if(obj.attachEvent){
		obj['e'+type+fn] = fn;
		obj[type+fn] = function(){obj['e'+type+fn](window.event );}
		obj.attachEvent('on'+type, obj[type+fn]);
	} else {
		obj.addEventListener(type,fn,false);
	};
};
/* Mapa do Google */
function initialize() {
  if (GBrowserIsCompatible()) {
	var map = new GMap2(document.getElementById("map_canvas"),
		{ size: new GSize(640,320) } );
	map.setCenter(new GLatLng(-12.9705662,-38.5136279), 16);
	var customUI = map.getDefaultUI();
	// Remove MapType.G_HYBRID_MAP
	customUI.maptypes.hybrid = false;
	map.setUI(customUI);
	//Faz uma marcação na SEDE
	var point = new GLatLng(-12.9705662,-38.5136279);
	map.addOverlay(new GMarker(point,{title:"Sede USUPORT"}));

  }
}
addEvent(window,"unload",GUnload);

function getElementsByClassName(classname, node)  {
    if(!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for(var i=0,j=els.length; i<j; i++)
        if(re.test(els[i].className))a.push(els[i]);
    return a;
}