﻿// PARA QUE O METOD INDEXOF FUNCIONE EM TODOS OS NAVEGADORES
if (!Array.prototype.indexOf) { 
 Array.prototype.indexOf = function(elt /*, from*/){ 
   var len = this.length >>> 0; 
   var from = Number(arguments[1]) || 0; 
   from = (from < 0) 
        ? Math.ceil(from) 
        : Math.floor(from); 
   if (from < 0) 
     from += len; 
   for (; from < len; from++){ 
     if (from in this && 
         this[from] === elt) 
       return from; 
   } 
   return -1; 
 }; 
} 
// PARA QUE O METOD INDEXOF FUNCIONE EM TODOS OS NAVEGADORES


// CARREGA PAGINAS
function load_carrega(modo) {
if(modo == 'h') { document.getElementById( "div_transparency" ).style.visibility = "hidden"; }
if(modo == 'v') { document.getElementById( "div_transparency" ).style.visibility = "visible"; }
}
// CARREGA PAGINAS

// DIV OPACIONAIS
function opcionais_filtro(modo) {
  if (modo == 'abrir') {
  $('#btn_seta_opc').html('<img src="../images/btn_seta.png" width="22" height="23" title="FECHAR BUSCA DE OPCIONAIS" style="cursor:pointer" onClick="opcionais_filtro(\'fechar\')">');
  $('#btn_seta_opc2').html('<div style="cursor:pointer; height:22px;" onClick="opcionais_filtro(\'fechar\')"></div>');
  $('#div_opcionais').slideDown();
  document.getElementById("div_opcionais").style.visibility="visible";
  
  if ( $('.check_opcionais').size() == 0){
	  $('#div_check_opcionais').html('<div align="center"><img src="../images/spinner.gif" align="absmiddle"><br><br><b>Carregando Opcionais...</b></div>');
	  $.post("../_includes/_busca_veiculo_opcionais.php",
	  {id:(123)},
	  function(valor){
	  $('#div_check_opcionais').html(valor);
	  } )   	  
   }
  }
  
  if (modo == 'fechar') {
  $('#btn_seta_opc2').html('<div style="cursor:pointer; height:22px;" onClick="opcionais_filtro(\'abrir\')"></div>');	  	  	  
  $('#btn_seta_opc').html('<img src="../images/btn_seta2.png" width="22" height="23" title="ABRIR BUSCA DE OPCIONAIS" style="cursor:pointer" onClick="opcionais_filtro(\'abrir\')">');	  
  $('#div_opcionais').slideUp();
  //document.getElementById("div_opcionais").style.visibility="hidden"; 
  }
}
// DIV OPCIONAIS


// NEWS LETTER
function news(modo){

if (modo=='abrir') {

 $("#div_news").animate({ marginLeft: 416 }, "normal" );

 $("#div_news2").animate({ width: 260 }, "normal" );
  
$('#div_news2').html('<table width="33%" border="0" cellspacing="2" cellpadding="0"><tr><td width="26%" nowrap><input type="text" name="news_nome" id="news_nome" style="width:100px" class="text_form_login" onfocus="if(this.value==\'digite seu nome\'){this.value=\'\'};" onblur="if(this.value==\'\'){this.value=\'digite seu nome\'};" value="digite seu nome"></td><td width="27%" nowrap><input name="news_email" type="text" class="text_form_login" id="news_email" style="width:100px" value="digite seu email" onfocus="if(this.value==\'digite seu email\'){this.value=\'\'};" onblur="if(this.value==\'\'){this.value=\'digite seu email\'};"></td><td width="47%" nowrap><div id="div_btn_news"><img src="../images/btn_ok.png" width="27" height="25" onClick="news(\'enviar\')" style="cursor:pointer"></div></td></tr></table>');
$('#btn_news').html('<img src="../images/news_right2.png" width="29" height="39" onClick="news(\'fechar\')" style="cursor:pointer" title="FECHAR NEWSLETTER">');

} // final do if abrir
 
if (modo=='fechar') {	
 
 $("#div_news2").animate({ width: 150 }, "normal" );
 
 $('#div_news2').animate({ "width": 150 }, "normal"); 
 $('#div_news2').html('<span class="titulos_news">Newsletter</span>');
 $('#btn_news').html('<img src="../images/news_right.png" width="29" height="39" onClick="news(\'abrir\')" style="cursor:pointer" title="FECHAR NEWSLETTER">');
  
 $("#div_news").animate({ marginLeft: 526 }, "normal" );

} // final do if fechar

if (modo=='enviar') {
 $('#div_btn_news').html('<img src="../images/spinner.gif" align="absmiddle">');
 $.post("../_includes/_enviar_news.php",
 {news_nome:$("#news_nome").val(),news_email:$("#news_email").val()},
 function(valor){
  if(valor==0){
   alert('email invalido !');
   $('#div_btn_news').html('<img src="../images/btn_ok.png" width="27" height="25" onClick="news(\'enviar\')" style="cursor:pointer">');

  }
  if(valor==2){
   alert('email duplicado');
      $('#div_btn_news').html('<img src="../images/btn_ok.png" width="27" height="25" onClick="news(\'enviar\')" style="cursor:pointer">');
	  
  }
  if(valor==1){
   alert('OK');	
      $('#div_btn_news').html('<img src="../images/btn_ok.png" width="27" height="25" onClick="news(\'enviar\')" style="cursor:pointer">');
  
  }
 } )

} // final do if enviar
 
}
// NEWS LETTER


// COMBOS BUSCA
function combo(tipo,valor,campo){
// alert(tipo+'-'+valor+'-'+campo);
//$("#descri_"+campo).val( $("#"+campo+" option:selected").text() );

 if(campo == 'id_tipo') {
  $('#id_modelo').attr("disabled", true);
  $('#id_marca').attr("disabled", true);
 }
	
 $('#opt_'+tipo).html('buscando...');
 $.post("../_includes/_combo_veiculo.php",
 {tipo:(tipo),valor:(valor),campo:(campo)},
 function(valor){
   $('#div_combo_'+tipo).attr("disabled", false);	
   $('#div_combo_'+tipo).html(valor);
 } 
 ) 
}
// COMBOS BUSCA


// ABAS DESTAQUES 
function aba_destaques_ON(str){ 
 $("#dest_current").attr("id","");
 $("#aba_destaques ul li:eq("+str+")").attr("id","dest_current");
};

function destaques(idcat){
 $('#tab_dest_0').html('<br><br><br><br><div align="center"><img src="../images/spinner.gif" align="absmiddle"><br><br><b>Carregando...</b></div>');
 $.post("../_includes/_busca_veiculo_catego.php",
 {idcat:(idcat)},
function(valor){
 $('#tab_dest_0').html(valor);
} ) }
// ABAS DESTAQUES


// ABAS DE BUSCA 
 $(document).ready(function() {
 $("#tabs_busca > div").hide();
 $("#tabs_busca > div:eq(0)").show();
});

function aba_busca_ON(str){ 
 $("#busca_current").attr("id","");
 $("#aba_busca ul li:eq("+str+")").attr("id","busca_current");
 $("#tabs_busca > div").hide();
 $("#tabs_busca > div:eq("+str+")").show();
};
// ABAS DE BUSCA

//INFORMES
function informes(idcat){
 $('#div_informes_home').html('<br><br><br><br><div align="center"><img src="../images/spinner.gif" align="absmiddle"><br><br><b>Carregando...</b></div>');
 $.post("../_includes/_informes.php",
 {idcat:(idcat)},
function(valor){
 $('#div_informes_home').html(valor);
} ) }
//INFORMES

// VALIDACAO BUSCA
function valida_form_busca(){
return valida_campos_busca('tudo');
}

function valida_campos_busca(campo){
if (campo == 'tudo') { // se for igual a tudo valido todos
                
    /*[X]*/ var requeridos = ['id_tipo','id_marca'];
                               
    $.each(requeridos,function(index, nome_campo) {                    

    //TIPOS = DATA, STR, EMAIL
    /*[X]*/ var tipo = ['STR','STR'];

    var val = $("#"+nome_campo).val();
    var tipo =  tipo[index]; // pego o valor da array 0,1,2

    switch (true) {
    case (tipo == 'STR' ):
    func_STR_BUSCA(nome_campo);
    break;
    case (tipo == 'EMAIL' ):
    func_EMAIL_BUSCA(nome_campo);
    break;
    case (tipo == 'CHECK' ):
    func_CHECK_BUSCA(nome_campo);
    break;
    case (tipo == 'RADIO' ):
    func_RADIO_BUSCA(nome_campo);
    break;
    default:
    func_STR_BUSCA(nome_campo);
    }

 } 
 );

// comparacao final da class alert nao tirar isso daqui 
if ( $('.combo_form_alert').size() > 0){
$('#div_msg_busca').html('Verifique os campos marcados !');
return false;}
// -----------------------------------------------------

} // final do if campo == ''

if (campo != 'tudo') { // se fo diferente de tudo entao

  /*[X]*/ var requeridos = ['id_tipo','id_marca'];
  //TIPOS = DATA, STR, EMAIL
  /*[X]*/ var tipo = ['STR','STR'];
                
  var name = campo;
  var val = $(this).val();
                
  if( $.inArray(name, requeridos) != -1 ) {               // comparo com os campos requeridos
  var tipo =  tipo[$.inArray(name, requeridos)] // pego o valor da array 0,1,2
                
    switch (true) {
    case (tipo == 'STR' ):
    func_STR_BUSCA(name);
    break;
    case (tipo == 'EMAIL' ):
    func_EMAIL_BUSCA(name);
    break;
    case (tipo == 'CHECK' ):
    func_CHECK_BUSCA(name);
    break;
    case (tipo == 'RADIO' ):
    func_RADIO_BUSCA(name);
    break;
    default:
    func_STR_BUSCA(name);
    }
                
  } // final do if
                
} // final do else do if campo == ''

}
// VALIDACAO BUSCA


// VALIDACAO BUSCA 2
function valida_form_busca2(){
return valida_campos_busca2('tudo');
}

function valida_campos_busca2(campo){
if (campo == 'tudo') { // se for igual a tudo valido todos
                
    /*[X]*/ var requeridos = ['cidade_revenda','id_revenda'];
                               
    $.each(requeridos,function(index, nome_campo) {                    

    //TIPOS = DATA, STR, EMAIL
    /*[X]*/ var tipo = ['STR','STR'];

    var val = $("#"+nome_campo).val();
    var tipo =  tipo[index]; // pego o valor da array 0,1,2

    switch (true) {
    case (tipo == 'STR' ):
    func_STR_BUSCA2(nome_campo);
    break;
    default:
    func_STR_BUSCA2(nome_campo);
    }

 } 
 );

// comparacao final da class alert nao tirar isso daqui 
if ( $('.combo_form_alert').size() > 0){
$('#div_msg_busca2').html('Verifique os campos marcados !');
return false;}
// -----------------------------------------------------

} // final do if campo == ''

if (campo != 'tudo') { // se fo diferente de tudo entao

  /*[X]*/ var requeridos = ['cidade_revenda','id_revenda'];
  //TIPOS = DATA, STR, EMAIL
  /*[X]*/ var tipo = ['STR','STR'];
                
  var name = campo;
  var val = $(this).val();
                
  if( $.inArray(name, requeridos) != -1 ) {               // comparo com os campos requeridos
  var tipo =  tipo[$.inArray(name, requeridos)] // pego o valor da array 0,1,2
                
    switch (true) {
    case (tipo == 'STR' ):
    func_STR_BUSCA2(name);
    break;
    default:
    func_STR_BUSCA2(name);
    }
                
  } // final do if
                
} // final do else do if campo == ''

}
// VALIDACAO BUSCA2

// ROLAGEM PARA O TOPO
jQuery(document).ready(function(){
	jQuery('body').prepend('<span id="bm-top" />');
	jQuery('#bm-arrow-top').bm_topLink({
		min: 200,
		fadeSpeed: 500
	});
	jQuery('#bm-arrow-top').click(function(e) {
		e.preventDefault();
	});		
	jQuery('a[href*=#]').click(function() {
		if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
	
			var $target = jQuery(this.hash);
			$target = $target.length && $target || jQuery('[name=' + this.hash.slice(1) +']');
		
			if ($target.length) {
				var targetOffset = $target.offset().top;
				jQuery('html,body').animate({scrollTop: targetOffset}, 1000);
				return false;
			}
		}
	});		
});
	jQuery.fn.bm_topLink = function(settings) {
		settings = jQuery.extend({
			min: 1,
			fadeSpeed: 200
		}, settings);
		return this.each(function() {
			var el = jQuery(this);
			el.hide(); 
			jQuery(window).scroll(function() {
				if (jQuery(window).scrollTop() >= settings.min) {
					el.fadeIn(settings.fadeSpeed);
				} else {
					el.fadeOut(settings.fadeSpeed);
				}
			});
		});
	};


//JANELA PARA RENOVAR DATAS ----------------------
function renovar_data_todas(){
tb_show('RENOVAR DATAS','_alert2.php?&KeepThis=true&TB_iframe=true&width=350&height=200&modal=true',null);
}

function renovar_data(idvei,idanu,modo,conta) {
 $('#div_renova_data'+conta).html('<img src="../images/spinner.gif" align="absmiddle">');	
 $.post("../anuncie/_renovar_data.php",
  {idvei:(idvei),idanu:(idanu),modo:(modo)},
  function(valor){
   $('#div_renova_data'+conta).html(valor);	
   $('#div_box_veiculo'+conta).removeClass('myClass class_opc_simples2'); 
   $('#div_box_veiculo'+conta).addClass('myClass class_opc_simples1');    
  } ) 
}

function renovar_data2(idvei,idanu,modo) {
 $('#div_renova_data').html('<img src="../images/spinner.gif" align="absmiddle"><br>Renovando Datas ...');	
 $.post("../anuncie/_renovar_data.php",
  {idvei:(idvei),idanu:(idanu),modo:(modo)},
  function(valor){
   $('#div_renova_data').html(valor);
 } ) 
}
//JANELA PARA RENOVAR DATAS ----------------------
