//<script>
function set_language(id) {
	var options = {"path": "/"};
	Cookie.set("IdLanguage", id, options);
	if (Cookie.get("IdLanguage") == id)
		window.location.reload();
	else
		AjaxFactory.OnError("CookieSetFailed");
}
function commun_start(with_update_display) {
	AjaxFactory.url = "script\/basket.php";
	AjaxFactory.messages.set("Unknown", "Une erreur est survenue : ");
	AjaxFactory.messages.set("CookieSetFailed", "Vous devez autoriser les cookies pour continuer !");
	AjaxFactory.messages.set("EmptyReply", "Le serveur n\u0027a pas répondu dans les temps, merci de réessayer ultérieurement ! Si l\u0027erreur persiste, merci de nous contacter.");
	AjaxFactory.messages.set("MysqlConnection", "Le serveur est indisponible, merci de réessayer ultérieurement ! Si l\u0027erreur persiste, merci de nous contacter.");
	if (with_update_display)
		init_update_display();
	else
		try { $("loading").hide(); } catch(e) { }
}
function init_update_display() {
	hex2bin = $H(hex2bin || {});
	AjaxFactory.UpdateDisplay = function(edit_id, where) {
		edit_id = edit_id || false;
		where = where || false;
		if (AjaxFactory.where != "Basket" && where == "ItemNew") {
			window.location.href = "http:\/\/www.harmonia-shop.com\/basket.php?step=view";
			return;
		}
		AjaxFactory.ItemList(function(data) {
			var items = $H();
			data.each(function(item) {
				items.set(item["IdItem"], item["Quantity"]);
			});
			$$('.basket').each(function(obj) {
				var id_hex = obj.id.substr(obj.id.indexOf('_') + 1);
				var id_bin = hex2bin.get(id_hex);
				var id_js = id_bin.escapeHTML().replace(/"/g, '&quot;').replace(/'/g, '\'');
				var quantity = items.get(id_bin), s = '';
				var _qty = "Quantité :";
				var _drop = "Retirer cet article";
				var _modify = "Modifier";
				var _new = "Ajouter au panier";
				if (quantity > 0) {
					if (id_bin == edit_id) {
						s = '<span>' + _qty + ': </span>' +
							'<input type="text" id="quantity_' + id_hex + '" value="' + quantity + '" maxlength="7" onkeypress="var k = event.which || event.keyCode || false; if(k != 13) return true; AjaxFactory.ItemNew(\'' + id_js + '\',this.value); return false" />' +
							'<a onclick="AjaxFactory.ItemNew(\'' + id_js + '\',$(\'quantity_' + id_hex + '\').value)">Ok</a>' +
							'<span> - </span>' +
							'<a onclick="AjaxFactory.ItemNew(\'' + id_js + '\',' + quantity + ')">' + _drop + '</a>';
					} else {
						s = '<span>' + _qty + ': ' + quantity + '</span>' + 
							'<span> - </span>' +
							'<a onclick="AjaxFactory.UpdateDisplay(\'' + id_js + '\')">' + _modify + '</a>' +
							'<span> - </span>' +
							'<a onclick="AjaxFactory.ItemDrop(\'' + id_js + '\')">' + _drop + '</a>';
					}
				} else {
					s = '<a onclick="AjaxFactory.where=\'Tag\';AjaxFactory.ItemNew(\'' + id_js + '\',1)">' + _new + '</a>';
				}
				$(obj).update(s);
			});
			try { $("loading").hide(); } catch(e) { }
			try { if (edit_id) $('quantity_' + hex2bin.index(edit_id)).activate() } catch(e) { }
		});
	}
	AjaxFactory.UpdateDisplay();
}

var Addresses = {
	serialize: function(getHash) {
		var temp = Cookie.get("Addresses");
		return ((getHash && temp != false) ? temp.toQueryParams() : temp);
	},
	get: function(key) {
		return Addresses.serialize(true)[key];
	},
	set: function(hash) {
		Cookie.set("Addresses", $H(hash).toQueryString());
	},
	update: function(hash) {
		Addresses.set($H(Addresses.serialize(true)).update(hash));
	},
	del: function() {
		Cookie.del("Addresses");
	}
}

function pop(id) {
	var targetElement;
	targetElement = document.getElementById(id) ;
	if (targetElement.style.display == "none") {
		$("#"+id).slideDown();
	} else {
		$("#"+id).slideUp();
	}
}



