//Galeria---------------
function jsOpenGal()
{
	url="Galeria/Galeria.php";
	jsAjaxIt(url,"divMain","jsStartLightbox()")
	
	jsRemovePortada()
	//document.getElementById("divMenu").style.background="url(images/backmenuhome.png)";
	//document.getElementById("divMenu").style.backgroundRepeat="no-repeat"
}


function jsStartLightbox()
{

		$('#lightboxin a').lightBox();

}

function jsOpenThisGaleria(Galeria)
{
	url="Galeria/thisGaleria.php?Galeria="+Galeria;
	$("#tdGaleria").load(url);
	//jsAjaxIt(url,"tdGaleria")
}

function jsOpenThisVideo(Video)
{
	url="Galeria/thisVideo.php?Video="+Video;
	$("#tdGaleria").load(url);
	//jsAjaxIt(url,"tdGaleria")
}

//home------------------
function jsOpenHome()
{
	document.location.href="index.php"
//	url="home/home.php";
	//jsRemovePortada()
	//jsShowPortada()
	//jsAjaxIt(url,"divMain")
	
//	document.getElementById("divMenu").style.background="url(images/backmenuhome.png)";
	//document.getElementById("divMenu").style.backgroundRepeat="no-repeat"
}

function jsOpenProductosHome(Categoria)
{
	url="Productos/Productos.php";
	jsAjaxIt(url,"divMain","jsOpenCategoria('"+Categoria+"')")	
	
	//pone el fondo
	//document.getElementById("divMenu").style.background="url(images/backmenuproductos.png)";
	//document.getElementById("divMenu").style.backgroundRepeat="no-repeat"
}

function jsOpenGrupoCategorias(IdGrupo)
{
	url="Productos/Productos.php?IdGroup="+IdGrupo;
	//document.getElementById("hBuscar").value=""
	jsRemovePortada()
	jsAjaxIt(url,"divMain")
}

//Productos-----------------------------

function jsOpenProductos()
{
	
	url="Productos/Productos.php";
	jsAjaxIt(url,"divMain")	
	jsRemovePortada()
	
	//pone el fondo
	//document.getElementById("divMenu").style.background="url(images/backmenuproductos.png)";
	//document.getElementById("divMenu").style.backgroundRepeat="no-repeat"
}

function jsRefreshProductosGroup(pag,IdGroup)
{
	if(pag===undefined||pag=="")pag=0;

	
	url="Productos/ListGroup.php?pag="+pag+"&IdGroup="+IdGroup;
	//jsAjaxIt(url,"divContenerTopTen")
	jsAjaxIt(url,"tdListProductos")
}

function jsOpenCategoria(Categoria)
{
	document.getElementById("hCat").value=Categoria
	url="Productos/ProductosXCategoria.php?Categoria="+Categoria;
	document.getElementById("hBuscar").value=""
	
	jsAjaxIt(url,"tdListProductos")
	
}

function jsRefreshProductos(pag,Buscar)
{
	if(pag===undefined||pag=="")pag=0;
	if(Buscar===undefined) Buscar=document.getElementById("hBuscar").value
	else document.getElementById("hBuscar").value=Buscar

	Categoria=document.getElementById("hCat").value
	
	url="Productos/ProductosXCategoria.php?pag="+pag+"&Buscar="+Buscar+"&Categoria="+Categoria;
	//jsAjaxIt(url,"divContenerTopTen")
	jsAjaxIt(url,"tdListProductos")
}

function jsShowInfoProducto(IdProducto)
{
	url="Productos/infoProducto.php?IdProducto="+IdProducto+"&height=440&width=800";	
	tb_show("",url,null)
}

function jsBuscarProducto()
{
	//abre el buscador
	if(trim(document.getElementById("txtBuscador").value)!="")
	{
		url="Productos/Productos.php";
		jsRemovePortada()
		jsAjaxIt(url,"divMain",'jsRefreshProductos(0,document.getElementById("txtBuscador").value)')	
		
		//pone el fondo
		//document.getElementById("divMenu").style.background="url(images/backmenuproductos.png)";
		//document.getElementById("divMenu").style.backgroundRepeat="no-repeat"
		
	}
	
}
//car------------------
function jsAddCar(ID)
{
	Cantidad=trim($("#txtCantidadCarrito").attr("value"));
	
	if(Cantidad!=""&&Cantidad.indexOf("0")!=0)
	{
		//Observaciones=trim($("#txtObservaciones").attr("value"));
		url="php/CART.php?Op=AddProductoCart&ID="+ID+"&Cant="+Cantidad;
		res=jsJQueryIt(url);
		if(res==1)
		{
			alert("se agrego al carrito con exito");
			tb_remove();
		}
		else
		{
			alert("Ocurrio un error "+res);	
		}
	}
	else
	{
		jsBounceLeft("#txtCantidad");
		//alert("Debes capturar una cantidad");
	}
}

function jsOpenListCart()
{
	url="Productos/ListCart.php?width=800&height=500";
	tb_show("Carrito de Compras",url)
}

function jsShowImg(Imagen)
{
	//Muestra una imagen del listado de el carrito
	//verificar si existe foto----------------------------
	url="php/CART.php?Op=VerificaFoto&Imagen="+Imagen;
	res=jsJQueryIt(url);
	
	if(res!=1)
		Imagen="Nodisponible.jpg";
		
	//x=getDimensions(objeto).x;	
	//y=getDimensions(objeto).y;

	//----------------------------------------------------
	
	x="280px";
	y="101px"
	//creamos un div para mostrar la imagen
	div = document.createElement('DIV');
 	div.style.top = y;
	div.style.left= x;
	div.id="imgEncima"
	div.style.zIndex="32000";
	div.style.position="absolute";
	div.style.backgroundColor="#fff"
	//div.style.border="1px solid"
	div.innerHTML="<img width='350' src='Fotos/"+Imagen+"'>"
  	$("body").append(div);
	//document.getElementById("document").appendChild(div); 
	
}

function jsRemoveImg()
{
  $("#imgEncima").remove();
}

function jsRemoveArticuloCart(codigo,num)
{
	if(confirm("Estas seguro de querer eliminar este articulo: "+codigo))	
	{
		url="php/CART.php?Op=RemoveArticulo&num="+num;
		res=jsJQueryIt(url);
		if(res==1)
		{
		 	alert("articulo Eliminado");
			//tb_remove();
			jsOpenListCart()
		}
		else
		{
			alert("Ocurrio un Error "+res);	
		}
	}
	else
	 return false;
	
}

function jsSendPedidoCart()
{
	//envia al correo el pedido
	
	NombrePedido=$("#txtCartNombre").attr("value");
	Ciudad=$("#txtCartCiudad").attr("value");
	Estado=$("#txtCartEstado").attr("value");
	Telefono=$("#txtCartTel").attr("value");
	Mail=$("#txtCartMail").attr("value");
	if(NombrePedido!=""&&Ciudad!=""&&Estado!=""&&Telefono!=""&&Mail!="")
	{
		if(!jsEvaluaEmail(Mail))
		{
			jsBounceLeft("#txtCartMail")
			return false;
		}
		
		Comentarios=$("#txtComentarios").attr("value");
		
		url="php/CART.php?Op=EnviaPedido&NombrePedido="+NombrePedido+"&Ciudad="+Ciudad+"&Estado="+Estado+"&Telefono="+Telefono
		url+="&Mail="+Mail+"&Comentarios="+Comentarios;
		res=jsJQueryIt(url)
		if(res==1)
		{
			alert("Pedido Enviado");
			r=jsJQueryIt("php/CART.php?Op=BorraPedidoEnviado")
			
			tb_remove();
		}
		else
		{
			alert("Ocurrio un Error "+res);	
		}
	}
	else
	{
		$("#tableSendCart input:text").each(function(){
														 if(this.value=="")
														 {
															cadena="#"+this.id
															jsBounceLeft(cadena); 
															return false
														 }
													 })
	}
}
//Acerca de-------------------------------------------------------
function jsOpenAcerca()
{
	url="Acerca/Acerca.php";
	jsAjaxIt(url,"divMain")
	jsRemovePortada()
	//document.getElementById("divMenu").style.background="url(images/backmenuacerca.png)";
	//document.getElementById("divMenu").style.backgroundRepeat="no-repeat"
}


//Contacto---------------
function jsOpenContacto()
{
	url="Contacto/index.php";
	jsAjaxIt(url,"divMain","initialize()")
	jsRemovePortada()
	//document.getElementById("divMenu").style.background="url(images/backmenucontacto.png)";
	//document.getElementById("divMenu").style.backgroundRepeat="no-repeat"
}


function jsEnviaContacto()
{
	var Nombre=trim(document.getElementById("txtNombre").value);
	var Telefono=trim(document.getElementById("txtTelefono").value);
	var Mensaje=trim(document.getElementById("txtMensaje").value);
	if(Mensaje!=""&&Telefono!=""&&Nombre!="")
	{
		var Estado=document.getElementById("txtEstado").value;
		var Ciudad=document.getElementById("txtCiudad").value;
		var Mail=document.getElementById("txtMail").value;
		if (Mail != "") 
		{
			if(!jsEvaluaEmail(Mail))
			return false;
		}
		url="Contacto/Envia.php?Nombre="+Nombre+"&Telefono="+Telefono+"&Mensaje="+Mensaje
		url+="&Estado="+Estado+"&Ciudad="+Ciudad+"&Mail="+Mail;
		
		
		res=jsJQueryIt(url);
		
		if(res==1)
		{
			jsOpenProductos()
			alert("Mensaje Enviado")
			//document.location.href=document.location.href;
		}
		else
		{
			alert("Ocurrio un error "+res);	
		}
	}
	else
	{
		alert("No deben quedar en blanco Nombre, Telefono Y Mensaje");
	}
}
//utilidades---------------
//google
function initialize() 
{ 
    //mapa 1
	var latlng = new google.maps.LatLng(20.666116,-103.357164); 
    var myOptions = { 
      zoom: 15, 
      center: latlng, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map1"), myOptions); 

	  var marker = new google.maps.Marker({ 
		  position: latlng,  
		  map: map, 
		  title:"AutoSport's Ninos Heroes!" 
	  }); 

	 //mapa2
	 var latlng = new google.maps.LatLng(20.641068, -103.419727); 
    var myOptions = { 
      zoom: 15, 
      center: latlng, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map2"), myOptions); 
	  var marker = new google.maps.Marker({ 
		  position: latlng,  
		  map: map, 
		  title:"AutoSport's Patria" 
	  }); 

	//mapa 3
	 var latlng = new google.maps.LatLng(20.664326, -103.359694); 
    var myOptions = { 
      zoom: 15, 
      center: latlng, 
      mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
	    var map = new google.maps.Map(document.getElementById("map3"), myOptions); 
	  var marker = new google.maps.Marker({ 
		  position: latlng,  
		  map: map, 
		  title:"AutoSport's Tolsa" 
	  }); 

} 
  
 //quita mujer y pone mujer
 function jsRemovePortada()
{
  $("#portada").remove();
  
  //pone estilo de los divs de fondo del main
  	//divs arriba y abajo
	arriba=document.getElementById("cArriba");
	arriba.style.backgroundImage="url(images/soporte-arriba.png)";
	arriba.style.height="28px";
	arriba.style.width="910px";
	abajo=document.getElementById("cAbajo");
	abajo.style.backgroundImage="url(images/soporte-abajo.png)";
	abajo.style.height="28px";
	abajo.style.width="910px";
	Main=document.getElementById("divMain");
	Main.style.backgroundImage="url(images/soporte.png)";
	
}

function jsShowPortada()
{
	//Muestra una imagen del listado de el carrito
	//verificar si existe foto----------------------------

		
	//x=getDimensions(objeto).x;	
	//y=getDimensions(objeto).y;

	//----------------------------------------------------
	
	x="-299px";
	y="0px";
	//creamos un div para mostrar la imagen
	div = document.createElement('DIV');
 	div.style.top = y;
	div.style.left= x;
	div.id="portada"
	div.style.zIndex="100";

	div.style.width="555px";
	div.style.height="900px"
	div.style.position="absolute";
	div.style.backgroundImage="url(images/chica.png)";
	div.style.backgroundRepeat="no-repeat"

	div.style.backgroundPosition="left top";
	//div.style.border="1px solid"
	//div.innerHTML="<img width='350' src='Fotos/"+Imagen+"'>"
  	$("body").append(div);
	
	
	//quita estilo
	arriba=document.getElementById("cArriba");
	arriba.style.backgroundImage="";
	//arriba.style.height="0px";
	abajo=document.getElementById("cAbajo");
	abajo.style.backgroundImage="";
	Main=document.getElementById("divMain");
	Main.style.backgroundImage="";
//	Main.style.top=Main.style.top-10;

	
}

numBanner=0;
function jsRefreshBanner()
{
	div=document.getElementById("banner");
	if(numBanner==0)
	{
		div.style.backgroundImage="url(images/banner-2.jpg)";
		numBanner=1;
	}
	else if(numBanner==1)
	{
		div.style.backgroundImage="url(images/banner-3.jpg)";
		numBanner=2;
	}
	else if(numBanner==2)
	{
		div.style.backgroundImage="url(images/banner-1.jpg)";	
		numBanner=0
	}
}

function jsMuestraHelp()
{
	$("#divHelp").show("slow");
}

function jsMuestraHelp2()
{
	$("#divHelp2").show("slow");
}