// JavaScript Document pro123
function handleEnter (field, event) 
{
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) 
			busq_like();
 		
}
function busq_marcas()
{
document.getElementById('id_marca').value=document.getElementById('marcas').options[document.getElementById('marcas').options.selectedIndex].value;
document.forms["enviar"].action="listas_marcas.php?index="+document.getElementById('marcas').options.selectedIndex;
document.forms["enviar"].submit();
}
function busq_like()
{
if(document.getElementById('buscar_2').value=="")
 alert("Ingrese texto de busqueda");
else
	{
		document.getElementById('filtrar_marca').value="false";
		document.getElementById('buscar').value=document.getElementById('buscar_2').value;
		document.forms["enviar"].action="busqueda.php";
		document.forms["enviar"].submit();
	}
}
function ordenar()
{
document.getElementById("carga").value="";
//alert(document.getElementById('orden_marca').options[document.getElementById('orden_marca').options.selectedIndex].value);
document.getElementById("index_precio").value=document.getElementById('pre').options.selectedIndex;
document.getElementById("index_orden_marca").value=document.getElementById('orden_marca').options.selectedIndex;
document.getElementById("marca").value=document.getElementById('orden_marca').options[document.getElementById('orden_marca').options.selectedIndex].value;
//alert(document.getElementById("carga").value);
document.forms["pasar"].submit();
}
var auxPrecioOfertas=0;
function ordenarOferta()
{
document.getElementById("pagina_actual").value="";
document.getElementById("total_productos").value="";
document.getElementById("total_paginas").value="";
//alert(document.getElementById('orden_marca').options[document.getElementById('orden_marca').options.selectedIndex].value);
document.getElementById("index_orden_marca").value=document.getElementById('orden_marca').options.selectedIndex;
document.getElementById("index_precio").value=document.getElementById('pre').options.selectedIndex;
//alert(document.getElementById("carga").value);
document.forms["pasar"].action="ofertas3.php?id_marca="+document.getElementById('orden_marca').options[document.getElementById('orden_marca').options.selectedIndex].value;
document.forms["pasar"].submit();
}

function ordenar2()
{
//alert(document.getElementById('orden_marca').options[document.getElementById('orden_marca').options.selectedIndex].value);
document.getElementById('id_categoria').value=
document.getElementById('categorias').options[document.getElementById('categorias').options.selectedIndex].value;
document.getElementById('index_cate').value=document.getElementById('categorias').options.selectedIndex;
document.getElementById('id_marca').value=document.getElementById('marcas').options[document.getElementById('marcas').options.selectedIndex].value;
document.getElementById("index_precio").value=document.getElementById('pre').options.selectedIndex;
document.getElementById("carga").value="";
document.forms["pasar"].submit();
}
function ordenar_semi()
{
//alert(document.getElementById('orden_marca').options[document.getElementById('orden_marca').options.selectedIndex].value);
document.getElementById('id_categoria').value=
document.getElementById('categorias').options[document.getElementById('categorias').options.selectedIndex].value;
document.getElementById('index_cate').value=document.getElementById('categorias').options.selectedIndex;
document.getElementById("index_precio").value=document.getElementById('pre').options.selectedIndex;
document.getElementById("carga").value="";
document.forms["pasar"].action="semi_nuevos.php";
document.forms["pasar"].submit();
}

function ordenar_dp()
{
//alert(document.getElementById('orden_marca').options[document.getElementById('orden_marca').options.selectedIndex].value);
document.getElementById('id_categoria').value=
document.getElementById('categorias').options[document.getElementById('categorias').options.selectedIndex].value;
document.getElementById('index_cate').value=document.getElementById('categorias').options.selectedIndex;
document.getElementById('index_sem').value=document.getElementById('sem').options.selectedIndex;
document.getElementById("index_precio").value=document.getElementById('pre').options.selectedIndex;
document.getElementById("carga").value="";
document.forms["pasar"].action="productos_dp.php?index_sem="+document.getElementById('index_sem').value;
document.forms["pasar"].submit();
}

function ordenar3()
{
//alert(document.getElementById('orden_marca').options[document.getElementById('orden_marca').options.selectedIndex].value);
document.getElementById("index_precio").value=document.getElementById('pre').options.selectedIndex;
document.forms["pasar"].submit();
}


/////////////////////////
function popdetalle(url)
{
window.open(url,"ventana1","fullscreen=yes,scrollbars=yes") ;
}
/////////////////////// VENTANA AGREGA CARRO ///////////////////////
var nombre, modelo, marca, tamano,id_producto,precio,detalle,x,y,stock,dias, idSemi, esSemi="0";
//agregar_producto_semi
function enviar_carro()
		{
            if( Number( document.getElementById('cantidad').value ) <= 0 || 
                isNaN(document.getElementById('cantidad').value ) ||
                parseInt(document.getElementById('cantidad').value ) != parseFloat( document.getElementById('cantidad').value ) )
                return;

            if( stock < Number(document.getElementById('cantidad').value ) ) {
                alert( "No hay suficientes productos para su pedido, por el momento existen "+stock+" ejemplares en bodega. Contáctese con nosotros si necesita una mayor cantidad de productos." );
                return;
            }

		if(esSemi!="true")
		{
				var url;
				if(document.getElementById('cantidad').value!="")
				{
					if(detalle!=true && detalle!='true')
						{
							 url="sesion/agrega_items.php?stock="+stock+"&precio="+precio+"&nombre="+nombre+"&modelo="+modelo+"&marca="+marca+
							 "&tamano="+tamano+"&id_producto="+id_producto+"&cantidad="+document.getElementById('cantidad').value;
								  cargaXML(url,document.getElementById('items_carro'));
								  cerrar_();
							abrir_mensaje_agrega();
						}
				
					else
						{
							url="../sesion/agrega_items.php?stock="+stock+"&precio="+precio+"&nombre="+nombre+"&modelo="+modelo+"&marca="+
							marca+"&tamano="+tamano+"&id_producto="+id_producto+"&cantidad="+document.getElementById('cantidad').value;
								cargaXML(url,window.opener.document.getElementById('items_carro'));
								cerrar_();
								var url_compara=window.opener.document.URL;								
								if(url_compara.substring(url_compara.length-13,url_compara.length)=="ver_carro.php")
									window.opener.document.forms["actualiza"].submit();
						}

				}
				else
					{alert("Debe agregar una cantidad");}
			}
//************
		else{//es semi-nuevo
			var url;
					if(detalle!=true && detalle!='true')
						{
							 url="sesion/agrega_items.php?idSemi="+idSemi+"&esSemi="+esSemi+"&stock=1&precio="+precio+"&nombre="+
							 nombre+"&modelo="+modelo+"&marca="+marca+"&tamano="+tamano+"&id_producto="+id_producto+"&cantidad=1";
								  cargaXML(url,document.getElementById('items_carro'));
								  cerrar_();
							abrir_mensaje_agrega();
						}
				
					else
						{
							url="../sesion/agrega_items.php?idSemi="+idSemi+"&esSemi="+esSemi+"&stock=1&precio="+precio+"&nombre="+nombre+
							"&modelo="+modelo+"&marca="+marca+"&tamano="+tamano+"&id_producto="+id_producto+"&cantidad=1";
								cargaXML(url,window.opener.document.getElementById('items_carro'));
								cerrar_();
								var url_compara=window.opener.document.URL;								
								if(url_compara.substring(url_compara.length-13,url_compara.length)=="ver_carro.php")
									window.opener.document.forms["actualiza"].submit();
						}

			}

//++
}
/////////////////////////////////////////////////////////////////////////////////////////
var x,y;
function position(e){
if(navigator.appName!="Microsoft Internet Explorer")
{
	x = e.pageX-100;
	y = e.pageY
if(y<500){y = y-100;}
else{y = y-150;}
}
}
////////////////////////////////////////////
var NO_url, NO_img, NO_mouse,noscroll=false;
//*************************************************************************************************************
function agregar_producto_no_disponible(url,img,mouse)
{
NO_url=url;
NO_img=img;
NO_mouse=mouse;
esSemiAgrega=false;
if(document.getElementById('agrega2_no_disponible').style.display!="none")
{
	document.getElementById('agrega2_no_disponible').style.display="none";
}
		var datos = url.split("@");
		if(navigator.appName=="Microsoft Internet Explorer")
		{
		document.getElementById('agrega2_no_disponible').style.top=300+"px";
		document.getElementById('agrega2_no_disponible').style.left=300+"px";
		new Effect.ScrollTo('agrega2_no_disponible',{duration:1.0});
		}
		else
		{
		position(mouse);
		document.getElementById('agrega2_no_disponible').style.top=y+"px";
		document.getElementById('agrega2_no_disponible').style.left=x+"px";
		}
		if(parseInt(datos[8])>1)
			document.getElementById('diasDemora').innerHTML=datos[8]+" d&iacute;as h&aacute;biles";
		else if(parseInt(datos[8])==1)
			document.getElementById('diasDemora').innerHTML=datos[8]+" d&iacute;a h&aacute;bil";
Effect.Appear('agrega2_no_disponible');
}
//*************************************************************************************************************
//*************************************************************************************************************
var esSemiAgrega=false;
function agregar_producto_no_disponible_semi(url,img,mouse)
{
esSemiAgrega=true;
NO_url=url;
NO_img=img;
NO_mouse=mouse;
if(document.getElementById('agrega2_no_disponible').style.display!="none")
{
	document.getElementById('agrega2_no_disponible').style.display="none";
}
		var datos = url.split("@");
		if(navigator.appName=="Microsoft Internet Explorer")
		{
		document.getElementById('agrega2_no_disponible').style.top=300+"px";
		document.getElementById('agrega2_no_disponible').style.left=300+"px";
		new Effect.ScrollTo('agrega2_no_disponible',{duration:1.0});
		}
		else
		{
		position(mouse);
		document.getElementById('agrega2_no_disponible').style.top=y+"px";
		document.getElementById('agrega2_no_disponible').style.left=x+"px";
		}
		document.getElementById('diasDemora').innerHTML="1 d&iacute;a h&aacute;bil";
Effect.Appear('agrega2_no_disponible');
}
//*************************************************************************************************************
function abrir_agrega2()
{
	
	if(document.getElementById('clave').value=="2009")
	{	
		noscroll=true;cerrar_no_disponible();
	if(esSemiAgrega==false){
		document.getElementById('cantidad').disabled=false;
		agregar_producto(NO_url,NO_img,NO_mouse);
		
	}
	else{
		
	agregar_producto_semi(NO_url,NO_img,NO_mouse)
	}
	
	}
	else
		alert("Ingresar una contraseña correcta para poder agregar el producto.");
	
}
//*************************************************************************************************************
function cerrar_no_disponible(){Effect.Fade('agrega2_no_disponible');}
//*************************************************************************************************************
function agregar_producto(url,img,mouse)
{
//document.getElementById('items_carro')
if(document.getElementById('agrega2').style.display!="none")
{
	document.getElementById('agrega2').style.display="none";
}
		var datos = url.split("@");
		marca= datos[0]; 
		nombre = datos[1];
		modelo= datos[2];
		precio= datos[3];
		id_producto= datos[4];
		tamano= datos[5];
		stock= datos[6];
		detalle=datos[7];
		dias=datos[8];
		if(navigator.appName=="Microsoft Internet Explorer")
		{
            x = y = 0;

            valores = findPos( mouse.srcElement );
            x = valores[ 0 ];
            y = valores[ 1 ];

		document.getElementById('agrega2').style.top=y-100+"px";
		document.getElementById('agrega2').style.left=x-100+"px";
		if(noscroll==false){
            Effect.Appear('agrega2');
		}
		else
			noscroll=false;
		}
		else
		{
		position(mouse);
		document.getElementById('agrega2').style.top=y+"px";
		document.getElementById('agrega2').style.left=x+"px";
		}
		document.getElementById('imagen').src=img;		
		//document.getElementById('imagen').width=110;		
		Effect.Appear('agrega2');
		document.getElementById('marca_').innerHTML=datos[0];
		document.getElementById('nombre_').innerHTML=datos[1];
		document.getElementById('modelo_').innerHTML=datos[2];
}
/////////++++++++++++++++++++++++++++
//*************************************************************************************************************
function agregar_producto_semi(url,img,mouse)
{
//document.getElementById('items_carro')
if(document.getElementById('agrega2').style.display!="none")
{
	document.getElementById('agrega2').style.display="none";
}
		var datos = url.split("@");
		marca= datos[0]; 
		nombre = datos[1];
		modelo= datos[2];
		precio= datos[3];
		id_producto= datos[4];
		tamano= datos[5];
		idSemi= datos[6];
		detalle=datos[7];
		esSemi=datos[8];
		if(navigator.appName=="Microsoft Internet Explorer")
		{
		document.getElementById('agrega2').style.top=300+"px";
		document.getElementById('agrega2').style.left=300+"px";
		if(noscroll==false){
		new Effect.ScrollTo('agrega2',{duration:1.0});
		}
		else
			noscroll=false;
		}
		else
		{
		position(mouse);
		document.getElementById('agrega2').style.top=y+"px";
		document.getElementById('agrega2').style.left=x+"px";
		}
		document.getElementById('imagen').src=img;		
		//document.getElementById('imagen').width=110;		
		Effect.Appear('agrega2');
		document.getElementById('marca_').innerHTML=datos[0];
		document.getElementById('nombre_').innerHTML=datos[1];
		document.getElementById('modelo_').innerHTML=datos[2];
		document.getElementById('cantidad').value=1;
		document.getElementById('cantidad').disabled=true;
}
//*************************************************************************************************************
/////////////////////////////// fin agregar carro/////////////////////////////
function filtrar_categoria()
{
document.getElementById('id_categoria').value=
document.getElementById('categorias').options[document.getElementById('categorias').options.selectedIndex].value;
document.getElementById('index_cate').value=document.getElementById('categorias').options.selectedIndex;
document.getElementById('id_marca').value=document.getElementById('marcas').options[document.getElementById('marcas').options.selectedIndex].value;
document.forms["enviar"].action="listas_marcas.php?carga=false&index="+document.getElementById('marcas').options.selectedIndex;
document.forms["enviar"].submit();
}
//////////////////////////////////////////////////////////////////////
/////////////////////////////// /////////////////////////////
function filtrar_categoria_semi()
{
document.getElementById('id_categoria').value=
document.getElementById('categorias').options[document.getElementById('categorias').options.selectedIndex].value;
document.getElementById('index_cate').value=document.getElementById('categorias').options.selectedIndex;
document.forms["enviar"].action="semi_nuevos.php?carga=false";
document.forms["enviar"].submit();
}
//*************************************************************************************************************
function filtrar_categoria_dp()
{
document.getElementById('id_categoria').value=
document.getElementById('categorias').options[document.getElementById('categorias').options.selectedIndex].value;
document.getElementById('index_cate').value=document.getElementById('categorias').options.selectedIndex;
document.getElementById('index_sem').value=document.getElementById('sem').options.selectedIndex;
document.forms["enviar"].action="productos_dp.php?carga=false&index_sem="+document.getElementById('index_sem').value;
document.forms["enviar"].submit();
}
//*************************************************************************************************************
function filtrar_dp()
{
document.getElementById('id_categoria').value=0;
document.getElementById('index_cate').value=0;
document.getElementById('index_sem').value=document.getElementById('sem').options.selectedIndex;
document.forms["enviar"].action="productos_dp.php?carga=false&index_sem="+document.getElementById('index_sem').value;
document.forms["enviar"].submit();
}

//////////////////////////////////////////////////////////////////////
function cerrar_()
{
Effect.Fade('agrega2');
document.getElementById('cantidad').value=1;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function cerrar_mensaje_agrega()
{
Effect.Fade('agrega2_consulta');
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ir_carro()
{
document.forms["enviar"].action="ver_carro.php";
document.forms["enviar"].submit();

}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function abrir_mensaje_agrega()
{
		document.getElementById('agrega2_consulta').style.top=document.getElementById('agrega2').style.top;
		document.getElementById('agrega2_consulta').style.left=document.getElementById('agrega2').style.left;
		Effect.Appear('agrega2_consulta');
}
//*************************************************************************************************************
function busq_marcas_busq()
{
if(document.getElementById('marcas_busq').options.selectedIndex!=0)
{
document.getElementById('id_marca').value=document.getElementById('marcas_busq').options[document.getElementById('marcas_busq').options.selectedIndex].value;
document.getElementById('filtrar_marca').value="true";
document.getElementById('buscar').value=document.getElementById('buscar_2').value;
document.forms["enviar"].action="busqueda.php?index="+document.getElementById('marcas_busq').options.selectedIndex+"&index_precio="+document.getElementById('pre').options.selectedIndex;
}
else
{
document.getElementById('buscar').value=document.getElementById('buscar_2').value;
document.getElementById('filtrar_marca').value="false";
document.forms["enviar"].action="busqueda.php?index=0&index_precio=0";
}
document.forms["enviar"].submit();
}

/////
var actualiza_carro=false;
///
function cerrar_sesion()
{
if(confirm("Si cierra su sesi?n, su carro se vaciara. ?Desea cerrar sesi?n de todas formas?"))
{
	document.getElementById('usuario').style.display="none";
	cargaXML("clientes/verificar.php?cerrar=true",document.getElementById('usuario'));
	document.getElementById('usuario').style.display="none";
if(actualiza_carro==true){
	setTimeout(cierre,500);
	}
	else{
	document.getElementById('usuario').style.display="none";
	cargaXML("clientes/verificar.php?cerrar=true",document.getElementById('usuario'));
	document.getElementById('usuario').style.display="none";
document.getElementById('regis').innerHTML ='<a href="clientes/" class="link_sesion" onMouseOver="overlib(\"Usuario registrado; Ingreso usuario nuevo\",FGCOLOR,\"#FFFFFF\",TEXTCOLOR,\"#660066\",WIDTH,\"250\",LEFT);" onMouseOut="nd();">Registrese</a>';
document.getElementById('regis2').innerHTML ='';
document.getElementById('items_carro').innerHTML='Productos:0<br>Cantidad: 0';
	}

}
}

function cierre()
{
	document.forms["enviar"].action="ver_carro.php";
	document.forms["enviar"].submit();
}
function llamar_comprar()
{
window.open("como_comprar.php","ventana5","scrollbars=yes,resizable=no,width=550,height=500");	
}
function llamar_seguridad()
{
window.open("seguridad_total.php","ventana5","scrollbars=yes,resizable=no,width=550,height=500");	
}

function findPos( obj ) {
	var curleft = curtop = 0;

    if (obj.offsetParent) {

        do {
                curleft += obj.offsetLeft;
                curtop += obj.offsetTop;
        } while( obj = obj.offsetParent );

        return [ curleft, curtop ];
    }
}

