﻿
// ===========================================================================


// --------------------------------------------
//  Class which is a version of the enum variable
//  in the c#-code for the different types
//  of objects.
// --------------------------------------------
var PageType = Class.create({ 
    initialize: function() { 
        this.Home = 0;
        this.ProjectInbox = 1; 
        this.Tasks = 2; 
    }
});

var PageTypeEnum = new PageType();

var CurrentPageType = PageTypeEnum.Home;  //this is the default value


// --------------------------------------------
//  Class which is a version of the enum variable
//  in the c#-code for the different types
//  of objects.
// --------------------------------------------
var ObjectType = Class.create({ 
    initialize: function() { 
        this.None = 0;
        this.Project = 1; 
        this.Company = 2; 
        this.Contact = 3; 
        this.Investment = 4;
        this.Inside = 5 ;
        this.Labels = 6;
        this.YourMarket = 7;
    }
});

var ObjectTypeEnum = new ObjectType();


// --------------------------------------------
//  "Enumeration" of the types that are called 
//  to the click event on the folder name.
// --------------------------------------------
var FolderType = Class.create({ 
    initialize: function() { 
        this.None = 0;
        this.Show = 1;
        this.AddCurrent = 2; 
        this.AddSelected = 3; 
        this.MoveCurrent = 4; 
        this.MoveSelected = 5;
        this.RemoveCurrent = 6;
        this.RemoveSelected = 7;
    }
});

var FolderTypeEnum = new FolderType();


// --------------------------------------------
//  Class which is a version of the enum variable
//  in the c#-code for the different types
//  of options for displaying tasks
// --------------------------------------------
var TaskShowOptions = Class.create({ 
    initialize: function() { 
        this.All = 1;
        this.Done = 2; 
        this.Delayed = 3; 
        this.Upcoming = 4;
        this.Today = 5;
        this.ClosingDateThisMonth = 6;
        this.ClosingDatePastMonth = 7;
        this.ClosingDateNextMonth = 8;
        this.Filter = 9;
    }
});

var TaskShowOptionsEnum = new TaskShowOptions();


// --------------------------------------------
//  "Enumeration" for the different types
//  of search options
// --------------------------------------------
var SearchOptions = Class.create({ 
    initialize: function() { 
        this.None = '';
        
        // group types...
        this.Geography = 'geography';
        this.ARegion = 'a_region';
        this.Role = 'role'; 
        this.Tender = 'tender'; 
        this.Material = 'material';
        this.Category = 'category';
        this.DevType = 'dev_type';
        this.SiteTitle = 'site_title';
        this.ContractType = 'contract_type';
        // single value types...
        this.FreeText = 'freetext';
        this.DynamicStartDate = 'igs_dynamic';
        this.ProjectDynamicStartDate = 'project_dynamic_igs';
        this.ProjectValue = 'project_value';
        
        this.Apartments = 'apartments';
        this.GrossFloorArea = 'gross_floor_area';
        this.Floor = 'floor';
        this.ProjectPostcode = 'project_postcode';
        this.CompanyPostcode = 'company_postcode';
        this.StartDate = 'igs';
        this.EndDate = 'end_date';
        this.Email = 'contact_e_mail';
         this.Founded = 'founded';
        this.Notes = 'own_notes';
        this.Tasks = 'tasks';
         this.Attribute = 'attribute';
        this.ProjectId = 'project_id_group';
        this.CompanyId = 'company_id_group';
        this.ContactId = 'contact_id_group';
        
        this.Favorites = 'favorites';
        this.SharedFolders = 'shared_folders';
        
        this.Class = 'company_class';  //only used on the norwegian "version" of the faktanetlive.
        this.Stage = 'stage';  // -- " --
        this.PlanningStage = 'planning_stage';  //only for the dannish version.

        this.Deleted = 'deleted';
        this.DeliveryDate = 'delivery_date_group';
         this.YAxisValue = 'y_axis_value';//YourMarket
         this.XAxisValue = 'x_axis_value';//YourMarket
         this.YMHeadline = 'ym_headline';//YourMarket
        
    }
});

var SearchOptionsEnum = new SearchOptions();



// --------------------------------------------
//  "Enumeration" for the different types
//  of icons that will be displayed in the hitlist.
// --------------------------------------------
var IconTypes = Class.create({ 
    initialize: function() { 
        this.Delete = 'delete';
        this.Favorite = 'favorite';
        this.ExportWebService = 'exportwebservice';
        this.SharedFolders = 'shared_folders';
        this.Coverage = 'coverage';
        this.Tasks = 'tasks';
        this.Notes = 'notes';
        this.Responsible = 'responsible';
    }
});

var IconTypeEnum = new IconTypes();


// ===========================================================================
//  This function generates a "unique value" - which can be used when ajaxpages 
//  are requested so the browers don't use cached files...
function GenerateUniqueValue()
{
    //can be used when a page are requested throw ajax so the browser isn't using a cached page.
    return (new Date()).getTime();
}


// ===========================================================================
//  This function is for changing the size of the hitlist and are mostly called
//  when the user changes the size of the browser window.

function ResizePanels()
{
    //calculates the height of the main content panels which is placed underneath the top menu.
    var newHeight = document.viewport.getHeight() - $('centerContent').offsetTop - 70;
    
    if (!newHeight || newHeight < 240)
        newHeight = 240; //min height of the panels.
        
    
    if ($('hitlistContainer'))
    {
        if ($('hitlistContainer').getWidth() <= 280 && document.viewport.getWidth() >= 1100)
            $('hitlistContainer').setStyle({width: '370px'});
            
        else if ($('hitlistContainer').getWidth() > 280 && document.viewport.getWidth() < 1100)
            $('hitlistContainer').setStyle({width: '280px'});
        
        //calculates the height of the innerpanel of the hitlist.
        var hitlistHeight = newHeight - 25;

        if ($('hitlistPageNavigationPanel'))
            hitlistHeight -= 10;
        
        if ($('hitlistPanel'))
            $('hitlistPanel').setStyle({height: hitlistHeight + 'px'});
    }
    
    if ($('dashboardContentPanel'))
        $('dashboardContentPanel').setStyle({height: newHeight + 'px'});
    
    if ($('projectCardPanel'))
    {
        $('projectCardPanel').setStyle({height: newHeight + 'px'});
        $('companyCardPanel').setStyle({height: newHeight + 'px'});
        $('contactCardPanel').setStyle({height: newHeight + 'px'});
    }
    
    if ($('taskListPanel'))
    {
        $('taskListPanel').setStyle({height: (newHeight-30) + 'px'});
        $('hitlistPanel').setStyle({height: newHeight + 'px'});
    }
        
    if ($('projectInboxListPanel'))
        $('projectInboxListPanel').setStyle({height: newHeight + 'px'});  
        
    if ($('documentShadowBackground') && $('documentShadowBackground').visible())
        ShowShadowBackground();

    if ($('topStatusBar') && $('topStatusBar').visible())
        $('topStatusBar').setStyle({'width' : document.viewport.getWidth() + "px"});
}



// ===========================================================================
//

function OnMouseMenuEvent(menuTextId, menuItemId, eventOption, e)
{
    try 
    {
        if (eventOption == 'over')
        {   
            if ($(menuTextId))
                $(menuTextId).addClassName('rootMenuItemOver');
                
            $(menuItemId).show();
        }
        else
        {
            var element = Event.element(e);
            
            if (element.tagName != 'SELECT')  //IE-fix
            {
                if ($(menuTextId))
                    $(menuTextId).removeClassName('rootMenuItemOver');
            
                $(menuItemId).hide();
            }
        }
    }
    catch (err)
    {
        new Ajax.Request('ajaxpages/Error.aspx', { 
            method: 'post',
            parameters: { unique: GenerateUniqueValue(), errorStatus: '0', errorStatusText: err.description, errorText: 'OnMouseMenuEvent() - ' + err, profileId: CurrentUserProfileId }
        });
    }        
}



var timeout	= 500;
var tbclosetimer = 0;
var tbddmenuitem = 0;
var tbddmenutextitem = 0;

function OnMouseToolbarMenuEvent(toolbarButton)
{
    var isSameElement = false;
    
	// cancel close timer
	tbMenuCancelCloseTime();

	// close old layer
	if(tbddmenuitem) 
	{
	    if (!tbddmenuitem.visible() || tbddmenuitem.id != 'toolbarMenu_' + toolbarButton)
	    {
    	    tbddmenuitem.hide();
            tbddmenutextitem.removeClassName('rootMenuItemOver');
            
            RemoveSelectionOnMenuItem(tbddmenuitem);
        }
        else
        {
            tbddmenuitem.setStyle({left:'0px'});
            isSameElement = true;
        }
    }
    else if (tbddmenutextitem) 
        tbddmenutextitem.removeClassName('rootMenuItemOver');


    if (toolbarButton == 'Favorites' && !isSameElement)
    {
        if (selectedTabObjectType == ObjectTypeEnum.None
            || (selectedTabObjectType == ObjectTypeEnum.Project && lastLoadedProjectId < 0)
            || (selectedTabObjectType == ObjectTypeEnum.Company && lastLoadedCompanyId < 0)
            || (selectedTabObjectType == ObjectTypeEnum.Contact && lastLoadedContactId < 0))
        {
            $('toolbarMenu_AddCurrentFavorites').writeAttribute('enabled', 'false');
            $('toolbarMenu_AddCurrentFavorites').childElements().each(function (element) 
                { 
                    if (element.nodeName == "A") 
                        element.addClassName('inactiveMenuItem'); 
                        
                    if (CurrentObjectTypeInHitList == ObjectTypeEnum.Company)
                        element.update(resource.lblAddCurrentCompanyToFavorites);
                    else if (CurrentObjectTypeInHitList == ObjectTypeEnum.Contact)
                        element.update(resource.lblAddCurrentContactToFavorites);
                    else 
                        element.update(resource.lblAddCurrentProjectToFavorites);
                });
                
            $('toolbarMenu_MoveCurrentFavorites').writeAttribute('enabled', 'false');
            $('toolbarMenu_MoveCurrentFavorites').childElements().each(function (element) 
                { 
                    if (element.nodeName == "A") 
                        element.addClassName('inactiveMenuItem'); 
                        
                    if (CurrentObjectTypeInHitList == ObjectTypeEnum.Company)
                        element.update(resource.lblMoveCurrentCompany);
                    else if (CurrentObjectTypeInHitList == ObjectTypeEnum.Contact)
                        element.update(resource.lblMoveCurrentContact);
                    else 
                        element.update(resource.lblMoveCurrentFavoriteProject);
                });

                
            $('toolbarMenu_RemoveCurrentFavorites').writeAttribute('enabled', 'false');
            $('toolbarMenu_RemoveCurrentFavorites').childElements().each(function (element) 
                { 
                    if (element.nodeName == "A") 
                        element.addClassName('inactiveMenuItem'); 
                        
                    if (CurrentObjectTypeInHitList == ObjectTypeEnum.Company)
                        element.update(resource.lblDeleteCurrentCompanyFromFavorites);
                    else if (CurrentObjectTypeInHitList == ObjectTypeEnum.Contact)
                        element.update(resource.lblDeleteCurrentContactFromFavorites);
                    else 
                        element.update(resource.lblDeleteCurrentProjectFromFavorites);
                });
        }
        else
        {
            $('toolbarMenu_AddCurrentFavorites').writeAttribute('enabled', 'true');
            $('toolbarMenu_AddCurrentFavorites').childElements().each(function (element) 
                { 
                    if (element.nodeName == "A") 
                        element.removeClassName('inactiveMenuItem'); 
                        
                    if (selectedTabObjectType == ObjectTypeEnum.Company)
                        element.update(resource.lblAddCurrentCompanyToFavorites);
                    else if (selectedTabObjectType == ObjectTypeEnum.Contact)
                        element.update(resource.lblAddCurrentContactToFavorites);
                    else 
                        element.update(resource.lblAddCurrentProjectToFavorites);
                });

            $('toolbarMenu_MoveCurrentFavorites').writeAttribute('enabled', 'true');
            $('toolbarMenu_MoveCurrentFavorites').childElements().each(function (element) 
                { 
                    if (element.nodeName == "A") 
                        element.removeClassName('inactiveMenuItem'); 
                        
                    if (selectedTabObjectType == ObjectTypeEnum.Company)
                        element.update(resource.lblMoveCurrentCompany);
                    else if (selectedTabObjectType == ObjectTypeEnum.Contact)
                        element.update(resource.lblMoveCurrentContact);
                    else 
                        element.update(resource.lblMoveCurrentFavoriteProject);
                });

            $('toolbarMenu_RemoveCurrentFavorites').writeAttribute('enabled', 'true');
            $('toolbarMenu_RemoveCurrentFavorites').childElements().each(function (element) 
                { 
                    if (element.nodeName == "A") 
                        element.removeClassName('inactiveMenuItem'); 
                        
                    if (selectedTabObjectType == ObjectTypeEnum.Company)
                        element.update(resource.lblDeleteCurrentCompanyFromFavorites);
                    else if (selectedTabObjectType == ObjectTypeEnum.Contact)
                        element.update(resource.lblDeleteCurrentContactFromFavorites);
                    else 
                        element.update(resource.lblDeleteCurrentProjectFromFavorites);
                });
        }
        
        if (CurrentObjectTypeInHitList == ObjectTypeEnum.None)
        {
            $('toolbarMenu_AddSelectedFavorites').writeAttribute('enabled', 'false');
            $('toolbarMenu_AddSelectedFavorites').childElements().each(function (element) 
                { 
                    if (element.nodeName == "A") 
                        element.addClassName('inactiveMenuItem'); 

                    element.update(resource.lblAddSelectedProjectToFavorites);
                });

            $('toolbarMenu_MoveSelectedFavorites').writeAttribute('enabled', 'false');
            $('toolbarMenu_MoveSelectedFavorites').childElements().each(function (element) 
                { 
                    if (element.nodeName == "A") 
                        element.addClassName('inactiveMenuItem'); 

                    element.update(resource.lblMoveSelectedFavoriteProjects);
                });

            $('toolbarMenu_RemoveSelectedFavorites').writeAttribute('enabled', 'false');
            $('toolbarMenu_RemoveSelectedFavorites').childElements().each(function (element) 
                { 
                    if (element.nodeName == "A") 
                        element.addClassName('inactiveMenuItem'); 

                    element.update(resource.lblDeleteSelectedProjectFromFavorites);
                });
        }
        else 
        {
            $('toolbarMenu_AddSelectedFavorites').writeAttribute('enabled', 'true');
            $('toolbarMenu_AddSelectedFavorites').childElements().each(function (element) 
                { 
                    if (element.nodeName == "A") 
                        element.removeClassName('inactiveMenuItem'); 
                        
                    if (CurrentObjectTypeInHitList == ObjectTypeEnum.Company)
                        element.update(resource.lblAddSelectedCompanyToFavorites);
                    else if (CurrentObjectTypeInHitList == ObjectTypeEnum.Contact)
                        element.update(resource.lblAddSelectedContactToFavorites);
                    else 
                        element.update(resource.lblAddSelectedProjectToFavorites);
                });

            $('toolbarMenu_MoveSelectedFavorites').writeAttribute('enabled', 'true');
            $('toolbarMenu_MoveSelectedFavorites').childElements().each(function (element) 
                { 
                    if (element.nodeName == "A") 
                        element.removeClassName('inactiveMenuItem'); 
                        
                    if (CurrentObjectTypeInHitList == ObjectTypeEnum.Company)
                        element.update(resource.lblMoveSelectedCompany);
                    else if (CurrentObjectTypeInHitList == ObjectTypeEnum.Contact)
                        element.update(resource.lblMoveSelectedContact);
                    else 
                        element.update(resource.lblMoveSelectedFavoriteProjects);
                });

            $('toolbarMenu_RemoveSelectedFavorites').writeAttribute('enabled', 'true');
            $('toolbarMenu_RemoveSelectedFavorites').childElements().each(function (element) 
                { 
                    if (element.nodeName == "A") 
                        element.removeClassName('inactiveMenuItem'); 
                        
                    if (CurrentObjectTypeInHitList == ObjectTypeEnum.Company)
                        element.update(resource.lblDeleteSelectedCompanyFromFavorites);
                    else if (CurrentObjectTypeInHitList == ObjectTypeEnum.Contact)
                        element.update(resource.lblDeleteSelectedContactFromFavorites);
                    else 
                        element.update(resource.lblDeleteSelectedProjectFromFavorites);
                });
        }
    }
    else if (toolbarButton == 'Delete' && !isSameElement)
    {
        if (selectedTabObjectType != ObjectTypeEnum.Project)
        {
            $('toolbarMenu_DeleteCurrentProject').writeAttribute('enabled', 'false').addClassName('inactiveMenuItem');
            $('toolbarMenu_UndeleteCurrentProject').writeAttribute('enabled', 'false').addClassName('inactiveMenuItem');
        }
        else 
        {
            $('toolbarMenu_DeleteCurrentProject').writeAttribute('enabled', 'true').removeClassName('inactiveMenuItem');
            $('toolbarMenu_UndeleteCurrentProject').writeAttribute('enabled', 'true').removeClassName('inactiveMenuItem');
        }

        if (CurrentObjectTypeInHitList != ObjectTypeEnum.Project)
        {
            $('toolbarMenu_DeleteSelectedProjects').writeAttribute('enabled', 'false').addClassName('inactiveMenuItem');
            $('toolbarMenu_UndeleteSelectedProjects').writeAttribute('enabled', 'false').addClassName('inactiveMenuItem');
        }
        else 
        {
            $('toolbarMenu_DeleteSelectedProjects').writeAttribute('enabled', 'true').removeClassName('inactiveMenuItem');
            $('toolbarMenu_UndeleteSelectedProjects').writeAttribute('enabled', 'true').removeClassName('inactiveMenuItem');
        }
    }
    
        else if (toolbarButton == 'Addons' && !isSameElement)
    {
        if (selectedTabObjectType != ObjectTypeEnum.Project)
        {
            $('toolbarMenu_AddCurrentShared').writeAttribute('enabled', 'false').addClassName('inactiveMenuItem');
            $('toolbarMenu_RemoveCurrentShared').writeAttribute('enabled', 'false').addClassName('inactiveMenuItem');
            $('toolbarMenu_MoveCurrentShared').writeAttribute('enabled', 'false').addClassName('inactiveMenuItem');

            
        }
        else 
        {
            $('toolbarMenu_AddCurrentShared').writeAttribute('enabled', 'true').removeClassName('inactiveMenuItem');
            $('toolbarMenu_RemoveCurrentShared').writeAttribute('enabled', 'true').removeClassName('inactiveMenuItem');
            $('toolbarMenu_MoveCurrentShared').writeAttribute('enabled', 'true').removeClassName('inactiveMenuItem');

        }

        if (CurrentObjectTypeInHitList != ObjectTypeEnum.Project)
        {
            $('toolbarMenu_AddSelectedShared').writeAttribute('enabled', 'false').addClassName('inactiveMenuItem');
            $('toolbarMenu_RemoveSelectedShared').writeAttribute('enabled', 'false').addClassName('inactiveMenuItem');
            $('toolbarMenu_MoveSelectedShared').writeAttribute('enabled', 'false').addClassName('inactiveMenuItem');

        }
        else 
        {
            $('toolbarMenu_AddSelectedShared').writeAttribute('enabled', 'true').removeClassName('inactiveMenuItem');
            $('toolbarMenu_RemoveSelectedShared').writeAttribute('enabled', 'true').removeClassName('inactiveMenuItem');
            $('toolbarMenu_MoveSelectedShared').writeAttribute('enabled', 'true').removeClassName('inactiveMenuItem');

        }
    }
    
    
    else if (toolbarButton == 'Print' && !isSameElement)
    {
        loadToolBarPrintList();
    }
    

    if (!isSameElement)
    {
        tbddmenutextitem = $('toolbarMenuText_' + toolbarButton);
        tbddmenutextitem.addClassName('rootMenuItemOver');

	    // get new layer and show it
	    tbddmenuitem = $('toolbarMenu_' + toolbarButton);
	    
	    if (tbddmenuitem)
    	    tbddmenuitem.show();
    }
    
	if (tbddmenuitem)
        submenuleftposition = tbddmenuitem.getWidth() - 20;
}


// close showed layer
function tbMenuClose()
{
    if(tbddmenuitem) 
    {
        tbddmenuitem.hide();
        
        RemoveSelectionOnMenuItem(tbddmenuitem);
    }
    
    if (tbddmenutextitem)
        tbddmenutextitem.removeClassName('rootMenuItemOver');


    tbSubMenuClose();
}

// go close timer
function tbMenuCloseTime(e)
{
    if (e)
    {
        var element = Event.element(e); 

        if (element.tagName != 'SELECT')  //IE-fix
    	    tbclosetimer = window.setTimeout(tbMenuClose, timeout);
    }
    else 
	    tbclosetimer = window.setTimeout(tbMenuClose, timeout);

}

// cancel close timer
function tbMenuCancelCloseTime()
{
	if(tbclosetimer)
	{
		window.clearTimeout(tbclosetimer);
		tbclosetimer = null;
	}
}

//===============================================================================================


var quickcardclosetimer = 0;
var quickcardddmenuitem = 0;
var quickcardddmenutextitem = 0;

function OnMouseQuickCardMenuEvent(toolbarButton)
{
	// cancel close timer
	quickCardMenuCancelCloseTime();

	// close old layer
	if(quickcardddmenuitem) 
	{
	    quickcardddmenuitem.hide();
        quickcardddmenutextitem.removeClassName('rootMenuItemOver');
    }

    if (toolbarButton == 'Favorites')
    {
        if (selectedTabObjectType == ObjectTypeEnum.None
            || (selectedTabObjectType == ObjectTypeEnum.Project && lastLoadedProjectId < 0)
            || (selectedTabObjectType == ObjectTypeEnum.Company && lastLoadedCompanyId < 0)
            || (selectedTabObjectType == ObjectTypeEnum.Contact && lastLoadedContactId < 0))
        {
            $('quickCardMenu_AddCurrentFavorites').writeAttribute('enabled', 'false');
            $('quickCardMenu_AddCurrentFavorites').addClassName('inactiveMenuItem'); 
                
            $('quickCardMenu_MoveCurrentFavorites').writeAttribute('enabled', 'false');
            $('quickCardMenu_MoveCurrentFavorites').addClassName('inactiveMenuItem'); 
                
            $('quickCardMenu_RemoveCurrentFavorites').writeAttribute('enabled', 'false');
            $('quickCardMenu_RemoveCurrentFavorites').addClassName('inactiveMenuItem'); 
        }
        else
        {
            $('quickCardMenu_AddCurrentFavorites').writeAttribute('enabled', 'true');
            $('quickCardMenu_AddCurrentFavorites').removeClassName('inactiveMenuItem'); 
                
            $('quickCardMenu_MoveCurrentFavorites').writeAttribute('enabled', 'true');
            $('quickCardMenu_MoveCurrentFavorites').removeClassName('inactiveMenuItem'); 
                
            $('quickCardMenu_RemoveCurrentFavorites').writeAttribute('enabled', 'true');
            $('quickCardMenu_RemoveCurrentFavorites').removeClassName('inactiveMenuItem'); 
        }

    }

    quickcardddmenutextitem = $('quickCardMenuText_' + toolbarButton);
    quickcardddmenutextitem.addClassName('rootMenuItemOver');

	// get new layer and show it
	quickcardddmenuitem = $('quickCardMenu_' + toolbarButton);
	quickcardddmenuitem.show();

    submenuleftposition = quickcardddmenuitem.getWidth() - 20;
}


// close showed layer
function quickCardMenuClose()
{
	if(quickcardddmenuitem) 
	{
	    quickcardddmenuitem.hide();
        quickcardddmenutextitem.removeClassName('rootMenuItemOver');
	}
}

// go close timer
function quickCardMenuCloseTime()
{
	quickcardclosetimer = window.setTimeout(quickCardMenuClose, timeout);
}

// cancel close timer
function quickCardMenuCancelCloseTime()
{
	if(quickcardclosetimer)
	{
		window.clearTimeout(quickcardclosetimer);
		quickcardclosetimer = null;
	}
}


//==================================================================================================



var submenuclosetimer = 0;
var ddsubmenuitem = 0;
var submenuleftposition = 0;

// open hidden layer
function tbSubMenuOpen(id, submenuPrefixName, favoriteTreeType, parentElement)
{	
	// cancel close timer
	tbSubMenuCancelCloseTime();

    if (favoriteTreeType != FolderTypeEnum.None)
    {
        if ((favoriteTreeType == FolderTypeEnum.AddCurrent && $(submenuPrefixName + '_AddCurrentFavorites').readAttribute('enabled') == 'false')
            || (favoriteTreeType == FolderTypeEnum.AddSelected && $(submenuPrefixName + '_AddSelectedFavorites').readAttribute('enabled') == 'false')
            || (favoriteTreeType == FolderTypeEnum.MoveCurrent && $(submenuPrefixName + '_MoveCurrentFavorites').readAttribute('enabled') == 'false')
            || (favoriteTreeType == FolderTypeEnum.MoveSelected && $(submenuPrefixName + '_MoveSelectedFavorites').readAttribute('enabled') == 'false'))
        {
            tbSubMenuClose();
            return;
        }
            
        SetFolderClickType(favoriteTreeType);

        favoriteTreeWriter.generateTree(id, submenuPrefixName, currentFolderType, '', false);
    }

	// close old layer
	if(ddsubmenuitem) 
	    ddsubmenuitem.hide();

	// get new layer and show it
	ddsubmenuitem = $(id);

    if (parentElement != null && parentElement != '')
    {
        var arr = $$('#toolbarMenu_Addons div.menuDiv');
        var y = 45;
        
        for ( i=0; i < arr.length; i++)
        {
            if (arr[i].readAttribute('submenu') == id)
                break;

            y += 24;
        }
        
	    ddsubmenuitem.setStyle({'top' : y + 'px'}); 
    }
    
    ddsubmenuitem.setStyle({'left' : submenuleftposition + 'px'});

    var objectTypeToCheck = 0;

    if (favoriteTreeType == FolderTypeEnum.None)
        objectTypeToCheck = 0;
        
    else if (favoriteTreeType == FolderTypeEnum.AddCurrent || favoriteTreeType == FolderTypeEnum.MoveCurrent)
        objectTypeToCheck = selectedTabObjectType;
        
    else if (favoriteTreeType == FolderTypeEnum.AddSelected || favoriteTreeType == FolderTypeEnum.MoveSelected)
        objectTypeToCheck = CurrentObjectTypeInHitList;

    ddsubmenuitem.select('div[objecttype]').each(function(element)
        {
            if (objectTypeToCheck != 0 && element.readAttribute('objecttype') != objectTypeToCheck)
                element.hide();
            else 
                element.show();
        });

	ddsubmenuitem.show();

    subsubmenuleftposition = ddsubmenuitem.getWidth() - 20;
}

// close showed layer
function tbSubMenuClose()
{
	if(ddsubmenuitem) 
	{
	    ddsubmenuitem.hide();
	    favoriteTreeWriter.clearUnderline();
	}
}

// go close timer
function tbSubMenuCloseTime()
{
	submenuclosetimer = window.setTimeout(tbSubMenuClose, timeout);
}

// cancel close timer
function tbSubMenuCancelCloseTime()
{
	if(submenuclosetimer)
	{
		window.clearTimeout(submenuclosetimer);
		submenuclosetimer = null;
	}
}



//==================================================================================================


var subsubmenuclosetimer = 0;
var ddsubsubmenuitem = 0;
var subsubmenuleftposition = 0;

// open hidden layer
function tbSubSubMenuOpen(id, folderTypeEnumValue)
{	
	// cancel close timer
	tbSubSubMenuCancelCloseTime();


    if (folderTypeEnumValue != FolderTypeEnum.None)
    {
        if ((folderTypeEnumValue == FolderTypeEnum.AddCurrent && $('toolbarMenu_AddCurrentShared').readAttribute('enabled') == 'false')
            || (folderTypeEnumValue == FolderTypeEnum.AddSelected && $('toolbarMenu_AddSelectedShared').readAttribute('enabled') == 'false')
            || (folderTypeEnumValue == FolderTypeEnum.MoveCurrent && $('toolbarMenu_MoveCurrentShared').readAttribute('enabled') == 'false')
            || (folderTypeEnumValue == FolderTypeEnum.MoveSelected && $('toolbarMenu_MoveSelectedShared').readAttribute('enabled') == 'false'))
        {
            tbSubSubMenuClose();
            return;
        }
        
        SetSharedFolderType(folderTypeEnumValue);
        
        mySharedFolder.generateTree(id, "toolbarMenu", folderTypeEnumValue, '', false, 
            { 
                onLoadComplete: function(menuelement, menuItemOffset) {

                    if (document.viewport.getWidth() < 1100) //move this sub menu to the leftside of the parent menu
                        menuelement.setStyle({'left' : ( menuItemOffset - menuelement.getWidth() + 20) + 'px'});
                },
                menuItemOffset: submenuleftposition
            });
    }

	// close old layer
	if(ddsubsubmenuitem) 
	    ddsubsubmenuitem.hide();

	// get new layer and show it
	ddsubsubmenuitem = $(id);

    var topValue = 60;
    
    if (folderTypeEnumValue == FolderTypeEnum.AddCurrent)
        topValue = 90;
    else if (folderTypeEnumValue == FolderTypeEnum.AddSelected)
        topValue = 115;
    else if (folderTypeEnumValue == FolderTypeEnum.MoveCurrent)
        topValue = 190;
    else if (folderTypeEnumValue == FolderTypeEnum.MoveSelected)
        topValue = 215;
        
    ddsubsubmenuitem.setStyle({'top' : topValue + 'px', 'left' : (submenuleftposition + ddsubmenuitem.getWidth() - 20) + 'px'});
    
    if (document.viewport.getWidth() < 1100) //move this sub menu to the leftside of the parent menu
        ddsubsubmenuitem.setStyle({'left' : (submenuleftposition - ddsubsubmenuitem.getWidth() + 20) + 'px'});
        

/*
    var objectTypeToCheck = 0;

    if (favoriteTreeType == FolderTypeEnum.None)
        objectTypeToCheck = 0;
        
    else if (favoriteTreeType == FolderTypeEnum.AddCurrent || favoriteTreeType == FolderTypeEnum.MoveCurrent)
        objectTypeToCheck = selectedTabObjectType;
        
    else if (favoriteTreeType == FolderTypeEnum.AddSelected || favoriteTreeType == FolderTypeEnum.MoveSelected)
        objectTypeToCheck = CurrentObjectTypeInHitList;

    ddsubsubmenuitem.select('div[objecttype]').each(function(element)
        {
            if (objectTypeToCheck != 0 && element.readAttribute('objecttype') != objectTypeToCheck)
                element.hide();
            else 
                element.show();
        });
*/
	ddsubsubmenuitem.show();
}

// close showed layer
function tbSubSubMenuClose()
{
	if(ddsubsubmenuitem) 
	{
	    ddsubsubmenuitem.hide();
	    //favoriteTreeWriter.clearUnderline();
	}
}


// go close timer
function tbSubSubMenuCloseTime()
{
	subsubmenuclosetimer = window.setTimeout(tbSubSubMenuClose, timeout);
}

// cancel close timer
function tbSubSubMenuCancelCloseTime()
{
	if(subsubmenuclosetimer)
	{
		window.clearTimeout(subsubmenuclosetimer);
		subsubmenuclosetimer = null;
	}
    
    tbSubMenuCancelCloseTime();
}

// close layer when click-out
//document.onclick = mclose; 



function AddSelectionToMenuItem(element)
{
    if ($(element).nodeName=='DIV')
    {
        RemoveSelectionOnMenuItem(element);
        $(element).addClassName('selectedMenuItem');
    }
}

function RemoveSelectionOnMenuItem(element)
{
    $(element).up(0).select('div.selectedMenuItem').each(function(el) { el.removeClassName('selectedMenuItem'); });
}


// ----------------------------------------------------------------
//  Writes the text that the info about the object are loading...
// ----------------------------------------------------------------
function WriteLoadingInfo(panelId, message)
{
    if (!message || message.empty())
        message = resource.lblLoadInformationMessage;
        
    var text = '<div style="padding:20px 10px;" class="font10 bold centertext"><img src="images/ajax-loader.gif" />'
    text += '<br /><br />'+message+'</div>';
    
    $(panelId).update(text);
}


// ----------------------------------------------------------------
//  Writes the text that the info about the object are loading...
// ----------------------------------------------------------------
function WriteLoadingImage(panelId)
{
    var text = '<div class="centertext"><br /><img src="images/ajax-loader.gif" /></div>';
    
    $(panelId).update(text);
}


function ResizeVerticalLinesOnObjectCard(objectTypeName)
{
    var maxHeight = 0;
    var parentNode = $(objectTypeName + 'CardPanel');
    var leftColumn = $(objectTypeName + '_leftColumn');
    var centerColumn = $(objectTypeName + '_centerColumn');
    
    //scrolls the div to the top...
    parentNode.scrollTop = 0;
    

    //gets the highest height of the columns that contains information
    if (leftColumn.getHeight() > maxHeight)
        maxHeight = leftColumn.getHeight();

    if (centerColumn.getHeight() > maxHeight)
        maxHeight = centerColumn.getHeight();
    
    
    //finds all the vertical lines on the current object card
    var nodes = parentNode.select('div.grayVerticalLine');
    
    //sets the max height that was found from the columns to the gray vertical lines.
    for (var i = 0; i < nodes.length; i++)
        nodes[i].setStyle({'height': maxHeight + 'px'});
}


function ShowShadowBackground()
{
    var shadowMainDiv = $('documentShadowBackground');
    var shadowSubDiv = $('documentBackground');

    var arrayPageSize = getPageSize();
    
    shadowMainDiv.setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
    
    if ($('documentBackground'))
        shadowSubDiv.setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
    
    shadowMainDiv.show();
    
    if ($('documentBackground') && !shadowSubDiv.visible())
       new Effect.Appear(shadowSubDiv, { duration: 0.2, from: 0.0, to: 0.4 });
}

function HideShadowBackground()
{
    if ($('documentShadowBackground'))
        $('documentShadowBackground').hide();
    
    if ($('documentBackground'))
        $('documentBackground').hide(); 
}


function ResizeShadowBackground()
{
    var arrayPageSize = getPageSize();

    if ($('documentShadowBackground').visible())
        $('documentShadowBackground').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
    
    if ($('documentBackground').visible())
        $('documentBackground').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
}


// parentElementId - use null if you want it to be centered on the page.
function CenterPanel(elementId, parentElementId, showElement)
{
    var element = $(elementId);
    
    var topPosition = 0;
    var leftPosition = 0;
    
    try {
        // calculate top position
        topPosition = document.viewport.getHeight() / 2 - element.getHeight() / 2;

        // calculate left position
        leftPosition = document.viewport.getWidth() / 2 - element.getWidth() / 2;
    }
    catch (exception)
    { }

    
    if (parentElementId)
    {
        topPosition = $(parentElementId).getHeight() / 2 - element.getHeight() / 2;
        leftPosition = $(parentElementId).getWidth() / 2 - element.getWidth() / 2;
    }

    
    if (topPosition < 0)
        topPosition = 0;

    if (leftPosition < 0)
        leftPosition = 0;

    element.setStyle({ top: topPosition + 'px', left: leftPosition + 'px' });
    
    if (showElement)
        element.show();
}


function getDocHeight() {
    var D = document;
    return Math.max(
        Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
        Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
        Math.max(D.body.clientHeight, D.documentElement.clientHeight)
    );
}

// gets the size of the whole page...
function getPageSize()
{
     var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}

	return [pageWidth,getDocHeight()];//pageHeight];
}



//this function will return the date in the ISO format yyyy-mm-dd
function FormatDate(date)
{
    return "" + date.getFullYear() + "-" + DateFormatAddZero((date.getMonth() + 1)) + "-" + DateFormatAddZero(date.getDate());
}


//This function will add an extra zero infront of the number if it's <10
function DateFormatAddZero(x) 
{
    return(x<0||x>9?"":"0")+x
}


// ----------------------------------------------------------------
//  This will set the option in the dropdown list that matches the 
//  "optionValue" to selected.
// ----------------------------------------------------------------
function SelectOptionInDropDownList(element, optionValue)
{
    var optionArray = $(element).options;
    
    for (i = 0; i < optionArray.length; i++) 
    {
        optionArray[i].selected = false;
        
        if (optionArray[i].value == optionValue)
            optionArray[i].selected = true;
    }
}


// ----------------------------------------------------------------
// tries to find the requested parameter and returns the value or 
// an empty string if it wasn't found.
// ----------------------------------------------------------------
function getUrlParameter( parameterKey )
{
  parameterKey = parameterKey.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");

  var regexS = "[\\?&]"+parameterKey+"=([^&#]*)";
  var regex = new RegExp( regexS );

  var results = regex.exec( window.location.href );

  if( results == null )
    return "";
  else
    return results[1];
}


// ----------------------------------------------------------------
// 
// ----------------------------------------------------------------
function CheckTextLength(event, length, allowAllTokens)
{
    var elt = $(Event.element(event)); 
	var key = event.keyCode || event.which;
	
    if ( key == Event.KEY_BACKSPACE || key == Event.KEY_DELETE || key == Event.KEY_LEFT || key == Event.KEY_RIGHT || key == Event.KEY_TAB )
        return true;
        
    else if ($F(elt).length > length-1 && GetSelectedText(elt).length <= 0)  //no more tokens then "length" value AND no text are selected
        return false;
    
    else if (!allowAllTokens && (key >= 48 && key <= 57) || (key >= 96 && key <= 105))  //numeric values
        return true;
        
    else
        return (allowAllTokens ? true : false);
}



// ----------------------------------------------------------------
// ----------------------------------------------------------------
function GetSelectedText(element)
{
    var $selection='';

    if (document.selection){
        // if IE
        $selection=document.selection.createRange().text;
    }
    else if (typeof element.selectionStart != 'undefined'){
        // if Firefox

        $selection = element.value.substring(element.selectionStart, element.selectionEnd);
    }

    element.focus();

    return $selection;
}

