﻿
var isDashboardLoaded = false;
var isDashboardLoading = false;
var selectedTabObjectType = ObjectTypeEnum.None;
var curSuperUserContactId;
var curSuperUserProfileId;


// ----------------------------------------------------------------
//  This function is used by the periodical search for updates
//  on the options on the dashboard - like new and updated projects,
//  project inbox, coverage etc...
// ----------------------------------------------------------------
function PeriodicalDashboardUpdate(responseText)
{
    var options = responseText.evalJSON();
    
    
    // NEW AND UPDATED PROJECTS
    try {
        var tdArray = $('dashboardNewUpdatedProjectList').select('td');
        
        if (options.get('new_projects'))
        {
            if (options.get('new_projects') > 0)
                tdArray[0].update('<a href="javascript:LoadNewProjectsFromDashboard()">' + resource.lblNew + '</a>:&nbsp;');
            else
                tdArray[0].update(resource.lblNew + ':&nbsp;');
                
            tdArray[1].update(options.get('new_projects'));
        }
        
        if (options.get('updated_projects'))
        {
            if (options.get('new_projects') > 0)
                tdArray[2].update('<a href="javascript:LoadUpdatedProjectsFromDashboard()">' + resource.lblUpdated + '</a>:&nbsp;');
            else
                tdArray[2].update(resource.lblUpdated + ':&nbsp;');
                
            tdArray[3].update(options.get('updated_projects'));
        }
    }
    catch (err)
    { }
    
    
    // TASKS
    try {
        var tdArray = $('dashboardTasksList').select('td');
        
        tdArray[1].update(options.get('tasks').delayed);
        tdArray[3].update(options.get('tasks').today);
        tdArray[5].update(options.get('tasks').upcoming);
    }
    catch (err)
    { }
    
    
    
    // INBOX
    try {
        $('projectInboxValue').update(options.get('inbox').unread_messages + ' ' + resource.lblNumOfNewProjectInboxProjects);
    }
    catch (err)
    { }
    
    
    // COVERAGE
    try {
        var tdArray = $('dashboardCoverageList').select('td');
        
        tdArray[1].update(options.get('coverage').project);
        tdArray[3].update(options.get('coverage').company);
        tdArray[5].update(options.get('coverage').contact);
    }
    catch (err)
    { }
    
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function LoadDashboard(addToBrowserHistory)
{
    //Since this page is the dashboard no object type is selected.        
    selectedTabObjectType = ObjectTypeEnum.None;

    $('dashboardContainer').show();
    $('objectCardContainer').hide();
    
    if (isDashboardLoading)
        return;
    
    if (!isDashboardLoaded)
    {
        isDashboardLoading = true;
        
        new Ajax.Updater('dashboardContentPanel', 'ajaxpages/LoadDashboard.aspx', 
            { method: 'get', parameters: { unique: GenerateUniqueValue() }, evalScripts: true,
            onFailure: function(transport) { (new Error()).doErrorResponseCheck('ajaxpages/LoadDashboard.aspx', '', transport); },
            onSuccess: function() 
            {
                if (addToBrowserHistory)
                    AddToHistory("dashboard", "");
            }, 
            onComplete: function() 
            {
                isDashboardLoaded = true;
                isDashboardLoading = false;
            }
        });
    }
    else
    {
        if (addToBrowserHistory)
            AddToHistory("dashboard", "");
    }
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function ShowDeliveryDateOptions()
{
    $('dashboardDeliveryDateOptionsClick').hide();
    $('dashboardDeliveryDateOptions').show();
    
    ChangeDeliveryDateDropDownList();
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function HideDeliveryDateOptions()
{
    if ($('dashboardDeliveryDateOptionsClick'))
        $('dashboardDeliveryDateOptionsClick').show();
        
    if ($('dashboardDeliveryDateOptions'))
        $('dashboardDeliveryDateOptions').hide();
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function ChangeDeliveryDateDropDownList(optionsListId)
{
    var optionSearchString = "";
    
    if (!optionsListId)
        optionSearchString = "#dashboardDeliveryDateOptions input[type=radio][name='dashboardDeliveryDateQuickSelect']";
    else 
        optionSearchString = "#selectDeliveryDateIntervall input[type=radio][name='searchDeliveryDateQuickSelect']";
        
    var selectedQuickOption = $$(optionSearchString);
    var fromDate = new Date();
    var toDate = new Date();
    
    for (var i = 0; i < selectedQuickOption.length; i++)
    {
        if (selectedQuickOption[i].checked)
        {
            if (selectedQuickOption[i].value == 'lastday')
                fromDate = new Date(toDate.getFullYear(), toDate.getMonth(), toDate.getDate());
            else if (selectedQuickOption[i].value == 'lastweek')
                fromDate = new Date(toDate.getFullYear(), toDate.getMonth(), toDate.getDate() - 7);
            else if (selectedQuickOption[i].value == 'lastmonth')
                fromDate = new Date(toDate.getFullYear(), toDate.getMonth() - 1, toDate.getDate());
            else if (selectedQuickOption[i].value == 'lastyear')
                fromDate = new Date(toDate.getFullYear() - 1, toDate.getMonth(), toDate.getDate());
        }
    }

    if (!optionsListId)
    {
        SetDateInDeliveryDropDownList("dashboardFromDeliveryDateYear", "dashboardFromDeliveryDateMonth", "dashboardFromDeliveryDateDay", fromDate);
        SetDateInDeliveryDropDownList("dashboardToDeliveryDateYear", "dashboardToDeliveryDateMonth", "dashboardToDeliveryDateDay", toDate);
    }
    else
    {
        SetDateInDeliveryDropDownList("searchFromDeliveryDateYear", "searchFromDeliveryDateMonth", "searchFromDeliveryDateDay", fromDate);
        SetDateInDeliveryDropDownList("searchToDeliveryDateYear", "searchToDeliveryDateMonth", "searchToDeliveryDateDay", toDate);
    }
    
    UnsetLoginDateDropDownList(optionsListId);
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function UnsetLoginDateDropDownList(optionList)
{
    if (!optionList)
    {
      if ($('dashboardProfileLoginDateList'))
        SelectOptionInDropDownList("dashboardProfileLoginDateList","-");
    }
    else
    {
      if ($('searchProfileLoginDateList'))
        SelectOptionInDropDownList("searchProfileLoginDateList","-");
    }
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function ChangeLoginDateDropDownList(optionList)
{
    var loginDate = "";
    
    if (!optionList)
        loginDate = $F("dashboardProfileLoginDateList");
    else
        loginDate = $F("searchProfileLoginDateList")
    
    //splits the string so we gets the year and month value in an array.
    var valueArray = loginDate.split(":");
    var fromArray = valueArray[0].split("-");
    var toArray = valueArray[1].split("-");
      
    fromDate = new Date(fromArray[0], fromArray[1]-1, fromArray[2]);   
    toDate = new Date(toArray[0], toArray[1]-1, toArray[2]);             
    
    if (!optionList)
    {
        SetDateInDeliveryDropDownList("dashboardFromDeliveryDateYear", "dashboardFromDeliveryDateMonth", "dashboardFromDeliveryDateDay", fromDate);
        SetDateInDeliveryDropDownList("dashboardToDeliveryDateYear", "dashboardToDeliveryDateMonth", "dashboardToDeliveryDateDay", toDate);
    }
    else
    {       
        SetDateInDeliveryDropDownList("searchFromDeliveryDateYear", "searchFromDeliveryDateMonth", "searchFromDeliveryDateDay", fromDate);
        SetDateInDeliveryDropDownList("searchToDeliveryDateYear", "searchToDeliveryDateMonth", "searchToDeliveryDateDay", toDate);
    }
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function UnsetSelectedQuickOption(optionListId)
{
    var optionSearchString = "";
    
    if (!optionListId)
        optionSearchString = "#dashboardDeliveryDateOptions input[type=radio][name='dashboardDeliveryDateQuickSelect']";
    else
        optionSearchString = "#selectDeliveryDateIntervall input[type=radio][name='searchDeliveryDateQuickSelect']";

    var selectedQuickOption = $$(optionSearchString);

    for (var i = 0; i < selectedQuickOption.length; i++)
    {
        selectedQuickOption[i].checked = false;
    }            
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function SetDateInDeliveryDropDownList(yearElement, monthElement, dayElement, date)
{
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();

    SelectOptionInDropDownList(yearElement, year);
    SelectOptionInDropDownList(monthElement, month);
    SelectOptionInDropDownList(dayElement, day);
}


// ----------------------------------------------------------------
//  Loads the task page.
// ----------------------------------------------------------------
function LoadTasksFromDashboard(showOption)
{
    document.location = "Tasks.aspx?showoption=" + showOption;
} 


// ----------------------------------------------------------------
//  Makes the search on the selected delivery dates.
// ----------------------------------------------------------------
function DoDashboardDeliveryDateSearch()
{
    var fromMonth = $F("dashboardFromDeliveryDateMonth");
    var fromDay = $F("dashboardFromDeliveryDateDay");
    
    var fromDate = $F("dashboardFromDeliveryDateYear") + DateFormatAddZero(fromMonth); 

    if (fromMonth == 1 || fromMonth == 3 || fromMonth == 5 || fromMonth == 7 || fromMonth == 8 || fromMonth == 10 || fromMonth == 12)
        fromDate += DateFormatAddZero(fromDay);
    else
    {
        if (fromMonth == 2 && fromDay > 28) //if the user has selected a day value more then there are days in the month...
            fromDate += '28';
        else if (fromDay > 30)
            fromDate += '30';
        else
            fromDate += DateFormatAddZero(fromDay);
    }


        
    var toMonth = $F("dashboardToDeliveryDateMonth");
    var toDay = $F("dashboardToDeliveryDateDay");
    
    var toDate = $F("dashboardToDeliveryDateYear") + DateFormatAddZero(toMonth);
    
    if (toMonth == 1 || toMonth == 3 || toMonth == 5 || toMonth == 7 || toMonth == 8 || toMonth == 10 || toMonth == 12)
        toDate += DateFormatAddZero(toDay);
    else
    {
        if (toMonth == 2 && toDay > 28) //if the user has selected a day value more then there are days in the month...
            toDate += '28';
        else if (toDay > 30)
            toDate += '30';
        else
            toDate += DateFormatAddZero(toDay);
    }
        var searchAmongType = 'all';
        var searchAmongTypeText = resource.lblAll;

        if ($('dashboardsearchAmongNotVisited').checked)
        {
            searchAmongType = $F('dashboardsearchAmongNotVisited');
            searchAmongTypeText = resource.lblProjectNotVisited;
        }
        else if ($('dashboardsearchAmongVisited').checked)
        {
            searchAmongType = $F('dashboardsearchAmongVisited');
            searchAmongTypeText = resource.lblProjectVisited;
        }
        
    
    ShowShadowBackground();
    CenterPanel("waitSearchMessagePanel", null, true);
    
    
    var action = new PageActionRequest("dashboard", "deliveryDateSearch");
    action.addAction("fromDate", fromDate);
    action.addAction("toDate", toDate);
    action.addAction("searchAmongType",searchAmongType);
    action.addAction("searchAmongTypeText",searchAmongTypeText);
    
    new Ajax.Request("ajaxpages/LoadDashboard.aspx", {
      method: "post", 
      parameters: { action: Object.toJSON(action)},
      onFailure: function(transport) { (new Error()).doErrorResponseCheck('ajaxpages/LoadDashboard.aspx', 'action: ' + Object.toJSON(action), transport); },
      onSuccess: function(transport) 
      {
        WriteLoadingInfo('hitlistContainer');

        var action = new PageActionRequest('hitlist', '');
        action.addAction('selectFirstObject', 'true');

        ReloadHitList('', Object.toJSON(action));

        HideShadowBackground();
        $('waitSearchMessagePanel').hide();
      }
    });
}



function DoTodayDeliveryDateSearch()
{
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();

    var fromDate = year + DateFormatAddZero(month) + DateFormatAddZero(day);
    var toDate = fromDate;
    
    ShowShadowBackground();
    CenterPanel("waitSearchMessagePanel", null, true);
    
    
    var action = new PageActionRequest("dashboard", "deliveryDateSearch");
    action.addAction("fromDate", fromDate);
    action.addAction("toDate", toDate);
    
    new Ajax.Request("ajaxpages/LoadDashboard.aspx", {
      method: "post", 
      parameters: { action: Object.toJSON(action)},
      onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadDashboard.aspx", 'action: ' + Object.toJSON(action), transport); },
      onSuccess: function(transport) 
      {
        WriteLoadingInfo('hitlistContainer');

        var action = new PageActionRequest('hitlist', '');
        action.addAction('selectFirstObject', 'true');

        ReloadHitList('', Object.toJSON(action));

        HideShadowBackground();
        $('waitSearchMessagePanel').hide();
      }
    });
}


// ----------------------------------------------------------------
//  
// ----------------------------------------------------------------
function LoadNewProjectsFromDashboard()
{
    LoadProjectsFromDashboard('new');
}


// ----------------------------------------------------------------
//  
// ----------------------------------------------------------------
function LoadUpdatedProjectsFromDashboard()
{
    LoadProjectsFromDashboard('updated');
}


// ----------------------------------------------------------------
//  
// ----------------------------------------------------------------
function LoadFavoriteProjectsFromDashboard(favoriteId)
{
    LoadProjectsFromDashboard('favorites', favoriteId);
}

function LoadSharedFavoriteProjectsFromDashboard(favoriteId)
{
    LoadProjectsFromDashboard('sharedfolders', favoriteId);
}

// ----------------------------------------------------------------
//  
// ----------------------------------------------------------------
function LoadUpdCoverageProjectsFromDashboard(objecttype)
{
    LoadUpdCoverageFromDashboard(objecttype);
}
// ----------------------------------------------------------------
//  
// ----------------------------------------------------------------
function LoadProjectsFromDashboard(typeOfProjects, favoriteId)
{
    var action = new PageActionRequest("dashboard", "projectSearch");
    action.addAction("typeOfSearch", typeOfProjects);
    
    if (favoriteId)
        action.addAction("favoriteId", favoriteId);

    new Ajax.Request("ajaxpages/LoadDashboard.aspx", {
      method: "post", 
      parameters: { action: Object.toJSON(action)},
      onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadDashboard.aspx", 'action: ' + Object.toJSON(action), transport); },
      onSuccess: function(transport) 
      {
        var action = new PageActionRequest('hitlist', '');
        action.addAction('selectFirstObject', 'true');

        ReloadHitList('', Object.toJSON(action));
      }
    });
}

// ----------------------------------------------------------------
//  
// ----------------------------------------------------------------
function LoadOpenTendersFromDashboard(typeOfProjects)
{
    var action = new PageActionRequest("dashboard", "loadOpenTendersSearch");
    action.addAction("typeOfSearch", typeOfProjects);
    
    new Ajax.Request("ajaxpages/LoadDashboard.aspx", {
      method: "post", 
      parameters: { action: Object.toJSON(action)},
      onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadDashboard.aspx", 'action: ' + Object.toJSON(action), transport); },
      onSuccess: function(transport) 
      {
        var action = new PageActionRequest('hitlist', '');
        action.addAction('selectFirstObject', 'true');

        ReloadHitList('', Object.toJSON(action));
      }
    });
}

// ----------------------------------------------------------------
//  
// ----------------------------------------------------------------
function LoadUpdCoverageFromDashboard(typeOfProjects)
{
    var action = new PageActionRequest("dashboard", "loadUpdCoverageSearch");
    action.addAction("typeOfSearch", typeOfProjects);
    
    new Ajax.Request("ajaxpages/LoadDashboard.aspx", {
      method: "post", 
      parameters: { action: Object.toJSON(action)},
      onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadDashboard.aspx", 'action: ' + Object.toJSON(action), transport); },
      onSuccess: function(transport) 
      {
        var action = new PageActionRequest('hitlist', '');
        action.addAction('selectFirstObject', 'true');

        ReloadHitList('', Object.toJSON(action));
      }
    });
}



// ----------------------------------------------------------------
//  
// ----------------------------------------------------------------
function ReloadLiveRanking()
{
    var selectedstartdate = "";
    WriteLoadingImage('dashboardLiveRanking');
    
    var action = new PageActionRequest("dashboard", "loadLiveRanking");
    action.addAction("roleCode", $F('dashboard_liveranking_rolelist'));
    
    var selectedstartdate = $$("#dashboardYourRankingForm input[type=radio][name='rblStartDateOption']");
    
    for (var i = 0; i < selectedstartdate.length; i++)
    {
        if (selectedstartdate[i] && selectedstartdate[i].checked)
        {
            selectedstartdate = selectedstartdate[i].value;
            break;
        }
    }
  
    action.addAction("startdate", selectedstartdate);
    var url = "ajaxpages/LoadDashboard.aspx";
    
    new Ajax.Updater('dashboardLiveRanking', url, 
        { 
            method: "get", 
            parameters: { unique: GenerateUniqueValue(), action: Object.toJSON(action) },
            onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadDashboard.aspx", 'action: ' + Object.toJSON(action), transport); }
        });
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function searchindocu(languageCode)
{
	if(languageCode=='SWE')
	{
	    var searchname = escape($F('docusearchname'));//document.forms[0].elements['name'].value;
		window.open('http://www.byggfaktadocu.se/dyn/pdc/search/search.jsp?site=10&type=all&name='+searchname,'','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=1,width=650,height=600')
	}
	else if(languageCode=='NOR')
	{
	    var productfaktalink = $F('documaterial');
	    window.open(productfaktalink,'','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=1,width=650,height=600')

	}
	else if(languageCode=='DEN')
	{	var productinformationlink = $F('documaterial');
	    window.open(productinformationlink,'','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=1,width=650,height=600')
    }
    else if(languageCode=='FIN')
	{
	    var searchname = escape($F('docusearchname'));//document.forms[0].elements['name'].value;
		window.open('http://www.rpthaku.fi/dyn/pdc/search/search.jsp?site=14&type=all&name='+searchname,'','toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=1,width=650,height=600')
	}

}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function LoadSuperUserForm(cid,pid)
{
    curSuperUserContactId = cid;
    curSuperUserProfileId = pid;

    ShowShadowBackground();
    $('quickMenuOptionPanel').setStyle({   'width': '800px'});  
    LoadSuperUserPanel(cid,pid)

}

// ----------------------------------------------------------------
// ----------------------------------------------------------------
function LoadSuperUserPanel(cid,pid)
{
    curSuperUserContactId = cid;
    curSuperUserProfileId = pid;
    var action = new PageActionRequest("dashboardsuperuser", "load");
    new Ajax.Request('ajaxpages/LoadQuickMenuOptionCriteria.aspx', 
    {
        method: "post",
        parameters: { action: Object.toJSON(action) }, 
        onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadQuickMenuOptionCriteria.aspx", 'action: ' + Object.toJSON(action), transport); }, 
        onSuccess: function(transport) 
        {
           $('quickMenuOptionPanel').update(transport.responseText);        
            CenterPanel('quickMenuOptionPanel', null, true);

            $('superUserOverviewCardTab').removeClassName('activeTab');
            $('superUserOverviewCardTab').addClassName('inactiveTab');

            $('superUserDetailCardTab').addClassName('activeTab');
            $('superUserDetailCardTab').removeClassName('inactiveTab');

            LoadInformationAboutUser(curSuperUserContactId,curSuperUserProfileId);
        }
    });
}

// ----------------------------------------------------------------
// ----------------------------------------------------------------
function LoadInformationAboutUser(cid,pid)
{
    WriteLoadingInfo('superuserseluserinformationForm', resource.lblWorkingPleaseWait);

     if(curSuperUserContactId != cid)
     curSuperUserContactId = cid;
     if(curSuperUserProfileId != pid)
     curSuperUserProfileId = pid;

    var action = new PageActionRequest("dashboardsuperuser", "loadinformationaboutuser");
    action.addAction("newContactId", cid);
    action.addAction("newProfileId", pid);
    
    new Ajax.Request('ajaxpages/LoadQuickMenuOptionCriteria.aspx', 
    {
        method: "post",
        parameters: { action: Object.toJSON(action) }, 
        onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadQuickMenuOptionCriteria.aspx", 'action: ' + Object.toJSON(action), transport); }, 
        onSuccess: function(transport) 
        {
            $('superuserseluserinformationForm').update(transport.responseText);
            
            ResizeShadowBackground();
        }
    });
}

// ----------------------------------------------------------------
// ----------------------------------------------------------------
function LoadSuperUserOverviewPanel(sortOrder)
{
    $('superUserDetailCardTab').removeClassName('activeTab');
    $('superUserDetailCardTab').addClassName('inactiveTab');

    $('superUserOverviewCardTab').addClassName('activeTab');
    $('superUserOverviewCardTab').removeClassName('inactiveTab');

    var action = new PageActionRequest("dashboardsuperuser", "loadoverview");
    action.addAction("newContactId", curSuperUserContactId);
    action.addAction("newProfileId", curSuperUserProfileId);
    action.addAction("sortby", sortOrder);

    new Ajax.Request('ajaxpages/LoadQuickMenuOptionCriteria.aspx', 
    {
        method: "post",
        parameters: { action: Object.toJSON(action) }, 
        onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadQuickMenuOptionCriteria.aspx", 'action: ' + Object.toJSON(action), transport); }, 
        onSuccess: function(transport) 
        {
            $('dashboardSuperUserOptionForm').update(transport.responseText);

            ResizeShadowBackground();
        }
    });
}

// ----------------------------------------------------------------
// ----------------------------------------------------------------
function PrintSuperUserReport()
{
    $('quickMenuOptionPanel').hide();
    $('quickMenuOptionPanel').setStyle({'width': '350px'});
    WriteLoadingInfo('quickMenuOptionPanel', resource.lblWorkingPleaseWait);
    CenterPanel('quickMenuOptionPanel', null, true);
    
    var action = new PageActionRequest("dashboardsuperuser", "printsuperuserreport");
    new Ajax.Request('ajaxpages/LoadQuickMenuOptionCriteria.aspx', 
    {
        method: "post",
        parameters: { action: Object.toJSON(action) }, 
        onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadQuickMenuOptionCriteria.aspx", 'action: ' + Object.toJSON(action), transport); }, 
        onSuccess: function(transport) 
        {
           OpenPopup(transport.responseText);
            //LoadFinishedForm(transport.responseText);
        },
        onComplete: function() 
        {
            $('quickMenuOptionPanel').hide();
            HideShadowBackground();
        }
    });
}

// ----------------------------------------------------------------
// ----------------------------------------------------------------
function LoadSuperUserObjects(objecttype)
{
    var action = new PageActionRequest("dashboardsuperuser", "loadobjects");
    action.addAction("newContactId", curSuperUserContactId);
    action.addAction("newProfileId", curSuperUserProfileId);
    action.addAction("objecttype", objecttype);
 
    new Ajax.Request("ajaxpages/LoadQuickMenuOptionCriteria.aspx", {
        method: "post", 
        parameters: { unique: GenerateUniqueValue(),action: Object.toJSON(action)},

        onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadQuickMenuOptionCriteria.aspx", 'action: ' + Object.toJSON(action), transport); }, 

        onComplete: function()
        {
            WriteLoadingInfo('hitlistContainer');

            var action = new PageActionRequest('hitlist', '');
            action.addAction('selectFirstObject', 'true');
            ReloadHitList('', Object.toJSON(action));

      }
    });
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function GenerateSalesTaskStatistics()
{
    ShowShadowBackground();
    
    $('superuserSalesTaskStatisticPanel').setStyle({'height':document.viewport.getHeight() - 100 + 'px'});
    $('salesTaskStatisticsList').setStyle({'height':$('superuserSalesTaskStatisticPanel').getHeight() - 150 + 'px'});
    
    WriteLoadingInfo('salesTaskStatisticsList', resource.lblWorkingPleaseWait);
    CenterPanel('superuserSalesTaskStatisticPanel', null, true);
    
    var action = new PageActionRequest("task", "superusersalestaskstatistics");
    
    new Ajax.Updater('salesTaskStatisticsList', 'ajaxpages/TaskAction.aspx', {
        method: 'post', 
        parameters: { unique: GenerateUniqueValue(), action: Object.toJSON(action)},
        onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/TaskAction.aspx", 'action: ' + Object.toJSON(action), transport); }
    });
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function CloseSuperUserSalesTaskStatistic()
{
    $('superuserSalesTaskStatisticPanel').hide();
    HideShadowBackground();
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function ShowFilterSalesTaskPanel()
{
    if ($('superuserSalesTaskFilterPanel').innerHTML == "")
    {
        WriteLoadingImage('superuserSalesTaskFilterPanel');
        $('superuserSalesTaskFilterPanel').show();

        var action = new PageActionRequest("task", "loadsuperuserfilter");

        new Ajax.Updater('superuserSalesTaskFilterPanel', 'ajaxpages/TaskAction.aspx', {
            method: 'post', 
            parameters: { action: Object.toJSON(action), unique: GenerateUniqueValue()},
            onFailure: function() { $('superuserSalesTaskFilterPanel').update(resource.lblError); }
        });
    }
    else
        $('superuserSalesTaskFilterPanel').show();
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function DoClearFilterSuperUserSalesTasks(taskShowOption)
{
    $('txtTaskFromClosingDate').value = "";
    $('txtTaskToClosingDate').value = "";
    $('txtTaskFromValue').value = "";
    $('txtTaskToValue').value = "";
    SelectOptionInDropDownList('ddlTaskFromProbability', "0");
    SelectOptionInDropDownList('ddlTaskToProbability', "0");
  
   SelectOptionInDropDownList('ddlTaskFilterSalesStatus', "0");

 if ($('ddlTaskOptionalList'))
   SelectOptionInDropDownList('ddlTaskOptionalList', "0");  
    
    //SelectOptionInDropDownList('ctl00_MainContentPlaceHolder_ddlTaskFilterSalesStatus', "0");
    
    //LoadLargeTaskList(TaskShowOptionsEnum.All);  //reloads the list of all tasks.*/
    //changes the cursor to a wait-icon
    $('superuserSalesTaskStatisticPanel').setStyle({'cursor':'wait'});

    $('superuserSalesTaskFilterPanel').hide();

    //creates a new object with the info we want to execute on the server...
    var action = new PageActionRequest('task', 'filtersuperuser');


    if (typeof(taskShowOption) == "undefined")
    {
        action.addAction("showOption", TaskShowOptionsEnum.Filter);
        
        action.addAction("closingDateFrom", $F('txtTaskFromClosingDate'));
        action.addAction("closingDateTo", $F('txtTaskToClosingDate'));

        action.addAction("valueFrom", $F('txtTaskFromValue'));
        action.addAction("valueTo", $F('txtTaskToValue'));

        action.addAction("probabilityFrom", ($F('ddlTaskFromProbability') == "0" ? "" : $F('ddlTaskFromProbability')));
        action.addAction("probabilityTo", ($F('ddlTaskToProbability') == "0" ? "" : $F('ddlTaskToProbability')));

        action.addAction("sales_status", ($F('ddlTaskFilterSalesStatus') == "0" ? "" : $F('ddlTaskFilterSalesStatus')));
        if ($('ddlTaskOptionalList'))
        action.addAction("task_optional", ($F('ddlTaskOptionalList') == "0" ? "" : $F('ddlTaskOptionalList')));
        
        
        
    }
    else
        action.addAction("showOption", taskShowOption);
       

    new Ajax.Updater({ success: 'salesTaskStatisticsList' }, 'ajaxpages/TaskAction.aspx', 
        {
            method: "post", 
            parameters: { action: Object.toJSON(action)},
            onFailure: function(transport) 
            { 
                var err = new Error();
                
                //makes the check what the error it was...
                err.doErrorResponseCheck('ajaxpages/TaskAction.aspx', 'action: ' + Object.toJSON(action), transport); 
            }, 
            onComplete: function(){
                $('superuserSalesTaskStatisticPanel').setStyle({'cursor':'default'});
            }
        });
}



// ----------------------------------------------------------------
// ----------------------------------------------------------------
function DoFilterSuperUserSalesTasks(taskShowOption)
{
    //changes the cursor to a wait-icon
    $('superuserSalesTaskStatisticPanel').setStyle({'cursor':'wait'});

    $('superuserSalesTaskFilterPanel').hide();

    //creates a new object with the info we want to execute on the server...
    var action = new PageActionRequest('task', 'filtersuperuser');


    if (typeof(taskShowOption) == "undefined")
    {
        action.addAction("showOption", TaskShowOptionsEnum.Filter);
        
        action.addAction("closingDateFrom", $F('txtTaskFromClosingDate'));
        action.addAction("closingDateTo", $F('txtTaskToClosingDate'));

        action.addAction("valueFrom", $F('txtTaskFromValue'));
        action.addAction("valueTo", $F('txtTaskToValue'));

        action.addAction("probabilityFrom", ($F('ddlTaskFromProbability') == "0" ? "" : $F('ddlTaskFromProbability')));
        action.addAction("probabilityTo", ($F('ddlTaskToProbability') == "0" ? "" : $F('ddlTaskToProbability')));

        action.addAction("sales_status", ($F('ddlTaskFilterSalesStatus') == "0" ? "" : $F('ddlTaskFilterSalesStatus')));
        
         if ($('ddlTaskOptionalList'))
             action.addAction("task_optional", ($F('ddlTaskOptionalList') == "0" ? "" : $F('ddlTaskOptionalList')));
        
    }
    else
        action.addAction("showOption", taskShowOption);
       

    new Ajax.Updater({ success: 'salesTaskStatisticsList' }, 'ajaxpages/TaskAction.aspx', 
        {
            method: "post", 
            parameters: { action: Object.toJSON(action)},
            onFailure: function(transport) 
            { 
                var err = new Error();
                
                //makes the check what the error it was...
                err.doErrorResponseCheck('ajaxpages/TaskAction.aspx', 'action: ' + Object.toJSON(action), transport); 
            }, 
            onComplete: function(){
                $('superuserSalesTaskStatisticPanel').setStyle({'cursor':'default'});
            }
        });
}

// ----------------------------------------------------------------
// ----------------------------------------------------------------
function DoCancelFilter()
{
    $('superuserSalesTaskFilterPanel').hide();
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function LoadSuperUserTaskObject(objectType, objectId)
{
    CloseSuperUserSalesTaskStatistic();
    
    if (ObjectTypeEnum.Project == objectType)
        LoadProject(objectId);
    else if (ObjectTypeEnum.Company == objectType)
        LoadCompany(objectId);
    else if (ObjectTypeEnum.Contact == objectType)
        LoadContact(objectId);
}





// =====================================================================================
//   HitList methods etc...
// =====================================================================================




// The pagenumber that are displayed at the moment.
var CurrentHitListPage = 1;

// The type of the objects in the hitlist - if it's project, company or contact-objects.
var CurrentObjectTypeInHitList = ObjectTypeEnum.None;

// The status of the action that selects all or none of the items in the hitlist.
var LastStatusOfSelectAllNone = 'none';

// the id of the object that was last selected in the hitlist.
var LastSelectedHitlistObjectId = -1;




// ===========================================================================
//  This function reloads the hitlist
//  param: pageNumber - the page number that should be visible. 
//                      If you leave this value the last page will be displayed

function ChangePageOnHitList(pageNumber)
{
    var parameters = ""; 
    
    if (pageNumber != null && pageNumber != '')
        parameters = pageNumber;
        
    ReloadHitList(pageNumber, '');
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function SortHitList(sortDirection)
{
    var sortOptionValue = $F('quickHitListMenuSortOption');
    var sortDirection = $F('quickHitListMenuSortDirection');
    
    var action = new PageActionRequest('hitlist', 'sort');
    action.addAction('option', sortOptionValue);
    action.addAction('direction', sortDirection);
    
    if ($('imgSortWorking'))
        $('imgSortWorking').show();
    
    ReloadHitList('', Object.toJSON(action));
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function SelectAllNone()
{
    var status = '';
    var action = new PageActionRequest('hitlist', 'select');
    
    if (LastStatusOfSelectAllNone == 'none')
        status = 'all';
    else
        status = 'none';

    action.addAction('selectType', status);

    //reloads the hitlist and executes the selection action        
    ReloadHitList('', Object.toJSON(action));

    //changes the last status of the requested "selection-action"
    LastStatusOfSelectAllNone = status;
}


// -----------------------------------------------------------------------
//  Send a command to the server which sets this selected object in the
//  hitlist to checked.
// -----------------------------------------------------------------------
function SelectHitListCheckbox(objectId)
{
    var action = new PageActionRequest('hitlist', 'select');
    action.addAction('selectType', 'single');
    action.addAction('objectId', '' + objectId);

    //url to the page that will give us the projects that are new or updated.
    var url = 'ajaxpages/LoadHitList.aspx';

    new Ajax.Request(url, 
        { 
            method: 'post', 
            parameters: { unique: GenerateUniqueValue(), noresponse: 'true', action: Object.toJSON(action) },
            onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadHitList.aspx", 'noresponse: true, action: ' + Object.toJSON(action), transport); } 
        });
}


// -----------------------------------------------------------------------
//  
// -----------------------------------------------------------------------
function ReloadHitList(pageParameter, actionParameter, loadDashboardOnSuccess)
{
    //url to the page that will give us the projects that are new or updated.
    var url = 'ajaxpages/LoadHitList.aspx'

    new Ajax.Updater( { success: 'hitlistContainer' }, url, 
        { 
            method: 'post', 
            parameters: { page: pageParameter, action: actionParameter, unique: GenerateUniqueValue() }, 
            evalScripts: true, 
            onFailure: function(transport) { (new Error()).doErrorResponseCheck(url, 'page: ' + pageParameter + ', action: ' + actionParameter, transport); },
            onSuccess: function() {
                if (loadDashboardOnSuccess && !isHistoryExecuted)
                    LoadDashboard(true);
                
                isHistoryExecuted = false;
            }
        });
}


// -----------------------------------------------------------------------
//  
// -----------------------------------------------------------------------
function SelectHitListItem(objectId)
{
    if (isLoadingObject)
        return;
        
    var selectedItems = $('hitlistPanel').select('div.selectedHitListItem');
    
    for (var i = 0; i < selectedItems.length; i++)
        selectedItems[i].removeClassName('selectedHitListItem');
    
    if ($('item_' + objectId)) 
        $('item_' + objectId).addClassName('selectedHitListItem');

    if ($('item_' + objectId + '_href'))
        $('item_' + objectId + '_href').addClassName('visitedItem');

    LastSelectedHitlistObjectId = objectId;
}



// -----------------------------------------------------------------------
// Adds an icon of the "IconTypeEnumValue"-type to the selected item 
// in the hitlist.
// -----------------------------------------------------------------------
function AddIconToHitlistItem(IconTypeEnumValue, imageAltText)
{
    var lastObjectId = 0;
    
    if (CurrentObjectTypeInHitList == ObjectTypeEnum.Project)
        lastObjectId = lastLoadedProjectId;
    else if (CurrentObjectTypeInHitList == ObjectTypeEnum.Company)
        lastObjectId = lastLoadedCompanyId;
    else if (CurrentObjectTypeInHitList == ObjectTypeEnum.Contact)
        lastObjectId = lastLoadedContactId;

    try {
        var iconPanel = $$('div#hitlistPanel div#item_' + lastObjectId + ' div.hitlistIconPanel');
        
        if (iconPanel && iconPanel.length > 0)
        {
            RemoveIconFromHitlistItem(IconTypeEnumValue);  //removes the icon if it's already there... :)

            iconPanel[0].appendChild(CreateImgIcon(IconTypeEnumValue, imageAltText));
        }
    }
    catch (err)
    { }
}


// -----------------------------------------------------------------------
// Adds an icon of the "IconTypeEnumValue"-type to the current object card.
// -----------------------------------------------------------------------
function AddIconToObjectCard(IconTypeEnumValue, imageAltText)
{
    var lastObjectTypeName = "";
    
    if (selectedTabObjectType == ObjectTypeEnum.Project)
        lastObjectTypeName = "project";
    else if (selectedTabObjectType == ObjectTypeEnum.Company)
        lastObjectTypeName = "company";
    else if (selectedTabObjectType == ObjectTypeEnum.Contact)
        lastObjectTypeName = "contact";

    try {
        var iconPanel = $(lastObjectTypeName + 'CardIconPanel');
        
        if (iconPanel)
        {
            RemoveIconFromObjectCard(IconTypeEnumValue);  //removes the icon if it's already there... :)

            iconPanel.appendChild(CreateImgIcon(IconTypeEnumValue, imageAltText));
        }
    }
    catch (err)
    { }
}

function CreateImgIcon(IconTypeEnumValue, imageAltText)
{
    var imgElement = new Element('img');

    imgElement.writeAttribute("src", "images/blank.gif");
    imgElement.writeAttribute("icontype", IconTypeEnumValue);

    imgElement.addClassName("iconPanelImg");
    imgElement.addClassName("img16x16");

    
    if (IconTypeEnumValue == IconTypeEnum.Favorite)
    {
        imgElement.addClassName("imgFavorite16");
    }
    
    else if (IconTypeEnumValue == IconTypeEnum.Delete)
    {
        imgElement.addClassName("imgDelete16");
    }

    else if (IconTypeEnumValue == IconTypeEnum.ExportWebService)
    {
        imgElement.addClassName("imgExportFolder16");
    }

    else if (IconTypeEnumValue == IconTypeEnum.SharedFolders)
    {
        imgElement.addClassName("imgSharedFolder16");
    }
    
    else if (IconTypeEnumValue == IconTypeEnum.Coverage)
    {
        imgElement.addClassName("imgCoverage16");
        imageAltText = resource.lblCoverage;
    }

    else if (IconTypeEnumValue == IconTypeEnum.Notes)
    {
        imgElement.addClassName("imgNotepad16");
        imageAltText = resource.lblNotes;
    }

    else if (IconTypeEnumValue == IconTypeEnum.Tasks)
    {
        imgElement.addClassName("imgCalendar16");
        imageAltText = resource.lblTasks;
    }
    else if (IconTypeEnumValue == IconTypeEnum.Responsible)
    {
        imgElement.addClassName("imgUser16");
       
    }

    if (imageAltText)
    {
        imgElement.writeAttribute("alt", imageAltText);
        imgElement.writeAttribute("title", imageAltText);
    }
            
    return imgElement;
}


// -----------------------------------------------------------------------
// Removes an icon of the "IconTypeEnumValue"-type from the panel of 
// icons in the hitlist.
// -----------------------------------------------------------------------
function RemoveIconFromHitlistItem(IconTypeEnumValue)
{
    var lastObjectId = 0;
    
    if (CurrentObjectTypeInHitList == ObjectTypeEnum.Project)
        lastObjectId = lastLoadedProjectId;
    else if (CurrentObjectTypeInHitList == ObjectTypeEnum.Company)
        lastObjectId = lastLoadedCompanyId;
    else if (CurrentObjectTypeInHitList == ObjectTypeEnum.Contact)
        lastObjectId = lastLoadedContactId;

    try {
        var iconPanel = $$('div#hitlistPanel div#item_' + lastObjectId + ' div.hitlistIconPanel');
        
        if (iconPanel && iconPanel.length > 0)
            iconPanel[0].select('[icontype="' + IconTypeEnumValue + '"]').each(function(element) { element.remove() });
    }
    catch (err)
    { }
}


// -----------------------------------------------------------------------
// Removes an icon of the "IconTypeEnumValue"-type from the panel of 
// icons in the hitlist.
// -----------------------------------------------------------------------
function RemoveIconFromObjectCard(IconTypeEnumValue)
{
    var lastObjectTypeName = "";
    
    if (selectedTabObjectType == ObjectTypeEnum.Project)
        lastObjectTypeName = "project";
    else if (selectedTabObjectType == ObjectTypeEnum.Company)
        lastObjectTypeName = "company";
    else if (selectedTabObjectType == ObjectTypeEnum.Contact)
        lastObjectTypeName = "contact";

    try {
        var iconPanel = $(lastObjectTypeName + 'CardIconPanel');
        
        if (iconPanel)
            iconPanel.select('[icontype="' + IconTypeEnumValue + '"]').each(function(element) { element.remove() });
    }
    catch (err)
    { }
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function HideAddonInfo(dashboardpart)
{
       
    var action = new PageActionRequest("dashboardlayout", "hide");
    action.addAction("dashboardpart", dashboardpart);       
   
 
    new Ajax.Request("ajaxpages/LoadDashboard.aspx", {
        method: "post", 
        parameters: { unique: GenerateUniqueValue(),action: Object.toJSON(action)},

        onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadDashboard.aspx", 'action: ' + Object.toJSON(action), transport); }, 
 onSuccess: function(transport) {   
 if(dashboardpart=="10")
    $('dashboardAddonPanel').update(transport.responseText);
 
 else if(dashboardpart=="11")
 $('dashboardYourMarketPanel').update(transport.responseText);

else if(dashboardpart=="12")
  $('dashboardBigPlanPanel').update(transport.responseText);
  
 else if(dashboardpart=="13")
   $('dashboardYourRankingPanel').update(transport.responseText);

else if(dashboardpart=="16")
    $('dashboardDocuInfoPanel').update(transport.responseText);
 
else if(dashboardpart=="17")
   $('dashboardNewsInfoPanel').update(transport.responseText); 

else if(dashboardpart=="18")
$('dashboardUserInfoPanel').update(transport.responseText); 
 
 }, 
 onComplete: 
        {
       
      }
    });

}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function LoadSuperUserFormOnlySingleProfiles(cid, pid) {
    curSuperUserContactId = cid;
    curSuperUserProfileId = pid;

    ShowShadowBackground();
    $('quickMenuOptionPanel').setStyle({ 'width': '800px' });
    LoadSuperUserPanelOnlySingleProfiles(cid, pid)

}

function LoadSuperUserPanelOnlySingleProfiles(cid, pid) {
    curSuperUserContactId = cid;
    curSuperUserProfileId = pid;
    var action = new PageActionRequest("dashboardsuperuser", "loadonlysingleprofiles");
    new Ajax.Request('ajaxpages/LoadQuickMenuOptionCriteria.aspx',
    {
        method: "post",
        parameters: { action: Object.toJSON(action) },
        onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadQuickMenuOptionCriteria.aspx", 'action: ' + Object.toJSON(action), transport); },
        onSuccess: function(transport) {
            $('quickMenuOptionPanel').update(transport.responseText);
            CenterPanel('quickMenuOptionPanel', null, true);
           
        }
    });
}



// ----------------------------------------------------------------
// ----------------------------------------------------------------
function LoadSuperUserOverviewPanelOSP(sortOrder, cid, pid, timeperiod) {

    var action = new PageActionRequest("dashboardsuperuser", "loadoverviewosp");
    action.addAction("newContactId", cid);
    action.addAction("newProfileId", pid);
    action.addAction("sortby", sortOrder);
    action.addAction("timeperiod", timeperiod);

    new Ajax.Request('ajaxpages/LoadQuickMenuOptionCriteria.aspx',
    {
        method: "post",
        parameters: { action: Object.toJSON(action) },
        onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadQuickMenuOptionCriteria.aspx", 'action: ' + Object.toJSON(action), transport); },
        onSuccess: function(transport) {
        $('dashboardSuperUserOverviewHeaderForm').update(transport.responseText);

        $('superUserOverviewCardTab').addClassName('activeTab');
        $('superUserOverviewCardTab').removeClassName('inactiveTab');

        $('superUserDetailCardTab').removeClassName('activeTab');
        $('superUserDetailCardTab').addClassName('inactiveTab');
          
            ResizeShadowBackground();
        }
    });
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function LoadSuperUserDetailUserPanelOSP(cid, pid, timeperiod, sortOrder) {

    var action = new PageActionRequest("dashboardsuperuser", "loaddetailosp");
    action.addAction("newContactId", cid);
    action.addAction("newProfileId", pid);
    action.addAction("sortby", sortOrder);
    action.addAction("timeperiod", timeperiod);


    new Ajax.Request('ajaxpages/LoadQuickMenuOptionCriteria.aspx',
    {
        method: "post",
        parameters: { action: Object.toJSON(action) },
        onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadQuickMenuOptionCriteria.aspx", 'action: ' + Object.toJSON(action), transport); },
        onSuccess: function(transport) {
      
            $('dashboardSuperUserOverviewHeaderForm').update(transport.responseText);

            $('superUserOverviewCardTab').removeClassName('activeTab');
            $('superUserOverviewCardTab').addClassName('inactiveTab');

            $('superUserDetailCardTab').addClassName('activeTab');
            $('superUserDetailCardTab').removeClassName('inactiveTab');

            ResizeShadowBackground();

            LoadSuperUserUserDetailsForm(cid, pid, timeperiod, sortOrder);

        }
    });
}

// ----------------------------------------------------------------
// ----------------------------------------------------------------
function LoadSuperUserObjectsTimePeriod(pid, objecttype, timeperiod, favoriteId) {
    var action = new PageActionRequest("dashboardsuperuser", "loadobjectstimeperiod");
   // action.addAction("newContactId", curSuperUserContactId);
    action.addAction("newProfileId", pid);

   // action.addAction("newProfileId", curSuperUserProfileId);
    action.addAction("objecttype", objecttype);
    action.addAction("timeperiod", timeperiod);
    action.addAction("favoriteId", favoriteId);


    

    new Ajax.Request("ajaxpages/LoadQuickMenuOptionCriteria.aspx", {
        method: "post",
        parameters: { unique: GenerateUniqueValue(), action: Object.toJSON(action) },

        onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadQuickMenuOptionCriteria.aspx", 'action: ' + Object.toJSON(action), transport); },

        onComplete: function() {
            WriteLoadingInfo('hitlistContainer');

            var action = new PageActionRequest('hitlist', '');
            action.addAction('selectFirstObject', 'true');
            ReloadHitList('', Object.toJSON(action));

        }
    });
}


// ----------------------------------------------------------------
// ----------------------------------------------------------------
function LoadSuperUserUserDetailsForm(cid, pid, timeperiod, sortOrder) {
    WriteLoadingInfo('superuserseluserinformationForm', resource.lblWorkingPleaseWait);
   
  /* if (curSuperUserContactId != cid)
        curSuperUserContactId = cid;
    if (curSuperUserProfileId != pid)
        curSuperUserProfileId = pid;
*/
    var action = new PageActionRequest("dashboardsuperuser", "loadsuperuseruserdetails");

    action.addAction("newContactId", cid);
    action.addAction("newProfileId", pid);
    action.addAction("sortby", sortOrder);
    action.addAction("timeperiod", timeperiod);

    new Ajax.Request('ajaxpages/LoadQuickMenuOptionCriteria.aspx',
    {
        method: "post",
        parameters: { action: Object.toJSON(action) },
        onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadQuickMenuOptionCriteria.aspx", 'action: ' + Object.toJSON(action), transport); },
        onSuccess: function(transport) {
        LoadTimePeriodDetailFrom(cid, pid, timeperiod, sortOrder);
            $('superuserseluserinformationForm').update(transport.responseText);

            ResizeShadowBackground();
           
        }
    });
}


function LoadTimePeriodDetailFrom(cid, pid, timeperiod, sortOrder) {
    //WriteLoadingInfo('superuserseluserinformationForm', resource.lblWorkingPleaseWait);

    /* if (curSuperUserContactId != cid)
    curSuperUserContactId = cid;
    if (curSuperUserProfileId != pid)
    curSuperUserProfileId = pid;
    */
    var action = new PageActionRequest("dashboardsuperuser", "loadtimeperioddetail");

    action.addAction("newContactId", cid);
    action.addAction("newProfileId", pid);
    action.addAction("sortby", sortOrder);
    action.addAction("timeperiod", timeperiod);

    new Ajax.Request('ajaxpages/LoadQuickMenuOptionCriteria.aspx',
    {
        method: "post",
        parameters: { action: Object.toJSON(action) },
        onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadQuickMenuOptionCriteria.aspx", 'action: ' + Object.toJSON(action), transport); },
        onSuccess: function(transport) {

        $('superusertimeperioddetailForm').update(transport.responseText);

            //ResizeShadowBackground();
        }
    });

    /* usersStr.Append("<div id=\"superusertimeperioddetailForm\" class=\"font8\" >");
    usersStr.Append(LoadHeaderDetailTable2(actionRequest.getActionData("sortby"), actionRequest.getActionData("newContactId"), actionRequest.getActionData("newProfileId"), actionRequest.getActionData("timeperiod")));
    */
}

function PrintSuperUserOverviewReport(timeperiod, sortOrder) {


    $('quickMenuOptionPanel').hide();
    $('quickMenuOptionPanel').setStyle({ 'width': '350px' });
    WriteLoadingInfo('quickMenuOptionPanel', resource.lblWorkingPleaseWait);
    CenterPanel('quickMenuOptionPanel', null, true);


    var action = new PageActionRequest("dashboardsuperuser", "printsuperuseroverviewreport");
    action.addAction("sortby", sortOrder);
    action.addAction("timeperiod", timeperiod);
    new Ajax.Request('ajaxpages/LoadQuickMenuOptionCriteria.aspx',
    {
        method: "post",
        parameters: { action: Object.toJSON(action) },
        onFailure: function(transport) { (new Error()).doErrorResponseCheck("ajaxpages/LoadQuickMenuOptionCriteria.aspx", 'action: ' + Object.toJSON(action), transport); },
        onSuccess: function(transport) {
            OpenPopup(transport.responseText);
            //LoadFinishedForm(transport.responseText);
        },
        onComplete: function() {
            $('quickMenuOptionPanel').hide();
            HideShadowBackground();
        }
    });
}
