var cscart = Class.extend({

	ListItem : 'shoppingcart_main',
	ShopForm : 'shoppingcart_form',
	I		 : 'shoppingcart',
	rURL	 : '/shoppingcart/',
	
	//+id:itemIDName;+C:item count
		add:
			function (obj, plus) {
					nameID = obj.name;

					c = plus != "delete" ? document.getElementById(obj.name).value.match(/\d+/ ) : "r0"; 
					
					if (nameID) {
							itemID = nameID.match(/\d+/ );
							
							if (plus == 'p') { 
								c = "p"+c;
								document.getElementById('message_'+itemID).style.display = 'block';
							}
							
							
							myAjax.setGET(itemID, c);
							myAjax.inObj = this.I;
							myAjax.request(this.rURL + "add.html");
							myAjax.onSuccess = function() { window.location = '/shoppingcart/'}
						return true;
					}
				return false;
			},

//only main
		refresh:
			function () {
				
					for (v in document.forms[this.ShopForm].elements) {
						
						if (typeof(document.forms[this.ShopForm].elements[v]) == 'object' && document.forms[this.ShopForm].elements[v] != null) {
							name = document.forms[this.ShopForm].elements[v].name;
							if (name=='main') {
									myAjax.setPOST('main', 1);	
							
							}
						
							if (typeof(name) == 'string' && name != '') {
								if (name.match(/item_\d+/)) {
							
									if (itemID = name.match(/item_(\d+)/)[1]) {
										myAjax.setPOST(itemID, "r"+document.forms[this.ShopForm].elements[v].value);
									}
								}
							}
						}
					}
					
					myAjax.inObj = this.ListItem;
					myAjax.request(this.rURL + 'refresh.html');
					myAjax.onSuccess = scart.absrefresh;
					
				
			},
		
		del:
			function (nameID) {
					this.add(nameID, "delete");
					if (document.getElementById(this.ListItem)) {
							myAjax.setPOST('main', 1);	
							myAjax.inObj = this.ListItem;
							myAjax.request(this.rURL + 'refresh.html');
							myAjax.onSuccess = scart.absrefresh;

//							this.refresh();
					}
				return false;
			},
			
		absrefresh:
			function () {
					httpRequest("/shoppingcart/refresh.html", "", setDIV, scart.I, "DIV");
			}

});

var scart = new cscart();
