﻿function pesquisaavancada(obj){
	var objeto = obj.id + "avancada";
	document.getElementById(objeto).style.display = 'inline';
}

function trim(String) {
	return String.replace(/^\s+|\s+$/g,"");
}

function verCarro(el){
	document.getElementById('imgMaior').src = el.href;
/*	document.getElementById('nome-carro').innerHTML = el.innerHTML; */	return false;	
}

function FormatacaoCpfCnpj(e){
    var tecla=(window.event)?event.keyCode:e.which;
    if((tecla >= 45 && tecla < 58) || ( tecla == 44 || tecla == 46)) 
		return true;
    else{
		if (tecla != 8) 
			return false;
		else 
			return true;
	}
}

function dataMaiorQueAtual(data){
	dataAtual = new Date();
	diaAtual = dataAtual.getDate();
	mesAtual = dataAtual.getMonth() +1;
	anoAtual= dataAtual.getFullYear(); 

	dia = data.split( "/" )[0].toString();
	mes = data.split( "/" )[1].toString();
	ano = data.split( "/" )[2].toString();
	
	if( (anoAtual > ano) || (anoAtual == ano && mesAtual > mes) || (anoAtual == ano && mesAtual == mes && diaAtual > dia)  )
	{
		return false;
	}else{
		return true;
	}
}

function AtualizaBanner()
{
    var existe = document.getElementById("divBanner");
    if(existe)
        document.getElementById("divBanner").innerHTML = ReescreveFlash('../banner/banner.swf', '693', '220', '', 'BannerCaltabiano');
    
    var existeSeminovos = document.getElementById("divBannerSeminovos");
    if(existeSeminovos)
        document.getElementById("divBannerSeminovos").innerHTML = ReescreveFlash('../banner/banner-seminovos.swf', '693', '220', '', 'BannerCaltabiano');
}

function Flash(swf, width, height, flashvars, id){
	var escreveFlash = new String();
	if (navigator.appName.indexOf("Microsoft") != -1){
		escreveFlash += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
		escreveFlash += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=version=8,0,0,0" ';
		escreveFlash += 'width="' + width + '" height="' + height + '" name="' + id + '"id = '+ id +'">';
		escreveFlash += '<param name="movie" value="' + swf + '"/>';
		if(flashvars != null) {escreveFlash += '<param name="flashvars" value="' + flashvars + '"/>'};
		escreveFlash += '<param name="menu" value="false"/>';
		escreveFlash += '<param name="salign" value="LT"/>';
		escreveFlash += '<param name="scale" value="noscale"/>';
		escreveFlash += '<param name="wmode" value="transparent"/>';
		escreveFlash += '<param name="allowScriptAccess" value="sameDomain"/>';
		escreveFlash += '</object>';
	} else{
		escreveFlash += '<embed src="' + swf + '" ';
		escreveFlash += 'width="' + width + '" ';
		escreveFlash += 'height="' + height + '" ';
		escreveFlash += 'id="' + id + '" ';
		escreveFlash += 'name="' + id + '" ';
		escreveFlash += 'menu="false" ';
		escreveFlash += 'scale="noscale" ';
		escreveFlash += 'salign="LT" ';
		escreveFlash += 'wmode="transparent" ';
		escreveFlash += 'allowScriptAccess="sameDomain" ';
		if(flashvars != null) {escreveFlash += 'flashvars="' + flashvars + '" '};
		escreveFlash += 'type="application/x-shockwave-flash" ';
		escreveFlash += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
		escreveFlash += '</embed>';
	}
	document.write(escreveFlash);
}

function ReescreveFlash(swf, width, height, flashvars, id){
	var escreveFlash = new String();
	if (navigator.appName.indexOf("Microsoft") != -1){
		escreveFlash += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ';
		escreveFlash += 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=version=8,0,0,0" ';
		escreveFlash += 'width="' + width + '" height="' + height + '" name="' + id + '"id = '+ id +'">';
		escreveFlash += '<param name="movie" value="' + swf + '"/>';
		if(flashvars != null) {escreveFlash += '<param name="flashvars" value="' + flashvars + '"/>'};
		escreveFlash += '<param name="menu" value="false"/>';
		escreveFlash += '<param name="salign" value="LT"/>';
		escreveFlash += '<param name="scale" value="noscale"/>';
		escreveFlash += '<param name="wmode" value="transparent"/>';
		escreveFlash += '<param name="allowScriptAccess" value="sameDomain"/>';
		escreveFlash += '</object>';
	} else{
		escreveFlash += '<embed src="' + swf + '" ';
		escreveFlash += 'width="' + width + '" ';
		escreveFlash += 'height="' + height + '" ';
		escreveFlash += 'id="' + id + '" ';
		escreveFlash += 'name="' + id + '" ';
		escreveFlash += 'menu="false" ';
		escreveFlash += 'scale="noscale" ';
		escreveFlash += 'salign="LT" ';
		escreveFlash += 'wmode="transparent" ';
		escreveFlash += 'allowScriptAccess="sameDomain" ';
		if(flashvars != null) {escreveFlash += 'flashvars="' + flashvars + '" '};
		escreveFlash += 'type="application/x-shockwave-flash" ';
		escreveFlash += 'pluginspage="http://www.macromedia.com/go/getflashplayer">';
		escreveFlash += '</embed>';
	}
	return escreveFlash;
}


$(function(){
	$('.brilho').hover(function(){
		$(this).fadeTo("fast", 0.2, function(){
			$(this).fadeTo("fast", 1)
		})
	});
})


	

// inicio de ajax para evento over do mouse em determinados objetos

$(function(){

	$('.tabela tr').mouseover(function(){
		$(this).find('td').addClass('tabela-over');
	})
	$('.tabela tr').mouseout(function(){
		$(this).find('td').removeClass('tabela-over');
	})
	$('.veiculo-seminovos').mouseover(function(){
		$(this).css('background-color','red');
	})	

	
	
	$('.textboxBusca').focus(function(){
		$(this).addClass('textboxBusca-over');
		//$(this).css('background','rgb(255, 255, 255)');
	})	
	
	$('.textboxBusca').blur(function(){
		$(this).removeClass('textboxBusca-over');
	})

})

// inicio de ajax Vendas Diplomáticas

function fechavendas(){
	document.getElementById('DIVum').style.display = 'none' ;
	document.getElementById('DIVdois').style.display = 'none' ;
	document.getElementById('DIVtres').style.display = 'none' ;
	document.getElementById('DIVquatro').style.display = 'none' ;
	document.getElementById('DIVcinco').style.display = 'none' ;
	document.getElementById('um').className = ''
	document.getElementById('dois').className = ''
	document.getElementById('tres').className = ''
	document.getElementById('quatro').className = ''
	document.getElementById('cinco').className = ''
	
}	
function verifica_venda_diplomatica_interno(obj){
	fechavendas();
	obj.className="linkativado";
	var usual = "DIV"+obj.id;
	document.getElementById(usual).style.display = 'inline' ;
}

// GOOGLE

function MapaGoogle(DivMapa, hdnLoja, hdnTo, hdnTelefone)
{
    mapa = new GMap2(document.getElementById(DivMapa), { size: new GSize(600, 300) });
    mapa.addControl(new GLargeMapControl());
    mapa.setCenter(new GLatLng(-23.547779, -46.639366), 12);
    mapa.addControl(new GMapTypeControl());    

    geocoder = new GClientGeocoder();
    mapa = showAddress(document.getElementById(hdnLoja).value,
    document.getElementById(hdnTo).value, document.getElementById(hdnTelefone).value, mapa);
}

function showAddress(loja, address, fone, mapa) {
    if (geocoder) {
        geocoder.getLatLng(
  address,
  function(point) {
      if (!point) {
          alert(address + " não encontrado");
      } else {
          mapa.setCenter(point, 16);
          var letteredIcon = new GIcon(G_DEFAULT_ICON);
          letteredIcon.image = "../imagens/icones/icone-mapa-caltabiano.png";
          markerOptions = { icon: letteredIcon };
          var marker = new GMarker(point, markerOptions);
          mapa.addOverlay(marker);
          GEvent.addListener(marker, "click", function() {
              marker.openInfoWindowHtml('<strong style="color:#00659B">' + loja + '</strong><br/>' + address + '</strong><br/>' + fone );
          });

      }
  }
);
    }
}    

function montarRota(divMapa, divRota, txtFrom, hdnTo) 
{
    var mapa = new GMap2(document.getElementById(divMapa), { size: new GSize(600, 300) });
    mapa.addControl(new GLargeMapControl());
    mapa.setCenter(new GLatLng(-23.547779, -46.639366), 12);
    mapa.addControl(new GMapTypeControl()); 
            
    directionsPanel = document.getElementById(divRota);
    directions = new GDirections(mapa, directionsPanel);
    document.getElementById(divRota).style.display = 'inline';
    var fromAddress = document.getElementById(txtFrom).value
    if (document.getElementById(hdnTo) == null) return
    var toAddress = document.getElementById(hdnTo).value;
    directions.load(fromAddress + ' to ' + toAddress, { 'locale': 'pt_BR' })
}

function MostraImagemPesquisa(nomeImagem, imagem)
{
    document.getElementById('ctl00_ContentPlaceHolder1_ListaSeminovos1_rptResultado_'+nomeImagem).src = "http://www.caltabiano.com.br/imgveiculos/" + imagem;  
}

function MostraDestalhesVeiculo(ChassiResumido, CodEmpresa, CodProduto, CodModelo)
{
    document.getElementById('ctl00_ContentPlaceHolder1_ListaSeminovos1_hdnChassiResumido').value = ChassiResumido;
    document.getElementById('ctl00_ContentPlaceHolder1_ListaSeminovos1_hdnCodEmpresa').value = CodEmpresa;
    document.getElementById('ctl00_ContentPlaceHolder1_ListaSeminovos1_hdnCodProduto').value = CodProduto;
    document.getElementById('ctl00_ContentPlaceHolder1_ListaSeminovos1_hdnCodModelo').value = CodModelo;          
}

function NumeroPagina(num)
{
    window.location="#topo";
    document.getElementById('ctl00_ContentPlaceHolder1_ListaSeminovos1_hdnPagina').value = num;
}

function NumeroBloco(num)
{
    window.location="#topo";
    document.getElementById('ctl00_ContentPlaceHolder1_ListaSeminovos1_hdnBloco').value = num;
}

