function getTecla(evento){
	var tecla=null;
	if(!document.all){
		tecla = evento.which;
		if(tecla <= 0) tecla = evento.keyCode;
	}else{
		tecla = window.event.keyCode;
	}
	return tecla;
}

function eventoComprar(e,codigo_articulo){
      if(getTecla(e) == 13)
      {
	comprarArticulo(codigo_articulo);
      }

}

function eventoEnviarAcceso(e){
      if(getTecla(e) == 13)
      {
	document.getElementsByName("formu_login").item(0).submit();
      }

}


function cargarFoto(n){
//alert(1);
	var imagen = window.document.getElementById("foto"+n);					//new Image()
	if(imagen != null){
		var param = "";
		x = imagen.width;
		y = imagen.height;
		param = comparar(x,y);
		var texto = "<img src=\""+imagen.src+"\"";
		texto += param;
		texto += " id=\"foto"+n+"2\" style=\"cursor:hand\">";
		try{
			window.document.getElementById("foto_grande"+n).innerHTML = texto;
		}catch(Exception){}
		
		var imagen = window.document.getElementById("foto"+n+"2")
		if(imagen && cont<10){
			if(imagen.height>tm || imagen.width>am){
				cont++;
				cargarFoto(n);
			}
		}else{
			try{
				alert(foto);
				window.document.getElementById("foto_grande").innerHTML = "<img src=\"fotos/"+foto+".jpg\" width="+am+" height="+tm+" style=\"cursor:hand\">";
			}catch(Exception){}
		}
		imagen = null;
	}
}
function comparar(cox,coy){
	var param = "";
	if(cox<am && coy<tm){
		param = "";
	}else if(cox<=am && coy>=tm){
		param = " height="+tm;
	}else if(cox>=am && coy<=tm){
		param = " width="+am;
	}else if(cox>am && coy>tm){
		var fx = am;
		var fy = tm;
		if(cox>coy){
			fy = fx*y/x;
		}else{
			fx = fy*x/y;
		}
		param = comparar(fx,fy);		
	}
	return param;
}
function abrirFoto(sCodigo){
	ventanaFoto = window.open("fotos.asp?codigo="+sCodigo,"ventana_foto","fullscreen=yes,scrollbars=no,resizable=no");
}
function borrar(id){
	if(confirm("¿Desea eliminar este artículo del pedido?")){
		window.document.getElementsByName("id").item(0).value = id;
		window.document.getElementsByName("opcion").item(0).value = "borrar";
		window.document.getElementsByName("formu").item(0).submit();
	}
}
function borrarArticuloPedido(id,page){
	if(confirm("¿Desea eliminar este artículo del pedido?")){
		window.location.href = "borrar_cesta.asp?id="+id+"&page="+page;
	}
}
function NavRollOver(oTd) {if (!oTd.contains(event.fromElement)) {oTd.bgColor="#F7FAE5";}}
function NavRollOut(oTd) {if (!oTd.contains(event.toElement)) {oTd.bgColor="#FFFFFF";}}
function valNum(obj){
	var valor = obj.value;
	var numero = new Number(valor);
	while(""+numero == "NaN"){
		valor = (valor.length>1)? valor.substring(0,valor.length-1) : "" ;
		numero = new Number(valor);
	}
	obj.value = valor;
}
sw_avanzar = true;
sw_retroceder = true;
function iniciar(){
	//-imagen javascript-//cargarFoto(1);
	//-imagen javascript-//cargarFoto(2);
	//-imagen javascript-//cargarFoto(3);
	//-imagen javascript-//cargarFoto(4);
	try{
		var control = window.document.getElementsByName("siguiente_pagina");
		if(control.length>0){
			control.item(0).focus();
		}else{
			
		}
	}catch(Exception){}
	
	try{
	document.onkeydown = function(){
		if(window.event && (window.event.keyCode == 39)){
			avanzar();
		}else if(window.event && (window.event.keyCode == 37)){
			retroceder();
		}
	}
	}catch(EXCEPTION){}
}
function verArticulo(sCod,idCesta,sCodCat){
	window.location.href = "http://www.alcodistribuciones.com/articulos.asp?codigo="+sCod+"&codigo_cat="+sCodCat
}
