basketNum = 0;
priceTot = 0.00;
inBasket = "";
basketArray = new Array();
order = "";
basketString = "";
LOGIN = "";
login = "";

exchangeRate = 1;
currencyCountry = 'UK';
currencyRate = 'UK';

loginArray = document.cookie.split(";");

for(j=0; j<loginArray.length; j++)
{
  if(loginArray[j].indexOf("DISC2") != -1)
  {
	 login = loginArray[j];
  }
}

if(login != "")
{
	fullArray = ((login.split("="))[1]).split("#");
	loginArray2 = new Array();
	placeInArray = 0;

	for(p=0; p<fullArray.length; p++)
	{
	  if(fullArray[p] != "")
	  {
	  LOGIN = fullArray[p];
	  //alert(fullArray[p]);
	  placeInArray++;
	  }
	}
}


function decPlace(price)
{
price += "";

pos = price.indexOf('.');

if(pos == -1)
{
price = price + ".00";
}
else
{

   price = price.split(".");
   pricebit = price[1].length;

   if(pricebit == 1)
   {
      price = price[0] + "." + price[1] + "0";
   }

}

return price;

}

function sortCash(cash)
{

if(currencyCountry == 'US')
{
cash = '&#36;' + ((parseFloat(cash))*(parseFloat(exchangeRate))).toFixed(2);
}

if(currencyCountry == 'UK')
{
cash = '&pound;' + cash;
}

if(currencyCountry == 'CAN')
{
cash = '&#36;' + ((parseFloat(cash))*(parseFloat(exchangeRate))).toFixed(2);
}

if(currencyCountry == 'AUS')
{
cash = '&#36;' + ((parseFloat(cash))*(parseFloat(exchangeRate))).toFixed(2);
}

if(currencyCountry == 'EU')
{
cash = '&#8364;' + ((parseFloat(cash))*(parseFloat(exchangeRate))).toFixed(2);
}

if(currencyCountry == 'JPN')
{
cash = '&#165;' + ((parseFloat(cash))*(parseFloat(exchangeRate))).toFixed(2);
}

return cash;
}

function pageJump(start,finish)
{
document.getElementById('startcount').value = start;
document.getElementById('finishcount').value = finish;
document.SEARCHFORM.submit();
}

function readCookie()
{

   if((document.cookie).indexOf("GENBASKET") != -1)
   {
       orderArray = document.cookie.split(";");

       for(j=0; j<orderArray.length; j++)
       {
		  if(orderArray[j].indexOf("GENBASKET") != -1)
		  {
		     order = orderArray[j];
		  }
       }

	for(j=0; j<orderArray.length; j++)
	{
	if(orderArray[j].indexOf("EXCHANGEAMOUNT") != -1)
	{
	exchangeRate = orderArray[j];
	}
	}

	exchangeArray = exchangeRate.split("=");
	for(e=0; e<exchangeArray.length; e++)
	{
	if(exchangeArray[e] != "")
	{
	exchangeRate = exchangeArray[e];
	}
	}
	
	for(j=0; j<orderArray.length; j++)
	{
	if(orderArray[j].indexOf("DISCCURRENCY") != -1)
	{
	currencyRate = orderArray[j];
	}
	}

	currencyArray = currencyRate.split("=");
	for(e=0; e<currencyArray.length; e++)
	{
	if(currencyArray[e] != "")
	{
	currencyCountry = currencyArray[e];
	}
        }
	
	


       fullArray = ((order.split("="))[1]).split("#");
       artArray = new Array();
       placeInArray = 0;

	   for(p=0; p<fullArray.length; p++)
	   {
	      if(fullArray[p] != "")
	      {
	      artArray[placeInArray] = fullArray[p];
	      placeInArray++;
	      }
	   }

	   for(k=0; k<artArray.length; k++)
	   {

	   basketArray[k] = artArray[k];


          if((artArray[k].split('/'))[0] != "")
          {
	      basketNum += parseInt((artArray[k].split('/'))[2]);
	      
	      priceTot = (parseFloat(priceTot) + ((parseFloat((artArray[k].split('/'))[1])))*(parseInt((artArray[k].split('/'))[2]))).toFixed(2);
	   
	      }

	      if((artArray[k].split('/'))[0] != "")
	      {
	      
if(LOGIN != 'CLIENT')
{
bagText = '<div class="checkout"><a href="sectionregister.php">CHECKOUT</a></div>';
}
else
{
bagText = '<div class="checkout"><a href="checkout1.php">CHECKOUT</a></div>';
}

bagText += '<div class="total"><p>TOTAL: <strong>' + sortCash(decPlace(priceTot)) + '</strong></p></div>';

bagText += '<div class="itemsincart"><a href="basket2.php">ITEMS IN CART: <strong>' + basketNum + '</strong></a></div>';
	      
	      }

	   }

        document.getElementById("cartinfo").innerHTML =  bagText;
        
      writeCookie();
      
   }
}
<!-- -->

function addToBasket(item,price)
{

   match = "false";
   newQuantity = "";
        
        quantity = 1
 
	for(i=0; i<basketArray.length; i++)
	{
	testProduct = (basketArray[i].split('/'))[0] + "/" + (basketArray[i].split('/'))[1];

	if(testProduct == (item + "/" + price))
	{
	match = "true";
	newQuantity = parseInt((basketArray[i].split('/'))[2]) + parseInt(quantity);
	basketArray[i] = item + "/" + price + "/" + newQuantity;
	}
	}

	if(match == "false")
	{
	basketArray[parseInt(basketArray.length)] = item + "/" + price + "/" + quantity;
	}
	
	//priceTot = parseInt(priceTot) + parseInt(price); 
	
	priceTot = (parseFloat(priceTot) + parseFloat(price)).toFixed(2);

	basketNum = basketNum + quantity;

if(LOGIN != 'CLIENT')
{
bagText = '<div class="checkout"><a href="sectionregister.php">CHECKOUT</a></div>';
}
else
{
bagText = '<div class="checkout"><a href="checkout1.php">CHECKOUT</a></div>';
}

bagText += '<div class="total"><p>TOTAL: <strong>' + sortCash(decPlace(priceTot)) + '</strong></p></div>';

bagText += '<div class="itemsincart"><a href="basket2.php">ITEMS IN CART: <strong>' + basketNum + '</strong></a></div>';

        document.getElementById("cartinfo").innerHTML =  bagText;

	alert("Item added to your basket.");

	writeCookie();

}


function writeCookie()
{
arrayContent = 0;

chocChipCookie = "GENBASKET=";
//chocChipCookie.Expires = DateTime.Now.AddMinutes(10000);

	for(i=0; i<basketArray.length; i++)
	{

	   if(basketArray[i] != "undefined")
	   {

          chocChipCookie += basketArray[i] + "#"
          arrayContent++;
	   }
	}
	
	chocChipCookie;

    if(arrayContent != 0)
    {
    document.cookie = chocChipCookie;
    }
    else
    {
    var kill_time = new Date("February 11, 1975");
    document.cookie = "GENBASKET=;expires=" + kill_time.toGMTString();

bagText = '<P>YOU HAVE <STRONG>0 ITEMS</STRONG><BR>IN YOUR BASKET</P>';
bagText += '<P>TOTAL: <STRONG>' + sortCash(0.00) + '</STRONG></P><A class="viewbasket href="basket2.php">VIEW BASKET &gt;&gt;</A>';

if(LOGIN != 'CLIENT')
{
bagText += '<a href="sectionregister.php" class="checkout">CHECKOUT &gt;&gt;</a>';
}
else
{
bagText += '<a href="checkout1.php" class="checkout">CHECKOUT &gt;&gt;</a>';
}

        document.getElementById("cartinfo").innerHTML =  bagText;

    }

}



