
/* ===============================================
 * 機　能：年月より日付を設定する。
 * 用　法：set_date( date_value, field )
 * 		     date_value:年月（YYYYMM）
 * 		     field: 設定するオブジェクト
 * 返し値：なし
 * Create on： 2006/04/11
 * Create by : Hirotaka Irinatsu
=============================================== */
function set_date(date_value, field, str_today) {
	var fyear = date_value.toString().substring(0, 4);
	var fmonth = date_value.toString().substring(4, date_value.toString().length);
	var fday = "";
	var date_array = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

	var fdays = date_array[fmonth-1];

	//うるう年対応
	if( fyear % 4 == 0 && fmonth == "02") {
		fdays = 29;
	}

	//未来日付非表示対応
	if( date_value.toString() == str_today.substring(0, 6) ) {
		fdays = str_today.substring(6, str_today.length) - 1;
	}

	//日付クリア
	for( i = field.length - 1; i >= 0 ; i-- ){
		field.options[i] = null;
	}

	//対象オブジェクトに日付を設定
	for(i = 0; i < fdays; i++){
		fday = i + 1;
		field.options[i] = new Option(fday.toString() + "日", i+1);
	}
}
/* ===============================================
 * 機　能：必須項目が入力済みかどうかチェック
 * 用　法：checkReqItem( field, label, focus )
 * 			 field: 確認フィールド
 * 			 label:ラベル名（チェック欄名）
 * 			 focus: true:フォーカスをあてる / false :フォーカスをあてない
 * 返し値：true : 入力済 / flase : 未入力
 * Create on： 2006/04/04
 * Create by : Hirotaka Irinatsu
=============================================== */
function checkReqItem( field, label, focus ) {
	if ( field.value == "" ) {
		alert( "「" + label + "」を入力してください。");
		if( focus != false ){
			field.focus();
		}
		return false;
	} else {
		return true;
	}
}

/* ===============================================
 * 機　能：半角英数字チェック
 * 用　法：checkAlphaNumeric( field, required label, focus )
 * 			field: 確認フィールド
 * 			label:ラベル名（チェック欄名）
 * 			focus: true:フォーカスをあてる / false :フォーカスをあてない
 * 返し値：ture : 半角英数字のみ / flase : 半角英数字以外
 * Create on： 2006/04/04
 * Create by : Hirotaka Irinatsu
=============================================== */
function checkAlphaNumeric( field, label, focus ) {
	var s = field.value;

	// 文字種チェック
	var alphaNumericChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	var i;
	for ( i = 0; i < s.length; i++ ) {
		if ( alphaNumericChars.indexOf( s.charAt( i ), 0 ) == -1 ) {
			alert( "「" + label + "」は半角英数字を入力してください。" );
			if( focus != false ){
				field.focus();
			}
			return false;
		}
	}
	
	return true;
}

/* ===============================================
 * 機　能：半角数字チェック
 * 用　法：checkNumeric( field, required label, focus )
 * 			field: 確認フィールド
 * 			label:ラベル名（チェック欄名）
 * 			focus: true:フォーカスをあてる / false :フォーカスをあてない
 * 返し値：ture : 半角数字のみ / flase : 半角数字以外
 * Create on： 2006/04/25
 * Create by : Yusaku Suzuki
=============================================== */
function checkNumeric( field, label, focus ) {
	var s = field.value;

	// 文字種チェック
	var NumericChars = "0123456789";
	var i;
	for ( i = 0; i < s.length; i++ ) {
		if ( NumericChars.indexOf( s.charAt( i ), 0 ) == -1 ) {
			alert( "「" + label + "」は半角数字を入力してください。" );
			if( focus != false ){
				field.focus();
			}
			return false;
		}
	}
	
	return true;
}

/* ===============================================
 * 機　能：全角文字かどうかチェック
 * 用　法：checkZenkaku( field, label, focus )
 * 			 field: 確認フィールド
 * 			 label:ラベル名（チェック欄名）
 * 			 focus: true:フォーカスをあてる / false :フォーカスをあてない
 * 返し値：true : 全角のみ / flase : 全角以外を含む
 * Create on： 2006/04/04
 * Create by : Hirotaka Irinatsu
=============================================== */
function checkZenkaku( field, label, focus ) {
	if( IsZenkaku(field.value) == false ){
		alert( "「" + label + "」は全角文字を入力してください。" );
		if( focus != false ){
			field.focus();
		}
		return false;
	}
	return true;
}

/* ===============================================
 * 機　能：全角であるかをチェックします。
 * 用　法：IsZenkaku( value )
 * 			value :	チェックする値
 * 返し値：true : 全角 / flase : 全角以外
 * Create on： 2006/04/04
 * Create by : Hirotaka Irinatsu
=============================================== */
function IsZenkaku( value ) {
	for (var i = 0; i < value.length; ++i) {
	var c = value.charCodeAt(i);
		if ( ( ( c >= 0x0 && c < 0x81 ) ||
				( c == 0xf8f0 ) ||
				( c >= 0xff61 && c < 0xffa0 ) ||
				( c >= 0xf8f1 && c < 0xf8f4 ) ) ) {

			return false;
		}
	}
	return true;
}

/* ===============================================
 * 機　能：ハイフン「-」を含む数字チェック
 * 用　法：checkZenkaku( field, label, focus )
 * 			 field: 確認フィールド
 * 			 label:ラベル名（チェック欄名）
 * 			 focus: true:フォーカスをあてる / false :フォーカスをあてない
 * 返し値：true : 入力済 / flase : 未入力
 * Create on： 2006/04/04
 * Create by : Hirotaka Irinatsu
=============================================== */
function checkNumericHyphen(field, label, focus) {
	var s = field.value;

	// 文字種チェック
	var alphaNumericChars = "0123456789-";
	var i;
	for ( i = 0; i < s.length; i++ ) {
		if ( alphaNumericChars.indexOf( s.charAt( i ), 0 ) == -1 ) {
			alert( "「" + label + "」は半角数字又は半角ハイフンのみを入力してください。" );
			if( focus != false ){
				field.focus();
			}
			return false;
		}
	}
	
	return true;
}

/* ===============================================
 * 機　能：入力項目の最大文字数を確認
 * 用　法：checkMaxByteSize( field, length, label, focus )
 * 			     field: 確認フィールド
 * 			     length: 最大文字数
 * 			     label:ラベル名（チェック欄名）
 * 			     focus: true:フォーカスをあてる / false :フォーカスをあてない
 * 返し値：ture : 最大文字数以下 / flase : 最大文字数以上
 * Create on： 2006/04/04
 * Create by : Hirotaka Irinatsu
=============================================== */
function checkMaxByteSize( field, length, label, focus ) {
	var s = field.value;
	var strLen = 0;
	for ( var i = 0; i < s.length; ++i ) {
		var sub = s.substring(i, i + 1);
		if( IsZenkaku(sub) ){	//全角の場合2バイト追加。
			strLen += 2;
		} else {
			strLen += 1;
		}
	}
	if ( strLen > length ) {
		alert( "「" + label + "」は" + length + "文字以内で入力してください。" );
		if( focus != false ){
			field.focus();
		}
		return false;
	}
	return true;
}

/* ===============================================
 * 機　能：URL正規表現チェック
 * 用　法：chekcURL( field, label, focus )
 * 		     field: 確認フィールド
 * 		     label:ラベル名（チェック欄名）
 * 		     focus: true:フォーカスをあてる / false :フォーカスをあてない
 * 返し値：true : URL入力フォーマットのみ / flase : URL入力フォーマット以外
 * Create on： 2006/04/04
 * Create by : Hirotaka Irinatsu
=============================================== */
function checkURL( field, label, focus ){
	var s = field.value;

	if( s != "" ){
		var matchURL = "s?https?:\/\/[-_.!~*()a-zA-Z0-9;\/?:\@&=+\$,%#]+";
		if( s.match( matchURL ) == s ){
			return true;
		} else {
			alert( "「" + label + "」が正しくありません。" );
			if( focus != false ){
				field.focus();
			}
			return false;
		}
	} else {
		return true;
	}
}

/* ===============================================
 * 機　能：メールアドレス正規表現チェック
 * 用　法：chekcMailAddr( field, label, focus )
 * 		          field: 確認フィールド
 * 		          label:ラベル名（チェック欄名）
 * 		          focus: true:フォーカスをあてる / false :フォーカスをあてない
 * 返し値：true : メールアドレスフォーマットのみ / flase : メールアドレスフォーマット以外
 * Create on： 2006/04/04
 * Create by : Hirotaka Irinatsu
=============================================== */
function checkMailAddr( field, label, focus ){
	var s = field.value;

	if( s != "" ){
		if( s.match( /[0-9A-Za-z_\x2D.]+@[0-9A-Za-z_\x2D.]+\.[0-9A-Za-z_\x2D]+/ ) == s ){
			return true;
		} else {
			alert( "「" + label + "」が正しくありません。" );
			if( focus != false ){
				field.focus();
			}
			return false;
		}
	} else {
		return true;
	}
}

/* ===============================================
 * 機　能：全角カタカナ正規表現チェック
 * 用　法：chekcZenkakuKatakana( field, label, focus )
 * 		         field: 確認フィールド
 * 		         label:ラベル名（チェック欄名）
 * 		         focus: true:フォーカスをあてる / false :フォーカスをあてない
 * 返し値：true : 全角カタカナのみ / flase : 全角カタカナ以外を含む
 * Create on： 2006/04/04
 * Create by : Hirotaka Irinatsu
=============================================== */
function checkZenkakuKatakana( field, label, focus ){
	var s = field.value;

	if( s != "" ){
		if ( s.match( "^[ア-ンァ-ヶ－ー―　]*$" ) == s )
		{
			return true;
		} else {
			alert( "「" + label + "」は全角カタカナで入力してください。" );
			if( focus != false ){
				field.focus();
			}
			return false;
		}
	} else {
		return true;
	}
}

/* ===============================================
 * 機　能：入力項目の文字数範囲を確認
 * 用　法：checkByteSize( field, minlength, maxlength, label, focus )
 * 			     field: 確認フィールド
 *               minlength: 最小文字数
 * 			     maxlength: 最大文字数
 * 			     label:ラベル名（チェック欄名）
 * 			     focus: true:フォーカスをあてる / false :フォーカスをあてない
 * 返し値：ture : 範囲文字数内 / flase : 範囲文字数外
 * Create on： 2006/04/25
 * Create by : Yusaku Suzuki
=============================================== */
function checkByteSize( field, minlength, maxlength, label, focus ) {
	var s = field.value;
	var strLen = 0;
	for ( var i = 0; i < s.length; ++i ) {
		var sub = s.substring(i, i + 1);
		if( IsZenkaku(sub) ){	//全角の場合2バイト追加。
			strLen += 2;
		} else {
			strLen += 1;
		}
	}
	if ( strLen < minlength ) {
	    alert( "「" + label + "」は" + minlength + "文字以上" + maxlength + "文字以内で入力してください。" );
	    if( focus != false ){
			field.focus();
		}
		return false;	    
	}
	if ( strLen > maxlength ) {
		alert( "「" + label + "」は" + maxlength + "文字以内で入力してください。" );
		if( focus != false ){
			field.focus();
		}
		return false;
	}
	return true;
}

/* ===============================================
 * 機　能：入力項目の文字数を確認
 * 用　法：checkTextSize( field, length, label, focus )
 * 			     field: 確認フィールド
 * 			     length: 文字数
 * 			     label:ラベル名（チェック欄名）
 * 			     focus: true:フォーカスをあてる / false :フォーカスをあてない
 * 返し値：ture : 指定文字数 / flase : 指定文字数以外
 * Create on： 2006/05/27
 * Create by : Hirotaka Irinatsu
=============================================== */
function checkTextSize( field, length, label, focus ) {
	var s = field.value;
	if ( s.toString().length != length ) {
		alert( "「" + label + "」は" + length + "文字で入力してください。" );
		if( focus != false ){
			field.focus();
		}
		return false;
	}
	return true;
}

/* ===============================================
 * 機　能：入力項目の最大文字数を確認
 * 用　法：checkMaxTextSize( field, length, label, focus )
 * 			     field: 確認フィールド
 * 			     length: 最大文字数
 * 			     label:ラベル名（チェック欄名）
 * 			     focus: true:フォーカスをあてる / false :フォーカスをあてない
 * 返し値：ture : 最大文字数以下 / flase : 最大文字数超過
 * Create on： 2006/04/04
 * Create by : Hirotaka Irinatsu
=============================================== */
function checkMaxTextSize( field, length, label, focus ) {
	var s = field.value;
	if ( s.toString().length > length ) {
		alert( "「" + label + "」は" + length + "文字以内で入力してください。" );
		if( focus != false ){
			field.focus();
		}
		return false;
	}
	return true;
}

/* ===============================================
 * 機　能：入力項目の文字数範囲チェック
 * 用　法：checkMaxMinTextSize( field, maxlength, minlength, label, focus )
 * 			     field: 確認フィールド
 * 			     minlength: 最小文字数
 * 			     maxlength: 最大文字数
 * 			     label:ラベル名（チェック欄名）
 * 			     focus: true:フォーカスをあてる / false :フォーカスをあてない
 * 返し値：ture : 範囲内文字数 / flase : 範囲外文字数
 * Create on： 2006/04/11
 * Create by : Hirotaka Irinatsu
=============================================== */
function checkMaxMinTextSize( field, minlength, maxlength, label, focus ) {
	var s = field.value;
	if ( s.toString().length > maxlength || s.toString().length < minlength ) {
		alert( "「" + label + "」は" + minlength + "文字以上" + maxlength + "文字以下で入力してください。" );
		if( focus != false ){
			field.focus();
		}
		return false;
	}
	return true;
}

/* ===============================================
 * 機　能：Microadロゴよりログアウトする場合の処理
 * 用　法：logOut()
 * 返し値：なし
 * Create on： 2006/05/27
 * Create by : Yusaku Suzuki
=============================================== */
function logOut() {
    if(window.confirm("ログアウトしますか？")){
        location.href = "/associate/logout";
    } else {
        return;
    }
}

/* ===============================================
 * 機　能：ログインチェック処理
 * 用　法：loginCheck()
 * 返し値：ture : ＯＫ / false : エラー
 * Create on： 2009/06/25
 * Create by : Shenyang Team
=============================================== */
function loginCheck(formName) {

	if(formName == undefined){
		formName = document.login;
	}

    if(!checkReqItem(formName.loginid, "メールアドレス", true )
    	|| !checkMailAddr(formName.loginid, "メールアドレス", true )
    	|| !checkMaxTextSize(formName.loginid, 100, "メールアドレス", true )) {
    	return false;
	}
    
    if(!checkReqItem(formName.loginpassword, "パスワード", true )
    	|| !checkAlphaNumeric(formName.loginpassword, "パスワード", true )
    	|| !checkMaxMinTextSize(formName.loginpassword, 6, 12, "パスワード", true )) {
    	return false;
	}
    formName.forward.value = 'Plc_01_03_000';
    formName.action.value = 'Plc_01_03_000';
    return true;
}
