window.onload = function(){
	var obj;
	for(var i = 0; (obj = document.getElementsByTagName("select")[i]); i ++){
		if(obj.getAttribute("class") == "change-num" || obj.getAttribute("className") == "change-num"){
			obj.onchange = function(){
				var code = this.getAttribute("title");
				var newNum = this.selectedIndex + 1;
				var newCart = "";
				var cookies = document.cookie + ";";
				var from = cookies.indexOf("jicoCart=");
				var to = cookies.indexOf(";", from + 1);
				var currentCart = cookies.substring(from + 9, to);
				var items = currentCart.split(",");
				for(var j in items){
					var codeAndNum = items[j].split("*");
					if(newCart) newCart += ",";
					if(codeAndNum[0] == code){
						newCart += code + "*" + newNum;
					}else{
						newCart += codeAndNum[0] + "*" + codeAndNum[1];
					}
				}
				document.cookie = "jicoCart=" + newCart + "; path=/; expires=Tue, 1-Jan-2030 00:00:00;";
				location.reload(true);
			}
		}
	}
	for(var i = 0; (obj = document.getElementsByTagName("a")[i]); i ++){
		if(obj.getAttribute("class") == "delete-item" || obj.getAttribute("className") == "delete-item"){
			obj.onclick = function(){
				if(confirm("この製品を買い物カゴから削除しますか？")){
					var code = this.getAttribute("title");
					var newCart = "";
					var cookies = document.cookie + ";";
					var from = cookies.indexOf("jicoCart=");
					var to = cookies.indexOf(";", from + 1);
					var currentCart = cookies.substring(from + 9, to);
					var items = currentCart.split(",");
					for(var j in items){
						if(items[j].indexOf(code + "*") == -1){
							if(newCart) newCart += ",";
							newCart += items[j];
						}
					}
					document.cookie = "jicoCart=" + newCart + "; path=/; expires=Tue, 1-Jan-2030 00:00:00;";
					location.href = "./";
				}
				return false;
			}
		}
	}
	setGetIntoCart();
	setSearchVehavior();
	setNewWin();
}
function number_format(num){
	var n = num.toString();
	var nums = n.split(".");
	var newNum = "";
	var i = 0;
	for(var j = (nums[0].length - 1); j >= 0; j --){
		if(newNum.length && i % 3 == 0) newNum = "," + newNum;
		newNum = nums[0].substr(j, 1) + newNum;
		i ++;
	}
	if(nums.length == 2){
		newNum += "." + nums[1];
	}
	return newNum;
}
