// JavaScript Document
//PRODUCTOS-----------------------------------------------------------------------------------------------------------------------------
function jsProductos()
{
	//abre productos
	jsPonerBoton('imgProducto','i_menu_productosover.jpg');
	jsAjaxIt('Productos/Productos.php?&Linea=BALATA','tdMain');
}

function jsPaginadoProducto(Pagina)
{
	//paginado de producto
	Linea=document.getElementById("hLinea").value
	
	var NoParte=document.getElementById('hNoParte').value
	var MarcaR=document.getElementById('hMarcaR').value
	var MarcaV=document.getElementById('hMarcaV').value;
	var ModeloV=document.getElementById('hModeloV').value;
	var Descripcion=document.getElementById('hDescripcion').value;
	var Ano1=document.getElementById('hAno1').value;
	var Ano2=document.getElementById('hAno2').value;
	
	var url='Productos/Productos.php?&pag='+Pagina+"&Linea="+Linea+"&MarcaR="+MarcaR+"&NoParte="+NoParte
	url+="&MarcaR="+MarcaR+"&MarcaV="+MarcaV+"&ModeloV="+ModeloV+'&Descripcion='+Descripcion+"&Ano1="+Ano1+"&Ano2="+Ano2;
	
	jsAjaxIt(url,'tdMain');
}

function jsImgProducto(ParteNo)
{
	//abre el thick box de la imagen
	
	jsWindowIt('Productos/frmImagen.php?ParteNo='+ParteNo,'Diafragmas Importados Guadalajara',800,600,'','');
}

function jsLineaProducto(Linea)
{
	//function: filtra linea en productos.
	jsAjaxIt('Productos/Productos.php?&Linea='+Linea,'tdMain');
}


function jsPonerBoton(Cadena,Imagen)
{
	//funcion: pone el boton que le corresponde, recibe el id de la imagen presionada y la cadena de su boton...
		
		document.getElementById('imgProducto').width=155
		document.getElementById('imgProducto').height=35
		document.getElementById('imgProducto').src='images/i_menu_productos.jpg';
		
		document.getElementById('imgEmpresa').width=155
		document.getElementById('imgEmpresa').height=35
		document.getElementById('imgEmpresa').src='images/i_menu_empresa.jpg';
		
		document.getElementById('imgContacto').width=155
		document.getElementById('imgContacto').height=35
		document.getElementById('imgContacto').src='images/i_menu_contacto.jpg';
		
		document.getElementById('imgOfertas').width=155
		document.getElementById('imgOfertas').height=35
		document.getElementById('imgOfertas').src='images/i_menu_ofertas.jpg';
		
		document.getElementById('imgInicio').width=155
		document.getElementById('imgInicio').height=35
		document.getElementById('imgInicio').src='images/i_menu_inicio.jpg';
		
		document.getElementById(Cadena).width=155;
		document.getElementById(Cadena).height=35;
		document.getElementById(Cadena).src="images/"+Imagen;	
	
}

function jsFiltraProducto()
{
	
	var Linea=document.getElementById('hLinea').value
	
	var NoParte=document.getElementById('cmdNoParte').value
	var MarcaR=document.getElementById('cmdMarcaR').value
	var MarcaV=document.getElementById('cmdMarcaV').value;
	var ModeloV=document.getElementById('cmdModeloV').value;
	var Descripcion=document.getElementById('cmdDescripcion').value;
	var Ano1=document.getElementById('cmdAno1').value;
	var Ano2=document.getElementById('cmdAno2').value;
	
	if(NoParte!=""||MarcaR!=""||MarcaV!=""||ModeloV!=""||Descripcion!=""||Ano1!=""||Ano2!="")
	{
		
			url="Productos/Productos.php?&Linea="+Linea+"&NoParte="+NoParte+"&MarcaR="+MarcaR+"&MarcaV="+MarcaV+"&ModeloV="+ModeloV+'&Descripcion='+Descripcion;
			url+="&Ano1="+Ano1+"&Ano2="+Ano2;
	
			jsAjaxIt(url,'tdMain');
		
	}
	else
	{
		
			alert('Debe haber datos a buscar');	
	}
}

function jsfrmCarrito(Id,Op)
{
	//FUNCION: ABRE EL FORMULARIO DE CARRITO DE COMPRAS
	var url="Productos/frmCarrito.php?Id="+Id;
	time=0
	if(Op==1)
	{
		time=1000
		tb_remove();
	}
	setTimeout(function(){jsWindowIt(url,"<img src='images/carrito.png' width='20'><span> Carrito de Compras</span>",600,520,'','')},time);
}

function jsAddCarrito(id)
{
	//function: agrega un product al carrito 
	
	var Cantidad=document.getElementById("txtCantidad").value;
	if(Cantidad!=""&&Cantidad!=0)
	{
		var NoParte=document.getElementById("hParteNoCar").value
		var Op="AddCarrito";
		var url="Productos/FunCarrito.php?id="+id+"&Cantidad="+Cantidad+"&Op="+Op+"&NoParte="+NoParte;
		res=jsJQueryIt(url);
		
		if(res==1)
		{
			alert("El producto se agrego al carrito con Exito");
			tb_remove();
		}
		else
		{
			alert("Ocurrio un Error");	
		}
	}
	else
	{
		alert("Debes capturar una cantidad del producto y debe de ser diferente de 0");	
		
		$("#txtCantidad").select().effect("bounce",{times:3,direction:'right'},250,function(){$("#txtCantidad").select()});
		//setTimeout(function(){$("#txtCantidad").select();},1000);
	}
}

function jsEliminaCarrito(iP)
{
	//funcion: elimina carrito
	Op="EliminaCarrito"
	url="Productos/FunCarrito.php?iP="+iP+"&Op="+Op
	res=jsJQueryIt(url);
	if(res==1)
		{
			alert("El producto se Elimino con Exito");
			tb_remove();
		}
		else
		{
			alert("Ocurrio un Error");	
		}
}

function jsfrmMailCarrito(totalCarrito)
{
	//abre el formulario de envio de registro
	if(totalCarrito>0)
	{
		tb_remove();
		url="Productos/frmPedidoCarrito.php?"
		setTimeout(function(){jsWindowIt(url,'Formulario de Envio',400,330,'','')},1000)
	}
	else
	{
		alert("No hay productos en carrito aun.")
		$("#txtCantidad").select();
	}
}

function jsEnviaMailCarrito()
{
	var Nombre=document.getElementById("cmdNombre").value;
	var Ciudad=document.getElementById("cmdCiudad").value;
	var Estado=document.getElementById("cmdEstado").value;
	var Email=document.getElementById("cmdEmail").value;
	var Telefono=document.getElementById("cmdTelefono").value;
	var Comentario=document.getElementById("cmdComentario").value;
	
	$("#cmdNombre,#cmdTelefono").each(function(i){
											   		if(this.value=="")
											   		{
												   		alert("El Nombre y el Telefono son obligatorios");
														this.select();
														return false();
											 	    }
											   })
	Op="EnviaMailProducto"
	url="Productos/FunCarrito.php?Nombre="+Nombre+"&Op="+Op+"&Ciudad="+Ciudad+"&Estado="+Estado+"&Email="+Email+"&Telefono="+Telefono+"&Comentario="+Comentario;
	res=jsJQueryIt(url);
	if(res==1)
	{
		alert("Pedido enviado con Exito")
		tb_remove();	
	}
	else
	{
		alert(res);	
	}
}


//EMPRESA---------------******************************************************************************************************************
function jsEmpresa()
{
	jsPonerBoton('imgEmpresa','i_menu_empresaover.jpg');
	jsAjaxIt('Empresa/Empresa.php','tdMain');	
}

//CONTACTO-----------------***************************************************************************************************************
function jsContacto()
{
//url="http://maps.google.com/maps/ms?ie=UTF8&amp;hl=es&amp;msa=0&amp;msid=116861696248321325148.00046d2f0fc0d08e6b89b&amp;ll=20.670412,-103.344741&amp;spn=0.009637,0.013733&amp;z=16&amp;output=embed"
//window.open(url,'Ubicacion');
	jsPonerBoton('imgContacto','i_menu_contactoover.jpg');
	jsAjaxIt('Contacto/Contacto.php','tdMain',jsSelectInicio('nombre'));	
	
	
}


function jsEnviaContacto()
{
	$("#nombre,#telefono").each(function(i){
											   		if(this.value=="")
											   		{
												   		alert("El Nombre y el Telefono son obligatorios");
														this.select();
														return false();
											 	    }
											   })
	
	Nombre=document.getElementById("nombre").value;
	Estado=document.getElementById("estado").value
	Telefono=document.getElementById("telefono").value;
	Email=document.getElementById("email").value
	Ciudad=document.getElementById("ciudad").value;
	Mensaje=document.getElementById("mensaje").value;
	url="Contacto/EnviaContacto.php?Nombre="+Nombre+"&Ciudad="+Ciudad+"&Estado="+Estado+"&Email="+Email+"&Telefono="+Telefono+"&Mensaje="+Mensaje;
	res=jsJQueryIt(url);
	if(res==1)
	{
		alert("Mensaje enviado con Exito")
		tb_remove();	
		document.location.href="index.php"
	}
	else
	{
		alert(res);	
	}
	
}

//HOME--------------------***************************************************************************************************************
function jsHome()
{
	jsPonerBoton('imgEmpresa','i_menu_ofertasover.jpg');
	jsAjaxIt('home.php','tdMain');		
}
