var PopupWindow = {
    init: function ()
    {
        if(this.ArrPopupPos == undefined) this.ArrPopupPos = new Array();
        if(this.MaxzIndex == undefined) this.MaxzIndex = 2000;        
        if(this.PanelLock == undefined) this.PanelLock = "";
        
        this.DragObject  = null;
        this.MouseOffset = null;
        if(this.IsWrap == undefined) this.IsWrap = false;
        if(this.PopupPosition == undefined) this.PopupPosition = null;                
        
        if(document.onmousemove != undefined) this.OnmousemoveObject = document.onmousemove;
        if(document.onmouseup != undefined) this.OnmouseupObject = document.onmouseup;
        if(document.onkeydown != undefined) this.OnkeydownObject = document.onkeydown;

        document.onmousemove = f_PW_MouseMove;
        document.onmouseup   = f_PW_MouseUp;
        
        //Folder Browser
        this.ItemSelectID= null;
        this.Path = null;
        this.RootPath = null;        
        this.Class = PopupWindowClass;
    },
    dispose: function()
    {   
        this.DragObject  = null;
        this.MouseOffset = null;              
        
        if(this.OnmousemoveObject != null) document.onmousemove = this.OnmousemoveObject;
        if(this.OnmouseupObject != null) document.onmouseup = this.OnmouseupObject;
        if(this.OnkeydownObject != null) document.onkeydown = this.OnkeydownObject;        
        this.OnmousemoveObject = null;
        this.OnmouseupObject = null;
        this.OnkeydownObject = null;
        
        //Folder Browser
        this.ItemSelectID= null;
        this.Path = null;
        
        this.Class = null;
    },
    ReleaseDocumentFunctionCatch: function()
    {   
        if(this.OnmousemoveObject != null) document.onmousemove = this.OnmousemoveObject;
        if(this.OnmouseupObject != null) document.onmouseup = this.OnmouseupObject;
        if(this.OnkeydownObject != null) document.onkeydown = this.OnkeydownObject;        
    },
    CreateImagePopup : function(p_Title,p_PopupName,p_ArrImage,p_ArrResoluton,p_ImgPos,p_IsWrap,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown)
    {   
        this.init();
        
        this.MaxzIndex = this.MaxzIndex + 1;
        //Check Panel exitst
        if(f_PW_CheckPanelNameExist(p_PopupName) == true)
            return;
        
        var p_PopupPos = f_PW_CheckPanelExist();
        
        var p_Arr = p_ArrImage.split("@");
        var p_ArrRes = p_ArrResoluton.split("@");
        var p_Width = parseInt(p_ArrRes[p_ImgPos].substring(0,p_ArrRes[p_ImgPos].indexOf("x"))) + 20;
        var p_Height = parseInt(p_ArrRes[p_ImgPos].substring(p_ArrRes[p_ImgPos].indexOf("x") + 1));
        
        var d = document;
	    var r = d.documentElement;    			
        var ww = r.clientWidth + r.scrollLeft;
	    var wh = r.clientHeight + r.scrollTop;	    
	    
	    if(p_Height > (r.offsetHeight - 75))
            p_IsWrap = false;         
        
	    // create a block element
        if(p_IsLock == true)
        {
            if(this.PanelLock.indexOf("|" + p_PopupPos + "|") == -1)
            {
                this.PanelLock += "|" + p_PopupPos + "|";
                if(f_E("PWOverLayer_div") == undefined)
                {
                    var b = d.createElement("div");                        
                    b.id = "PWOverLayer_div";        
                    b.style.cssText = "top:0px;left:0px;position:absolute;width:100%;height:100%;background:#000;z-index:" + this.MaxzIndex + ";opacity: 0.3;filter:alpha(opacity=30)";
                    b = d.body.insertBefore(b,d.body.firstChild);			
                    b.innerHTML = "";    
                    
                    b.style.height = wh + "px"; 
                }
            }
        }        
    	
	    var p_PopupDiv = d.createElement("div");	
        p_PopupDiv.id = "PWImagePopup" + p_PopupPos + "_div";
        p_PopupDiv.style.cssText = "width:" + p_Width + "px;top:" + (r.scrollTop + 5) + "px;left:" + parseInt((ww/2) - (p_Width/2)) + "px;position:absolute;margin:0px; padding:0px; border:0px;z-index:" + (p_IsLock ? (this.MaxzIndex + 1) : this.MaxzIndex) + ";opacity: 0;filter:alpha(opacity=0)";
        p_PopupDiv = d.body.insertBefore(p_PopupDiv,d.body.firstChild);
        p_PopupDiv.title = p_PopupName;        
        
        p_ArrayButton = p_ArrButton.split("|");
        var p_ButtonHTML = "";
        if(p_Arr.length > 1)
        {
            p_ButtonHTML =  "<div class=\"PW_Div9\">" + 
                                "<a href=\"javascript:void(0)\" class=\"PW_Link1\" alt=\"First\" onclick=\"PopupWindow.FirstImage('" + p_ArrImage + "','" + p_ArrResoluton + "'," + p_PopupPos + "," + p_IsWrap + "," + p_IsLock + ",'" + p_ArrButton + "','" + p_CloseFunction + "'," + p_IsCatchKeyDown + ");\"></a>" + 
                                "<a href=\"javascript:void(0)\" class=\"PW_Link2\" alt=\"Previous\" onclick=\"PopupWindow.PreImage('" + p_ArrImage + "','" + p_ArrResoluton + "'," + p_PopupPos + "," + p_IsWrap + "," + p_IsLock + ",'" + p_ArrButton + "','" + p_CloseFunction + "'," + p_IsCatchKeyDown + ");\"></a>" +  
                                "<div id=\"PWImagePos" + p_PopupPos + "_lb\" class=\"PW_Div10\">" + (p_ImgPos + 1) + "/" + p_Arr.length + "</div>" +                                       
                                "<a href=\"javascript:void(0)\" class=\"PW_Link3\" alt=\"Next\" onclick=\"PopupWindow.NextImage('" + p_ArrImage + "','" + p_ArrResoluton + "'," + p_PopupPos + "," + p_IsWrap + "," + p_IsLock + ",'" + p_ArrButton + "','" + p_CloseFunction + "'," + p_IsCatchKeyDown + ");\"></a>" + 
                                "<a href=\"javascript:void(0)\" class=\"PW_Link4\" alt=\"Last\" onclick=\"PopupWindow.LastImage('" + p_ArrImage + "','" + p_ArrResoluton + "'," + p_PopupPos + "," + p_IsWrap + "," + p_IsLock + ",'" + p_ArrButton + "','" + p_CloseFunction + "'," + p_IsCatchKeyDown + ");\"></a>" + 
                            "</div>";
        }
	    p_PopupDiv.innerHTML =  "<div class=\"PW_Div1\"></div>" + 
                                "<div class=\"PW_Div2\" style=\"width:" + (p_Width - 24) + "px\">" + 
                                    "<div id=\"PWDrag" + p_PopupPos + "_Div\" class=\"PW_Text1\" style=\"float:left;width:" + (p_Width - 115) + "px;height:28px\" onMouseOver=\"this.style.cursor='move';\" ondblclick=\"PopupWindow.MaximizeWindow(this);\">" + p_Title + "</div>" + 
                                    "<div class='PW_Div8' onclick=\"PopupWindow.ClosePopupWindow(this);" + (p_CloseFunction == null ? "" : p_CloseFunction) + "\">&nbsp;</div>" + 
                                    (p_ArrayButton[1] != "1" ? "" : "<div class='PW_Div11' onclick='PopupWindow.MaximizeWindow(this);'>&nbsp;</div>") + 
                                    (p_ArrayButton[2] != "1" ? "" : "<div class='PW_Div12' onclick='PopupWindow.MinimizeWindow(this,document.documentElement.offsetHeight - 30);'>&nbsp;</div>") + 
                                "</div>" + 
                                "<div class=\"PW_Div3\"></div>" + 
                                "<div style=\"width:" + p_Width + "px; background:#000; clear:both\">" + 
                                    "<div style=\"width:" + (p_Width - 10) + "px;height:" + p_Height + "px;margin-left:auto; margin-right:auto;text-align:center;padding-bottom:5px;background:#ffffff\">" + 
                                        "<img id=\"PWPopupImage" + p_PopupPos + "_img\" src=\"" + p_Arr[p_ImgPos] + "\" alt=\"Image\" width=\"" + (p_Width - 20) + "\" height=\"" + p_Height + "\" />" + 
                                    "</div>" +
                                    "<div id=\"PWBottomDrag" + p_PopupPos + "_Div\" class=\"PW_Div4\" style=\"width:" + (p_Width - 10) + "px\">" + p_ButtonHTML + "</div>" +
                                "</div>" + 
                                "<div class=\"PW_Div5\"></div>" + 
                                "<div class=\"PW_Div6\" style=\"width:" + (p_Width - 24) + "px\"></div>" + 
                                "<div class=\"PW_Div7\"></div>"; 
                                
        //Relocate position
        var p_DimenHeight = r.offsetHeight - p_PopupDiv.offsetHeight;    
        if(p_DimenHeight > 0)
        {
            p_PopupDiv.style.top = parseInt(p_DimenHeight/2) + r.scrollTop + "px";        
        }     
                           
        var p_OpacityAnimate = new OpacityTween(p_PopupDiv,Tween.strongEaseIn, 0, 100, 0.4);
        p_OpacityAnimate.start();         
        
        if(p_IsWrap == false)        
            f_PW_MakeDraggable(p_PopupDiv.id,p_PopupDiv.id,p_IsWrap);                               
        else
            f_PW_MakeDraggable("PWDrag" + p_PopupPos + "_Div",p_PopupDiv.id,p_IsWrap);
            
        this.ArrPopupPos[this.ArrPopupPos.length] = p_PopupPos; 
        
        if(p_IsCatchKeyDown != null && p_IsCatchKeyDown == true)
        {
            p_PopupDiv.childNodes[0].title = "1";
            document.onkeydown = function(event)
            {
                event = event || window.event;  
    	    
	            var p_KeyID = event.keyCode;
	            if(p_KeyID == 27)    
	            {   
	                if(PopupWindow.ArrPopupPos.length > 0)
	                {	                    
	                    var p_PopupCtrl = f_E("PWImagePopup" + PopupWindow.ArrPopupPos[PopupWindow.ArrPopupPos.length - 1] + "_div");
	                    if(p_PopupCtrl.childNodes[0].title == "1")
	                    {
	                        p_PopupCtrl.childNodes[0].title = "0";
	                        PopupWindow.ClosePopupWindow(p_PopupCtrl);
	                        if(p_CloseFunction != null) 
	                            setTimeout(p_CloseFunction,1);
	                    }
	                }
	            }
	            else
	            if(p_Arr.length > 1)
	            {
	                if(p_KeyID == 37)
	                {
	                    f_PW_PreImage(p_ArrImage,p_ArrResoluton,1,p_IsWrap,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown);
	                }
	                else
	                if(p_KeyID == 38)
	                {
	                    f_PW_FirstImage(p_ArrImage,p_ArrResoluton,1,p_IsWrap,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown);
	                }
	                else
	                if(p_KeyID == 39)
	                {
	                    f_PW_NextImage(p_ArrImage,p_ArrResoluton,1,p_IsWrap,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown);
	                }
	                else
	                if(p_KeyID == 40)
	                {
	                    f_PW_LastImage(p_ArrImage,p_ArrResoluton,1,p_IsWrap,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown);
	                }
	            }     
                return false;
            };   
        }        
    },
    CreateHTMLPopup : function(p_Title,p_PopupName,p_HTML,p_Width,p_Height,p_IsWrap,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown)
    {   
        this.init();
        
        this.MaxzIndex = this.MaxzIndex + 1;
        //Check Panel exitst
        if(f_PW_CheckPanelNameExist(p_PopupName) == true)
            return;
            
        var p_PopupPos = f_PW_CheckPanelExist();
        
        var d = document;
	    var r = d.documentElement;
        var ww = r.clientWidth + r.scrollLeft;
	    var wh = r.clientHeight + r.scrollTop;
	    
	    if(p_Height > (r.offsetHeight - 75))
            p_IsWrap = false; 
            
	    // create a block element	    
        if(p_IsLock == true)
        {   
            this.PanelLock += "|" + p_PopupPos + "|";            
            if(f_E("PWOverLayer_div") == undefined)
            {
                var b = d.createElement("div");                        
                b.id = "PWOverLayer_div";        
                b.style.cssText = "top:0px;left:0px;position:absolute;width:100%;height:100%;background:#000;z-index:" + this.MaxzIndex + ";opacity: 0.3;filter:alpha(opacity=30)";
                b = d.body.insertBefore(b,d.body.firstChild);			
                b.innerHTML = "";
                
                b.style.height = wh + "px";      
            }                 
        }        
        
        p_ArrButton = p_ArrButton.split("|");
	    var p_PopupDiv = d.createElement("div");	
        p_PopupDiv.id = "PWImagePopup" + p_PopupPos + "_div";
        p_PopupDiv.style.cssText = "width:" + p_Width + "px;top:" + (r.scrollTop + 5) + "px;left:" + parseInt((ww/2) - (p_Width/2)) + "px;position:absolute;margin:0px; padding:0px; border:0px;z-index:" + (p_IsLock ? (this.MaxzIndex + 1) : this.MaxzIndex) + ";opacity: 0;filter:alpha(opacity=0)";
        p_PopupDiv = d.body.insertBefore(p_PopupDiv,d.body.firstChild);        
        
	    p_PopupDiv.innerHTML =  "<div class=\"PW_Div1\"></div>" + 
                                "<div class=\"PW_Div2\" style=\"width:" + (p_Width - 24) + "px\">" + 
                                    "<div id=\"PWDrag" + p_PopupPos + "_Div\" class=\"PW_Text1\" style=\"float:left;width:" + (p_Width - 115) + "px;height:28px\" onMouseOver=\"this.style.cursor='move';\"" + (p_ArrButton[1] != "1" ? "" : " ondblclick=\"PopupWindow.MaximizeWindow(this);\"") + ">" + p_Title + "</div>" + 
                                    "<div class='PW_Div8' onclick=\"PopupWindow.ClosePopupWindow(this);" + (p_CloseFunction == undefined ? "" : p_CloseFunction) + "\">&nbsp;</div>" + 
                                    (p_ArrButton[1] != "1" ? "" : "<div class='PW_Div11' onclick='PopupWindow.MaximizeWindow(this);'>&nbsp;</div>") + 
                                    (p_ArrButton[2] != "1" ? "" : "<div class='PW_Div12' onclick='PopupWindow.MinimizeWindow(this,document.documentElement.offsetHeight - 30);'>&nbsp;</div>") + 
                                "</div>" + 
                                "<div class=\"PW_Div3\"></div>" + 
                                "<div style=\"width:" + p_Width + "px; background:#000; clear:both\">" + 
                                    "<div style=\"width:" + (p_Width - 10) + "px;height:" + p_Height + "px;margin-left:auto; margin-right:auto;text-align:left;background:#ffffff; overflow:auto\">" + 
                                        p_HTML + 
                                    "</div>" +
                                    "<div id=\"PWBottomDrag" + p_PopupPos + "_Div\" class=\"PW_Div4\" style=\"width:" + (p_Width - 10) + "px\"></div>" +
                                "</div>" + 
                                "<div class=\"PW_Div5\"></div>" + 
                                "<div class=\"PW_Div6\" style=\"width:" + (p_Width - 24) + "px\"></div>" + 
                                "<div class=\"PW_Div7\"></div>"; 
                                
        //Relocate position
        var p_DimenHeight = r.offsetHeight - p_PopupDiv.offsetHeight;    
        if(p_DimenHeight > 0)
        {
            p_PopupDiv.style.top = parseInt(p_DimenHeight/2) + r.scrollTop + "px";        
        }     
                           
        var p_OpacityAnimate = new OpacityTween(p_PopupDiv,Tween.strongEaseIn, 0, 100, 0.4);
        p_OpacityAnimate.start();
            
        f_PW_MakeDraggable("PWDrag" + p_PopupPos + "_Div",p_PopupDiv.id,p_IsWrap);
        f_PW_MakeDraggable("PWBottomDrag" + p_PopupPos + "_Div",p_PopupDiv.id,p_IsWrap);
            
        this.ArrPopupPos[this.ArrPopupPos.length] = p_PopupPos;        
                
        if(p_IsCatchKeyDown != undefined && p_IsCatchKeyDown == true)
        {
            p_PopupDiv.childNodes[0].title = "1";
            document.onkeydown = function(event)
            {
                event = event || window.event;  
    	    
	            var p_KeyID = event.keyCode;	        
	            if(p_KeyID == 27)    
	            {
	                if(PopupWindow.ArrPopupPos.length > 0)
	                {
	                    var p_PopupCtrl = f_E("PWImagePopup" + PopupWindow.ArrPopupPos[PopupWindow.ArrPopupPos.length - 1] + "_div");
	                    if(p_PopupCtrl.childNodes[0].title == "1")
	                    {
	                        p_PopupCtrl.childNodes[0].title = "0";
	                        PopupWindow.ClosePopupWindow(p_PopupCtrl);
	                        if(p_CloseFunction != null) 
	                            setTimeout(p_CloseFunction,1);
	                    }
	                }
	                return false;            
	            }	            
            };   
        }
    },
    CreateHTMLPopup2 : function(p_Title,p_PopupName,p_HTML,p_Width,p_Height,p_IsWrap,p_IsLock,p_CloseFunction,p_IsCatchKeyDown)
    {   
        this.init();
        
        this.MaxzIndex = this.MaxzIndex + 1;
        //Check Panel exitst
        if(f_PW_CheckPanelNameExist(p_PopupName) == true)
            return;
            
        var p_PopupPos = f_PW_CheckPanelExist();
        
        var d = document;
	    var r = d.documentElement;
        var ww = r.clientWidth + r.scrollLeft;
	    var wh = r.clientHeight + r.scrollTop;
	    
	    if(p_Height > (r.offsetHeight - 75))
            p_IsWrap = false; 
            
	    // create a block element	    
        if(p_IsLock == true)
        {   
            this.PanelLock += "|" + p_PopupPos + "|";            
            if(f_E("PWOverLayer_div") == undefined)
            {
                var b = d.createElement("div");                        
                b.id = "PWOverLayer_div";
                b.className = "PW_Div13";
                b.style.cssText = "z-index:" + this.MaxzIndex;
                b = d.body.insertBefore(b,d.body.firstChild);			
                b.innerHTML = "";
                
                b.style.height = wh + "px";      
            }                 
        }        
                
	    var p_PopupDiv = d.createElement("div");	
        p_PopupDiv.id = "PWImagePopup" + p_PopupPos + "_div";        
        p_PopupDiv.style.cssText = "width:" + p_Width + "px;top:" + (r.scrollTop + 5) + "px;left:" + parseInt((ww/2) - (p_Width/2)) + "px;z-index:" + (p_IsLock ? (this.MaxzIndex + 1) : this.MaxzIndex) + ";opacity: 1;filter:alpha(opacity=100)";
        p_PopupDiv.className = "PW_Div14";
        p_PopupDiv = d.body.insertBefore(p_PopupDiv,d.body.firstChild);        
        
	    
	    p_PopupDiv.innerHTML =  "<div style='float:left;width:100%;position:relative'><a href='javascript:void(0)' class='PW_Link6' style='left:385px' onclick='PopupWindow.ClosePopupWindow(this);'></a>" + p_HTML + "</div>" +		                             
	                            "<div class='PW_Div15 PW_Text2'>" + 
	                                p_Title + 
	                            "</div>";
        //Relocate position
        var p_DimenHeight = r.offsetHeight - p_PopupDiv.offsetHeight;    
        if(p_DimenHeight > 0)
        {
            p_PopupDiv.style.top = parseInt(p_DimenHeight/2) + r.scrollTop + "px";        
        } 
            
        f_PW_MakeDraggable("PWDrag" + p_PopupPos + "_Div",p_PopupDiv.id,p_IsWrap);        
            
        this.ArrPopupPos[this.ArrPopupPos.length] = p_PopupPos;        
        
        if(p_IsCatchKeyDown != undefined && p_IsCatchKeyDown == true)
        {
            p_PopupDiv.childNodes[0].title = "1";
            document.onkeydown = function(event)
            {
                event = event || window.event;  
    	    
	            var p_KeyID = event.keyCode;	        
	            if(p_KeyID == 27)    
	            {
	                if(PopupWindow.ArrPopupPos.length > 0)
	                {   
	                    var p_PopupCtrl = f_E("PWImagePopup" + PopupWindow.ArrPopupPos[PopupWindow.ArrPopupPos.length - 1] + "_div");
	                    if(p_PopupCtrl.childNodes[0].title == "1")
	                    {
	                        p_PopupCtrl.childNodes[0].title = "0";
	                        PopupWindow.ClosePopupWindow(p_PopupCtrl);
	                        if(p_CloseFunction != null) 
	                            setTimeout(p_CloseFunction,1);
	                    }
	                }
	                return false;            
	            }	            
            };   
        }
    },
    CreateContextMenu : function(event,p_MousePos,p_Rank,p_StrIcon,p_StrTitle,p_StrFunction)    
    {   
        this.init();
        
        document.oncontextmenu = function(){return false;};
        f_PW_RemoveContextMenu(p_Rank);
        
        var p_SeperateChar = "[" + p_Rank + "]";
        var p_SeperateChildChar = "[" + (p_Rank + 1) + "]";        
        
        var p_ArrIcon = p_StrIcon.split(p_SeperateChar);
        var p_ArrTitle = p_StrTitle.split(p_SeperateChar);
        var p_ArrFunction = p_StrFunction.split(p_SeperateChar);        
        if(p_MousePos == null)
        {
            p_MousePos  = f_GetMouseCoords(event);
        }
        
        if (!event)     
            event = window.event; 
        var p_KeyID;
        
        if(BrowserDetect.browser == "Opera")
            p_KeyID = event.which;        
        else    
            p_KeyID = event.button;
        
        if(p_KeyID == 2 || p_Rank > 1) //right click
        {   
            var p_ChildMenuTop = p_MousePos[1];
            var p_Len = p_ArrTitle.length;
            var p_HTML = "<table cellspacing='0' cellpadding='3' class='PW_TD1'>";            
            for(i=0;i<p_Len;)
            {   
                if(p_ArrTitle[i] == "")
                {
                    p_HTML += "<tr><td colspan='2' style='height:10px'></td></tr>";
                    p_ChildMenuTop += 11;
                }
                else
                {
                    //Check if child menu                
                    if(p_ArrIcon[i].indexOf(p_SeperateChildChar) != -1)
                    {           
                        var p_ChildTitle = p_ArrTitle[i].substring(0,p_ArrTitle[i].indexOf(p_SeperateChildChar));
                        var p_ChildIcon = p_ArrIcon[i].substring(0,p_ArrIcon[i].indexOf(p_SeperateChildChar));                        
                        p_HTML +=   "<tr onclick=\"var p_Ctrl = f_E('ContextMenu" + p_Rank + "_div');PopupWindow.CreateContextMenu(event,new Array(p_Ctrl.offsetLeft + p_Ctrl.offsetWidth," + p_ChildMenuTop + ")," + (p_Rank + 1) + ",'" + p_ArrIcon[i].substring(p_ArrIcon[i].indexOf(p_SeperateChildChar) + 3) + "','" + p_ArrTitle[i].substring(p_ArrTitle[i].indexOf(p_SeperateChildChar) + 3) + "','" + p_ArrFunction[i].substring(p_ArrFunction[i].indexOf(p_SeperateChildChar) + 3) + "');\">" + 
                                        "<td id='ContextMenu_" + p_ChildTitle + "_box' style='width:20px' class='PW_TD2 " + p_ChildIcon + "'></td><td class='PW_TD2'><div style='float:left;height:100%'><a href='javascript:void(0)' class='PW_Link5'>" + p_ChildTitle + "</a></div><div class='QueryAnalyzer_DIV23'>&nbsp;</div></td>" + 
                                    "</tr>";                      
                    }
                    else
                    {
                        p_HTML +=   "<tr>" + 
                                        "<td style='width:20px' class='PW_TD2 " + p_ArrIcon[i] + "'></td><td class='PW_TD2'><a href='javascript:void(0)' class='PW_Link5' onclick=\"" + p_ArrFunction[i] + "PopupWindow.RemoveContextMenu(1);\">" + p_ArrTitle[i] + "</a></td>" +  
                                    "</tr>";                     
                    }
                    p_ChildMenuTop += 28;
                }
                i++;
            }        
            p_HTML += "</table>";
                                
            var p_Div = document.createElement("div");
	        p_Div.id = "ContextMenu" + p_Rank + "_div";	
	        p_Div.style.cssText = "position:absolute; left:" + p_MousePos[0] + "px; top:" + p_MousePos[1] + "px; z-index:" + (this.MaxzIndex*2);
	        p_Div = document.body.insertBefore(p_Div,document.body.firstChild);
	        p_Div.innerHTML =   p_HTML;    	    
    	    
	        //Check Border Bottom
	        var p_DimenHeight = p_Div.offsetHeight + p_MousePos[1] - document.documentElement.offsetHeight;
	        if(p_DimenHeight > 0)
	        {
	               p_Div.style.top = p_MousePos[1] - p_DimenHeight + "px";
	               p_Div.style.left = p_MousePos[0] + 3 + "px";
	        }
        }
    },
    ArrangePopupPosition : function()
    {   
        if(this.ArrPopupPos.length == 2)
        {   
            var p_Ctrl1 = f_E("PWImagePopup" + this.ArrPopupPos[0] + "_div"); 
            var p_Ctrl2 = f_E("PWImagePopup" + this.ArrPopupPos[1] + "_div"); 
            if(p_Ctrl1.offsetWidth + p_Ctrl2.offsetWidth > document.documentElement.offsetWidth)
            {
                p_Ctrl1.style.left = "5px";
                p_Ctrl1.style.top = "5px";
                p_Ctrl2.style.left = parseInt(document.documentElement.offsetWidth - p_Ctrl2.offsetWidth - 5) + "px";
                p_Ctrl2.style.top = parseInt(document.documentElement.offsetHeight - p_Ctrl2.offsetHeight - 5) + "px";
            }
            else
            {
                var p_SpaceWidth = parseInt((document.documentElement.offsetWidth - p_Ctrl1.offsetWidth - p_Ctrl2.offsetWidth)/3);
                p_Ctrl1.style.left = p_SpaceWidth + "px";            
                p_Ctrl2.style.left = parseInt(2*p_SpaceWidth + p_Ctrl1.offsetWidth) + "px";            
            }
        }    
    },
    CreateFileBrowserDialogPopup : function(p_Type,p_InputResultID,p_RootPath)
    {   
        var p_HTML = "";
        switch(p_Type)
        {
            case "Folder":
            {          
                p_HTML ="<div style=\"height:10px; clear:both\"></div>" + 
                        "<div class=\"FBD_TEXT1\" style=\"float:left;width:100px; height:37px; line-height:1.7;text-align:right\">Look in : &nbsp; </div>" + 
                        "<div id=\"RootDirectory_box\" style=\"float:left;width:300px; height:37px\"></div>" + 
                        "<div class=\"FBD_DIV5\" onclick=\"PopupWindow.UpFolder();\"></div>" + 
                        "<div id=\"DialogContent_box\" style=\"margin-left:auto; margin-right:auto; overflow:auto;width:480px; height:280px; border:1px solid #3C86EE; clear:both; background:#fff\"></div>" + 
                        "<div style=\"height:10px; clear:both\"></div>" + 
                        "<div style=\"height:30px\">" + 
                            "<div class=\"FBD_TEXT1\" style=\"float:left; width:100px; height:100%; text-align:right;line-height:1.5\">Folder name : &nbsp; </div>" + 
                            "<div style=\"float:left; width:300px; height:100%; line-height:1.5\">" + 
                                "<input id=\"BrowserValue_txt\" type=\"text\" style=\"border:1px solid #3C86EE; height:22px; width:100%\" />" + 
                            "</div>" + 
                            "<div style=\"float:right; width:74px; height:100%; text-align:left;line-height:1.5\">" + 
                                "<input id=\"Open_bt\" type=\"button\" value=\"Open\" style=\"width:60px\" onclick=\"f_E('" + p_InputResultID + "').value = PopupWindow.Path + '/' + f_E('BrowserValue_txt').value; PopupWindow.RemovePopup(PopupWindow.ArrPopupPos[PopupWindow.ArrPopupPos.length - 1]);Combobox.dispose();\" />" + 
                            "</div>" + 
                        "</div>" + 
                        "<div style=\"height:30px\">" + 
                            "<div class=\"FBD_TEXT1\" style=\"float:left; width:100px; height:100%; text-align:right;line-height:1.5\">" +
                                "Files of type : &nbsp; " + 
                            "</div>" + 
                            "<div id=\"FileType_box\" style=\"float:left; width:300px; height:100%; line-height:1.5\">" + 
                            "</div>" + 
                            "<div style=\"float:right; width:74px; height:100%; text-align:left;line-height:1.5\">" + 
                                "<input id=\"Cancel_bt\" type=\"button\" value=\"Cancel\" style=\"width:60px\" onclick=\"PopupWindow.RemovePopup(PopupWindow.ArrPopupPos[PopupWindow.ArrPopupPos.length - 1]); Combobox.dispose();\" />" +
                            "</div>" + 
                        "</div>";     
                this.CreateHTMLPopup("Folder Choose","FolderPopup",p_HTML,520,400,true,true,"1|0|1","Combobox.dispose();",false);
                
                this.init();
                Combobox.CreateComboboxStyle1("RootDirectory_box","RootDir_cb",300,0,"","Root...","Root...","");
                Combobox.CreateComboboxStyle1("FileType_box","FileType_cb",300,0,"","All files","All files","");
                this.Path = p_RootPath;
                this.RootPath = p_RootPath;
                f_PW_ShowContentDialog("Folder");                
                break;
            }
        }
    },
    ClosePopupWindow : function(p_Ctrl)
    {
        while(p_Ctrl.id.indexOf("PWImagePopup") != 0)
        {
            p_Ctrl  = p_Ctrl.parentNode;
        }
        var p_PopupPos = p_Ctrl.id.substring(12,p_Ctrl.id.lastIndexOf("_div"));        
        f_PW_RemovePopup(p_PopupPos);
    },
    CloseContextMenu : function(p_Ctrl)
    {
        if(p_Ctrl != undefined)
        {
            while(p_Ctrl.id.indexOf("ContextMenu") != 0)
            {
                p_Ctrl  = p_Ctrl.parentNode;
            }
            p_Ctrl.parentNode.removeChild(p_Ctrl);
        }
    },
    DoubleClickFolder : function(p_FolderName)
    {
        f_PW_DoubleClickFolder(p_FolderName);
    },
    ClickFolder : function(p_Ctrl)
    {
        f_PW_ClickFolder(p_Ctrl);
    },
    RootComboClick : function(p_Str,p_OccChar)
    {
        f_PW_RootComboClick(p_Str,p_OccChar);
    },
    UpFolder : function()
    {
        f_PW_UpFolder();
    },
    FirstImage : function(p_ArrImage,p_ArrResoluion,p_PopupPos,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown)
    {
        f_PW_FirstImage(p_ArrImage,p_ArrResoluion,p_PopupPos,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown);
    },
    PreImage : function(p_ArrImage,p_ArrResoluion,p_PopupPos,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown)
    {
        f_PW_PreImage(p_ArrImage,p_ArrResoluion,p_PopupPos,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown);
    },
    NextImage : function(p_ArrImage,p_ArrResoluion,p_PopupPos,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown)
    {
        f_PW_NextImage(p_ArrImage,p_ArrResoluion,p_PopupPos,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown);
    },
    LastImage : function(p_ArrImage,p_ArrResoluion,p_PopupPos,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown)
    {
        f_PW_LastImage(p_ArrImage,p_ArrResoluion,p_PopupPos,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown);
    },
    RemovePopup : function(p_PopupPos)
    {
        f_PW_RemovePopup(p_PopupPos);
    },
    RemoveContextMenu : function(p_Rank)
    {
        f_PW_RemoveContextMenu(p_Rank);
    },
    MinimizeWindow : function(p_Ctrl,p_Top)
    {
        f_PW_MinimizeWindow(p_Ctrl,p_Top);
    },
    MaximizeWindow : function(p_Ctrl)
    {
        f_PW_MaximizeWindow(p_Ctrl);
    }
};
/****FILE BROWSER DIALOG*****************/
function f_PW_GetLocalFolderList()
{   
    var p_HTML = "";
    var p_ArrFile = new Array();
    var p_Count = 0;  
    var p_Data;  
    var i;
    p_Data = PopupWindow.Class.GetLocalFolderList(PopupWindow.Path).value;
    if(p_Data)
    {
        p_ArrFile = p_Data.split("|");
        p_Count = p_ArrFile.length;
        for(i=0;i<p_Count;)        
        {   
            p_HTML +=   "<div id=\"Content" + i + "_box\" class=\"FBD_DIV2\" onclick=\"PopupWindow.ClickFolder(this);\"  ondblclick=\"PopupWindow.DoubleClickFolder('" + p_ArrFile[i] + "');\">" + 
                            "<div class=\"FBD_DIV3\"></div>" + 
                            "<div>" + p_ArrFile[i] + "</div>" + 
                        "</div>";
            i++;
        }        
    }
    return p_HTML;
}

function f_PW_ShowContentDialog(p_Type)
{   
    switch(p_Type)
    {
        case "Folder":
        {   
            var p_Title = PopupWindow.Class.GetTreeRoot(PopupWindow.RootPath,PopupWindow.Path).value;
            var p_Value = p_Title;
            var p_OnclickFunction = "";
            var p_ArrTitle = p_Title.split("|");
            var i;
            var p_Count = p_ArrTitle.length;
            for(i=0;i<p_Count;)
            {   
                p_OnclickFunction += "PopupWindow.RootComboClick('" + p_ArrTitle[i].substring(0,p_ArrTitle[i].lastIndexOf("/") + 1) + "','../');|";
                i++;
            }
            p_Title = p_Title.replace(new RegExp("../","g"),"&nbsp;&nbsp;");
            Combobox.RenewDetailCombo("RootDir_cb","0","",p_Title,p_Value,p_OnclickFunction);            
            
            var p_HTML = f_PW_GetLocalFolderList(PopupWindow.Path);     
            if(p_HTML != "")
            {
                f_E("DialogContent_box").innerHTML = p_HTML;                              
                f_E("BrowserValue_txt").value = "";                
                return true;
            }
            else
            {   
                //Fix up level
                var p_CharPos = PopupWindow.Path.lastIndexOf("/");
                if(p_CharPos != PopupWindow.Path.length - 1)
                    PopupWindow.Path = PopupWindow.Path.substring(0,p_CharPos == 2 ? (p_CharPos + 1) : p_CharPos);
                    
                return false;
            }            
        }
    }
}

function f_PW_DoubleClickFolder(p_FolderName)
{   
    if(PopupWindow.Path[PopupWindow.Path.length - 1] != "/" ) 
    {   
        PopupWindow.Path = PopupWindow.Path + "/" + p_FolderName;
    }
    else
    {
        PopupWindow.Path = PopupWindow.Path + p_FolderName;
    }      
    if(f_PW_ShowContentDialog("Folder") == true)
        PopupWindow.ItemSelectID = null;
}

function f_PW_ClickFolder(p_Ctrl)
{   
    if(PopupWindow.ItemSelectID != null)
    {   
        f_E(PopupWindow.ItemSelectID).childNodes[1].className = "";        
    }

    p_Ctrl.childNodes[1].className = "FBD_DIV4";
    f_E("BrowserValue_txt").value = p_Ctrl.childNodes[1].innerHTML;
    PopupWindow.ItemSelectID = p_Ctrl.id;
}
    
function f_PW_RootComboClick(p_Str,p_OccChar)
{
    var p_Count = f_CountOccurrenceCharacter(p_Str,p_OccChar);     
    if(p_Count > 0)
    {
        while(p_Count > 0)
        {   
            f_PW_CreatePreviousFolderPath();
            p_Count--;
        }  
        f_PW_ShowContentDialog("Folder"); 
    }
}

function f_PW_CreatePreviousFolderPath()
{
    var p_CharPos = PopupWindow.Path.lastIndexOf("/");       
    if(p_CharPos != PopupWindow.Path.length - 1)
        PopupWindow.Path = PopupWindow.Path.substring(0,p_CharPos == 2 ? (p_CharPos + 1) : p_CharPos);
}

function f_PW_UpFolder()
{   
    var p_CharPos = PopupWindow.Path.lastIndexOf("/");       
    if(p_CharPos != PopupWindow.Path.length - 1)
    {   
        if(PopupWindow.Path != PopupWindow.RootPath)
        {            
            PopupWindow.Path = PopupWindow.Path.substring(0,p_CharPos == 2 ? (p_CharPos + 1) : p_CharPos);
            f_PW_ShowContentDialog("Folder");
        }                
    }
}
/*********************************************/
function f_PW_CheckPanelExist()
{
    var p_Count = PopupWindow.ArrPopupPos.length;
    var p_Pos = 0;
    if(p_Count == 0)
        p_Pos = 1;
    else
    {
        var p_Result;
        var i = 1;
        var j;          
        while(p_Pos == 0)
        {   
            p_Result = false;
            for(j=0;j<p_Count;)
            {
                if(i == PopupWindow.ArrPopupPos[j])
                {
                    p_Result = true;              
                    break;
                }                
                j++;
            }
            if(p_Result == false)
            {
                p_Pos = i;
            }
            i++;
        }
    }
    return p_Pos;    
}

function f_PW_CheckPanelNameExist(p_Name)
{
    var p_Result = false;
    if(p_Name != null)
    {
        var i;
        var p_ItemCount = PopupWindow.ArrPopupPos.length;
        for(i=0;i<p_ItemCount;)
        {
            if(f_E("PWImagePopup" + PopupWindow.ArrPopupPos[i] + "_div").title == p_Name)
            {
                p_Result = true;
                break;
            }
            i++;
        }
    }
    return p_Result;
}

function f_PW_CompareResolution(p_ArrResoluton,p_PosA,p_PosB)
{
    p_PosA -= 1;
    p_PosB -= 1;
    
    var p_ArrRes = p_ArrResoluton.split("@");    
    var p_OldWidth = parseInt(p_ArrRes[p_PosA].substring(0,p_ArrRes[p_PosA].indexOf("x")));
    var p_OldHeight = parseInt(p_ArrRes[p_PosA].substring(p_ArrRes[p_PosA].indexOf("x") + 1));
    var p_NewWidth = parseInt(p_ArrRes[p_PosB].substring(0,p_ArrRes[p_PosB].indexOf("x")));
    var p_NewHeight = parseInt(p_ArrRes[p_PosB].substring(p_ArrRes[p_PosB].indexOf("x") + 1));
    if(p_OldWidth == p_NewWidth && p_OldHeight == p_NewHeight)
    {
        return true;
    }    
    return false;
}
function f_PW_FirstImage(p_ArrImage,p_ArrResoluion,p_PopupPos,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown)
{   
    var p_Ctrl = f_E("PWImagePos" + p_PopupPos + "_lb"); 
    var p_ArrPos = p_Ctrl.innerHTML.split("/");        
    if(p_ArrPos[0] == "1") return;
    
    p_ArrPos[0] = parseInt(p_ArrPos[0]);
    p_ArrPos[1] = parseInt(p_ArrPos[1]);
    
    if(f_PW_CompareResolution(p_ArrResoluion,p_ArrPos[0],1))
    {
        var p_Arr = p_ArrImage.split("@");
        var p_ImageCtrl = f_E("PWPopupImage" + p_PopupPos + "_img");
        p_ImageCtrl.src = "";
        p_ImageCtrl.src = p_Arr[0];        
    }
    else
    {   
        f_PW_DeleteArrItem(p_PopupPos);
        var p_Title = f_E("PWDrag" + p_PopupPos + "_Div").innerHTML;
        var p_PopupName = f_E("PWImagePopup" + p_PopupPos + "_div").title;
        document.body.removeChild(f_E("PWImagePopup" + p_PopupPos + "_div"));
        PopupWindow.ReleaseDocumentFunctionCatch();
        PopupWindow.CreateImagePopup(p_Title,p_PopupName,p_ArrImage,p_ArrResoluion,0,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown);
        PopupWindow.ArrangePopupPosition();
    }
    p_Ctrl.innerHTML = 1 + "/" + p_ArrPos[1];
}

function f_PW_PreImage(p_ArrImage,p_ArrResoluion,p_PopupPos,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown)
{   
    var p_Ctrl = f_E("PWImagePos" + p_PopupPos + "_lb");
    var p_ArrPos = p_Ctrl.innerHTML.split("/");
    var p_ImgPos = parseInt(p_ArrPos[0]);    
    if(p_ImgPos > 1)
    {
        if(f_PW_CompareResolution(p_ArrResoluion,p_ImgPos,p_ImgPos - 1))
        {
            var p_Arr = p_ArrImage.split("@");            
            var p_ImageCtrl = f_E("PWPopupImage" + p_PopupPos + "_img");
            p_ImageCtrl.src = "";
            p_ImageCtrl.src = p_Arr[p_ImgPos - 2];        
        }
        else
        {   
            f_PW_DeleteArrItem(p_PopupPos);
            var p_Title = f_E("PWDrag" + p_PopupPos + "_Div").innerHTML;
            var p_PopupName = f_E("PWImagePopup" + p_PopupPos + "_div").title;
            document.body.removeChild(f_E("PWImagePopup" + p_PopupPos + "_div"));
            PopupWindow.ReleaseDocumentFunctionCatch();
            PopupWindow.CreateImagePopup(p_Title,p_PopupName,p_ArrImage,p_ArrResoluion,p_ImgPos - 2,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown);
            PopupWindow.ArrangePopupPosition();
        }
        p_Ctrl.innerHTML = (p_ImgPos - 1) + "/" + p_ArrPos[1];
    }
}

function f_PW_NextImage(p_ArrImage,p_ArrResoluion,p_PopupPos,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown)
{   
    var p_Ctrl = f_E("PWImagePos" + p_PopupPos + "_lb");
    var p_ArrPos = p_Ctrl.innerHTML.split("/");
    var p_ImgPos = parseInt(p_ArrPos[0]);    
    if(p_ImgPos < parseInt(p_ArrPos[1]))
    {
        if(f_PW_CompareResolution(p_ArrResoluion,p_ImgPos,p_ImgPos + 1))
        {
            var p_Arr = p_ArrImage.split("@");
            var p_ImageCtrl = f_E("PWPopupImage" + p_PopupPos + "_img");        
            p_ImageCtrl.src = "";            
            p_ImageCtrl.src = p_Arr[p_ImgPos];        
        }
        else
        {   
            f_PW_DeleteArrItem(p_PopupPos);
            var p_Title = f_E("PWDrag" + p_PopupPos + "_Div").innerHTML;
            var p_PopupName = f_E("PWImagePopup" + p_PopupPos + "_div").title;
            document.body.removeChild(f_E("PWImagePopup" + p_PopupPos + "_div"));
            PopupWindow.ReleaseDocumentFunctionCatch();
            PopupWindow.CreateImagePopup(p_Title,p_PopupName,p_ArrImage,p_ArrResoluion,p_ImgPos,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown);
            PopupWindow.ArrangePopupPosition();
        }
        p_Ctrl.innerHTML = (p_ImgPos + 1) + "/" + p_ArrPos[1];
    }
}

function f_PW_LastImage(p_ArrImage,p_ArrResoluion,p_PopupPos,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown)
{   
    var p_Ctrl = f_E("PWImagePos" + p_PopupPos + "_lb");
    var p_ArrPos = p_Ctrl.innerHTML.split("/");
    if(p_ArrPos[0] == p_ArrPos[1]) return;
    
    p_ArrPos[0] = parseInt(p_ArrPos[0]);
    p_ArrPos[1] = parseInt(p_ArrPos[1]);
    
    if(f_PW_CompareResolution(p_ArrResoluion,p_ArrPos[0],p_ArrPos[1]))
    {
        var p_Arr = p_ArrImage.split("@");
        var p_ImageCtrl = f_E("PWPopupImage" + p_PopupPos + "_img");
        p_ImageCtrl.src = "";
        p_ImageCtrl.src = p_Arr[p_ArrPos[1] - 1];        
    }
    else
    {  
        f_PW_DeleteArrItem(p_PopupPos);
        var p_Title = f_E("PWDrag" + p_PopupPos + "_Div").innerHTML;
        var p_PopupName = f_E("PWImagePopup" + p_PopupPos + "_div").title;
        document.body.removeChild(f_E("PWImagePopup" + p_PopupPos + "_div"));
        PopupWindow.ReleaseDocumentFunctionCatch();
        PopupWindow.CreateImagePopup(p_Title,p_PopupName,p_ArrImage,p_ArrResoluion,p_ArrPos[1] - 1,p_IsWarp,p_IsLock,p_ArrButton,p_CloseFunction,p_IsCatchKeyDown);
        PopupWindow.ArrangePopupPosition();
    }
    p_Ctrl.innerHTML = p_ArrPos[1] + "/" + p_ArrPos[1];    
}

function f_PW_RemovePopup(p_PopupPos)
{   
    PopupWindow.PanelLock = PopupWindow.PanelLock.replace("|" + p_PopupPos + "|","");
    
    var p_ImagePopupID = "PWImagePopup" + p_PopupPos + "_div";
    var p_OverLayerID = "PWOverLayer_div";
    var p_ImagePopupCtrl = f_E(p_ImagePopupID);    
    var p_OpacityAnimate = new OpacityTween(p_ImagePopupCtrl,Tween.strongEaseIn, 100, 0, 0.6);
    p_OpacityAnimate.start();
    p_OpacityAnimate.onMotionFinished = function()
    {   
        document.body.removeChild(p_ImagePopupCtrl);
        f_PW_DeleteArrItem(p_PopupPos);
        //if(f_E(p_OverLayer) != undefined && PopupWindow.ArrPopupPos.length == 0) 
        //alert(PopupWindow.PanelLock + "@" + p_PopupPos);       
        if(f_E(p_OverLayerID) != undefined && PopupWindow.PanelLock == "")
        {   
            document.body.removeChild(f_E(p_OverLayerID));            
            PopupWindow.dispose();
        }        
    }    
}

function f_PW_DeleteArrItem(p_Data)
{
    var i;
    var p_Count = PopupWindow.ArrPopupPos.length;
    for(i=0; i<p_Count;)
    {
        if(p_Data == PopupWindow.ArrPopupPos[i])
        {
            PopupWindow.ArrPopupPos.splice(i,1);
            return;
        }                
        i++;
    }
}

function f_PW_MapPath(p_Path)
{
    return window.location.protocol + "//" + window.location.host + "/" + window.location.pathname.split("/")[1] + "/" + p_Path;
}

function f_PW_CheckMousePointInContextMenu(event)
{   
    var i;
    var p_CtrlID = "";
    for(i=1;i<4;)
    {
        p_CtrlID = "ContextMenu" + i + "_div";
        if(f_E(p_CtrlID))
        {
            if(f_PW_CheckMousePointInObject(event,f_E(p_CtrlID)) == true)            
                return true;
        }    
        i++;
    }
    return false;
}

function f_PW_CheckMousePointInObject(event,p_Ctrl)
{   
    var p_Left,p_Right,p_Top,p_Bottom;
    p_Left = p_Ctrl.offsetLeft;    
    p_Right = p_Ctrl.offsetLeft + p_Ctrl.offsetWidth;
    p_Top = p_Ctrl.offsetTop;
    p_Bottom = p_Ctrl.offsetTop + p_Ctrl.offsetHeight;        
    
    if(event.clientX >= p_Left && event.clientX <= p_Right && event.clientY >= p_Top && event.clientY <= p_Bottom)
        return true;
    return false;
}

function f_PW_RemoveContextMenu(p_Rank)
{
    var i = p_Rank;
    for(i;;)
    {
        if(f_RemoveNode("ContextMenu" + i + "_div") == false)
            return;
        i++;
    }
}
/*
 *  Capture Drag Drop
 */ 
function f_PW_GetMouseOffset(p_Target, event)
{
	event = event || window.event;

	var p_DocPos    = f_GetPosition(p_Target);
	var p_MousePos  = f_GetMouseCoords(event);
	return new Array(p_MousePos[0] - p_DocPos[0], p_MousePos[1] - p_DocPos[1]);
}

function f_PW_MouseMove(event)
{   
    if(PopupWindow.DragObject)
	{	
	    event = event || window.event;
	    var p_MousePos = f_GetMouseCoords(event);
	    
	    var p_X = p_MousePos[0] - PopupWindow.MouseOffset[0];
	    var p_Y = p_MousePos[1] - PopupWindow.MouseOffset[1];
	    PopupWindow.DragObject.style.top = p_Y + "px";
        PopupWindow.DragObject.style.left = p_X + "px";
        
        var p_ScreenWidth = document.documentElement.offsetWidth + document.documentElement.scrollLeft - PopupWindow.DragObject.offsetWidth;
        var p_ScreenHeight = document.documentElement.offsetHeight + document.documentElement.scrollTop - PopupWindow.DragObject.offsetHeight;
	    if(PopupWindow.IsWrap == true)
	    {   
	        if(p_X < 0)	        
	            PopupWindow.DragObject.style.left = "0px";	            	        
	        else
	            if(p_X > p_ScreenWidth)
	                PopupWindow.DragObject.style.left = p_ScreenWidth + "px";
	            
	        if(p_Y < 0)	             
	            PopupWindow.DragObject.style.top = "0px";	        
	        else
	            if(p_Y > p_ScreenHeight)
	            {	                
	                PopupWindow.DragObject.style.top = p_ScreenHeight + "px";
	            }
	    }	    
	}	
	return false;
}

function f_PW_MouseUp()
{
	PopupWindow.DragObject = null;
	return false;
}

function f_PW_MakeDraggable(p_CtrlName,p_CtrlMoveName,p_IsWarp)
{   
	var p_Ctrl = f_E(p_CtrlName);
	if(!p_Ctrl)
	    return;
	
	p_Ctrl.onmousedown = function(event)
	{
	    PopupWindow.IsWrap = p_IsWarp;
		PopupWindow.DragObject  = f_E(p_CtrlMoveName);
		PopupWindow.MouseOffset = f_PW_GetMouseOffset(PopupWindow.DragObject, event);	
		
		if(p_CtrlName == p_CtrlMoveName)
		{
		    if(this.style.zIndex != PopupWindow.MaxzIndex)
		    {		    
	            PopupWindow.MaxzIndex = PopupWindow.MaxzIndex + 1;
	        }
	        this.style.zIndex = PopupWindow.MaxzIndex;
		}
		
		return false;	
	};	
	//Change zIndex when click panel
	if(p_CtrlName != p_CtrlMoveName)
	{
	    f_E(p_CtrlMoveName).onmousedown = function()
	    {
	        if(PopupWindow.ArrPopupPos.length > 1)
	        {
	            if(this.style.zIndex != PopupWindow.MaxzIndex)
	            {
	                PopupWindow.MaxzIndex = PopupWindow.MaxzIndex + 1;	                
	            }
	            this.style.zIndex = PopupWindow.MaxzIndex;		
	        }
	        //return false;
	    };	    
	}	
}

function f_PW_MinimizeWindow(p_Ctrl,p_Top)
{
    while(p_Ctrl.id.indexOf("PWImagePopup") != 0)
    {
        p_Ctrl  = p_Ctrl.parentNode;
    }     
    if(p_Ctrl.offsetWidth != 220 && (p_Ctrl.offsetWidth != document.documentElement.offsetWidth || p_Ctrl.offsetHeight != (document.documentElement.offsetHeight + 5)))
    {   
        PopupWindow.PopupPosition = p_Ctrl.offsetLeft + "|" + p_Ctrl.offsetTop + "|" + p_Ctrl.offsetWidth + "|" + p_Ctrl.offsetHeight;        
    }
    
    p_Ctrl.childNodes[3].style.display = "none";    
    p_Ctrl.style.width = "220px";
    p_Ctrl.childNodes[1].style.width = "196px";
    p_Ctrl.childNodes[1].childNodes[0].style.width = "105px";
    p_Ctrl.childNodes[5].style.width = "196px";
    
    p_Ctrl.childNodes[1].childNodes[0].onclick = function()
    {
        f_PW_MaximizeWindow(p_Ctrl);
        return false;
    };
    
    var p_TopAnimate = new Tween(p_Ctrl.style,"top",Tween.strongEaseOut,p_Ctrl.offsetTop, p_Top, 0.3,"px");
    p_TopAnimate.start();
    var p_LeftAnimate = new Tween(p_Ctrl.style,"left",Tween.strongEaseOut,p_Ctrl.offsetLeft, 0, 0.3,"px");
    p_LeftAnimate.start();
}

function f_PW_MaximizeWindow(p_Ctrl)
{
    while(p_Ctrl.id.indexOf("PWImagePopup") != 0)
    {
        p_Ctrl  = p_Ctrl.parentNode;
    }
    var p_MaxWidth = document.body.offsetWidth;
    var p_MaxHeight = document.body.offsetHeight;    
    if(p_MaxWidth == p_Ctrl.offsetWidth || p_Ctrl.offsetWidth == 220)
    {   
        if(p_Ctrl.offsetWidth == 220)
        {
            f_AddEvent(p_Ctrl.childNodes[1].childNodes[0],"click",function (){},true);
        }
        var p_ArrPosition = PopupWindow.PopupPosition.split("|");
        f_PW_ResizeWindow(p_Ctrl,parseInt(p_ArrPosition[0]),parseInt(p_ArrPosition[1]),parseInt(p_ArrPosition[2]),parseInt(p_ArrPosition[3]));
    }
    else
    {
        if(p_Ctrl.offsetWidth != 220)
            PopupWindow.PopupPosition = p_Ctrl.offsetLeft + "|" + p_Ctrl.offsetTop + "|" + p_Ctrl.offsetWidth + "|" + p_Ctrl.offsetHeight;
        f_PW_ResizeWindow(p_Ctrl,0,0,p_MaxWidth,p_MaxHeight);
    }
}

function f_PW_ResizeWindow(p_Ctrl,p_Left,p_Top,p_Width,p_Height)
{   
    var p_TopAnimate = new Tween(p_Ctrl.style,"top",Tween.strongEaseOut,p_Ctrl.offsetTop, p_Top, 0.3,"px");
    p_TopAnimate.start();
    var p_LeftAnimate = new Tween(p_Ctrl.style,"left",Tween.strongEaseOut,p_Ctrl.offsetLeft, p_Left, 0.3,"px");
    p_LeftAnimate.start();
    var p_WidthAnimate = new Tween(p_Ctrl.style,"width",Tween.strongEaseOut,p_Ctrl.offsetWidth, p_Width, 0.3,"px");
    p_WidthAnimate.start();    
    p_WidthAnimate.onMotionFinished = function()
    {
        p_Ctrl.childNodes[1].style.width = (p_Width - 24) + "px";
        p_Ctrl.childNodes[1].childNodes[0].style.width = (p_Width - 115) + "px";
        p_Ctrl.childNodes[5].style.width = (p_Width - 24) + "px";
        p_Ctrl.childNodes[3].style.width = p_Width + "px";
        p_Ctrl.childNodes[3].childNodes[0].style.height = (p_Height - 79) + "px";
        p_Ctrl.childNodes[3].childNodes[0].style.width = (p_Width - 10) + "px";    
        p_Ctrl.childNodes[3].childNodes[1].style.width = (p_Width - 10) + "px";
        p_Ctrl.childNodes[3].style.display = "";
    };
}
