/*  CROSS-BROWSER MODULAR DHTML API (c) 2001-2005 Angus Turnbull, http://www.twinhelix.com
  This notice may not be altered or removed. See my site for licensing and more scripts! */
var isDOM=document.getElementById?1:0,
 isIE=document.all?1:0,
 isNS4=navigator.appName=='Netscape'&&!isDOM?1:0,
 isIE4=isIE&&!isDOM?1:0,
 isOp=self.opera?1:0,
 isDyn=isDOM||isIE||isNS4,
 isWin=navigator.platform.indexOf('Win')!=-1?1:0;
function getRef(i, p)
{
 p=!p?document:p.navigator?p.document:p;
 return isIE ? p.all[i] :
  isDOM ? (p.getElementById?p:p.ownerDocument).getElementById(i) :
  isNS4 ? p.layers[i] : null;
};
function getSty(i, p)
{
 var r=getRef(i, p);
 return r?isNS4?r:r.style:null;
};

if (!self.LayerObj) var LayerObj = new Function('i', 'p',
 'this.ref=getRef(i, p); this.sty=getSty(i, p); return this');
function getLyr(i, p) { return new LayerObj(i, p) };
function LyrFn(n, f)
{
 LayerObj.prototype[n] = new Function('var a=arguments,p=a[0],px=isNS4||isOp?0:"px"; ' +
  'with (this) { '+f+' }');
};
LyrFn('x','if (!isNaN(p)) sty.left=p+px; else return parseInt(sty.left)');
LyrFn('y','if (!isNaN(p)) sty.top=p+px; else return parseInt(sty.top)');
LyrFn('w','if (p) (isNS4?sty.clip:sty).width=p+px; ' +
 'else return (isNS4?ref.document.width:ref.offsetWidth)');
LyrFn('h','if (p) (isNS4?sty.clip:sty).height=p+px; ' +
 'else return (isNS4?ref.document.height:ref.offsetHeight)');
LyrFn('vis','sty.visibility=p');
LyrFn('bgColor','if (isNS4) sty.bgColor=p?p:null; ' +
 'else sty.background=p?p:"transparent"');
LyrFn('bgImage','if (isNS4) sty.background.src=p?p:null; ' +
 'else sty.background=p?"url("+p+")":"transparent"');
LyrFn('clip','if (isNS4) with(sty.clip){left=a[0];top=a[1];right=a[2];bottom=a[3]} ' +
 'else sty.clip="rect("+a[1]+"px "+a[2]+"px "+a[3]+"px "+a[0]+"px)" ');
LyrFn('write','if (isNS4) with (ref.document){write(p);close()} else ref.innerHTML=p');
LyrFn('alpha','var f=ref.filters,d=(p==null),o=d?"inherit":p/100; if (f) {' +
 'if (!d&&sty.filter.indexOf("alpha")==-1) sty.filter+=" alpha(opacity="+p+")"; ' +
 'else if (f.length&&f.alpha) with(f.alpha){if(d)enabled=false;else{opacity=p;enabled=true}} }' +
 'else if (isDOM)sty.opacity=sty.MozOpacity=o');
function setLyr(v, dw, p)
{
 if (!setLyr.seq) setLyr.seq=0;
 if (!dw) dw=0;
 var o = !p ? isNS4?self:document.body : !isNS4&&p.navigator?p.document.body:p,
  IA='insertAdjacentHTML', AC='appendChild', id='_sl_'+setLyr.seq++;

 if (o[IA]) o[IA]('beforeEnd', '<div id="'+id+'" style="position:absolute"></div>');
 else if (o[AC])
 {
  var n=document.createElement('div');
  o[AC](n); n.id=id; n.style.position='absolute';
 }
 else if (isNS4)
 {
  var n=new Layer(dw, o);
  id=n.id;
 }

 var l=getLyr(id, p);
 with (l) if (ref) { vis(v); x(0); y(0); sty.width=dw+(isNS4?0:'px') }
 return l;
};
if (!self.page) var page = { win: self, minW: 0, minH: 0, MS: isIE&&!isOp,
 db: document.compatMode&&document.compatMode.indexOf('CSS')>-1?'documentElement':'body' };
page.winW=function()
 { with (this) return Math.max(minW, MS?win.document[db].clientWidth:win.innerWidth) };
page.winH=function()
 { with (this) return Math.max(minH, MS?win.document[db].clientHeight:win.innerHeight) };
page.scrollX=function()
 { with (this) return MS?win.document[db].scrollLeft:win.pageXOffset };
page.scrollY=function()
 { with (this) return MS?win.document[db].scrollTop:win.pageYOffset };
page.docW=function()
 { with (this) return Math.max(minW, isNS4?win.document.width:win.document.offsetWidth) };
page.docH=function()
 { with (this) return Math.max(minH, isNS4?win.document.height:win.document.offsetHeight) };
page.elmPos=function(e,p)
{
 var x=0,y=0,w=p?p:this.win;
 e=e?(e.substr?(isNS4?w.document.anchors[e]:getRef(e,w)):e):p;
 if(isNS4){if(e&&(e!=p)){x=e.x;y=e.y};if(p){x+=p.pageX;y+=p.pageY}}
 if (e && this.MS && navigator.platform.indexOf('Mac')>-1 && e.tagName=='A')
 {
  e.onfocus = new Function('with(event){self.tmpX=clientX-offsetX;' +
   'self.tmpY=clientY-offsetY}');
  e.focus();x=tmpX;y=tmpY;e.blur()
 }
 else while(e){x+=e.offsetLeft;y+=e.offsetTop;e=e.offsetParent}
 return{x:x,y:y};
};
function addEvent(o, i, f, c)
{
 var l = 'addEventListener', n = 'on'+i, b = o[n], a = o.evts = o.evts || [],
  m = / u=(\d+),r/.exec(b), u = m ? parseInt(m[1]) : a.length;
 if (o[l]) return o[l](i, f, false);
 a[u] = a[u] || [];
 if (!m)
 {
  if (b) a[u][0] = b;
  o[n] = new Function('e', 'e=e||self.event;var u=' + u + ',r=true,o=this,n="' + n +
   '",t=n+"TMP",a=o.evts[u];for(var f in a){o[t]=a[f];r=o[t](e)!=false&&r}return r&&isNS4&&' +
   c + '?o.routeEvent(e):r');
  if (isNS4 && c) o.captureEvents(Event[i.toUpperCase()]);
 }
 a[u][a[u].length] = f;
}
function addEvent(o, n, f)
{
 var a='addEventListener', h='on'+n;
 if (o[a]) return o[a](n, f, false);
 if (o[h])
 {
  o._c |= 0;
  var b = '_b' + (++o._c);
  o[b] = o[h];
 }
 o[h] = function(e)
 {
  e=e||self.event;
  var r = true;
  if (o[b]) r = o[b](e) != false && r;
  o._f=f;
  r = o._f(e) != false && r;
  return r;
 }
};
/* ****************************** */
var oScCntnt, statL, winstartposx, winstartposy, winendposx, winendposy, dx=0, dy=0, dw=0, dh=0, dt=0, ix=0, iy=0, iw=0, ih=0, animationrunning, direction;
//Animationparams
var winorginx = 80, winorginy = 0, winopenx = 133, winopeny = 13; //relative to topleft of checkoutbutton
var steps = 10; duration = 300; showhideOpentime = 2000, w = 500; lineheight = 24; msgheight = 16; 
var langScContent = 'empty';
var lbl_itemtxt = 'item';
var lbl_itemstxt = 'items';
var lbl_checkout_buttontxt = "checkout";
var lbl_emptytxt = "empty";
var h = 0;
var items = 0;
var lines = 5;
var cookielifetime = 0 //days

var cartid = new Array();
var cartanz = new Array();
var carttxt = new Array();
var cartmsg = new Array();
var scartid="";
var scartanz="";
var scarttxt="";
var scartmsg="";

function putArrays()
{
	var sep = "";
	scartid="";
	scartanz="";
	scarttxt="";
	scartmsg="";
	for(i=0;i<cartid.length;i++)
	{
		if(parseInt(cartid[i])!= -1)
		{
			scartid = scartid + sep +cartid[i];
			scartanz = scartanz + sep +cartanz[i];
			scarttxt = scarttxt + sep +carttxt[i];
			scartmsg = scartmsg + sep +cartmsg[i];
			sep = "#";
		}
	}
	setCookie('cartid',scartid); 
	setCookie('cartanz',scartanz); 
	setCookie('carttxt',scarttxt); 
	setCookie('cartmsg',scartmsg); 
}
function getArrays()
{
	scartid = getCookie('cartid');
	scartanz = getCookie('cartanz');
	scarttxt = getCookie('carttxt');
	scartmsg = getCookie('cartmsg');
	cartid = scartid.split("\#");
	cartanz = scartanz.split("\#");
	carttxt = scarttxt.split("\#");
	cartmsg = scartmsg.split("\#");
	
}
function setParams(itemtxt,itemstxt,checkout_buttontxt,emptytxt)
{
	if(itemtxt != '') lbl_itemtxt = itemtxt;
	if(itemstxt != '') lbl_itemstxt = itemstxt;
	if(checkout_buttontxt != '') lbl_checkout_buttontxt = checkout_buttontxt;
	if(emptytxt != '') lbl_emptytxt = emptytxt;
}
function clearCart()
{
	delCookie('items');
	delCookie('cartid');
	delCookie('cartanz');
	delCookie('carttxt');
	delCookie('cartmsg');
	cartid = [];
	cartanz = [];
	carttxt = [];
	cartmsg = [];
	
	hideShoppingcart();
}
function incItemcount()
{
	setItemcount(getItemcount() + 1);
}
function decItemcount()
{
	var n = getItemcount();
	if(n > 0) 
		setItemcount(n-1);
}
function setItemcount(n)
{
	items = n;
	setCookie('items',n);
}
function getItemcount()
{
	var val=getCookie('items');
	if(isNaN(val) | val=="")
	{
		items = 0;
	}
	else
	{
		items = parseInt(val);
	}
	return items;
}	
function getCookie(name) 
{
	var dcookie = document.cookie; 
	var cname = name + "=";
	var clen = dcookie.length;
	var cbegin = 0;
	while (cbegin < clen) 
	{
		var vbegin = cbegin + cname.length;
		if (dcookie.substring(cbegin, vbegin) == cname) 
		{ 
			var vend = dcookie.indexOf (";", vbegin);
			if (vend == -1) vend = clen;
			return unescape(dcookie.substring(vbegin, vend));
		}
		cbegin = dcookie.indexOf(" ", cbegin) + 1;
		if (cbegin == 0) break;
	}
	return "";
}
function setCookie (name, value) 
{
	var expires = new Date();
	var later = expires.getTime() + (cookielifetime * 24 * 60 * 60 * 1000);
	expires.setTime(later);	
	if(cookielifetime > 0)
	{
		document.cookie = name + "=" + escape (value) + "; expires=" + expires.toGMTString() +  "; path=/";
	}else{
		document.cookie = name + "=" + escape (value) + "; path=/";
	}
}
function delCookie (name) 
{
	document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}
function addtoCart(ttid,itemid,txt,delivery,alertmsg,alertmsg2,number)
{
	var delaymsg = "";
	var searchindex = -1;
	if(delivery!='0')
	{
		delaymsg = alertmsg + " " + delivery; 
		if (!confirm(decodeURIComponent(delaymsg)+"\n"+alertmsg2))
		{
			return false;
		}
	}
	setItemcount(getItemcount() + parseInt(number));	
	//setCookie(itemid,number);
	
	for(i=0;i<cartid.length;i++)
	{
		if(cartid[i]==itemid) searchindex = i;
	}
	//alert(searchindex);
	if(searchindex == -1)
	{
		cartid.push(itemid);
		cartanz.push(number);
		carttxt.push(txt);
		cartmsg.push(delaymsg);
	}
	else
	{
		cartanz[searchindex]=parseInt(cartanz[searchindex])+parseInt(number);
	}
	putArrays();
	setCookie('showhide','1');
	return true;
}
function incitem(itemid)
{
        var searchindex = -1;
        for(i=0;i<cartid.length;i++)
        {
                if(cartid[i]==itemid) searchindex = i;
        }
	if(searchindex != -1)
	{
		cartanz[searchindex]=parseInt(cartanz[searchindex])+1;
		incItemcount();
		putArrays();
		location.replace(location.href);
	}
} 
function decitem(itemid)
{
	var searchindex = -1;
	for(i=0;i<cartid.length;i++)
	{
		if(cartid[i]==itemid) searchindex = i;
	}
	if(searchindex != -1)
	{
		var ca=parseInt(cartanz[searchindex]);
		if(ca>1)
		{
			cartanz[searchindex]=ca-1;
			decItemcount();
	 		putArrays();
           	location.replace(location.href);
		}
		else if(ca==1)
		{
			cartid[searchindex]=-1;
			decItemcount();
			putArrays();
			location.replace(location.href);
		}
	}
}
function writeCartShortItems()
{
	var txt = lbl_emptytxt;
	var script_action2;
	if(items == 1)
	{
		txt = items + "&nbsp;" + lbl_itemtxt;
	}
	else
	{
		txt = items + "&nbsp;" + lbl_itemstxt;
	}		
	l = script_action.indexOf('"',10);
	script_action2 = script_action.substr(9,l-9);
	if (!statL) statL = getLyr('shoppingcartleft');
	statL.write('<form name="cartform" method="post" action="/'+script_action2+'"><table class="yellowbox"><tr><td width="78%"><ul><li>' +
	txt + '</li></ul></td></tr><tr><td align="center"><input id="cobutton" name="Submit" type="submit" value="' + lbl_checkout_buttontxt + '" onmouseover="showCartcontent()" onmouseout="hideCartcontent()"/></td></tr></table></form>');
} 
function showShoppingcart(mode)
{
	if(mode == '1')
	{
		if(document.cookie)
		{
			getItemcount();
		}
		writeCartShortItems();
	}
	else
	{
		if(document.cookie)
		{
			if(getItemcount() > 0)
			{
				writeCartShortItems();
			}
		}
	}
}
function hideShoppingcart()
{
 if (!statL) statL = getLyr('shoppingcartleft');
 statL.write('');
}
function showhideCartcontent()
{
	if(document.cookie)
	{
		if(getItemcount() > 0)
		{
			getArrays();
			if(getCookie('showhide')=='1')
			{
				showCartcontent();
				setTimeout('hideCartcontent()', showhideOpentime + duration)
				delCookie('showhide');
			}
		}
	}
}
function showCartcontent()
{
	var htmlclass = "tr-even";
	var linecnt=0;
	if(getItemcount() == 0) return;
	getArrays();
	lines = 0;
	h=0;
	if(isIE) h+=2;
	langScContent="<table class=\"carttable\">";
	for(i=0;i<cartid.length;i++)
	{
		lines++;
		h+=lineheight;
		if(cartmsg[i]!="") h+=msgheight;
		if(linecnt++ % 2 == 0)
		{
			htmlclass = "tr-even tr-0";
		}
		else
		{
			htmlclass = "tr-odd tr-0";
		}
		langScContent=langScContent+"<tr class=\""+ htmlclass +"\"><td class=\"td-0\">"+cartanz[i]+"</td>";
		langScContent=langScContent+"<td class=\"td-last td-1\">"+decodeURIComponent(carttxt[i]);
		langScContent=langScContent+"<br><i>"+decodeURIComponent(cartmsg[i])+"</i></td></tr>";
	}
	langScContent=langScContent+"</table>";
	//h=lines*lineheight;
	winstartposx = 61 + winorginx;
	winstartposy = 194 + winorginy;
	winendposx = 61 + winopenx;
	winendposy = 194 + winopeny;
	if(isOp) steps=5;
	dx=(winopenx-winorginx)/steps;
	dy=(winopeny-winorginy)/steps;
	dw=w/steps;
	dh=h/steps;
	dt=duration/steps;
	ix=winstartposx;
	iy=winstartposy;
	iw=0;
	ih=0;
    animationrunning = false;
	if(!oScCntnt) oScCntnt = setLyr('visible', iw, statL.ref);
	if (oScCntnt.ref) with (oScCntnt)
	{
		bgColor('#CCE4F3');
		sty.zIndex = 99;
		direction = 1;
		if(animationrunning == false) doanimation();
	}
}
function hideCartcontent()
{
	direction = -1;
	if(animationrunning == false) doanimation();	
}
function doanimation()
{
	if(oScCntnt)
	{
		if(direction < 0)
		{
			oScCntnt.write('');
		}
		if(iw > 0 & direction < 0 | iw < w & direction > 0)
		{
			animationrunning = true;
			ix+=direction*dx;
			iy+=direction*dy;
			iw+=direction*dw;
			ih+=direction*dh;
			if(ix>0 & iy>0 & iw>0 & ih>0)
			{
				oScCntnt.x(ix);
				oScCntnt.y(iy);
				oScCntnt.w(iw);
				oScCntnt.h(ih);
			}
			setTimeout('doanimation()', dt);
		}
		else
		{
			if(direction > 0)
			{
				oScCntnt.write(langScContent);
			}
			else
			{
				oScCntnt.vis('hidden');
				oScCntnt = null;
			}			
			animationrunning = false;
		}
	}
}
function doBlink() {
  // Blink, Blink, Blink...
  var blink = document.all.tags("BLINK")
  for (var i=0; i < blink.length; i++)
    blink[i].style.visibility = blink[i].style.visibility == "" ? "hidden" : "" 
}

function startBlink() {
  // Make sure it is IE4
  if (document.all)
    setInterval("doBlink()",700)
}

