/* イベント初期化 */
$(function() {
	// 検索条件決定
	$("#frmCondition").submit(function()
	{
		var d = zen_make_params("#frmCondition", "check");
		$.post(
			location.href,
			d,
			function (ret)
			{
				if (ret.status == "SUCCESS")
				{
					location.href = "./rMailMember.html";
				}
				else
				{
					alert(ret.msg);
				}
			},
			"json"
		);
		return false;
	});

	// 検索条件のクリア
	$("#clearCondition2").click(function(){
		$.post(
			'/search/ui/',
			{"cmd-clearCondition": 1},
			function (ret)
			{
				if (ret.status == "SUCCESS")
				{
					window.location.reload(true);
				}
				else
				{
					alert(ret.msg);
				}
			},
			"json"
		);
		return false;
	});

	// 構造・外観　条件すべてチェック
	$("#chk_view_all").click(function(){
		var ck = this.checked;
		$("#frmCondition .view input[@type='checkbox']").each(function(){
			this.checked = ck;
		})
		return true;
	});

	// 設備・サービス　条件すべてチェック　
	$("#chk_equip_all").click(function(){
		var ck = this.checked;
		$("#frmCondition .equip input[@type='checkbox']").each(function(){
			this.checked = ck;
		})
		return true;
	});

	JT_init();

	$("#clearCondition").click(function(){
		$.post(
			'/search/ui/',
			{"cmd-clearCondition": 1},
			function (ret)
			{
				if (ret.status == "SUCCESS")
				{
					// 検索条件一覧を更新
					if(ret.url)
					{
						window.location.href= ret.url;
					}
					else
					{
						window.location.href= "./";
					}
				}
				else
				{
					alert(ret.msg);
				}
			},
			"json"
		);
		return false;
	});

});


/* ボタン型選択のイベントハンドラー */
function onBtnClick(o)
{
	var id	= $(o).attr("id");
	var d = { "id" : id , 'href':$(o).attr("href")  };
	var cmd  = "cmd-" + $(o).attr("cmd") ;
	d[cmd] = 1;
	$.post(
		'/search/ui/',
		d,
		function (ret)
		{
			if (ret.status == "SUCCESS")
			{
				if(ret.msg)
				{
					alert(ret.msg);
				}
				// コントロールの更新
				if(ret.html)
				{
					$.each(ret.html, function(cid,body){
						if($(cid)&&$(cid).html)
						{
							$(cid).html(''+ body);
						}
					});
				}
				if(ret.condition)
				{
					$("#conditionText").html(ret.condition);
				}
			}
			else
			{
				alert(ret.msg);
			}
		},
		"json"
	);
}


/* jTip によるポップアップ */
var jTipID = '';
function showTip(o)
{
	JT_remove();
	//if( jTipID != o.id )
	{
		var href = (o.href)? o.href : $(o).attr('url');
		JT_show(href, o.id, o.name);
		jTipID = o.id;
	}
	//else
	{
		jTipID = '';
	}
	return false;
}

/******************************************************************************
 * すべてを選択チェックボックス
 *****************************************************************************/
function onCheckViewAll() {
	if ($("#chkViewAll").attr("checked")) $("#pnlViewCheck input.view").attr("checked", "checked");
	else $("#pnlViewCheck input.view").removeAttr("checked");
}

function onCheckEquipAll() {
	if ($("#chkEquipAll").attr("checked")) $("#pnlEquipCheck input.equip").attr("checked", "checked");
	else $("#pnlEquipCheck input.equip").removeAttr("checked");
}

/******************************************************************************
 * エリア変更イベントハンドラ
 * @param li
 * @returns {Boolean}
 */
function onAreaTabClick(code) {
	var d = { "code": code, "cmd-changeArea": 1 };
	$.post(
		location.href,
		d,
		function (ret) {
			if (ret.status == "SUCCESS")
			{
				$("#arealist").html(ret.area);
			}
			else {
				alert(ret.msg);
			}
		},
		"json"
	);
	return false;
}
