
//var DefaultFrameRowsSetting = "45px,50%,50%";
//var MinimizedFrameRowsSetting = "45px,*,1px";

function ProfileFrameIsVisible()
{
   var IsVisible = GetCookie ("ProfileFrameIsVisible");
   
   // If the Minimized Cookie has not been set, default it to Invisible
   // NOTE: If Default changes, you must also see  ViewerItem.CreateFrames() method.
   if ( IsVisible == null )
      IsVisible = 0;
   
   return IsVisible;   
}

function ProfileFrameSetRows()
{
   var FrameSetRowsValue = GetCookie ("ProfileFrameSetRows");
   
   // If the Minimized Cookie has not been set, default it to Visible
   if (FrameSetRowsValue == null)
      FrameSetRowsValue = DefaultFrameRowsSetting;
   
   return FrameSetRowsValue;
}

function ToggleProfilePanel()
{
   // Visible TRUE = 1
   //         FALSE = 0
   var FrameSetRows = GetCookie ("ProfileFrameValue") 
   var ParentFrameSet = document.getElementById('IMRViewFrameSet');
      
   if (ProfileFrameIsVisible() == 1)
   {
      // We need to Hide the Profile Panel since it is visible now
      SetCookie("ProfileFrameIsVisible",0);
      ParentFrameSet.rows = MinimizedFrameRowsSetting;
   }
   else
   {
      // We need to Show the Profile Panel since it is not visible now
      SetCookie("ProfileFrameIsVisible",1);
      // Set the FrameSets Rows property.
      ParentFrameSet.rows = ProfileFrameSetRows();
   }
}

function ReSizeProfileFrame()
{
   if (ProfileFrameIsVisible() == 1)
   {
      var ParentFrameSet = document.getElementById('IMRViewFrameSet');
      
      ParentFrameSet.children(0).height
      //var Frame0Height = ParentFrameSet.frames(0).frameElement.height;
      //var Frame2Height = ParentFrameSet.frames(2).frameElement.height;
      
      var Frame0Height = ParentFrameSet.children(0).height;
      var Frame2Height = ParentFrameSet.children(2).height;
      var NewRowsValue = Frame0Height + "px,*," + Frame2Height + "px";
      
      SetCookie("ProfileFrameSetRows",NewRowsValue);
      ParentFrameSet.rows = NewRowsValue;
   }
}

// Code needed to get set cookies

// to set a cookie with an expiration date 30 days in the future.
//    var expDays = 30;
//    var exp = new Date(); 
//    exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
//    SetCookie('count',newcount,exp)

function GetCookie (name)
{
   var arg = name + "="; 
   var alen = arg.length; 
   var clen = document.cookie.length; 
   var i = 0; 
   while (i < clen) 
   {
      var j = i + alen; 
      if (document.cookie.substring(i, j) == arg) 
         return getCookieVal (j); 
      i = document.cookie.indexOf(" ", i) + 1; 
      if (i == 0) 
         break; 
   } 
   return null;
}

function SetCookie (name, value) 
{ 
   var argv = SetCookie.arguments; 
   var argc = SetCookie.arguments.length; 
   var expires = (argc > 2) ? argv[2] : null; 
   var path = (argc > 3) ? argv[3] : null; 
   var domain = (argc > 4) ? argv[4] : null; 
   var secure = (argc > 5) ? argv[5] : false; 
   
   document.cookie = name + "=" + escape (value) + 
      ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
      ((path == null) ? "" : ("; path=" + path)) + 
      ((domain == null) ? "" : ("; domain=" + domain)) + 
      ((secure == true) ? "; secure" : "");
}
   
function DeleteCookie (name) 
{ 
   var exp = new Date(); 
   exp.setTime (exp.getTime() - 1); 
   var cval = GetCookie (name); 
   document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getCookieVal(offset) 
{
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

var vHidePrintButton = false;
function HidePrintButton()
{
   // Hide the Print Button when the Custom Viewers are displayed.
   var PrintLink = document.frames(0).document.getElementById('PrintLink');
   
   if (PrintLink == null)
      self.setTimeout('HidePrintButton()', 500);
   else
   {
      PrintLink.style.display = "none";
      vHidePrintButton = true;
   }
}

var vItemLSACL = 0;
var vRepositoryACL = 0;
function SetItemLSACL(ItemLSACL,RepositoryACL)
{
   // Are we in a frames environment?
   if (document.frames.length > 0)
   {
      // Since we are dealing with Frames - we must make sure the DocLinks frame is loaded before
      // Calling the EnbleLSActions() method.

      var ItemLSActionLink =  document.frames(0).document.getElementById('CheckOutLink'); 
 
      if (ItemLSActionLink == null)
         self.setTimeout('SetItemLSACL( "' + ItemLSACL + '", ' + RepositoryACL + ' )', 500);
      else
      {
         document.frames(0).EnableLSActions(ItemLSACL,RepositoryACL);
         vItemLSACL = ItemLSACL;
         vRepositoryACL = RepositoryACL;
      }
   }
}

function RedoLinkStatusOnRefresh()
{
   if (vHidePrintButton == true)
      HidePrintButton();
   if (vItemLSACL != 0 && vRepositoryACL != 0)
      SetItemLSACL(vItemLSACL,vRepositoryACL);
}
