/***********************************************************************
*
* 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;
	}
	
/***********************************************************************
*
* win	- calls up the WUP window
*
* Input   - None
* Returns - None
************************************************************************/

function win()
	{
	var sMsg = window.open("paycash1.htm","","height = 507, width = 400, left = 378, top = 40");
	}

/***********************************************************************
*
* 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;
	}

/***********************************************************************
*
* getFullCart		-	fetches full cart content summary
*
*
* Returns:		-	HTML string for summary display
*
************************************************************************/

function getFullCart(){

var tableOpen="<table width='100%' style='font-size:9pt'>";
var itemLine="<tr><td valign='top'>VAR:QUANTITYx </td><td><div class='menuItemUl' onmouseover='this.className=\"menuItemHl\";' onmouseout='this.className=\"menuItemUl\";'><a class='menu' href='VAR:LINK' style='margin-left:0px'>VAR:TITLE...</a></div></td><td align='right' valign='top'>VAR:PRICE</td></tr>"

var shippingLine="<tr><td colspan='2'>Shipping</td><td align='right'>VAR:SHIPPING</td></tr>"
var vatLine="<tr><td colspan='2'>VAT</td><td align='right'>VAR:VAT</td></tr>"
var discountLine="<tr><td colspan='2'>Discounts</td><td align='right'>VAR:DISCOUNT</td></tr>"
var surchargeLine="<tr><td colspan='2'>Surcharges</td><td align='right'>VAR:SURCHARGE</td></tr>"
var totalLine="</table><table width='100%'><tr><td><b>Total</b></td><td align='right'><b>VAR:TOTAL</b></td></tr>"
var tableClose="</table>"
var emptyLine="<div style='text-align:center'>There are no items in your basket.</div>";

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);
gTotal=(gTotal/100).toFixed(2);
if (total>gTotal){
	str=str+=discountLine.replace("VAR:DISCOUNT","-"+match[1]+(total-gTotal).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;

if (getObj("lstClass")){
	window.level=(gTotal-match[4]/100-match[5]/100)*1.175*100;
	calcShipOffer();
	}
return str;
}

function couponLookup(){
codeBox=document.getElementById('couponcode');
codeImg=document.getElementById('couponValid');
if (!codeBox.value){
	codeImg.src="";
	codeImg.title="";
	codeImg.style.display="none";
	return;
	}
req=(window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Msxml2.XMLHTTP"));
if (req){
	req.onreadystatechange=function(){
	if (req.readyState==4){
		if (req.status==200){
			var response=eval('(' + req.responseText + ')');
			if (response.error){
				codeImg.src='http://www.diskdepot.co.uk/acatalog/couponInvalid.jpg';
				codeImg.title=response.error;
				codeImg.style.display="inline";
				}
			else{
				codeBox.value=response.coupon;
				codeImg.src='http://www.diskdepot.co.uk/acatalog/couponValid.jpg';
				codeImg.title='Coupon accepted';
				codeImg.style.display="inline";
				}
			}
		}
	};
	req.open("GET","http://www.diskdepot.co.uk/cgi-bin/coupon.pl?action=lookup&code="+codeBox.value,true);
	req.send("");
	}
else{
	// try an iframe
	alert("Error: XMLHttpRequest not supported");
	}
}

