var cscart = Class.extend({

	ListItem : 'shoppingcart_main',
	ShopForm : 'shoppingcart_form',
	I		 : 'shoppingcart',
	rURL	 : '/shoppingcart/',
	itemID	 : 0,
	
	//+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+/ );
							this.itemID = itemID; 
							
							if (plus == 'p') { 
								c = "p"+c;
								if (document.getElementById('message_'+itemID))
								document.getElementById('message_'+itemID).style.display = 'block';
							}
 							
							if (document.getElementById('overlay')) 
							document.getElementById('overlay').style.display = 'block';
							
							this.itemID = itemID;
							if (typeof(mypopupshow) == 'function') {
							myAjax.onSuccess = mypopupshow;
							}
							
							myAjax.setGET(itemID, c);
							myAjax.inObj = this.I;
							myAjax.request(this.rURL + "add.html");
						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) {
				
					if (typeof(nameID) == 'string') {
						OnameID = document.createElement("div");
						OnameID.name = nameID;
						nameID = OnameID;
					}
					
					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();
