
	function GetWidth()
	{
		var x = 0;
		if (self.innerHeight)
		{
			x = self.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
		{
			x = document.documentElement.clientWidth;
		}
		else if (document.body)
		{
			x = document.body.clientWidth;
		}
		return x;
	}
	function GetHeight()
	{
		var y = 0;
		if (self.innerHeight)
		{
			y = self.innerHeight;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
		{
			y = document.documentElement.clientHeight;
		}
		else if (document.body)
		{
			y = document.body.clientHeight;
		}
		return y;
	}
 
	function updateCartBox(cartsize){
		if(cartsize>0){
			if(cartsize>1){
				shows="s";
			}else{
				shows="";
			}
			$('cartsize').innerHTML=""+cartsize+" item"+shows+" in cart";
			$('cartbox').style.display="block";
		}else{
			$('cartbox').style.display="none";
		}
	}
	function addItemToCart(productid){
			showMessage("Adding item to cart","info");


			var url = 'buy-'+productid+'.htm';
			new Ajax.Request(url, {
				method: 'get',
				onSuccess:loginReturn,
				onFailure: ajaxError
			});
			function ajaxError(request) {
				showMessage('Ajax Error!',"alert");
			}
			function loginReturn(transport) {
				if(transport.responseText=="error-wrongbasket"){
					showMessage('Sorry, you must complete your order from this tiptop site before adding items from another tiptop site.',"warning");
				}else{
					showMessage("Your item was added to the cart. When finished shopping, click 'View Cart' to checkout.","info");
					updateCartBox(parseInt(transport.responseText));
				}
			}
	}
	function outofstock(){
			showMessage("Sorry this item is out of stock!","alert");
	}
	function getCart(){
			showMessage("Getting Cart","info");


			var url = 'ajax/getcart.htm?r='+Math.random();
			new Ajax.Request(url, {
				method: 'get',
				onSuccess:loginReturn,
				onFailure: ajaxError
			});
			function ajaxError(request) {
				showMessage('Ajax Error!',"alert");
			}
			function loginReturn(transport) {
				totalprice=0;
				totalvat=0;
				carttable1='<table>';
				transport.responseText.evalJSON().each( function(item, index){
					totalprice=totalprice+(item.price*item.quantity);
					itemvat=((item.price*item.quantity)/(100+parseInt(item.vatrate))*18);
					totalvat=totalvat+itemvat;						
					carttable1+='<tr><td style="width:290px;">'+item.name+' <a href="ajax/deleteitem-'+item.id+'"><img src="assets/img-design/delete.png" alt="delete" /></a></td><td style="width:100px;" class="align-right">'+item.quantity+'</td><td style="width:80px;" class="align-right">&euro;'+(item.price*1).toFixed(2)+'</td><td style="width:110px;" class="align-right">&euro;'+(item.price*item.quantity).toFixed(2)+'</td></tr>';
				});
				carttable1+='<tr><td colspan="4"><img src="assets/img-design/cart-table-divider.jpg" alt="_______"</td></tr>';
				carttable1+='<tr><td colspan="2">&nbsp;</td><td class="align-right"><img src="assets/img-design/cart-subtotal.jpg" alt="Subtotal"></td><td class="align-right">&euro;'+(totalprice-totalvat).toFixed(2)+'</td></tr>';
				carttable1+='<tr><td colspan="2">&nbsp;</td><td class="align-right"><img src="assets/img-design/cart-vat.jpg" alt="Subtotal"></td><td class="align-right">&euro;'+totalvat.toFixed(2)+'</td></tr>';
				carttable1+='<tr><td colspan="2">&nbsp;</td><td class="align-right"><img src="assets/img-design/cart-total.jpg" alt="Subtotal"></td><td class="align-right">&euro;'+totalprice.toFixed(2)+'</td></tr>';
				carttable1+='<tr><td colspan="4" class="align-right"><a href="ajax/emptycart"><img src="assets/img-design/cart-empty.jpg" alt="empty cart"></a> &nbsp; <a href="checkout.htm"><img src="assets/img-design/cart-checkout.jpg" alt="checkout"></a></td></tr>';
				carttable1+="</table>";
				
				$('carttable').innerHTML=carttable1;
				clearMessages();
			}
	}
	
	function showMessage(theMessage,type){
		var queue = Effect.Queues.get('global');
		queue.each(function(effect) { effect.cancel(); });

		$('messagebox-image').src="assets/img-design/messagebox-"+type+".png";
		$('messagebox').className='messagebox-'+type;
		$('messagebox-text').innerHTML=theMessage;
		$('messagebox').style.left=((GetWidth()-400)/2)+'px';
		$('messagebox').style.top=((GetHeight()-$('messagebox').style.height)/2)+'px';
		$('messagebox').appear({ duration: 0.5 });
		Element.hide.delay(3.5, "messagebox");
	}
	function clearMessages(){
		var queue = Effect.Queues.get('global');
		queue.each(function(effect) { effect.cancel(); });
		Element.hide("messagebox");
	}
	
	function searchfilter(type){
		$$(".searchresult").each(function(s){ $(s).style.display='none' });
		$$("."+type).each(function(s){ $(s).style.display='block' });
	}


	function clickSub(thediv){
	$$('.subs').each(function(name,value){
							  
		if(name.id==thediv){
			$(name.id).show();
		}else{
			$(name.id).hide();
		}
	});
	
}