/***********************************************************************
*
* getCartItem		-	Gets the Actinic Cart Value & No of Items
*
* Input: nIndex	-	Cart item index to retrieve
*							1 = TOTAL_VALUE
*							3 = CART_COUNT
*
* Returns:				Requested cart item or 0 (zero) if not found
*
************************************************************************/

//CART_CONTENT = Cookie name
//1 = TOTAL_VALUE
//3 = CART_COUNT

function getCartItem(nIndex)
	{
	var act_cart= getCookie("CART_CONTENT")
	var sTemp =(act_cart != null) ? sTemp=act_cart.split("\t"):0;
	return (sTemp.length > 0) ? sTemp[nIndex] : 0;
	}

/***********************************************************************
*
* GotoAnchor - JS for jumping to an anchor - some user agents don't handle
*				anchors correctly if BASE HREF is present
*
* Input: 				sAnchor
*
* Returns:				nothing
*
************************************************************************/

function GotoAnchor(sAnchor)
	{
	window.location.hash = sAnchor;
	}

/***********************************************************************
*
* getMiniCart		-	fetches cart content summary
*
* Returns:		-	HTML string for summary display
*
* Graham Bradley 2007
*
* To make editing the output HTML easier, output code has been split into
* nine 'template' strings.
*
*	tableOpen	-	the opening table code
*	itemLine	-	repeated for each item in the cart
*	shippingLine	-	for displaying shipping charges (if any)
*	vatLine		-	for displaying VAT on items & shipping (if any)
*	discountLine	-	for displaying discount total (if any)
*	surchargeLine	-	for displaying surcharge total (if any)
*	totalLine	-	for displaying the cart total
*	tableClose	-	the closing table code
*	emptyLine	-	displayed when cart is empty
*
* Within these templates, you can use variables to insert values into
* the summary, similar to variables in Actinic:
*
*	VAR:QUANTITY	-	The quantity of item in cart
*	VAR:TITLE	-	Abbreviated name of item
*	VAR:LINK	-	URL of item via the cgi-bin
*	VAR:PRICE	-	Formatted price of item
*	VAR:SHIPPING	-	Total of shipping applied
*	VAR:VAT		-	Total VAT on cart items & shipping
*	VAR:DISCOUNT	-	Total of discounts applied
*	VAR:SURCHARGE	-	Total of surcharges applied
*	VAR:TOTAL	-	Grand total
*
* Variables can only be used in the templates in which they are found.	
*
************************************************************************/

function getMiniCart(){

var tableOpen="<table width='100%'>";
var itemLine="<tr><td valign='top'align='right' class='actsmall' width='10'>VAR:QUANTITYx </td><td class='actsmall'><a href='VAR:LINK' >VAR:TITLE...</a></td><td align='right' valign='top' class='actsmall'>VAR:PRICE</td></tr>"
var shippingLine="<tr><td colspan='2' class='actsmall'>Shipping</td><td align='right' class='actsmall'>VAR:SHIPPING</td></tr>"
var vatLine="<!--VAR:VAT-->"
var discountLine="<tr><td colspan='2' class='actsmall'>Discounts</td><td align='right' class='actsmall'>VAR:DISCOUNT</td></tr>"
var surchargeLine="<!--VAR:SURCHARGE-->"
var totalLine="</table><table width='100%' class='actsmall'><tr><td class='actsmall'><b>Total</b></td><td align='right' class='actsmall'><b>VAR:TOTAL</b></td></tr>"
var tableClose="</table>"
var emptyLine="<span class='actlarge'>Nothing in your basket yet :-)</span>";

var cookie=getCartItem(4);

if (!cookie){
	return emptyLine;
	}
var re=new Array();
var match=new Array();
var total=0;
var str;
re[1]=/cur=([^&]*)&!/g;
re[2]=/&!(.*)/g;
re[3]=/ss=(.*)cur=/i;
re[4]=/tx=(.*)sh=/i;
re[5]=/sh=(.*)ss=/i;
for (i=1;i<re.length;i++){
	match[i]=re[i].exec(cookie);
	match[i]=match[i][1];
	}
lines=match[2].split("&!");
store=new Array();
re[0]=/^(\d*)x/;
re[1]=/x([^>]*)>/;
re[2]=/>([^>]*)>/;
re[3]=/>([^>]*)$/;
str=tableOpen;
for (i=0;i<lines.length;i++){
	for (j=0;j<re.length-2;j++){
		detail=lines[i].match(re[j]);
		store[j]=detail[1];
		}
	str+=itemLine.replace("VAR:QUANTITY",store[0]).replace("VAR:LINK",match[3]+"?PRODREF="+store[1]+"&NOLOGIN=1").replace("VAR:TITLE",store[2]).replace("VAR:PRICE",match[1]+((store[3]*1).toFixed(2)));
	total+=(store[3]*1);
	}
if (match[5] > 0){
	str+=shippingLine.replace("VAR:SHIPPING",match[1]+(match[5]/100).toFixed(2));
	total=total+=(match[5]/100);
	}
if (match[4] > 0){
	str+=vatLine.replace("VAR:VAT",match[1]+(match[4]/100).toFixed(2));
	total=total+=(match[4]/100);
	}
gTotal=getCartItem(1);
var r=/&#(\d*);/gi;
var m=new Array();
var f=new Array();
while((m = r.exec(gTotal))!=null){
	f[f.length]=m[1];
	}
for (i=0;i<f.length;i++){
	gTotal=gTotal.replace("&#"+f[i]+";","");
	}
total=total.toFixed(2);
vatsum=(match[4]/100).toFixed(2)
gTotal=(gTotal/100).toFixed(2);
if (total>gTotal){
	str=str+=discountLine.replace("VAR:DISCOUNT","-"+match[1]+((total-gTotal)-(match[4]/100)).toFixed(2));
	}
else if (total<gTotal){
	str=str+=surchargeLine.replace("VAR:SURCHARGE",match[1]+(gTotal-total).toFixed(2));
	}
str+=totalLine.replace("VAR:TOTAL",match[1]+(gTotal));
str+=tableClose;
return str;
}


/* TOPNAV IMG SWAP *******************************************************/


function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
