function Cookie(){	
	var remote = document.getElementById('remote').getElementsByTagName("input");
	this.key = remote[0];
	this.num = remote[1];
	this.funEdit = remote[2].onclick;
	this.total = 0;
	this.size = 0;
}
Cookie.prototype = {
	editNum:function(){		
			if(/^\d+$/.test(this.value) && parseInt(this.value) > 0 && parseInt(this.value) <= parseInt(this.getAttribute('max'))){
				cookie.key.value = this.id;
				cookie.num.value = this.value;
				cookie.funEdit.call();				
				cookie.total = new Number(cookie.total - this.getAttribute('price') * (this.getAttribute('protonum') - this.value)).toFixed(2);				
				document.getElementById("total").innerHTML = cookie.total;
				this.parentNode.parentNode.cells[8].innerHTML = new Number(this.getAttribute('price')* this.value).toFixed(2) + "元";
				this.setAttribute('protonum',this.value);				
			}else{
				this.value = this.getAttribute('protonum');
			}
	},
	delGoods:function(gid){		
				var text = document.getElementById(gid);
				document.getElementById("size").innerHTML = -- cookie.size;
				cookie.total = new Number(cookie.total - text.getAttribute('price') * text.value).toFixed(2);
				document.getElementById("total").innerHTML = cookie.total;				
				var tr = text.parentNode.parentNode;
				tr.style.display = "none";			
	}
}
var cookie;
window.onload= function ini(){	
	cookie = new Cookie;
	var table = document.getElementById("table");
	var edit = table.getElementsByTagName("input");
	var i;
	var total =  new Number(0);
	for(i = 0; i<edit.length ;i++){		
		var text = edit[i];
		text.onchange = cookie.editNum;
		var allPrice = text.getAttribute('protonum') *  text.getAttribute('price') ;		
		table.rows[i + 1 ].cells[8].innerHTML =new Number(allPrice).toFixed(2)+"元";
		total +=allPrice;
	}
	cookie.total = new Number(total).toFixed(2);
	cookie.size = i;
	document.getElementById("size").innerHTML = i;
	document.getElementById("total").innerHTML = cookie.total;	
}
