function checkForm() {
	// フォーム要素すべてを変数にセット
	var f = window.document.the_form;
	var the_kanjiname = window.document.the_form.kanjiname.value;
	var the_usrname = window.document.the_form.usrname.value;
	var the_usrtel = window.document.the_form.usrtel.value;
	var the_usrmail = window.document.the_form.usrmail.value;
	var the_zip = window.document.the_form.zip.value;

	// ワードチェック用正規表現
	var check_tel = /\D/;
	var check_zip = /\D/;
	var check_mail = /.+@.+\..+/;

	var check = false;
	for (var i=0; i < f.method.length; i++) {
		if (f.method[i].checked == true) {
			check = true;
		}
	}
	if (check == false) {
		alert("支払い方法を選択してください");
		return false;
	}
	if (the_kanjiname == "") {
		alert('お名前「漢字」を入力してください');
		return false;
	}
	if (the_usrname == "") {
		alert('お名前「ローマ字」を入力してください');
		return false;
	}
	if (the_zip == "") {
		alert('郵便番号を入力して下さい');
		return false;
	}
	if (the_zip.match(check_zip)) {
		alert("郵便番号は数字で入力して下さい\nハイフンはいりません");
		return false;
	}
	if (f.state.value == 0) {
		alert("都道府県を指定して下さい");
		return false;
	}
	if (f.addr1.value == "") {
		alert("住所を入力して下さい");
		return false;
	}
	if (the_usrtel == "") {
		alert('電話番号を入力してください');
		return false;
	}
	if (the_usrtel.match(check_tel)) {
		alert("電話番号は数字で入力してください\nハイフンはいりません");
		return false;
	}
	if (the_usrmail == "") {
		alert("メールアドレスを入力してください");
		return false;
	}
	if (!the_usrmail.match(check_mail)) {
		alert("メールアドレスが正しくありません");
		return false;
	}
	return true;
}

function checkFormSP() {
	// フォーム要素すべてを変数にセット
	var the_kanjiname = window.document.the_form.kanjiname.value;
	var the_usrname = window.document.the_form.usrname.value;
	var the_zip = window.document.the_form.zip.value;
	var the_address = window.document.the_form.address.value;
	var the_usrtel = window.document.the_form.usrtel.value;
	var the_usrmail = window.document.the_form.usrmail.value;
	var card_no1 = window.document.the_form.card_no1.value;
	var card_no2 = window.document.the_form.card_no2.value;
	var card_no3 = window.document.the_form.card_no3.value;
	var card_no4 = window.document.the_form.card_no4.value;
	// ワードチェック用正規表現
	var check_tel = /\D/;
	var check_zip = /\D/;
	var check_mail = /.+@.+\..+/;
	var check_no1 = card_no1.match(/[0-9]+/g);
	var check_no2 = card_no2.match(/[0-9]+/g);
	var check_no3 = card_no3.match(/[0-9]+/g);
	var check_no4 = card_no4.match(/[0-9]+/g);
	if ((card_no1.length != 3) || (card_no2.length != 3) ||
		(card_no3.length != 3) || (card_no4.length != 4)) {
		alert('カード番号は「３桁」-「３桁」-「３桁」-「４桁」です');
		return false;
	}
	if ((card_no1 != check_no1) || (card_no2 != check_no2) ||
		(card_no3 != check_no3) || (card_no4 != check_no4)) {
		alert('カード番号は数字で入力してください');
		return false;
	}
	if (the_kanjiname == "") {
		alert('お名前「漢字」を入力してください');
		return false;
	}
	if (the_usrname == "") {
		alert('お名前「ローマ字」を入力してください');
		return false;
	}
	if (the_zip == "") {
		alert("郵便番号を入力して下さい");
		return false;
	}
	if (the_zip.match(check_zip)) {
		alert("郵便番号は数字で入力して下さい\nハイフンはいりません");
		return false;
	}
	if (the_address == "") {
		alert('住所を入力して下さい');
		return false;
	}
	if (the_usrtel == "") {
		alert('電話番号を入力してください');
		return false;
	}
	if (the_usrtel.match(check_tel)) {
		alert("電話番号は数字で入力してください\nハイフンはいりません");
		return false;
	}
	if (the_usrmail == "") {
		alert("メールアドレスを入力してください");
		return false;
	}
	if (!the_usrmail.match(check_mail)) {
		alert("メールアドレスが正しくありません");
		return false;
	}
	return true;
}

function changeURL() {
	parent.location.href = "checkout.html";
}
	
function visitSite(the_site) {
	window.location = the_site;
}

function openImg(img, x, y) {
	var options = "width="+x+",height="+y+",scrollbars=no";
	window.open(img,"item",options);
}

//function openImg(img, X, Y) {
//	var YY = Y + 30;
//	var XX = X + 30;
//	var height = window.screen.availHeight;
//	var width = window.screen.availWidth;
//	var left_point = parseInt(width / 2) - parseInt(XX / 2);
//	var top_point = parseInt(height / 2) - parseInt(YY / 2);
//	myWin = window.open("", img, "scrollbars=0,width=" + XX + ",height=" + YY);
//	myWin.document.write("<html><head><title>" + img + "</title></head>");
//	myWin.document.write("<body><center><img src=/items/" + img + ">");
//	myWin.document.write('<br>');
//	myWin.document.write("<input type=\"submit\" onClick='window.close()' value=CLOSE></center>");
//	myWin.document.write('</body></html>');
//	myWin.moveTo(left_point, top_point);
//	myWin.document.focus();
//	myWin.document.close();
//}

function readTheCookie(the_info)
{
    var split_stuff;

    // クッキーを変数にロードしてデコードする
    var the_cookie = WM_readCookie("cart");
    if (the_cookie)
    {
        if (the_cookie.indexOf(':') != -1)
        {
            split_stuff = the_cookie.split(":");
            for (var loop=0; loop < split_stuff.length; loop++)
            {
                the_info[loop] = split_stuff[loop];
            }
        } else {
            the_info[0] = the_cookie;
        }
    }
}

function addToCart(item_no) { 
  var purch_string = item_no;
	var NG_item = new Array();
	var the_qty = 1;
	var the_item = ""
	var the_str = "";
	var the_array = "";
	var the_item_no = "";
	var broken_info = "";

  // load the cookie into a variable and unescape it
  var the_cookie = WM_readCookie("cart");
  if (the_cookie) {
		// 同一商品は数量を１つ足す
		the_item_no = the_cookie.indexOf(item_no);
		if (the_item_no >= 0) {
			if (the_cookie.indexOf(':') != -1) {
				var the_array = the_cookie.split(":");
				for (var loop=0; loop < the_array.length; loop++) {
					property_value = the_array[loop];
					broken_info = property_value.split("/");
					the_item = broken_info[0];
					the_qty = broken_info[1];
					for (var lp=0; lp < NG_item.length; lp++) {
						if (NG_item[lp] == purch_string) {
							alert("この商品はお一人様１点のみとさせていただきます");
							return false;
						}
					}
					if (purch_string == the_item) {
						parseInt(the_qty);
						the_qty++;
					}
					the_str = the_str + the_item + "/" + the_qty + ":";
				}
				the_str = the_str.replace(/:$/, "");
				purch_string = the_cookie.replace(the_cookie, the_str);
				//alert("カートに追加しました。");
			} else {
				the_array = the_cookie.split("/");
				the_item = the_array[0];
				the_qty = the_array[1];
				for (var lp=0; lp < NG_item.length; lp++) {
					if (NG_item[lp] == the_item) {
						alert("この商品はお一人様１点のみとさせていただきます");
						return false;
					}
				}
				parseInt(the_qty);
				the_qty++;
				the_str = the_item + "/" + the_qty;
				purch_string = the_cookie.replace(the_cookie, the_str);
				//alert("カートに追加しました。");
			}
		} else {
			purch_string = the_cookie + ":" + purch_string + "/" + the_qty;
			//alert("カートに追加しました。");
		}
	} else {
		purch_string = purch_string + "/" + the_qty;
		//alert("カートに追加しました。");
	}
	WM_setCookie("cart",purch_string,1,"/");
	window.open('http://www.tokiko.com/yshopping/step1');
}

// 次の数行は、ユーザーがクッキーを受け入れる設定にしているか調べるためのもの
var WM_acceptsCookies = false;
if(document.cookie == '') {
    document.cookie = 'WM_acceptsCookies=yes'; // 試しにクッキーを書いてみる
    if(document.cookie.indexOf('WM_acceptsCookies=yes') != -1) {
        WM_acceptsCookies = true;
    }// うまく書けたら、フラグ変数をセットする
} else { // すでにクッキーが存在する場合
    WM_acceptsCookies = true;
}


function WM_setCookie (name, value, hours, path, domain, secure) {
    if (WM_acceptsCookies) { // ブラウザがクッキーを受け入れない場合は、無駄なことはしない
        var not_NN2 = (navigator && navigator.appName
                       && (navigator.appName == 'Netscape')
                       && navigator.appVersion
                       && (parseInt(navigator.appVersion) == 2))?false:true;

        if(hours && not_NN2) { // NN2 は Date を扱えないので、この部分はスキップする
            if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // 最初から Date 文字列
                var numHours = hours;
            } else if (typeof(hours) == 'number') { // 時間数から Date を計算する
                var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
            }
        }
        document.cookie = name + '=' + escape(value) + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // 指定された引数を追加して、クッキーを書き込む
    }
} // WM_setCookie


function WM_readCookie(name) {
    if(document.cookie == '') { // クッキーが存在しないので、処理終了
        return false;
    } else { // クッキーが存在する
        var firstChar, lastChar;
        var theBigCookie = document.cookie;
        firstChar = theBigCookie.indexOf(name); // クッキー名の先頭を探す
        var NN2Hack = firstChar + name.length;
        if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) { // クッキーが見つかったら
            firstChar += name.length + 1; // クッキー名と '=' を読み飛ばす
            lastChar = theBigCookie.indexOf(';', firstChar); // 値の文字列の末尾（すわなち次の ';'）を探す
            if(lastChar == -1) lastChar = theBigCookie.length;
            return unescape(theBigCookie.substring(firstChar, lastChar));
        } else { // 該当する名前のクッキーがなければ、偽を返す
            return false;
        }
    }
} // WM_readCookie

function WM_killCookie(name, path, domain) {
  var theValue = WM_readCookie(name); // クッキーを削除するためには、クッキー名が必要
  if(theValue) {
      document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // すでに有効期限切れのクッキーを書き込む
  }
} // WM_killCookie
