/*
 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
 *
 * http://www.lockon.co.jp/
 */
// 親ウィンドウの存在確認.
function fnIsopener() {
    var ua = navigator.userAgent;
    if( !!window.opener ) {
        if( ua.indexOf('MSIE 4')!=-1 && ua.indexOf('Win')!=-1 ) {
            return !window.opener.closed;
        } else {
        	return typeof window.opener.document == 'object';
        }
	} else {
		return false;
	}
}

// 郵便番号入力呼び出し.
function fnCallAddress(php_url, tagname1, tagname2, input1, input2) {
	zip1 = document.form1[tagname1].value;
	zip2 = document.form1[tagname2].value;

	if(zip1.length == 3 && zip2.length == 4) {
		url = php_url + "?zip1=" + zip1 + "&zip2=" + zip2 + "&input1=" + input1 + "&input2=" + input2;
		window.open(url,"nomenu","width=500,height=350,scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=no");
	} else {
		alert("郵便番号を正しく入力して下さい。");
	}
}

// 郵便番号から検索した住所を渡す.
function fnPutAddress(input1, input2) {
	// 親ウィンドウの存在確認。.
	if(fnIsopener()) {
		if(document.form1['state'].value != "") {
			// 項目に値を入力する.
			state_id = document.form1['state'].value;
			town = document.form1['city'].value + document.form1['town'].value;
			window.opener.document.form1[input1].selectedIndex = state_id;
			window.opener.document.form1[input2].value = town;
		}
	} else {
		window.close();
	}
}

function fnOpenNoMenu(URL) {
	window.open(URL,"nomenu","scrollbars=yes,resizable=yes,toolbar=no,location=no,directories=no,status=no");
}

function fnOpenWindow(URL,name,width,height) {
	window.open(URL,name,"width="+width+",height="+height+",scrollbars=yes,resizable=no,toolbar=no,location=no,directories=no,status=no");
}

function fnSetFocus(name) {
	if(document.form1[name]) {
		document.form1[name].focus();
	}
}

// セレクトボックスに項目を割り当てる.
function fnSetSelect(name1, name2, val) {
	sele1 = document.form1[name1];
	sele2 = document.form1[name2];

	if(sele1 && sele2) {
		index=sele1.selectedIndex;

		// セレクトボックスのクリア
		count=sele2.options.length
		for(i = count; i >= 0; i--) {
			sele2.options[i]=null;
		}

		// セレクトボックスに値を割り当てる。
		len = lists[index].length
		for(i = 0; i < len; i++) {
			sele2.options[i]=new Option(lists[index][i], vals[index][i]);
			if(val != "" && vals[index][i] == val) {
				sele2.options[i].selected = true;
			}
		}
	}
}

// Enterキー入力をキャンセルする。(IEに対応)
function fnCancelEnter()
{
	if (gCssUA.indexOf("WIN") != -1 && gCssUA.indexOf("MSIE") != -1) {
		if (window.event.keyCode == 13)
		{
			return false;
		}
	}
	return true;
}

// モードとキーを指定してSUBMITを行う。
function fnModeSubmit(mode, keyname, keyid) {
	switch(mode) {
	case 'delete_category':
		if(!window.confirm('選択したカテゴリとカテゴリ内のすべてのカテゴリを削除します')){
			return;
		}
		break;
	case 'delete':
		if(!window.confirm('一度削除したデータは、元に戻せません。\n削除しても宜しいですか？')){
			return;
		}
		break;
	case 'confirm':
		if(!window.confirm('登録しても宜しいですか')){
			return;
		}
		break;
	case 'delete_all':
		if(!window.confirm('検索結果をすべて削除しても宜しいですか')){
			return;
		}
		break;
	default:
		break;
	}
	document.form1['mode'].value = mode;
	if(keyname != "" && keyid != "") {
		document.form1[keyname].value = keyid;
	}
	document.form1.submit();
}

function fnFormModeSubmit(form, mode, keyname, keyid) {
	switch(mode) {
	case 'delete':
		if(!window.confirm('一度削除したデータは、元に戻せません。\n削除しても宜しいですか？')){
			return;
		}
		break;
	case 'confirm':
		if(!window.confirm('登録しても宜しいですか')){
			return;
		}
		break;
	case 'regist':
		if(!window.confirm('登録しても宜しいですか')){
			return;
		}
		break;
	default:
		break;
	}
	document.forms[form]['mode'].value = mode;
	if(keyname != "" && keyid != "") {
		document.forms[form][keyname].value = keyid;
	}
	document.forms[form].submit();
}

function fnFormMessageModeSubmit(mode, keyname, keyid, message) {
	switch(mode) {
	case 'delete':
		if(!window.confirm('一度削除したデータは、元に戻せません。\n削除しても宜しいですか？\n' + message)){
			return;
		}
		break;
	case 'confirm':
		if(!window.confirm('登録しても宜しいですか')){
			return;
		}
		break;
	case 'regist':
		if(!window.confirm('登録しても宜しいですか')){
			return;
		}
		break;
	default:
		break;
	}
	document.form1['mode'].value = mode;
	if(keyname != "" && keyid != "") {
		document.form1[keyname].value = keyid;
	}
	document.form1.submit();
}

function fnSetFormSubmit(form, key, val) {
	document.forms[form][key].value = val;
	document.forms[form].submit();
	return false;
}

function fnSetFormVal(form, key, val) {
	document.forms[form][key].value = val;
}

function fnChangeAction(url) {
	document.form1.action = url;
}

// ページナビで使用する。
function fnNaviPage(pageno) {
	document.form1['pageno'].value = pageno;
	document.form1.submit();
}

function fnSearchPageNavi(pageno) {
	document.form1['pageno'].value = pageno;
	document.form1['mode'].value = 'search';
	document.form1.submit();
	}

	function fnSubmit(){
	document.form1.submit();
}

// ポイント入力制限。
function fnCheckInputPoint() {
	if(document.form1['point_check']) {
		list = new Array(
						'use_point'
						);

		if(!document.form1['point_check'][0].checked) {
			color = "#dddddd";
			flag = true;
		} else {
			color = "";
			flag = false;
		}

		len = list.length
		for(i = 0; i < len; i++) {
			if(document.form1[list[i]]) {
				document.form1[list[i]].disabled = flag;
				document.form1[list[i]].style.backgroundColor = color;
			}
		}
	}
}

// 別のお届け先入力制限。
function fnCheckInputDeliv() {
	if(!document.form1) {
		return;
	}
	if(document.form1['deliv_check']) {
		list = new Array(
						'deliv_name01',
						'deliv_name02',
						'deliv_kana01',
						'deliv_kana02',
						'deliv_pref',
						'deliv_zip01',
						'deliv_zip02',
						'deliv_addr01',
						'deliv_addr02',
						'deliv_tel01',
						'deliv_tel02',
						'deliv_tel03'
						);

		if(!document.form1['deliv_check'].checked) {
			fnChangeDisabled(list, '#dddddd');
		} else {
			fnChangeDisabled(list, '');
		}
	}
}

// 贈り主入力制限。
function fnCheckInputSender() {
	if(!document.form1) {
		return;
	}
	if(document.form1['sender_check']) {
		list = new Array(
						'sender_name01',
						'sender_name02',
						'sender_kana01',
						'sender_kana02',
						'sender_pref',
						'sender_zip01',
						'sender_zip02',
						'sender_addr01',
						'sender_addr02',
						'sender_tel01',
						'sender_tel02',
						'sender_tel03'
						);

		if(!document.form1['sender_check'].checked) {
			fnChangeDisabled(list, '#dddddd');
		} else {
			fnChangeDisabled(list, '');
		}
	}
}

// ついでに会員登録入力制限。
function fnCheckInputEntry() {
	if(!document.form1) {
		return;
	}
	if(document.form1['entry_check']) {
		list = new Array(
						'entry_flg',
						'password',
						'password02',
						'reminder',
						'reminder_answer',
						'mailmaga_flg'
						);

		if(!document.form1['entry_check'].checked) {
			fnChangeDisabled(list, '#dddddd');
		} else {
			fnChangeDisabled(list, '');
		}
	}
}


// 購入時会員登録入力制限。
function fnCheckInputMember() {
	if(document.form1['member_check']) {
		list = new Array(
						'password',
						'password_confirm',
						'reminder',
						'reminder_answer'
						);

		if(!document.form1['member_check'].checked) {
			fnChangeDisabled(list, '#dddddd');
		} else {
			fnChangeDisabled(list, '');
		}
	}
}

// 最初に設定されていた色を保存しておく。
var g_savecolor = new Array();

function fnChangeDisabled(list, color) {
	len = list.length;

	for(i = 0; i < len; i++) {
		if(document.form1[list[i]]) {
			if(color == "") {
				// 有効にする。
				// フォームの要素がラジオボタンの場合も考慮
				input_type = "";
				if(document.form1[list[i]].length > 0){
					input_type =  document.form1[list[i]][0].type;
				}

				if(input_type == "radio"){
					form_len = document.form1[list[i]].length;

					for(j = 0; j < form_len; j++){
						list_elem = document.form1[list[i]][j];
						list_elem.disabled = false;
						list_elem.style.backgroundColor = g_savecolor[list[i]];
					}
				}else{
					document.form1[list[i]].disabled = false;
					document.form1[list[i]].style.backgroundColor = g_savecolor[list[i]];
				}

			} else {
				// 無効にする
				// フォームの要素がラジオボタンの場合も考慮
				input_type = "";
				if(document.form1[list[i]].length > 0){
					input_type =  document.form1[list[i]][0].type;
				}

				if(input_type == "radio"){

					form_len = document.form1[list[i]].length;

					for(j = 0; j < form_len; j++){
						list_elem = document.form1[list[i]][j];
						list_elem.disabled = true;
						list_elem.style.backgroundColor = color;//"#f0f0f0";
					}
					g_savecolor[list[i]] = list_elem.style.backgroundColor;

				}else{
					document.form1[list[i]].disabled = true;
					g_savecolor[list[i]] = document.form1[list[i]].style.backgroundColor;
					document.form1[list[i]].style.backgroundColor = color;//"#f0f0f0";
				}

			}
		}
	}
}


// ログイン時の入力チェック
function fnCheckLogin(formname) {
	var lstitem = new Array();

	if(formname == 'login_mypage'){
	lstitem[0] = 'mypage_login_email';
	lstitem[1] = 'mypage_login_pass';
	}else{
	lstitem[0] = 'login_email';
	lstitem[1] = 'login_pass';
	}
	var max = lstitem.length;
	var errflg = false;
	var cnt = 0;

	//　必須項目のチェック
	for(cnt = 0; cnt < max; cnt++) {
		if(document.forms[formname][lstitem[cnt]].value == "") {
			errflg = true;
			break;
		}
	}

	// 必須項目が入力されていない場合
	if(errflg == true) {
		alert('メールアドレス/パスワードを入力して下さい。');
		return false;
	}
}

// 時間の計測.
function fnPassTime(){
	end_time = new Date();
	time = end_time.getTime() - start_time.getTime();
	alert((time/1000));
}
start_time = new Date();

//親ウィンドウのページを変更する.
function fnUpdateParent(url) {
	// 親ウィンドウの存在確認
	if(fnIsopener()) {
		window.opener.location.href = url;
	} else {
		window.close();
	}
}

//特定のキーをSUBMITする.
function fnKeySubmit(keyname, keyid) {
	if(keyname != "" && keyid != "") {
		document.form1[keyname].value = keyid;
	}
	document.form1.submit();
}

//文字数をカウントする。
//引数1：フォーム名称
//引数2：文字数カウント対象
//引数3：カウント結果格納対象
function fnCharCount(form,sch,cnt) {
	document.forms[form][cnt].value= document.forms[form][sch].value.length;
}


// テキストエリアのサイズを変更する.
function ChangeSize(button, TextArea, Max, Min, row_tmp){

	if(TextArea.rows <= Min){
		TextArea.rows=Max; button.value="小さくする"; row_tmp.value=Max;
	}else{
		TextArea.rows =Min; button.value="大きくする"; row_tmp.value=Min;
	}
}

function alertMail(emailform){
	mailaddress = emailform.value;

	// メールアドレスの@から後ろをみる
	atfrom = mailaddress.lastIndexOf("@");
	if(atfrom != -1){

		domainStr = "hotmail.com";
		domainIndex = mailaddress.lastIndexOf(domainStr);
		if(domainIndex == -1){
			domainStr = "hotmail.co.jp";
			domainIndex = mailaddress.lastIndexOf(domainStr);
			if(domainIndex == -1){
				domainStr = "msn.com";
				domainIndex = mailaddress.lastIndexOf(domainStr);
				if(domainIndex == -1){
					return ;
				}
			}
		}

		if(atfrom < domainIndex && mailaddress.length == (domainStr.length + domainIndex)){
			alert("Hotmailをご使用の場合、ご注文確認メールが届かない場合がございます。\n他のメールアドレスで登録されることをおすすめします。");
		}

	}
}

function showCalendar(url){
	// w = window.open("about:blank", "calendar");
	var dt = new Date();
	document.search_form.target = "_blank";
	document.search_form.method = "POST";
	document.search_form.action = url + "?m=" + dt.getTime();
	document.search_form.submit();
}

// 表示時の個数計算
function setCartProduct(){
	quanIndexStr = "quan_";
	baseIndexStr = "base_";
	showIndexStr = "show_";
	len = document.form1.elements.length;
	arrId = new Array();

	for(i = 0; i < len; i++){
		if(document.form1.elements[i].name.indexOf(quanIndexStr) == 0 && document.form1.elements[i].type.indexOf("select") == 0){
			// 個数選択セレクトボックスの場合に処理をする
			show = document.form1.elements[i].name.substring(quanIndexStr.length, document.form1.elements[i].name.length);
			quan = show.substring(show.indexOf("_") + 1, show.length);

			// 各お届け先に表示しているカートの残り個数をリセットする
			document.getElementById(showIndexStr + show).innerHTML = document.form1[baseIndexStr + quan].value;

			// 後の計算ように要素のID名を保持
			arrId.push(showIndexStr + show);
		}
	}

	for(i = 0; i < len; i++){
		// 個数選択セレクトボックスの場合に処理をする
		if(document.form1.elements[i].name.indexOf(quanIndexStr) == 0 && document.form1.elements[i].type.indexOf("select") == 0){

			quan = document.form1.elements[i].name.substring(quanIndexStr.length, document.form1.elements[i].name.length);
			quan = quan.substring(quan.indexOf("_") + 1, quan.length);

			// 個数セレクトボックスの選択されている箇所
			var index = document.form1.elements[i].selectedIndex;

			len2 = arrId.length;

			for(j = 0; j < len2; j++){
				quanElem = arrId[j].substring(quanIndexStr.length, arrId[j].length);
				quanElem = quanElem.substring(quanElem.indexOf("_") + 1, quanElem.length);
				if(quan == quanElem){
					quanInt = parseInt(document.getElementById(arrId[j]).innerHTML);
					document.getElementById(arrId[j]).innerHTML = quanInt - document.form1.elements[i].options[index].value;
					document.getElementById(arrId[j]).style.color = "#ec0000";
					document.getElementById(arrId[j]).style.fontWeight = "bold";
				}
			}

		}
	}
}


// 選択時の商品個数の変更
function selectQuan(quanName){
	quanIndexStr = "quan_";
	baseIndexStr = "base_";
	showIndexStr = "show_";
	len = document.form1.elements.length;
	arrId = new Array();

	for(i = 0; i < len; i++){
		if(document.form1.elements[i].name.indexOf(quanIndexStr) == 0 && document.form1.elements[i].type.indexOf("select") == 0){
			// 個数選択セレクトボックスの場合に処理をする
			show = document.form1.elements[i].name.substring(quanIndexStr.length, document.form1.elements[i].name.length);
			quan = show.substring(show.indexOf("_") + 1, show.length);

			// 各お届け先に表示しているカートの残り個数をリセットする
			document.getElementById(showIndexStr + show).innerHTML = document.form1[baseIndexStr + quan].value;

			// 後の計算ように要素のID名を保持
			arrId.push(showIndexStr + show);
		}
	}

	for(i = 0; i < len; i++){
		// 個数選択セレクトボックスの場合に処理をする
		if(document.form1.elements[i].name.indexOf(quanIndexStr) == 0 && document.form1.elements[i].type.indexOf("select") == 0){

			quan = document.form1.elements[i].name.substring(quanIndexStr.length, document.form1.elements[i].name.length);
			quan = quan.substring(quan.indexOf("_") + 1, quan.length);

			// 個数セレクトボックスの選択されている箇所
			index = document.form1.elements[i].selectedIndex;

			len2 = arrId.length;

			for(j = 0; j < len2; j++){
				quanElem = arrId[j].substring(quanIndexStr.length, arrId[j].length);
				quanElem = quanElem.substring(quanElem.indexOf("_") + 1, quanElem.length);
				if(quan == quanElem){
					quanInt = parseInt(document.getElementById(arrId[j]).innerHTML);
					document.getElementById(arrId[j]).innerHTML = quanInt - document.form1.elements[i].options[index].value;
				}
			}

		}
	}
}

// チェックを入れると入力可。
function fnCheckVisible(checknm,disparea) {
	if(!document.form1) {
		return;
	}
	if(document.form1[checknm]) {
		if(!document.form1[checknm].checked) {
			var obj = document.getElementById(disparea);
			obj.className = 'nodisp';
		} else {
			var obj = document.getElementById(disparea);
			obj.className = '';
		}
	}
}