/*'
'@name    : Window.Class
'@desc    : _OrangeÀÇ fnWIndow.js ¹× comn.js¸¦ ClassÈ­
'           window open¿¡ »ç¿ë µÉ optionÀÇ CossBrowsing Àû¿ëÀ» À§ÇØ GEOMETRY¸¦ Æ÷ÇÔ ÇÑ´Ù.
'@author  : ÀÌ»óÇõ (romeo131@cj.net)
'@history : 2008.08.25 ÃÖÃÊ ÀÛ¼º
'
'*/

/*'
'@name    : GEOMETRY class
'@desc    : window open¿¡ »ç¿ë µÉ optionÀÇ CossBrowsing Àû¿ëÀ» À§ÇÑ ±¸Á¶Ã¼
'*/
var GEOMETRY = {};
    
if(window.screenLeft != undefined) {
    GEOMETRY.getWindowX = function() { return window.screenLeft; };
    GEOMETRY.getWindowY = function() { return window.screenTop;  };
} else if (window.screenX) {
    GEOMETRY.getWindowX = function() { return window.screenX; };
    GEOMETRY.getWindowY = function() { return window.screenY; };
}

if(window.innerWidth) {
    GEOMETRY.getViewportWidth    = function() { return window.innerWidth; };
    GEOMETRY.getViewportHeight   = function() { return window.innerHeight; };
    GEOMETRY.getHorizontalScroll = function() { return window.pageXOffset; };
    GEOMETRY.getVerticalScroll   = function() { return window.pageYOffset; };
} else if (document.documentElement && document.documentElement.clientWidth) {
    GEOMETRY.getViewportWidth    = function() { return document.documentElement.clientWidth; };
    GEOMETRY.getViewportHeight   = function() { return document.documentElement.clientHeight; };
    GEOMETRY.getHorizontalScroll = function() { return document.documentElement.scrollLeft; };
    GEOMETRY.getVerticalScroll   = function() { return document.documentElement.scrollTop; };
} else if (document.body && document.body.clientWidth) {
    GEOMETRY.getViewportWidth    = function() { return document.body.clientWidth; };
    GEOMETRY.getViewportHeight   = function() { return document.body.clientHeight; };
    GEOMETRY.getHorizontalScroll = function() { return document.body.scrollLeft; };
    GEOMETRY.getVerticalScroll   = function() { return document.body.scrollTop; };        
}

var WINDOW = {

    open : {

        /*
        '@name      : WINDOW.open.winW('/bit/open.asp', '300', '200', 'newPopup', pScroll, pResize, pTop, pLeft)
        '@desc      : 
        '@arguments : [0] url                                            
                      [1] width
                      [2] height
                      [3] window name
                      [4] scrollbars »ç¿ë¿©ºÎ (0:¹Ì»ç¿ë/else:»ç¿ë)
                      [5] resize     »ç¿ë¿©ºÎ (0:¹Ì»ç¿ë/else:»ç¿ë)
                      [6] ÆË¾÷ÀÇ top
                      [7] ÆË¾÷ÀÇ left                      
        '@return    : popup°´Ã¼ ¸í
        */    
        common : function() {//WINDOW.open.common('/bit/open.asp', 'newPopup', '300', '200', pScroll, pResize, pTop, pLeft)
            
            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 {
                var popup = window.open(pURL, pName, strOption);
                
                if (popup != null || !popup.close) popup.focus();
            } catch(e) {
                alert("ÆË¾÷Â÷´Ü ¼³Á¤À» Ç®¾îÁÖ¼¼¿ä.\n[¹æ¹ý: µµ±¸-ÆË¾÷Â÷´Ü »ç¿ë¾ÈÇÔ Å¬¸¯]");
            }
            return popup;
        },

        /*
        '@name      : WINDOW.open.newWin()
        '@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;
        },
         
        /*
        '@name      : WINDOW.open.sms()
        '@desc      : smsÃ¢À» ¿¬´Ù
        '@arguments : 
        '@return    : popup°´Ã¼ ¸í
        */
        sms : function() {
            WINDOW.open.win(NM_DOMAIN_SERVICE + '/SMS/Index.asp', 510, 614);
        }, 
                
        /*
        '@name      : WINDOW.open.onlineFriend()
        '@desc      : 
        '@arguments : 
        '@return    : void
        */
        onlineFriend : function() {
            top.location.href = NM_DOMAIN_MYPAGE + "/mypage/friend/";
        }, 
        
        /*
        '@name      : WINDOW.open.memoAlram()
        '@desc      : 
        '@arguments : 
        '@return    : void
        */
        memoAlram : function() {
            top.location.href = NM_DOMAIN_MYPAGE + "/mypage/memo/mymemoenv.asp";
        }
    },
    
    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] - objBody.clientWidth;                                                      
	        changeHeight = arguments[1] - objBody.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.normalWinResize()
        '@desc      : ±âÁ¸ÆÄÀÏ¿¡ ÀÖ¾î¼­ º¯È¯ÇÏ±â´Â Çß´Âµ¥ ´çÃÖ ¾ù´Ù ¾²´ÂÁö ¸ð¸£°ÚÀ½ -_-
        '@arguments : objChangeSize
        '@return    : 
        */          
        normalWinResize : function(objChangeSize) {
	        if ( !objChangeSize )
		        return;
        },

        /*
        '@name      : WINDOW.size.normalWinResize()
        '@desc      : ±âÁ¸ÆÄÀÏ¿¡ ÀÖ¾î¼­ º¯È¯ÇÏ±â´Â Çß´Âµ¥ ´çÃÖ ¾ù´Ù ¾²´ÂÁö ¸ð¸£°ÚÀ½ -_-        
        '@arguments : [0]width
                      [1]height
                      [2]bCenter        
        '@return    : void
        */          
        modalWinResize : function() {
        
	        var objChangeSize, dWidth, dHeight;
        	
	        if ( !arguments[0] || !arguments[1] )
		        return;
        	
	        if ( !(objChangeSize = WINDOW.size.getChangeSize(arguments[0], arguments[1])) ) 
		        return;
        	
	        dWidth  = parseInt(top.dialogWidth)  + objChangeSize.width;
	        dHeight = parseInt(top.dialogHeight) + objChangeSize.height;
        	
	        self.top.dialogWidth  = dWidth+"px";
	        self.top.dialogHeight = dHeight+"px";
        	
	        if (arguments[2])
		        setCenter(arguments[0], arguments[1]);
        },
        
        /*
        '@name      : WINDOW.size.windowResize()
        '@desc      : À©µµ¿ì sizeº¯°æÇÏ°í option¿¡ µû¶ó Áß¾ÓÀ¸·Î Á¤·Ä ÇÑ´Ù.  
        '@arguments : [0]width
                      [1]height
                      [2]bCenter        
        '@return    : void
        */          
        windowResize : function() {
        
	        var objChangeSize, w, h, bCenter;
	        
	        w       = arguments[0];
	        h       = arguments[1];
	        bCenter = arguments[2];

 
	        try {
        		  
//		        if (WINDOW.type.isDialogWindow())
//			        return setTimeout("WINDOW.size.normalWinResize("+w+", "+h+", "+bCenter+")",0);
           		
		        if (!w)
			        w = document.body.scrollWidth;
		        if (!h)
			        h = document.body.scrollHeight;
   		
		        if (!(objChangeSize = WINDOW.size.getChangeSize(w, h))) 
			        return;
        			
		        self.top.resizeBy(objChangeSize.width , objChangeSize.height);
        		
		        if (bCenter)
			        WINDOW.position.setCenter(w,h);
	        }
	        catch(x) {alert(x.message)}
        }, 
        
        /*
        '@name      : WINDOW.size.windowAutoResize()
        '@desc      : 
        '@arguments : [0]bCenter        
        '@return    : 
        */          
        windowAutoResize : function() {        
            WINDOW.size.windowResize(document.body.scrollWidth, document.body.scrollHeight, arguments[0]);
        }, 
        
        /*
        '@name      : WINDOW.size.popResize()
        '@desc      : 
        '@arguments : 
        '@return    : void
        */
        popResize : function() {
	        var objWin  = self;	        
	        var nWidth, nWidthTmp;
	        var objBody = self.document.body;
	        var nHeight = objBody.scrollHeight + (objBody.offsetHeight - objBody.clientHeight);
	        
	        nWidth	= document.body.scrollWidth  + 10;
	        nHeight	= document.body.scrollHeight + 29;
	        
	        self.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 ? document.body : false);
        }    
    }
    
}    
