// 예약 체크 전역변수
var gSubscription = false;

function openWindow(fileName, windowName, theWidth, theHeight, etcParam) {
	var objNewWin;
	var x = theWidth;
	var y = theHeight;

	var sy = window.screen.height / 2 - y / 2 - 70;

	if (etcParam == 'fix') {
		var sy = window.screen.height / 2 - y / 2 - 40;
	} else if (etcParam == 'resize') {
		var sy = window.screen.height / 2 - y / 2 - 40;
	}
	etcParam = "status:No;resizable:No;scroll:no;";


	var sx = window.screen.width  / 2 - x / 2;

	if (sy < 0 ){
		sy = 0;
	}

	var sz = "px; dialogTop:" + sy + ";dialogLeft:" + sx;

	if (windowName == "newMessageWindow") 	{
		windowName = new String(Math.round(Math.random() * 100000));
	}

	objNewWin = showModalDialog(fileName, window, etcParam + ";dialogWidth:" + x + "px; dialogHeight:" + y + sz);

//	window.open(fileName, "", etcParam + ";dialogWidth:" + x + "px; dialogHeight:" + y + sz);
}

// 결재문서 Call
function openDocWindow(fileName,windowName,etcParam,scrollbars) {
	var x;
	var y;

	if (windowName == "newMessageWindow")
	{
	windowName = new String(Math.round(Math.random() * 100000));
	}

	if (etcParam == 'fix') {
		x = window.screen.availWidth - 10;
		y = window.screen.availheight - 30;

		etcParam = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0";
	}
	else if (etcParam == 'resize') {
		x = window.screen.availWidth - 10;
		y = window.screen.availheight - 30;

		etcParam = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars="+scrollbars+",resizable=1";
	}
	objNewWin = window.open(fileName,windowName, etcParam + ",top=0,left=0,width=" + x + ",height=" + y);
}

//
function openHelpWindow(fileName,windowName,theWidth,theHeight, etcParam) {

	var objNewWin;
	var x = theWidth;
	var y = theHeight;

	var sy = window.screen.height / 2 - y / 2 - 70;
	if (etcParam == 'fix') {
		etcParam = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0";
		var sy = window.screen.height / 2 - y / 2 - 40;
	}
	else if (etcParam == 'resize') {
		etcParam = "toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1";
		var sy = window.screen.height / 2 - y / 2 - 40;
	}

	var sx = window.screen.width  / 2 - x / 2;


	if (sy < 0 ) {
		sy = 0;
	}

	var sz = ",top=" + sy + ",left=" + sx;

	if (windowName == "newMessageWindow")
	{
	windowName = new String(Math.round(Math.random() * 100000));
	}

	objNewWin = window.open(fileName,windowName, etcParam + ",width=" + x + ",height=" + y + sz);
	objNewWin.focus();
	return objNewWin;
}

function openModalessWindow(fileName, windowName, theWidth, theHeight, etcParam) {
	var objNewWin;
	var x = theWidth;
	var y = theHeight;

	var sy = window.screen.height / 2 - y / 2 - 70;

	if (etcParam == 'fix') {
		var sy = window.screen.height / 2 - y / 2 - 40;
	} else if (etcParam == 'resize') {
		var sy = window.screen.height / 2 - y / 2 - 40;
	}
	etcParam = "status:No;resizable:No;scroll:no";

	var sx = window.screen.width  / 2 - x / 2;

	if (sy < 0 ){
		sy = 0;
	}

	var sz = "px; dialogTop:" + sy + ";dialogLeft:" + sx;

	if (windowName == "newMessageWindow") 	{
		windowName = new String(Math.round(Math.random() * 100000));
	}

	objNewWin = showModelessDialog(fileName, window, etcParam + ";dialogWidth:" + x + "px; dialogHeight:" + y + sz);

//	window.open(fileName, "", etcParam + ";dialogWidth:" + x + "px; dialogHeight:" + y + sz);
}

function EnterToTab() {
    key_code			= event.keyCode;
    key_shift			= event.shiftKey;

    if(key_shift != true) {
		if(key_code == 13) {
			event.keyCode         = 9;
//			selectNext(event.srcElement, 1);
			return;
		}
    }
}

function EnterToTabTarget(TargetObj) {
    key_code			= event.keyCode;
    key_shift			= event.shiftKey;

    if(key_shift != true) {
		if(key_code == 13) {
			TargetObj.focus();
//			selectNext(event.srcElement, 1);
			return;
		}
    }
}


// 콤마 관련
function CommaIn(input) {
	eval(input).value = putComma(eval(input).value);
}

function CommaOut(input) {
	eval(input).value = eval(input).value.replace(/,/gi,"");
}

function putComma(input) {
	var num = input;

	if (num < 0) {
		num *= -1;
		var minus = true
	}else{
		var minus = false
	}

	var dotPos = (num+"").split(".")
	var dotU = dotPos[0]
	var dotD = dotPos[1]
	var commaFlag = dotU.length%3

	if(commaFlag) {
		var out = dotU.substring(0, commaFlag)
		if (dotU.length > 3) out += ","
	}
	else var out = ""

	for (var i=commaFlag; i < dotU.length; i+=3) {
		out += dotU.substring(i, i+3)
		if( i < dotU.length-3) out += ","
	}

	if(minus) out = "-" + out
	if(dotD) return out + "." + dotD
	else return out
}
//
function OBJEtc1(obj1, obj2){
	if (obj1){
		return obj1.value
	}else{
		return obj2
	}
}


// Cookie 관련
var cProcID

function GetProcID(){
	var acookie = document.cookie;
	var op = 0;

	if(acookie.length > 0){
		var cc = acookie.split(";");
		for(var i = 0; i < cc.length; i++){
			if(cc[i].match("ProcID=")) {
				cProcID = cc[i].replace("ProcID=", "");
				cProcID = cProcID.replace("%B0%FC%B8%AE%C0%DA", "관리자");
				cProcID = cProcID.replace("%7C", "|");
				cProcID = cProcID.replace("%7C", "|");
				cProcID = cProcID.replace("%7C", "|");
				return;
			}
		}
	}
}
GetProcID();

function getCookie(name) {
        var nameStr = name + "=" ;
        var nameLen = nameStr.length;
        var cookieLen = document.cookie.length;                //쿠기값이 없을시 기본적으로 45이다.  document.cookie.length >= 45

        //        a로 지정시 : document.cookie ==> lucya=a; ASPSESSIONIDQGQQGLDC=GKDDHCPDJBOBAONCMJLHBCCN
        var i = 0;
        while( i < cookieLen ) {
                var j = i + nameLen;
                if ( document.cookie.substring(i, j) == nameStr ) {
                        var end = document.cookie.indexOf(";", j); // ;의 위치
                        if( end == -1) end = document.cookie.length;
                        return unescape( document.cookie.substring(j, end) ); //쿠키값 반환
                }
                i = document.cookie.indexOf(" ", i) + 1;
                if ( i == 0) {
                        break;
                }
        }
}

function setCookie(name, value, expiredays) {
	var todayDate = new Date();
	todayDate.setDate( todayDate.getDate() + expiredays );
	document.cookie = name + "=" + escape( value ) + "; path=/; expires=" + todayDate.toGMTString() + ";"
}


//쿠키체크
function cookieVal(cookieName){
	thisCookie = document.cookie.split("; ");
	for(i=0; i<thisCookie.length; i++){
		if(cookieName == thisCookie[i].split("=")[0]){
			return thisCookie[i].split("=")[1];
		}
	}
	return "x";
}

//
function InitFrameCheck(){
	var FrameLogOutPath = "/common/Logon_mgmt/Logoff.asp";

	try{
		var targetWindow;

		if (typeof(dialogArguments) == "undefined" && typeof(window.opener) == "undefined"){
			if (typeof(top.mainFrame) == "undefined"){
				top.location.replace(FrameLogOutPath);
				alert("접근 불가 합니다.");
			}
		}else{
			if (typeof(dialogArguments) == "undefined"){
				targetWindow = window.opener;
			}else{
				targetWindow = dialogArguments;
			}

			if (typeof(targetWindow.top.mainFrame) == "undefined"){
				window.close();
				alert("접근 불가 합니다.");
			}

		}
	}
	catch (e){
		top.location.replace(FrameLogOutPath);
		alert("접근 불가 합니다.");
	}
}
//InitFrameCheck();

function jReplace(val, de1, de2){
	if (de2.indexOf(de1) >= 0){
		return '';
	}

	while (val.indexOf(de1) >= 0){
		val = val.replace(de1, de2);
	}

	return val;
}

function Writefdg(fdgName){
	//document.write("<OBJECT id='" + fdgName + "' name='" + fdgName + "' style='visibility:hidden;z-index: 0' CLASSID='clsid:D76D712E-4A96-11d3-BD95-D296DC2DD072' VIEWASTEXT codebase='/common/ocx/Vsflex7.ocx#version=7,0,0,112'></OBJECT>");
	document.write("<OBJECT classid='clsid:5220cb21-c88d-11cf-b347-00aa00a28331' VIEWASTEXT><PARAM Name='LPKpath' VALUE='/common/ocx/vsgrid8.lpk'></OBJECT>");
	document.write("<OBJECT id='" + fdgName + "' name='" + fdgName + "' style='visibility:hidden;z-index: 0' CLASSID='clsid:C945E31A-102E-4A0D-8854-D599D7AED5FA' VIEWASTEXT codebase='/common/ocx/vsflex8.cab#version=8, 0, 20034, 194'></OBJECT>");
}


/*------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
var winCommon = {
	setLoginMaintain : function(){
		var url = '/common/Logon_mgmt/LoginMaintain.asp';
		var pars = "";
		pars += "ecd=Login&";
		loadAjaxXML(url, pars, null, null);
		//alert("로그인 확인");
	},

	popupZipSearch : function(gb){
        var nWidth  = 500;
        var nHeight = 450;
		var path = '/pop/pop_address_search.asp?gb=' + gb;

		//openWindow(path, "newMessageWindow", nWidth, nHeight, "fix");
		openHelpWindow(path, "newMessageWindow", nWidth, nHeight, "fix");
	},

	popupRPrtPos : function(fld){
        var nWidth  = 462;
        var nHeight = 443;
		var path = '/pop/pop_printback_info.asp?RPrtPos=' + fld.RPrtPos + "&gb=" + fld.gb;

		//openWindow(path, "newMessageWindow", nWidth, nHeight, "fix");
		openHelpWindow(path, "newMessageWindow", nWidth, nHeight, "fix");
	},

	popupLogoAtt : function(fld){
        var nWidth  = 500;
        var nHeight = 500;
		var path = '/pop/pop_logo_search.asp?AttSeq=' + fld.AttSeq + "&gb=" + fld.gb;

		//openWindow(path, "newMessageWindow", nWidth, nHeight, "fix");
		openHelpWindow(path, "newMessageWindow", nWidth, nHeight, "fix");
	}


}
document.write("<INPUT TYPE='hidden' NAME='tempCopyit'>");

/*팝업제어--------------------------------------------------------------*/
/**
 * example:
 *  fitPopupSize( [doMove] );                  <- ID가 'page_content'인 object의 clientWidth, clientHeight 값에 따라 사이즈 조절
 *  fitPopupSize( object, [doMove] );          <- 주어진 object의 clientWidth, clientHeight값에 따라 사이즈 조절
 *  fitPopupSize( "pageOuter", [doMove] );     <- ID가 'pageOuter'인 object의 clientWidth, clientHeight 값에 따라 사이즈 조절
 *  fitPopupSize( 300, 400, [doMove] );        <- 팝업 크기를 300 x 400으로 조절
 */
function fitPopupSize( arg1, arg2, arg3 ) {
	var toWidth = null;
	var toHeight = null;
	var objOut = null;
	var positionRequired = true;

	var typeArg1 = typeof(arg1);
	var typeArg2 = typeof(arg2);
	var typeArg3 = typeof(arg3);

	if( typeArg1 == "undefined" || typeArg1 == "boolean" ) {
		objOut = document.getElementById("page_content");

		if( typeArg1 == "boolean" ) {
			positionRequired = arg1;
		}
	}
	if( typeArg1 == "string" ) {
		objOut = document.getElementById(arg1);
		if( objOut == null ) { return; }

		if( typeArg2 == "boolean" ) {
			positionRequired = arg2;
		}
	}

	if( typeArg1 == "object" ) {
		objOut = arg1;

		if( typeArg2 == "boolean" ) {
			positionRequired = arg2;
		}
	}

	if( objOut != null ) {
		var objParent = objOut.parentNode;
		var getStyle = function(obj) {
			if( obj.currentStyle ) {
				return obj.currentStyle;
			} else if( document.defaultView.getComputedStyle ) {
				return document.defaultView.getComputedStyle(obj, null);
			}
			}

		if( objParent != null && objParent.tagName == "BODY" && getStyle(objOut).position == "absolute" ) {
			try {
				var bodyPaddingTop = 0; var outerPaddingTop = 0;
				var bodyPaddingBottom = 0; var outerPaddingBottom = 0;
				var bodyPaddingLeft = 0; var outerPaddingLeft = 0;
				var bodyPaddingRight = 0; var outerPaddingRight = 0;

				if( document.body.currentStyle ) {
					var bodyCurrentStyle = document.body.currentStyle;
					bodyPaddingTop = parseInt(bodyCurrentStyle.paddingTop);
					bodyPaddingBottom = parseInt(bodyCurrentStyle.paddingBottom);
					bodyPaddingLeft = parseInt(bodyCurrentStyle.paddingLeft);
					bodyPaddingRight = parseInt(bodyCurrentStyle.paddingRight);

					var outerCurrentStyle = objOut.currentStyle;
					outerPaddingTop = parseInt(outerCurrentStyle.paddingTop);
					outerPaddingBottom = parseInt(outerCurrentStyle.paddingBottom);
					outerPaddingLeft = parseInt(outerCurrentStyle.paddingLeft);
					outerPaddingRight = parseInt(outerCurrentStyle.paddingRight);

				} else if( document.defaultView.getComputedStyle ) {
					var objBodyStyle = document.defaultView.getComputedStyle(document.body, null);
					bodyPaddingTop = parseInt(objBodyStyle.getPropertyValue("padding-top"));
					bodyPaddingBottom = parseInt(objBodyStyle.getPropertyValue("padding-bottom"));
					bodyPaddingLeft = parseInt(objBodyStyle.getPropertyValue("padding-left"));
					bodyPaddingRight = parseInt(objBodyStyle.getPropertyValue("padding-right"));

					var outerCurrentStyle = document.defaultView.getComputedStyle(objOut, null);
					outerPaddingTop = parseInt(outerCurrentStyle.getPropertyValue("padding-top"));
					outerPaddingBottom = parseInt(outerCurrentStyle.getPropertyValue("padding-bottom"));
					outerPaddingLeft = parseInt(outerCurrentStyle.getPropertyValue("padding-left"));
					outerPaddingRight = parseInt(outerCurrentStyle.getPropertyValue("padding-right"));
				}

				var adjustHeight = bodyPaddingTop + bodyPaddingBottom;
				var adjustWidth = bodyPaddingLeft + bodyPaddingRight;

				var oWidth = objOut.clientWidth;
				var oHeight = objOut.clientHeight;

				// objOut.style.height = oHeight + adjustHeight;
				objOut.style.paddingTop = outerPaddingTop + bodyPaddingTop;
				objOut.style.paddingBottom = outerPaddingBottom + bodyPaddingBottom;

				// objOut.style.width = oWidth + adjustWidth;
				objOut.style.paddingLeft = outerPaddingLeft + bodyPaddingLeft;
				objOut.style.paddingRight = outerPaddingRight + bodyPaddingRight;
			} catch(e) {
				// do nothing
				// alert( e.message );
			}
		}
		toWidth = objOut.clientWidth;
		toHeight = objOut.clientHeight;
	}

	if( typeArg1 == "number" && typeof(arg2) == "number" ) {
		toWidth = arg1;
		toHeight = arg2;

		if( typeArg3 == "boolean" ) {
			positionRequired = arg3;
		}
	}

	if( toWidth == null && toHeight == null ) { return; }

	if (toWidth > screen.availWidth) toWidth = screen.availWidth;
	if (toHeight > screen.availHeight) toHeight = screen.availHeight;


	if( positionRequired ) {
		fitPopupSize_adjustPosition( toWidth, toHeight );
	}

	fitPopupSize_resize( toWidth, toHeight );
}

function fitPopupSize_adjustPosition( toWidth, toHeight ) {
	var posLeft = (window.screenLeft) ? window.screenLeft : window.screenX;
	var posTop = (window.screenTop) ? window.screenTop : window.screenY;
	var adjustLeft = 0;	var marginWidth = 50;
	var adjustTop = 0;	var marginHeight = 50;
	var movingRequired = false;

	if( posTop + toHeight + marginHeight > screen.availHeight ) {
		adjustTop = -(posTop + toHeight + marginHeight - screen.availHeight);
		movingRequired = true;
	}
	if( posLeft + toWidth + marginWidth > screen.availWidth ) {
		adjustLeft = -(posLeft + toWidth + marginWidth - screen.availWidth);
		movingRequired = true;
	}
	if( movingRequired ) {
		window.moveBy( adjustLeft, adjustTop );
	}
}


function fitPopupSize_resize( toWidth, toHeight ) {
	var oBody = document.body;
	if( oBody == null ) { return; }

	if( typeof(window.innerHeight) != "undefined" && typeof(window.innerWidth) != "undefined" ) {
		window.innerHeight = toHeight;
		window.innerWidth = toWidth;
	} else {
		var clientWidth = Math.max( document.documentElement.clientWidth, oBody.clientWidth );
		var clientHeight = Math.max( document.documentElement.clientHeight, oBody.clientHeight );

		var diffX = toWidth - clientWidth;
		var diffY = toHeight - clientHeight;

		window.resizeBy( diffX, diffY );
	}
/*
	var posLeft = (window.screenLeft) ? window.screenLeft : window.screenX;
	var posTop = (window.screenTop) ? window.screenTop : window.screenY;

	if( oBody.clientHeight > screen.availHeight ) {
		var adjustHeight = screen.availHeight - (oBody.clientHeight + 50);
		window.moveTo(posLeft, 0);
		window.resizeBy( 0, adjustHeight );
	}
*/
}
/*팝업제어--------------------------------------------------------------*/

function charAt(n){
   var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var s;
   s = str.charAt(n - 1);

   return(s);
}


function getRealOffsetTop(el) {
    return el ? el.offsetTop + getRealOffsetTop(el.offsetParent) : 0;
}
function getRealOffsetLeft(el) {
    return el ? el.offsetLeft + getRealOffsetLeft(el.offsetParent) : 0;
}
