// funcoes d validação
function FormataCampo(Campo,teclapres,mascara){
	//pegando o tamanho do texto da caixa de texto com delay de -1 no event
	//ou seja o caractere que foi digitado não será contado.
	strtext = Campo.value
	tamtext = strtext.length
	//pegando o tamanho da mascara
	tammask = mascara.length
	//criando um array para guardar cada caractere da máscara
	arrmask = new Array(tammask)	
	//jogando os caracteres para o vetor
	for (var i = 0 ; i < tammask; i++){
		arrmask[i] = mascara.slice(i,i+1)
	} 
	//alert (teclapres.keyCode)
	//começando o trabalho sujo
	if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))){
		if ((teclapres.keyCode >= 37 && teclapres.keyCode <= 40)||(teclapres.keyCode >= 48 && teclapres.keyCode <= 57)||(teclapres.keyCode >= 96 && teclapres.keyCode <= 105)||(teclapres.keyCode == 8)||(teclapres.keyCode == 9) ||(teclapres.keyCode == 46) ||(teclapres.keyCode == 13)){
			Organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext)		
		}
		else{
			Detona_Event(Campo,strtext)
		}
	}
	else{//Aqui funcionaria a mascara para números mas eu ainda não implementei
		if ((arrmask[tamtext] == "A"))	{
			charupper = event.valueOf()
			//charupper = charupper.toUpperCase()
			Detona_Event(Campo,strtext)
			masktext = strtext + charupper 
			Campo.value = masktext
		}
	}
}

// Função abre nova janela
// utilização: 											PROPRIEDADES
//				abrejanela('PAGINA.htm','TITULO','scrollbars=yes,resizable=no,width=500,height=400')"

function trimAll(sString) 
{
  while (sString.substring(0,1) == ' ')
   {
     sString = sString.substring(1, sString.length);
   }
  while (sString.substring(sString.length-1, sString.length) == ' ')
   {
     sString = sString.substring(0,sString.length-1);
   }
  return sString;
}


function rightTrim(sString) 
{
   while (sString.substring(sString.length-1, sString.length) == ' ')
    {
      sString = sString.substring(0,sString.length-1);
    }
      return sString;
}



function leftTrim(sString) 
{
   while (sString.substring(0,1) == ' ')
     {
       sString = sString.substring(1, sString.length);
     }
   return sString;
}


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

function abrejanela(url,nome,propriedades){ 
   window.open(url,nome,propriedades);
}

//Checa o campo E-Mail
function verifica_mail(email){
	var campo = email;
	//se a "@" não existe e é o primeiro caractere 
	if (campo.indexOf("@") < 1) return false
	//se o caracter antes da "@" é "." 
	if(campo.charAt(campo.indexOf("@")-1) == ".") return false;
	//se a última incidência de "." está antes da @ 
	if (campo.lastIndexOf(".") <= campo.indexOf("@")) return false;
	//se o último caracter é ponto,
	if (campo.lastIndexOf(".")  == (campo.length-1)) return false; 
	
	return true;
}

function val_cnpj(numero) {
	//numero = numero1.value;
	dig_1 = 0;
	dig_2 = 0;
	controle_1 = 5;
	controle_2 = 6;

if ( (numero.length != 18)  || (numero.substring(2, 3) != ".") || (numero.substring(6, 7) != ".") || (numero.substring(10, 11) != "/") || (numero.substring(15, 16) != "-") ) {
     return false;
}else{ 
  	   numero = (numero.substring(0, 2)) + "" + (numero.substring(3, 6)) + "" + (numero.substring(7, 10))+ "" + (numero.substring(11, 15)) + "" + (numero.substring(16, 18)) 
	   for ( i=0 ; i < 12 ; i++) {
	        dig_1 = dig_1 + parseFloat(numero.substring(i, i+1) * controle_1);
	          controle_1 = controle_1 - 1;
	        if (i == 3) {
	           controle_1 = 9;
	        }
	   }
	   
	   resto = dig_1 % 11;
	   dig_1 = 11 - resto;
	   
	   if ((resto == 0) || (resto == 1)){
	        dig_1 = 0;
	   }
	   
	   for ( i=0 ; i < 12 ; i++) {
	        dig_2 = dig_2 + parseInt(numero.substring(i, i+1) * controle_2);
	          controle_2 = controle_2 - 1;
	        if (i == 4) {
	           controle_2 = 9;
	        }
	   }
	   
	   dig_2 = dig_2 + (2 * dig_1);
	   resto = dig_2 %11;
	   dig_2 = 11 - resto;
	   
	   if ((resto == 0) || (resto == 1)){
	        dig_2 = 0;
	   }
	   
	   dig_ver = (dig_1 * 10) + dig_2;
	   
	   if (dig_ver != parseFloat(numero.substring(numero.length-2,numero.length))) {
	          return false;
	   }
 }
 return true;
}

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

function FormataCNPJ(Campo, teclapres){

	var tecla = teclapres.keyCode;

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

//Valida o cpf 
function val_cpf(numero2) {
  dig_1 = 0;
  dig_2 = 0;
  controle_1 = 10;
  controle_2 = 11;
  lsucesso = 1;
  
  var numero = numero2.substr(0,3) + numero2.substr(4,3) + numero2.substr(8,3) + numero2.substr(12,2);
  
  if (numero == "00000000000" || numero == "11111111111" || numero == "22222222222" || numero == "33333333333" || numero == "44444444444" || numero == "55555555555" || numero == "66666666666" || numero == "77777777777" || numero == "88888888888" || numero == "99999999999") {
  	return false;
  }
  
  if ((numero.length != 11) && (numero.length != 0)) {
     return false;
  }
  else {
     for ( i=0 ; i < 9 ; i++) {
        dig_1 = dig_1 + parseInt(numero.substring(i, i+1) * controle_1);
          controle_1 = controle_1 - 1;
     }
    
     resto = dig_1 % 11;
     dig_1 = 11 - resto;
     if ((resto == 0) || (resto == 1)) {
          dig_1 = 0;
     }
     for ( i=0 ; i < 9 ; i++) {
          dig_2 = dig_2 + parseInt(numero.substring(i, i + 1) * controle_2);
        controle_2 = controle_2 - 1;
     }
     dig_2 = dig_2 + 2 * dig_1;
     resto = dig_2 % 11;
     dig_2 = 11 - resto;
     if ((resto == 0) || (resto == 1)) {
        dig_2 = 0;
     }
     dig_ver = (dig_1 * 10) + dig_2;
     if (dig_ver != parseFloat(numero.substring(numero.length-2,numero.length))) {
          return false;
        }
  }

return true;
}

function abre_impressao(url) {
	window.open(url, "impressao", "width=600,height=450");
}
//Utilização: onkeypress="evita_letra(event)" onKeydown="FormataHora('NOMEDOCAMPO','NOMEDOFORM',event)" maxlength="5"
function FormataHora(campo,formname,teclapres){
	var tecla = teclapres.keyCode;
	vr = document[formname][campo].value;
	vr = vr.replace( ":", "" );
	tam = vr.length + 1;
	
	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 ){
			document[formname][campo].value = vr.substr( 0, tam - 2  ) + ':' + vr.substr( tam - 2, tam );
		}
	}
}
// FUNÇÃO QUE AUTOCOMPLETA DATA COM '/'
// COMO UTILIZAR:    onkeydown="FormataData(this.name,this.form.name,event);" 
function FormataData(campo,formname,teclapres) { // Máscara para os campos de data
	var tecla = teclapres.keyCode;
	vr = document[formname][campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document[formname][campo].value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			document[formname][campo].value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
}
// COMO UTILIZAR: onkeypress="evita_letra2(event)"
// Não permite digitar letras em um input type=text
function evita_letra2(tecla) {
	if (tecla.keyCode < 48 || tecla.keyCode > 57) 
		tecla.returnValue = false;
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function ToggleAll(checked) {
    len = document.listagem.elements.length;
    var i = 0;
    for(i = 0; i < len; i++) {
        document.listagem.elements[i].checked = checked;
    }
}

function in_array(s,a) {
  for (i = 0; i < a.lenght; i++) {
	  /*if (a[i] == s) {
	  	return true;
	  }*/
	  alert(a[i]+'=='+s.name);
  }
  //return false;
}


// HINT
// Example:
// onMouseOver="hint('tool tip text here')";
// onMouseOut="hint()";
// -or-
// onMouseOver="hint('more good stuff', '#FFFF00', 'orange')";
// onMouseOut="hint()"; 
/*

MOVE this to the <body>:
<div id="hintLayer" style="position:absolute; visibility: hidden"></div>
<script language="JavaScript"><!--
initToolTips(); //--></script>
*/
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all;
var ie4 = document.all;
offsetX = 0;
offsetY = 20;
var hintSTYLE="";
function initToolTips()
{
  if(ns4||ns6||ie4)
  {
    if(ns4) hintSTYLE = document.hintLayer;
    else if(ns6) hintSTYLE = document.getElementById("hintLayer").style;
    else if(ie4) hintSTYLE = document.all.hintLayer.style;
    if(ns4) document.captureEvents(Event.MOUSEMOVE);
    else
    {
      hintSTYLE.visibility = "visible";
      hintSTYLE.display = "none";
    }
    document.onmousemove = moveToMouseLoc;
  }
}
function hint(msg, fg, bg)
{
  if(hint.arguments.length < 1) // hide
  {
    if(ns4) hintSTYLE.visibility = "hidden";
    else hintSTYLE.display = "none";
  }
  else // show
  {
    if(!fg) fg = "#777777";
    if(!bg) bg = "#FFFFFF";
    var content =
    '<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + fg + '"><td>' +
    '<table border="0" cellspacing="0" cellpadding="1" bgcolor="' + bg + 
    '"><td align="center"><font face="sans-serif" color="' + fg +
    '" size="-2">&nbsp\;' + msg +
    '&nbsp\;</font></td></table></td></table>';
    if(ns4)
    {
      hintSTYLE.document.write(content);
      hintSTYLE.document.close();
      hintSTYLE.visibility = "visible";
    }
    if(ns6)
    {
      document.getElementById("hintLayer").innerHTML = content;
      hintSTYLE.display='block'
    }
    if(ie4)
    {
      document.all("hintLayer").innerHTML=content;
      hintSTYLE.display='block'
    }
  }
}
function moveToMouseLoc(e)
{
  if(ns4||ns6)
  {
    x = e.pageX;
    y = e.pageY;
  }
  else
  {
    x = event.x + document.body.scrollLeft;
    y = event.y + document.body.scrollTop;
  }
  hintSTYLE.left = x + offsetX;
  hintSTYLE.top = y + offsetY;
  return true;
}

// formulario , 'array de valores obrigatorios '
function obrigatorio(ffff,ele)
{//começa valida
  var c=ele.split(',');
  for(x = 0; x<ffff.elements.length; x++)//varre o formulário
  {  
    //alert(c[x]);//atriz com os elementos
	//e = document.getElementById(c[x]);
	
	for(j=0;j<c.length;j++)//varre os obrigatórios
	{
	   var formul=ffff.elements[x];
	   //alert(formul);
       if(formul.name==c[j] &&  leftTrim(formul.value)=='')//se tem o elemento no formulário
	   {
	      alert('O campo '+document.getElementById(formul.name+"_label").innerHTML+' é obrigatorio');
//		  ffff.elements[formul.name].className='erro';
		  ffff.elements[formul.name].focus();		 
		  return false;
	   }
	}//fim for
	
  }//fim for
  return true;
  //ffff.submit();
}//fim valida

// formata campo valor
function FormataValor(tammax,teclapres, tf) { 
	var tecla = teclapres.keyCode;
	vr = tf.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 ){ 
	 		tf.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		tf.value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		tf.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		tf.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) ){
	 		tf.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) ){
	 		tf.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 ) ;}
	}
}
// formata campo valor
function FormataDt(tammax,teclapres, tf) {
	var tecla = teclapres.keyCode;
	vr = tf.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 ){ 
	 		tf.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		tf.value = vr.substr( 0, tam - 2 ) + '/' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		tf.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		tf.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) ){
	 		tf.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) ){
	 		tf.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 ) ;}
	}
}


//FUNÇÃO PARA MOSTRAR OU ESCONDER DIV OU ID
function mostra(div){
	if(document.getElementById(div).className=='mostra'){
		document.getElementById(div).className = 'esconde';
	}else{
		document.getElementById(div).className = 'mostra';
	}
}  


// monta selects

// inicia ajax para a busca dos dados da empresa quando efetuada uma pesquisa
var ajax = new sack();

function limpa(campo){
	var marca = campo.options;
	marca.length = 1;
}
// seleção das marcas apos escolhido uma categoria		
function getMarca(cat){
	if(cat!=''){
		var pagina = 'modulos/busca/veiculos/marca.inc.php?cat='+cat;		
		limpa(document.getElementById('marca'));
		ajax.requestFile = pagina;	
		ajax.onLoading = document.getElementById('msel').innerHTML='Carregando...';
		ajax.onCompletion = function(){
			document.getElementById('msel').innerHTML='Selecione...';
			document.getElementById('marca').focus();
			eval(ajax.response);
		}	
			ajax.runAJAX();	
	}
}	
// selecao dos modelos a partir de uma marca
function getModelo(marca){
	if(marca!=''){
		var pagina = 'modulos/busca/veiculos/modelos.inc.php?marca='+marca;		
		limpa(document.getElementById('modelo'));
		ajax.requestFile = pagina;	
		ajax.onLoading = document.getElementById('mosel').innerHTML='Carregando...';
		ajax.onCompletion = function(){
			document.getElementById('mosel').innerHTML='Selecione...';
			document.getElementById('modelo').focus();
			eval(ajax.response);
		}	
			ajax.runAJAX();	
	}
}

// selecao da loja
function getLoja(id){
	var pagina = 'modulos/veiculos/lojas/modulo.php?loja='+id;		
	ajax.requestFile = pagina;
	ajax.onLoading = document.getElementById('meio').innerHTML='<div id="carregando">Carregando...<br /><img src="images/carregando.gif" width="86" height="10" /></div>';
	ajax.onCompletion = function(){
		document.getElementById('meio').innerHTML=ajax.response;
	}
	ajax.runAJAX();	
}	



// seleciona um item do guia por categoria
function getGuia(id){
	var pagina = 'modulos/guia/modulo.php?cat='+id;		
	ajax.requestFile = pagina;	
	ajax.onLoading = document.getElementById('guia').innerHTML='<div id="carregando">Carregando...<br /><img src="images/carregando.gif" width="86" height="10" /></div>';
	ajax.onCompletion = function(){
		document.getElementById('guia').innerHTML=ajax.response;
	}	
	ajax.runAJAX();	
}	

// verifica se retornou alguma coisa 
function pegaUsr(xmlhttp){
	//alert(xmlhttp.responseText);
	if(xmlhttp.responseText.length == 8){
		document.getElementById('login').className='mostra';	
		alert('E-Mail e ou Senha inválidos ou não cadastradado!');	
	}else{
		document.getElementById('carregando').className='mostra';	
		dados = pegarConteudo(xmlhttp.responseText);
		gravaSession(dados[1][4],dados[1][5]);
	}
}
// grava a sessão ou retorna mensagem ao usuario 
function gravaSession(u2,s2){
	if(s2!=document.getElementById('senha').value){
		alert('Erro ao tentar sincronizar conferência da senha');
		return false;
	}
	var pagina = 'modulos/login/setSession.php?e='+u2+'&s='+s2;
	ajax.requestFile = pagina;	
	ajax.onLoading = document.getElementById('carregando').className='mostra';
	ajax.onCompletion = function(){
		//alert(ajax.response);
		if(ajax.response=='logado'){
			document.getElementById('carregando').className='esconde';
			location.href="anunciante/index.php";
		}else{
			alert("Não foi possivel efetuar o login. \n "+ ajax.response);
			document.getElementById('carregando').className='esconde';
			document.getElementById('login').className='mostra';	
		}
	}	
	ajax.runAJAX();	
}
// transforma miniatura em foto grande sem refresh 
function getFoto(foto,tipo,id,ft){
	var pagina = 'modulos/'+tipo+'/detalhes/foto.php?foto='+foto+'&id='+id+'&ft='+ft;
	ajax.requestFile = pagina;	
	ajax.onLoading = document.getElementById('foto').innerHTML='<div id="carregando">Carregando...<br /><img src="images/carregando.gif" width="86" height="10" /></div>';
	ajax.onCompletion = function(){
		document.getElementById('foto').innerHTML=ajax.response;
	}	
	ajax.runAJAX();	
}

// seleciona a proposta para resposta
function getProp(id){
	var pagina = 'modulos/anunciante/propostas/modulo.php?id='+id;		
	ajax.requestFile = pagina;	
	ajax.onLoading = document.getElementById('anunciante').innerHTML='<div id="carregando">Carregando...<br /><img src="images/carregando.gif" width="86" height="10" /></div>';
	ajax.onCompletion = function(){
		document.getElementById('anunciante').innerHTML=ajax.response;
	}
	ajax.runAJAX();
}

// seleciona anuncio para alterar dados
function getAnuncio(id,cat,marca,modelo){
	var pagina = 'modulos/anunciante/anuncios/modulo.php?id='+id;		
	ajax.requestFile = pagina;	
	ajax.onLoading = document.getElementById('anunciante').innerHTML='<div id="carregando">Carregando...<br /><img src="images/carregando.gif" width="86" height="10" /></div>';
	ajax.onCompletion = function(){
		document.getElementById('anunciante').innerHTML=ajax.response;
		hint();
		getMarca2(cat,marca,modelo);
	}	
	ajax.runAJAX();	
}	

// seleção das marcas apos escolhido uma categoria e marca existentes
function getMarca2(cat,marca,modelo){
	if(cat!=''){
		var pagina = 'modulos/anunciante/anuncios/marca.inc.php?cat='+cat+'&marca='+marca;	
		ajax.requestFile = pagina;	
		ajax.onLoading = document.getElementById('msel').innerHTML='Carregando...';
		ajax.onCompletion = function(){
			document.getElementById('msel').innerHTML='Selecione...';
			eval(ajax.response);
			getModelo2(marca,modelo);
		}	
			ajax.runAJAX();	
	}
}	
// selecao dos modelos a partir de uma marca e modelo ja existentes
function getModelo2(marca,modelo){
	if(marca!=''){
		var pagina = 'modulos/anunciante/anuncios/modelos.inc.php?marca='+marca+'&modelo='+modelo;		
		ajax.requestFile = pagina;	
		ajax.onLoading = document.getElementById('mosel').innerHTML='Carregando...';
		ajax.onCompletion = function(){
			document.getElementById('mosel').innerHTML='Selecione...';
			eval(ajax.response);
		}	
			ajax.runAJAX();	
	}
}

// alterar o status do anuncio
function setStatus(id,tipo){
	var pagina = 'modulos/anunciante/anuncios/mudastatus.php?id='+id+'&tipo='+tipo;		
	ajax.requestFile = pagina;	
	ajax.onCompletion = function(){
		document.getElementById('statusImg'+id).innerHTML = ajax.response;		
	}	
	ajax.runAJAX();	
}

// abre boleto
function getBoleto(id){
	var url = 'modulos/anunciante/financeiro/boleto/boleto.php?id='+id;
	var nome = 'Boleto';
	var propriedades ='menubar=yes,scrollbars=yes,resizable=yes,width=777,height=600';

	abrejanela(url,nome,propriedades);
}
