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_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_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_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 popUP(sURL, sName, iWidth, iHeight, scrollb) { 
	posHoriz = parseInt((screen.availWidth / 2) - parseInt(iWidth / 2));
	posVert = parseInt((screen.availHeight / 2) - parseInt(iHeight / 2));
	
	open (sURL, sName, "status=yes, scrollbars="+scrollb+", left=" + posHoriz + ", top=" + posVert + ", width="+iWidth+", height="+iHeight)
}

function busca_carro()
{
	$("#bgBusca").attr('background','/imagens/bg_busca_carro.gif');
	
	$("#form_busca_produto").animate({width: '0'},function(){
		
		$("#form_busca_produto").hide();
		$("#form_busca_carro").show().animate({width: '95%'});
		
	});
	
}

function busca_produto()
{	
	$("#bgBusca").attr('background', '/imagens/bg_busca_produto.gif');
	
	$("#form_busca_carro").animate({width: '0'},function(){
		
		$("#form_busca_carro").hide();
		$("#form_busca_produto").show().animate({width: '198px'});
		
	});
	
}

function troca_lmu(tipo)
{
	var img = $("#imgLMU");
	
	if(tipo == 'lancamento'){
		img.attr('src','/imagens/tit_lmu_mais_lancamentos.gif');
		
			$("#mais_vendidos").hide();
			$("#ultimos_vistos").hide();
			$("#lancamento").show();
		
	}
	else if(tipo == 'vendidos'){
		img.attr('src','/imagens/tit_lmu_mais_vendidos.gif');
		
			$("#lancamento").hide();
			$("#ultimos_vistos").hide();			
			$("#mais_vendidos").show();	
	}
	else if(tipo == 'visitados'){
		img.attr('src','/imagens/tit_lmu_mais_visitados.gif');
		
		$("#lancamento").hide();
		$("#mais_vendidos").hide();
		$("#ultimos_vistos").show();
	}
}

function muda_cor_borda(obj, sCor)
{
	obj.style.borderColor = sCor;
}

function trocaImagem(i, pro)
{
	var img = document.getElementById("imgFotoProduto");
	img.src = '/imagens/produto/m/'+ pro +'_'+ i +'.jpg';
	idFotoSelecionada = i;
}

function trocaFundoProduto(td, id){
	
	if(id != idOpcaoSelecionada){
		
		td.style.background='#b7e721';
		var opcao = document.getElementById("opcao_" + idOpcaoSelecionada);

		conteudo = document.getElementById("ConteudoSelecionado");
		conteudo.innerHTML = conteudoOpcao[id];
		opcao.style.background='#d3d3d3';		
		idOpcaoSelecionada = id;
	}
}


var msg = new Object();
msg = {	

	showMessageTimer : function(text, time)
	{
		msg.remove();
		
		this.showMessageBlock(text,false);
		
		setTimeout(function(){
			msg.remove();
		},time);		
	},
	showMessageBlock : function(text,unBlock){
		
		
		//jQuery.blockUI({ message: text, css: {fontSize: '15px'} });
		
		msg.remove();
		
		$.blockUI({
		message: "<p style='font-size: 22px'>"+text+" </p>",
		timeout: 2, 
		css: 
		{
			border: 'none', 
			padding: '19px', 
			backgroundColor: '#B6D91E', 
			'-webkit-border-radius': '10px', 
			'-moz-border-radius': '10px', 
			opacity: .9,
			color: '#000000'			
		}});
		
		if(unBlock) {
			setTimeout(function(){
				msg.remove();
			}, 2000);
		}
	},	
	show : function(text)
	{		
		msg.remove();
		
		//$('body').prepend("<div align='center' class='msg_text' id='msg_text'>"+text+"</div>");
		
		$.blockUI({
		message: "<p style='font-size: 22px'>"+text+" </p>",
		timeout: 2,
		css: 
		{
			border: 'none', 
			padding: '19px', 
			backgroundColor: '#B6D91E', 
			'-webkit-border-radius': '10px', 
			'-moz-border-radius': '10px', 
			opacity: .9,
			color: '#000000'			
		}});
		
		//$('body').prepend("<div align='center' class='msg' id='msg'><table border='0' height='100%' width='100%'><tr><td align='center' style='color:#fff; font-weight:bold; font-size:28px;'>"+text+"</td></tr></table></div>");
			
			setTimeout(function(){
				msg.remove();
			},2000);
	},
	remove : function(){
		$('#msg').remove();
		$.unblockUI(); 
	},
	
	ErroCampoFormulario : function(Campo, sMsg){
		C = $(Campo);
	
		C.addClass("formulario_erro");
		C.parent().find("img").hide();
		C.parent().find("span").hide();
		C.parent().append("<span class='fonteVermelha'><br>"+sMsg+"</span>");
	}
}

number_format = function( number, decimals, dec_point, thousands_sep ) {

    var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
    var d = dec_point == undefined ? "." : dec_point;
    var t = thousands_sep == undefined ? "," : thousands_sep, s = n < 0 ? "-" : "";
    var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "", j = (j = i.length) > 3 ? j % 3 : 0;
    
    return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
}


trocaModelo = function(idMarca, idModelo){
		
	Campo = $(idMarca);
	Modelo = $(idModelo);
	
	if(Campo.val() == "") return;

	Query = "id="+Campo.val()+"&comando=retorna_modelo_veiculo";
	
	Modelo.removeOption(/./);
	Modelo.removeOption("");
	
	$.getJSON("/admin/includes/ajax/ajax_json.php?"+Query, function(aSessoes){

		jQuery.each(aSessoes,function(indice,oModelo){
			val = oModelo.vmod_id;
			text = oModelo.vmod_nome;
			Modelo.addOption(val,text);
		});
		
		Modelo.selectOptions("",true);
		
	});	
}

chamadaRemota = function(conf){
	return $.ajax({url:conf.url,async:false,cache: false}).responseText;
}

var Remote = function(){
	
	this.conf = {
		type: "text",
		url: "/script/ajax.php",
		async: false
	}
	
	this.get = function(dados){ 
		
		res = $.ajax({
		  url:this.conf.url,
		  async:this.conf.async,
		  data: dados,
		  cache: false,
		  dataType: this.conf.type
		});
		
		return res;		
	}	
}



