var vRefresh = null;
var vGFPRefresh = null;
var vSecRefresh = new Array();
var vFormattedReportLinkRefresh = null;
var bFirstLoad = true;

var vReportIds          = new Array();
var vGFPIds             = new Array();
var vFormattedReportLinkIds      = new Array();
var vSecIds             = new Array();
var vFormattedReportIds = new Array();

var sSectionIdStyleInfo = new Array();

var sEmbedFrameID = "idEmbed";
var sEmbedFrameDivID = "idEmbedFrameDiv";

//for sitemap
var bDescShown = false;

var bEnableIERepaintWorkAround = false;
var bEnableRefreshDashboardAfterSuccessfulLoad = false;
//Enable this to workaround the browser repaint issue on IE Browsers
if (is_ie)
   bEnableIERepaintWorkAround = false;
if (is_ie6 && is_ie7)
   bEnableRefreshDashboardAfterSuccessfulLoad = false;

//-------------------
function SetPortalLogo(path)
{
	var tFrame = parent.frames['banner'];
	tFrame.document.images['PortalImage'].src = path;
}

//-------------------
function SetPageBackground(bg)
{
	document.body.background=bg;
}

//-------------------
function HideSectionHeading()
{
}

// for sitemap //
function siteMapShowDesc()
{
   if (bDescShown)
      sVal = "none";
   else
      sVal = "inline";
   bDescShown = !bDescShown;
   var vObjects = parent.document.getElementsByTagName("div");
   for (var i=0; i < vObjects.length; i++)
   {
      var tDiv = vObjects[i];
      if (tDiv.getAttribute("type") == "desc")
      {
         try{
         tDiv.style.display = sVal;
         }
         catch(er)
         {
         }
      }
   }
}

//-------------------
// page tab click
function DashboardChangePage(sCmd)
{
   var viewStateDiv = document.getElementById("idViewStateDiv");
   if (viewStateDiv)
   {
//      sCmd += "&Action=navigate";
      sCmd += "&ViewState=" + viewStateDiv.getAttribute("stateID");
      sCmd += "&StateAction=NewPage";
   }
   saw.runThisURL(sCmd);
   return false;
}

//-------------------
// guided nav redirect
function GuidedNav(sCmd, bAddViewState)
{
   var viewStateDiv = document.getElementById("idViewStateDiv");
   if (viewStateDiv && bAddViewState)
   {
//      sCmd += "&Action=navigate";
      sCmd += "&ViewState=" + viewStateDiv.getAttribute("stateID");
      sCmd += "&StateAction=NewPage";
      sCmd += "&Options=mfrdg";
   }
        
   saw.runThisURL(sCmd);
   return false;
}

//-------------------
// advanced reporting
function toggleAdvancedReportVersions(sImgExpandId, sImgCollapseId, sCellId, sWaitCellId, 
                                      sDivId, sIframeId)
{
   var tImgExpand = document.getElementById(sImgExpandId);
   var tImgCollapse = document.getElementById(sImgCollapseId);
   var tCell = document.getElementById(sCellId);
   var tWaitCell = document.getElementById(sWaitCellId);
   var tDiv = document.getElementById(sDivId);
   var tIframe = document.getElementById(sIframeId);
   
   if (tImgCollapse.style.display == '')
   {
      // versions are visible; collapse them
      tImgCollapse.style.display = 'none';
      tCell.style.display = 'none';
      tWaitCell.style.display = 'none';
      tImgExpand.style.display = '';
   }
   else
   {
      tImgCollapse.style.display = '';
      tImgExpand.style.display = 'none';
      
      // if the div is already loaded, there's no need for an iframe call
      var sDivLoaded = (null != tDiv.loaded) ? tDiv.loaded : tDiv.getAttribute("loaded");
      if (sDivLoaded == "true")
      {
         tCell.style.display = '';
         tWaitCell.style.display = 'none';
      }
      else
      {
         tDiv.setAttribute("loaded", "false");
         tCell.style.display = 'none';
         tWaitCell.style.display = '';
         
         var sPSrc = (null != tIframe.pSrc) ? tIframe.pSrc : tIframe.getAttribute("pSrc");
         tIframe.src = sPSrc;
      }
   }
}

//-------------------
function loadAdvancedReportVersions(sCellId, sWaitCellId, sDivId, sIframeId)
{
   var tCell = document.getElementById(sCellId);
   var tWaitCell = document.getElementById(sWaitCellId);
   var tDiv = document.getElementById(sDivId);
   var tIframe = document.getElementById(sIframeId);

   if (null == tDiv || null == tCell || null == tWaitCell || null == tIframe)
      return;

   // check if the div needs to be loaded
   var sDivLoaded = (null != tDiv.loaded) ? tDiv.loaded : tDiv.getAttribute("loaded");
   if (sDivLoaded == "false")
   {
      tCell.style.display = '';
      tWaitCell.style.display = 'none';
      
      tDiv.innerHTML = tIframe.contentWindow.document.body.innerHTML;
      tDiv.setAttribute("loaded", "true");
   }
}

//-------------------
// force cache refresh
function RefreshPage(sCmd)
{
   var viewStateDiv = document.getElementById("idViewStateDiv");
   if (viewStateDiv)
   {
      sCmd += "&Action=RefreshAll";
      sCmd += "&ViewState=" + viewStateDiv.getAttribute("stateID");
      sCmd += "&StateAction=samePageState";
   }
   window.location.replace(sCmd);
   return false;
}

function RefreshPageUsingCache(sCmd)
{
   var viewStateDiv = document.getElementById("idViewStateDiv");
   if (viewStateDiv)
   {
      sCmd += "&ViewState=" + viewStateDiv.getAttribute("stateID");
      sCmd += "&StateAction=samePageState";
   }
   window.location.replace(sCmd);
   return false;
}

//-------------------
// page tab click
function DashboardReportLink(sLink, sViewID, sDone, bNew)
{
   var viewStateDiv = document.getElementById("idViewStateDiv");
   if (viewStateDiv)
   {
      sLink += "&ViewState=" + viewStateDiv.getAttribute("stateID");
      sLink += "&StateAction=samePageState";
      sLink += "&ViewID=" + sViewID;

      sDone += "&ViewState=" + viewStateDiv.getAttribute("stateID");
   }

   if (bNew)
   {
      sLink += "&Done=Close";
      window.open(sLink);
   }
   else
   {
      sLink += "&Done=" + saw.encodeURIComponent(sDone);
      saw.runThisURL(sLink);
   }
   return false;
}

//-------------------
function PortalPrint(sUrl,bNewWindow)
{
   NQWClearActiveMenu();

	viewStateDiv = document.getElementById("idViewStateDiv");
	if (viewStateDiv)
	{
	  sUrl += "&ViewState=" + viewStateDiv.getAttribute("stateID");
	}

   if(bNewWindow)
      window.open(sUrl);
   else
      window.location.href = sUrl;

   return false;
}

//-------------------
// PopupBBWindow
// This method is used to popup a new window for the briefing book a new argument is added
// to the PrintURL and that is the viewstate

function PopupBBWindow(sURL, sFrame, nWidth, nHeight, sFeatures)
{
	var vT = sFrame == null ? "_blank" : sFrame;
	var vW = nWidth == null ? 720 : nWidth;
	var vH = nHeight == null ? 520 : nHeight;
	var vF = sFeatures == null ? "resizable=yes,scrollbars=yes" : sFeatures;

	var sFeat = "width=" + vW + ",height=" + vH + "," + vF;

	var tViewState = document.getElementById("idViewStateDiv");
	if(tViewState != undefined)
	{
	   sURL += "&ViewState=" + tViewState.getAttribute("StateID");
	}

	window.open(sURL, vT, sFeat);
}


/******************************************************/
function RefreshDashboard(sURL)
{
	var tViewState = document.getElementById("idViewStateDiv");
	if(tViewState != undefined)
	{
	   sURL += "&ViewState=" + tViewState.getAttribute("StateID");
	}
	window.location.href = sURL;
}




saw.dashboard = function() { }
saw.dashboard.impl = function () { }

saw.dashboard.needsRefresh = function(id)
{
   //Bug Fix 6158611 :Check for Object Validity.
   if (saw.aViewsToRefresh)
      return (saw.aViewsToRefresh["all"] || saw.aViewsToRefresh[id]);   
   else
      return false;
}

//---------------------
// This function copies the report xml to the clipboard
getCopySwf = function(classid, codebase, objectEleId, movieValue, flashvarValue)
{
   // Fix Bug 8329148 --- DO NOT --- format the line below.  It needs to be on one line for IE7.
   var reportInfo = '<object classid="'+ classid + '" id="'+ objectEleId + '" width="30" height="21"' + 'codebase="' + codebase + '">' + '<param name="movie" value="' + movieValue + '"/>' + '<param name="quality" value="high"/>' + '<param name="bgcolor" value="#FFFFFF"/>' + '<param name="wmode" value="transparent"/>' + '<param name="play" value="true"/>' + '<param name="flashvars" value="' + flashvarValue + '" />' +'<param name="allowScriptAccess" value="sameDomain" />' +'</object>';
   return reportInfo;
}  

// inline report load support on dashboard
saw.dashboard.transferToParent = function(tData)
{
    if (!vRefresh)
        saw.dashboard.impl.setReloadView(-1, true);

    var vScripts = new Array();
    var sCallerAction = saw.checkObjectReference(tData.tCallerObj)?tData.tCallerObj:"reload";

    // get listing of all scripts on page
    var aScripts = document.getElementsByTagName("script");
    if (aScripts)
    {
        for(i = 0; i < aScripts.length; ++i)
        {
            var curScript = aScripts[i];
            // Bug 8669206: With FF 3.0, the ".src" JavaScript property is returning
            // a fully qualified URL which is not matching the src="xxx" text in the
            // generated markup. Hence the Ajax code is tripping up and not handling
            // incremental reload of JavaScript properly.
            if (curScript.getAttribute('src'))
                vScripts[curScript.getAttribute('src')] = true;
        }
    }	  
    var tIFrame = sawr.iFrameConnection.getIFrame(sEmbedFrameID);
    // TODO: why is getContentDocument not working on IE?
    var tLoadingDoc = tData.getHTMLInDocument(tIFrame ? tIFrame.document : null);
    var clipBoardSpanId;
    var statePathDiv = tLoadingDoc.getElementById("idStatePathDiv");
    if (statePathDiv)
       clipBoardSpanId = statePathDiv.getAttribute("statePath");  //this span id must be unique
   
    var movieValue;
    var flashValue;
    var classid; 
    var codeBase; 
    var objectEleId;
    if (is_ie)
    {
       var clipSpan = tLoadingDoc.getElementById(clipBoardSpanId);
       if (clipSpan)
       {
          objectEleId = "copy2cliptest" + clipBoardSpanId;  //this one must be unique
          var obj = tLoadingDoc.getElementById(objectEleId);
          if (obj)
          {
             classid = obj.getAttribute("classid");
             codeBase = obj.getAttribute("codeBase"); 
             for(var i = 0; i < obj.childNodes.length; ++i)
             {
               var child = obj.childNodes[i];
               if(child.getAttribute("name").toLowerCase() == "flashvars")
                  flashValue = child.getAttribute("value");
               if(child.getAttribute("name").toLowerCase() == "movie")
                  movieValue = child.getAttribute("value");
             }
         }
       }
    }
    var tViewsToRefreshElement = tLoadingDoc.getElementById("idViewsToRefresh");
    if (tViewsToRefreshElement && tViewsToRefreshElement.innerHTML != '')
        eval(tViewsToRefreshElement.innerHTML);
    
    //load minimized section
    for (var i=0; i<vSecIds.length; i++)
    {
        var id = vSecIds[i];
        if (saw.dashboard.needsRefresh(id))
        {
            var embedId = "Embed" + id;
            var embedView = tLoadingDoc.getElementById(embedId);
            var actualView = document.getElementById(embedId);
            //alert(embedId + " " + embedView + " " + actualView);
            if (actualView != null && embedView != null)
            {
                var sMin = embedView.getAttribute("minimized");

                if (sMin != "true")
                {
                    actualView.innerHTML = embedView.innerHTML;
                    actualView.setAttribute("loaded", "true");            
                }
                vSecRefresh[id] = false;
                actualView.setAttribute("minimized", sMin);
            }
        }
    }

    //load gfp
    for (var i=0; i<vGFPIds.length; i++)
    {
        var id = vGFPIds[i];
        var embedId = "EmbedView" + id;
        var embedView = tLoadingDoc.getElementById(embedId);
        var actualView = document.getElementById(embedId);

        //var resultDiv = tLoadingDoc.getElementById(id + "Result");
        var actualResultDiv = document.getElementById(id + "Result");
        if (actualView != null && embedView != null)
        {
            if ((actualResultDiv && actualResultDiv.result != "searching") &&
                (actualResultDiv.loaded && actualResultDiv.loaded == "true" || !actualResultDiv.loaded) &&
                (!saw.dashboard.needsRefresh(id) || bFirstLoad))
            {
                vGFPRefresh[id] = false;
                continue;
            }
            XUICloseActiveDiv();
            actualView.innerHTML = embedView.innerHTML;
            actualView.setAttribute("loaded", "true");
            vGFPRefresh[id] = false;
        }
    }
   
    //load Advanced Reporting Links
    for (var i=0; i<vFormattedReportLinkIds.length; i++)
    {
        var id = vFormattedReportLinkIds[i];
        var embedId = "EmbedView" + id;
        var embedView = tLoadingDoc.getElementById(embedId);
        var actualView = document.getElementById(embedId);
        var actualResultDiv = document.getElementById(id + "Result");
        //var resultDiv = tLoadingDoc.getElementById(id + "Result");
        if (actualView != null && embedView != null)
        {
            if ((actualResultDiv && actualResultDiv.result != "searching") &&
                (actualResultDiv.loaded && actualResultDiv.loaded == "true" || !actualResultDiv.loaded) &&
                (!vFormattedReportRefresh[id] || bFirstLoad))
            {
                vFormattedReportLinkRefresh[id] = false;
                continue;
            }
            actualView.innerHTML = embedView.innerHTML;
            actualView.setAttribute("loaded", "true");
            vFormattedReportLinkRefresh[id] = false;
        }
    }
    
    // load reports
    for (var i=0; i<vReportIds.length; i++)
    {
        var id = vReportIds[i];
        var embedId = "EmbedView" + id;
        var embedView = tLoadingDoc.getElementById(embedId);
        var actualView = document.getElementById(embedId);
        var actualResultDiv = document.getElementById(id + "Result");
        var resultDiv = tLoadingDoc.getElementById(id + "Result");
        var navDone = tLoadingDoc.getElementById(id + "NavDone");
        var navSearch = tLoadingDoc.getElementById(id + "NavSearch");
        var navContent = tLoadingDoc.getElementById(id + "NavContent");

        if (resultDiv != null)
        {
            // if report has returned something
            if (resultDiv.getAttribute("result") != "searching")
            {
                if (embedView != null)
                {
                    // hide navigation link helpers and show content
                    if (navSearch != null && navDone != null)
                    {
                        var tDoneFlag = navDone.getAttribute("doneflag");
                        if (tDoneFlag == null || tDoneFlag != "true")
                        {
                            navSearch.style.display = "none";
                            navSearch.style.position = "absolute";
                            
                            try
                            {
                                navDone.setAttribute("doneflag","true");
                            }
                            catch (e) 
                            {
                            }
                            if (resultDiv.getAttribute("result") == "errorStop")
                                embedView.innerHTML = resultDiv.innerHTML;
                            else if ((resultDiv.getAttribute("result") != "finished" && navDone.getAttribute("condition") !="noRows") ||
                                     (resultDiv.getAttribute("result") != "noData" && navDone.getAttribute("condition") =="noRows"))
                                embedView.innerHTML = "";
                                
                            if (navContent != null)
                                navContent.style.display = "";
                        }                                
                    }
                }
            }
            // if still running report
            else
            {
                bStillSearching = true;
                if (embedView != null)
                {
                    //show navSearch if still searching
                    /*if (navSearch != null && navDone != null && resultDiv.getAttribute("result") != "Prompt")
                    {
                        // copy child nodes and contents
                        navSearch.style.display = "";
                        var temp = navSearch.cloneNode(true);
                        temp.innerHTML = navSearch.innerHTML;
                        embedView.innerHTML = "";
                        embedView.appendChild(temp);
                    }*/
                    vRefresh[id] = true;
                }

            }

            if (actualView != null && embedView != null)
            {
                //this if statement needs to be reviewed
                var bIsFromMinimiziedSection = (actualResultDiv && actualResultDiv.getAttribute("minimized") && actualResultDiv.getAttribute("minimized") == "true" && sCallerAction == "maximize")?true:false;
                
                if ( ( actualResultDiv && actualResultDiv.getAttribute("result") != "searching" && !bIsFromMinimiziedSection) &&
                     ( actualResultDiv.getAttribute("loaded") && actualResultDiv.getAttribute("loaded") == "true" || 
                       !actualResultDiv.getAttribute("loaded")
                     ) && 
                     (!saw.dashboard.needsRefresh(id) || bFirstLoad)
                   )
                {
                    vRefresh[id] = false;
                    continue;
                }

                if (saw.dashboard.needsRefresh(id) || bFirstLoad || bIsFromMinimiziedSection || 
                    (actualResultDiv && actualResultDiv.getAttribute("result") == "searching"))
                {
                    actualView.innerHTML =  embedView.innerHTML;
                    
                    if (bEnableIERepaintWorkAround)
                    {  // JCPenny QF_255 refresh page fix for all version of IEx 
                       var aRepaintViews = aRepaintViews || [];
                       aRepaintViews.push(actualView);

                       var repaintTimer = repaintTimer || setTimeout(function(){
                          for (var i = 0; i < aRepaintViews.length; i++)
                          {
                             try{
                                var tempView = aRepaintViews[i];
                                tempView.style.display="none";
                                var redrawFix = tempView.offsetHeight;
                                tempView.style.display="block";
                             }
                             catch(e)
                             {}
                          }
                       }, 1000);
                    }                    
                }
                if (actualResultDiv)
                    actualResultDiv.setAttribute("result", resultDiv.getAttribute("result"));

                actualView.setAttribute("loaded", "true");
                if (resultDiv.getAttribute("result") != "searching")
                    vRefresh[id] = false;

                //special for iframes (case with office docs)
                {
                    var vIFrames = actualView.getElementsByTagName("iframe");
                    if (vIFrames)
                    {
                        for (var iF = 0; iF < vIFrames.length; iF++)
                        {
                            var pSrc = vIFrames[iF].getAttribute("pSrc");
                            if (pSrc)
                            {
                                vIFrames[iF].src = pSrc;
                            }
                        }
                    }
                }
            }
        }
    }
	
    for(var iF = 0; iF < vFormattedReportIds.length; ++iF)
    {
        var tSrcFrame = null;
        var id = vFormattedReportIds[iF];
        if(!vFormattedReportRefresh[id])
            continue;

        tSrcFrame = tLoadingDoc.getElementById(id);

        if(tSrcFrame != null)
        {
            var tFrame = document.getElementById(vFormattedReportIds[iF]);

            if(tFrame != null)
            {
                var pSrc = tSrcFrame.getAttribute("pSrc");
                if(pSrc)
                    tFrame.src = pSrc;

                vFormattedReportRefresh[id] = false;
            }
        }
    }
  
    // reinitialize scripts on main window
    var aHeadScripts = tData.getScriptInDocument().getElementsByTagName("script");
    saw.dashboard.evalScripts(aHeadScripts, vScripts);
    var aBodyScripts = tLoadingDoc.getElementsByTagName("script");
    saw.dashboard.evalScripts(aBodyScripts, vScripts);

    //updated viewstate on dashboard
    var actualViewState = document.getElementById("idViewStateDiv");
    var viewState = tLoadingDoc.getElementById("idViewStateDiv");
    if (actualViewState && viewState)
    {
        actualViewState.setAttribute("stateID", viewState.getAttribute("stateID"));
        //#debug only
        if (document.getElementById("idViewStateDisplay"))
            document.getElementById("idViewStateDisplay").innerHTML = viewState.getAttribute("stateID");

    }
    bFirstLoad = false;
    document.body.style.cursor = "";
    tLoadingDoc = null;
    			
    NQWDefaultCursor();			

    var bHaveObjectsToLoad = saw.dashboard.reload();
    if (bEnableRefreshDashboardAfterSuccessfulLoad && !bHaveObjectsToLoad && sCallerAction != "PromptConstrain")
    {
        var tViewForm = GetViewFormHelper("");
        if (tViewForm)
        {
           var sSawCMD = saw.commandToURL('Dashboard');
           var sPortalPath = tViewForm.PortalPath.value;
           var sPageName = tViewForm.Page.value;
           var sCmd = sSawCMD + '&PortalPath=' + saw.encodeURIComponent(sPortalPath) + '&Page=' + saw.encodeURIComponent(sPageName);
           RefreshPageUsingCache(sCmd);
        }
    }   
    if(is_ie)
    {
       var clipSpan = document.getElementById(clipBoardSpanId);
       if (clipSpan)
       {  
          clipSpan.innerHTML = "";
          clipSpan.innerHTML = getCopySwf(classid, codeBase, objectEleId, movieValue, flashValue);
       }
    }
}

saw.dashboard.evalScripts = function(aScripts, vExistingScripts)
{
    var RE = new RegExp("document.write","gi");
    for(var i = 0; i < aScripts.length; ++i)
    {
        var curScript = aScripts[i];
        if (curScript.src == "" &&  curScript.htmlFor == "")
        {
            if (curScript.innerHTML && curScript.getAttribute("userDefined") != "true")
            {
                try
                {
                    var script = curScript.innerHTML;
                    script = script.replace(RE, "void");
                    eval(script);
                    var onLoadCallScript = curScript.getAttribute("onLoadCall");
                    if (onLoadCallScript != null && onLoadCallScript != "")
                        eval(onLoadCallScript);
                }
                catch (e)
                {
                }
            }
        }
        //add any new scripts
        else if (curScript.src && !vExistingScripts[curScript.src])
        {
            NQWDynamicLoadJS(curScript.src, curScript.src);
        }
    }
}

saw.dashboard.addReportId = function(sID)
{
   for (var i=0; i < vReportIds.length; i++)
	{
	   var id = vReportIds[i];
		if (id == sID)
   		return;
	}
   vReportIds[vReportIds.length] = sID;
   }

saw.dashboard.addGFPId = function(sID)
{
   for (var i=0; i < vGFPIds.length; i++)
	{
	   var id = vGFPIds[i];
		if (id == sID)
   		return;
	}
   vGFPIds[vGFPIds.length] = sID;
}

saw.dashboard.addFormattedReportLinkId = function(sID)
{
   for (var i=0; i < vFormattedReportLinkIds.length; i++)
   {
      var id = vFormattedReportLinkIds[i];
      if (id == sID)
         return;
   }
   vFormattedReportLinkIds[vFormattedReportLinkIds.length] = sID;
}

// sets which elements on dashbaord should be refreshed next time a reload happens
saw.dashboard.impl.setReloadView = function(nViewID, bValue)
{
   if (!vRefresh)
   {
      vRefresh = new Array();
      vGFPRefresh = new Array();
      vFormattedReportLinkRefresh = new Array();
      vSecRefresh = new Array();
      vFormattedReportRefresh = new Array();
   }

   if (nViewID == -1)
   {
       for (var i=0; i<vReportIds.length; i++)
         vRefresh[vReportIds[i]] = bValue;

       for (var i=0; i<vGFPIds.length; i++)
         vGFPRefresh[vGFPIds[i]] = true;

       for (var i=0; i<vFormattedReportLinkIds.length; i++)
         vFormattedReportLinkRefresh[vFormattedReportLinkIds[i]] = true;
       
       // RIE: can't afford like in the previous cases to go overboard here  
       for (var i = 0; i < vFormattedReportIds.length; i++)
         vFormattedReportRefresh[vFormattedReportIds[i]] = true;
   }
   else
   {
      var index = 0, i = 0;
      for(; i < vReportIds.length; i++)
      {
         if(vReportIds[i] == nViewID)
         {
            vRefresh[nViewID] = bValue;
            var resultDiv = document.getElementById(nViewID + "Result");
            if (resultDiv != null)
               resultDiv.setAttribute("result", "searching");            
            break;
         }
      }

      for(i = 0; i < vGFPIds.length; i++)
      {
         if(vGFPIds[i] == nViewID)
         {
            vGFPRefresh[nViewID] = bValue;
            break;
         }
      }

      for(i = 0; i < vFormattedReportLinkIds.length; i++)
      {
         if(vFormattedReportLinkIds[i] == nViewID)
         {
            vFormattedReportLinkRefresh[nViewID] = bValue;
            break;
         }
      }

      index = 0;

      for(i = 0; i < vSecIds.length; i++)
      {
         if(vSecIds[i] == nViewID)
         {
            vSecRefresh[nViewID] = bValue;
            break;
         }
      }
      
      for(i = 0 ; i < vFormattedReportIds.length; ++i)
      {
         if(vFormattedReportIds[i] == nViewID)
         {
            vFormattedReportIds[nViewID] = bValue;
            break;
         }
      }
   }
}


//-------------------
// HAW: this return reload call command without the "saw.dll?"
saw.dashboard.impl.getReloadCall = function(sOriginal)
{
   var tReloadCallDiv = document.getElementById("idReloadCall");
   if (tReloadCallDiv)
   {
      return tReloadCallDiv.getAttribute("call");
   }
   else
      return sOriginal;
}

//-------------------
saw.dashboard.impl.setFormForReload = function(tForm)
{
   //tForm.action = saw.dashboard.impl.getReloadCall(tForm.action);
   //var sReloadCall = saw.dashboard.impl.getReloadCall("");
   //if (sReloadCall != "")
	//   tForm.action = saw.commandToURL(sReloadCall);
	tForm.Done.value = saw.dashboard.impl.getReloadCall(tForm.Done.value);
	//tForm.target = 'EmbedFrame';
   bFirstLoad = false;
}

//-------------------
saw.dashboard.impl.setFormForRefreshDashboard = function(tForm)
{
   var tDashboardCallDiv = document.getElementById("idDashboardCall");
   if (tDashboardCallDiv)
   {
      var sDashboardCall = tDashboardCallDiv.getAttribute("call");
      if (sDashboardCall)
         tForm.action = saw.commandToURL(sDashboardCall);
      tForm.Done.value = sDashboardCall;
   }

	tForm.target = "";
   bFirstLoad = true;
}

saw.dashboard.getSearchingIds = function(sTarget)
{
   var sSearchingReports = sTarget ? sTarget + "," : "";
   var numEmbed = vReportIds.length;

	for (var i=0; i < numEmbed; i++)
	{
	   var id = vReportIds[i];
		var resultDiv = document.getElementById(id + "Result");

      //alert(resultDiv + " " + id);
		if (resultDiv != null)
		{
			if (resultDiv.getAttribute("result") == "searching")
			{
			   if (id.lastIndexOf("r:navReport") != -1)
			      id = id.substr(0, id.length-12);		
			     
    			sSearchingReports += id + ",";   
			}
		}
	}
	if (sSearchingReports)
	   sSearchingReports = sSearchingReports.substr(0, sSearchingReports.length-1);
	
	return sSearchingReports;
}

//-------------------
saw.dashboard.reload = function(tFormArg)
{
    var sSearchingReports = saw.dashboard.getSearchingIds();
    //if (!sSearchingReports)
    //    return false;
    if (!sSearchingReports)
        { // custom script
          cust_dshb_format();
                
          return false;
          //return;
        }

    var tEmbedFrameDiv = document.getElementById(sEmbedFrameDivID);
    if (tEmbedFrameDiv)
    {
        var tForm = saw.createFormFromString(tEmbedFrameDiv.getAttribute("src"));
        tForm.ViewState.value = document.getElementById("idViewStateDiv").getAttribute("stateID");

        saw.addHiddenInput(tForm, "reloadTargets", sSearchingReports);
		
		 if(tFormArg)
        {
           saw.addHiddenInput(tForm, "Action", tFormArg.Action.value);
           saw.addHiddenInput(tForm, "ViewID", tFormArg.ViewID.value);
        }

        var req = new sawr.serverRequest(saw.dashboard.impl.getReloadCall(), saw.dashboard.transferToParent);
        req.setCallerObj("reload");
        req.setErrorHandler(saw.dashboard.showError);

        var conn = new sawr.iFrameConnection(req);

        if (conn.setVisible)
        {
            if (tEmbedFrameDiv.getAttribute("display") == "visible")
                conn.setVisible(true);

            conn.setID(sEmbedFrameID);
        }
        conn.postForm(tForm);

		cust_dshb_format();
        return true;
    }
    return false;
}

saw.dashboard.prepareVirtualBufferUpdate = function()
{
   var objNew = document.createElement('p');
   var objHidden = document.createElement('input');

   objHidden.setAttribute('type', 'hidden');
   objHidden.setAttribute('value', '1');
   objHidden.setAttribute('id', 'virtualbufferupdate');
   objHidden.setAttribute('name', 'virtualbufferupdate');

   objNew.appendChild(objHidden);
   document.body.appendChild(objNew);
}

// Bug Fix 6404636 Method removes the height and width from the sectionTable style
function remove_height_width(sStyle)
{
   var sResultStyle = "";
   var sStyleTokens = sStyle.split(";");
      
   for(i = 0; i < sStyleTokens.length; i++)
   {
      if((-1 != sStyleTokens[i].search("height"))||(-1 != sStyleTokens[i].search("width")))
      {
        //Do nothing.
        //alert(sStyleTokens[i])
      }
      else
      {
         sResultStyle=sResultStyle.concat(sStyleTokens[i])
         sResultStyle=sResultStyle.concat(";")
       }
   }

   return sResultStyle;
}

//Bug Fix 6404636 When you maximize the method will set the proper style to the sectionTable.
function setSectionStyle(tSection,sStyle)
{
  var sChildNodes = tSection.childNodes;
  for(var i = 0; i != sChildNodes.length; i++)
  {
   //if nodetype is element type(1) 
   if(sChildNodes[i].nodeType == 1)
   {
      if(sChildNodes[i].nodeName == "TABLE")
      {
         sChildNodes[i].style.cssText = sStyle;
      }
    }
  }
}

// Bug Fix 6404636 - Method sets the style.height style.width trimmed
function getSectionStyle_trim(tSection)
{
   var sChildNodes = tSection.childNodes;
   var sStyle = "";
   for (var i = 0; i != sChildNodes.length; i++)
   {
      //if nodetype equals 1 means element type
      if (sChildNodes[i].nodeType == 1)
      {
         if (sChildNodes[i].nodeName == "TABLE")
         {
            sStyle = sChildNodes[i].getAttribute("style");
            if (typeof sStyle == 'object')
            {
                sStyle = sStyle.cssText.toLowerCase();
            }

            var sMinimizeStyle = remove_height_width(sStyle);
            sChildNodes[i].style.cssText = sMinimizeStyle; 

            break;
         }
      }
   }

   return sStyle;
}


//-------------------
saw.dashboard.onToggleSection = function(sSectionID, event)
{
        var tContents = document.getElementById(sSectionID + "Contents");
        var tMax = document.getElementById(sSectionID + "Max");
        var tMin = document.getElementById(sSectionID + "Min");
        var tSection = document.getElementById("Embed" + sSectionID);

        var sAction = "minimize";
        if (tSection.getAttribute("minimized") == "true")
            sAction = "maximize";

        if (tContents)
        {
            if (sAction == "maximize")
            {
                var tImg = document.getElementById(sSectionID + "SearchingImg");
         var sStyle="";
                if (tImg)
                    tImg.style.display = "";
                tContents.style.display = "";
                tMax.style.display = "none";
                tMin.style.display = "";
                tSection.setAttribute("minimized", "false");
         var i;
         for (i in vSecIds)
         {
            var id = vSecIds[i];
            if (id == sSectionID)
            {
              sStyle = sSectionIdStyleInfo[i];
              setSectionStyle(tSection,sStyle);
              break;
            }
         }
            }
            else if (sAction == "minimize")
            {
                tContents.style.display = "none";
                tMax.style.display = "";
                tMin.style.display = "none";
                tSection.setAttribute("minimized", "true");
         
         // Method removes the height and width from style attribute of sectionTable.
         sStyle = getSectionStyle_trim(tSection);
            }

            vSecIds[vSecIds.length] = sSectionID;
      sSectionIdStyleInfo[sSectionIdStyleInfo.length] = sStyle;
            vSecRefresh["Embed" + sSectionID] = true;
            var tForm = GetViewForm(sSectionID);
            tForm.Action.value = sAction;
            dashboardToggleSubmitForm(tForm,sAction, true);
            NQWWaitCursor();
    } // if (tContents)
}

//TODO: style!
saw.dashboard.showError = function(tData, aError)
{
   var tErrorDiv = document.getElementById("DashboardErrorDiv");
   for (var i=0; i<aError.length; i++)
   {
      var sType = aError[i].getType();
      var sMsg = aError[i].getMessage();
      var tDiv = document.createElement("div");
      tDiv.appendChild(document.createTextNode("! " + sType + " : " + sMsg));
      tErrorDiv.appendChild(tDiv);
   }
   tErrorDiv.style.display = "";
}


/////////////////////////////////////////////////////////////////
//-------------------
function GetViewFormHelper(sViewID)
{
	var tForm = document.forms["ViewForm"];
	if (!tForm)
	   return null;

	saw.addHiddenInput(tForm, "ViewID", sViewID);

   updateFormViewState(tForm);
	return tForm;
}




//override for dashboard purposes
function GetViewForm(sViewID, sViewIDToRefresh, bGFPReloadInline)
{
   var tForm = GetViewFormHelper(sViewID);

   // GFP has a switch to decide whether the hidden frame is used
   if (bGFPReloadInline == false)
   {
      saw.dashboard.impl.setFormForRefreshDashboard(tForm);

      return tForm;
   }

  
   if (!sViewIDToRefresh)
      sViewIDToRefresh = sViewID

      var sSearchingReports = "all";

      if (sViewIDToRefresh != null )
      {

      //special case for view selector view
      //when the view being processed is embeded in view selector view, we need do remove "~v:viewSelector!1" from sViewIdToRefresh
         var index = -1;
         if (sViewIDToRefresh.indexOf != null)
            index = sViewIDToRefresh.indexOf("~v:viewSelector");
         
         if(index != -1)
            sViewIDToRefresh = sViewIDToRefresh.substr(0,index);

        saw.dashboard.impl.setReloadView(sViewIDToRefresh, true);

      }
      tForm = GetViewFormHelper(sViewID);
      saw.dashboard.impl.setFormForReload(tForm);
      //get list of objects to reload

      if (sViewIDToRefresh != -1)
         sSearchingReports = saw.dashboard.getSearchingIds(sViewIDToRefresh);
      saw.addHiddenInput(tForm, "reloadTargets", sSearchingReports);

   return tForm;
}

//override for dashboard purposes
SubmitViewFormToRefresh = function(tForm)
{
    saw.dashboard.reload(tForm);
}

function dashboardToggleSubmitForm(tForm, sNewAction, bHideFromHistory)
{
    //only viewform used for inline loads
    if (tForm.name == "ViewForm")
    {
        var tEmbedFrameDiv = document.getElementById(sEmbedFrameDivID);
        if (tEmbedFrameDiv)
        {
            var req = new sawr.serverRequest(saw.dashboard.impl.getReloadCall(""), saw.dashboard.transferToParent);
            req.setCallerObj(sNewAction);
            req.setErrorHandler(saw.dashboard.showError);

            var conn = null;

            // TODO: could not get this to work on Mozilla (or IE when dashboard is in an iframe)
            if (is_ie && bHideFromHistory && 1 == 2)
                conn = new sawr.xhrConnection(req);
            else
            {
                conn = new sawr.iFrameConnection(req);
                if (conn.setVisible)
                {      
                    if (tEmbedFrameDiv.getAttribute("display") == "visible")
                        conn.setVisible(true);

                    conn.setID(sEmbedFrameID);
                }
            }
            conn.postForm(tForm);
            return;
        }
    }
    if(sNewAction != null)
        tForm.action = sNewAction;

    tForm.submit();
}

function submitViewForm(tForm, sNewAction)
{
   dashboardToggleSubmitForm(tForm, sNewAction);
}

if (typeof(onCustomNavigate) == 'undefined')
{
   onCustomNavigate = function(aValues, sNavPortalPath, sNavPortalPage)
   {
      
      var sURL = saw.commandToURL("Dashboard") + "&Action=Navigate&PortalPath="+saw.encodeURIComponent(sNavPortalPath)+"&Page="+saw.encodeURIComponent(sNavPortalPage);
      for (var i = 0; i < aValues.length; i++)
      {
         sURL += '&col'+ (i+1) + '=' + saw.encodeURIComponent(aValues[i][0]) 
               + '&op' + (i+1) + '=' + 'eq'
               + '&val'+ (i+1) + '=' + '\"' + saw.encodeURIComponent(aValues[i][1]) + '\"';
      }
      //alert(sURL);
      saw.runThisURL(sURL);
      return false;
   }
}

