/* イベント初期化 */
$(function() {
	JT_init();
	$(".showMylist").click(function(){ window.location.href = "/mypage/" ; return false;}); 
	$(".showNairan").click(function(){ window.location.href = "/search/request.html"; return false; }); 
	$(".showRequest").click(function(){ window.location.href = "/search/request.html";  return false;}); 
	$(".changeCondition").click(function(){ window.location.href = "/search/condition.html";  return false;}); 
	$("#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 onMylistClick(o){
	
	var code = $(o).attr("code");
	var seq  = $(o).attr("seq");
	var d = { "code" : code, "seq" : seq };
	var cmd  = "cmd-" + $(o).attr("cmd") + "MyList";	// add or del
	d[cmd] = 1;
	$("#body").css('cursor','wait');
	$.post(
		'/search/',
		d,
		function (ret)
		{
			$("#body").css('cursor','auto');

			if (ret.status == "SUCCESS")
			{
				// 一覧の更新
				$("#list_" + code + "_" + seq + "_1").html(ret.list1);
				$("#list_" + code + "_" + seq + "_2").html(ret.list2);

				$(".showMylist").attr('src','/search/images/btn_mylist_blink.gif');
				
				if(ret.msg)
				{
					alert(ret.msg);
				}
			}
			else
			{
				alert(ret.msg);
			}
		},
		"json"
	);
}


/* ボタン型選択のイベントハンドラー */
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);
						}
//						alert( $('#frmCondition').attr('action'));
						// フォームの飛び先を変更 （地域・路線変更時
						if(cid=='action')
						{
							$('#frmCondition').attr('action', ''+body);
						}
						// 20090622
						//self.location.href = $('#frmCondition').attr('action');
					});
				}
			}
			else
			{
				alert(ret.msg);
			}
		},
		"json"
	);
	return false;
}


/* 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;
}
