/*********************************************************************
 *
 *
 *
*********************************************************************/

var arrErrList = new Array();

/*************************
 * function name	:setCheckNGAction
 *					 入力チェックNG時の画面設定を行う
 * param			:
 * return			:
*************************/
function setDspAction(objName, bgcolor, msg, objFocus) {

	var msgTitle = "err_title";
	var msgItem = "err_" + objName;

	var msgBgColorL = "td_" + objName + "_L";
	var msgBgColorR = "td_" + objName + "_R";

	// エラーリストセット
	setErrList(objFocus, !isEmpty(msg));

	// 背景色変更
	if ( document.getElementById(msgBgColorL) != null ) {
		setBackGroundColor(document.getElementById(msgBgColorL), bgcolor);
	}
	if ( document.getElementById(msgBgColorR) != null ) {
		setBackGroundColor(document.getElementById(msgBgColorR), bgcolor);
	}

	// メッセージ表示
	if ( document.getElementById(msgTitle) != null ) {
		if ( 0 < arrErrList.length ) {
			setInnerText(document.getElementById(msgTitle), getMessage(0));
		} else {
			setInnerText(document.getElementById(msgTitle), "");
		}
	}
	if ( document.getElementById(msgItem) != null ) {
		setInnerText(document.getElementById(msgItem), msg);
	}

	// フォーカスをセット
	if ( !isEmpty(msg) && objFocus != null && objFocus.type != 'hidden') {
		objFocus.focus();
	}
}

/*************************
 * function name	:setErrList
 *					 エラーリストを設定する
 * param			:item object
 *					 リストからのアクション 追加(true)／削除(false)
 * return			:
*************************/
function setErrList(objItem, flg) {
	var targetIdx = -1;
	for (i = 0; i < arrErrList.length; i++) {
		if( arrErrList[i] == objItem.name ) {
			targetIdx = i;
			break;
		}
	}

	if ( flg && targetIdx < 0 ) {
		arrErrList.push(objItem.name);
	} else if ( !flg && 0 <= targetIdx ) {
		arrErrList.splice(targetIdx,1);
	}

	return;
}


/*************************
 * function name	:checkMemberId
 *					 ユーザーIDのチェックを行う
 * param			:
 * return			:
*************************/
function checkMemberId(formName, bAjaxFlg) {
	var val = document.forms[formName].member_id.value;
	var mail = document.forms[formName].mail.value;
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(1, "ユーザID");
	} else if ( isNGWord(val) ) {
		errflg = true;
		msg = getMessage(6, "ユーザID", "[\"],['],[,],[?],[!]");
	} else if ( val == mail ) {
		// メールアドレスと同じならOK
	} else if ( !isNumAlph(val) ) {
		errflg = true;
		msg = getMessage(7, "ユーザID", "半角英数");
	} else if ( !isAllowLen(val, 1, 30) ) {
		errflg = true;
		msg = getMessage(4, "ユーザID", "30");
	}

	if ( isEmpty(msg) && bAjaxFlg) {
		// ユーザID重複チェック
	}

	if ( errflg ) {
		setDspAction("member_id", GB_COLOR_NG, msg, document.forms[formName].member_id);
	} else {
		setDspAction("member_id", GB_COLOR_OK, "", document.forms[formName].member_id);
	}

	return !errflg;
}

/*************************
 * function name	:checkMemberIdEdit
 *					 ユーザーIDのチェックを行う(変更画面)
 * param			:
 * return			:
*************************/
function checkMemberIdEdit(formName, bAjaxFlg) {
	var val = document.forms[formName].member_id.value;

	if ( isEmpty(val, true) ) {
		setDspAction("member_id", GB_COLOR_NG, getMessage(1, "ユーザID"), document.forms[formName].member_id);
		return false;
	} else {
		setDspAction("member_id", GB_COLOR_OK, "", document.forms[formName].member_id);
		return true;
	}
}

/*************************
 * function name	:checkPass
 *					 パスワードのチェックを行う
 * param			:
 * return			:
*************************/
function checkPass(formName) {
	var val = document.forms[formName].passwd_1.value;
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(1, "パスワード");
	} else if ( !isNumAlph(val) ) {
		errflg = true;
		msg = getMessage(7, "パスワード", "半角英数");
	} else if ( !isAllowLen(val, 4, 12) ) {
		errflg = true;
		msg = getMessage(5, "パスワード", "4", "12");
	} else if ( isNGWord(val) ) {
		errflg = true;
		msg = getMessage(6, "パスワード", "[\"],['],[,],[?],[!]");
	} else if ( !isEmpty(document.forms[formName].passwd_2.value, true) && val == document.forms[formName].passwd_2.value ) {
		// パスワードとパスワード(再)が一致する場合パスワード(再)のエラーを取り除く
		setDspAction("passwd_2", GB_COLOR_OK, "", document.forms[formName].passwd_2);
	} else if ( !isEmpty(document.forms[formName].passwd_2.value, true) && val != document.forms[formName].passwd_2.value ) {
		// パスワードとパスワード(再)が一致しない場合パスワード(再)のエラーを表示
		setDspAction("passwd_2", GB_COLOR_NG, getMessage(10, "パスワード", "パスワード（再入力）"), document.forms[formName].passwd_2);
	}

	if ( errflg ) {
		setDspAction("passwd_1", GB_COLOR_NG, msg, document.forms[formName].passwd_1);
	} else {
		setDspAction("passwd_1", GB_COLOR_OK, "", document.forms[formName].passwd_1);
	}

	return !errflg;
}

/*************************
 * function name	:checkPassConf
 *					 パスワード再入力のチェックを行う
 * param			:
 * return			:
*************************/
function checkPassConf(formName) {
	var val = document.forms[formName].passwd_2.value;
	var pass1 = document.forms[formName].passwd_1.value;
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(1, "パスワード（再入力）");
	} else if ( !isEmpty(pass1, true) && val != pass1 ) {
		errflg = true;
		msg = getMessage(10, "パスワード", "パスワード（再入力）");
	}

	if ( errflg ) {
		setDspAction("passwd_2", GB_COLOR_NG, msg, document.forms[formName].passwd_2);
	} else {
		setDspAction("passwd_2", GB_COLOR_OK, "", document.forms[formName].passwd_2);
	}

	return !errflg;

}

/*************************
 * function name	:checkName
 *					 氏名(漢字)のチェックを行う
 * param			:
 * return			:
*************************/
function checkName(formName) {
	var val = document.forms[formName].name.value;
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(1, "氏名（漢字）");
	}

	if ( errflg ) {
		setDspAction("name", GB_COLOR_NG, msg, document.forms[formName].name);
	} else {
		setDspAction("name", GB_COLOR_OK, "", document.forms[formName].name);
	}

	return !errflg;
}

/*************************
 * function name	:checkNameKana
 *					 氏名(カナ)のチェックを行う
 * param			:
 * return			:
*************************/
function checkNameKana(formName) {
	var val = document.forms[formName].name_kana.value;
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(1, "氏名（カナ）");
	} else if ( !isZenkakuKana(val) ) {
		errflg = true;
		msg = getMessage(7, "氏名（カナ）", "全角カナ");
	}

	if ( errflg ) {
		setDspAction("name_kana", GB_COLOR_NG, msg, document.forms[formName].name_kana);
	} else {
		setDspAction("name_kana", GB_COLOR_OK, "", document.forms[formName].name_kana);
	}

	return !errflg;

}

 /*************************
  * function name	:checkName2
  *					 氏名のチェックを行う
  * param			:
  * return			:
 *************************/
 function checkName2(formName) {
 	var val = document.forms[formName].name.value;
 	var errflg = false;
 	var msg = "";

 	if ( isEmpty(val, true) ) {
 		errflg = true;
 		msg = getMessage(1, "氏名");
 	}

 	if ( errflg ) {
 		setDspAction("name2", GB_COLOR_NG, msg, document.forms[formName].name);
 	} else {
 		setDspAction("name2", GB_COLOR_OK, "", document.forms[formName].name);
 	}

 	return !errflg;
}

/*************************
 * function name	:checkNickName
 *					 ニックネームのチェックを行う
 * param			:
 * return			:
*************************/
function checkNickName(formName, bAjaxFlg) {
	var val = document.forms[formName].nickname.value;
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(1, "ニックネーム");
	} else if ( 16 < getByte(val) ) {
		errflg = true;
		msg = getMessage(11, "ニックネーム", "8", "16");
	} else if ( isContains(STRLIST_KATAKANA_HAN, val) ) {
		errflg = true;
		msg = getMessage(6, "ニックネーム", "半角カナ");
	}

	if ( errflg ) {
		setDspAction("nickname", GB_COLOR_NG, msg, document.forms[formName].nickname);
	} else {
		setDspAction("nickname", GB_COLOR_OK, "", document.forms[formName].nickname);
	}

	return !errflg;
}


/*************************
 * function name	:checkSex
 *					 性別のチェックを行う
 * param			:
 * return			:
*************************/
function checkSex(formName) {
	var val = getSelectValue(document.forms[formName].sex);
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(8, "性別");
	}

	if ( errflg ) {
		setDspAction("sex", GB_COLOR_NG, msg, document.forms[formName].sex);
	} else {
		setDspAction("sex", GB_COLOR_OK, "", document.forms[formName].sex);
	}

	return !errflg;

}

/*************************
 * function name	:checkBirthday
 *					 生年月日のチェックを行う
 * 					 （クライアントからPOSTする際のチェック時に使用する）
 * param			:
 * return			:
*************************/
function checkBirthday(formName) {
	var yy = getSelectValue(document.forms[formName].birthday_y);
	var mm = getSelectValue(document.forms[formName].birthday_m);
	var dd = getSelectValue(document.forms[formName].birthday_d);
	var errflg = false;
	var msg = "";

	if ( isEmpty(yy, true) ) {
		errflg = true;
		msg = getMessage(8, "生年月日(年)");
		setDspAction("birthday", GB_COLOR_NG, msg, document.forms[formName].birthday_y);
	} else if ( isEmpty(mm, true) ) {
		errflg = true;
		msg = getMessage(8, "生年月日(月)");
		setDspAction("birthday", GB_COLOR_NG, msg, document.forms[formName].birthday_m);
	} else if ( isEmpty(dd, true) ) {
		errflg = true;
		msg = getMessage(8, "生年月日(日)");
		setDspAction("birthday", GB_COLOR_NG, msg, document.forms[formName].birthday_d);
	} else if ( !isDate(yy, mm, dd) ) {
		errflg = true;
		msg = getMessage(12, "生年月日");
		setDspAction("birthday", GB_COLOR_NG, msg, document.forms[formName].birthday_y);
	}

	return !errflg;
}


/*************************
 * function name	:checkBirthday_y
 *					 生年月日（年）のチェックを行う
 * param			:
 * return			:
*************************/
function checkBirthday_y(formName) {
	var yy = getSelectValue(document.forms[formName].birthday_y);
	var mm = getSelectValue(document.forms[formName].birthday_m);
	var dd = getSelectValue(document.forms[formName].birthday_d);
	var errflg = false;
	var msg = "";

	if ( !isEmpty(yy, true) && !isEmpty(mm, true) && !isEmpty(dd, true) ) {
		if ( !isDate(yy, mm, dd) ) {
			errflg = true;
			msg = getMessage(12, "生年月日");
		}
	} else if ( isEmpty(yy, true) ) {
		errflg = true;
		msg = getMessage(8, "生年月日(年)");
	}

	if ( errflg ) {
		setDspAction("birthday", GB_COLOR_NG, msg, document.forms[formName].birthday_y);
	} else {
		setDspAction("birthday", GB_COLOR_OK, "", document.forms[formName].birthday_y);
	}

	return !errflg;
}

/*************************
 * function name	:checkBirthday_m
 *					 生年月日（月）のチェックを行う
 * param			:
 * return			:
*************************/
function checkBirthday_m(formName) {
	var yy = getSelectValue(document.forms[formName].birthday_y);
	var mm = getSelectValue(document.forms[formName].birthday_m);
	var dd = getSelectValue(document.forms[formName].birthday_d);
	var errflg = false;
	var msg = "";

	if ( !isEmpty(yy, true) && !isEmpty(mm, true) && !isEmpty(dd, true) ) {
		if ( !isDate(yy, mm, dd) ) {
			errflg = true;
			msg = getMessage(12, "生年月日");
		}
	} else if ( isEmpty(mm, true) ) {
		errflg = true;
		msg = getMessage(8, "生年月日(月)");
	}

	if ( errflg ) {
		setDspAction("birthday", GB_COLOR_NG, msg, document.forms[formName].birthday_m);
	} else {
		setDspAction("birthday", GB_COLOR_OK, "", document.forms[formName].birthday_m);
	}

	return !errflg;
}

/*************************
 * function name	:checkBirthday_d
 * 					 （クライアントでの入力チェックに使用する）
 *					 生年月日（日）のチェックを行う
 * param			:
 * return			:
*************************/
function checkBirthday_d(formName) {
	var yy = getSelectValue(document.forms[formName].birthday_y);
	var mm = getSelectValue(document.forms[formName].birthday_m);
	var dd = getSelectValue(document.forms[formName].birthday_d);
	var errflg = false;
	var msg = "";

	if ( !isEmpty(yy, true) && !isEmpty(mm, true) && !isEmpty(dd, true) ) {
		if ( !isDate(yy, mm, dd) ) {
			errflg = true;
			msg = getMessage(12, "生年月日");
		}
	} else if ( isEmpty(dd, true) ) {
		errflg = true;
		msg = getMessage(8, "生年月日(日)");
	}

	if ( errflg ) {
		setDspAction("birthday", GB_COLOR_NG, msg, document.forms[formName].birthday_d);
	} else {
		setDspAction("birthday", GB_COLOR_OK, "", document.forms[formName].birthday_d);
	}

	return !errflg;
}

/*************************
 * function name	:checkZipCode1
 *					 郵便番号のチェックを行う
 * param			:
 * return			:
*************************/
function checkZipCode1(formName) {
	var val = document.forms[formName].zip_code_1.value;
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(1, "郵便番号(前)");
	} else if ( !isNummeric(val) || !isAllowLen(val, 3, 3) ) {
		errflg = true;
		msg = getMessage(7, "郵便番号(前)", "半角数値3桁");
	}

	if ( errflg ) {
		setDspAction("zip_code", GB_COLOR_NG, msg, document.forms[formName].zip_code_1);
	} else {
		setDspAction("zip_code", GB_COLOR_OK, "", document.forms[formName].zip_code_1);
	}

	return !errflg;
}

/*************************
 * function name	:checkZipCode2
 *					 郵便番号のチェックを行う
 * param			:
 * return			:
*************************/
function checkZipCode2(formName) {
	var val = document.forms[formName].zip_code_2.value;
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(1, "郵便番号(後)");
	} else if ( !isNummeric(val) || !isAllowLen(val, 4, 4) ) {
		errflg = true;
		msg = getMessage(7, "郵便番号(後)", "半角数値4桁");
	}

	if ( errflg ) {
		setDspAction("zip_code", GB_COLOR_NG, msg, document.forms[formName].zip_code_2);
	} else {
		setDspAction("zip_code", GB_COLOR_OK, "", document.forms[formName].zip_code_2);
	}

	return !errflg;
}

/*************************
 * function name	:checkPref
 *					 都道府県チェックを行う
 * param			:
 * return			:
*************************/
function checkPref(formName) {
	var val = getSelectValue(document.forms[formName].pref_code);
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(8, "住所（都道府県）");
	}

	if ( errflg ) {
		setDspAction("pref_code", GB_COLOR_NG, msg, document.forms[formName].pref_code);
	} else {
		setDspAction("pref_code", GB_COLOR_OK, "", document.forms[formName].pref_code);
	}

	return !errflg;

}

/*************************
 * function name	:checkAdd1
 *					 市区町村のチェックを行う
 * param			:
 * return			:
*************************/
function checkAdd1(formName) {
	var val = document.forms[formName].add_1.value;
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(1, "市区町村");
	}

	if ( errflg ) {
		setDspAction("add_1", GB_COLOR_NG, msg, document.forms[formName].add_1);
	} else {
		setDspAction("add_1", GB_COLOR_OK, "", document.forms[formName].add_1);
	}

	return !errflg;
}

/*************************
 * function name	:checkAdd2
 *					 番地のチェックを行う
 * param			:
 * return			:
*************************/
function checkAdd2(formName) {
	var val = document.forms[formName].add_2.value;
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(1, "番地");
	}

	if ( errflg ) {
		setDspAction("add_2", GB_COLOR_NG, msg, document.forms[formName].add_2);
	} else {
		setDspAction("add_2", GB_COLOR_OK, "", document.forms[formName].add_2);
	}

	return !errflg;
}

/*************************
 * function name	:checkAdd3
 *					 それ以降の住所のチェックを行う
 * param			:
 * return			:
*************************/
function checkAdd3(formName) {
	return true;
}

/*************************
 * function name	:checkTel
 *					 電話番号のチェックを行う
 * param			:
 * return			:
*************************/
function checkTel(formName) {
	var val = document.forms[formName].tel.value;
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(1, "電話番号");
	} else if ( !isNummeric(val.replace(/-/g, "0")) ) {
		errflg = true;
		msg = getMessage(7, "電話番号", "半角数値または「-」");
	} else if ( val.substring(0,1) != "0" || val.substring(val.length - 1, val.length) == "-") {
		errflg = true;
		msg = getMessage(12, "電話番号");
	}

	if ( errflg ) {
		setDspAction("tel", GB_COLOR_NG, msg, document.forms[formName].tel);
	} else {
		setDspAction("tel", GB_COLOR_OK, "", document.forms[formName].tel);
	}

	return !errflg;

}

/*************************
 * function name	:checkMail
 *					 メールアドレスのチェックを行う
 * param			:
 * return			:
*************************/
function checkMail(formName, bAjaxFlg) {
	var val = document.forms[formName].mail.value;
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(1, "メールアドレス");
	} else if ( !isAllowLen(val, 1, 100) ) {
		errflg = true;
		msg = getMessage(4, "メールアドレス", "100");
	} else if ( !isMail(val) ) {
		errflg = true;
		msg = getMessage(12, "メールアドレス");
	} else if ( bAjaxFlg ) {
		// メールアドレス重複チェック
	}

	if ( errflg ) {
		setDspAction("mail", GB_COLOR_NG, msg, document.forms[formName].mail);
	} else {
		setDspAction("mail", GB_COLOR_OK, "", document.forms[formName].mail);
	}
	return !errflg;
}

/*************************
 * function name	:checkMailMagazine
 *					 メールマガジン設定のチェックを行う
 * param			:
 * return			:
*************************/
function checkMailMagazine(formName) {
	var val = getSelectValue(document.forms[formName].melmaga_flg);
	var errflg = false;
	var msg = "";

	if ( isEmpty(val, true) ) {
		errflg = true;
		msg = getMessage(8, "メールマガジン設定");
	}

	if ( errflg ) {
		setDspAction("melmaga_flg", GB_COLOR_NG, msg, document.forms[formName].melmaga_flg);
	} else {
		setDspAction("melmaga_flg", GB_COLOR_OK, "", document.forms[formName].melmaga_flg);
	}

	return !errflg;
}

/*************************
 * function name	:loadDoubleErrPatern
 *					 重複エラー時のエラーを設定する
 * param			:項目ID(1:ユーザID／2:メールアドレス／3:ニックネーム)
 * return			:
*************************/
function loadDoubleErrPatern(formName, ptn) {
	if ( ptn == 1 ) {
		setDspAction("member_id", GB_COLOR_NG, getMessage(9, "ユーザID"), document.forms[formName].member_id);
	} else if ( ptn == 2 ) {
		setDspAction("mail", GB_COLOR_NG, getMessage(9, "メールアドレス"), document.forms[formName].mail);
	} else if ( ptn == 3 ) {
		setDspAction("nickname", GB_COLOR_NG, getMessage(9, "ニックネーム"), document.forms[formName].nickname);
	}
	return false;
}

/*************************
 * function name	:bid
 *					 入札を行う
 * param			:識別子
					:フォームオブジェクト
					:送信タイプ
					:送信先ファイル
					:フラグ1
					:フラグ2
 * return			:
*************************/
function bid(str, objForm, methodType, file, flg1, flg2) {
	// 入札金額と入札個数を半角に変換

	objForm.price.value = repHankakuNum(objForm.price.value);
	objForm.bid_num_input.value = repHankakuNum(objForm.bid_num_input.value);

	if ( objForm.price.value == 0 || objForm.bid_num_input.value == 0 ) {
		alert("金額・個数には0を入力することはできません。");
		return false;
	}

	var paramstr = "&" + objForm.price.name            + "=" + objForm.price.value
					+ "&" + objForm.bid_num_input.name + "=" + objForm.bid_num_input.value
					+ "&" + objForm.syohin_name.name   + "=" + objForm.syohin_name.value
					+ "&" + objForm.auction_id.name    + "=" + objForm.auction_id.value
					+ "&" + objForm.auction_code.name  + "=" + objForm.auction_code.value
					+ "&" + objForm.image.name         + "=" + objForm.image.value
					+ "&" + objForm.syohin_code.name   + "=" + objForm.syohin_code.value
					+ "&" + objForm.ticket_name.name   + "=" + objForm.ticket_name.value
					+ "&" + objForm.ref_info.name      + "=" + objForm.ref_info.value
					+ "&" + objForm.bid_comment.name   + "=" + objForm.bid_comment.value
					+ "&" + objForm.bid_cnt.name       + "=" + objForm.bid_cnt.value
					+ "&" + objForm.remain_date.name   + "=" + objForm.remain_date.value;

	return sendRequest(str, paramstr, methodType, file, flg1, flg2);
}
