﻿//
//共通
//

//次のページに遷移
function common_transfer(strForm){
	document.forms[strForm].submit();
}

//単体MAPを表示
function common_map(){
	//引数をチェック
	if (!common_map.arguments) return;
	var strForm = common_map.arguments[0];
	if (common_map.arguments.length >= 2){
		document.forms[strForm].elements["map_media_id"].value = common_map.arguments[1];
	}
	if (common_map.arguments.length >= 3 && document.getElementById(common_map.arguments[2])){
		document.forms[strForm].elements["map_area2_id"].value = document.getElementById(common_map.arguments[2]).value;
	}
	//ウィンドウサイズを設定
	var w = screen.availWidth;
	var h = screen.availHeight;
	if (w > 900) w = 900;
	if (h > 878) h = 878;
	//MAPページを表示
	var win = window.open("about:blank", "map", "width=" + w + ",height=" + h + ",dependent=yes,scrollbars=yes,status=no");
	document.forms[strForm].submit();
	win.focus();
}

//配列の要素を追加・削除
function common_addRmvArray(arrOrg, strItem, intAdd){
	var arrRet = new Array();
	for (var i = 0; i < arrOrg.length; i ++){
		if (arrOrg[i] != strItem){
			arrRet.push(arrOrg[i]);
		}
	}
	if (intAdd == 1){
		arrRet.push(strItem)
	}
	return arrRet;
}


//
//トップページ
//top.aspx
//

//キーワード入力チェック
function top_validateKeyword(){
	if (document.forms["f_top_searchKeyword"].elements["search_keyword"].value == ""){
		alert("キーワードを入力して下さい。");
		return false;
	}
	return true;
}

//キーワード検索
function top_searchKeyword(){
	if (top_validateKeyword()){
		document.forms["f_top_searchKeyword"].submit();
	}
}

//メディア種別検索
function top_searchType(strValue){
	//検索実行
	document.forms["f_top_searchType"].elements["type_id"].value = strValue;
	document.forms["f_top_searchType"].submit();
}


//
//詳細検索ページ
//search.aspx
//

//業種業態の表示を切替
function search_changeDisplay(strId){
	if (document.getElementById(strId).value == "0"){
		//開く
		document.getElementById(strId + "ul").style.display = "block";
		document.getElementById(strId + "img").src = "../images/static/search/close_btn.gif";
		document.getElementById(strId + "img").alt = "閉じる";
		document.getElementById(strId).value = "1";
	}else{
		//閉じる
		document.getElementById(strId + "ul").style.display = "none";
		document.getElementById(strId + "img").src = "../images/static/search/open_btn.gif";
		document.getElementById(strId + "img").alt = "開く";
		document.getElementById(strId).value = "0";
	}
}

//グループのチェックを一括操作
function search_checkChildren(objParent){
	var elem = document.getElementById(objParent.id + "ul").getElementsByTagName("input")
	for (var i = 0; i < elem.length; i ++){
		if (elem[i].type == "checkbox" && !elem[i].disabled) elem[i].checked = objParent.checked;
	}
}


//
//検索結果ページ
//result.aspx
//

//メディアを選択
function result_selectMedia(objChk, strId){
	if (objChk.checked){
		if (document.getElementById("select_media_id").value.split(",").length > 20){
			objChk.checked = false;
			alert("同時に選択できるのは20件までとなっています。");
			return;
		}
		document.getElementById("select_media_id").value = common_addRmvArray(document.getElementById("select_media_id").value.split(","), strId, 1).join(",");
	}else{
		document.getElementById("select_media_id").value = common_addRmvArray(document.getElementById("select_media_id").value.split(","), strId, 0).join(",");
	}
}

//メディアの選択チェック
function result_validateMedia(){
	if (document.getElementById("select_media_id").value == ""){
		alert("メディアが選択されていません。");
		return false;
	}
	return true;
}

//複数メディアを一括マップ表示
function result_map(){
	if (result_validateMedia()){
		//選択メディアを設定
		document.forms["f_result_map"].elements["map_media_id"].value = document.getElementById("select_media_id").value;
		//ウィンドウサイズを設定
		var w = screen.availWidth;
		var h = screen.availHeight;
		if (w > 900) w = 900;
		if (h > 878) h = 878;
		//MAPページを表示
		var win = window.open("about:blank", "map", "width=" + w + ",height=" + h + ",dependent=yes,scrollbars=yes,status=no");
		document.forms["f_result_map"].submit();
		win.focus();
	}
}

//複数メディアを一括問い合わせ
function result_request(){
	if (result_validateMedia()){
		document.forms["f_result_request"].elements["request_media_id"].value = document.getElementById("select_media_id").value;
		document.forms["f_result_request"].submit();
	}
}