var maxPulMenu = 10;
var arGoodscode = new Array(); 
var arGoodsname = new Array(); 
var arQuantity = new Array(); 
var arPrice = new Array(); 
var arStationcode = new Array(); 
var arImage = new Array(); 
var arExceptinventory = new Array(); 
var LineCount;
var Total = 0;
var Sep = '::';
focus();
function lineDelete(goodscode){
	var i, j;
	LineCount = getCookie("LineCount");
	for (i = 1; i <= LineCount; i++){
		sStr = getCookie('Line_' + i).split(Sep);
		arGoodscode[i] = sStr[0];
		arGoodsname[i] = decodeURL(sStr[1]);
		arQuantity[i] = sStr[2];
		arPrice[i] = sStr[3];
		arStationcode[i] = sStr[4];
		arImage[i] = sStr[5];
		arExceptinventory[i] = sStr[6];
		if (goodscode == arGoodscode[i]){
			for (j = i; j < LineCount; j++){
				setCookie('Line_' + j, getCookie('Line_' + (j + 1)));
			}
			clearCookie('Line_' + LineCount);
			LineCount -= 1;
			setCookie('LineCount', LineCount);
		}
	}
	window.location.href=window.location.href;
}
function changeData(){
	var i;
	var Line = 0;
	LineCount = getCookie("LineCount");
	cartClear0();
	for (i = 1; i <= LineCount; i++){
		if (!isNaN(document.cart['f_quantity_' + i].value) && (document.cart['f_quantity_' + i].value != 0)){
				Line++;
				setCookie('Line_' + Line, document.cart['f_commoditycode_' + i].value + Sep + encodeURL(document.cart['f_commodityname_' + i].value) + Sep + document.cart['f_quantity_' + i].value + Sep + document.cart['f_saleunitprice_' + i].value + Sep + document.cart['f_stationcode_' + i].value + Sep + document.cart['f_image_' + i].value + Sep + document.cart['f_exceptinventory_' + i].value);
		}
	}
	setCookie('LineCount', Line);
	window.location.href=window.location.href;
}
function lineGet(){
	var i;
	LineCount = getCookie("LineCount");
	for (i = 1; i <= LineCount; i++){
		sStr = getCookie('Line_' + i).split(Sep);
		arGoodscode[i] = sStr[0];
		arGoodsname[i] = decodeURL(sStr[1]);
		arQuantity[i] = sStr[2];
		arPrice[i] = sStr[3];
		arStationcode[i] = sStr[4];
		arImage[i] = sStr[5];
		arExceptinventory[i] = sStr[6];
	}
}
function getCookie(key, tmp1, tmp2, xx1, xx2, xx3) {
	tmp1 = " " + document.cookie + ";";
	xx1 = xx2 = 0;
	len = tmp1.length;
	while (xx1 < len) {
		xx2 = tmp1.indexOf(";", xx1);
		tmp2 = tmp1.substring(xx1 + 1, xx2);
		xx3 = tmp2.indexOf("=");
		if (tmp2.substring(0, xx3) == key) {
			return(tmp2.substring(xx3 + 1, xx2 - xx1 - 1));
		}
		xx1 = xx2 + 1;
	}
	return("");
}
function setCookie(key, val, tmp, flag) {
    tmp = key + "=" + val + "; ";
		if (flag){
	    tmp += "expires=Tue, 31-Dec-2030 23:59:59; ";
		}
    document.cookie = tmp;
}
function clearCookie(key) {
    document.cookie = key + "=" + "xx; expires=Tue, 1-Jan-1980 00:00:00;";
}
function cartSet(goodscode,goodsname,quantity,saleunitprice,stationcode,image,exceptinventory){
	var i;
	var newQuantity;
	var LineCount = getCookie("LineCount");
	var tmp = '';
	var val;
	goodsname = encodeURL(goodsname);
	if (LineCount == ''){
		setCookie('LineCount', '1');
		setCookie('Line_1', goodscode + Sep + goodsname + Sep + quantity + Sep + saleunitprice + Sep + stationcode + Sep + image + Sep + exceptinventory);
	} else {
		for (i = 1; i <= LineCount; i++){
			val = getCookie('Line_' + i);
			sStr = val.split(Sep);
			if (sStr[0] == goodscode){
				newQuantity = Number(sStr[2]) + Number(quantity);
				if ((newQuantity > exceptinventory) || (newQuantity > maxPulMenu)){
					alert('「' + decodeURL(goodsname) + '」は、数量オーバーです。');
				} else {
					setCookie('Line_' + i, goodscode + Sep + goodsname + Sep + newQuantity + Sep + saleunitprice + Sep + stationcode + Sep + image + Sep + exceptinventory);
				}
				tmp = i;
				break;
			}
		}
		if (tmp == ''){
			setCookie('LineCount', i);
			setCookie('Line_' + i, goodscode + Sep + goodsname + Sep + quantity + Sep + saleunitprice + Sep + stationcode + Sep + image + Sep + exceptinventory);
		} else {
			setCookie('LineCount', LineCount);
		}
	}
	return false;
}
function cartClear(){
	cartClear0();
	window.location.href=window.location.href;
}
function cartClear0(){
	LineCount = getCookie("LineCount");
	for (i = 1; i <= LineCount; i++){
		clearCookie('Line_' + i);
	}
	clearCookie('LineCount');
}
function winClose(){
	window.close();
}
/*  Function Equivalent to java.net.URLEncoder.encode(String, "UTF-8")
    Copyright (C) 2002, Cresc Corp.
    Version: 1.0
*/
function encodeURL(str){
    var s0, i, s, u;
    s0 = "";                // encoded str
    for (i = 0; i < str.length; i++){   // scan the source
        s = str.charAt(i);
        u = str.charCodeAt(i);          // get unicode of the char
        if (s == " "){s0 += "+";}       // SP should be converted to "+"
        else {
            if ( u == 0x2a || u == 0x2d || u == 0x2e || u == 0x5f || ((u >= 0x30) && (u <= 0x39)) || ((u >= 0x41) && (u <= 0x5a)) || ((u >= 0x61) && (u <= 0x7a))){       // check for escape
                s0 = s0 + s;            // don't escape
            }
            else {                  // escape
                if ((u >= 0x0) && (u <= 0x7f)){     // single byte format
                    s = "0"+u.toString(16);
                    s0 += "%"+ s.substr(s.length-2);
                }
                else if (u > 0x1fffff){     // quaternary byte format (extended)
                    s0 += "%" + (oxf0 + ((u & 0x1c0000) >> 18)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0x3f000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else if (u > 0x7ff){        // triple byte format
                    s0 += "%" + (0xe0 + ((u & 0xf000) >> 12)).toString(16);
                    s0 += "%" + (0x80 + ((u & 0xfc0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
                else {                      // double byte format
                    s0 += "%" + (0xc0 + ((u & 0x7c0) >> 6)).toString(16);
                    s0 += "%" + (0x80 + (u & 0x3f)).toString(16);
                }
            }
        }
    }
    return s0;
}
 
/*  Function Equivalent to java.net.URLDecoder.decode(String, "UTF-8")
    Copyright (C) 2002, Cresc Corp.
    Version: 1.0
*/
function decodeURL(str){
    var s0, i, j, s, ss, u, n, f;
    s0 = "";                // decoded str
    for (i = 0; i < str.length; i++){   // scan the source str
        s = str.charAt(i);
        if (s == "+"){s0 += " ";}       // "+" should be changed to SP
        else {
            if (s != "%"){s0 += s;}     // add an unescaped char
            else{               // escape sequence decoding
                u = 0;          // unicode of the character
                f = 1;          // escape flag, zero means end of this sequence
                while (true) {
                    ss = "";        // local str to parse as int
                        for (j = 0; j < 2; j++ ) {  // get two maximum hex characters for parse
                            sss = str.charAt(++i);
                            if (((sss >= "0") && (sss <= "9")) || ((sss >= "a") && (sss <= "f"))  || ((sss >= "A") && (sss <= "F"))) {
                                ss += sss;      // if hex, add the hex character
                            } else {--i; break;}    // not a hex char., exit the loop
                        }
                    n = parseInt(ss, 16);           // parse the hex str as byte
                    if (n <= 0x7f){u = n; f = 1;}   // single byte format
                    if ((n >= 0xc0) && (n <= 0xdf)){u = n & 0x1f; f = 2;}   // double byte format
                    if ((n >= 0xe0) && (n <= 0xef)){u = n & 0x0f; f = 3;}   // triple byte format
                    if ((n >= 0xf0) && (n <= 0xf7)){u = n & 0x07; f = 4;}   // quaternary byte format (extended)
                    if ((n >= 0x80) && (n <= 0xbf)){u = (u << 6) + (n & 0x3f); --f;}         // not a first, shift and add 6 lower bits
                    if (f <= 1){break;}         // end of the utf byte sequence
                    if (str.charAt(i + 1) == "%"){ i++ ;}                   // test for the next shift byte
                    else {break;}                   // abnormal, format error
                }
            s0 += String.fromCharCode(u);           // add the escaped character
            }
        }
    }
    return s0;
}
