<!--

//copyright e-Business Systems Limited - www.e-businesssystems.co.uk
// This script may not be used without written permission from e-Business Systems Limited.

//version 2 - 05/06/09

//Stephen Einhorn version




var basket = new Basket_control();


function Redisplay_basket(str)
{
	basket.Refresh_do(str);
}


function Redisplay_basket_error(str)
{
	//alert("error: - " + str);
}





//=======================================================


function Basket_control()
{
	
	this.lines = new Array();
	
	this.subtotal_ex = 0;
	this.discount = 0;
	this.online_discount = 0;
	this.volume_discount = 0;
	this.delivery = 0;
	this.vat = 0;
	this.total = 0;
	this.saved_basket_count = 0;
	this.currency_html = "&pound;";
	this.delimiter1 = "\\";
	this.delimiter2 = "|";
	this.basket_container_div = 'basket_rh_panel';
	
	/* functions:
	
	Add_line 
	Delete_line
	Redisplay_basket
	Clear_basket
	Refresh_request
	Refresh_do
	*/
}









//------------------------------------------------------

//used for adding basket line that already exists on the website database
Basket_control.prototype.Add_line = function (part_code, quantity, price_ex, description, image)
{
	this.lines.push(new Basket_line(part_code, quantity, price_ex, description, image));
}









//------------------------------------------------------
Basket_control.prototype.Delete_line = function (cost_list_index,  update_website)
{
	var k = this.lines[cost_list_index];
	
	if (update_website)
	{
		var d = new Date();
		var t = d.getTime();
		
		ajax.Make_request("doGet",pricing_delete_error, cost_list_index, 'job_processing_update_pricing.asp?cost_item_id=' + k.cost_item_id + '&pricing_form_action=delete' + '&cost_job_no=' + this.job_no + '&cost_random_id=' + k.cost_random_id + '&t=' + t,formData2QueryString(Gebid('pricing_form')),pricing_delete_response);
	
	}
	
	this.lines[cost_list_index] = null;
	
}






	
	



//------------------------------------------------------
Basket_control.prototype.Clear_basket = function ()
{
	this.lines.length = 0;
	
	this.subtotal_ex = 0;
	this.discount = 0;
	this.online_discount = 0;
	this.volume_discount = 0;
	this.delivery = 0;
	this.vat = 0;
	this.total = 0;
	this.saved_basket_count = 0;
	
}









//------------------------------------------------------
Basket_control.prototype.Refresh_request = function ()
{
	var d = new Date();
	var t = d.getTime();
	ajax.Make_request("doGet",Redisplay_basket_error, 0, 'retrieve_basket.asp?t=' + t,"",Redisplay_basket);
	
}










//------------------------------------------------------
Basket_control.prototype.Refresh_do = function (str)
{
	
	var i,j,k;
	var input = str.split(this.delimiter1);
	
	this.Clear_basket();
	
	for (i = 0; i < input.length; i++)
	{
		var field = input[i].split(this.delimiter2);
		if (field[0] == "totals")
		{
			this.subtotal_ex = field[1];
			
		}
		
		if (field[0] == "line")
		{
			this.Add_line(field[1],field[2],field[3],field[4],field[5])
		}
		
		
		
		if (field[0] == "saved_basket_count")
		{
			try
			{
				this.saved_basket_count = parseInt(field[1]);
			}
			catch( e )
			{
				this.saved_basket_count = 0;
			}
		}
		
		
		if (field[0] == "end")
		{
			//alert("end");
		}
		
		
	}
	
	
	this.Redisplay_basket(this.basket_container_div);
}













//------------------------------------------------------
Basket_control.prototype.Redisplay_basket = function (target_div_id)
{
	var basket_html = "";
	var i,j,k;
	var total = 0;
	var basket_line_view_modify_page = "javascript:alert('Coming soon');";
	
	
	if (this.lines.length == 0)
	{
		basket_html = "";
		basket_html += '<div class="basket_empty">Your basket is empty</div>';
	
	}
	
	else
	{
		
		
		
		//basket lines
		for (i = 0; i < this.lines.length; i++)
		{
			if (this.lines[i])
			{
				
				k = this.lines[i];
				
				if (k.quantity > 0)
				{
				
					basket_html += '<div class="basket_item">';
	
					
					//################### modify commented out temp ##########################
					if (k.image.length > 0)
					{
						
						basket_html += '<a href="' + basket_line_view_modify_page + '">';
						basket_html += '<img border="0" src="product_images/small_images/';
						basket_html += k.image;
						basket_html += '" alt="' + k.description;
						basket_html += '. Click to modify.';
						basket_html += '"  title="' + k.description;
						basket_html += '. Click to modify.';
						basket_html +=  '">';
						basket_html +=  '</a>';
						
						/*
						basket_html += '<a href="' + basket_line_view_modify_page + '"><img border="0" src="product_images/small_images/';
						basket_html += k.image;
						basket_html += '" alt="' + k.description + '. Click to modify."  title="' + k.description + '. Click to modify."></a>';
						*/
					}		
							
					basket_html += '<div class="basket_item_text">';
					//basket_html += '<p class="modify"><a href="' + basket_line_view_modify_page + '">View/modify</a></p>';	////################### commented out temp ##########################
					basket_html += '<p class="qty">Qty: <span>' + k.quantity + '</span></p>';
					basket_html += '<p class="price">' + k.price_ex;
					
					if (parseInt(k.quantity > 1))
					{
						basket_html += ' each';
					}
					
					basket_html += '</span></p>';
					basket_html += '</div></div>';
				}
			}
		}	
			
			
		
		
		//basket totals	
			
			
		
		basket_html += '<div id="basket_rh_totals">';
		basket_html += '<p class="subtotal">Subtotal: <span>' + this.subtotal_ex + '</span></p>';
		basket_html += '<p class="save"><a href="save_basket.asp" title="Click to save your current basket for a later date" id="save_basket_for_later_link">Save basket for later</a></p>';
		basket_html += '</div>';
		basket_html += '<div id="basket_rh_checkout_button">';
		basket_html += '<a href="view_basket.asp"><img border="0" src="images/style/go_to_checkout_button.gif" alt="Go to checkout" title="Click to go to the checkout"></a>';
		basket_html += '</div>';
		
		
		
		
		
		
						   
				
		//retrieve saved baskets
		
		if (this.saved_basket_count > 0)
		{
			basket_html += '<p class="save" id="view_saved_basket_link"><a href="view_saved_baskets.asp" title="Click to view the basket(s) you have previously saved">View saved basket';
			
			if (this.saved_basket_count > 1)
			{
				basket_html += 's';
			}
			
		}
		
	}
	
	
	
	
	
	//apply update
	Gebid(target_div_id).innerHTML = basket_html;
	
	
}







//=======================================================
						
function Basket_line(part_code, quantity, price_ex, description, image)
{
	
	this.part_code = part_code;
	this.quantity = quantity;
	this.price_ex = price_ex;
	this.description = description;
	this.image = image;
	
	/* functions:
	
	*/
}










//------------------------------------------------------






//-->