// JavaScript Document
function GetXmlHttpObject() {
    var xmlHttp = null;
    try {
        xmlHttp = new XMLHttpRequest();
    } catch(e) {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }
    return xmlHttp;
}

loadingState = 0;

function ajaxStateChanged(obj, fadeTarget, loadingData) {
	var loadingObj = window.document.getElementById(obj);
	if(loadingObj){
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
			if(fadeTarget){
				$(function() {
					// fadeTo used instead of fadeOut as there were some conflicts with the cart forms
					$("#"+fadeTarget).fadeTo("slow", 0, function() {
						$("#"+fadeTarget).hide();
						window.document.getElementById(obj).innerHTML = xmlHttp.responseText; // SET NEW TEXT
						$("#"+obj).css('opacity', 1);
						$("#"+obj).fadeIn();
					} );
					setTimeout('$("#'+obj+'").fadeOut("slow", function() { $("#'+fadeTarget+'").show(); $("#'+fadeTarget+'").fadeTo("slow", 1); } );', 3000);
				});
				return;
			}
			window.document.getElementById(obj).innerHTML = xmlHttp.responseText; // SET NEW TEXT
		} else if(loadingData && (loadingState == 0)){
			loadingState = 1;
			if(loadingObj) loadingObj.innerHTML = loadingData;
		}
	}
	return;
}

function linkTo(url){
	window.top.location.href = url;
	return;
}

function product_purchase(obj, mode){
	loadingState = 0;
	var formParent = obj;
	var overlay = formParent.name+'_overlay';
	var input = new Array();
	var inputs = formParent.getElementsByTagName('input');
	var count = inputs.length;
	for(var i = 0; i < count; i++){
		input[inputs[i].name] = inputs[i].value;
	}
	var id = input['id'];
	var qty = (parseInt(input['qty']) > 0) ? input['qty'] : 1;
	
	var url = './includes/ajax_addProduct.inc.php?id='+id+'&qty='+qty+'&mode='+mode;
	//AJAX
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support AJAX - Please update");
        return false;
    }
	xmlHttp.onreadystatechange = function() {
        ajaxStateChanged(overlay, String(obj.name));
    };
	setTimeout("updateCartStatus();", 2000);
	xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
	return false; // STOP FORM SUBMITTING
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function validate(elements){
	var error = false;
	var count = elements.length;
	
	for(var i = 0; i < count; i++){
		var obj = window.document.getElementById(elements[i]);
		if(obj){
			var er_block = String(obj.name) + '_error';
			if(trim(obj.value) == ''){
				obj.value = '';
				if(!error) obj.focus();
				window.document.getElementById(er_block).style.display = 'inline';
				error = true;
			}else{
				var param_block = er_block+'_param';
				var param_div = window.document.getElementById(param_block);
				if(param_div){
					var param = param_div.title;
					param = param.split('_');
					var param_length = param.length;
					var param_type = param[0];
					var param_value = param[1];
					if(param_length > 2){ // ALLOW PARAM VALUE TO HAVE UNDERSCORES
						for(var x = 2; x < param_length; x++){
							param_value = param_value+'_'+param[x];
						}
					}
					switch(param_type){
						case 'LEN':
							if(trim(obj.value).length < param_value){
								if(!error) obj.focus();
								error = true;
								window.document.getElementById(er_block).style.display = 'inline';
								continue;
							}
						break;
						case 'SAME':
							var orig = window.document.getElementById(param_value);
							if(orig){
								if(trim(obj.value) != trim(orig.value)){
									if(!error) obj.focus();
									error = true;
									window.document.getElementById(er_block).style.display = 'inline';
									continue;
								}
							}
						break;
						case 'EMAIL':
							var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@((([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})|(localhost))+$/;
							str = trim(obj.value);
							if(!str.match(emailRegEx)){
								if(!error) obj.focus();
								error = true;
								window.document.getElementById(er_block).style.display = 'inline';
								continue;
							}
						break;
						case 'CHECKBOX':
							if(obj.value == param_value){
								if(!obj.checked){
									if(!error) obj.focus();
									error = true;
									window.document.getElementById(er_block).style.display = 'inline';
									continue;
								}
							}
						break;
					}
				}
				window.document.getElementById(er_block).style.display = 'none';
			}
		}
	}
	if(!error) return true;
	return false;
}

function reg_validate(page){
	if(page==1){
		var elements = new Array('fname_txt','sname_txt','email_txt','pwd1_txt','pwd2_txt','dtel_txt','dadd1_txt','dadd2_txt','dadd3_txt','dcounty_txt','dpcode_txt','tandcs_chk');
	}else if(page==2){
		//var elements = new Array('add1_txt','add2_txt','add3_txt','county_txt','pcode_txt');
	}
	return validate(elements);
}

function reg_sameAddress(){
	var add1 = window.document.getElementById('add1_txt');
	var add2 = window.document.getElementById('add2_txt');
	var add3 = window.document.getElementById('add3_txt');
	var town = window.document.getElementById('town_txt');
	var county = window.document.getElementById('county_txt');
	var pcode = window.document.getElementById('pcode_txt');
	if(add1){
		add1.value = window.document.getElementById('dadd1_txt').value;
	}
	if(add2){
		add2.value = window.document.getElementById('dadd2_txt').value;
	}
	if(add3){
		add3.value = window.document.getElementById('dadd3_txt').value;
	}
	if(town){
		town.value = window.document.getElementById('dtown_txt').value;
	}
	if(county){
		county.value = window.document.getElementById('dcounty_txt').value;
	}
	if(pcode){
		pcode.value = window.document.getElementById('dpcode_txt').value;
	}
	return false;
}

function chkout_validate(page){
	var elements = false;
	if(page==2){
		var timetable = window.document.getElementById('ddatetime_selected');
		if(timetable){
			if(timetable.value == ''){
				window.alert('Please select a delivery date from the timetable.');
				return false;
			}
		}else{
			window.alert('Please select a delivery date from the timetable.');
			return false;
		}
		var elements = new Array('dname_txt','dadd1_txt','dadd2_txt','dadd3_txt','dcounty_txt','dpcode_txt');
	}else if(page==3){
		var elements = new Array('add1_txt','add2_txt','add3_txt','tel_txt','county_txt','pcode_txt');
	}else if(page==4){
		var cod = window.document.getElementById('cod_opt');
		if(cod){
			if(cod.value=='No') var elements = new Array('cname_txt','cnum_txt','cexpDate_txt','cv2_txt');
		}else{
			var elements = new Array('cname_txt','cnum_txt','cexpDate_txt','cv2_txt');
		}
	}
	if(!elements) return true;
	return validate(elements);
}

function showHideCardOpts(obj){
	var target = window.document.getElementById('checkout_cardDetails');
	if(!target) return false;
	if(obj.value=='No'){
		target.style.display = 'block';
	}else{
		target.style.display = 'none';
	}
	return false;
}

function showHideIssueNum(obj){
	var target = window.document.getElementById('CARDISSUE');
	if(!target) return false;
	if(obj.value=='SWITCH'){
		target.style.display = 'block';
	}else{
		target.style.display = 'none';
	}
	return false;
}

function newsl_validate(){
	var elements = new Array('fname_txt','email_txt');
	return validate(elements);
}

function refer_validate(){
	var elements = new Array('fname_txt','sname_txt','email_txt');
	return validate(elements);
}

function account_validate(){
	var elements = new Array('fname_txt','sname_txt','dadd1_txt','dadd2_txt','dadd3_txt','tel_txt','email_txt');
	return validate(elements);
}

function contact_validate(){
	var elements = new Array('name_txt','email_txt','comments_txt');
	return validate(elements);
}

function paginate(page, action, query, param){
	loadingState = 0;
	switch(action){
		case 'next':
			page++;
		break;
		case 'prev':
			page--;
		break;
		case 'first':
			page = 1;
		break;
	}
	var target = 'ajax_productTable';
	
	var query = query + '&p=' + page + '&param='+param;
	
	var loadingData = '<p>&nbsp;</p><p><img src="./images/ajax-loader.gif" border="0" alt="Loading..." class="left" /><div class="left noBold">&nbsp;&nbsp;&nbsp;Loading items... Please wait</div></p>';
	
	var url = './includes/ajax_paginate.inc.php?page='+page+'&q='+query;
	
	//AJAX
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support AJAX - Please update");
        return false;
    }
	xmlHttp.onreadystatechange = function() {
        ajaxStateChanged(target, false, loadingData);
    };
	xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
	return false; // STOP FORM SUBMITTING
}

function updateCartStatus(){
	var target = 'minicart_stats';
	var url = './includes/ajax_setMiniCart.inc.php';
	
	//AJAX
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support AJAX - Please update");
        return false;
    }
	xmlHttp.onreadystatechange = function() {
        ajaxStateChanged(target);
    };
	xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
	return;
}

function ajax_quickSearchPredictive(obj){
	if(obj.value.length < 3){
		window.document.getElementById('predictive_container').innerHTML = '';
		return false;
	}
	if(!obj.getAttribute("automplete")) obj.setAttribute("autocomplete", "off");
	var url = './includes/ajax_predictive.inc.php?q='+obj.value;
	//AJAX
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support AJAX - Please update");
        return false;
    }
	xmlHttp.onreadystatechange = function() {
        ajaxStateChanged('predictive_container');
    };
	xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
	return false;
}

$("#predictive_container").bind("mouseenter",function(){
  $("#predictive_container").bind("mouseleave",function(){
      window.document.getElementById('predictive_container').innerHTML = '';
    });
});

function addToFavouties(id, target){
	var url = './includes/ajax_favourites.inc.php?id='+id+'&target='+target;
	//AJAX
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support AJAX - Please update");
        return false;
    }
	xmlHttp.onreadystatechange = function() {
        ajaxStateChanged(target);
    };
	xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
	return false;
}

function removeFromFavouties(id, target, mode){
	if(!mode) mode = 'remove';
	var url = './includes/ajax_favourites.inc.php?id='+id+'&mode='+mode+'&target='+target;
	//AJAX
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support AJAX - Please update");
        return false;
    }
	xmlHttp.onreadystatechange = function() {
		ajaxStateChanged(target);
		if(mode=='removefav'){
			if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
				var ar = target.split('_');
				var rowtarget = 'prRow_'+ar[1];
				window.document.getElementById(rowtarget).style.display = 'none';
			}
		}
    };
	xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
	return false;
}

function helpCategory(id){
	var target = 'helpItem_'+id;
	var ul = window.document.getElementById(target);
	if(ul){
		if(ul.style.display == 'inline'){
			ul.style.display = 'none';
		}else{
			ul.style.display = 'inline';
		}
	}
	return false;
}

function loadHelp(id){
	var target = 'helpContent';
	var url = './includes/ajax_help.inc.php?id='+id;
	//AJAX
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support AJAX - Please update");
        return false;
    }
	xmlHttp.onreadystatechange = function() {
        ajaxStateChanged(target);
    };
	xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
	return false;
}

function fruitCategory(id){
	var target = 'fruitItem_'+id;
	var ul = window.document.getElementById(target);
	if(ul){
		if(ul.style.display == 'inline'){
			ul.style.display = 'none';
		}else{
			ul.style.display = 'inline';
		}
	}
	return false;
}

function loadFruit(id){
	var target = 'fruitContent';
	var url = './includes/ajax_fruit.inc.php?id='+id;
	//AJAX
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support AJAX - Please update");
        return false;
    }
	xmlHttp.onreadystatechange = function() {
        ajaxStateChanged(target);
    };
	xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
	return false;
}

function changeCurrency(obj){
	var value = obj.value;
	var url = './includes/ajax_currency.inc.php?mode='+value;
	//AJAX
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support AJAX - Please update");
        return false;
    }
	xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
	var container = window.document.getElementById('ajax_productTable');
	if(container){
		var spans = container.getElementsByTagName('span');
		var len = spans.length;
		var hidename = 'eurprice_span';
		if(value=='EUR') hidename = 'gbpprice_span';
		for(var i = 0; i < len; i++){
			if(spans[i].className == hidename){
				spans[i].style.display = 'none';
			}else{
				spans[i].style.display = 'inline';
			}
		}
	}
	var container = window.document.getElementById('specialOffers_panel');
	if(container){
		var spans = container.getElementsByTagName('span');
		var len = spans.length;
		var hidename = 'eurprice_span';
		if(value=='EUR') hidename = 'gbpprice_span';
		for(var i = 0; i < len; i++){
			if(spans[i].className == hidename){
				spans[i].style.display = 'none';
			}else{
				spans[i].style.display = 'inline';
			}
		}
	}
	var container = window.document.getElementById('ajax_productTable_alt');
	if(container){
		var spans = container.getElementsByTagName('span');
		var len = spans.length;
		var hidename = 'eurprice_span';
		if(value=='EUR') hidename = 'gbpprice_span';
		for(var i = 0; i < len; i++){
			if(spans[i].className == hidename){
				spans[i].style.display = 'none';
			}else{
				spans[i].style.display = 'inline';
			}
		}
	}
	updateCartStatus();
	return false;
}

function recipeHop(letter, cat, obj){
	var target = 'recipeTable_'+letter;
	var parenttarget = 'recipes_list_'+cat;
	var container = window.document.getElementById(parenttarget);
	var divs = container.getElementsByTagName('div');
	var len = divs.length;
	for(var i = 0; i < len; i++){
		if(divs[i].id.indexOf('recipeTable_')==-1) continue;
		if(divs[i].id == target) divs[i].style.display = 'inline';
		else divs[i].style.display = 'none';
	}
	//CHANGE ACTIVE STATES
	var container = window.document.getElementById('alpha_container');
	var alphas = container.getElementsByTagName('a');
	var len = alphas.length;
	for(var i = 0; i < len; i++){
		if(alphas[i].className.indexOf(' active')!=-1){
			var cname = alphas[i].className.split(' active');
			alphas[i].className = cname[0];
			break;
		}
	}
	//CHANGE CURRENT TO ACTIVE STATE
	obj.className = obj.className + ' active';
	return false;
}

function recipeCatHop(obj){
	//HIDE ALL
	var parent = window.document.getElementById('recipe_cat_container');
	if(parent){
		var divs = parent.getElementsByTagName('div');
		var len = divs.length;
		for(var i = 0; i < len; i++){
			if(divs[i].id.indexOf('recipes_list_')==-1) continue;
			if((divs[i].className == 'hide') && divs[i].style.display == 'inline'){
				divs[i].style.display = 'none';
				break;
			}
		}
	}
	//SHOW ACTIVE
	var value = obj.value;
	var target = 'recipes_list_'+value;
	var activeObject = window.document.getElementById(target);
	if(activeObject){
		activeObject.style.display = 'inline';
	}
	return false;
}

function chkout_summary(){
	var dname = window.document.getElementById('dname_txt');
	var dadd1 = window.document.getElementById('dadd1_txt');
	var dadd2 = window.document.getElementById('dadd2_txt');
	var dadd3 = window.document.getElementById('dadd3_txt');
	//var dtown = window.document.getElementById('dtown_txt').value;
	var dcounty = window.document.getElementById('dcounty_txt');
	var dpcode = window.document.getElementById('dpcode_txt');
	var add1 = window.document.getElementById('add1_txt');
	var add2 = window.document.getElementById('add2_txt');
	var add3 = window.document.getElementById('add3_txt');
	//var town = window.document.getElementById('town_txt');
	var county = window.document.getElementById('county_txt');
	var pcode = window.document.getElementById('pcode_txt');
	var ctype = window.document.getElementById('ctype_opt');
	var cname = window.document.getElementById('cname_txt');
	var cnum = window.document.getElementById('cnum_txt');
	var cexp = window.document.getElementById('cexpDate_txt');
	var ccv2 = window.document.getElementById('cv2_txt');
	
	if(dname){
		window.document.getElementById('dnamejs_txt').innerHTML = dname.value;
	}
	if(dadd1){
		window.document.getElementById('dadd1js_txt').innerHTML = dadd1.value;
	}
	if(dadd2){
		window.document.getElementById('dadd2js_txt').innerHTML = dadd2.value;
	}
	if(dadd3){
		window.document.getElementById('dadd3js_txt').innerHTML = dadd3.value;
	}
	if(dcounty){
		window.document.getElementById('dcountyjs_txt').innerHTML = dcounty.value;
	}
	if(dpcode){
		window.document.getElementById('dpcodejs_txt').innerHTML = dpcode.value;
	}
	if(add1){
		window.document.getElementById('badd1js_txt').innerHTML = add1.value;
	}
	if(add2){
		window.document.getElementById('badd2js_txt').innerHTML = add2.value;
	}
	if(add3){
		window.document.getElementById('badd3js_txt').innerHTML = add3.value;
	}
	if(county){
		window.document.getElementById('bcountyjs_txt').innerHTML = county.value;
	}
	if(pcode){
		window.document.getElementById('bpcodejs_txt').innerHTML = pcode.value;
	}
	return false;
}

function timetableSelect(obj){
	//REMOVE ANY SELECTED TDS
	var container = window.document.getElementById('timetable');
	var cells = container.getElementsByTagName('td');
	var len = cells.length;
	for(var i = 0; i < len; i++){
		if(cells[i].className == 'available active'){
			cells[i].className = 'available';
			break;
		}
	}
	//ACTIVATE CURRENT TD
	var cname = obj.className;
	if(cname.indexOf('active')==-1){
		obj.className = 'available active';
	}
	//GET CURRENT TD INFO
	var info = obj.innerHTML;
	var regex = /<\/?span>/igm;
	info = info.replace(regex, '');
	if(info.indexOf('"ddatetime')==-1) info = info.replace('ddatetime', '"ddatetime_selected" id="ddatetime_selected"'); /* IE FIX */
	else info = info.replace('ddatetime"', 'ddatetime_selected" id="ddatetime_selected"');
	window.document.getElementById('timetable_selected').innerHTML = info;
}

function timetable_hop(direction, week, group){
	var target = 'timetable_container';
	var url = './includes/ajax_timetable.inc.php?d='+direction+'&wk='+week+'&group='+group;
	//AJAX
    xmlHttp = GetXmlHttpObject();
    if (xmlHttp == null) {
        alert("Browser does not support AJAX - Please update");
        return false;
    }
	xmlHttp.onreadystatechange = function() {
        ajaxStateChanged(target);
    };
	xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
	return false;
}

function addPromoCode(currency){
	var promo_txt = window.document.getElementById('promo_txt');
	if(promo_txt.value.length != 0){
		var target = 'promoStatus';
		var url = './includes/ajax_promocode2.inc.php?code='+promo_txt.value;
		url = url + '&mode=' + currency;
		//AJAX
		xmlHttp = GetXmlHttpObject();
		if (xmlHttp == null) {
			alert("Browser does not support AJAX - Please update");
			return false;
		}
		xmlHttp.onreadystatechange = function() {
			var loadingObj = window.document.getElementById(target);
			if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
				var txt = xmlHttp.responseText;
				if(txt.indexOf('<ERROR>')==-1){
					if(txt.indexOf('</GBPTOTAL>')!=-1){
						var gbp_txt = txt.split('</GBPTOTAL>');
						var gbp = gbp_txt[0];
						var eur_txt = gbp_txt[1].split('</EURTOTAL>');
						var eur = eur_txt[0];
						var ar_currency = eur_txt[1].split('</CURRENCY>');
						currency = ar_currency[0];
						var input = ar_currency[1];
						var eurprice = '<span class="eurprice_span"';
						var gbpprice = '<span class="gbpprice_span"';
						if(currency=='GBP') eurprice += ' style="display:none"';
						else gbpprice += ' style="display:none"';
						eurprice += '>'+eur+'</span>';
						gbpprice += '>'+gbp+'</span>';
						var msg = 'Your cart total has now been updated to '+gbpprice+eurprice;
						window.document.getElementById(target).innerHTML = msg;
						window.document.getElementById(target).style.display = 'block';
						var discountedtotal = window.document.getElementById('discounted_total_1');
						var discountedtotal2 = window.document.getElementById('discounted_total_2');
						var minicarttotal = window.document.getElementById('miniCartTotal');
						if(discountedtotal && minicarttotal){
							minicarttotal.innerHTML = gbpprice+eurprice+'<textarea style="display:none;">'+minicarttotal.innerHTML+'</textarea>';
							for(var c = 0; c < 2; c++){
								var discountedtotalelem = discountedtotal;
								if(c == 1) discountedtotalelem = discountedtotal2;
								var spans = discountedtotalelem.getElementsByTagName('span');
								var spancount = spans.length;
								for(var i = 0; i < spancount; i++){
									if(spans[i].className == 'pricetarget'){
										spans[i].innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+gbpprice+eurprice;
										break;
									}
								}
							}
							discountedtotal.style.display = '';
							discountedtotal2.style.display = '';
						}
					}
				} else {
					var minicarttotal = window.document.getElementById('miniCartTotal');
					var discountedtotal = window.document.getElementById('discounted_total_1');
					var discountedtotal2 = window.document.getElementById('discounted_total_2');
					if(discountedtotal) discountedtotal.style.display = 'none';
					if(discountedtotal2) discountedtotal2.style.display = 'none';
					if(minicarttotal){
						var carthtml = minicarttotal.innerHTML;
						if(carthtml.indexOf('<textarea')!==-1){
							var ar_carthtml = carthtml.split('<textarea style="display: none;">');
							var newcarthtml = ar_carthtml[1];
							newcarthtml = newcarthtml.replace('</textarea>', '');
							minicarttotal.innerHTML = newcarthtml;
						}
					}
					var total = window.document.getElementById('promoprice_total');
					if(total){
						total.style.display = 'none';
					}
					var summarytotal = window.document.getElementById('summaryTotal');
					if(summarytotal){
						summary.style.display = 'none';
					}
					//PROMO CODE NOT AVAILABLE
					txt = txt.replace('<ERROR>', '');
					window.document.getElementById(target).innerHTML = txt;
					window.document.getElementById('promoStatus').style.display = 'block';
				}
			}
		};
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
	return false;
}


function addPromoCode2(currency){
	var promo_txt = window.document.getElementById('promo_txt');
	if(promo_txt.value.length != 0){
		var target = 'promoStatus';
		var url = './includes/ajax_promocode2.inc.php?code='+promo_txt.value;
		url = url + '&mode=' + currency;
		//AJAX
		xmlHttp = GetXmlHttpObject();
		if (xmlHttp == null) {
			alert("Browser does not support AJAX - Please update");
			return false;
		}
		xmlHttp.onreadystatechange = function() {
			var loadingObj = window.document.getElementById(target);
			if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
				var txt = xmlHttp.responseText;
				if(txt.indexOf('<ERROR>')==-1){
					if(txt.indexOf('</GBPTOTAL>')!=-1){
						var gbp_txt = txt.split('</GBPTOTAL>');
						var gbp = gbp_txt[0];
						var eur_txt = gbp_txt[1].split('</EURTOTAL>');
						var eur = eur_txt[0];
						var ar_currency = eur_txt[1].split('</CURRENCY>');
						currency = ar_currency[0];
						var input = ar_currency[1];
						var eurprice = '<span class="eurprice_span"';
						var gbpprice = '<span class="gbpprice_span"';
						if(currency=='GBP') eurprice += ' style="display:none"';
						else gbpprice += ' style="display:none"';
						eurprice += '>'+eur+'</span>';
						gbpprice += '>'+gbp+'</span>';
						var msg = 'Your cart total has now been updated to '+gbpprice+eurprice;
						window.document.getElementById(target).innerHTML = msg;
						window.document.getElementById(target).style.display = 'block';
						var discountedtotal = window.document.getElementById('discounted_total_1');
						var discountedtotal2 = window.document.getElementById('discounted_total_2');
						var minicarttotal = window.document.getElementById('miniCartTotal');
						if(discountedtotal && minicarttotal){
							minicarttotal.innerHTML = gbpprice+eurprice+'<textarea style="display:none;">'+minicarttotal.innerHTML+'</textarea>';
							for(var c = 0; c < 2; c++){
								var discountedtotalelem = discountedtotal;
								if(c == 1) discountedtotalelem = discountedtotal2;
								var spans = discountedtotalelem.getElementsByTagName('span');
								var spancount = spans.length;
								for(var i = 0; i < spancount; i++){
									if(spans[i].className == 'pricetarget'){
										spans[i].innerHTML = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'+gbpprice+eurprice;
										break;
									}
								}
							}
							discountedtotal.style.display = '';
							discountedtotal2.style.display = '';
						}
					}
				} else {
					var minicarttotal = window.document.getElementById('miniCartTotal');
					var discountedtotal = window.document.getElementById('discounted_total_1');
					var discountedtotal2 = window.document.getElementById('discounted_total_2');
					if(discountedtotal) discountedtotal.style.display = 'none';
					if(discountedtotal2) discountedtotal2.style.display = 'none';
					if(minicarttotal){
						var carthtml = minicarttotal.innerHTML;
						if(carthtml.indexOf('<textarea')!==-1){
							var ar_carthtml = carthtml.split('<textarea style="display: none;">');
							var newcarthtml = ar_carthtml[1];
							newcarthtml = newcarthtml.replace('</textarea>', '');
							minicarttotal.innerHTML = newcarthtml;
						}
					}
					var total = window.document.getElementById('promoprice_total');
					if(total){
						total.style.display = 'none';
					}
					var summarytotal = window.document.getElementById('summaryTotal');
					if(summarytotal){
						summary.style.display = 'none';
					}
					//PROMO CODE NOT AVAILABLE
					txt = txt.replace('<ERROR>', '');
					window.document.getElementById(target).innerHTML = txt;
					window.document.getElementById('promoStatus').style.display = 'block';
				}
			}
		};
		xmlHttp.open("GET", url, true);
		xmlHttp.send(null);
	}
	return false;
}

function toggle(obj){
	$("#"+obj).toggle();
	return false;
}
