//<input type="button" value="Open ShadowBox" onclick="abrirVentana('Un Titulo','http://www.google.com.co',0,0);" />
function abrirVentana(titulo, url,width1,height1){
	try{
	if(width1==0 || height1==0){
		//try{
			Shadowbox.open({type:'iframe',content:url, title: titulo});
		//}catch(err){}
	} else{
		//try{
			Shadowbox.open({type:'iframe',content:url, title: titulo, width:width1, height: height1});
		//}catch(err){}
	}
	}catch(E){}
//	return false;
}
function abrirCotizador(){
	window.open("http://www.autolarte.com.co/creditos/carga.html","window_cotizador","location=1,status=1,scrollbars=0,width=765,height=505");
	//return false;
}
function abrirCotizadorUsados(){
	window.open("http://www.autolarte.com.co/scripts/credito_usados/creditoUsados.php","window_usados","location=1,status=1,scrollbars=0,width=650,height=450");
	return false;
}
function abrirCambiesucarro(){
	//var ventanaXXL=window.open("http://www.cambiesucarro.com","_blank");
	abrirPopup("http://www.cambiesucarro.com/",600,500);
}
function abrirPopup(url,w,h,ret){
	var fecha=new Date();
	var wuid=fecha.getSeconds()+fecha.getMinutes()+fecha.getMilliseconds();
	window.open(url,"window"+wuid,"location=1,status=1,scrollbars=0,width="+w+",height="+h);
	if(!ret)return false;
}
function irAUsados(ancla){
	alert("vehiculos_usados/tablausados.php#"+ancla);
	document.getElementById("iFrameUsados").src="vehiculos_usados/tablausados.php#"+ancla;
}
function opcionCapa(capa,opcion){
	var laCapa=document.getElementById(capa);
	if(opcion==1) laCapa.style.display="block";
		else laCapa.style.display="none";
}
function ocultarMostrarCapa(capa,opcion){
	document.getElementById(capa).style.display=opcion;
}
function MM_showHideLayers(capa,opcion1,opcion2){
	if(opcion2=="hide") document.getElementById(capa).style.display="none";
		else document.getElementById(capa).style.display="block";
}
function mostrarBuscador(){
	//alert("algo");
	//return false;
	//if(typeof MooTools=="undefined") return false;
	//else 
	abrirVentana("Buscador de Usados","http://www.autolarte.com.co/usados/");
	//return false;
	/*return false;
	$('el_contenido').innerHTML="";
	var elIframe=new Element('iframe',{
		'id':'iframeusados',
		'name':'iframeusados',
		'width':'100%',
		'height': '780px',
		'src':'usados/',
		'scrolling': 'auto',
		'frameborder': '0'
	});
	elIframe.inject($('el_contenido'));
	*/
}
function mostrarLayer()
{
	var obj=$('splash');
	obj.setStyles({'top':0,'display':'block'});
	mostrarCapa('splash');
}
function quitarLayer(){
	alert("Quitar Layer");
	var obj=$('splash');
	
	var myEffect = obj.effect('opacity', {duration: 1000, transition: Fx.Transitions.Quad.easeIn});
	myEffect.start(1,0);
}
function mostrarCapa(capa){
	var capa=$(capa);
	var myEffect = capa.effect('opacity', {duration: 500, transition: Fx.Transitions.Quad.easeOut});
	myEffect.start(0, 1);
}
var version=navigator.appVersion;
var isIE=version.indexOf("MSIE");
var isIE7=version.indexOf("MSIE 7.0");
var evento=(isIE)?'load':'domready';
window.addEvent(evento,function(){
	var menus=new Array('ul#menu_carros li a','ul#menu_usados li a','ul#menu_taller li a');
	var lis=new Array('ul#menu_carros li','ul#menu_usados li','ul#menu_taller li');
	for(var t=0;t<menus.length;t++){
		try{
			var empresa_links=$$(menus[t]);
			var empresa_li=$$(lis[t]);
			empresa_links.each(function (el){
				el.setStyles({'opacity':.65});
				var fx = new Fx.Styles(el, {duration:300, wait:false});
				el.addEvent('mouseenter',function(){
					fx.start({
						'opacity':1
					});
				});
				el.addEvent('mouseleave',function(){
					fx.start({
						'opacity':.65
					});
				});
			});
			empresa_li.each(function (el){
				el.setStyles({
					'margin-left': 0
				});
				var fx = new Fx.Styles(el, {duration:300, wait:false});
				el.addEvent('mouseenter',function(){
					fx.start({
						'margin-left': 5
					});
				});
				el.addEvent('mouseleave',function(){
					fx.start({
						'margin-left': 0
					});
				});
			});
				
			//$('splash').setStyles({opacity: 0});
				
		}catch(E){}
	}
});
/**NOVEDADES HOME**/
window.addEvent(evento,function(){
		try{
		var novedades=$('novedades_home');
		//alert(novedades.id);
		var h2=novedades.getFirst();
		var novedad=novedades.getLast();
		
		var topNovedades=novedades.getTop();
		var leftNovedades=novedades.getLeft();
		var heightInicialNovedades=novedades.getSize().size.y;
		var heightFinalNovedades=471;//novedades.getSize().size.y;
		var heightInicialNovedad=novedad.getSize().size.y;
		novedades.setStyles({
			'position':'absolute',
			'left':leftNovedades,
			'z-index':50,
			'height':heightInicialNovedades,
			'top':topNovedades,
			'opacity':1
		});
		window.addEvent('resize',function(){
			novedades.setStyles({
				'left':$('imagen_usados').getLeft()+$('imagen_usados').getSize().size.x
			});
		});
		var fx,fx2;
		novedades.addEvent('mouseenter',function(){
			this.setStyles({'background-color':'#FFF'});
			novedad.setStyles({'background-color':'#FFF'});
			try{fx.stop();}catch(e){}
			try{fx2.stop();}catch(e){}
			fx = new Fx.Styles(this, {duration:300, wait:false,onComplete:function(){
				novedades.setStyles({'background-color':'#FFF'});
				novedad.setStyles({'background-color':'#FFF'});
				h2.setStyles('background-position: 0 -37px');
			}});
			fx2 = new Fx.Styles(novedad, {duration:300, wait:false});
			fx.start({'top':parseInt(topNovedades-313),'height':heightFinalNovedades,'opacity':0.93});
			fx2.start({'height':433});
		});
		novedades.addEvent('mouseleave',function(){
			try{fx.stop();}catch(e){}
			try{fx2.stop();}catch(e){}
			fx = new Fx.Styles(this, {duration:300, wait:false,onComplete:function(){
				novedades.setStyles({
					'background-color':'transparent',
					'border':'0 none'
				});
				h2.setStyles('background-position: 0 0');
			}});
			fx2 = new Fx.Styles(novedad, {duration:300, wait:false,onComplete:function(){
				novedad.removeProperty('style');
			}});
			fx.start({'top':topNovedades,'height':heightInicialNovedades,'opacity':1});
			fx2.start({'height':heightInicialNovedad});
		});
		}catch(E){}
		try{
			var div=$$('div.moduletable_circuito')[0].getParent();
			div.setStyles({'width':218,'height':135});
		}catch(e){}
		/*****SECCION B*******/
		try{
			var textoInicialBuscador=$('buscador_txt').value;
			$('buscador_txt').addEvent('focus',function(){
				if(this.value==textoInicialBuscador)this.value='';
				this.setStyles({
					'background-position':'0 -22px',
					'color':'#000'
				});
			});
			$('buscador_txt').addEvent('blur',function(){
				if(this.value=='')this.value=textoInicialBuscador;
				this.removeProperty('style');
			});
			$('buscador_prev').setStyles({'visibility':'hidden'});
			$('buscador_next').setStyles({'visibility':'hidden'});
			$('buscador_txt').addEvent('keyup',function(){
					var data='palabra='+$('buscador_txt').value;
					data+="&knowbi_ajax=1&opcion=buscador&option=com_knowbi_ajax";
					try{ajaxBuscador.cancel();}catch(e){}
					$('loader').setStyles({'display':'block'});
					ajaxBuscador=new Ajax($('frmBuscador').getProperty('action'),{data:data,method:'post',onComplete:function(request){
						var res=request.split('/*');
						$('loader').setStyles({'display':'none'});
						if(res[0]!='error'){
							var widthAux=280;
							var rBuscador=new Element('div',{
								'id':'resultado_buscador'+resultadosBuscador,
								'class':'buscador_resultados',
								'styles':{
									'left':resultadosBuscador*widthAux,
									'width':widthAux
								}
							});
							$('resultado_buscador').setStyle('width',(resultadosBuscador+1)*widthAux);
							resultadosBuscador++;
							actualPage=resultadosBuscador;
							mostrarNavegacion();
							rBuscador.setHTML(res[0]);
							rBuscador.inject($('resultado_buscador'));
							animarEntradaResultados();
						}else alert(res[1]);
					}});
					ajaxBuscador.request();
			});
			topInicialResultados=$('buscador').getTop()-$('buscador_resultado').getSize().size.y-1;
			$('buscador_resultado').setStyles({
				'top':topInicialResultados,
				'left':	$('buscador').getLeft()-((isIE7)?1:0),
				'opacity':.96
			});
			window.addEvent('resize',function(){
				topInicialResultados=$('buscador').getTop()-$('buscador_resultado').getSize().size.y;
				$('buscador_resultado').setStyles({
					'top':topInicialResultados,
					'left':	$('buscador').getLeft()
				});
				try{
					$('capaFullImage').setStyles({
					'top':$('buscador_resultado').getTop(),
					'left':	$('buscador_resultado').getLeft()+$('buscador_resultado').getSize().size.x
				});
				}catch(e){}
			});
		}catch(e){}
});
/**BUSCADOR**/
function mostrarNavegacion(){
	$('buscador_prev').setStyles({'visibility':'hidden'});
	$('buscador_next').setStyles({'visibility':'hidden'});
	if(actualPage<resultadosBuscador)$('buscador_next').setStyles({'visibility':'visible'});
		else $('buscador_next').setStyles({'visibility':'hidden'});
	
	if(actualPage>1)$('buscador_prev').setStyles({'visibility':'visible'});
		else $('buscador_prev').setStyles({'visibility':'hidden'});
}
function navegar(donde){
	if(donde=='avanzar') actualPage++;
	else actualPage--;
	resBFX2=new Fx.Styles($('resultado_buscador'),{wait:false,duration:200,transition:Fx.Transitions.Quint.easeOut});
	resBFX2.start({
		'left':-1*($('buscador_resultado').getSize().size.x-1)*(actualPage-1)
	});
	mostrarNavegacion();
}
var topInicialBuscador,resBFX,resBFX2,ajaxBuscador,actualPage;
var maxH=278;
var maxW=415;
var resultadosBuscador=actualPage=0;
function animarEntradaResultados(){
	//ocultarFullImage();
	try{resBFX.stop();resBFX2.stop();}catch(e){}
	resBFX=new Fx.Styles($('buscador_resultado'),{wait:false,duration:500,transition:Fx.Transitions.Quint.easeOut});
	resBFX2=new Fx.Styles($('resultado_buscador'),{wait:false,duration:200,transition:Fx.Transitions.Quint.easeOut});
	
	var top1=$('buscador').getTop()-maxH-1;
	$('buscador_resultado').setStyles({'display':'block'});
	resBFX.start({
		'height':maxH,
		'top':top1,
		'left':	$('buscador').getLeft()-((isIE7)?1:0)
	});
	var leftAux=(-1*($('buscador_resultado').getSize().size.x-1)*(resultadosBuscador-1));
	resBFX2.start({'left':leftAux});
	
}
function animarSalidaResultados(){
	try{resBFX.stop();resBFX2.stop();}catch(e){}
	resBFX=new Fx.Styles($('buscador_resultado'),{wait:false,duration:500,transition:Fx.Transitions.Quint.easeOut});
	resBFX.start({
		'height':0,
		'top':$('buscador').getTop()-1
	});
	resBFX.addEvent('onComplete',function(){
		$('buscador_resultado').setStyles({'display':'none'});
	});
	ocultarFullImage();
}
function ocultarFullImage(){
	try{
		capaImgFx=new Fx.Styles(capaImagen,{wait:false,duration:200,transition:Fx.Transitions.Quint.easeOut});
		capaImgFx.start({'opacity':0});
		capaImgFx.addEvent('onComplete',function(){capaImagen.setStyles({'width':0});});
	}catch(e){}
}
var capaImgFx,imgFx,imgLastId,capaImagen,laImagen;
function mostrarFullImage(id,src){
	//alert(src);
	try{capaImgFx.stop();imgFx.stop();}catch(e){}
	capaImagen=$('capaFullImage');
	if(!capaImagen){
		capaImagen=new Element('div',{
			'id':'capaFullImage',
			'styles':{
				'height':$('buscador_resultado').getSize().size.y-1,
				'top':$('buscador_resultado').getTop(),
				'left':$('buscador_resultado').getLeft()+$('buscador_resultado').getSize().size.x
			}
		});
		capaImagen.inject($(document.body));
	}
	laImagen=$('fullImage');
	if(!laImagen){
		laImagen=new Element('img',{
			'id':'fullImage'
		});
		laImagen.inject(capaImagen);
	}
	capaImagen.setStyles({'opacity':1});
	imgFx=new Fx.Styles(laImagen,{wait:false,duration:300,transition:Fx.Transitions.Quint.easeOut});
	imgFx.start({'left':-maxW});
	capaImgFx=new Fx.Styles(capaImagen,{wait:false,duration:300,transition:Fx.Transitions.Quint.easeOut});
	capaImgFx.start({'width':0});
	capaImgFx.addEvent('onComplete',function(){
		laImagen.src=src;
		laImagen.addEvent('load',function(){
			try{$('loader'+id).setStyles({'display':'none'});}catch(e){}	
			imgLastId=id;
			laImagen.setStyles({
				'padding-top':parseInt((maxH-laImagen.getSize().size.y)/2)
			});
			animarEntradaImagen(id);
		});
	});
	$$('img.loader_carro').each(function(elm){elm.setStyle('display','none');});
	try{$('loader'+id).setStyles({'display':'block'});}catch(e){}
	
	//Ocultar ultimo Cargador por si da click rapido
	//try{$('loader'+imgLastId).setStyles({'display':'none'});}catch(e){}
}
function animarEntradaImagen(id){
	try{capaImgFx.stop();imgFx.stop();}catch(e){}
	capaImgFx=new Fx.Styles(capaImagen,{wait:false,duration:300,transition:Fx.Transitions.Quint.easeOut});
	capaImgFx.start({'width':maxW});
	imgFx=new Fx.Styles(laImagen,{wait:false,duration:300,transition:Fx.Transitions.Quint.easeOut});
	imgFx.start({'left':0});
}
/**END BUSCADOR**/
/**FORMULARIO DE CONVERSION**/
function isEmail(email){
	var filter=/^[A-Za-z.\-][A-Za-z0-9_.\-]*@[A-Za-z0-9_\-]+\.[A-Za-z0-9_.\-]+[A-za-z]$/;
	if(!filter.test(email)){
		return false;
	}
	return true;
}
function enviarFormularioUsados(_form){
	if(_form.nombre.value==''){
		alert('Debe digitar su nombre completo');
		_form.nombre.focus();
		return false;
	}
	if(!isEmail(_form.email.value)){
		alert("Por favor, debe digitar un E-mail v\u00e1lido");
		_form.email.focus();
		return false;
	}
	if(_form.telefono.value==''){
		alert('Debe digitar su n\u00famero de tel\u00e9fono');
		_form.telefono.focus();
		return false;
	}
	if(_form.ciudad.value==''){
		alert('Debe digitar la ciudad');
		_form.ciudad.focus();
		return false;
	}
	var formEnviar=$(_form);
	$('enviar').disabled=true;
	$('enviar').value='Enviando...';
	formEnviar.send({method:'post',onComplete:function(request){
		var res=Json.evaluate(request);
				if(!res.error){
					alert(res.msj);
					var new_img=new Element('img',{
						'id':'google_image_convertion',
						'src':'http://www.googleadservices.com/pagead/conversion/1034337040/?label=c7j1COTk4QEQkPaa7QM&amp;guid=ON&amp;script=0',
						'alt':'',
						'width':'1px',
						'height':'1px',
						'Styles':{
							'border-style':'none'
						}
					});
					var texto=$('usados_texto');
					new_img.inject(texto);
					var form=$('usados_form');
					form.setStyles({
						'display':'none'
					});
					var fxText = new Fx.Styles(texto, {duration:400, wait:false});
					fxText.start({
						'width':720
					});
					
					_form.reset();
				}else{
					alert(res.msj);
					$('enviar').disabled=false;
					$('enviar').value='Enviar';
				}

	}});

	return false;
}
function formularioUsados(){
	var texto=$('usados_texto');
	var form=$('usados_form');
	form.setStyles({
		'overflow':'hidden',
		'float':'left',
		'width':0,
		'display':'block',
		'width':260,
		'opacity':0,
		'margin':'0 0 0 10px',
		'padding': '0 10px'
	});
	texto.setStyles({
		'float':'left',
		'width':430
	});
	var fxForm = new Fx.Styles(form, {duration:1000, wait:false});
	fxForm.start({
		'opacity':1
	});
	return false;
}
/***SPLAYER***/
var fxVelo,fxImagen;
var evento=isIE6 || isIE7?'load':'domready';
function cerrarSplayer(){
	fxImagen.start({'top':-620});
	fxVelo.start({'opacity':0});
}
//Layer publicado por Diego Castro Knowbi.com 07122010
/*
window.addEvent('load',function(){
	if(isHome){
		var velo=new Element('div',{
			'id':'velo_07122010',
			'styles':{
				'width':'100%',
				'height':'100%',
				'position':'fixed',
				'z-index':2000,
				'left':0,
				'top':0,
				'opacity':0,
				'background-color':'#000'
			}
		});
		var imagen=$('splayer');
		imagen.src='./images/layers/banner_splayer.png';
		velo.inject($(document.body));
		fxVelo=new Fx.Styles(velo,{duration:300,transition:Fx.Transitions.Quint.easeIn});
		fxVelo.start({'opacity':0.5});
		fxImagen=new Fx.Styles(imagen,{duration:1500,transition:Fx.Transitions.Bounce.easeOut});
		imagen.addEvent('load',function(){
			fxImagen.start({'top':90});
		});
	}
});
*/
/****FIN SPLAYER****/
