// ¿¹¾à Ã¼Å© Àü¿ªº¯¼ö
var gSubscription = false;

var nowTopRightAdBnrIdx = 0;

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();
}

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
}

// 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>");
}


/*------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------------------------------------------------*/
var winCommon = {
	popupItemSearch : function(fld){
		var e = "message";
		var opt = {w:600, h:400, x:65, y:35};
		var path;

		path = "/common/SearchWindow/ItemSearch/ItemSearch.asp?c=&";

		if (typeof fld != "undefined"){
			if (typeof fld.Title != "undefined"){
				path += "Title=" + Form.escape(fld.Title) + "&";
			}
			if (typeof fld.opt != "undefined"){
				opt = fld.opt;
			}
		}

        window.Flyer.doModal(e+'Div', opt);
		$(e+'Iframe').src = path;
	},

	popupZipSearch : function(gb){
		var e = "message";
		var opt = {w:400, h:330, x:200, y:200};

        window.Flyer.doModal(e+'Div', opt);
		$(e+'Iframe').src = '/common/SearchWindow/ZipSearch/ZipSearch.asp?gb=' + gb;
	},

	popupOrderSearch : function(MemberNo){
		var e = "message";
		var opt = {w:700, h:450, x:200, y:200};
		var path = '/common/SearchWindow/OrderSearch/OrderSearch.asp?MemberNo=' + MemberNo;

        window.Flyer.doModal(e+'Div', opt);
		$(e+'Iframe').src = path;
	},

	popupEmployeeSearch : function(fld){
		var e = "message";
		var opt = {w:400, h:440, x:200, y:160};
		var path = '/common/SearchWindow/EmployeeSearch/EmployeeSearch.asp?gb=' + fld.gb;
		path += '&Title=' + fld.Title;

		if (typeof fld.opt != "undefined"){
			opt = fld.opt;
		}

        window.Flyer.doModal(e+'Div', opt);
		$(e+'Iframe').src = path;
	},

	popupDesignOrder : function(OrderNo){
        var nWidth  = 920;
        var nHeight = 650;
		var path = '/solution/Order_mgmt/Order_Enroll/DesignOrderRPT.asp?OrderNo=' + OrderNo;

		openHelpWindow(path, "newMessageWindow", nWidth, nHeight, "fix");
	},

	getSubscription : function(){
		var url = "toJSON";
		var pars = ""
		pars += "id=" + Form.escape("p_getEmpSubscription") + "&";
		pars += "param=CmpCode";
		pars += "RegiUser";

		pars = pars.replace(/$/, " ");

		loadAjaxXML(url, pars, this.setSubscription, null, null);

	},
	setSubscription : function (originalRequest){
		var evalData = setJSON(originalRequest);

		if (evalData.Rss.length == 1 && evalData.Rss[0].cnt > 0){
			gSubscription = true;
		}else{
			gSubscription = false;
		}
	},

	popupSubscription : function(){
        var nWidth  = 900;
        var nHeight = 440;
		var path = '/common/SearchWindow/SubscriptionSearch/SubscriptionSearch.asp';
		path += "?Title=»ó´ã¿¹¾à ¸®½ºÆ®";
		path += "&oneExec=1";

		openHelpWindow(path, "newMessageWindow", nWidth, nHeight, "fix");
	},

	copyit : function(fld){
		var ResultMsg = "º¹»ç¿Ï·á";
		$('tempCopyit').value = fld.str;
		therange = $('tempCopyit').createTextRange();
		therange.execCommand("Copy");

		if (typeof fld.ResultMsg != "undefined"){
			ResultMsg = fld.ResultMsg;
		}
		alert(ResultMsg);
	},

	getDay : function(day, st){
		if (typeof st == "undefined"){
			st = ".";
		}

		if (day.length == 8){
			return day.substring(0,4) + st + day.substring(4,6) + st + day.substring(6,8)
		}
	},

	popSearchIDPW : function(){
        var nWidth  = 636;
        var nHeight = 450;
		var path = '/member/popup_find.asp';

		openHelpWindow(path, "newMessageWindow", nWidth, nHeight, "fix");
	},

    popComment : function(fld){
        var nWidth  = 430;
        var nHeight = 300;
		var path = '/popup/pop_Comment.asp?Idx='+fld.Idx;
        path += '&CommentSeq='+fld.CommentSeq;

		openHelpWindow(path, "Comment", nWidth, nHeight, "fix");
    },

    popComment2 : function(fld){
        var nWidth  = 430;
        var nHeight = 250;
		var path = '/popup/pop_Comment2.asp?SaleIdx='+fld.SaleIdx;
        path += '&CommentSeq='+fld.CommentSeq;

		openHelpWindow(path, "Comment", nWidth, nHeight, "fix");
    },

    popComment3 : function(fld){
        var nWidth  = 430;
        var nHeight = 250;
		var path = '/popup/pop_Comment3.asp?CookIdx='+fld.CookIdx;
        path += '&CommentSeq='+fld.CommentSeq;

		openHelpWindow(path, "Comment", nWidth, nHeight, "fix");
    }
}

function setContentsImage(width){
	if (typeof width == "undefined" || typeof width == "object"){
		width = 610;
	}

	if ($$('span.[class="sContents"]').length > 0){
		$$('span [class="sContents"] img', 'span [class="sContents"] table', 'span [class="sContents"] td', 'span [class="sContents"] EMBED', 'span [class="sContents"] object').each(function(obj, index){
			if (obj.width > width){
				obj.style.width = width;
			}
		});
	}

	setTimeout("setContentsImage()", 10000);
}

Event.observe(window, 'load', setContentsImage, false);

document.write("<INPUT TYPE='hidden' NAME='tempCopyit'>");

function setLocation(fld){
    var gotoPage = fld.gotoPage;
    var params = fld.params;

    location.href=location.pathname+"?gotoPage="+gotoPage+"&"+params+"";
}
function setPage(fld){
    var PageSize = fld.PageSize;
    var gotoPage = fld.gotoPage;
    var TotalCount = fld.TotalCount;
    var PageCount = fld.PageCount;
    var btnPrev10 = fld.btnPrev10;
    var btnPrev = fld.btnPrev;
    var btnNext = fld.btnNext;
    var btnNext10 = fld.btnNext10;
    var params = fld.params;
    var html = "";
    var i = 0;

    var StartPage = 0;
    var EndPage = 0;

    if (gotoPage=="0"){
        gotoPage = "1";
    }

    if (typeof PageSize=="undefined"){
        PageSize = "15";
    }
    if (typeof btnPrev10=="undefined"){
        btnPrev10 = "";
    }
    if (typeof btnPrev=="undefined"){
        btnPrev = "";
    }
    if (typeof btnNext=="undefined"){
        btnNext = "";
    }
    if (typeof btnNext10=="undefined"){
        btnNext10 = "";
    }
    if (typeof PageCount=="undefined"){
        PageCount = parseInt((TotalCount -1) / PageSize) + 1;
    }

    var splitPageSize = 10;
    StartPage = (parseInt((gotoPage - 1) / splitPageSize) * splitPageSize) + 1;
    EndPage = (parseInt((gotoPage - 1) / splitPageSize) * splitPageSize) + splitPageSize;


    //ÀÌÀü 10°³
    if (StartPage-10 >= 1){
        html += "<img src='"+btnPrev10+"' onclick=\"setLocation({gotoPage:"+(StartPage - splitPageSize)+", params:'"+params+"'});\" style='cursor:pointer;'>&nbsp;";
    }
    //ÀÌÀü 1°³
    if (gotoPage - 1 >= 1){
        //html += "<img src='"+btnPrev+"' onclick=\"setLocation({gotoPage:"+gotoPage+"-1, params:'"+params+"'});\">";
    }

    for (i=StartPage;i <= EndPage && i <= PageCount ;i++ ){
        if (i == gotoPage){
            html += "<strong><font color='#FF0000'>"+i+"</font></strong>&nbsp;";
        }else{
            html += "<a onclick=\"javascript:setLocation({gotoPage:"+i+", params:'"+params+"'});\" style='cursor:pointer'>"+i+"</a>&nbsp;";
        }

    }
    //´ÙÀ½ 1°³
    if (PageCount > gotoPage){
        //html += "<img src='"+btnNext+"' onclick=\"setLocation({gotoPage:"+gotoPage+"+1, params:'"+params+"'});\">";
    }

    if (StartPage + 10 <= PageCount){
        html += "<img src='"+btnNext10+"' onclick=\"setLocation({gotoPage:"+(StartPage+splitPageSize)+", params:'"+params+"'});\" style='cursor:pointer;'>";
    }

    if (TotalCount > 0){
        return html;
    }else{
        return ""
    }


}

//¼ýÀÚ¸¸ ÀÔ·Â Ã¼Å©
function NumberCheck(fl) {
    t = fl.value ;
    for(i=0;i<t.length;i++)
    if (t.charAt(i)<'0' || t.charAt(i)>'9') {
        alert("¼ýÀÚ¸¸ ÀÔ·ÂÇØÁÖ¼¼¿ä.") ;
        fl.value="";
        fl.focus() ;
        return false ;
    }
}

function StringCut(as_Str, ai_Num){
	if (as_Str == 'undefined')
	{
		return "";
	}else{
		if (as_Str.length < ai_Num){
			return as_Str;
		}else{
			return as_Str.substring(0, ai_Num) + "...";
		}
	}
}

function MoveTopRightAdBanner(inPN, Cnt)
{
	var arrTopRightAdBnr = new Array(Cnt);

    arrTopRightAdBnr[0] = $("trAdBnr0");
    for(var i=1; i<Cnt; i++)
    {
        arrTopRightAdBnr[i] = $("trAdBnr"+i);
    }

    switch(inPN)
    {
        case "P" :
            arrTopRightAdBnr[nowTopRightAdBnrIdx].style.display = "none";
            nowTopRightAdBnrIdx--;
            if ( nowTopRightAdBnrIdx < 0 ) nowTopRightAdBnrIdx = arrTopRightAdBnr.length-1;
            arrTopRightAdBnr[nowTopRightAdBnrIdx].style.display = "block";
            break;
        case "N" :
            arrTopRightAdBnr[nowTopRightAdBnrIdx].style.display = "none";
            nowTopRightAdBnrIdx++;
            if ( nowTopRightAdBnrIdx >= arrTopRightAdBnr.length ) nowTopRightAdBnrIdx = 0;
            arrTopRightAdBnr[nowTopRightAdBnrIdx].style.display = "block";
            break;
    }
}

function fnGoUrl(f){
	location.href=f;
}

