$(document).ready(function(){

	$("#slider").easySlider({
		auto: true,
		speed: 		800,
		pause:		3000,
		continuous: true
	});


	$("a[rel='example1']").colorbox();
	$("a[rel='example2']").colorbox();
	$("a[rel='example3']").colorbox();
	$("a[rel='politica']").colorbox();
	
	//$(".inlineBarra").colorbox({inline:true, width:"50%"});
	

	/*
	$("#btn-condicao").click(function(){
		$('.img-condicao').css('display','block');
	});
	$(".btn-condicao").click(function(){
		$('.img-condicao').css('display','block');
	});
	
	$("#btn-fechar").click(function(){
		$('.img-condicao').css('display','none');
	});
	*/

	/* PLUGIN DE WATERMARK */
	watermark.init();

	/* PLUGIN DE PNG FIX */
	if($.browser.msie && ($.browser.version == "6.0")){ $(document).pngFix(); }

	$('#telefone,#q_telefone').val('Telefone *');

	$('#phone').val('Telefone *');
	$('#mobile').val('Celular');
	$('#date_born').val('Data de Nascimento *');
	$('#q_phone').val('Telefone *');
	$('#cpf').val('CPF');
	$('#cep').val('CEP');
	$('#cep_1').val('Cep onde o veículo pernoita *');

	/* ABAS */
	$("div.contaba").hide();
	$("div.contaba:first").show();
	$("#abas a:first").addClass("selected");

	$("#abas a").click(function(){
		$("div.contaba").hide();
		$("#abas a").removeClass("selected");
		$(this).addClass("selected");
		$($(this).attr("href")).show();
		return false;
	});
	/* ABAS */

	/* CAROUSEL */
	if($('.circle-home ul').size()) {
		$('.circle-home ul').cycle({
			fx:     'fade',
			speed:  300,
			timeout: 8000,
			pager:  '#nav',
			pagerEvent: 'mouseover',
			pauseOnPagerHover: true
		});
	}
	/* CAROUSEL */

	/* AJUSTES DOS FLASH */
	//src		  : base_url + 'header.swf',
	if($('.conceptual_home').size()){
		$('.conceptual_home').flash({
			src		  : base_url + 'assets/site/swf/conceitual_janeiro.swf',
			width	  : "950",
			height	  : "280",
			wmode	  : 'transparent',
			flashvars : {
				link  : base_url
			}
		}, { update: false });
		if(!jQuery.browser.flash)
			$('.conceptual_home').html('<img src="'+base_url+'assets/site/img/pics/conceptual.jpg" />');
	}
	/* AJUSTES DOS FLASH */

	/* SCRIPTS NON OBSTRUCTIVE  */
	$('.imgs-thumbs li img').each(function() {
		$(this).mouseover(function() {
			var link = $(this).attr('rel');
			$('#img-id').attr('src',link);
		});
	});

	/* see video serie */
	$(".see-video").click(function() {
		var id = $(this).attr('rel');
		jQuery.facebox({ ajax: 'viewVideo.php?id='+id });
	});


	/* SCRIPTS NON OBSTRUCTIVE  */

	/* LIGHTBOX */
	if($("#light").size()) {
		$('a[rel="lightbox"]').lightBox({
			overlayBgColor: '#000',
			overlayOpacity: 0.6,
			imageLoading: base_url+'assets/site/js/plugins-jquery/lightbox/images/lightbox-ico-loading.gif',
			imageBtnClose: base_url+'assets/site/js/plugins-jquery/lightbox/images/lightbox-btn-close.gif',
			imageBtnPrev: base_url+'assets/site/js/plugins-jquery/lightbox/images/lightbox-btn-prev.gif',
			imageBtnNext: base_url+'assets/site/js/plugins-jquery/lightbox/images/lightbox-btn-next.gif',
			containerResizeSpeed: 150,
			txtImage: 'Imagem',
			txtOf: 'de'
		});
	}
	/* LIGHTBOX */

	/* ALIGNS */
	$('.product-img img').each(function(i){
		var parent_height 	= 110;
		var image_height 	= $(this).height();
		var top_margin 		= (parent_height - image_height)/2;
		$(this).css( 'margin-top' , top_margin);
	});
	/* ALIGNS */

	/* SCROLL ANIMATE */
	$('.scrollPage').click(function() {
		var elementClicked = $(this).attr("href");
		var destination = $(elementClicked).offset().top;
		$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
		return false;
	});
	/* SCROLL ANIMATE */

	/* MENU SERIES */
	$(".menu li a.v15").click(function() {
		var id = $(this).attr('rel');
		$(".menu-serie").hide();
		$("#"+id).show();
	});

	$(document).click( function(e){
		if (!$(e.target).closest('.menu-serie').length &&
		!$(e.target).closest('.menu').length) 	$('.menu-serie').hide();
	});
	/* MENU SERIES */
	

});

/* form_service */
function sendService(form) {
	msg = "";

	disabledFormButton('.btn-send');

	if($("#name").val() == "" || $("#name").val() == "Nome *")
	msg += "Nome não preenchido.\n";

	if($("#email").val() == ""){
		msg += "E-mail  não preenchido.\n";
	} else if(!valEmail.test($("#email").val())) {
		msg += "E-mail inválido.\n";
	}

	if($("#phone").val() == "" || $("#phone").val() == "Telefone *")
	msg += "Telefone não preenchido.\n";

	if($("#city").val() == "" || $("#city").val() == "Cidade *")
	msg += "Cidade não preenchida.\n";

	if($("#state").val() == "")
	msg += "Estado não preenchido.\n";

	if($("#car").val() == "" || $("#car").val() == "Veículo *")
	msg += "Veículo não preenchido.\n";

	if($("#year").val() == "" || $("#year").val() == "Ano *")
	msg += "Ano não preenchidao\n";

	if($("#description").val() == "" || $("#description").val() == "Descrição *")
	msg += "Descrição não preenchida\n";

	if(msg != ""){
		alert("Os campo abaixo encontra-se com erros:\n\n"+msg);
		enabledFormButton('.btn-send');
	} else {

		if($("#cpf").val() == 'CPF')  					 $("#cpf").val('');
		if($("#cep").val() == 'CEP')  					 $("#cep").val('');
		if($("#address").val() == 'Endereço')  			 $("#address").val('');
		if($("#number").val() == 'Número / Complemento') $("#number").val('');
		if($("#plate").val() == 'Placa')  				 $("#plate").val('');
		if($("#model").val() == 'Modelo')  				 $("#model").val('');
		if($("#chassi").val() == 'Chassi')  			 $("#chassi").val('');
		if($("#km").val() == 'Quilometragem')  			 $("#km").val('');

		$("#"+form).submit();
	}

}
/* form_service */

/* form_peaces */
function sendPeaces(form) {
	msg = "";

	disabledFormButton('.btn-send');

	if($("#name").val() == "" || $("#name").val() == "Nome *")
	msg += "Nome não preenchido.\n";

	if($("#email").val() == ""){
		msg += "E-mail  não preenchido.\n";
	} else if(!valEmail.test($("#email").val())) {
		msg += "E-mail inválido.\n";
	}

	if($("#phone").val() == "" || $("#phone").val() == "Telefone *")
	msg += "Telefone não preenchido.\n";

	if($("#car").val() == "" || $("#car").val() == "Automóvel que possui *")
	msg += "Veículo não preenchido.\n";

	if($("#description").val() == "" || $("#description").val() == "Descreva a peça *")
	msg += "Descrição de peça não preenchida\n";

	if(msg != ""){
		alert("Os campo abaixo encontra-se com erros:\n\n"+msg);
		enabledFormButton('.btn-send');
	} else {

		if($("#model").val() == 'Modelo')  				 $("#model").val('');

		$("#"+form).submit();
	}

}
/* form_peaces */

/* proposta */
function sendProposta(form) {
	msg = "";

	disabledFormButton('.btn-send');

	if($("#name_p").val() == "" || $("#name_p").val() == "Nome *")
	msg += "Nome não preenchido.\n";

	if($("#email_p").val() == ""){
		msg += "E-mail  não preenchido.\n";
	} else if(!valEmail.test($("#email_p").val())) {
		msg += "E-mail inválido.\n";
	}

	if($("#phone_p").val() == "" || $("#phone_p").val() == "Telefone *")
	msg += "Telefone não preenchido.\n";

	if($("#description_p").val() == "" || $("#description_p").val() == "Proposta *")
	msg += "Proposta não preenchida\n";

	if(msg != ""){
		alert("Os campo abaixo encontra-se com erros:\n\n"+msg);
		enabledFormButton('.btn-send');
	} else {
		$("#"+form).submit();
	}

}
/* proposta */

/* cotacao */
function sendQuotation(form) {
	msg = "";

	disabledFormButton('.btn-send');

	if($("#q_name").val() == "" || $("#q_name").val() == "Nome *")
	msg += "Nome não preenchido.\n";

	if($("#q_email").val() == ""){
		msg += "E-mail  não preenchido.\n";
	} else if(!valEmail.test($("#q_email").val())) {
		msg += "E-mail inválido.\n";
	}

	if($("#q_phone").val() == "" || $("#q_phone").val() == "Telefone *")
	msg += "Telefone não preenchido.\n";

	if($("#q_city").val() == "" || $("#q_city").val() == "Cidade *")
	msg += "Cidade não preenchida.\n";

	if($("#q_state").val() == "")
	msg += "Estado não preenchido.\n";

	if($("#q_model").val() == "")
	msg += "Modelo não preenchido.\n";

	if($("#q_description").val() == "" || $("#q_description").val() == "Mensagem *")
	msg += "Mensagem não preenchida\n";
	
	if ($("input[type=checkbox][name=ip_politica]:not(:checked)").val()){
		msg += "Você precisa aceitar a política de privacidade.";
	}

	if(msg != ""){
		alert("Os campo abaixo encontra-se com erros:\n\n"+msg);
		enabledFormButton('.btn-send');
	} else {

		$.ajax({
			type: "POST",
			url: base_url+"index.php|on=home&in=sendQuotation",
			data: "name="+$("#q_name").val()+"&email="+$("#q_email").val()+"&phone="+$("#q_phone").val()+"&city="+$("#q_city").val()+"&state="+$("#q_state").val()+"&model="+$("#q_model").val()+"&description="+$("#q_description").val(),
			success: function(msg){
				
				if(msg == 'ok') {
					alert('Cotação enviada com sucesso');
	
					$("#q_name").val('Nome *');
					$("#q_email").val('Email *');
					$("#q_phone").val('Telefone *');
					$("#q_city").val('Estado *');
					$("#q_state").get(0);
					$("#q_description").val('Mensagem *');
					
					var conversion = '<div style="display:inline;"><img height="1" width="1" style="border-style:none;" alt="" src="http://www.googleadservices.com/pagead/conversion/1007722267/?value=17&amp;label=bUSfCL3a2gEQm77C4AM&amp;guid=ON&amp;script=0"/></div>';
					
					$('#quotationConversion').html(conversion);
					
				} else 
					alert('Erro no envio. Tente mais tarde.');
				
				enabledFormButton('.btn-send');
			}
		});
	}

}
/* cotacao */

/* career */
function sendCareer(form) {
	msg = "";

	disabledFormButton('.btn-enviar');

	if($("#name").val() == "" || $("#name").val() == "Nome *")
	msg += "Nome não preenchido.\n";

	if($("#email").val() == ""){
		msg += "E-mail  não preenchido.\n";
	} else if(!valEmail.test($("#email").val())) {
		msg += "E-mail inválido.\n";
	}

	if($("#phone").val() == "" || $("#phone").val() == "Telefone *")
	msg += "Telefone não preenchido.\n";

	if($("#city").val() == "" || $("#city").val() == "Cidade *")
	msg += "Cidade não preenchida.\n";

	if($("#state").val() == "")
	msg += "Estado não preenchido.\n";

	var name_file = $('#file').val();
	var arExt = name_file.split(".");
	var arExt = arExt.reverse();
	var ext = arExt[0].toLowerCase();

	if($("#file").val() == "")
	msg += "Arquivo não preenchido.\n";
	else if (ext != 'pdf' && ext != 'doc' && ext != 'txt' && ext != 'docx')
	msg += "Formato de arquivo inválido.\n";

	if($("#description").val() == "" || $("#description").val() == "Experiências *")
	msg += "Experiências não preenchida.\n";

	if(msg != ""){
		alert("Os campo abaixo encontra-se com erros:\n\n"+msg);
		enabledFormButton('.btn-enviar');
	} else {
		if($("#cpf").val() == "CPF") $("#cpf").val('');
		$("#"+form).submit();
	}

}
/* career */

/* insurance */
function sendInsurance(form) {
	msg 		 	= "";
	contact_type 	= false;
	home 		 	= false;
	other_conductor = false;
	total_loss		= false;
	other_car 		= false;
	garage	  		= false;
	car		  		= false;
	antitheft 		= false;
	present_insurance = false;

	disabledFormButton('.btn-enviar');

	if($("#name").val() == "" || $("#name").val() == "Nome *") 			msg += "Nome não preenchido.\n";
	if($("#cpf").val() == "" || $("#cpf").val() == "CPF")				msg += "CPF não preenchido.\n";
	if($("#gender").val() == "")										msg += "Sexo não preenchido.\n";
	if($("#city").val() == "" || $("#city").val() == "Cidade *")		msg += "Cidade não preenchida.\n";
	if($("#state").val() == "")											msg += "Estado não preenchido.\n";
	if($("#phone").val() == "" || $("#phone").val() == "Telefone *")	msg += "Telefone não preenchido.\n";

	if($("#email").val() == ""){
		msg += "E-mail  não preenchido.\n";
	} else if(!valEmail.test($("#email").val())) {
		msg += "E-mail inválido.\n";
	}

	$("input[name=contact_type]").each(function() {
		if($(this).is(':checked'))	contact_type = true;
	});
	if(contact_type == false) msg += "Meio de contato.\n";

	/* dados do veiculo */
	if($("#brand").val() == "" || $("#brand").val() == "Marca *")		msg += "Marca não preenchida.\n";
	if($("#model").val() == "" || $("#model").val() == "Modelo *")		msg += "Modelo não preenchido.\n";
	if($("#year_manufacture").val() == "")								msg += "Ano de Fabricação não preenchido.\n";
	if($("#year_model").val() == "")									msg += "Ano do Modelo não preenchido.\n";
	if($("#renavam").val() == "" || $("#renavam").val() == "RENAVAM *")	msg += "RENAVAM não preenchido.\n";
	if($("#use_for").val() == "")										msg += "Utilização do veículo não preenchido.\n";

	/* dados do condutor */
	if($("#date_born").val() == "" || $("#date_born").val() == "Data de Nascimento *")			msg += "Data de Nascimento não preenchida.\n";
	if($("#marital_status").val() == "" || $("#marital_status").val() == "Estado Civil *")		msg += "Estado Civil não preenchido.\n";
	if($("#occupation").val() == "" || $("#occupation").val() == "Atividade Profissional *")	msg += "Atividade Profissional não preenchida.\n";

	$("input[name=home]").each(function() {
		if($(this).is(':checked'))	home = true;
	});
	if(home == false) msg += "Local onde reside.\n";

	$("input[name=other_conductor]").each(function() {
		if($(this).is(':checked'))	other_conductor = true;
	});
	if(other_conductor == false) msg += "Filhos ou outros condutores entre 15 e 25 anos.\n";

	$("input[name=total_loss]").each(function() {
		if($(this).is(':checked'))	total_loss = true;
	});
	if(total_loss == false) msg += "Roubo ou perda total nos últimos 24 meses.\n";

	if($("#dut").val() == "" || $("#dut").val() == "Documento do Veículo (DUT) em nome de: *")	msg += "Nome no DUT não preenchido.\n";
	if($("#year_hab").val() == "" || $("#year_hab").val() == "Ano de Habilitação *")	msg += "Ano de habilitação não preenchido.\n";

	$("input[name=other_car]").each(function() {
		if($(this).is(':checked'))	other_car = true;
	});
	if(other_car == false) msg += "Outro carro na residência.\n";

	$("input[name=garage]").each(function() {
		if($(this).is(':checked'))	garage = true;
	});
	if(garage == false) msg += "Garagem fechada na residência.\n";

	$("input[name=car]").each(function() {
		if($(this).is(':checked'))	car = true;
	});
	if(car == false) msg += "Veículo não selecionado.\n";

	$("input[name=antitheft]").each(function() {
		if($(this).is(':checked'))	antitheft = true;
	});
	if(antitheft == false) msg += "Sistema anti-furto.\n";

	if($("#cep_1").val() == "" || $("#cep_1").val() == "Cep onde o veículo pernoita *")	msg += "CEP do pernoite não preenchido.\n";

	$("input[name=present_insurance]").each(function() {
		if($(this).is(':checked'))	present_insurance = true;
	});
	if(present_insurance == false) msg += "Possui seguro atualmente.\n";

	if(msg != ""){
		alert("Os campo abaixo encontra-se com erros:\n\n"+msg);
		enabledFormButton('.btn-enviar');
	} else {

		if($("#ramal").val() == "Ramal") 	$("#ramal").val('');
		if($("#mobile").val() == "Celular") $("#mobile").val('');
		if($("#version").val() == "Versão") $("#version").val('');
		if($("#placa").val() == "Placa") 	$("#placa").val('');

		if($("#insurance_name").val() == "Nome da seguradora") 				$("#insurance_name").val('');
		if($("#insurance_bonus").val() == "Bônus") 							$("#insurance_bonus").val('');
		if($("#insurance_end").val() == "Término de vigência da apólice")	$("#insurance_end").val('');

		$("#"+form).submit();
	}
}
/* insurance */

/* contact */
function sendContact(form) {
	msg = "";

	disabledFormButton('.btn-enviar');

	if($("#name").val() == "" || $("#name").val() == "Nome *")
	msg += "Nome não preenchido.\n";

	if($("#email").val() == ""){
		msg += "E-mail  não preenchido.\n";
	} else if(!valEmail.test($("#email").val())) {
		msg += "E-mail inválido.\n";
	}

	if($("#phone").val() == "" || $("#phone").val() == "Telefone *")
	msg += "Telefone não preenchido.\n";

	if($("#city").val() == "" || $("#city").val() == "Cidade *")
	msg += "Cidade não preenchida.\n";

	if($("#state").val() == "")
	msg += "Estado não preenchido.\n";

	if($("#description").val() == "" || $("#description").val() == "Mensagem *")
	msg += "Mensagem não preenchida.\n";

	if(msg != ""){
		alert("Os campo abaixo encontra-se com erros:\n\n"+msg);
		enabledFormButton('.btn-enviar');
	} else {

		if($("#telefone").val() == "Telefone") $("#telefone").val('');
		if($("#assunto").val() == "Assunto") $("#assunto").val('');

		$("#"+form).submit();
	}

}
/* contact */

/* news search */
function searchNoticia(url_path) {
	var query = $('#q').val();

	if(query != "" && query != "Palavra Chave") {
		query = str_replace(query,'-','');
		query = str_replace(query,'/','');
		query = str_replace(query,'%','');

		window.location = url_path+'|q='+query;
	}
	else  alert('Digite uma palavra chave para notícias.');
}
/* news search */

/* eventos search */
function searchEventos(url_path) {
	var query = $('#q1').val();

	if(query != "" && query != "Palavra Chave") {
		query = str_replace(query,'-','');
		query = str_replace(query,'/','');
		query = str_replace(query,'%','');
		window.location = url_path+'|ce=true&q='+query;
	}
	else  alert('Digite uma palavra chave para eventos.');
}
/* eventos search */

/* seminovo search */
function searchSeminovo(localPath) {
	var url = '';
	var modelo 		= $('#q').val();
	var ano 		= $('#ano').val();
	var marca_id 	= $('#marca_id').val();
	var de 			= $('#de').val();
	var ate 		= $('#ate').val();
	var blindado	= $('#valorBlind').val();

	if(modelo != "" && modelo != "Modelo") 	url += '&modelo='+modelo;
	if(ano != "" && ano != "Ano") 			url += '&ano='+ano;
	if(marca_id != "")						url += '&marca_id='+marca_id;
	if(de != "" && de != "De R$") 			url += '&de='+de;
	if(ate != "" && ate != "Até R$") 		url += '&ate='+ate;
	if(blindado == '1')						url += '&blindado=1';

	url = str_replace(url,'-','');
	url = str_replace(url,'/','');
	url = str_replace(url,'%','');

	window.location = localPath+'|'+url;
}
/* seminovo search */

/* seminovo search */
function searchReport(localPath,tipo) {
	
	if(tipo == 'seminovos') {
	
		var url = '';
		var veiculo		= $('#veiculo').val();
		var nome 		= $('#nome').val();
		var placa 		= $('#placa').val();
		var de 			= $('#dataFim').val();
		var ate 		= $('#dataFim').val();
		
		if(veiculo != "" && veiculo != "Veiculo") 	url += '&veiculo='+veiculo;
		if(nome != "" && nome != "Nome do cliente") url += '&nome='+nome;
		if(placa != "" && placa != "Placa") 		url += '&placa='+placa;
		if(de != "" && de != "Data inicio") 		url += '&de='+de;
		if(ate != "" && ate != "Data fim") 			url += '&ate='+ate;
		 										    url += '&tipo=semi';
		
	} else if(tipo == 'novos') {
		
		var url = '';
		var modelo		= $('#q_model').val();
		var nome		= $('#q_nome').val();
		var uf 			= $('#q_state').val();
		var de 			= $('#q_dataIni').val();
		var ate 		= $('#q_dataFim').val();
	
		if(modelo != "") 							url += '&modelo='+modelo;
		if(nome != "" && nome != "Nome do cliente") url += '&nome='+nome;
		if(uf != "") 								url += '&uf='+uf;
		if(de != "" && de != "Data inicio") 		url += '&de='+de;
		if(ate != "" && ate != "Data fim") 			url += '&ate='+ate;
													url += '&tipo=novo';
	}
	
	//url = str_replace(url,'-','');
	url = str_replace(url,'/',' ');
	url = str_replace(url,'%','');
	
	window.location = localPath+'|'+url;
}
/* seminovo search */

function str_replace(haystack, needle, replacement) {
	var temp = haystack.split(needle);
	return temp.join(replacement);
}

function disabledFormButton(ct) {
	$(ct).attr('disabled','disabled').css('cursor','default').css('filter','alpha(opacity=40)').css('-moz-opacity','0.4').css('opacity','0.4');
}

function enabledFormButton(ct) {
	$(ct).attr('disabled','').css('cursor','pointer').css('filter','alpha(opacity=100)').css('-moz-opacity','1').css('opacity','1');
}

function hideError() {
	$("#retorno_erro").animate({
		left: '+=50',
		height: 'toggle'
	}, 500, function() {
		$("#retorno_erro").html('');
		$("#retorno_erro").css('display','block');
	});

	window.clearTimeout(timeoutID);
}

function topo() 	 {
	window.location = document.URL+'#';
}

function gotoAnchor(value) {
	var elementClicked = '#'+value;
	var destination = $(elementClicked).offset().top;
	$("html:not(:animated),body:not(:animated)").animate({ scrollTop: destination-20}, 500 );
}

var valEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
