
// START CATALOG FUNCTIONS ---------------------------------------------------------------------------------------------------------------


//TIMER
//var MMFsecs;
//var MMFtimerID = null;
//var MMFtimerRunning = false;
//var MMFdelay = 1000;

//function MMFInitializeTimer()
//{
    // Set the length of the timer, in seconds
    //MMFsecs = 2
    //MMFStopTheClock()
    //MMFStartTheTimer()
//}

/*function MMFStopTheClock()
{
    if(MMFtimerRunning)
        clearTimeout(MMFtimerID)
    MMFtimerRunning = false;
    
    MMFsecs = null;
        MMFtimerID = null;
        MMFtimerRunning = null;
        MMFdelay = null;
}

function MMFStartTheTimer()
{
    if (MMFsecs==0)
    {
        MMFStopTheClock()
    }
    else
    {
        self.status = MMFsecs;
        MMFsecs = MMFsecs - 1;
        MMFtimerRunning = true;
        MMFtimerID = self.setTimeout("MMFStartTheTimer()", MMFdelay);
    }
}*/
//--------------------------------------------





// Find if it is a click or a drag and drop
var sourceZoneID;
var sourceZoneIndex;

function MMFDockDragStart (sender, eventArgs)
{
    sourceZoneID = sender.get_DockZoneID();
    sourceZoneIndex = sender.get_Index();
    
    // HIDE CATALOG PREVIEW
    MMFHideCatalogPreViewMasterHolder();
    
    
    //MMFInitializeTimer();
}

function MMFDockPositionChanged(sender, eventArgs)
{
}

function MMFDockDragEnd (sender, eventArgs)
{
    var uniqueName = sender.get_UniqueName();

    var targetZoneID = sender.get_DockZoneID();
    var targetZoneIndex = sender.get_Index();
    
    if(sourceZoneID != targetZoneID || sourceZoneIndex != targetZoneIndex)
    {
        __doPostBack(uniqueName, eventArgs);
    }
    else
    {
        // SHOW CATALOG PREVIEW
        MMFShowCatalogPreViewMasterHolder();
    }
    
    sourceZoneID = null;
    sourceZoneIndex = null;
    targetZoneID = null;
    targetZoneIndex = null;
    uniqueName = null;
}



// CATALOG MODULE PREVIEW
function MMFShowCatalogPreView(previewHolderID)
{
    var x = GetX(document.getElementById('CatalogHolder'));
    var y = GetY(document.getElementById('CatalogHolder'));
    
    if(navigator.appName == "Microsoft Internet Explorer")
    {
        x = x + 297;
    }
    else
    {
        x = x + 285;
    }
    
    //y = y + 10;
    
    var e = document.getElementById(previewHolderID);
    e.style.display = "block";
    e.style.left = x + "px";
    e.style.top = y + "px";
    
    e = null;
    x = null;
    y = null;
}

function MMFShowCatalogPreViewMasterHolder()
{
    document.getElementById('catalogPreviewMasterHolder').style.display = "block";
}

function MMFHideCatalogPreViewMasterHolder()
{
    document.getElementById('catalogPreviewMasterHolder').style.display = "none";
}

function MMFHideCatalogPreView(previewHolderID, toolTipHolderID)
{
    document.getElementById(previewHolderID).style.display = "none";
    
    //MMFHideToolTipDragAndDrop(toolTipHolderID);
}

// ----------------------------



function MMFShowToolTipDragAndDrop(toolTipHolderID)
{
    document.getElementById(toolTipHolderID).style.display = "block";
}

function MMFHideToolTipDragAndDrop(toolTipHolderID)
{
    document.getElementById(toolTipHolderID).style.display = "none";
}

//--------------------------------------------




function MMFCloseCatalog()
{
    document.getElementById("CatalogHolder").style.display = "none";
    eraseCookie("catIsOpen");
    eraseCookie("catpos");
}

function MMFShowCatalog()
{
    document.getElementById("CatalogHolder").style.display = "block";
    document.cookie = "catIsOpen=1";
}

// Create Dragable Catalog and Mantain Panel position / using Scriptaculos
function MMFSetCatalogHandle(catalogPanelID)
{
    new Draggable(catalogPanelID ,{handle:'Handle'});
}



var startScrollPosition;

function MMFSaveCatalogPosition(catalogPanelID)
{
    var  catalog = document.getElementById(catalogPanelID);
    document.cookie = "catpos=" + catalog.style.top + "/" + catalog.style.left;
    
    catalog = null;

    startScrollPosition = document.documentElement.scrollTop;
}

function MMFSetCatalogPosition()
{
    // TODO: Make it compatible with Safari
    if(navigator.appVersion.match("Safari") == null)
    {
        var catalogPosition = readCookie('catpos')
        
        var top = 205;
        var left = 100;
        
        if(catalogPosition != null)
        {  
            var catPosArray = catalogPosition.split('/',2);
            
            top = parseInt(catPosArray[0].replace('px',''));
            left = parseInt(catPosArray[1].replace('px','')); 
        }
        
        var scrollTop = document.documentElement.scrollTop; 
        if(startScrollPosition > 0)
        {
            scrollTop = scrollTop - startScrollPosition;
        }
        
        top = top + scrollTop;       
        left = left + document.documentElement.scrollLeft;

        var cat = document.getElementById('ctl00_MemberContentPlaceHolder_pnCatalogHandle');

        if(cat != null)
        {
            cat.style.top = top + "px";
            cat.style.left = left + "px";
        }
        
        catalogPosition = null;
        top = null;
        left = null;
        catPosArray = null;
        cat = null;
        scrollTop = null;

    }
}

function MMFResetCatalogPosition()
{  
    var top = 205;
    var left = 100;
    
    var cat = document.getElementById('ctl00_MemberContentPlaceHolder_pnCatalogHandle');

    if(cat != null)
    {
        cat.style.top = top + "px";
        cat.style.left = left + "px";
        
        document.cookie = "catpos=" + cat.style.top + "/" + cat.style.left;
    }
    
    top = null;
    left = null;
    cat = null;
}


// END CATALOG FUNCTIONS ---------------------------------------------------------------------------------------------------------------







// START DOCK FUNCTIONS ---------------------------------------------------------------------------------------------------------------

function MMFSetHandle(dock, args)
{
    var moduleDivAtts = document.getElementById(dock.get_id()).attributes;
    var handleID = moduleDivAtts.getNamedItem('handleID').value;
    dock.set_handle(document.getElementById(handleID));
    
    moduleDivAtts = null;
    handleID = null;
}

function MMFShowCmd(_moduleUniqueName)
{
    var edit = document.getElementsByName("cmdEdit" + _moduleUniqueName);
    var close = document.getElementsByName("cmdClose" + _moduleUniqueName);
    //var collapse = document.getElementsByName("cmdCollapse" + _moduleUniqueName);
    
    edit.item(0).style.visibility = "visible";
    close.item(0).style.visibility = "visible";
    //collapse.item(0).style.visibility = "visible";
    
    edit = null;
    close = null;
}

function MMFHideCmd(_moduleUniqueName)
{
    var edit = document.getElementsByName("cmdEdit" + _moduleUniqueName);
    var close = document.getElementsByName("cmdClose" + _moduleUniqueName);
    //var collapse = document.getElementsByName("cmdCollapse" + _moduleUniqueName);
    
    edit.item(0).style.visibility = "hidden";
    close.item(0).style.visibility = "hidden";
    //collapse.item(0).style.visibility = "hidden";
    
    edit = null;
    close = null;
    
}

// END DOCK FUNCTIONS ---------------------------------------------------------------------------------------------------------------









// EDIT MODULE ---------------------------------------------------------------------------------------------------------------

function MMFLoadEdit(dock, args)
{
    //document.cookie = "MMFIsNewEdit=true";
    //document.cookie = "editModule=true";
}

// Create Dragable Edit Panel and Mantain position / using Scriptaculos
function MMFSetEditHandle(editPanelID)
{
    new Draggable(editPanelID ,{handle:'editHandle'});
    
}
    
function MMFSaveEditPosition(editPanelID)
{
    var edit = document.getElementById(editPanelID);
    document.cookie = "editpos=" + edit.style.top + "/" + edit.style.left;
    
    edit = null;
}

/* EDIT MODULE CLOSE/COLLAPSE/EXPAND FUNCTIONS */
function MMFCloseModuleEdit(editHolderID)
{
    document.getElementById(editHolderID).style.display = "none";
    eraseCookie("editModule");
}

function MMFCollapseModuleEdit(editHolderID)
{
    //document.getElementById(editHolderID).style.display = "none";
    Effect.BlindUp(editHolderID, {duration:.5});
    document.getElementById('editModCollapse').style.display = "none";
    document.getElementById('editModExpand').style.display = "block";

}

function MMFExpandModuleEdit(editHolderID)
{
    //document.getElementById(editHolderID).style.display = "block";
    Effect.BlindDown(editHolderID, {duration:.5});
    document.getElementById('editModCollapse').style.display = "block";
    document.getElementById('editModExpand').style.display = "none";
}

function MMFCollapseTip()
{
    //document.getElementById('editModuleTip').style.display = "none";
    Effect.BlindUp('editModuleTip', {duration:.5});
    document.getElementById('editCollapseTip').style.display = "none";
    document.getElementById('editExpandTip').style.display = "block";
}

function MMFExpandTip()
{
    //document.getElementById('editModuleTip').style.display = "block";
    Effect.BlindDown('editModuleTip', {duration:.5});
    document.getElementById('editCollapseTip').style.display = "block";
    document.getElementById('editExpandTip').style.display = "none";
}

function MMFShowModuleEdit(editHolderID)
{
    document.getElementById(editHolderID).style.display = "block";
}

function MMFTABMouseHover(tabHolderID)
{
    document.getElementById(tabHolderID).className = "LTModuleEditTABHover";
}

function MMFTABMouseOut(tabHolderID)
{
    var tab = document.getElementById(tabHolderID);
    
    if(tab.readAttribute('selected') == "false") // using prototype - readAttribute
    {
        document.getElementById(tabHolderID).className = "LTModuleEditTAB";
    }
    
    tab = null;
}

function MMFShowModuleEditMainOptions()
{
    // Option Panels
    document.getElementById('editModOptionsMain').style.display = "block";
    document.getElementById('editModOptionsExtras').style.display = "none";
    
    // TABs
    var tabOptions = document.getElementById('editTABOptions');
    var tabExtras = document.getElementById('editTABExtras');
    
    tabOptions.className = "LTModuleEditTABHover";
    tabExtras.className = "LTModuleEditTAB";
    
    tabOptions.setAttribute('selected','true');
    tabExtras.setAttribute('selected','false');
    
    tabOptions = null;
    tabExtras = null;
}

function MMFShowModuleEditExtraOptions()
{
    // Option Panels
    document.getElementById('editModOptionsMain').style.display = "none";
    //document.getElementById('editModOptionsExtras').style.display = "block";
    
    // TABs
    var tabOptions = document.getElementById('editTABOptions');
    //var tabExtras = document.getElementById('editTABExtras');
    
    tabOptions.className = "LTModuleEditTAB";
    //tabExtras.className = "LTModuleEditTABHover";
    
    tabOptions.setAttribute('selected','false');
    //tabExtras.setAttribute('selected','true');
    
    tabOptions = null;
}

function MMFToggleIntroText(introTextContainerID)
{
    var introText = document.getElementById(introTextContainerID);
    
    if(introText.style.display == 'none')
    {
        introText.style.display = 'block';
    }
    else
    {
        introText.style.display = 'none';
    }
    
    introText = null;
}

function MMFShowToolTip(toolTipContainerID, questionIconID)
{
    var toolTip = document.getElementById(toolTipContainerID);
    var question = document.getElementById(questionIconID);
    
    var x = GetX(question);
    var y = GetY(question);
    x = x + 20;
    
    toolTip.style.display = 'block';
    
    toolTip.style.top = y + "px";
    toolTip.style.left = x + "px";
    
    toolTip = null;
    question = null;
    x = null;
    y = null;
}

function MMFHideToolTip(toolTipContainer)
{
    var toolTip = document.getElementById(toolTipContainer);
    toolTip.style.display = 'none';
    toolTip = null;
}


//-----------------------------------------------------------------------------------------------------------------------------






