var esNav=(navigator.appName=="Netscape");
var pulsar=true, imagen=null, detalles=true, situar=false;
var coordx, coordy, datox, datoy, cursorx, cursory, distancia, timer=null;

function iniciar() {
if (esNav) {
	for (i=0;i<document.layers.length;i++) {
		document.layers[i].document.captureEvents(Event.MOUSEDOWN);
		document.layers[i].document.onmousedown=new Function("evento","coger(evento,'"+document.layers[i].name+"')");
		}
	document.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
	}
else {
	document.ondragstart=mover;
	document.onmousedown=coger;
	}
document.onmousemove=mover;
document.onmouseup=soltar;

// Colocación de la bolsa de la compra en modo móvil.
distancia=(esNav) ? document.layers.bolsa.top : document.all.bolsa.style.pixelTop;
timer=setInterval("cambiar()",50); 
}

function coger(evento,nombre) {
if (esNav) {
	if (nombre.substring(0,5)=="mover" && evento.which==1) {
		pulsar=false;
		imagen=document.layers[nombre];
		imagen.zIndex=10;
		datox=imagen.left;
		datoy=imagen.top;
		coordx=evento.x;
		coordy=evento.y;
		cursorx=evento.pageX;
		cursory=evento.pageY;
		}
	}
else {
	if (event.button==1) {
		imagen=event.srcElement;
		while(imagen!=null && imagen.id.substring(0,5)!="mover") imagen=imagen.parentElement;
		if (imagen!=null) {
			pulsar=false;
			imagen.style.zIndex=10;
			datox=imagen.style.pixelLeft;
			datoy=imagen.style.pixelTop;
			coordx=event.offsetX;
			coordy=event.offsetY;
			cursorx=event.clientX;
			cursory=event.clientY;
			}
		}
	}
}

function mover(evento) {
if (imagen!=null) {
	if (esNav) {
		imagen.left=evento.pageX-coordx;
		imagen.top=evento.pageY-coordy;
		imagen.document.images[0].src=imagen.document.images[0].src; // Evita movimiento a saltos.
		}
	else {
		if (event.button!=1 && event.clientX>=0 && event.clientY>=0 && event.clientX<=document.body.clientWidth && event.clientY<=document.body.clientHeight) soltar();
		else {
			imagen.style.pixelLeft=event.clientX+document.body.scrollLeft-coordx;
			imagen.style.pixelTop=event.clientY+document.body.scrollTop-coordy;
			}
		}
	}
return pulsar;
}

function soltar(evento) {
if (imagen!=null) {
	detalles=false;
	if (esNav) {
		compra=document.layers.bolsa;
		if (imagen.left<=compra.left+compra.document.images[0].width && imagen.top<=compra.top+compra.document.images[0].height && imagen.left+imagen.document.images[0].width>=compra.left && imagen.top+imagen.document.images[0].height>=compra.top) {
			if (imagen.id.substr(0,6)=="mover0") alert("Este producto no está disponible.");
			else location="../bolsa.php3?ID="+document.inicio.ID.value+"&PD="+imagen.id.substr(5)+"&NP=S&NT="+(new Date()).getTime();
			}
		if (Math.abs(evento.pageX-cursorx)<2 && Math.abs(evento.pageY-cursory)<2) detalles=true;
		imagen.left=datox;
		imagen.top=datoy;
		imagen.zIndex=4;
		}
	else {
		compra=document.all.bolsa.style;
		if (imagen.style.pixelLeft<=compra.pixelLeft+compra.pixelWidth && imagen.style.pixelTop<=compra.pixelTop+compra.pixelHeight && imagen.style.pixelLeft+imagen.style.pixelWidth>=compra.pixelLeft && imagen.style.pixelTop+imagen.style.pixelHeight>=compra.pixelTop) {
			if (imagen.id.substr(0,6)=="mover0") alert("Este producto no está disponible.");
			else location="../bolsa.php3?ID="+document.inicio.ID.value+"&PD="+imagen.id.substr(5)+"&NP=S&NT="+(new Date()).getTime();
			}
		if (Math.abs(event.clientX-cursorx)<2 && Math.abs(event.clientY-cursory)<2) detalles=true; 
		imagen.style.pixelLeft=datox;
		imagen.style.pixelTop=datoy;
		imagen.style.zIndex=4;
		}
	}
pulsar=true;
imagen=null;
}

function cambiar() {
if (esNav) movido=window.pageYOffset-document.layers.bolsa.top+distancia;
else movido=document.body.scrollTop-document.all.bolsa.style.pixelTop+distancia;
if (movido) {
	modo=((movido>0) ? 1 : -1)*Math.floor(Math.pow(Math.abs(movido),0.6));
	if (esNav) document.layers.bolsa.top+=modo; else document.all.bolsa.style.pixelTop+=modo;
	}
}

function activar(nombre,datos) {
if (detalles) location="../"+nombre+"?ID="+document.inicio.ID.value+"&DIM="+((document.layers) ? innerWidth : document.body.offsetWidth)+criterios;
return false;
}

function entrar(nombre,datos) {
lugar=nombre+"?ID="+document.inicio.ID.value+datos+((nombre.indexOf("bolsa.php3")!=-1) ? "&NT="+(new Date()).getTime() : "");
if (nombre.indexOf("bolsa.php3")!=-1 && document.URL.indexOf("bolsa.php3")!=-1) location.replace(lugar); else location=lugar;
return false;
}

// Posibles estados de modo:
//	0 - Debe ocultarse el menu.
//	1 - Debe mostrarse el menu.
//	2 - Se trata de una imagen a cambiar.

function menu(boton,oculto,modo) {
if (esNav) {
	switch (modo) {
		case 0:
			document.layers[oculto].visibility="hidden";
			break;
		case 1:
			document.layers[oculto].clip.left=document.layers[boton].left-document.layers[oculto].left;
			document.layers[oculto].clip.top=document.layers[boton].top-document.layers[oculto].top;
			document.layers[oculto].clip.width=document.layers[boton].document.width;
			document.layers[oculto].clip.height=document.layers[boton].document.height;
			document.layers[oculto].visibility="visible";
			break;
		case 2:
			document.images[boton].src=oculto;
			break;
		}
	}
else {
	switch (modo) {
		case 0:
			document.all[oculto].style.visibility="hidden";
			break;
		case 1:
			superior=document.all[boton].style.pixelTop-document.all[oculto].style.pixelTop;
			izquierda=document.all[boton].style.pixelLeft-document.all[oculto].style.pixelLeft;
			derecha=izquierda+document.all[boton].style.pixelWidth;
			inferior=superior+document.all[boton].style.pixelHeight;
			document.all[oculto].style.clip="rect("+superior+" "+derecha+" "+inferior+" "+izquierda+")";
			document.all[oculto].style.visibility="visible";
			break;
		case 2:
			document.all[boton].src=oculto;
			break;
		}
	}
if (modo==0) status="";
else {
	switch (boton) {
		case "boton10":
			status="Acceda a nuestra amplia variedad de Cámaras Digitales.";
			break;
		case "boton11":
			status="Acceda a nuestra amplia variedad de Videocámaras Digitales.";
			break;
		case "boton12":
			status="Todas las memorias disponibles en el mercado para Cámaras Digitales.";
			break;
		case "boton13":
			status="Si necesita una nueva batería de mayor duración, aquí puede encontrarla.";
			break;
		case "boton14":
			status="Aquí tiene todas las lentes que puede necesitar para cualquier situación.";
			break;
		case "boton15":
			status="Vea todos los accesorios disponibles para su Cámara Digital.";
			break;
		case "boton16":
			status="Consulte el estado de su pedido o déjenos ayudarle a resolver sus dudas.";
			break;
		case "boton17":
			status="Acceda a nuestro amplio Glosario de términos sobre las Cámaras Digitales.";
			break;
		case "boton18":
			status="Los enlaces más interesantes relacionados con las Cámaras Digitales.";
			break;
		case "boton19":
			status="Todas las respuestas que buscaba sobre nuestra Tienda Virtual.";
			break;
		default:
			status=(oculto.indexOf("menu41.gif")!=-1)? "" : "Su motor de búsqueda si necesita localizar algo rápidamente.";
		}
	}
return true;
}

function comprobar(formulario,datos) {
for (n=0;n<=datos;n++) {
	if ((formulario.elements[n].type=="text") ? formulario.elements[n].value=="" : formulario.elements[n].selectedIndex==0) {
		alert ("Debe introducir el dato que a continuación le indicamos.");
		formulario.elements[n].focus();
		return false;
		}
	}
return true;
}


