﻿var closedockid;
var oZone = new Array();
var oDock = new Array();

var oDock1 = new Array();
var oDock2 = new Array();
var oDock3 = new Array();
var oZoneRect = new Array();

function alertOnlyMember(dockObj,eventArgs){
    RadAlert('เฉพาะสมาชิก / Only members');
}

function clientCollapse(dockObj,eventArgs) {
    dockObj.Collapse();
    dockObj.GetCommandByName('_Collapse').Enable(false);
    dockObj.GetCommandByName('_Expand').Enable(true);
    document.getElementById(dockObj.id).style.borderBottom = "";

    var sName = splitter1.ID.replace("RadSplitter1", "");

    document.getElementById(sName + 'hdnPostBack').value = "CollapseDock";
    document.getElementById(sName + 'hdnValue1').value = dockObj.id;
    document.getElementById('btnShow').click();
    
    document.getElementById(dockObj.id).style.height = "100%";
    SetPaneHeight(GetMaxZoneHeight());
}   
function clientExpand(dockObj,eventArgs) {
    try{
        dockObj.Expand(true);
    }catch(e) {}
    dockObj.GetCommandByName('_Collapse').Enable(true);
    dockObj.GetCommandByName('_Expand').Enable(false);
    document.getElementById(dockObj.id).style.borderBottom = "solid 1px #c5d7ef";

    var sName = splitter1.ID.replace("RadSplitter1", "");

    document.getElementById(sName + 'hdnPostBack').value = "ExpandDock";
    document.getElementById(sName + 'hdnValue1').value = dockObj.id;
    document.getElementById('btnShow').click();
    
    document.getElementById(dockObj.id).style.height = "100%";
    SetPaneHeight(GetMaxZoneHeight());
}

function clientClose(dockObj, eventArgs) {

    dockObj.Hide();

    closedockid = dockObj.id;
    document.getElementById('undel_title').innerText = '"' + dockObj.TitleBar.innerText + '" ';
    document.getElementById('undel_titleEN').innerText = '"' + dockObj.TitleBar.innerText + '" ';
    document.getElementById('undel_msg').style.display = "block";

    var sName = splitter1.ID.replace("RadSplitter1", "");

    document.getElementById(sName + 'hdnPostBack').value = "CloseDock";
    document.getElementById(sName + 'hdnValue1').value = dockObj.id;
    document.getElementById('btnShow').click();
    SetPaneHeight(GetMaxZoneHeight());
}  

function querySt(ji) {
    hu = window.location.search.substring(1);
    gy = hu.split("&");
    for (i=0;i<gy.length;i++) {
        ft = gy[i].split("=");
        if (ft[0] == ji) {
            return ft[1];
        }
    }
}

function editSettings(dockObj,eventArgs){
    disposeMenu();
    
    var pos = new Array();
    pos = dockObj.id.split("_");

    if (document.getElementById('divSetting_' + pos[pos.length - 1]) != null){
        menuHeight = 40;
        addMenuItem("แก้ไขการตั้งค่า / Edit setting", "document.getElementById('divSetting_" + pos[pos.length - 1] + "').style.display = 'block';SetPaneHeight(GetMaxZoneHeight());");
    }else{
        menuHeight = 22;
    }
    addMenuItem("เกี่ยวกับ Gadget นี้ / About this Gadget", "window.location.href='Gadget/GadgetDetail.aspx?a=0&i=" + pos[pos.length - 1] + "'");

    createMenu(pos[pos.length - 1]);

    showMenu(eventArgs.firstChild);
    
    SetPaneHeight(GetMaxZoneHeight());
}
function saveSettingFeed(gadgetId, xmlSetting){
    var sName = splitter1.ID.replace("RadSplitter1","");
    document.getElementById(sName + 'hdnPostBack').value = "SaveSetting";
    document.getElementById(sName + 'hdnValue1').value = gadgetId;
    document.getElementById(sName + 'hdnValue2').value = GetXmlGadgetNodeValue("feed", gadgetId, xmlSetting)
    document.getElementById(sName + 'btnSetting').click();
}

function saveSettingModule(gadgetId, xmlSetting){
     var sName = splitter1.ID.replace("RadSplitter1","");
    document.getElementById(sName + 'hdnPostBack').value = "SaveSetting";
    document.getElementById(sName + 'hdnValue1').value = gadgetId;
    if (CheckXmlGadgetNodeValue("module", gadgetId, xmlSetting)){
        document.getElementById(sName + 'hdnValue2').value = GetXmlGadgetNodeValue("module", gadgetId, xmlSetting);
    }else{
        document.getElementById(sName + 'hdnValue2').value = "<UserSettings />";
    }
    document.getElementById(sName + 'btnSetting').click();
}

function _undel(){

    if (closedockid != null){
        document.getElementById('undel_msg').style.display = "none";
        
        dockObj = RadDock_GetDockableObject(closedockid);
        dockObj.Show();

        var sName = splitter1.ID.replace("RadSplitter1", "");

        document.getElementById(sName + 'hdnPostBack').value = "UndoCloseDock";
        document.getElementById(sName + 'hdnValue1').value = dockObj.id;
        document.getElementById('btnShow').click();
    }
    
}
function _confirmdel(){
    closedockid = null;
    document.getElementById('undel_msg').style.display = "none";
}

var posDock = null;
function OnClientDrop (dockObj, eventArgs)
{
    var sName = splitter1.ID.replace("RadSplitter1", "");

    document.getElementById(sName + 'hdnPostBack').value = "MoveDock";
    document.getElementById(sName + 'hdnValue1').value = dockObj.id;
    document.getElementById(sName + 'hdnValue2').value = dockObj.ParentDockingZone.id;
    document.getElementById(sName + 'hdnValue3').value = dockObj.ParentDockingZone.GetPosition(dockObj);
    document.getElementById('btnShow').click();

    document.releaseCapture();
   
}

function OnClientDragStart (dockObj, eventArgs)
{
    var obj = document.getElementById(dockObj.id + '_TitleCell');
    obj.setCapture();

}

function OnClientDock(dockObj, eventArgs){
    SetPaneHeight(GetMaxZoneHeight());
}

function GetZone(x, y){
    for(i=0; i<3; i++){
        if (x > oZoneRect[i].left && x < oZoneRect[i].right) {
            return oZone[i];
        }
    }
}

 menuItems = new Array();
 menuItemNum = 0;

 function addMenuItem(text, url, img)
 {
  if(img) menuItems[menuItemNum] = new Array(text, url, img);
  else if(text) menuItems[menuItemNum] = new Array(text, url);
  else menuItems[menuItemNum] = new Array();
  menuItemNum++;
 }

 menuWidth = 133; //menu width
 menuHeight = 40; //menu height
 menuDelay = 0; //delay before menu appears
 menuSpeed = 1; //speed which menu appears (lower=faster)
 menuOffset = 0; //offset of menu from mouse pointer

if(window.navigator.appName == "Microsoft Internet Explorer" && window.navigator.appVersion.substring(window.navigator.appVersion.indexOf("MSIE") + 5, window.navigator.appVersion.indexOf("MSIE") + 8) >= 5.5)
  isIe = 1;
 else
  isIe = 0;

var menuPopup;

function createMenu(element)
{
          menuContent = '<table id="rightMenu" width="0" height="0" cellspacing="0" cellpadding="0" style="font:menu;color:menutext"><tr height="1"><td style="background:threedlightshadow" colspan="4"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedhighlight" colspan="2"></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr><tr height="10"><td style="background:threedlightshadow"></td><td style="background:threedhighlight"></td><td style="background:#fff"><table cellspacing="0" cellpadding="0" nowrap style="font:menu;color:menutext;cursor:default;">';
          for(m=0;m<menuItems.length;m++)
          {
               if(menuItems[m][0] && menuItems[m][2])           
               {
                    menuContent += '<tr height="17" onMouseOver="this.style.background=\'highlight\';this.style.color=\'highlighttext\';" onMouseOut="this.style.background=\'#fff\';this.style.color=\'menutext\';" onClick="parent.window.location.href=\'' + menuItems[m][1] + '\'"><td style="background:#fff" width="1" nowrap></td><td width="21" nowrap><img src="' + menuItems[m][2] + '"></td><td nowrap>' + menuItems[m][0] + '</td><td width="21" nowrap></td><td style="background:#fff" width="1" nowrap></td></tr>';
               }else if(menuItems[m][0])
               {
                    menuContent += '<tr height="17" onMouseOver="this.style.background=\'highlight\';this.style.color=\'highlighttext\';" onMouseOut="this.style.background=\'#fff\';this.style.color=\'menutext\';" onClick="' + menuItems[m][1] + '"><td style="background:#fff" width="1" nowrap></td><td width="21" nowrap></td><td nowrap>' + menuItems[m][0] + '</td><td width="21" nowrap></td><td style="background:#fff" width="1" nowrap></td></tr>';
               }else
               {
                    menuContent += '<tr><td colspan="5" height="4"></td></tr><tr><td colspan="5"><table cellspacing="0"><tr><td width="2" height="1"></td><td width="0" height="1" style="background:threedshadow"></td><td width="2" height="1"></td></tr><tr><td width="2" height="1"></td><td width="100%" height="1" style="background:threedhighlight"></td><td width="2" height="1"></td></tr></table></td></tr><tr><td colspan="5" height="3"></td></tr>';
               }
          }
          menuContent += '</table></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedhighlight"></td><td style="background:#fff"></td><td style="background:threedshadow"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threedlightshadow"></td><td style="background:threedshadow" colspan="3"></td><td style="background:threeddarkshadow"></td></tr><tr height="1"><td style="background:threeddarkshadow" colspan="5"></td></tr></table>';

          
          document.getElementById("divContainerMenu").innerHTML = menuContent;

}

function disposeMenu()
{
    if(menuItems.length > 0) {
        menuItems = new Array();
        menuItemNum = 0;
    }
} 


 function showMenu(element)
 { 

      getPos(element);

      menuXPos = menuXPos - Math.ceil(menuWidth/2);
      menuYPos = menuYPos + 2;
            
      menuXIncrement = menuWidth / menuSpeed;
      menuYIncrement = menuHeight / menuSpeed;

      openMenu(0,0);
      
      return false;
 }


function getPos(element)
{
            
    menuXPos = element.offsetLeft;
    menuYPos = element.offsetTop;
        
    while(element=element.offsetParent)
    {
        menuXPos += element.offsetLeft;
        menuYPos += element.offsetTop;
    }
}
 function openMenu(height, width) {
      
     var divMsg = document.getElementById("divMsg");
     document.getElementById("divContainerMenu").style.display = "block";
     if (divMsg.style.display == "block")
         document.getElementById("divContainerMenu").style.top = (menuYPos - 95) + "px";
     else if (divMsg.style.display == "none")
         document.getElementById("divContainerMenu").style.top = (menuYPos - 75) + "px";
     document.getElementById("divContainerMenu").style.left = (menuXPos - 65) + "px";      
 }
