
var PAGE = new function() {
	this.init = function() {
		//
	};
	
	this.continueShopping = function(url) {
		window.location.href = url;
	};
	
	this.updateCart = function() {
		this.submit("action=update");
	};
	
	this.addSelectionsToCart = function() {
		this.submit("action=add");
	};
	
	this.createCart = function() {
		this.submit("action=load&cart_num=0");
	};
	
	this.loadCart = function() {
		var cart_id = document.getElementById("cart_num_select").value;
		if (cart_id.length){
			this.submit("action=load&cart_num="+ cart_id);
		}else{
			this.createCart();
		}
	};
	
	this.deleteCart = function() {
		var cart_id = document.getElementById("cart_num_select").value;
		if (cart_id.length && confirm("Are you sure you want to delete this saved cart?")){
			this.submit("action=delete&cart_num_delete="+ cart_id);
		}
	};
	
	this.renameCart = function(tgl) {
		if (tgl==null){
			jQuery("#cart_ctrlpanel_1").hide();
			jQuery("#cart_ctrlpanel_2").show();
			var cart_select = document.getElementById("cart_num_select");
			var cart_name = cart_select.options[cart_select.selectedIndex].text;
			cart_name = cart_name.replace(/\s\(\d+\sitems\)$/, '');
			_form.cart_name.value = cart_name;
		}else if (tgl==true){
			var cart_name = _form.cart_name.value.trim();
			this.submit("action=rename&cart_name="+ escape(cart_name));
		}else if (tgl==false){
			jQuery("#cart_ctrlpanel_2").hide();
			jQuery("#cart_ctrlpanel_1").show();
		}
	};
	
	this.submit = function(values) {
		_form.action = BASE_URL +"pages/cart.aspx" + (values.length ? "?" + values : "");
		_form.submit();
	};

};


