var DEBUG_FLG = false;
// ----------------------------------------------------------------
// 指定された文字列が、すべて全角の文字で構成されているかをチェック
// 戻り値 ：  TRUE  = 全角文字で構成されています
//            FALSE = １文字以上の半角文字が含まれています
// ----------------------------------------------------------------
function IsZenkaku(strCheckString) {
	if (strCheckString.search(/[｡-ﾟ]/) != -1 ) {
		// 半角カナが含まれている
		if ( DEBUG_FLG ) { alert("半角文字が含まれています"); }
		return false;
	} else {
		// すべて全角文字である
		return true;
	}
}
// ----------------------------------------------------------------
// 指定された文字列が、すべて半角カナ以外の文字で構成されているかをチェック
// 戻り値 ：  TRUE  = 半角カナは含まれていません
//            FALSE = １文字以上の半角カナが含まれています
// ----------------------------------------------------------------
function HanKanaCheck(strCheckString) {
	if (strCheckString.search(/[｡-ﾟ]/) != -1 ) {
		// 半角カナが含まれている
		if ( DEBUG_FLG ) { alert("半角カナが含まれています"); }
		return false;
	} else {
		// すべて全角カナである
		return true;
	}
}
// ----------------------------------------------------------------
// 指定された文字列が、すべて半角英数字で構成されているかをチェック
// 戻り値 ：  TRUE  = すべて半角英数字で構成されています
//            FALSE = １文字以上の半角英数字以外の文字が含まれています
// ----------------------------------------------------------------
function AsciiCheck(strCheckString) {

	if (strCheckString.search(/[^A-Za-z0-9\ ]/) != -1) {
		// 半角英数字以外の文字列を含む
		if ( DEBUG_FLG ) { alert("半角英数字以外の文字が含まれています"); }
		return false;
	} else {
		// 半角英数字のみ
		return true;
	}
}
// ----------------------------------------------------------------
// 指定された文字列が、すべて半角数字で構成されているかをチェック
// 戻り値 ：  TRUE  = すべて半角数字で構成されています
//            FALSE = １文字以上の半角数字以外の文字が含まれています
// ----------------------------------------------------------------
function AsciiNumCheck(strCheckString) {
	if ( strCheckString.search(/[^0-9]/) != -1) {
		// 半角数字以外の文字列を含む
		if ( DEBUG_FLG ) { alert("半角数字以外の文字が含まれています"); }
		return false;
	} else {
		// 半角数字のみ
		return true;
	}
}
// ----------------------------------------------------------------
// 指定された文字列が、すべて全角カナで構成されているかをチェック
// 戻り値 ：  TRUE  = すべて全角カナで構成されています
//            FALSE = １文字以上の全角カナ以外の文字が含まれています
// ----------------------------------------------------------------
function ZenKanaCheck(strCheckString) {
	if (strCheckString.search(/[^ァ-ヶ\　ー]/) != -1 ) {
		// 全角カナ以外が含まれている
		if ( DEBUG_FLG ) { alert("全角カナ以外の文字が含まれています"); }
		return false;
	} else {
		// すべて全角カナである
		return true;
	}
}
// ----------------------------------------------------------------
// 指定された文字列が、正しいメールアドレスの書式であるかをチェック
// 戻り値 ：  TRUE  = 指定された文字列は、正しいメールアドレスの書式で構成されています
//            FALSE = 正しいメールアドレスの書式で構成されていません
// ----------------------------------------------------------------
function EmailCheck( strCheckString ) {

	if ( strCheckString.value == '' ) {
		return true;
	}

	// 指定された文字列中に＠が指定されているかチェック。
	if ( strCheckString.indexOf("@") == -1 ) {
		// ＠が指定されていません。
		if ( DEBUG_FLG ) { alert("文字列中に＠が、含まれていません"); }
		return false;
	}

	// 先頭文字列or最終文字列が@or.かチェック
	if( strCheckString.charAt(0) == '@'
	 || strCheckString.charAt(strCheckString.length-1) == '@'
	 || strCheckString.charAt(0) == '.'
	 || strCheckString.charAt(strCheckString.length-1) == '.' ){
		// 先頭文字列or最終文字列が@or.です。
		if ( DEBUG_FLG ) { alert("先頭文字列or最終文字列が@or."); }
		return false;
	}

	// 最後の@以降に存在する.の個数が1個以上か
	if ( strCheckString.substring(strCheckString.lastIndexOf("@")+1).search(/^.*\..*$/) == -1 ) {
		// 最後の@以降に存在する.の個数が1個以下である
		if ( DEBUG_FLG ) { alert("最後の@以降に存在する.の個数が1個以下"); }
		return false;
	}

return true;
}
// ----------------------------------------------------------------
// 指定された文字列が、正しい郵便番号の書式であるかをチェック（ハイフンは含まないという前提です）
// 戻り値 ：  TRUE  = 指定された文字列は、正しい郵便番号の書式で構成されています
//            FALSE = 正しい郵便番号の書式で構成されていません
// ----------------------------------------------------------------
function ZipcodeCheck( strCheckString ) {

	// 郵便番号(ハイフンあり)正規表現チェック。
	if ( strCheckString.search(/^[0-9]{3}\-[0-9]{4}$/) == -1 ) {
		if ( DEBUG_FLG ) { alert("郵便番号の記述が正しくありません。"); }
		return false;
	}

	if ( strCheckString == "000-0000" || strCheckString == "999-9999" ) {
		if ( DEBUG_FLG ) { alert("[000-0000] および [999-9999]で構成されています"); }
		return false;
	}

	return true;
}
// ----------------------------------------------------------------
// 指定された年月日が、有効な日付であるかをチェック
// 戻り値 ：  TRUE  = 指定された年月日は、存在する日付です
//            FALSE = 存在しない日付が指定されています
// ----------------------------------------------------------------
function DateCheck( strYear, strMonth, strDay ) {

	// 月に対応する日数の配列を作成します。
	var maxday = new Array(0,31,28,31,30,31,30,31,31,30,31,30,31);

	// 指定されている文字が、すべて数字かチェック。
	if 			( ! AsciiNumCheck(strYear) || ! AsciiNumCheck(strMonth) || ! AsciiNumCheck(strDay) ) {
		if ( DEBUG_FLG ) { alert("半角数字以外の文字が指定されています"); }
		return false;
	}
	// 年の範囲チェック
	if ( ! ( Number(strYear) >= 1850 && Number(strYear) <= 2050 ) ) {
		if ( DEBUG_FLG ) { alert("年が有効範囲を超えています"); }
		return false;
	}
	// 月の範囲チェック
	if ( ! ( Number(strMonth) >= 1 && Number(strMonth) <= 12 ) ) {
		if ( DEBUG_FLG ) { alert("存在しない月を指定しています"); }
		return false;
	}

	// 閏年の判定
	if ((( Number(strYear) % 4 == 0) && ( Number(strYear) % 100 != 0)) || ( Number(strYear) % 400 == 0))
	{	maxday[2] = 29;	}
	// 日の範囲チェック
	if ( ! ( Number(strDay) >= 1 && Number(strDay) <= maxday[Number(strMonth)] ) ) {
		if ( DEBUG_FLG ) { alert("指定した月に存在しない日を指定しています"); }
		return false;
	}

	return true;
}
// ----------------------------------------------------------------
// 指定された年月日が、有効な日付であるかをチェック
// 戻り値 ：  TRUE  = 指定された年月日は、存在する日付です
//            FALSE = 存在しない日付が指定されています
// ----------------------------------------------------------------
function DateCheck2( checkstring ) {

	// 日付を分けます。
	datest = checkstring.split("/");

	if ( datest.length != 2 && datest.length != 3 ) {
		if ( DEBUG_FLG ) { alert("指定した日付の書式が正しくありません"); }
		return false;
	}
  if ( datest[1].length != 2 || datest[2].length != 2 ){
    if ( DEBUG_FLG ) { alert("日付は'YYYY/MM/DD'形式で指定してください。例)2001/07/01"); }
    return false;
  }
	if ( datest.length == 3 ) {

		if ( ! AsciiNumCheck(datest[0]) || ! AsciiNumCheck(datest[1]) || ! AsciiNumCheck(datest[2]) ) {
			if ( DEBUG_FLG ) { alert("指定した日付の書式が正しくありません"); }
			return false;
		}

		return ( DateCheck(datest[0], datest[1], datest[2]) );
	
	}else{

		if ( ! AsciiNumCheck(datest[0]) || ! AsciiNumCheck(datest[1]) ) {
			if ( DEBUG_FLG ) { alert("指定した日付の書式が正しくありません"); }
			return false;
		}

		nowst = new Date();
		datest[3] = "0" + (1900 + (nowst.getYear() % 1900));
		return ( DateCheck( datest[3], datest[0], datest[1]) );

	}
	
}
// ----------------------------------------------------------------
// 指定された年月日が、休日・祝日であるかをチェック
// 戻り値 ：  -1   = 指定された日付は、休日および祝日です
//             0   = 指定された日付は、平日です
//             1   = 有効な日付が指定されていません
// ----------------------------------------------------------------
function DateHolidayCheck( strYear, strMonth, strDay ) {

	// 日付の有効性チェック
	if ( ! DateCheck( strYear, strMonth, strDay ) ) {
		return 1;
	}

	// 日付の有効性チェック
	if ( Date(strYear + "/" + strMonth + "/" + strDay).getDay == 0 ) {
		return -1;
	}

	// 国民の祝日セット
	Holidays			= new Array();
	Holidays[0]		= strYear + "/01/02";
	Holidays[1]		= strYear + "/01/15";
	if (strYear >= 2000) {
		WorkDate = new Date(strYear + "/01/01");
		if (WorkDate.getDay() <= 1) {
			Holidays[1] = strYear + "/01/" + (7 + (2 - WorkDate.getDay()));
		} else {
			Holidays[1] = strYear + "/01/" + (14 - (WorkDate.getDay() - 2));
		}
	}
	Holidays[2]		= strYear + "/02/11";
	Holidays[3] 	= strYear + "/03/" +  Math.floor(20.8431 + 0.242194 * (Number(strYear) - 1980) - Math.floor((Number(strYear) - 1980)/4));
	Holidays[4]		= strYear + "/04/29";
	Holidays[5]		= strYear + "/05/03";
	Holidays[6]		= strYear + "/05/04";
	Holidays[7]		= strYear + "/05/05";
	Holidays[8]		= strYear + "/07/20";
	Holidays[9]		= strYear + "/09/15";
	Holidays[10] 	= strYear + "/09/" +  Math.floor(23.2488 + 0.242194 * (Number(strYear) - 1980) - Math.floor((Number(strYear) - 1980)/4));
	Holidays[11]	= strYear + "/10/10";
	if (strYear >= 2000) {
		WorkDate = new Date(strYear + "/10/01");
		if (WorkDate.getDay() <= 1) {
			Holidays[11] = strYear + "/10/" + (7 + (2 - WorkDate.getDay()));
		} else {
			Holidays[11] = strYear + "/10/" + (14 - (WorkDate.getDay() - 2));
		}
	}
	Holidays[12]	= strYear + "/11/03";
	Holidays[13]	= strYear + "/11/23";
	Holidays[14]	= strYear + "/12/23";

	// 振替休日の自動計算
	for (i = 0; i < Holidays.length; i++) {
		WorkDate = Date(Holidays[i]);
		if ( WorkDate.getDay() == 0 ) {
			Holidays[i] = (1900 + (WorkDate.getYear() % 1900)) + "/" + ( WorkDate.getMonth() + 1 ) + "/" + ( WorkDate.getDate() + 1 );
		}
		// 休日・祝日の判定
		if ( WorkDate == Date(strYear + "/" + strMonth + "/" + strDay) ) {
			return -1;
		}
	}
	return 0;
}
// ----------------------------------------------------------------
// 指定された文字列が、住所で使用できる文字で構成されているかをチェック
// 戻り値 ：  TRUE  = 住所で使用できる文字列で構成されています
//            FALSE = 使用できない文字が１文字以上含まれています
// ----------------------------------------------------------------
function AddressCheck(strCheckString) {

	if ( strCheckString.search(/[!-+:-@\[-`\x7b-\xff｡-ﾟ]/) != -1 ) {
		if ( DEBUG_FLG ) { alert("使用できない文字が含まれています"); }
		return false;
	}
	return true;

}
// ----------------------------------------------------------------
// 指定された年月日から、指定された年数・月数・日数を計算します
// 戻り値 ：  計算された日付（日付型）
//				：	失敗＝NULL
// ----------------------------------------------------------------
function DateSerial( DateString, iYear, iMonth, iDay ) {

	if ( ! DateCheck2( DateString ) ) {
		return null;
	}

	// 日付を分けます。
	datest = DateString.split("/");
	if ( datest.length == 2 ) {
		nowst = new Date();
		datest[2] = datest[1];
		datest[1] = datest[0];
		datest[0] = "0" + (1900 + (nowst.getYear() % 1900));
	}
	
	nextdate = new Date(Number(datest[0]) + iYear, Number(datest[1]) + iMonth - 1, Number(datest[2]) + iDay);
	if ( DEBUG_FLG ) { alert( (1900 + (nextdate.getYear() % 1900)) + "/" + nextdate.getMonth() + "/" + nextdate.getDate() ); }

	return nextdate ;

}

// ----------------------------------------------------------------
// 指定された文字列が、正しい郵便番号の書式であるかをチェック（文字種類及び文字数のみ）
// 戻り値 ：  TRUE  = 指定された文字列は、正しい郵便番号の書式で構成されています
//            FALSE = 正しい郵便番号の書式で構成されていません
// ----------------------------------------------------------------
function chkform_zip(){
    chkflg = true;
    src_zip = document.FRM_ORDER_ZIP.ZIP.value;
    document.FRM_ORDER_ZIP.ZIP.value = src_zip.replace("　","");
    if( document.FRM_ORDER_ZIP.ZIP.value  == ""){
        alert("検索条件を入力してください。");
        chkflg = false;
    }else{

//20100616 保守案件EC-256 郵便番号ハイフン無し対応 start
    if(document.FRM_ORDER_ZIP.ZIP.value.length == 7 && document.FRM_ORDER_ZIP.ZIP.value.match(/^[\d]+$/)){
    	document.FRM_ORDER_ZIP.ZIP.value = document.FRM_ORDER_ZIP.ZIP.value.slice(0,3) + "-" + document.FRM_ORDER_ZIP.ZIP.value.slice(3);
    }
//20100616 保守案件EC-256 郵便番号ハイフン無し対応 end

        if ( ! ZipcodeCheck(document.FRM_ORDER_ZIP.ZIP.value)) {
//20100616 保守案件EC-256 郵便番号ハイフン無し対応 start
            //alert("郵便番号は「xxx-xxxx」の形式で入力してください。");
            alert("郵便番号は「xxx-xxxx」、又は「xxxxxxx」の形式で入力してください。");
//20100616 保守案件EC-256 郵便番号ハイフン無し対応 end
            chkflg = false;
        }
    }
    if ( !chkflg ) {
        document.FRM_ORDER_ZIP.ZIP.focus();
    }
    return chkflg;
}

// ----------------------------------------------------------------
// 指定された文字列が、正しい店舗名の書式であるかをチェック
// 戻り値 ：  TRUE  = 指定された文字列は、正しい店舗名の書式で構成されています
//            FALSE = 正しい店舗名の書式で構成されていません
// ----------------------------------------------------------------
function chkform_shopname(){
    chkflg = true;
    src_name = document.FRM_SHOP_NAME.SRC_SHOP_NAME.value;
    if ( document.FRM_SHOP_NAME.SRC_SHOP_NAME.value == '' ) {
        alert("検索条件を入力してください。");
        chkflg = false;
    }else if ( document.FRM_SHOP_NAME.SRC_SHOP_NAME.length > 30 ) {
        alert("店舗名は、３０文字以上は指定できません。");
        chkflg = false;
    }else if( ! IsZenkaku(document.FRM_SHOP_NAME.SRC_SHOP_NAME.value) ) {
        alert("店舗名は全て全角で入力してください。");
        chkflg = false;
    }
    if ( !chkflg ) {
        document.FRM_SHOP_NAME.SRC_SHOP_NAME.focus();
    }
    return chkflg;
}

// ----------------------------------------------------------------
// 指定された文字列が、正しい都道府県の書式であるかをチェック
// 戻り値 ：  TRUE  = 指定された文字列は、正しい都道府県の書式で構成されています
//            FALSE = 正しい都道府県の書式で構成されていません
// ----------------------------------------------------------------
function chkform_selectpref(){
    chkflg = true;
    if( document.FRM_PREF.PREF_CD.value == '') {
        alert("都道府県を選択してください。");
        chkflg = false;
    }
    if ( !chkflg ) {
        document.FRM_PREF.PREF_CD.focus();
    }
    return chkflg;
}

// ----------------------------------------------------------------
// 指定された文字列が、正しい電話番号の書式であるかをチェック（国際表記対応）。
// 戻り値 ：  TRUE  = 指定された文字列は、正しい電話番号の書式で構成されています
//            FALSE = 正しい電話番号の書式で構成されていません
// ----------------------------------------------------------------
function TelephoneCheck( strCheckString ) {

	if ( strCheckString.value == '' ) {
		return true;
	}

	//先頭が'+'である場合
	if ( strCheckString.slice(0, 1) == '+' ) {
		//先頭の'+'を削除する
		strCheckString = strCheckString.slice(1);
	}

	// 指定された文字列がすべて半角数字およびハイフンかをチェック。
	if ( strCheckString.search(/[^0-9\-]/) != -1 ) {
		if ( DEBUG_FLG ) { alert("数字およびハイフン以外の文字が含まれています"); }
		return false;
	} else if(strCheckString.length > 16){
		if ( DEBUG_FLG ) { alert("文字数が16文字を超えています"); }
		return false;
	}

	return true;
}