<!--// otus

    function presentValue(value) {
        if(value<=0.9999) {
            newPounds='0';
        } else {
            newPounds=parseInt(value);
        }
        dec='1';
        for (var i=1; i<=2;i++) {
            dec=dec+'0';
        }
        if (value>0) {
            newPence=Math.round((value+.000008 - newPounds)*(eval(dec)));
        } else {
            newPence=0;
        }
        compstring='9';
        for (var i=1; i <=2-1;i++) {
            if (eval(newPence) <= eval(compstring)) newPence='0'+newPence;
            compstring=compstring+'9';
        }
        if (2>0) {
            newString='£' + newPounds + '.' + newPence + '';
        } else {
            newString='£' + newPounds + '';
        }
        return (newString);
    }

function buyItem(newItem, newPrice, newTaxable, newURL, newSize, newColour, newQuantity) 
{
var cookieParm;

	if(newQuantity<=0) 
	{
            rc = alert('The quantity entered is incorrect');
        } 
	else 
	{
        	if (confirm('Add '+newQuantity+' x '+newItem+' to order? ')) 
		{
			cookieParm = GetCookie("otus");
 		
   			var expires = new Date();
 			cookieParm = cookieParm + '['+newItem+'|'+newPrice+'|'+newTaxable+'|'+newURL+'|'+newSize+'|'+newColour+'|'+newQuantity+']';
  			expires.setTime(expires.getTime() + 1);   // + 1 day
			SetCookie("otus", cookieParm, expires.toGMTString(), "");
//			WriteCookie ("otus", cookieParm, 5) 
		}
	}
}


function goBuy() 
{
var cookieParm;

	cookieParm = GetCookie("otus");

//	alert(cookieParm.length);

//	if (cookieParm.length == 4)
//		alert("Nothing");
//	else
//		alert(cookieParm);

        cookieParm =changeSpaces(cookieParm );

//	alert(cookieParm);
	
	if (cookieParm == "null")
		alert("Your basket is empty.  Please add the items you wish to purchase.");
	else
        	top.location='http://www.birdingimages.com/shop/buy.htm?items='+cookieParm ;
}

function changeSpaces(tstring) 
{
	nstring='';
        
	for (var i=0; i <= tstring.length; i++) 
	{
        	if (tstring.charAt(i)==' ') 
		{
			nstring=nstring+'^';
            	} 
		else 
		{ 
			nstring=nstring+tstring.charAt(i); 
		}
        }

        return nstring;
    }

function showBasket() 
{
var fulllist;

	fulllist= GetCookie("otus");

        totprice=0;
        document.writeln('<form name="basketform">');
        document.writeln('<table cols=6 border=0>');
        document.writeln('<tr><td align=left colspan=3><b><font size=-1>Product</font></b></td><td align=right><b><font size=-1>Quantity</font></b></td><td align=right><b><font size=-1>Cost Each</font></b></td><td align=right><b><font size=-1>Total Cost</font></b></td><td><b><font size=-1><center>Action</center></font></b></td></tr>');
        itemlist=0;
        for(var i=0; i<=fulllist.length;i++) {
            if(fulllist.substring(i,i+1)=='[') {
                itemstart=i+1;
                thisitem=1;
            }else if (fulllist.substring(i,i+1)==']') {
                itemend=i;
                thequantity=fulllist.substring(itemstart,itemend);
                itemtotal=0;
                itemtotal=(eval(theprice*thequantity));
                temptotal=itemtotal*100;
                totprice=totprice+itemtotal;
                itemlist=itemlist+1;
                document.writeln('<tr><td>'+field1+'&nbsp;</td><td>'+field8+'&nbsp;</td><td>'+field9+'&nbsp;</td><td align=right>&nbsp;<INPUT TYPE=TEXT NAME="quant'+itemlist+'" VALUE="'+thequantity+'" SIZE=3></td><td align=right>&nbsp;'+presentValue(eval(theprice))+'</td><td align=right>&nbsp;'+presentValue(itemtotal)+'</td><td><a href="javascript:removeItem('+itemlist+');"><img src="images/remove.jpg" border=0 alt="Remove"></a></td></tr>');
            } else if (fulllist.substring(i,i+1)=='|') {
                if (thisitem==1) field1 = fulllist.substring(itemstart,i);
                if (thisitem==2) theprice = fulllist.substring(itemstart,i);
                if (thisitem==3) field4 = fulllist.substring(itemstart,i);
                if (thisitem==4) theurl = fulllist.substring(itemstart,i);
                if (thisitem==5) field8 = fulllist.substring(itemstart,i);
                if (thisitem==6) field9 = fulllist.substring(itemstart,i);
                thisitem++;
                itemstart=i+1;
            }
        }
        document.writeln('<tr><td colspan=5><b>Total Goods</b></td><td align=right>&nbsp;'+presentValue(totprice)+'</td><td></td></tr>');
        document.writeln('</table>');
        document.writeln('<br><a href="javascript:clearBasket();"><img src="images/cancel-order-but.jpg" border=0 alt="Clear Basket"></a>');
        document.writeln('&nbsp;<a href="javascript:updateBasket();"><img src="images/update-order-but.jpg" border=0 alt="Update Basket"></a>');
        document.writeln('</form>');
    }

 function removeItem(itemno)
 {
	var fulllist;
	var newItemList;


        newItemList=null;
        itemlist=0;

	fulllist = GetCookie("otus");

        for(var i=0;i<=fulllist.length;i++) 
	{
        	if (fulllist.substring(i,i+1)=='[') 
		{
                	itemstart=i+1;
            	} 
		else if (fulllist.substring(i,i+1)==']') 
		{
                	itemend=i;
                	theitem = fulllist.substring(itemstart,itemend);
                	itemlist=itemlist+1;
                	if(itemlist != itemno) 
			{
                    		newItemList = newItemList+'['+fulllist.substring(itemstart,itemend)+']';
                	}
            	}
        }
  		
   	var expires = new Date();
 	expires.setTime(expires.getTime() + 1);   // + 1 day
 	SetCookie("otus", newItemList, expires.toGMTString(), "");
	self.location = "basket.htm";
}

function clearBasket() 
{
	if (confirm('Are you sure you wish to cancel your Order?')) 
	{
   		var expires = new Date();
 		expires.setTime(expires.getTime() + 1);   // + 1 day
 		SetCookie("otus", "", expires.toGMTString(), "");

            	self.location='basket.htm';
        }
}

function updateBasket() 
{
var fulllist;
var newItemList;

	newItemList=null;
	fulllist = GetCookie("otus");

        itemlist=0;
        for(var i=0;i<=fulllist.length; i++) 
	{
        	if(fulllist.substring(i,i+1)=='[') 
		{
                	thisitem=1;
                	itemstart=i+1;
                	fullstart=i+1;
            	} 
		else if(fulllist.substring(i,i+1)==']') 
		{
                	itemend=i;
                	itemlist++;
                	thiselement='quant'+itemlist;
                	newItemList=newItemList+'['+field1+'|'+field2+'|'+field3+'|'+field4+'|'+field5+'|'+field6+'|'+document.basketform.elements[thiselement].value+']';
            	} 
		else if(fulllist.substring(i,i+1)=='|') 
		{
                	if (thisitem==1) field1 = fulllist.substring(itemstart,i);
                	if (thisitem==2) field2 = fulllist.substring(itemstart,i);
                	if (thisitem==3) field3 = fulllist.substring(itemstart,i);
                	if (thisitem==4) field4 = fulllist.substring(itemstart,i);
                	if (thisitem==5) field5 = fulllist.substring(itemstart,i);
                	if (thisitem==6) field6 = fulllist.substring(itemstart,i);
                	thisitem++;
                	itemstart=i+1;
            	}
        }
        
	var expires = new Date();
 	expires.setTime(expires.getTime() + 1);   // + 1 day
 	SetCookie("otus", "", expires.toGMTString(), "");

        self.location='basket.htm';
}



function getCookieVal (offset) {  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
		endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name) 
{  
	var defString;
	defString = "A";
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) {    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}

	return defString;
}

function SetCookie (name, value, expiry, pathname) 
{  
	var strMsg;
	
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  

	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	
	var expiryDate = new Date();
	expiryDate.setTime(expiryDate.getTime() + (1000 * 24 * 60 * 60 * 5));   // 5 days

	document.cookie = name + "=" + escape (value) + 
		((expires == null) ? "" : ("; expires=" + expiryDate.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) +  
		((domain == null) ? "" : ("; domain=" + domain)) +    
		((secure == true) ? "; secure" : "");
}

//function WriteCookie (cookieName, cookieValue, expiry) 
//{
//var expDate = new Date();

//if(expiry)
//{
//expDate.setTime (expDate.getTime() + expiry);
 //   document.cookie = cookieName + "=" + escape (cookieValue) + "; expires=" + expDate.toGMTString();
//    }
//    else
//    {
//        document.cookie = cookieName + "=" + escape (cookieValue);
//	}
//}


//-->

