// wwtop2.js 
// 2005-02-28	JJ fixed cart double up issue or no entry issue
// 2007-07-19	ka cursor: pointer

floatX=40;
floatY=34;
layerwidth=200;
layerheight=180;
align="right";
valign="center";
delayspeed=1;
NSpass = 0;		// NetScape passed routine.

NS6=false;
IE4=(document.all);
if (!IE4) {NS6=(document.getElementById);}
NS4=(document.layers);


document.write("<style> .hand { cursor: pointer;}</style>");


function adjust() {
	if ((NS4) || (NS6)) 
	{
		if (lastX==-1 || delayspeed==0)
		{
			lastX=window.pageXOffset + floatX;
			lastY=window.pageYOffset + floatY;
		}
		else
		{
			dx=Math.abs(window.pageXOffset+floatX-lastX);
			dy=Math.abs(window.pageYOffset+floatY-lastY);
			d=Math.sqrt(dx*dx+dy*dy);
			c=Math.round(d/10);
			if (window.pageXOffset+floatX>lastX) {lastX=lastX+delayspeed+c;}
			if (window.pageXOffset+floatX<lastX) {lastX=lastX-delayspeed-c;}
			if (window.pageYOffset+floatY>lastY) {lastY=lastY+delayspeed+c;}
			if (window.pageYOffset+floatY<lastY) {lastY=lastY-delayspeed-c;}
		}
		if (NS4)
		{
			document.layers['floatlayer'].pageX = lastX;
			document.layers['floatlayer'].pageY = lastY;
		}
		if (NS6)
		{
			document.getElementById('floatlayer').style.left=lastX;
			document.getElementById('floatlayer').style.top=lastY;
		}
	}
	else if (IE4)
	{
		if (lastX==-1 || delayspeed==0)
		{
			lastX=document.body.scrollLeft + floatX;
			lastY=document.body.scrollTop + floatY;
		}
		else
		{
			dx=Math.abs(document.body.scrollLeft+floatX-lastX);
			dy=Math.abs(document.body.scrollTop+floatY-lastY);
			d=Math.sqrt(dx*dx+dy*dy);
			c=Math.round(d/10);
			if (document.body.scrollLeft+floatX>lastX) {lastX=lastX+delayspeed+c;}
			if (document.body.scrollLeft+floatX<lastX) {lastX=lastX-delayspeed-c;}
			if (document.body.scrollTop+floatY>lastY)  {lastY=lastY+delayspeed+c;}
			if (document.body.scrollTop+floatY<lastY)  {lastY=lastY-delayspeed-c;}
		}
		document.all['floatlayer'].style.posLeft = lastX;
		document.all['floatlayer'].style.posTop = lastY;
	} 
	setTimeout('adjust()',50);
}

function define()
{
	if ((NS4) || (NS6)) 
	{ 
		if (align=="left")		{floatX=ifloatX};
		if (align=="right")		{floatX=window.innerWidth-ifloatX-layerwidth-20};
		if (align=="center")	{floatX=Math.round((window.innerWidth-20)/2)-Math.round(layerwidth/2)};
		if (valign=="top")		{floatY=ifloatY};
		if (valign=="bottom")	{floatY=window.innerHeight-ifloatY-layerheight};
		if (valign=="center")	{floatY=Math.round((window.innerHeight-20)/2)-Math.round(layerheight/2)};
	}
	if (IE4) 
	{
		if (align=="left")		{floatX=ifloatX};
		if (align=="right")		{floatX=document.body.offsetWidth-ifloatX-layerwidth-20}
		if (align=="center")	{floatX=Math.round((document.body.offsetWidth-20)/2)-Math.round(layerwidth/2)}
		if (valign=="top")		{floatY=ifloatY};
		if (valign=="bottom")	{floatY=document.body.offsetHeight-ifloatY-layerheight}
		if (valign=="center")	{floatY=Math.round((document.body.offsetHeight-20)/2)-Math.round(layerheight/2)}
	}
}

function tryCookies()
{
	var x = true;
	var a;
	setCookie('try','success');		// try setting and reading a cookie to see if they are enabled
	a=getCookie('try');
	if(a!='success') 
	{
		alert('You have cookies disabled,\nwhich will prevent you from\nusing our shopping cart.');
		x = false;
	} 
	return(x);
}

function testCookies()
{
	if(NSpass == 0)
	{
		var b = getCookie('ksize');
		if(!b)
		{
			setCookie('ksize',10);
			document.cart.kar.size = 10;
		} 
		else
		{
			document.cart.kar.size = b;
		}
		var a = getCookie('kf');			
		delayspeed = 0;
		if(a=='off')													
		{																
			layerwidth=200;
			lastX += 223;
			cc();
		}																
		if(a=='on')														
		{																
			layerwidth=200;
			define();
		}																
		var a = getCookie('cart');
		if(!a) 
		{	
			setCookie('cart',"\xff");	// Initialize the cart cookie if cart cookie not set
			a = "\xff";
		}
		// initialize cart window with values on cookie
		var k = new Array();
		k = a.split("\xff");			// first and last are always bogus!!!
		var l = k.length;				// how many did I find?
		if ((NS4) || (NS6)) 
		{
			l++;						// If netscape add one, to get all processed.
		}
		if (l>2)						// anything under 3 means nothing
		{
			for (var i=1;i<l-1;i++)
			{
				var optionName = new Option(unescape(k[i]), unescape(k[i]), false, true);
			    var length = document.cart.kar.length;
				document.cart.kar.options[length] = optionName;
			}		
		}
		setTimeout('sc()',100);
		NSpass = 1;
	}
}

function sc() 
{
	document.getElementById("floatlayer").style.display = '';
	delayspeed = 1;
}

function delkar()
{
	var input_box=confirm('Are you sure you want to empty your cart?');
	if(input_box==true)
	{
		setCookie('cart',"\xff");	// Initialize the cart cookie 
	    var length = document.cart.kar.length;
		for( var i=length; i>=0 ; --i)
		{
		    document.cart.kar.options[i] = null;
		}
	}
}

function remrec()
{
    var Current = document.cart.kar.selectedIndex;
	var tekst="ll";
	if(Current > -1)
	{
 		tekst = document.cart.kar.options[Current].text;
		// remove from cookie
		var a=getCookie('cart'); 
		var s = new RegExp("\xff"+escape(tekst)+"\xff", "i");
		a=a.replace(s, "\xff");				// replace tekst with nothing
		setCookie('cart',a);				// put cookie back where it came form

		// remove from dropdown
	    document.cart.kar.options[Current] = null;
		var length = document.cart.kar.length;
		if(Current == length) 
		{
			if(length>0) document.cart.kar.options[Current-1].selected = true;
		}
		else
		{
			if(length>0) document.cart.kar.options[Current].selected = true;
		}
	}
	else alert('Please click on a title first!');
}

function wso()				// v1.07
{							// v1.07
	window.status=' ';		// v1.07
}							// v1.07

function aC(artnum)
{
	if(tryCookies())
	{
		var a=getCookie('cart');
		if(!a) a="\xff";
		// first check of artikel already exists in cart, if so remove
		a+=escape(artnum)+"\xff";	
		setCookie('cart',a);				// put cookie back where it came from

		// Now add option to cart
		var optionName = new Option(artnum, artnum, false, true);
	    var length = document.cart.kar.length;
		document.cart.kar.options[length] = optionName;
		window.status='Item added to cart successfully';				// v1.07
		setTimeout("wso();",2000);										// v1.07 turn off after 2 secs
	}
}

function co()
{
	window.location.href="order.html";
}

function cc()
{
	if(layerwidth==200)
	{	// go small
		layerwidth=-23;
		setCookie('ksize',document.cart.kar.size);
		setCookie('kf','off');
		document.cart.kar.size = 1;
		document.cart.cartvis.src = 'gfx/cart_ri.gif';
	}
	else
	{	// go big
		layerwidth=200;
		setCookie('kf','on');
		var a = getCookie('ksize');
		document.cart.kar.size = a;
		document.cart.cartvis.src = 'gfx/cart_le.gif';
	}
	define();
}

function cs(t)
{
	if (t==1) 
	{
		if (document.cart.kar.size<20) document.cart.kar.size += 1;
	} else 
	{
		if (document.cart.kar.size > 1) document.cart.kar.size -= 1;
    }
	setCookie('ksize',document.cart.kar.size);
}		
