// お気に入り登録
function touroku(url, msg) {
  if (window.external) {
    window.external.AddFavorite(url, msg);
  } else {
    alert("Internet Explorer 4.0 以降でのみ使用可能です。");
  }
}

// アクセス解析
// トップページ
function access() {
	document.write("<p align=center><a href=http://cgi.members.interq.or.jp/ox/groove/cgi_bin/access/access.cgi?vew>");
	document.write("<img src=http://cgi.members.interq.or.jp/ox/groove/cgi_bin/access/access.cgi?" + document.referrer + " width=1 height=1 border=0></a></p>");
}
// 加盟店登録画面
function access_rec() {
	document.write("<p align=center><a href=http://cgi.members.interq.or.jp/ox/groove/cgi_bin/access_rec/access.cgi?vew>");
	document.write("<img src=http://cgi.members.interq.or.jp/ox/groove/cgi_bin/access_rec/access.cgi?" + document.referrer + " width=1 height=1 border=0></a></p>");
}

// ボタン制御

// ログアウト
function rogoutBtn() {
	document.forms[0].action = "Logout.do";
	document.forms[0].submit();
}
// 会員登録規約同意しない
function noTermsBtn() {
	document.forms[0].action = "/tokudanebijin/Init.do";
	document.forms[0].submit();
}
// 会員登録規約同意
function okTermsBtn() {
	document.forms[0].action = "/tokudanebijin/RegisterTerms.do";
	document.forms[0].submit();
}
// トップページへ戻る
function initBtn() {
	document.forms[0].action = "Init.do";
	document.forms[0].submit();
}
// 会員情報変更
function registerChangeBtn() {
	document.forms[0].action = "RegisterChange.do";
	document.forms[0].submit();
}
// キャンセル(前画面へ遷移)
function cancelBtn(act) {
	document.forms[0].action = act;
	document.forms[0].submit();
}


/**
 * トリム
 *
 * @param str チェック対象文字列
 * @return トリム後の文字列
 */
function trim(str) {
    str = str.replace(/^\s+|[\s　]$/g, "");
	return(str);
}

/**
 * 引数の値がNULLや空文字でないかをチェックする.
 * 入力値前方･後方の半角スペース・全角スペースを切り捨てる.
 *
 * @param str チェックする文字
 * @return NULLでも空文字でもない場合はtrue
 **/
function checkNotNull(str) {
	str = trim(str);
    if ((str != null) && (str != "")) {
        return true;
    }
    return false;
}

/**
 * 必須入力チェック.
 *
 * @param str チェックする文字
 * @param itemName チェックするオブジェクト名
 * @return 入力値が半角SPと全角SP以外場合はtrue
 **/
function validateRequired(str, itemName) {
	if (checkNotNull(str) == true) {
		return true;
	}
	alert(itemName + "は、必須項目です。");
	return false;
}

/**
 * 必須入力チェック(2つの項目のうち、どちらかは必須の場合）.
 *
 * @param str チェックする文字
 * @param str2 チェックする文字
 * @param itemName チェックするオブジェクト名
 * @param itemName2 チェックするオブジェクト名
 * @return 入力値が半角SPと全角SP以外場合はtrue
 **/
function validateRequired2(str, str2, itemName, itemName2) {

	if (checkNotNull(str) == true || checkNotNull(str2) == true) {
	   return true;
	}
	alert(itemName + "または、" + itemName2 + "のいづれかは必須項目です。");
	return false;
}

/**
 * 半角英数チェック.
 *
 * @param str チェック対象文字列
 * @param itemName チェックするオブジェクト名
 * @return 文字列が半角英数字のみであればtrue
 */
function validateHalfAlphanumeric(str, itemName) {
	str = trim(str);	
	var c = new RegExp();
	c = /^[A-Za-z0-9\ ]*$/;
	if (c.test(str)) {
		return true;
	}
	alert(itemName + "は、半角英数字で入力して下さい。");
	return false;
}

/**
 * 半角英数チェック(メール用).
 * 
 * .(ピリオド)、_(アンダースコア)、-(ハイフン)は容認
 * @param str チェック対象文字列
 * @param itemName チェックするオブジェクト名
 * @return 文字列が半角英数字のみであればtrue
 */
function validateHalfAlphanumericMail(str, itemName) {
	str = trim(str);	
	var c = new RegExp();
	c = /^[A-Za-z0-9.@_\-\ ]*$/;
	if (c.test(str)) {
		return true;
	}
	alert(itemName + "は、半角英数字で入力して下さい。");
	return false;
}

/**
 * 全角文字チェック.
 *
 * @param str チェック対象文字列
 * @param itemName チェックするオブジェクト名
 * @return 文字列が全角文字のみであればtrue
 */
function validateZenkaku(str, itemName) {
	str = trim(str);	
	var c = new RegExp();
	c = /^[A-Za-z0-9ｱ-ﾝ\ ]*$/;
	if (c.test(str)) {
        alert(itemName + "は、全角文字で入力して下さい。");
		return false;
	}
	return true;
}

/**
 * ふりがなチェック
 *
 * @param str チェック対象文字列
 * @param itemName チェックするオブジェクト名
 * @return 文字列が全角文字のみであればtrue
 */
function validateFurigana(str, itemName) {
   if( str.match( /[^ア-ン　\s]+/ ) ) {
      alert(itemName + "は、全角カタカナのみで入力して下さい。");
      return false;
   }
   return true;
}

/**
 * 半角数字チェック
 *
 * @param str チェック対象文字列
 * @param itemName チェックするオブジェクト名
 * @return 文字列が半角数字のみであればtrue
 */
function validateNumber(str, itemName) {
    if( str.match( /[^0-9]+/ ) ) {
        alert(itemName + "は、半角数字のみで入力して下さい。");
        return false;
    }
    return true;
}

/**
 * 半角数字チェック
 *
 * @param str チェック対象文字列
 * @param itemName チェックするオブジェクト名
 * @return 文字列が半角数字のみ(カンマは可)であればtrue
 */
function validateNumberAndComma(str, itemName) {
    if( str.match( /[^0-9,]+/ ) ) {
        alert(itemName + "は、半角数字のみで入力して下さい。");
        return false;
    }
    return true;
}

/**
 * 半角数字チェック(電話用)
 *
 * @param str チェック対象文字列
 * @param itemName チェックするオブジェクト名
 * @return 文字列が半角数字のみであればtrue
 */
function validateNumberTel(str, itemName) {
    if( str.match( /[^0-9-]+/ ) ) {
        alert(itemName + "は、半角数字のみで入力して下さい。");
        return false;
    }
    return true;
}

/**
 * 固定電話チェック
 *
 * 許可する形式
 * 999-9999-9999
 * 999-999-9999
 * 9999-99-9999
 * 99-9999-9999
 * 9999-999-999
 *
 * @param str チェック対象文字列
 * @param itemName チェックするオブジェクト名
 * @return 文字列が半角数字のみであればtrue
 */
function validatePhone(str, itemName) {
	if(!str.match(/^\d{3}-\d{4}-\d{4}$|^\d{11}$|^\d{3}-\d{3}-\d{4}$|^\d{10}$|^\d{4}-\d{2}-\d{4}$|^\d{10}$|^\d{2}-\d{4}-\d{4}$|^\d{10}$|^\d{4}-\d{3}-\d{3}$|^\d{10}$/)) {
      alert(itemName + "の番号が不正です。");
      return false;
   }
   return true;
}

/**
 * 携帯番号チェック
 *
 * @param str チェック対象文字列
 * @param itemName チェックするオブジェクト名
 * @return 文字列が半角数字のみであればtrue
 */
function validateMobile(str, itemName) {
	if(!str.match(/^\d{3}-\d{4}-\d{4}$|^\d{11}$/)) {
        alert(itemName + "の番号が不正です。");
      return false;
   }
   return true;
}


/* 桁数チェック
 *
 * @param str チェック対象文字列
 * @param size 桁数
 * @param itemName チェックするオブジェクト名
 * @return 文字列が桁数と等価であればtrue
 */
function isNumDigit(str, size, itemName) {
    len = str.length;
    if(size != len) {
        alert(itemName + "は、" + size + "桁で入力して下さい。");
        return false;
    }
    return true;
}

/* 桁数チェック
 *
 * @param str チェック対象文字列
 * @param min 最小値桁数
 * @param max 最大値桁数
 * @param itemName チェックするオブジェクト名
 * @return 文字列が桁数範囲であればtrue
 */
function isNumDigitRange(str, min, max, itemName) {
    len = str.length;
    if(min < len && max < len) {
        alert(itemName + "は、" + min + "桁 〜 " + max + "桁の範囲で入力して下さい。");
        return false;　
    }
    return true;
}

/* 桁数チェック
 *
 * @param str チェック対象文字列
 * @param min 最小値桁数
 * @param itemName チェックするオブジェクト名
 * @return 文字列が桁数以上であればtrue
 */
function isNumDigitRangeMin(str, min, itemName) {
    len = str.length;
    if(min > len) {
        alert(itemName + "は、" + min + "桁以上で入力して下さい。");
        return false;
    }
    return true;
}

/** 
 * 文字列が全角特殊文字で構成されているかチェックします.
 *
 * @param str チェック対象文字
 * @return 全角特殊文字で構成されていれば true
 */
function checkMultiByteSpecialChar(str) {
	var c = new RegExp();
	// 修飾数字
	c = /[\@\A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S]+/;
	if (c.test(str)) {
		return true;
	} else {
		// ローマ数字
		c = /[\T\U\V\W\X\Y\Z\[\\\]]+/;
		if (c.test(str)) {
			return true;
		} else {
			// 単位
			c = /[\_\`\a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u]+/;
			if (c.test(str)) {
				return true;
			} else {
				// 省略文字、通貨単位、学術単位、その他
				c = /[\\ソЫ\\\\噂浬欺圭構蚕十~\\―貼能禄兢+/;
				if (c.test(str)) {
					return true;
				} else {
					return false;
				}
			}
		}
	}
}

/** 
 * 文字列が半角特殊文字で構成されているかチェックします.
 *
 * @param str チェック対象文字
 * @return 半角特殊文字で構成されていれば true
 */
function checkSingleByteSpecialChar(str) {
	var c = new RegExp();
	// 半角カナ
	c = /[\ｱ\ｲ\ｳ\ｴ\ｵ\ｶ\ｷ\ｸ\ｹ\ｺ\ｻ\ｼ\ｽ\ｾ\ｿ\ﾀ\ﾁ\ﾂ\ﾃ\ﾄ\ﾅ\ﾆ\ﾇ\ﾈ\ﾉ\ﾊ\ﾋ\ﾌ\ﾍ\ﾎ]+/;
	if (c.test(str)) {
		return true;
	} else {
		// 半角カナと記号
		c = /[\ﾏ\ﾐ\ﾑ\ﾒ\ﾓ\ﾔ\ﾕ\ﾖ\ﾗ\ﾘ\ﾙ\ﾚ\ﾛ\ﾜ\ｦ\ﾝ\ｧ\ｨ\ｩ\ｪ\ｫ\ｬ\ｭ\ｮ\ｯ\ｰ\｡\｢\｣\､\･\ﾞ\ﾟ]+/;
		if (c.test(str)) {
			return true;
		} else {
			return false;
		}
	}
}

/**
 * 使用禁止文字チェック.
 *
 * @param str チェック対象文字列
 * @param itemName チェックするオブジェクト名
 * @return 使用禁止文字が含まれていない場合 ⇒ true
 */
function validateSpecialChar(str, itemName) {
	if (!checkNotNull(str)) {
		return true;
	}
	str = trim(str);
	if (checkSingleByteSpecialChar(str) == false &&
		checkMultiByteSpecialChar(str) == false) {
		return true;
	} else {
		alert("『" + itemName + "』に以下のいづれかの使用禁止文字が含まれています。\n\n@ABCDEFGHIJKLMNOPQRS\nTUVWXYZ[\]\n_`abcdefghijklmn\nopqrstuｇョх援括窮欠合紫順~\n∞島這匆｡｢｣､ﾞﾟ");
		return false;
	}
}

/* 再確認のチェック
 *
 * @param str チェック対象文字列
 * @param str2 チェック対象文字列
 * @param itemName チェックするオブジェクト名
 * @return 双方の文字列が同じであればtrue
 */
function reconfirCheck(str, str2, itemName) {
    if(str != str2) {
        alert(itemName + "が確認用と一致していません。");
        return false;
    }
    return true;
}

/**
 * ラジオボタン選択チェック
 *
 * @param obj エレメンツ名
 * @param itemName エラーメッセージに出力する項目名
 **/
function selectRadioBox(obj, itemName) {
    var flg = false;
    // 選択チェック
	for(i = 0; i < obj.length; i++){
		if (obj[i].checked){
            flg = true;
		}
	}
	if(!flg){
		alert(itemName + "にチェックをしてください。");
		return false
	}
    return true;
}

/**
 * メールアドレスチェック
 *
 * @param str チェック対象文字列
 * @param itemName エラーメッセージに出力する項目名
 **/
function mailCheck(str, itemName)　{
	if (!str.match(/^\S+@\S+\.\S+$/)) {
		alert(itemName + "が正しくありません。");
		return false;
    }
    return true;
}

/**
 * 日付の妥当性チェック
 * @param year 年
 * @param month 月
 * @param date 日
 */
function checkDate(year, month, date, itemName) {
    var dt = new Date(year, month - 1, date);
    if(dt == null || dt.getFullYear() != year || dt.getMonth() + 1 != month || dt.getDate() != date) {
        alert(itemName + "が正しくありません。選択した月末日などを再度ご確認下さい。");
        return false;
    }
    return true;
}

/**
 * 日付の比較チェック
 * @param yearS 始年
 * @param monthS 始月
 * @param dateS 始日
 * @param yearE 終年
 * @param monthE 終月
 * @param dateE 終日
 */
function checkSymdToEymd(yearS, monthS, dateS, yearE, monthE, dateE, itemName) {
	var dt1 = new Date(yearS, monthS - 1, dateS);
	var dt2 = new Date(yearE, monthE - 1, dateE);
	if(dt1.getTime() > dt2.getTime()) {
        alert(itemName + "の始年月日が終年月日より未来です。");
        return false;
	}
    return true;
}

/**
 * 任意の日付の曜日を取得
 * @param year 年
 * @param month 月
 * @param date 日
 */
function getDay(year, month, date) {
	var week = new Array("日", "月", "火", "水", "木", "金", "土");
	var dt = new Date(year, month - 1, date);
    if (dt == null) {
        return false;
    }
	return week[dt.getDay()];
}

/**
 * 日付の比較チェック
 * @param year 始年
 * @param month 始月
 * @param date 始日
 */
function checkReservaDate(year, month, date, itemName) {
	var dt1 = new Date(year, month - 1, date);
    var dt2 = new Date();
	if(dt1.getTime() < dt2.getTime()) {
        alert(itemName + "は、本日を含め過去日の予約は出来ません。");
        return false;
	}
    return true;
}


/**
 * URLチェック
 * @param value URL
 */
function checkUrl(value) {
	data = value.match(/(http|ftp):\/\/.+/);
	if (!data) {
        alert("URLが正しくありません。");
        return false;
    }
    return true;
}

/**
 * カンマ挿入関数
 * @param value 金額等
 */
function insertComma(value) {
    var destStr = value;
    var tmpStr = "";
    while (destStr != (tmpStr = destStr.replace(/^([+-]?\d+)(\d\d\d)/,"$1,$2"))) {
        destStr = tmpStr;
    }
    return destStr;
}

/**
 * カンマを取り外します
 * @param value カンマ付き金額等
 */
function delComma(value) {
    return value.split(",").join("");
}

/**
 * 画像の縦横比を変えずに画像縮小をします。
 * @param max_width 横幅最大値
 * @param max_height 縦幅最大値
 * @param picFlg className判定フラグ
 */
function keep_max(max_width, max_height, picFlg) {
	for (i in document.images) {
		if (document.images[i].className != picFlg)
            continue;
		if (document.images[i].width > document.images[i].height && document.images[i].width > max_width) {
			document.images[i].width = max_width ;
		} else {
			if (document.images[i].height > max_height) {
                document.images[i].height = max_height;
            }
		}
	}
}

/**
 * 入力範囲の比較チェック
 * @param max 最大値
 * @param param チェックパラメータ
 * @param itemName maxの部品名
 * @param itemName2 paramの部品名
 */
function checkFrame(max, param, itemName, itemName2) {
    if (parseInt(max) < parseInt(param)) {
		alert(itemName2 + "は、" + itemName + "数の範囲内で入力して下さい。");
		return false;
    }
    return true;
}

/**
 * 入力文字チェック
 * textフィールドのonkeyup用
 * 数値とバックスペース、リターン、タブ、デリート(keyCode=46)のみOK
 */
function checkNum() {
	var c = String.fromCharCode(event.keyCode);
    var k = window.event.keyCode;
	if ("0123456789\b\r\t".indexOf(c,0) < 0 && k != 46 ) {
        alert("数値以外入力できません。");
        return false;
    }
    return true;
}


/**
 * 文字化け対策
 * 住所登録１ー２ー３などのハイフン文字化け対応
 */
function changeHyphen(value) {
    var word = value;
    var tmpWord = "";
    //while (word != (tmpWord = word.replace("〜", " - "))) {
    //    word = tmpWord;
    //}
    while (word != (tmpWord = word.replace("―", "-"))) {
        word = tmpWord;
    }
    //while (word != (tmpWord = word.replace("−", "-"))) {
    //    word = tmpWord;
    //}
    //while (word != (tmpWord = word.replace("･", "・"))) {
    //    word = tmpWord;
    //}
    return word;
}

/**
 * 文字化け対策
 * 「\」 ⇒ 「￥」へ文字化け対応
 */
function changeYen(value) {
    var word = value;
    var tmpWord = "";
    while (word != (tmpWord = word.replace(/\\|\\/g,"￥"))) {
        word = tmpWord;
    }
    return word;
}

/**
 * enterキー押下時のイベント設定
 */
function enter(){
    // サイトトップ画面で、検索テキストフィールドに値があり、
    // enterキーが押下された場合は、検索画面へ飛ぶ
    if (document.forms[0].word.value != "") {
        searchFindIndexBtn(0);
    }
	return false;
}