var curViewRcType = "";
var curViewJidx = "";

function viewSummary(rcType, j_idx, event) {
	if (curViewRcType != "" && curViewJidx != "") {
		closeSummary(curViewJidx);
	}
	if ($("SummaryClose" + j_idx) != null) $("SummaryClose" + j_idx).style.display = "block";
	if ($("SummaryView" + j_idx) != null) $("SummaryView" + j_idx).style.display = "none";

	curViewRcType = rcType;
	curViewJidx = j_idx;

	var mainWidth = Element.getWidth($("global"));		// 960
	var mainLeft = $("global").offsetLeft;
	var eventLeft = Event.pointerX(event);
	var eventTop = Event.pointerY(event);
	var btnGap = 8; //$("SummaryView" + j_idx).offsetTop;
	var layerWidth = 504;
	var layerLeft = eventLeft - mainLeft;

	new Insertion.Bottom("global", "<div id='SummaryContainer' class='summary' style='background:none'></div>");
	ajax_updater("SummaryContainer", "/alba/alba_view_preview.asp", "get", "rcType=" + rcType + "&j_idx=" + j_idx.split("|")[0]);
	if ((layerLeft + layerWidth) < mainWidth) {
		$("SummaryContainer").style.left = layerLeft + "px";
		$("SummaryContainer").style.top = (eventTop + btnGap) + "px";
	} else if ((layerLeft - layerWidth) < 0) {
		$("SummaryContainer").style.left = parseInt((mainWidth - layerWidth) / 2) + "px";
		$("SummaryContainer").style.top = (eventTop + btnGap) + "px";
	} else if ((layerLeft + layerWidth) > mainWidth) {
		$("SummaryContainer").style.left = (layerLeft - layerWidth) + "px";
		$("SummaryContainer").style.top = (eventTop + btnGap) + "px";
	}
	$("SummaryContainer").style.display = "block";
}

function closeSummary(j_idx) {
	curViewRcType = "";
	curViewJidx = "";
	if ($("SummaryClose" + j_idx) != null) $("SummaryClose" + j_idx).style.display = "none";
	if ($("SummaryView" + j_idx) != null) $("SummaryView" + j_idx).style.display = "block";
	$("SummaryContainer").style.display = "none";
}

function ajax_updater(_placeholder, _url, _method, _pars) {
	//showLoadingLayer();
	var myAjax = new Ajax.Updater(
		{success: _placeholder},
		_url,
		{
			method: _method,
			parameters: _pars,
			/*onLoading: function(req) {
				if (req.readyState == 1) {
					$(_placeholder).innerHTML = "<div style='height:100px;text-align:center;padding-top:30;'><img src='http://image.alba.kr/common/loading.gif' /></div>";
				}
			},*/
			onFailure: function(req) {$(_placeholder).innerHTML = "Error...";},
			//onComplete: function(req) {hideLoadingLayer();},
			evalScripts: true
		}
	);
}

function ajax_result(_url, _method, _pars, _obj) {
	var objAjax = new Ajax.Request(
		_url, {
			method: _method,
			parameters: _pars,
			onComplete: function(response) {fillSelectBoxJSON(response, _obj);}
			//onComplete: showResponse
		}
	);
}

// For Test
function showResponse(originalRequest) {
	alert("RESULT:" + originalRequest.responseText);
}

function fillSelectBoxJSON(res, obj)
{
	var serverData = res.responseText;
	var evalData = eval("(" + serverData + ")");
	obj.options.length = 1;

	if (evalData.result != "SUCCESS") {
		return;
	}

	for (var i = 0; i < evalData.data.length; i++) {
		var opt = new Option;
		opt.value = evalData.data[i].value;
		opt.text = evalData.data[i].text;
		obj.options[i + 1] = opt;
	}
	obj.options[evalData.data.length + 1] = new Option("ÀüÃ¼", "ÀüÃ¼");
}