//gDebug = true;

function doRootLogin()
{
	if ($('loginID').value == "")
	{
		alert("아이디를 입력하세요.");
		setFocus('loginID');
		return ;
	}

	if ($('passwd').value == "")
	{
		alert("패스워드를 입력하세요.");
		setFocus('passwd');
		return ;
	}

	gHttpObj.clearValue();
	gHttpObj.setForm('loginForm');

	if (gHttpObj.doSubmit(gURL_root + gSitePath + "/auth.php"))
	{
		try
		{
			var result = gHttpObj.oMessage.selectSingleNode('//message/text()').nodeValue;
			switch (result)
			{
				case 'LOGIN_FAILED':
					$('passwd').value = "";
					setFocus('passwd');
					alert("입력하신 패스워드가 맞는지 다시 확인해 주시기 바랍니다.");
					break;
				case 'LOGINED':
					location.href = $('url').value;
				break;
			}
		}
		catch (e)
		{
			alert("로그인에 실패하였습니다. [오류코드: LOGIN ERR-1]");
		}
	}
	else
	{
		alert("로그인에 실패하였습니다. [오류코드: LOGIN ERR-2]");
	}

	return ;
}

/*
	Prima Page Control
*/
var primaPageControl = function() {};

primaPageControl = {
	_distance:50,
	_curWidth:984,
	_pageMenuWidth:204, // __pageMenuHolder
	_x:null,
	_isDragStarted:false,
	_bMenuVisible:true,
	setWidth:function(nWidth)
	{
		if (this._curWidth == nWidth)
			return ;

		if (nWidth < 984)
		{
			primaPageControl._isDragStarted = false;
			nWidth = 984;
//			alert(loadString('MSG_PAGE_MINIMIZED'));
//			return ;
		}

		this.reSize(nWidth);
	},
	reSize:function(nWidth)
	{
		var nContentWidth = nWidth - this._pageMenuWidth;

		if (!this._bMenuVisible)
		{
			nContentWidth = nContentWidth + 160;

			if ($('__pageMenuHolder'))
			{
				$('__pageMenuHolder').style.float = 'left';
				$('__pageMenuHolder').style.width = '10px';
			}

			hide($('__treeMenuHide'));
			show($('__treeMenuShow'));
		}
		else
		{
			if ($('__pageMenuHolder'))
			{
				$('__pageMenuHolder').style.float = 'left';
				$('__pageMenuHolder').style.width = '170px';
			}

			show($('__treeMenuHide'));
			hide($('__treeMenuShow'));
		}

		this._curWidth = nWidth;

		$('__masterPage').style.width = nWidth + "px";
		$('__pageHolder').style.width = nWidth + "px";

		if ($('__contentHolder'))
			$('__contentHolder').style.width = nContentWidth + "px";
	},
	plus:function()
	{
		this.setWidth(this._curWidth + this._distance);
	},
	minus:function()
	{
		this.setWidth(this._curWidth - this._distance);
	},
	startDrag:function()
	{
		primaPageControl._isDragStarted = true;
		primaPageControl._x	= event.clientX;

		document.body.style.cursor = "e-resize";

//		document.onmousemove = primaPageControl.onDrag;
		document.onmouseup = primaPageControl.stopDrag;
	},
	onDrag:function()
	{
		if (primaPageControl._isDragStarted == false)
			return;
	},
	stopDrag:function()
	{
		if (primaPageControl._isDragStarted == false)
			return;

		document.body.style.cursor = "auto";

		var nDistance  = parseInt(event.clientX) - primaPageControl._x;
		primaPageControl.setWidth(parseInt(primaPageControl._curWidth) + parseInt(nDistance));

		//window.status = "onDrag: " + nDistance + " , curWidth: " + primaPageControl._curWidth;

		// 너비가 조정되었으므로, 관리자 환경 설정에 반영
		gHttpObj.clearValue();
		gHttpObj.setValue('action', 'BackgroundSetting');
		gHttpObj.setValue('key','page_width');
		gHttpObj.setValue('value', primaPageControl._curWidth);
		gHttpObj.doSubmitByQue(gURL_root + gSitePath + "/manage/preference.php");

		primaPageControl._isDragStarted = false;
	},
	toggleMenu:function()
	{
		if (this._bMenuVisible)
		{
			hide($('__pageMenuTitleHolder'));
			hide($('__pageMenuTreeHolder'));
		}
		else
		{
			show($('__pageMenuTitleHolder'));
			show($('__pageMenuTreeHolder'));
		}

		this._bMenuVisible = !this._bMenuVisible;

		this.reSize(this._curWidth);
	}
};


/* onSubmit */
function isValidFormData(oForm)
{
	return true;
}

function findForm(oResetFormFields, bFillFormValue)
{
	if (bFillFormValue == undefined)
		var bFillFormValue = false;

	var oForm = document.forms['pageForm'];

	if (!oForm)
	{
		alert('pageForm 폼을 찾을 수 없습니다.');
		return ;
	}

	if (oForm.onsubmit &&
		oForm.onsubmit() == false)
		return ;

	if (oForm.prefix)
		oForm.prefix.value = '';

	if (oResetFormFields != undefined)
	{
		for (var k in oResetFormFields)
			oForm[k].value = bFillFormValue ? oResetFormFields[k] : "";
	}

	oForm.page.value = '1';
	oForm.submit();
}


/* 우편번호 찾기(manage 용) */
function findZipcode(formName, zipcode1, zipcode2, address, focusFormName)
{
	showPopup(gURL_root + gSitePath + "/manage/zipcode.php?formName=" + formName + "&zipcode1=" + zipcode1 + "&zipcode2=" + zipcode2 + "&address=" + address + "&focusFormName=" + focusFormName, "zipcode", 460, 370, false, false);
}

/* 엑셀자료 */
function saveAsExcel()
{
	var oForm = document.forms['pageForm'];

	oForm['is_excel'].value = 1;
	oForm.submit();
	oForm['is_excel'].value = 0;
}

// 폼 페이지에서 현재 폼 값으로 리로드 시 사용
function needReloadForm(oForm)
{
	oForm['action'].value = "Form";
	oForm.submit();
}

