// JavaScript Document
function flash(largura, altura, arquivo, transparencia){
 document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largura+'" height="'+altura+'" id="teste" align="middle">');
 document.write('<param name="allowScriptAccess" value="sameDomain" /><param name="wmode" value="'+transparencia+'" /><param name="menu" value="false" />');
 document.write('<param name="movie" value="'+arquivo+'" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><embed src="'+arquivo+'" wmode="'+transparencia+'" menu="false" quality="best" width="'+largura+'" height="'+altura+'" name="teste" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
 document.write('</object>');
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}


<!--

function updateClock(d) {
  var currentTime = new Date(d);

  var currentHours = currentTime.getHours();
  var currentMinutes = currentTime.getMinutes();
  var currentSeconds = currentTime.getSeconds();

  // Pad the minutes and seconds with leading zeros, if required
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

  // Choose either "AM" or "PM" as appropriate
  // var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";

  // Convert the hours component to 12-hour format if needed
  // currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

  // Convert an hours component of "0" to "12"
  // currentHours = ( currentHours == 0 ) ? 12 : currentHours;

  // Compose the string for display
  // var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
  
  // Correcao de erro na data (6h a menos)
  currentHours += 6;
  currentHours = ( currentHours > 24 ) ? currentHours - 24 : currentHours;
  
  var currentTimeString = currentHours + ":" + currentMinutes;

  // Update the time display
  document.getElementById("clock").firstChild.nodeValue = currentTimeString;
  
  dx=d+1000;
  setTimeout("updateClock(dx)", 1000);
}


// copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
// Modo de usar:  <INPUT NAME="dollar" SIZE="5" MAXLENGTH="5" onKeyPress="return numbersonly(this, event)">

function numbersonly(myfield, e, dec) {
	var key;
	var keychar;
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	   return true;
	
	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;
	
	// decimal point jump
	else if (dec && (keychar == ".")) {
	   myfield.form.elements[dec].focus();
	   return false;
	} else
	   return false;
}


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

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() + ' caracteres restantes';//exibe o texto na div
}

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

function formataCPF(Campo, e){

	if (numbersonly(Campo, e)) {
		if (window.event) {
			var tecla = e.keyCode;
		} else var tecla = e.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);
		}
	} else {
		return false;
	}
}

function formataRG(campo, e) {
	if (numbersonly(campo, e)) {
		if (window.event) {
			var tecla = e.keyCode;
		} else var tecla = e.which;
	
		var vr = new String(campo.value);
		vr = vr.replace(" ", "");
		
		tam = vr.length + 1;
	
	   
		if (tecla != 9 && tecla != 8) {
			if (tam > 8 && tam < 11)
			   campo.value = vr.substr(0,8) + ' ' + vr.substr(8,tam-8);
		}
	} else {
		return false;
	}	
}

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 (numbersonly(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);
		}
	} else {
		return false;
	}
}

function formataTel(Campo, e){

	if (numbersonly(Campo, e)) {
		if (window.event)
	   		var tecla = window.event.keyCode;
		else if (e)
	  		tecla = e.which;
		
		var v = Campo.value;
		v = v.replace(/\D/g,"");
        v = v.replace(/^(\d\d)(\d)/g,"($1) $2");
        v = v.replace(/(\d{4})(\d)/,"$1-$2");
		Campo.value = v;
	} else {
		return false;
	}
}

function formataData(Campo, teclapres){

	if (numbersonly(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);
		}
	} else {
		return false;
	}
}


function alerta() {
	if (!confirm('Esta operação é irreversível!\nDeseja continuar ?')) return false; 
}
function alerta2() {
	if (!confirm('Esta operação apagará todos os registros desta mídia e seu histórico de utilização!\nDeseja continuar ?')) return false; 
}
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_dmenu(objname) {
	var obj = MM_findObj(objname);
	if(obj && obj.style) obj.style.display = (obj.style.display=="none") ? "" : "";
}

function MM_dmenuClose(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 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 mudaAba2(abaEscolhida,qtd) {
	
	for(x=1;x<=qtd;x++) {
		aba = 'aba'+x;
		ctd = 'ctd'+x;
		with (document.getElementById(aba)) {
			style.borderColor="#ccc";
			style.borderBottomColor="#000";
		}
		MM_dmenuh(ctd);		
	}
	aba = 'aba'+abaEscolhida;
	ctd = 'ctd'+abaEscolhida;
	MM_dmenus(ctd);
	with (document.getElementById(aba)) {
		style.borderLeftColor="#000";
		style.borderLeftStyle="solid";
		style.borderLeftWidth="1px";
		style.borderRightColor="#000";
		style.borderRightStyle="solid";
		style.borderRightWidth="1px";
		style.borderTopColor="#000";
		style.borderTopStyle="solid";
		style.borderTopWidth="1px";
		style.borderBottomColor="#fff";
	}
}

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

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 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();
    }
}

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=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);
}

// 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 soLetras(campo, e) {
	var key;
	var keychar;
	
	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);
	
	// control keys
	if ((key==null) || (key==0) || (key==8) || 
		(key==9) || (key==13) || (key==27) )
	   return true;
	
	// numbers
	else if ((("0123456789/;:.,<>?-_+=}{][()*&¨%$#@!|\\ªº¹²³£¢¬§°'\"").indexOf(keychar) == -1)) {
	   return true;
	} else
	   return false;
}

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 FormataInteiro(objname){
	var obj=MM_findObj(objname);
	var valor = Limpar(obj.value,"0123456789");
    var formatado = '';
	var tam = valor.length;
	if (tam>3) {
		var ponto = tam-4;
		for (var i=tam-1; i>=0; i--) {
			if (i==ponto) {
				formatado = "." + formatado;
			}
			formatado = valor.charAt(i) + formatado;
		}
		valor=formatado;
	}
	if (tam>6) {
		var ponto = tam-7;
		for (var i=tam-1; i>=0; i--) {
			if (i==ponto) {
				formatado = "." + formatado;
			}
			formatado = valor.charAt(i) + formatado;
		}
		valor=formatado;
	}
	obj.value = valor;
}

// 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'); // comentar esta linha para funcionar no IE7
	}
	// 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;
}

function setaCheckBox(id) {
	checkBox = document.getElementById(id);
	if (checkBox.checked) {
		checkBox.value = 's';
	} else {
		checkBox.value = 'n';
	}
}

function excluirCategoria() {
	categoria = document.getElementById('selCategoria');
	if (categoria.value != '') {
		form = document.forms[0];
		form.acao.value = 'excluir categoria';
		form.submit();
	} else {
		alert('É preciso escolher uma categoria para exluir.');
	}
}

function criarCategoria(valor) {
	botaoExcluirCategoria = document.getElementById('botaoExcluirCategoria');
	trNovaCategoria = document.getElementById('trClassificadosNovaCategoria');
	if (valor == 'nova') {
		trNovaCategoria.style.visibility = 'visible';
		botaoExcluirCategoria.setAttribute("disabled","disabled");
	}else if (valor == '') {
		trNovaCategoria.style.visibility = 'collapse';
		botaoExcluirCategoria.setAttribute("disabled","disabled");
	} else {
		trNovaCategoria.style.visibility = 'collapse';
		botaoExcluirCategoria.removeAttribute("disabled");
	}
}

function adicionarCategoria(id) {
	novaCategoria = document.getElementById(id);
	if (novaCategoria.value != '') {
		form = document.forms[0];
		form.acao.value = 'adicionar categoria';
		form.submit();
	} else {
		alert('Campo Nova categoria vazio.');
	}
}

function checkMail(mail){
	var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if (typeof(mail) == "string") {
    	if(er.test(mail)) {
			return true;
		}
	} else if (typeof(mail) == "object") {
        if(er.test(mail.value)) { 
            return true; 
        }
    } else {
        return false;
    }
}
