/*'
'@name    : Window.Class
'@desc    : _OrangeÀÇ fnWIndow.js ¹× comn.js¸¦ ClassÈ­
'@author  : ÀÌ»óÇõ (romeo131@cj.net)
'@history : 2008.08.25 ÃÖÃÊ ÀÛ¼º
'*/
var WINDOW = {

    iecompat : function() {
        return (document.compatMode && document.compatMode!="BackCompat") ? document.documentElement : document.body;
    },

    open : {

        /*
        '@name      : WINDOW.open.common('/bit/open.asp', 'newPopup', '300', '200',pScroll, pResize, pTop, pLeft)
        '@desc      :
        '@arguments : [0] url
                      [1] window name
                      [2] width
                      [3] height
                      [4] scrollbars »ç¿ë¿©ºÎ (0:¹Ì»ç¿ë/else:»ç¿ë)
                      [5] resize     »ç¿ë¿©ºÎ (0:¹Ì»ç¿ë/else:»ç¿ë)
                      [6] ÆË¾÷ÀÇ top
                      [7] ÆË¾÷ÀÇ left
        '@return    : popup°´Ã¼ ¸í
        */
        common : function() {

            var optionScroll = "no";
            var optionResize = "no";
            var optionTop    = "";
            var optionLeft   = "";

            var pURL    = arguments[0];
            var pName   = arguments[1];
            var pWidth  = arguments[2];
            var pHeight = arguments[3];

            if(arguments[4] == undefined || arguments[4] == "")
                optionScroll = "no";
            else
                arguments[4] == 0 ? optionScroll="no" : optionScroll="yes";


            if(arguments[5] == undefined || arguments[5] == "")
                optionResize = "no";
            else
                arguments[5] == 0 ? optionResize="no" : optionResize="yes";


            if(arguments[6] == undefined || arguments[6] == "")
                optionTop    = (screen.height - pHeight) / 2 - 40;
            else
                optionTop    = arguments[6];

            if(arguments[7] == undefined || arguments[7] == "")
                optionLeft   = (screen.width - pWidth) / 2;
            else
                optionLeft   = arguments[7];

            var strOption  = "'toolbar=no,location=no,directories=no,status=0,menubar=no,copyhistory=no,";
                strOption += " scrollbars="+optionScroll+",resizable="+optionResize+",";
                strOption += " top="  + optionTop +",left="  + optionLeft +",";
                strOption += " width="+ pWidth +",height="+ pHeight +"'";

            try {
                popup = window.open(pURL, pName, strOption);

                if (popup != "undefined" || popup != null || !popup.close) popup.focus();
            } catch(e) {
                alert("ÆË¾÷Â÷´Ü ¼³Á¤À» Ç®¾îÁÖ¼¼¿ä.\n[¹æ¹ý: µµ±¸-ÆË¾÷Â÷´Ü »ç¿ë¾ÈÇÔ Å¬¸¯]");
            }
            return popup;
        },

        /*
        '@name      : WINDOW.open.newWindow()
        '@desc      : ±âÁ¸Ã¢ ¿©ºÎ È®ÀÎ ÈÄ ¾øÀ¸¸é »õÃ¢À» ¿­°í, ÀÖÀ¸¸é ±âÁ¸Ã¢¿¡ focus¸¦ ÁØ´Ù(popup bloking check)
        '@arguments :
        '@return    : popup°´Ã¼ ¸í
        */
        newWindow : function() {

            var pURL    = arguments[0];
            var pName   = arguments[1];

            try {
                var popup = window.open(pURL, pName);
                if (popup != null || !popup.close) popup.focus();
            } catch(e) {
                alert("ÆË¾÷Â÷´Ü ¼³Á¤À» Ç®¾îÁÖ¼¼¿ä.\n[¹æ¹ý: µµ±¸-ÆË¾÷Â÷´Ü »ç¿ë¾ÈÇÔ Å¬¸¯]");
            }
            return popup;
        }
    },


    size : {

        /*
        '@name      : WINDOW.size.getChangeSize()
        '@desc      :
        '@arguments : [0]°´Ã¼ÀÇ width
                      [1]°´Ã¼ÀÇ height
        '@return    :
        */
        getChangeSize : function() {

	        var curWidth, curHeight, objBody, objRet, changeWidth, changeHeight;

	        if (!(objBody = WINDOW.type.getBodyObj()))                                                              //document.body¸¦ »ç¿ëÇÒ ¼ö ¾ø´Ù¸é ½ÇÇàÀ» ¸ØÃá´Ù
		        return;

	        changeWidth  = arguments[0] - WINDOW.iecompat().clientWidth;
	        changeHeight = arguments[1] - WINDOW.iecompat().clientHeight;

	        if (isNaN(changeWidth) || isNaN(changeHeight) || (changeWidth == 0 && changeHeight == 0))
		        return false;

	        return new WINDOW.size.setSize(changeWidth, changeHeight);
        },

        /*
        '@name      : WINDOW.size.setSize()
        '@desc      : °´Ã¼ÀÇ width¿Í height¸¦ ¼³Á¤ÇÑ´Ù
        '@arguments : [0]°´Ã¼ÀÇ width
                      [1]°´Ã¼ÀÇ height
        '@return    : void
        */
        setSize : function() {
            this.width  = arguments[0];
            this.height = arguments[1];
        },

        /*
        '@name      : WINDOW.size.windowResize()
        '@desc      : À©µµ¿ì sizeº¯°æÇÏ°í option¿¡ µû¶ó Áß¾ÓÀ¸·Î Á¤·Ä ÇÑ´Ù.
        '@arguments : [0]width
                      [1]height
                      [2]bCenter
        '@return    : void
        */
        windowResize : function() {

	        var w, h, bCenter;

	        w       = arguments[0];
	        h       = arguments[1];
	        bCenter = arguments[2];

	        try {
		        window.resizeTo(w ,h);

		        if (bCenter)
			        WINDOW.position.setCenter(w,h);
	        } catch(e){}
        },

        /*
        '@name      : WINDOW.size.windowAutoResize()
        '@desc      :
        '@arguments : [0]bCenter
        '@return    :
        */
        windowAutoResize : function() {
        
	        var objChangeSize, w, h, bCenter;
	        
	        w       = arguments[0];
	        h       = arguments[1];
	        bCenter = arguments[2];
	        
	        try {
	        
	            if (!w)
		            w = WINDOW.iecompat().scrollWidth;
	            if (!h)
		            h = WINDOW.iecompat().scrollHeight;	        
    	        
	            if (!(objChangeSize = WINDOW.size.getChangeSize(w, h))) 
		            return;
    			      
		             self.top.resizeBy(objChangeSize.width , objChangeSize.height);

		            if (bCenter)
			            WINDOW.position.setCenter(w,h);
	        } catch(e){}
        },

        /*
        '@name      : WINDOW.size.popResize()
        '@desc      :
        '@arguments :
        '@return    : void
        */
        popResize : function() {

            var nWidth, nHeight

	        nWidth	= WINDOW.iecompat().scrollWidth +10;
	        nHeight	= WINDOW.iecompat().scrollHeight+80;

	        window.resizeTo(nWidth, nHeight);
        }
    },

    position : {

        /*
        '@name      : WINDOW.position.setCenter(350, 200)
        '@desc      : °´Ã¼(popup µî)¸¦ ¸ð´ÏÅÍ Áß¾ÓÀ¸·Î ÀÌµ¿ ½ÃÅ²´Ù
        '@arguments : [0]°´Ã¼ÀÇ width
                      [1]°´Ã¼ÀÇ height
        '@return    : void
        */
        setCenter : function() {

	        var nTop, nLeft;

	        if ( !arguments[0] || !arguments[1] )
		        return;

	        nLeft = (screen.width  - arguments[0])/2;
	        nTop  = (screen.height - arguments[1])/2;

	        if (WINDOW.type.isDialogWindow()) {
		        self.top.dialogTop  = nTop+"px";
		        self.top.dialogLeft = nLeft+"px";
	        }
	        else
		        self.top.moveTo(nLeft, nTop);
        }
    },

    type : {

        /*
        '@name      : WINDOW.type.isDialogWindow()
        '@desc      : ÇöÀç ÆäÀÌÁö°¡ dialog windowÀÎÁö¸¦ return ÇÑ´Ù
        '@arguments : [0]°´Ã¼ÀÇ width
                      [1]°´Ã¼ÀÇ height
        '@return    : BOOL
        */
        isDialogWindow : function() {
            return (typeof(self.dialogWidth) != "undefined");
        },

        /*
        '@name      : WINDOW.type.getBodyObj()
        'desc       : document.body °´Ã¼ÀÇ »ç¿ë°¡´É À¯¹«¸¦ È®ÀÎ ÇÏ¿© return ÇÑ´Ù
        */
        getBodyObj : function() {
            return (document ? WINDOW.iecompat() : false);
        }
    }
}
