/*
 * オーバーレイ形式の条件追加用のJavaScriptです。
 * 動作には、事前に jQuery を読み込んでおく必要があります。
 */

var elScreen = null;
var elFrame = null;
var elUnderFrame = null;
var objDisplayTab = null;
var objSelectCategory = null;
var objTopCategory = null;
var objSubCategory = null;

var defLanguageVals = null;
var defQualificationVals = null;

/*
 * 語学部分の選択肢
 */
var arLanguageLevel = new Array();
arLanguageLevel[0] = {"value": "", "text": "選択してください"};
arLanguageLevel[1] = {"value": "1", "text": "初級"};
arLanguageLevel[2] = {"value": "2", "text": "中級"};
arLanguageLevel[3] = {"value": "3", "text": "上級"};


/*
 * 資格年月の範囲
 */
var date = new Date();
var startYear = date.getFullYear() - 25;
var endYear = date.getFullYear();

/*
 * オフィス印刷用CSSの定義
 */
var datCssOffice = {"src": "../../common/css/print_office.css"};
var obCssOffice = null;


/*
 * 追加条件指定用のポップアップをオーバーレイ形式で表示する
 */
function visibleSelectWin(id, hdnId) {

	// 表示時に内容を初期化する
	switch (id) {
		case "popupOfficePlace":
		case "popupBusinessType":
		case "popupExpBusinessType":
		case "popupBusinessTypeUL":
		case "popupJobType":
		case "popupExpJobType":
		case "popupJobTypeUL":
			var chkValue = $("#" + hdnId).val();
			var arChecked = chkValue.split(",");
			var obElCheck = $("input[@type='checkbox']", $("#" + id));
			obElCheck.each(function() {
				var isCheck = false;
				var length = arChecked.length;
				for (var i=0; i<length; i++) {
					if (this.value == arChecked[i]) {
						isCheck = true;
						break;
					}
				}
				this.checked = isCheck;
			});
			break;
		case "popupPrefecture":
			var chkValue = $("#" + hdnId).val();
			var obElCheck = $("input[@type='radio']", $("#" + id));
			obElCheck.each(function() {
				if (this.value == chkValue) {
					this.checked = true;
				}
			});
			break;
		case "popupLanguage":
			defLanguageVals = analyzeSelectedLanguage(hdnId);
			var obElCheck = $("input[@type='checkbox']", $("#" + id));
			obElCheck.each(function() {
				var isCheck = false;
				var length = defLanguageVals.length;
				for (var i=0; i<length; i++) {
					if (this.value == defLanguageVals[i].value) {
						isCheck = true;
						break;
					}
				}
				this.checked = isCheck;
			});
			break;
		case "popupQualification":
			defQualificationVals = analyzeSelectedQualification(hdnId);
			var obElCheck = $("input[@type='checkbox']", $("#" + id));
			obElCheck.each(function() {
				var isCheck = false;
				var length = defQualificationVals.length;
				for (var i=0; i<length; i++) {
					if (this.value == defQualificationVals[i].value) {
						isCheck = true;
						break;
					}
				}
				this.checked = isCheck;
			});
			break;
		case "popupOfficeMap01":
		case "popupOfficeMap02":
		case "popupOfficeMap03":
			$("#" + id).css("display", "block");
			var cssOffice = document.createElement("link");
			obCssOffice = $(cssOffice).attr("rel", "stylesheet").attr("type", "text/css").attr("href", datCssOffice.src).attr("media", "print");
			$("head").append(obCssOffice);
			break;
	}

	// 背景を作成する
	elScreen = findElement("PU_screen", null, "div");
//	elScreen.onclick = function() {
//		hiddenSelectWin(id);
//	}

	// ポップアップ本体の表示位置を調整する
	var el = $("#" + id)[0];
	var width = el.offsetWidth;
	var height = el.offsetHeight;

	$("#" + id).css({
		"left" : "50%",
		"top" : "50%",
		"margin-left" : 0 - parseInt(width / 2) + "px",
		"margin-top" : 0 - parseInt(height / 2) + 9 + "px",
		"visibility" : "visible"
	});

	// ポップアップのタイトルを取得する
	var popupTitle = $("#" + id + " > h3").html();

	// ポップアップ枠を作成し、表示位置を調整する
	var fWidth = width + 14;
	var fHeight = height + 32;
	elFrame = findElement(id, "_frame", "div");
	elFrame.className = "PU_frame";

	$("#" + id + "_frame").css({ 
		"width" : fWidth + "px",
		"height" : fHeight + "px",
		"margin-left" : 0 - parseInt(fWidth / 2) + "px",
		"margin-top" : 0 - parseInt(fHeight / 2) + "px"
	});

	elFrame.innerHTML = "<div class=\"header\"><p class=\"left\"></p><p class=\"body\">" + popupTitle + "</p><p class=\"right\"></p><a href=\"javascript:hiddenSelectWin('" + id + "');\" class=\"closeButton\">CLOSE</a></div><div class=\"body\"></div><div class=\"content\" style=\"height: " + height + "px;\"></div><div class=\"footer\"><p class=\"left\"></p><p class=\"body\"></p><p class=\"right\"></p></div>";

	// ターゲットブラウザの判別
	var isIE6 = false;
	var isSafari1_3 = false;
	var isFirefox2 = false;
	if (navigator.userAgent.match(/MSIE (\d\.\d+)/)) {
		if (RegExp.$1 == "6.0") isIE6 = true;
	} else if (navigator.userAgent.match(/Safari\/([\.\d]+)/)) {
		if (300 <= parseInt(RegExp.$1) && parseInt(RegExp.$1) < 400) {
			isSafari1_3 = true;
		} else if (500 <= parseInt(RegExp.$1)) {
		}
	} else if (navigator.userAgent.match(/Firefox\/([\.\d]+)/)) {
		if (parseInt(RegExp.$1) < 3) isFirefox2 = true;
	}

	if (isIE6) {		// IE6用のバグ対策

		// 背景部分のサイズを調整する
		var screenHeight;
		if (document.body.scrollHeight > document.body.offsetHeight) {
			screenHeight = document.body.scrollHeight;
		} else {
			screenHeight = document.body.offsetHeight;
		}
		$(elScreen).css("height", screenHeight + "px");


		// IE用に印刷の前後で、背景部分のサイズを変更する
		document.body.onbeforeprint = function() {	// 印刷前
			$(elScreen).css("height", "0");
		}

		document.body.onafterprint = function() {// 印刷後
			$(elScreen).css("height", screenHeight + "px");
		}

		// インラインフレームの幅と高さは、角丸の半径の分だけ差し引く
		var ufWidth = fWidth - 6;
		var ufHeight = fHeight - 6;

		// オーバーレイの下にselectタグがあると、表示がおかしくなるので、ifameを下に表示する
//		elUnderFrame = findElement(id, "_underFrame", "iframe");
//		$(elUnderFrame).attr("class", "PU_Uframe").attr("src", "/common/blank.html");
//		elUnderFrame.className = "PU_Uframe";
		var targetId = id + "_underFrame";
		elUnderFrame = $("#" + targetId)[0];
		if (!elUnderFrame) {
			elUnderFrame = document.createElement("iframe");
			elUnderFrame.id = targetId;
			elUnderFrame.src = "/common/blank.html";
			document.body.appendChild(elUnderFrame);
		}
		elUnderFrame.className = "PU_Uframe";


		$("#" + id + "_underFrame").css({ 
			"width" : ufWidth + "px",
			"height" : ufHeight + "px",
			"margin-left" : 0 - parseInt(ufWidth / 2) + "px",
			"margin-top" : 0 - parseInt(ufHeight / 2) + "px"
		});

		// margin で位置を調整する
		var scrollTop = document.documentElement.scrollTop;
		$("#" + id).css("margin-top", 0 - parseInt(height / 2) + 9 + scrollTop + "px");
		$("#" + id + "_frame").css("margin-top", 0 - parseInt(fHeight / 2) + scrollTop + "px");
		$("#" + id + "_underFrame").css("margin-top", 0 - parseInt(ufHeight / 2) + scrollTop + "px");

/*	} else if (isSafari1_3) {	// Safari1.3 の場合は、スクロールすると表示がおかしくなるので・・・IE6と同様の表現にする*/
	} else {	// Safari1.3 の場合は、スクロールすると表示がおかしくなるので・・・IE6と同様の表現にする
		var scrollTop;
		if (window.scrollY) {
			scrollTop = window.scrollY;
		} else {
			scrollTop = document.documentElement.scrollTop;
		}

		$(".PU_body").css({
			"position": "absolute",
			"margin-top": (0 - parseInt(height / 2) + 9 + parseInt(scrollTop) + "px")
		});
		$(".PU_frame").css({
			"position": "absolute",
			"margin-top": (0 - parseInt(fHeight / 2) + parseInt(scrollTop) + "px")
		});
	}

	// 業種・職種選択の場合は、最初の項目（タブ）を表示状態にする
	switch (id) {
		case "popupBusinessType":
		case "popupExpBusinessType":
		case "popupBusinessTypeUL":
		case "popupQualification":
		case "popupJobTypeUL":
			var elAnchor = $("a", $("#" + id + " > .popupConditions"));
			objSelectCategory = $(elAnchor.get(0));
			objSelectCategory.addClass("focus");
			var elTab = $("div", $("#" + id + " > .popupTabFrame"));
			objDisplayTab = $(elTab.get(0));
			objDisplayTab.css("visibility", "visible");
			break;
		case "popupJobType":
		case "popupExpJobType":
			var elAnchor = $("a", $("#" + id + " > .popupConditions"));
			objTopCategory = $(elAnchor.get(0));
			objTopCategory.addClass("focus");
			objSelectCategory = $($("table", $("#" + id + " > .popupSubConditions"))[0]);
			objSelectCategory.css("visibility", "visible");
			var elAnchor02 = $("a", $("#" + id + " > .popupSubConditions"));
			objSubCategory = $(elAnchor02.get(0));
			objSubCategory.addClass("focus");
			var elTab = $("div", $("#" + id + " > .popupTabFrame"));
			objDisplayTab = $(elTab.get(0));
			objDisplayTab.css("visibility", "visible");
			break;
	}
	return false;
}

/*
 * 表示中のポップアップの値を選択後、非表示にする
 */
function selectAndCloseWin(id, txtId, hdnId) {
	if (id == "popupPrefecture") {
		var obElCheck = $("input[@type='radio']", $("#" + id));
		var chkVal = "";
		var chkTxt = "";
		obElCheck.each(function() {
			if (this.checked) {
				chkVal = this.value;
				chkTxt = $(this).next().html();
			}
		});
		$("#" + hdnId).val(chkVal);
		$("#" + txtId).html(chkTxt);
	} else {
		var obElCheck = $("input[@type='checkbox']", $("#" + id));
		var arChecked = new Array();
		var i = 0;
		obElCheck.each(function() {
			if (this.checked) {
				arChecked[i] = new Object();
				arChecked[i].value = this.value;
				if (id == "popupJobType" || id == "popupExpJobType") {
					arChecked[i].text = $(this).parent().parent().parent().parent().parent().attr("title") + " &gt; " + $(this).next().html();
				} else {
					arChecked[i].text = $(this).next().html();
				}
				i++;
			}
		});

		var isError = false;
		switch (id) {
			// 勤務地選択
			case "popupOfficePlace":
				if (4 < i) {
					alert("希望勤務地は4つまでしか選択できません");
					isError = true;
				}
				break;
			// 言語選択
			case "popupLanguage":
				if (2 < i) {
					alert("語学は2つまでしか選択できません");
					isError = true;
				}
				break;
			// 資格選択
			case "popupQualification":
				if (6 < i) {
					alert("資格は6つまでしか選択できません");
					isError = true;
				}
				break;
			// 業界選択
			case "popupBusinessType":
			case "popupExpBusinessType":
				if (3 < i) {
					alert("業界は3つまでしか選択できません");
					isError = true;
				}
				break;
			// 職種選択
			case "popupJobType":
			case "popupExpJobType":
				if (3 < i) {
					alert("職種は3つまでしか選択できません");
					isError = true;
				}
				break;
		}

		if (isError) {
			return false;
		} else {
			var setIds = "";
			var setText = "";
			if (id == "popupJobType" || id == "popupExpJobType") {
				for (var j = 0; j<i; j++) {
					setIds += "," + arChecked[j].value;
					setText += "<br />" + arChecked[j].text;
				}
				setIds = setIds.substring(1, setIds.length);
				setText = setText.substring(6, setText.length);
			} else if (id == "popupLanguage") {
				var newLanguageVals = new Array();
				for (var j=0; j<i; j++) {
					var isSelected = false;
					var length = defLanguageVals.length;
					for (var k=0; k<length; k++) {
						if (arChecked[j].value == defLanguageVals[k].value) {
							isSelected = true;
							break;
						}
					}
					newLanguageVals[j] = new Object();
					newLanguageVals[j].value = arChecked[j].value;
					newLanguageVals[j].text = arChecked[j].text;
					if (isSelected) {
						var sel1 = defLanguageVals[k].sel1;
						var sel2 = defLanguageVals[k].sel2;
						var sel3 = defLanguageVals[k].sel3;
						newLanguageVals[j].sel1 = sel1;
						newLanguageVals[j].sel2 = sel2;
						newLanguageVals[j].sel3 = sel3;
						setIds += "," + arChecked[j].value + "-" + sel1 + "-" + sel2 + "-" + sel3;
					} else {
						newLanguageVals[j].sel1 = "";
						newLanguageVals[j].sel2 = "";
						newLanguageVals[j].sel3 = "";
						setIds += "," + arChecked[j].value + "---";
					}
				}
				defLanguageVals = newLanguageVals;
				setIds = setIds.substring(1, setIds.length);
				// tableを作成する
				setText = setLanguageHTML(hdnId);
			} else if (id == "popupQualification") {
				var newQualificationVals = new Array();
				for (var j=0; j<i; j++) {
					var isSelected = false;
					var length = defQualificationVals.length;
					for (var k=0; k<length; k++) {
						if (arChecked[j].value == defQualificationVals[k].value) {
							isSelected = true;
							break;
						}
					}
					newQualificationVals[j] = new Object();
					newQualificationVals[j].value = arChecked[j].value;
					newQualificationVals[j].text = arChecked[j].text;
					if (isSelected) {
						var sel1 = defQualificationVals[k].sel1;
						var sel2 = defQualificationVals[k].sel2;
						newQualificationVals[j].sel1 = sel1;
						newQualificationVals[j].sel2 = sel2;
						setIds += "," + arChecked[j].value + "-" + sel1 + "-" + sel2;
					} else {
						newQualificationVals[j].sel1 = "";
						newQualificationVals[j].sel2 = "";
						setIds += "," + arChecked[j].value + "--";
					}
				}
				defQualificationVals = newQualificationVals;
				setIds = setIds.substring(1, setIds.length);
				// tableを作成する
				setText = setQualificationHTML(hdnId);
			} else {
				for (var j=0; j<i; j++) {
					setIds += "," + arChecked[j].value;
					setText += "、" + arChecked[j].text;
				}
				setIds = setIds.substring(1, setIds.length);
				setText = setText.substring(1, setText.length);
			}
			$("#" + hdnId).val(setIds);
			$("#" + txtId).html(setText);
		}
	}

	// ポップアップを非表示にする
	hiddenSelectWin(id);
}

/*
 * 選択したその他言語の情報に従って一覧を作成する
 */
function setLanguageHTML(hdnId) {
	var setHTML = "";
	var length = defLanguageVals.length;
	if (length == 0) {
			setHTML += "<table class=\"dummyTable\"><tr><td class=\"language\"></td><td class=\"level\"></td></tr></table>";
	} else {
		for (var i=0; i<length; i++) {
			var thisValue = defLanguageVals[i].value;
			var thisText = defLanguageVals[i].text;

			var addClass = "";
			if (0 < i) { addClass = " class=\"addLanguage\""; }

			setHTML += "<table id=\"addSelectedLanguage" + thisValue + "\"" + addClass + " summary=\"" + thisText + "\">";
			setHTML += "<tr><td class=\"language\">" + thisText + "</td>";
			setHTML += "<td class=\"level\">";
			for (var j=0; j<3; j++) {
				var existValue = "";
				switch (j) {
					case 0:
						setHTML += "会話力";
						existValue = defLanguageVals[i].sel1;
						break;
					case 1:
						setHTML += "読解力";
						existValue = defLanguageVals[i].sel2;
						break;
					case 2:
						setHTML += "作文力";
						existValue = defLanguageVals[i].sel3;
						break;
				}
				setHTML += "&nbsp;<select onchange=\"setLanguageLevel(this, '" + hdnId + "', '" + thisValue + "', " + (j + 1) + ");\">";
				var itemLength = arLanguageLevel.length;
				for (var k=0; k<itemLength; k++) {
					var optionsVal = arLanguageLevel[k].value;
					var selected = "";
					if (optionsVal == existValue) {
						selected = " selected=\"selected\"";
					}
					setHTML += "<option value=\"" + arLanguageLevel[k].value + "\"" + selected + ">" + arLanguageLevel[k].text + "</option>";
				}
				setHTML += "</select><br />";
			}
			setHTML += "</td></tr></table>";
		}
	}
	return setHTML;
}

/*
 * 選択した資格の情報に従って一覧を作成する
 */
function setQualificationHTML(hdnId) {
	var setHTML = "";
	var length = defQualificationVals.length;
	if (length == 0) {
			setHTML += "<table class=\"dummyTable\"><tr><td class=\"name\"></td><td class=\"date\"></td></tr></table>";
	} else {
		var addClass = "";
		if (length == 1) { addClass = " class=\"oneQualification\""; }
		for (var i=0; i<length; i++) {
			var thisValue = defQualificationVals[i].value;
			var thisText = defQualificationVals[i].text;

			if (0 < i) { addClass = " class=\"addQualification\""; }

			setHTML += "<table id=\"addSelectedQualification" + thisValue + "\"" + addClass + " summary=\"" + thisText + "\">";
			setHTML += "<tr><td class=\"name\">" + thisText + "</td>";
			setHTML += "<td class=\"date\">";
			setHTML += "<select onchange=\"setQualificationDate(this, '" + hdnId + "', '" + thisValue + "', 1);\">";
			setHTML += "<option value=\"\">----</option>";
			for (var j=parseInt(startYear, 10); j<=parseInt(endYear, 10); j++) {
				var selected = "";
				if (j == parseInt(defQualificationVals[i].sel1, 10)) {
					selected = " selected=\"selected\"";
				}
				setHTML += "<option value=\"" + j + "\"" + selected + ">" + j + "</option>";
			}
			setHTML += "</select>&nbsp;年&nbsp;&nbsp;";
			setHTML += "<select onchange=\"setQualificationDate(this, '" + hdnId + "', '" + thisValue + "', 2);\">";
			setHTML += "<option value=\"\">--</option>";
			for (var j=1; j<=12; j++) {
				var selected = "";
				if (j == parseInt(defQualificationVals[i].sel2, 10)) {
					selected = " selected=\"selected\"";
				}
				setHTML += "<option value=\"" + j + "\"" + selected + ">" + j + "</option>";
			}
			setHTML += "</select>&nbsp;月";
			setHTML += "</td></tr></table>";
		}
	}
	return setHTML;
}

/*
 * 表示中のポップアップを非表示にする
 */
function hiddenSelectWin(id) {
	switch (id) {
		case "popupBusinessType":
		case "popupExpBusinessType":
		case "popupBusinessTypeUL":
		case "popupQualification":
		case "popupJobTypeUL":
			if (objSelectCategory) {
				objSelectCategory.removeClass("focus");
			}
			if (objDisplayTab) {
				objDisplayTab.css("visibility", "hidden");
				objDisplayTab = null;
			}
			break;
		case "popupJobType":
		case "popupExpJobType":
			if (objTopCategory) {
				objTopCategory.removeClass("focus");
			}
			if (objSelectCategory) {
				objSelectCategory.css("visibility", "hidden");
				objSelectCategory = null;
			}
			if (objSubCategory) {
				objSubCategory.removeClass("focus");
			}
			if (objDisplayTab) {
				objDisplayTab.css("visibility", "hidden");
				objDisplayTab = null;
			}
			break;
		case "popupOfficeMap01":
		case "popupOfficeMap02":
		case "popupOfficeMap03":
			$("#" + id).css("display", "none");
			if (obCssOffice) {
				obCssOffice.remove();
				obCssOffice = null;
			}
			break;
	}

	if (id == "popupPrefecture") {
		var obElCheck = $("input[@type='radio']", $("#" + id));
		obElCheck.each(function() {
			this.checked = false;
		});
	} else {
		var obElCheck = $("input[@type='checkbox']", $("#" + id));
		obElCheck.each(function() {
			this.checked = false;
		});
	}

	$("#" + id).css( {"visibility": "hidden", "left": "0", "top": "0"} );
	removeElement(elScreen);
	removeElement(elFrame);
	removeElement(elUnderFrame);
}

/*
 * サブカテゴリの表示を切り替える
 */
function displaySubConstion(obj, id) {
	if (objTopCategory) {
		objTopCategory.removeClass("focus");
	}
	objTopCategory = $(obj);
	objTopCategory.addClass("focus");

	if (objSelectCategory) {
		objSelectCategory.css("visibility", "hidden");
	}
	objSelectCategory = $("#" + id);
	objSelectCategory.css("visibility", "visible");

	if (objSubCategory) {
		objSubCategory.removeClass("focus");
	}

	if (objDisplayTab) {
		objDisplayTab.css("visibility", "hidden");
	}
}

/*
 * タブの表示を切り替える
 */
function displayTab(obj, id, parentId) {
	if (parentId) {
		if (objSelectCategory && objSubCategory) {
			objSubCategory.removeClass("focus");
		}
		objSelectCategory = $("#" + parentId);
		objSubCategory = $(obj);
		objSubCategory.addClass("focus");
	} else {
		if (objSelectCategory) {
			objSelectCategory.removeClass("focus");
		}
		objSelectCategory = $(obj);
		objSelectCategory.addClass("focus");
	}

	if (objDisplayTab) {
		objDisplayTab.css("visibility", "hidden");
	}
	objDisplayTab = $("#" + id);
	objDisplayTab.css("visibility", "visible");
}



/*
 * 言語選択 - 語学のレベルを選択した時の処理
*/
function setLanguageLevel(obj, hdnId, langVal, selType) {
	var arLanguage = analyzeSelectedLanguage(hdnId);

	var elSel = $(obj).get(0);
	var thisVal = elSel[elSel.selectedIndex].value;

	var targetNo = 0;
	var length = arLanguage.length;
	for (var i=0; i<length; i++) {
		if (arLanguage[i].value == langVal) {
			targetNo = i;
			break;
		}
	}

	switch (parseInt(selType, 10)) {
		case 1:
			arLanguage[targetNo].sel1 = thisVal;
			break;
		case 2:
			arLanguage[targetNo].sel2 = thisVal;
			break;
		case 3:
			arLanguage[targetNo].sel3 = thisVal;
			break;
	}
	setSelectedLanguageLevel(hdnId, arLanguage);
}

/*
 * 言語選択 - hiddenフィールドの値を分割し、Arrayに格納する
*/
function analyzeSelectedLanguage(hdnId) {
	var arLanguage = new Array();
	var arSelVals = $("#" + hdnId).val().split(",");
	var length = arSelVals.length;
	for (var i=0; i<length; i++) {
		var divOneVal = arSelVals[i].split("-");
		arLanguage[i] = new Object();
		arLanguage[i].value = divOneVal[0];
		arLanguage[i].sel1 = divOneVal[1];
		arLanguage[i].sel2 = divOneVal[2];
		arLanguage[i].sel3 = divOneVal[3];
	}
	return arLanguage;
}

/*
 * 言語選択 - 選択した言語のレベルをhiddenフィールドに格納する
*/
function setSelectedLanguageLevel(hdnId, arLanguage) {
	var setValue = "";
	var length = arLanguage.length;
	for (var i=0; i<length; i++) {
		setValue += "," + arLanguage[i].value + "-" + arLanguage[i].sel1 + "-" + arLanguage[i].sel2 + "-" + arLanguage[i].sel3;
	}
	setValue = setValue.substring(1, setValue.length);
	$("#" + hdnId).val(setValue);
}


/*
 * 資格選択 - 資格の取得年月を選択した時の処理
*/
function setQualificationDate(obj, hdnId, langVal, selType) {
	var arQualification = analyzeSelectedQualification(hdnId);

	var elSel = $(obj).get(0);
	var thisVal = elSel[elSel.selectedIndex].value;

	var targetNo = 0;
	var length = arQualification.length;
	for (var i=0; i<length; i++) {
		if (arQualification[i].value == langVal) {
			targetNo = i;
			break;
		}
	}

	switch (parseInt(selType, 10)) {
		case 1:
			arQualification[targetNo].sel1 = thisVal;
			break;
		case 2:
			arQualification[targetNo].sel2 = thisVal;
			break;
	}
	setSelectedQualificationDate(hdnId, arQualification);
}

/*
 * 資格選択 - hiddenフィールドの値を分割し、Arrayに格納する
*/
function analyzeSelectedQualification(hdnId) {
	var arQualification = new Array();
	var arSelVals = $("#" + hdnId).val().split(",");
	var length = arSelVals.length;
	for (var i=0; i<length; i++) {
		var divOneVal = arSelVals[i].split("-");
		arQualification[i] = new Object();
		arQualification[i].value = divOneVal[0];
		arQualification[i].sel1 = divOneVal[1];
		arQualification[i].sel2 = divOneVal[2];
	}
	return arQualification;
}

/*
 * 資格選択 - 選択した言語のレベルをhiddenフィールドに格納する
*/
function setSelectedQualificationDate(hdnId, arQualification) {
	var setValue = "";
	var length = arQualification.length;
	for (var i=0; i<length; i++) {
		setValue += "," + arQualification[i].value + "-" + arQualification[i].sel1 + "-" + arQualification[i].sel2;
	}
	setValue = setValue.substring(1, setValue.length);
	$("#" + hdnId).val(setValue);
}

/*
 * ページ領域の取得
*/
function getPageSize() {
	var de = document.documentElement;
	var w = window.innerWidth || self.innerWidth || (de && de.clientWidth) || document.body.clientWidth;
	var h = window.innerHeight || self.innerHeight || (de && de.clientHeight) || document.body.clientHeight;
	var arrayPageSize = new Object();
	arrayPageSize.w = w;
	arrayPageSize.h = h;
	return arrayPageSize;
}

/*
 * 指定されたIDに該当する要素を取得
 * 要素が存在しない場合は、新たに作成する
*/
function findElement(id, addId, tag) {
	var targetId = id;
	if (addId) targetId = targetId + addId;

	var el = $("#" + targetId)[0];
	if (!el) {
		el = document.createElement(tag);
		el.id = targetId;
		document.body.appendChild(el);
	}
	return el;
}

/*
 * 指定された要素を取り除く
*/
function removeElement(obj) {
	if (obj) {
		document.body.removeChild(obj);
	}
}

/*
 * 都道府県の標記を復元する
*/
function restorePrefecture(id, hdnId, popupId) {
	if ($("#" + hdnId).val() != "") {
		var arSelVals = $("#" + hdnId).val().split(",");
		var setText = "";
		if (popupId == "popupOfficePlace") {
			setText = restoreValue(popupId, arSelVals);
		} else if (popupId == "popupPrefecture") {
			var obElRadio = $("input[@type='radio']", $("#popupPrefecture"));
			var length = arSelVals.length;
			obElRadio.each(function() {
				for (var i=0; i<length; i++) {
					var rdoValue = arSelVals[i];
					if (this.value == rdoValue) {
						setText += $(this).next().html() + "、";
						break;
					}
				}
			});
			if (setText != "") {
				setText = setText.substring(0, setText.length - 1);
			}
		}
		$("#" + id).html(setText);
	}
}

/*
 * 業種の標記を復元する
*/
function restoreBusinessType(id, hdnId, popupId) {
	if ($("#" + hdnId).val() != "") {
		var arSelVals = $("#" + hdnId).val().split(",");
		var setText = restoreValue(popupId, arSelVals);
		$("#" + id).html(setText);
	}
}

/*
 * 職種の標記を復元する
*/
function restoreJobType(id, hdnId, popupId) {
	if ($("#" + hdnId).val() != "") {
		var arSelVals = $("#" + hdnId).val().split(",");
		var setText = "";
		if (popupId == "popupJobTypeUL") {
			setText = restoreValue(popupId, arSelVals);
		} else {
			var obElCheck = $("input[@type='checkbox']", $("#" + popupId));
			var length = arSelVals.length;
			obElCheck.each(function() {
				for (var i=0; i<length; i++) {
					var chkValue = arSelVals[i];
					if (this.value == chkValue) {
						setText += $(this).parent().parent().parent().parent().parent().attr("title") + " &gt; " + $(this).next().html() + "<br />";
						break;
					}
				}
			});
			if (setText != "") {
				setText = setText.substring(0, setText.length - 6);
			}
		}
		$("#" + id).html(setText);
	}
}

/*
 * 言語選択欄の標記を復元する
*/
function restoreLanguage(id, hdnId) {
	if ($("#" + hdnId).val() != "") {
		// hiddenフィールドの値を分析 → 配列に格納
		defLanguageVals = analyzeSelectedLanguage(hdnId);

		// ポップアップ部分からテキスト値を取得する
		var obElCheck = $("input[@type='checkbox']", $("#popupLanguage"));
		var length = defLanguageVals.length;
		obElCheck.each(function() {
			for (var i=0; i<length; i++) {
				var chkValue = defLanguageVals[i].value;
				if (this.value == chkValue) {
					defLanguageVals[i].text = $(this).next().html();
					break;
				}
			}
		});

		// 表示するHTMLを作成する
		var setText = setLanguageHTML(hdnId);
		$("#" + id).html(setText);
	}
}

/*
 * 資格選択欄の標記を復元する
*/
function restoreQualification(id, hdnId) {
	if ($("#" + hdnId).val() != "") {
		// hiddenフィールドの値を分析 → 配列に格納
		defQualificationVals = analyzeSelectedQualification(hdnId);

		// ポップアップ部分からテキスト値を取得する
		var obElCheck = $("input[@type='checkbox']", $("#popupQualification"));
		var length = defQualificationVals.length;
		obElCheck.each(function() {
			for (var i=0; i<length; i++) {
				var chkValue = defQualificationVals[i].value;
				if (this.value == chkValue) {
					defQualificationVals[i].text = $(this).next().html();
					break;
				}
			}
		});

		// 表示するHTMLを作成する
		var setText = setQualificationHTML(hdnId);
		$("#" + id).html(setText);
	}
}

/*
 * 選択したポップアップ欄の標記を復元する
*/
function restoreValue(popupId, arVals) {
	var setText = "";
	var obElCheck = $("input[@type='checkbox']", $("#" + popupId));
	var length = arVals.length;
	obElCheck.each(function() {
		for (var i=0; i<length; i++) {
			var chkValue = arVals[i];
			if (this.value == chkValue) {
				setText += $(this).next().html() + "、";
				break;
			}
		}
	});
	if (setText != "") {
		setText = setText.substring(0, setText.length - 1);
	}
	return setText;
}

/*
 * 地図表示用のポップアップをオーバーレイ形式で表示する
 */
function visibleMapWin(id) {
	// 表示時に内容を初期化する
	$("#" + id).css("display", "block");
	var cssOffice = document.createElement("link");
	obCssOffice = $(cssOffice).attr("rel", "stylesheet").attr("type", "text/css").attr("href", datCssOffice.src).attr("media", "print");
	$("head").append(obCssOffice);

	// 背景を作成する
	elScreen = findElement("PU_screen", null, "div");
//	elScreen.onclick = function() {
//		hiddenSelectWin(id);
//	}

	// ポップアップ本体の表示位置を調整する
	var el = $("#" + id)[0];
	var width = el.offsetWidth;
	var height = el.offsetHeight;

	$("#" + id).css({
		"left" : "50%",
		"top" : "50%",
		"margin-left" : 0 - parseInt(width / 2) + "px",
		"margin-top" : 0 - parseInt(height / 2) + 9 + "px",
		"visibility" : "visible"
	});

	// ポップアップのタイトルを取得する
	var popupTitle = $("#" + id + " > h3").html();

	// ポップアップ枠を作成し、表示位置を調整する
	var fWidth = width + 14;
	var fHeight = height + 32;
	elFrame = findElement(id, "_frame", "div");
	elFrame.className = "PU_frame";

	$("#" + id + "_frame").css({ 
		"width" : fWidth + "px",
		"height" : fHeight + "px",
		"margin-left" : 0 - parseInt(fWidth / 2) + "px",
		"margin-top" : 0 - parseInt(fHeight / 2) + "px"
	});

	elFrame.innerHTML = "<div class=\"header\"><p class=\"left\"></p><p class=\"body\">" + popupTitle + "</p><p class=\"right\"></p><a href=\"javascript:hiddenMapWin('" + id + "');\" class=\"closeButton\">CLOSE</a></div><div class=\"body\"></div><div class=\"content\" style=\"height: " + height + "px;\"></div><div class=\"footer\"><p class=\"left\"></p><p class=\"body\"></p><p class=\"right\"></p></div>";

	// ターゲットブラウザの判別
	var isIE6 = false;
	var isSafari1_3 = false;
	var isFirefox2 = false;
	if (navigator.userAgent.match(/MSIE (\d\.\d+)/)) {
		if (RegExp.$1 == "6.0") isIE6 = true;
	} else if (navigator.userAgent.match(/Safari\/([\.\d]+)/)) {
		if (300 <= parseInt(RegExp.$1) && parseInt(RegExp.$1) < 400) {
			isSafari1_3 = true;
		} else if (500 <= parseInt(RegExp.$1)) {
		}
	} else if (navigator.userAgent.match(/Firefox\/([\.\d]+)/)) {
		if (parseInt(RegExp.$1) < 3) isFirefox2 = true;
	}

	if (isIE6) {		// IE6用のバグ対策

		// 背景部分のサイズを調整する
		var screenHeight;
		if (document.body.scrollHeight > document.body.offsetHeight) {
			screenHeight = document.body.scrollHeight;
		} else {
			screenHeight = document.body.offsetHeight;
		}
		$(elScreen).css("height", screenHeight + "px");


		// IE用に印刷の前後で、背景部分のサイズを変更する
		document.body.onbeforeprint = function() {	// 印刷前
			$(elScreen).css("height", "0");
		}

		document.body.onafterprint = function() {// 印刷後
			$(elScreen).css("height", screenHeight + "px");
		}

		// インラインフレームの幅と高さは、角丸の半径の分だけ差し引く
		var ufWidth = fWidth - 6;
		var ufHeight = fHeight - 6;

		// オーバーレイの下にselectタグがあると、表示がおかしくなるので、ifameを下に表示する
//		elUnderFrame = findElement(id, "_underFrame", "iframe");
//		elUnderFrame.className = "PU_Uframe";
		var targetId = id + "_underFrame";
		elUnderFrame = $("#" + targetId)[0];
		if (!elUnderFrame) {
			elUnderFrame = document.createElement("iframe");
			elUnderFrame.id = targetId;
			elUnderFrame.src = "/common/blank.html";
			document.body.appendChild(elUnderFrame);
		}
		elUnderFrame.className = "PU_Uframe";

		$("#" + id + "_underFrame").css({ 
			"width" : ufWidth + "px",
			"height" : ufHeight + "px",
			"margin-left" : 0 - parseInt(ufWidth / 2) + "px",
			"margin-top" : 0 - parseInt(ufHeight / 2) + "px"
		});

		// margin で位置を調整する
		var scrollTop = document.documentElement.scrollTop;
		$("#" + id).css("margin-top", 0 - parseInt(height / 2) + 9 + scrollTop + "px");
		$("#" + id + "_frame").css("margin-top", 0 - parseInt(fHeight / 2) + scrollTop + "px");
		$("#" + id + "_underFrame").css("margin-top", 0 - parseInt(ufHeight / 2) + scrollTop + "px");

/*	} else if (isSafari1_3) {	// Safari1.3 の場合は、スクロールすると表示がおかしくなるので・・・IE6と同様の表現にする*/
	} else {	// Safari1.3 の場合は、スクロールすると表示がおかしくなるので・・・IE6と同様の表現にする
		var scrollTop;
		if (window.scrollY) {
			scrollTop = window.scrollY;
		} else {
			scrollTop = document.documentElement.scrollTop;
		}

		$(".PU_body").css({
			"position": "absolute",
			"margin-top": (0 - parseInt(height / 2) + 9 + parseInt(scrollTop) + "px")
		});
		$(".PU_frame").css({
			"position": "absolute",
			"margin-top": (0 - parseInt(fHeight / 2) + parseInt(scrollTop) + "px")
		});
	}
	return false;
}

/*
 * 地図表示用ポップアップを非表示にする
 */
function hiddenMapWin(id) {
	$("#" + id).css("display", "none");
	if (obCssOffice) {
		obCssOffice.remove();
		obCssOffice = null;
	}

	$("#" + id).css( {"visibility": "hidden", "left": "0", "top": "0"} );
	removeElement(elScreen);
	removeElement(elFrame);
	removeElement(elUnderFrame);
}


var objFlash = null;
var objFlashObjects = null;
var objFlashEmbeds = null;
var objDummyImage = null;

/*
 * 転職ノウハウFlashをオーバーレイ形式で表示する
 */
function showAdviceFlash(obj, width, height, popupTitle, dummyId) {

	// 親が面のFlashを一旦非表示にする
	// Flash上にdiv要素などのHTMLによるレイヤーは重ねることができないため（ブラウザの仕様）
	objFlashObjects = $("object");
	objFlashEmbeds = $("embed");

	var isImageSet = false;
	if (objFlashObjects) {
		objFlashObjects.css("visibility", "hidden");
	}

	if (objFlashEmbeds) {
		objFlashEmbeds.css("visibility", "hidden");
	}

	var id = "flashWrap";

	// 背景を作成する
	elScreen = findElement("PU_screen", null, "div");
//	elScreen.onclick = function() {
//		hiddenSelectWin(id);
//	}

	var elFlash = findElement(id, null, "iframe");
	objFlash = $(elFlash);
	objFlash.attr("src", obj.href);
	objFlash.attr("border", "0");
	objFlash.attr("frameborder", "0");
	objFlash.addClass("PU_body");
	objFlash.css({
		"overflow" : "hidden",
		"left" : "50%",
		"top" : "50%",
		"margin-left" : 0 - parseInt(width / 2) + "px",
		"margin-top" : 0 - parseInt(height / 2) + 9 + "px",
		"padding": "0",
		"border": "0",
		"width": width + "px",
		"height": height + "px",
		"visibility" : "visible",
		"z-index": "200"
	});

	// ポップアップ枠を作成し、表示位置を調整する
	var fWidth = width + 14;
	var fHeight = height + 32;
	elFrame = findElement(id, "_frame", "div");
	elFrame.className = "PU_frame";

	$("#" + id + "_frame").css({ 
		"width" : fWidth + "px",
		"height" : fHeight + "px",
		"margin-left" : 0 - parseInt(fWidth / 2) + "px",
		"margin-top" : 0 - parseInt(fHeight / 2) + "px"
	});

	elFrame.innerHTML = "<div class=\"header\"><p class=\"left\"></p><p class=\"body\">" + popupTitle + "</p><p class=\"right\"></p><a href=\"javascript:hiddenAdviceFlash('" + id + "');\" class=\"closeButton\">CLOSE</a></div><div class=\"body\"></div><div class=\"content\" style=\"height: " + height + "px;\"></div><div class=\"footer\"><p class=\"left\"></p><p class=\"body\"></p><p class=\"right\"></p></div>";

	// ターゲットブラウザの判別
	var isIE6 = false;
	var isSafari1_3 = false;
	var isFirefox2 = false;
	if (navigator.userAgent.match(/MSIE (\d\.\d+)/)) {
		if (RegExp.$1 == "6.0") isIE6 = true;
	} else if (navigator.userAgent.match(/Safari\/([\.\d]+)/)) {
		if (300 <= parseInt(RegExp.$1) && parseInt(RegExp.$1) < 400) {
			isSafari1_3 = true;
		} else if (500 <= parseInt(RegExp.$1)) {
		}
	} else if (navigator.userAgent.match(/Firefox\/([\.\d]+)/)) {
		if (parseInt(RegExp.$1) < 3) isFirefox2 = true;
	}

	if (isIE6) {		// IE6用のバグ対策

		// 背景部分のサイズを調整する
		var screenHeight;
		if (document.body.scrollHeight > document.body.offsetHeight) {
			screenHeight = document.body.scrollHeight;
		} else {
			screenHeight = document.body.offsetHeight;
		}
		$(elScreen).css("height", screenHeight + "px");


		// IE用に印刷の前後で、背景部分のサイズを変更する
		document.body.onbeforeprint = function() {	// 印刷前
			$(elScreen).css("height", "0");
		}

		document.body.onafterprint = function() {// 印刷後
			$(elScreen).css("height", screenHeight + "px");
		}

		// インラインフレームの幅と高さは、角丸の半径の分だけ差し引く
		var ufWidth = fWidth;
		var ufHeight = fHeight;
//		var ufWidth = fWidth - 6;
//		var ufHeight = fHeight - 6;

		// オーバーレイの下にselectタグがあると、表示がおかしくなるので、ifameを下に表示する
//		elUnderFrame = findElement(id, "_underFrame", "iframe");
//		elUnderFrame.className = "PU_Uframe";
		var targetId = id + "_underFrame";
		elUnderFrame = $("#" + targetId)[0];
		if (!elUnderFrame) {
			elUnderFrame = document.createElement("iframe");
			elUnderFrame.id = targetId;
			elUnderFrame.src = "/common/blank.html";
			document.body.appendChild(elUnderFrame);
		}
		elUnderFrame.className = "PU_Uframe";

		$("#" + id + "_underFrame").css({ 
			"width" : ufWidth + "px",
			"height" : ufHeight + "px",
			"margin-left" : 0 - parseInt(ufWidth / 2) + "px",
			"margin-top" : 0 - parseInt(ufHeight / 2) + "px"
		});

		// margin で位置を調整する
		var scrollTop = document.documentElement.scrollTop;
		$("#" + id).css("margin-top", 0 - parseInt(height / 2) + 9 + scrollTop + "px");
		$("#" + id + "_frame").css("margin-top", 0 - parseInt(fHeight / 2) + scrollTop + "px");
		$("#" + id + "_underFrame").css("margin-top", 0 - parseInt(ufHeight / 2) + scrollTop + "px");

/*	} else if (isSafari1_3) {	// Safari1.3 の場合は、スクロールすると表示がおかしくなるので・・・IE6と同様の表現にする*/
	} else {	// Safari1.3 の場合は、スクロールすると表示がおかしくなるので・・・IE6と同様の表現にする
		var scrollTop;
		if (window.scrollY) {
			scrollTop = window.scrollY;
		} else {
			scrollTop = document.documentElement.scrollTop;
		}

		$(".PU_body").css({
			"position": "absolute",
			"margin-top": (0 - parseInt(height / 2) + 9 + parseInt(scrollTop) + "px")
		});
		$(".PU_frame").css({
			"position": "absolute",
			"margin-top": (0 - parseInt(fHeight / 2) + parseInt(scrollTop) + "px")
		});
	}

	if (isFirefox2) {
		$(elScreen).css("position", "absolute");
	}

	return false;
}

/*
 * 転職ノウハウ（Flash）のポップアップを非表示にする
 */
function hiddenAdviceFlash(id) {

	objFlash.attr("src", "");


	$("#" + id).css( {"visibility": "hidden", "left": "0", "top": "0"} );
	removeElement(elScreen);
	removeElement(elFrame);
	removeElement(elUnderFrame);

	if (objFlashObjects) {
		objFlashObjects.css("visibility", "visible");
		objFlashObjects = null;
	}
	if (objFlashEmbeds) {
		objFlashEmbeds.css("visibility", "visible");
		objFlashEmbeds = null;
	}
}

