function product(code,description,weight,price1,price2,price3,price4,price5){
	this.code = code;
	this.description = description;
	this.weight = weight;
	this.price1 = price1;
	this.price2 = price2;
	this.price3 = price3;
	this.price4 = price4;
	this.price5 = price5;
}

products = new Object();

products[0] = new product("0101",   "I2C Bus Monitor and SDK for Windows",   "150",     "150.00",   "135.00",   "120.00",   "100.00",   "75.00"  );
products[1] = new product("0102",   "I2C Bus Tool and SDK for Windows",      "150",     "250.00",   "225.00",   "200.00",   "175.00",   "150.00" );

products[2] = new product("0110",   "USB Adaptor",                           "150",     "25.00",    "22.50",    "20.00",    "17.50",    "15.00"  );
    
products[3] = new product("0120",   "I2C Interface and SDK for Windows",     "125",     "75.00",    "70.00",    "62.50",    "50.00",    "40.00" );
products[4] = new product("0121",   "I2C Standard and SDK for Windows",      "125",     "150.00",   "135.00",   "120.00",   "100.00",   "75.00" );
products[5] = new product("0122",   "I2C Professional and SDK for Windows",  "125",     "100.00",   "80.00",    "70.00",    "60.00",   "50.00");

products[6] = new product("0130",   "I2C Interface UPGRADE to Standard",     "50",      "100.00",   "80.00",    "70.00",    "60.00",    "50.00");
products[7] = new product("0131",   "I2C Interface UPGRADE to Professional", "50",      "200.00",   "175.00",   "150.00",   "125.00",   "115.00");
products[8] = new product("0132",   "I2C Standard UPGRADE to Professional",  "50",      "125.00",   "115.00",   "100.00",   "90.00",    "80.00");

products[9] = new product("0201",    "Control-L SDK including Serial Cable",   "50",     "150.00",   "150.00",   "150.00",   "150.00",   "150.00" );
products[10] = new product("0202",   "Control-L Serial Cable",                "50",     "50.00",    "45.00",    "40.00",    "35.00",    "25.00"  );
products[11] = new product("0203",   "LANC to MIDI Timecode Generator",       "50",     "75.00",    "67.50",    "60.00",    "55.00",    "50.00"  );
products[12] = new product("0204",   "Control-L SDK including USB Cable",     "50",     "150.00",   "150.00",   "150.00",   "150.00",   "150.00" );
products[13] = new product("0205",   "Control-L USB Cable",                   "50",     "60.00",    "55.00",    "50.00",    "45.00",    "35.00"  );
    
products[14] = new product("0211",   "Control-M SDK including Cable",         "150",     "150.00",   "150.00",   "150.00",   "150.00",   "150.00" );
products[15] = new product("0212",   "Control-M Cable",                       "150",     "50.00",    "45.00",    "40.00",    "35.00",    "25.00"  );
products[16] = new product("0213",   "Control-M to MIDI Timecode Generator",  "150",     "75.00",    "67.50",    "60.00",    "55.00",    "50.00"  );
    
products[17] = new product("0301",   "RS232 to TTL Cable (Low speed)",        "100",     " 40.00",   "36.00",    "32.00",    "27.50",    "25.00"  );
products[18] = new product("0302",   "RS232 to TTL Cable (High speed)",       "100",     " 40.00",   "36.00",    "32.00",    "27.50",    "25.00"  );
products[19] = new product("0303",   "RS232 to TTL Cable",                    "100",     " 40.00",   "36.00",    "32.00",    "27.50",    "25.00"  );
products[20] = new product("0311",   "USB to TTL Cable",                      "45",      " 16.00",   "15.00",    "14.00",    "12.00",    "11.00"  );
products[21] = new product("0312",   "USB to TTL Cable - OEM",     			  "45",      " 12.50",   "11.00",    "10.00",    "9.00",     "7.50"  ); 
products[22] = new product("0313",   "USB to TTL Cable - GALVANIC",			  "45",      " 15.00",   "13.75",    "12.50",    "11.00",    "10.00"  ); 
       
products[23] = new product("0320",   "FTDI USB to TTL Cable - 5v BLACK",       "70",      " 12.50",   "11.00",    "10.00",    "9.00",     "7.50"  ); 
products[24] = new product("0321",   "FTDI USB to TTL Cable - 5v TRANSPARENT", "70",      " 12.50",   "11.00",    "10.00",    "9.00",     "7.50"  ); 
products[25] = new product("0322",   "FTDI USB to TTL Cable - 3v3 BLACK",     "70",      " 12.50",   "11.00",    "10.00",    "9.00",     "7.50"  ); 
products[26] = new product("0323",   "FTDI USB to TTL Cable - 3v3 TRANSPARENT","70",      " 12.50",   "11.00",    "10.00",    "9.00",     "7.50"  ); 

products[27] = new product("0401",   "USB to I2S Audio Interface",            "125",     "60.00",    "57.50",    "55.00",    "52.50",    "50.00" );

products[28] = new product("0206",   "Control-L USB TimeLapse Cable",         "110",     "110.00",   "110.00",   "110.00",   "110.00",   "110.00" );



//Old Function to be removed
function addToCart(BuyCode, BuyDescription, BuyQty, BuyPrice, NoRefresh) {
 	addItemToCart(BuyCode,BuyQty,NoRefresh);
}     

function addItemToCart(BuyCode, BuyQty, NoRefresh) {
 	var vscount = 0;
 	var BuyPrice = null;
 	var BuyDescription = null;

	x = 0;
 	pPrice = 0;

	//General Information before item is added to cart.
	//alert("AVIT Research Ltd is on Summer Shutdown from 25th to 29th July 2011\nOrders will not be processed until 1st August 2011\nSorry for any inconvenience this may cause");


    if (isNaN(BuyQty)){
        alert(BuyQty+" is not a valid Quantity.");
        return;
    }
    if(BuyQty <= 0){
        alert("You must order at least one of this item.");
        return;
    }

    if(BuyCode == "0311"){
		input_box = confirm("Unless you are buying this product for legacy reasons, we would really recommend you save money any buy the OEM version.\n\nClick OK to Change to OEM Version or CANCEL to continue");
		if(input_box == true)
		{
			BuyCode = "0312";
			alert("Product Changed to OEM version");
		}
    }
	//if(BuyCode == "0312"){
	//	alert("USB to TTL OEM Cables are currently out of stock\nNew batch due 28th November\nSorry for any inconvenience this may cause");
	//}



    //ADV seek through the cart and looking to see if item exists...
    cartdata = new String(GetCookie('Cart'));
 
    ItemNotFound = 1; 
	CartList = null;
	listcount = 0;
 	for (var i = 0; i <= cartdata.length; i++) {
  		if (cartdata.substring(i,i+1) == '[') {
  			listbegin = i+1;
  			itembegin = listbegin;
  		} 
        else if (cartdata.substring(i,i+1) == ']') {
  		    vscount = 0;
  		    listfinish = i;
            if(Code == BuyCode)
            {
                ItemNotFound = 0; 
                total = 0;
                total = eval(Qty) + eval(BuyQty);

                BuyPrice = GetQuantityPrice(BuyCode, total);
                BuyDescription = GetDescription(BuyCode);
        
                if(CartList == null)
                {
                    CartList = "["+BuyCode+"#"+BuyDescription+"#"+total+"#"+BuyPrice+"#]";
                }
                else
                {
                    CartList = CartList+"["+BuyCode+"#"+BuyDescription+"#"+total+"#"+BuyPrice+"#]";
                }
            }
            else
            {
                if(CartList == null)
                {
                    CartList = '['+cartdata.substring(listbegin, listfinish)+']';
                }
                else
                {
                    CartList = CartList+'['+cartdata.substring(listbegin, listfinish)+']';
                }
            }
  		}
        else if (cartdata.substring(i,i+1) == '#') {
  			vscount = vscount + 1;
            if (vscount == 1) {Code = cartdata.substring(itembegin, i);}
            if (vscount == 2) {Description = cartdata.substring(itembegin, i);}
            if (vscount == 3) {Qty = cartdata.substring(itembegin, i);}   
            if (vscount == 4) {Price = cartdata.substring(itembegin, i);}
            itembegin= i+1;
        }
    }
    
    
    if(ItemNotFound)
    {
        BuyPrice = GetQuantityPrice(BuyCode, BuyQty);
        BuyDescription = GetDescription(BuyCode);
        if (cartdata == 'null')
        {
            CartList = "["+BuyCode+"#"+BuyDescription+"#"+BuyQty+"#"+BuyPrice+"#]";
        }
     	else{
            CartList = cartdata+"["+BuyCode+"#"+BuyDescription+"#"+BuyQty+"#"+BuyPrice+"#]";
     	}
    }    
    
    SetCookie('Cart',CartList);
	if (!NoRefresh){
    	location = "shoppingbasket.htm";
   	}
}


function GetQuantityPrice(BuyCode, BuyQty)
{
    var Price = null;
       
    for(i in products)
    {
        if(products[i].code == BuyCode)
        {
		    if(BuyQty < 5)
		        Price = products[i].price1;
		    else if (BuyQty < 10)        
				Price = products[i].price2;
			else if (BuyQty < 50)        
		        Price = products[i].price3;
		    else if (BuyQty < 100)        
		        Price = products[i].price4;
		    else
		        Price = products[i].price5;
        }
    }
    return Price;
}

function GetWeight(BuyCode, BuyQty)
{
    var Weight = null;
       
    for(i in products)
    {
        if(products[i].code == BuyCode)
        {
			Weight = products[i].weight * BuyQty;
			//Add in CD and Jiffy
			Weight += 40;
        }
    }
    return Weight;
}


function GetDescription(BuyCode)
{
    var i;
    var Description = null;
    
    for(i in products)
    {
        if(products[i].code	== BuyCode)
        {
            Description = products[i].description;
        }
    }
    return Description;
}

