	function updateDelivery(info)
	{
		var el = document.getElementById('deliveryOptions');
		var id = el.selectedIndex;
		
		AJAX_FetchData('/shop/recalcDelivery.php?id='+id, changeDelivery);
	}




	function changeDelivery(http)
	{
		var txt_el = document.getElementById('basketSummary');
		
		txt_el.innerHTML =  http.responseText;
	
	} // changeDelivery()
	
	
	
	
		
	function loadRegistration(type)
	{
		var txt_el = document.getElementById('stage');
		txt_el.innerHTML =  "Register &gt; "+type;
		
		AJAX_FetchData('/site/loadRegistration.php?type='+type, changeRegContent);

	} // loadRegistration()



	function regThankYou(type)
	{
		var txt_el = document.getElementById('stage');
		txt_el.innerHTML =  "Register &gt; "+type+" &gt; Thank you";
		
		AJAX_FetchData('/site/loadRegThankYou.php?type='+type, changePageContentUM);

	} // regThankYou()

	
	
	function loadPageContent(sectionName, param1, param2)
	{
		if(param1 == '') param1=1;
		if(param2 == '') param2=1;
		AJAX_FetchData('/cms/'+sectionName+'.php?id='+param1+'&param2='+param2, changePageContent);

	} // loadPageContent()


	function changePageContent(http)
	{	
		var txt_el = document.getElementById('pageContent');
	
		txt_el.innerHTML =  http.responseText;
		
	} // changePageContent()



	function changeRegContent(http)
	{	
		var txt_el = document.getElementById('pageContent');
	
		txt_el.innerHTML =  http.responseText;
		prefsCollapse();
		
		
	} // changePageContent()
	



	function changePageContentUM(http)
	{	
		var txt_el = document.getElementById('pageContent');
	
		txt_el.innerHTML =  http.responseText;
		AJAX_FetchData('/site/updateTopMenu.php?id=1', updateTopMenu);
		
	} // changePageContentUM()


	function updateTopMenu(http)
	{
		var txt_el = document.getElementById('topMenu');
		txt_el.innerHTML =  http.responseText;
		
	} // updateTopMenu()



	
	function addFilter(pss, option)
	{
		AJAX_FetchData('/shop/addFilter.php?pss='+pss+'&option='+option, filterProducts);
		
	} // addFilter()
	
	
	function removeFilter(pss)
	{
		AJAX_FetchData('/shop/removeFilter.php?pss='+pss, filterProducts);
		
	} // addFilter()
	

	function clearFilters(cat)
	{	
	 	Cookie.set("accordOpenElement", 0, {duration: 3600});
		AJAX_FetchData('/shop/clearFilters.php?cat='+cat, filterProducts);
		
	} // clearFilter()
	
	
	
	function gotoPage(pageNo)
	{
		AJAX_FetchData('/shop/filteredProducts.php?page='+pageNo, showProducts);
		
	} // gotoPage()
	
	
	
	
	function gotoEventPage(pageNo)
	{
		AJAX_FetchData('/shop/filteredEvents.php?page='+pageNo, showProducts);
		
	} // gotoEventPage()
	
		
		
				
	function foodPage(pageNo)
	{
		AJAX_FetchData('/shop/foodProducts.php?page='+pageNo, showProducts2);
		
	} // foodPage()
	




	function filterProducts()
	{
		AJAX_FetchData('/shop/filteredProducts.php?page=1', showProducts);
		
	} // filterProducts()
	


	function searchFor(obj)
	{
		AJAX_FetchData('/shop/searchForProducts.php?phrase='+obj.value, showProducts);
		
	} // filterProducts()
	



	function showProducts(http)
	{
		var txt_el = document.getElementById('productList');
	
		txt_el.innerHTML =  http.responseText;
		AJAX_FetchData('/shop/leftMenu.php?id=1', updateMenus);
		//alert("menus");
	} // showProducts()




	function showEvents(http)
	{
		var txt_el = document.getElementById('producstList');
	
		txt_el.innerHTML =  http.responseText;
		AJAX_FetchData('/shop/leftMenu.php?id=1', updateMenus);
		//alert("menus");
		
	} // showEvenst()





	function showProducts2(http)
	{
		var txt_el = document.getElementById('productsList');
	
		txt_el.innerHTML =  http.responseText;
		AJAX_FetchData('/shop/leftMenu.php?id=1', updateMenus);
		
	} // showProducts()




	function updateMenus(http)
	{
		var txt_el = document.getElementById('menuContents');
	
		txt_el.style.display = 'none';
		txt_el.innerHTML =  http.responseText;
		reloadMenu();
		txt_el.style.display = 'block';
	} // updateMenus()






	function addToBasket(productID, type)
	{
		if(type == null) type = 1;
		var el = document.getElementById('qty'+productID);
		AJAX_FetchData('/shop/addToBasket.php?id='+productID+'&qty='+el.value+'&type='+type, added);	
				
	} // addToBasket()
	
	
	function added(http)
	{
		var data = http.responseText;
		var bits = data.split(":");
	
		var del = $('productsList').getElements('div[class=deliveryText]');
	
		for(var i=0; i < del.length; i++)
		{
			del[i].setHTML(bits[2]);
		}
		
	//alert("Updated "+del.length);
	
		var el = document.getElementById('cartDetails');
		el.innerHTML = bits[1];
		
		el = document.getElementById('addedDetails');
		el.innerHTML = bits[0];
	
	} // added()
	
	
	
	
	
	function showProductDetails(id, type)
	{
		if(type == null) type = 1;
		
		AJAX_FetchData('/shop/getProductDetails.php?id='+id+'&type='+type, updateDetails);	
	
	} // showProductDetails()




	function showEventDetails(id)
	{
		AJAX_FetchData('/shop/getEventDetails.php?id='+id, updateDetails);	
	
	} // showEventDetails()

	
	
	function showOffer(id)
	{
		AJAX_FetchData('/shop/getOfferDetails.php?id='+id, updateOfferDetails);	
	
	} // showProductDetails()
	
	
	
	function updateDetails(http)
	{
		var el = document.getElementById('details');
		el.innerHTML = http.responseText;
		showDetails('productDetails');
		
	} // updateDetails()
	
	
	
	function updateOfferDetails(http)
	{
		var el = document.getElementById('offer');
		el.innerHTML = http.responseText;
		showDetails('offerDetails');
		
	} // updateOfferDetails()
	
	

	function showDetails(element)
	{
		var el = document.getElementById(element);
		el.style.display = 'block';
		window.scroll(0,0);
		
	} // showDetails()
	
	
	function hideDetails(element)
	{
		var el = document.getElementById(element);
		el.style.display = 'none';
		
	} // hideDetails()
	
	
	
	
	function clearErrors()
	{
		errorBox = document.getElementById('errors');
		errorBox.innerHTML = "";
	
	} // clearErrors()
	


	function showErrors(errors)
	{
		errorBox = document.getElementById('errors');
		errorHTML = '<ul><label>Some required information is missing</label>';
		
		 for(var i=0; i < errors.length; i++)
		 {
		 	errorHTML = errorHTML + '<li>'+errors[i]+'</li>';
		 }
		 
		errorHTML = errorHTML + '</ul>'; 
		
		errorBox.innerHTML = errorHTML;
	
	} // showErrors()


	function noNumbers(sText)
	{
		var ValidChars = "0123456789";
  		var hasNoNumber=true;
   		var Char;

 
	   	for (i = 0; i < sText.length && hasNoNumber == true; i++) 
      	{ 
      		Char = sText.charAt(i); 
      		if (ValidChars.indexOf(Char) != -1) 
        	 {
         		return false;
         	}
      	}
   
   		return true;
		
	} // noNumbers()
	
	
	
	
	function validEmail(str) 
	{

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1)
		{
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		{
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		{
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1)
		 {
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		 {
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1)
		 {
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1)
		 {
		    return false;
		 }

 		 return true					
	
	} // validEmail()




	
	function validUserName(sText)
	{
		
		var ValidChars2 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  		var hasNoNumber2=true;
   		var Char2;

 
	   	for (i = 0; i < sText.length && hasNoNumber2 == true; i++) 
      	{ 
      		Char2 = sText.charAt(i); 
      		if (ValidChars2.indexOf(Char2) == -1) 
        	 {
         		return false;
         	}
      	}
   
   		return true;
		
		
		
	} // validUserName()

	
	
	
	
	function usernameExisits()
	{	
		var el = document.getElementById('username');
		var name = el.value;
		
		AJAX_FetchData('/site/usernameExists.php?name='+name, updateUsernameExisits);		
		
	} // userNameExists()
	
	
	
	function updateUsernameExisits(http)
	{
		var fel = document.getElementById('usernameExists');
		fel.value = null;
		
		
		var el = document.getElementById('unError');
		el.innerHTML = "";
		
		if(http.responseText == '1')
		{
			el.innerHTML = "username taken";
		}
					
		fel.value = http.responseText;
		
	} // userNameExists()
	
		
		
	function reloadMenu()
	{
			
		
		var openElement = Cookie.get("accordOpenElement");
		
 		
		if(openElement == 1) openElement = 2;
		var elOpen = openElement;
		var leftMenu = new Accordion('li.atStart', 'ul.atStart', {
		openAll: true, 
		opacity: false,
    	alwaysHide: false, 
    	show:openElement.toInt(),
	 	 onActive: function(toggler, element ){
 
	       
	       var openElId;
	       this.elements.each(function(el, i){
              if (el==element)
                  openElId = i;
         }),this;   
 
        Cookie.set("accordOpenElement", openElId, {duration: 3600});
        if (openElId == 5)
              elOpen = 0;
		
		toggler.setStyle('color', '#000000');

	  	},
		
	  	onBackground : function(toggler, element )
	  	{
	       var elementId;
	       element.getParent().getElements('dd').each(function(el, i){
              if (el == element)
                  elementId = i;
         }),this;
 
	       if ((elementId == 5) && (elOpen == 0)) 
		   {
	          Cookie.set("accordOpenElement", "", {duration: 3600});
         	}
         
		 if (elementId == 5)
		 {
              elOpen = 0;
		 }
		 
 		toggler.setStyle('color', '#713735');
    	}
		});
	


	} // reloadMenu()
	
	
	
	
	function expand(element)
	{
		$(element).setStyle('display', 'block');
		$('expand'+element).setStyle('display', 'none');
	} // expand()



	function shrink(element)
	{
		$(element).setStyle('display', 'none');
		$('expand'+element).setStyle('display', 'inline');
	} // expand()


		
	function startCollapse()
	{
		reloadMenu();
	}
	
	
	function prefsCollapse()
	{
		var accordion = new Accordion('label.atStart', 'div.atStart', {opacity: false, onActive: function(pref, prefChoices){pref.setStyle('color', '#7A1600'),pref.setStyle('background-image','url(arrowDown.gif)');},onBackground: function(pref, prefChoices){pref.setStyle('color','#888888' ); pref.setStyle('background-image','url(arrowUp.gif)');}, alwaysHide: true, display:-1}, $('optionalQuestions'));
	} // startCollapse()
	



	function loadRegions(countryID)
	{
		AJAX_FetchData('/site/loadRegions.php?country='+countryID, updateRegions);
	
	} // loadRegions
	
	
	
	
	function updateRegions(http)
	{
		var el = document.getElementById('regionList');
		
		el.innerHTML =  http.responseText;
	
	} // updateRegions()
	
	
	
	
	
	window.onload = startCollapse();