﻿// inherited
Event.observe(window, "load", OnInitializeApplication);
Event.observe(window, "resize", SetScreenElements);
var printallowed = true;

function OnInitializeApplication()
{   
  Event.observe(document, MAGMA.EVENT.APPLICATION.LOADED, OnApplicationLoaded);
  Event.observe(document, MAGMA.EVENT.APPLICATION.LOADAUTHORIZED, OnApplicationLoadAuthorized);

  new KMMagmaLanguageListUI("loginLanguageList"); 
  new KMMagmaLanguageListUI("mainLanguageList");  

  if ((self.KMMagmaHealthUI) && (self.KMMagmaHealth)) {
    new KMMagmaHealthUI({      
      DivPanel: "ErrorDialog",
      DivNetworkFailure: "NetworkFailure",
      DivPermanentNetworkFailure: "PermanentNetworkFailure", 
      DivSessionFailure: "SessionFailure", 
      EventSink: Proxy.GetEventSink()});    
    Proxy.GetEventSink().observe(HEALTH.SESSIONFAILURE, OnSessionFailure);   
  }
  
  new KMMagmaLicenseLoader({
    LoginPanel: "loginarea", IdField: "idValue", PasswordField: "passValue",
    RememberField: "remember", LoginCommand: "commandLogin",
    PasswordRecoveryPanel: "pwdrecoverypanel",
    TogglePasswordRecoveryCommand: "commandShowPasswordRecovery",        
    RecoverIdField: "recoverId", RecoverCommand: "commandRecover",
    CancelRecoverCommand: "commandCancel",
    MessagePanel: "LoginDialog", MessageField: "LoginMessage",
    MessageCloseCommand: "LoginDialogCommandClose"}); 
}  
    
function OnSessionFailure()
{  
  if (self.MagmaLicense) {
    window.setTimeout("MagmaLicense.LogOff();", 5000);  
  } else {
    window.setTimeout("Proxy.Application.Reload();", 5000);
  }
}

var areatop = 70;
var pubviewertop = 108;
var allowtogglemainpage = true;
var allowtoggledocinfo = true;
var allowtoggleopendocs = true;
var allowtogglelinkmanager = true;
var allowtogglefavorites = true;
var allowtoggleslotlicense = true;
var allowtogglefilemanagement = true;


function OnApplicationLoadAuthorized()
{  
  MagmaLoader.Start();
}

function OnApplicationLoaded(host)
{   
  var deeplink = Proxy.GetValues().Application.HasDelayedRequest;  
  if (!deeplink) {
    ExpandPanel();  
  }
  
  host = self;
  Proxy.GetEventSink().observe(UPLATFORM.BOOKUPDATED, OnBookUpdated);    
  Proxy.GetEventSink().observe(UPLATFORM.DOCUMENTUPDATED, OnDocumentUpdated);
  Proxy.GetEventSink().observe(UPLATFORM.BOOKERROR, OnBookError); 
  Proxy.GetEventSink().observe(UPLATFORM.FAVORITEDOCUMENTUPDATED, OnFavoriteDocumentUpdated); 
  
  Proxy.GetEventSink().observe(UPLATFORM.SHOWLINKMANAGEMENT, OnShowLinkManagement);
  Proxy.GetEventSink().observe(UPLATFORM.HIDELINKMANAGEMENT, OnHideLinkManagement);
    
  Proxy.GetEventSink().observe(UPLATFORM.RELEASE.CHANGED, OnReleaseUpdated);
  Proxy.GetEventSink().observe(UPLATFORM.RELEASE.LIBRARYCHANGED, OnLibraryUpdated);
  
  Proxy.GetEventSink().observe(UPLATFORM.VAULTSTORAGE.COMMANDEXECUTED, CollapseFileManagement);
  
  Proxy.GetEventSink().observe(UPLATFORM.VAULTSTORAGE.DATAUPDATED, FileManagementAvailable);   
  
  Event.observe($("librarytocframe"), "blur", CloseLibrary);  
      
  host.Proxy.GetEventSink().observe(UPLATFORM.HISTORYUPDATED, OnHistoryUpdated);     
  
  Element.show("maintoolbar");
  if ($("maintoolbar_background")) { Element.show("maintoolbar_background"); }
  Element.show("linkbutton_logoff");
  Element.show("queryTextMain");
  Element.show("mainLanguageSelection");
  Element.show("commandQueryMain");
  Element.show("publicationviewerframe");
  Element.show("documentinfobar");
  Element.show("docinfobuttons");
  Element.show("docinfotext");  
  Element.show("statusbar");
  Element.show("historytoolbar");
  
  Element.show("logo");
  Element.hide("lineleft");
  Element.hide("lineright");
  Element.hide("watermark");
  
  if (self.slotlicenseavailable) {
	  var slotlicensebutton = $("docinfo_slotlicense");
	  if (slotlicensebutton) {
	    if (slotlicenseavailable=="True") {
	      Element.show(slotlicensebutton);	
	    } else {
	      Element.hide(slotlicensebutton);	
	    }
	  }
	}
     
  OnReleaseUpdated();
  UpdateStatusBar();
  SetScreenElements();  


  Proxy.SingleInstance.Register("slotlicensearea", CollapseSlotLicenseArea); 
  Proxy.SingleInstance.Register("linkmanager", CollapseLinkManager);  
  Proxy.SingleInstance.Register("filemanagement", CollapseFileManagement);  
  Proxy.SingleInstance.Register("licarea", CollapseLicArea);
  Proxy.SingleInstance.Register("infobar", CollapseInfoBar);
  Proxy.SingleInstance.Register("releasearea", CollapseReleaseArea);  
  
  Proxy.SingleInstance.Register("librarytoc", function() {HidePage("librarytoc");});
  Proxy.SingleInstance.Register("search", function() {HidePage("search");});
  Proxy.SingleInstance.Register("misc", function() {HidePage("misc");});   
  Proxy.SingleInstance.Register("languageselection", function() {HideLanguageList("main");});
  
  RegisterCustomElements()
}

function OnHistoryUpdated(event)
{    
  var previous = $("historyprev");
  var next = $("historynext");
  var previousdisabled = $("historyprev_disabled");
  var nextdisabled = $("historynext_disabled");
  
  if (event.memo.Next != null) {
    next.setAttribute("alt",unescape(event.memo.Next.Book.Title) + ": " + unescape(event.memo.Next.Book.Document.Title));
    nextdisabled.style.display = "none";
    next.style.display = "";
  } else {
    next.setAttribute("alt","");
    nextdisabled.style.display = "";
    next.style.display = "none";
  }
  
  if (event.memo.Previous != null) {
    previous.setAttribute("alt",unescape(event.memo.Previous.Book.Title) + ": " + unescape(event.memo.Previous.Book.Document.Title));
    previousdisabled.style.display = "none";
    previous.style.display = "";
  } else {
    previous.setAttribute("alt","");
    previousdisabled.style.display = "";
    previous.style.display = "none";  
  }
}  

function HoverLargeLinkButton(obj)
{
  if (obj.getAttribute("status") != "selected") {
    obj.className = "largelinkbuttonhover";
  }
}

function DehoverLargeLinkButton(obj) 
{
  if (obj.getAttribute("status") != "selected") {
    obj.className = "largelinkbutton";
  }
}

function HoverLinkButton(obj)
{
  if (obj.getAttribute("status") != "selected") {
    obj.className = obj.className + "hover";
  }
}

function DehoverLinkButton(obj) 
{
  if (obj.getAttribute("status") != "selected") {
    obj.className = obj.className.substr(0,obj.className.indexOf("hover"));
  }
}

function LogOff()
{     
  Proxy.GetContext().MagmaLicense.LogOff();
}

function TogglePage(id)
{ 
  var area = $(id + "area");
  if (area) {
    if (area.getAttribute("status") != "show") {
      if (id == "search") {
        ShowSearchPage();
      } else {
        ShowPage(id);	
      }
    } else {
      HidePage(id);	
    }	         	 
  }	
}

function AllowToggleMainPage()
{
	allowtogglemainpage = true;
}

function OverSideBarItem(obj)
{
  var icon = $(obj.id + "_icon");
  var iconhot = $(obj.id + "_iconhot");
  if ((icon) && (iconhot)) {
  	Element.hide(icon);	
    Element.show(iconhot);	
  }
}

function OutSideBarItem(obj)
{
  var icon = $(obj.id + "_icon");
  var iconhot = $(obj.id + "_iconhot");
  if ((icon) && (iconhot)) {
  	Element.show(icon);	
    Element.hide(iconhot);	
  } 
}

function CloseLibrary()
{
  HidePage("librarytoc");	
}

function OnBookUpdated(event)
{    
  if ((event) && (event.memo) && (Object.isString(event.memo.Title))) {
    $("booktitle").innerHTML = unescape(event.memo.Title);
  } else {
    $("booktitle").innerHTML = "";	
  }       
}
  
function OnDocumentUpdated(event)
{     
	animationallowed = false; 
	if ((event) && (event.memo) && (Object.isString(event.memo.Title))) {
    SetDocInfoButtons(true); 
    
    Proxy.SingleInstance.HideAll(new Array("linkmanager"));	   // argument is exlude array of registered singleinstance id's	
	}	else {
	  SetDocInfoButtons(false); 				  
	}	
  
	animationallowed = true;
}

function SetDocInfoButtons(allow)
{
  if (Proxy.GetContext().UPlatform.Release.GetValues().Release.LicenseItems) { 	
  	if (Proxy.GetContext().UPlatform.Release.GetValues().Release.LicenseItems.print === false) {
    	printallowed = false;
    }  
  } 

  var mtf = $("docinfo_mailtofriend");
	var mtf_disabled = $("docinfo_mailtofriend_disabled");
	var p = $("docinfo_print");
	var p_disabled = $("docinfo_print_disabled");
	var ibi_collapsed = $("infobarimage_collapsed");
	var ibi_collapsed_disabled = $("infobarimage_collapsed_disabled");
	var ibi_collapsedoctoc = $("infobarimage_collapsedoctoc");
	var ibi_expanddoctoc = $("infobarimage_expanddoctoc");
	if ((mtf) && (mtf_disabled) && (p) && (p_disabled) && (ibi_collapsed) && 
      (ibi_collapsed_disabled) && (ibi_collapsedoctoc) && (ibi_expanddoctoc)) {		  	
	  if (allow) {	    
	    Element.hide(mtf_disabled);
	    if (printallowed) {
  	    Element.hide(p_disabled);
  	    Element.show(p);  
  	  }  	  
  	  Element.hide(ibi_collapsed_disabled);
  	  Element.show(mtf); 	  	        
	    Element.show(ibi_collapsed);	    	    
	    Element.hide(ibi_expanddoctoc); 	    
	    Element.show(ibi_collapsedoctoc);	    	         	  
	  } else {
	  	CollapseInfoBar();	
	    Element.hide(mtf);
	    if (printallowed) {
			  Element.hide(p);
			  Element.show(p_disabled);		
			}
			Element.hide(ibi_collapsed);
			Element.hide(ibi_collapsedoctoc);	 
			Element.hide(ibi_expanddoctoc);	  		
			Element.show(mtf_disabled);					
			Element.show(ibi_collapsed_disabled);			  
	  }
	} 
}

function OnBookError(event)
{
  $("booktitle").innerHTML = unescape(event.memo.message);
  $("documenttitle").innerHTML = event.memo.type;
}
  
function OnFavoriteDocumentUpdated(event) 
{      
  var docinfo_favorites = $("docinfo_favorites");
  var docinfo_addfavorite = frames["favoritesframe"].$("docinfo_addfavorite");
  var docinfo_addfavorite_textlabel = frames["favoritesframe"].$("docinfo_addfavorite_textlabel");
  
  
  var docinfo_favorites_disabled = $("docinfo_favorites_disabled");
  var docinfo_addfavorite_disabled = frames["favoritesframe"].$("docinfo_addfavorite_disabled");
  var docinfo_addfavorite_textlabel_disabled = frames["favoritesframe"].$("docinfo_addfavorite_textlabel_disabled"); 
   
  if (event.memo.IsDocument) {
    if (event.memo.IsFavorite) {
      Element.hide(docinfo_favorites);
      Element.hide(docinfo_addfavorite);
      Element.hide(docinfo_addfavorite_textlabel);
      Element.show(docinfo_favorites_disabled);
      Element.show(docinfo_addfavorite_disabled);
      Element.show(docinfo_addfavorite_textlabel_disabled);
      
      
    } else {     
      Element.hide(docinfo_favorites_disabled); 
      Element.hide(docinfo_addfavorite_disabled);   
      Element.hide(docinfo_addfavorite_textlabel_disabled);
      Element.show(docinfo_favorites);
      Element.show(docinfo_addfavorite);
      Element.show(docinfo_addfavorite_textlabel);
    }   
  } else {    
    Element.hide(docinfo_favorites_disabled);
    Element.hide(docinfo_addfavorite);
    Element.hide(docinfo_addfavorite_textlabel);
    Element.show(docinfo_favorites);
    Element.show(docinfo_addfavorite_disabled);
    Element.show(docinfo_addfavorite_textlabel_disabled);
  }
}
    
function AddFavorite()
{    
  Proxy.GetContext().UPlatform.Favorites.AddCurrent();
}

function MailToFriend()
{
  var currentbook = Proxy.GetContext().UPlatform.CurrentBook();
  if ((currentbook) && (currentbook.Document)) {
    var subjecttemplate = new Template(LanguageValues.MailTo.Subject);
    var bodytemplate = new Template(LanguageValues.MailTo.Body); 
    var parameters = {
      Name: unescape(Proxy.GetContext().MagmaLicense.GetValues().License.Name),
      ApplicationName: unescape(Proxy.GetValues().Application.Name),
      Url: Proxy.GetContext().UPlatform.GetDocumentDeepLink(),
      BookTitle: currentbook.Title,
      DocumentTitle: currentbook.Document.Title};    
    var subjecttext = subjecttemplate.evaluate(parameters);
    var bodytext = bodytemplate.evaluate(parameters);

    window.open("mailto: &subject=" + subjecttext + "&body=" + bodytext);	
  }
}
  
function PrintDocument()
{
  if (printallowed) {
    frames["publicationviewerframe"].frames["contentframe"].focus();
    frames["publicationviewerframe"].frames["contentframe"].print();
  } else {
    alert("Met deze licentie is afdrukken niet toegestaan");	
  }
}

function ExecuteBookCompiler(printtype)
{ 
  
  Proxy.GetContext().UPlatform.BookCompiler.Execute(printtype);	
  CollapseInfoBar();
}
  
function OnReleaseUpdated()
{
  var releasestatus = $('release_statusbar'); 
  var releasetextarea = $("release_text_area");
  if ((releasestatus) && (releasetextarea)) {
  	if (Proxy.GetContext().UPlatform.Release.GetValues() != null) {
      releasestatus.innerHTML = releasetextarea.innerHTML + " " + unescape(Proxy.GetContext().UPlatform.Release.GetValues().Release.DisplayRelease);
    }
  }
}
 
function OnLibraryUpdated() {
	
} 
  
function UpdateStatusBar()
{
  var lic_status = $("lic_statusbar");

  if (lic_status) {   
    lic_status.innerHTML = unescape(Proxy.GetContext().MagmaLicense.GetValues().License.Name); 
  }
}

function OnShowLinkManagement()
{
  if ((allowtogglelinkmanager) && ($("docinfo_linkmanagerarea").getAttribute("status") != "expanded")) {
    ExpandLinkManager();
  }
  var docinfo_linkmanager = $("docinfo_linkmanager");
  var docinfo_linkmanager_disabled = $("docinfo_linkmanager_disabled");
  if ((docinfo_linkmanager) && (docinfo_linkmanager_disabled)) {
    docinfo_linkmanager.style.display = "";	
    docinfo_linkmanager_disabled.style.display = "none";	
  }
}

function OnHideLinkManagement()
{
	if ((allowtogglelinkmanager) && ($("docinfo_linkmanagerarea").getAttribute("status") != "collapsed")) {
    CollapseLinkManager();
  }
	
	var docinfo_linkmanager = $("docinfo_linkmanager");
  var docinfo_linkmanager_disabled = $("docinfo_linkmanager_disabled");
  if ((docinfo_linkmanager) && (docinfo_linkmanager_disabled)) {
    docinfo_linkmanager.style.display = "none";	
    docinfo_linkmanager_disabled.style.display = "";	
  }    	
}

function ToggleLinkManager()
{
	var linkmanagerarea = $("docinfo_linkmanagerarea");
	if (linkmanagerarea.getAttribute("status") != "expanded") {
	  ExpandLinkManager();      	
	} else {
	  CollapseLinkManager();	
	}
}

function ExpandLinkManager() 
{ 
  if (allowtogglelinkmanager) {
	  var linkmanagerarea = $("docinfo_linkmanagerarea");
	  if (linkmanagerarea) { 
	  	if (linkmanagerarea.getAttribute("status") != "expanded") {	
	      Proxy.SingleInstance.Show("linkmanager"); 
	      linkmanagerarea.setAttribute("status","expanded");
	      allowtogglelinkmanager = false;
	      Effect.SlideDown(linkmanagerarea, {duration:0.5, afterFinish:function() {allowtogglelinkmanager=true;}});
	    }	
	  }
	}
}

function CollapseLinkManager()
{
  if (allowtogglelinkmanager) {
	  var linkmanagerarea = $("docinfo_linkmanagerarea");
	  if (linkmanagerarea){
	  	if (linkmanagerarea.getAttribute("status") != "collapsed") {
	      linkmanagerarea.setAttribute("status","collapsed");
	      allowtogglelinkmanager = false;
	      Effect.SlideUp(linkmanagerarea, {duration:0.5, afterFinish:function() {allowtogglelinkmanager=true;}});
	    }	
	  }	
	}
}

var _stopBlinkFileManagement = false;
function FileManagementAvailable(event)
{
	if ((event) && (event.memo.Enabled)) {
	  Element.show("docinfo_filemanagement");	
	  if (event.memo.Dirty == true) {	 
      _stopBlinkFileManagement = false;
	    DoBlinkFileManagement();	
	  } else {
      _stopBlinkFileManagement = true;
    }    
	} else {
	  Element.hide("docinfo_filemanagement");
	}
}

function DoBlinkFileManagement()
{
  var obj = $("docinfo_filemanagement");
  if (obj) {
    if (_stopBlinkFileManagement) {
      SmallFileManagement();
      _stopBlinkFileManagement = false;
    } else {
      if (obj.getAttribute("status") != "large") {
        LargeFileManagement(); 	
      } else {
        SmallFileManagement(); 		
      }	
      window.setTimeout("DoBlinkFileManagement()", 1000);	  
    }
  }      
}

function SmallFileManagement()
{
  var obj = $("docinfo_filemanagement");
	var n_elem = $(obj.id);
	var l_elem = $(obj.id + "_large");	
	
	n_elem.style.visibility = "visible";
	l_elem.style.display = "none";	
	obj.setAttribute("status", "small");	
}

function LargeFileManagement()
{
  var obj = $("docinfo_filemanagement");
  var id = obj.id
	var n_elem = $(id);
	var l_elem = $(id + "_large");	
	
	var lleft = Element.cumulativeOffset(n_elem).left - 10;
	var ltop = Element.cumulativeOffset(n_elem).top - 8;
	
	n_elem.style.visibility = "hidden";
	l_elem.style.left = lleft + "px";
	l_elem.style.top = ltop + "px";
	l_elem.style.display = "";		
	obj.setAttribute("status", "large");
}

function ToggleFileManagement()
{
	var vaultstoragearea = $("vaultstoragearea");
	if (vaultstoragearea.getAttribute("status") != "expanded") {
	  ExpandFileManagement();      	
	} else {
	  CollapseFileManagement();	
	}
}

function ExpandFileManagement() 
{  
  if (allowtogglefilemanagement) {
	  var vaultstoragearea = $("vaultstoragearea");
	  if (vaultstoragearea) { 
	  	if (vaultstoragearea.getAttribute("status") != "expanded") {
	  		Proxy.SingleInstance.Show("filemanagement");	
	      vaultstoragearea.setAttribute("status","expanded");
	      allowtogglefilemanagement = false;
	      Effect.SlideDown(vaultstoragearea, {duration:0.5, afterFinish:function() {allowtogglefilemanagement=true;}});
	    }	
	  }
	}
}

function CollapseFileManagement()
{
  if (allowtogglefilemanagement) {
	  var vaultstoragearea = $("vaultstoragearea");
	  if (vaultstoragearea){
	  	if (vaultstoragearea.getAttribute("status") != "collapsed") {
	      vaultstoragearea.setAttribute("status","collapsed");
	      allowtogglefilemanagement = false;
	      Effect.SlideUp(vaultstoragearea, {duration:0.5, afterFinish:function() {allowtogglefilemanagement=true;}});
	    }	
	  }	
	}
}


function ToggleOpenDocsArea()
{
	var docinfo_activedocs = $("docinfo_activedocs");
	if (docinfo_activedocs.getAttribute("status") != "expanded") {
	  ExpandOpenDocsArea();      	
	} else {
	  CollapseOpenDocsArea();	
	}
}

function ExpandOpenDocsArea() 
{  
  if (allowtoggleopendocs) {
	  var docinfo_activedocs = $("docinfo_activedocs");
	  if (docinfo_activedocs) { 
	  	if (docinfo_activedocs.getAttribute("status") != "expanded") {	
	  		Proxy.SingleInstance.Show("opendocsarea");
	      docinfo_activedocs.setAttribute("status","expanded");
	      allowtoggleopendocs = false;
	      Effect.SlideDown(docinfo_activedocs, {duration:0.5, afterFinish:function() {allowtoggleopendocs=true;}});
	    }	
	  }
	}
}

function CollapseOpenDocsArea()
{
  if (allowtoggleopendocs) {
	  var docinfo_activedocs = $("docinfo_activedocs");
	  if (docinfo_activedocs){
	  	if (docinfo_activedocs.getAttribute("status") != "collapsed") {
	      docinfo_activedocs.setAttribute("status","collapsed");
	      allowtoggleopendocs = false;
	      Effect.SlideUp(docinfo_activedocs, {duration:0.5, afterFinish:function() {allowtoggleopendocs=true;}});
	    }	
	  }	
	}
}

function ToggleFavorites()
{  
	var docinfo_favorites = $("docinfo_favoritesarea");
	if (docinfo_favorites.getAttribute("status") != "expanded") {
	  ExpandFavoritesArea();      	
	} else {
	  CollapseFavoritesArea();	
	}
}

function ExpandFavoritesArea() 
{  
  if (allowtogglefavorites) {
	  var docinfo_favorites = $("docinfo_favoritesarea"); 
	  if (docinfo_favorites) { 	 			
	  	if (docinfo_favorites.getAttribute("status") != "expanded") {	
	  		Proxy.SingleInstance.Show("favoritesarea");
	      allowtogglefavorites = false;
	      Effect.SlideDown(docinfo_favorites, {duration:0.5, afterFinish:function() {allowtogglefavorites=true;}});            
	      docinfo_favorites.setAttribute("status", "expanded");	     
	    }
	  }
	}
}

function CollapseFavoritesArea()
{
  if (allowtogglefavorites) {
	  var docinfo_favorites = $("docinfo_favoritesarea");
	  if (docinfo_favorites){       
	    if (docinfo_favorites.getAttribute("status") != "collapsed") {	
	    	allowtogglefavorites = false;
	      Effect.SlideUp(docinfo_favorites, {duration:0.5, afterFinish:function() {allowtogglefavorites=true;}});
	      docinfo_favorites.setAttribute("status", "collapsed");	
	    }	
	  }	
	}
}

function ToggleSlotLicense()
{  
	var docinfo_slotlicense = $("docinfo_slotlicensearea");
	if (docinfo_slotlicense.getAttribute("status") != "expanded") {
	  ExpandSlotLicenseArea();      	
	} else {
	  CollapseSlotLicenseArea();	
	}
}

function ExpandSlotLicenseArea() 
{  
  if (allowtoggleslotlicense) {
	  var docinfo_slotlicense = $("docinfo_slotlicensearea"); 
	  if (docinfo_slotlicense) { 	 			
	  	if (docinfo_slotlicense.getAttribute("status") != "expanded") {	
	  		Proxy.SingleInstance.Show("slotlicensearea");
	      allowtoggleslotlicense = false;
	      Effect.SlideDown(docinfo_slotlicense, {duration:0.5, afterFinish:function() {allowtoggleslotlicense=true;}});            
	      docinfo_slotlicense.setAttribute("status", "expanded");	     
	    }
	  }
	}
}

function CollapseSlotLicenseArea()
{
  if (allowtoggleslotlicense) {
	  var docinfo_slotlicense = $("docinfo_slotlicensearea");
	  if (docinfo_slotlicense){       
	    if (docinfo_slotlicense.getAttribute("status") != "collapsed") {	
	    	allowtoggleslotlicense = false;
	      Effect.SlideUp(docinfo_slotlicense, {duration:0.5, afterFinish:function() {allowtoggleslotlicense=true;}});
	      docinfo_slotlicense.setAttribute("status", "collapsed");	
	    }	
	  }	
	}
}

function ExpandInfoBar()
{
  if (allowtoggledocinfo) {
	  Proxy.SingleInstance.Show("infobar"); 
	  var docinfoextra =  $("docinfo_extra");
	  var img_expanded = $("infobarimage_expanded");
	  var img_collapsed = $("infobarimage_collapsed"); 	
	  if ((docinfoextra) && (img_expanded) && (img_collapsed)) {
	  	if (docinfoextra.getAttribute("status") != "expanded") {	
	      docinfoextra.setAttribute("status","expanded");
	      allowtoggledocinfo = false;
	      Effect.SlideDown(docinfoextra, {duration:0.5, afterFinish:function() {allowtoggledocinfo=true;}});
	      img_collapsed.style.display = "none";
	      img_expanded.style.display = "";      
	    }
	  }
	}
}


function CollapseInfoBar()
{
  if (allowtoggledocinfo) {
	  var docinfoextra =  $("docinfo_extra");	
	  var img_expanded = $("infobarimage_expanded");
	  var img_collapsed = $("infobarimage_collapsed"); 
	  if ((docinfoextra) && (img_expanded) && (img_collapsed)) {
	  	if (docinfoextra.getAttribute("status") != "collapsed") {
	  	  docinfoextra.setAttribute("status","collapsed");
	      allowtoggledocinfo = false;
	      Effect.SlideUp(docinfoextra, {duration:0.5, afterFinish:function() {allowtoggledocinfo=true;}});
	      img_collapsed.style.display = "";
	      img_expanded.style.display = "none";
	    }
	  }	
	}
}

function OverDocInfoButton(obj)
{
	var id = obj.id;
	if (id.indexOf("_large") != -1) {
		var n_elem = $(id.substr(0, id.indexOf("_large")));
	  var l_elem = $(id);  	
	} else {
	  var n_elem = $(id);
	  var l_elem = $(id + "_large");	
	}
	
	var lleft = Element.cumulativeOffset(n_elem).left - 10;
	var ltop = Element.cumulativeOffset(n_elem).top - 8;
	
	n_elem.style.visibility = "hidden";
	l_elem.style.left = lleft + "px";
	l_elem.style.top = ltop + "px";
	l_elem.style.display = "";	
}

function OutDocInfoButton(obj)
{
	var id = obj.id;
	if (id.indexOf("_large") != -1) {
		var n_elem = $(id.substr(0, id.indexOf("_large")));
	  var l_elem = $(id);  	
	} else {
	  var n_elem = $(id);
	  var l_elem = $(id + "_large");	
	}
	
	n_elem.style.visibility = "visible";
	l_elem.style.display = "none";	
}

function OnOverStatusItem(obj)
{
  obj.className = obj.className + "_hover";	
}

function OnOutStatusItem(obj)
{
  obj.className = obj.className.substr(0,obj.className.indexOf("_hover"));
}

function ClickLicense()
{
	var licarea = $("licarea");
	if (licarea) {
	  if (licarea.getAttribute("status") != "expanded") {
      Proxy.GetContext().MagmaLicense.UpdateValues();
	    ExpandLicArea();     
	  } else {
	    CollapseLicArea();	
	  }	
	}
}

function ExpandLicArea()
{ 
	var ph = parseInt(document.body.clientHeight);
	var pw = parseInt(document.body.clientWidth);
	var licarea = $("licarea");
	if (licarea) {
		if (licarea.getAttribute("status") != "expanded") {
			Proxy.SingleInstance.Show("licarea");
	    licarea.setAttribute("status","expanded");
	    licarea.style.display = "";
	    new Effect.Move(licarea, { x:(pw-Element.getWidth(licarea)-4), y:(ph - Element.getHeight(licarea)), mode:'absolute', duration:0.5});
	  }
	}
}

function CollapseLicArea()
{
	var ph = parseInt(document.body.clientHeight);
	var pw = parseInt(document.body.clientWidth);
	var licarea = $("licarea");
	if (licarea) {
		if (licarea.getAttribute("status") != "collapsed") {
	    licarea.setAttribute("status","collapsed");	    
	    new Effect.Move(licarea, { x:(pw-Element.getWidth(licarea)-4), y:ph, mode: 'absolute', afterFinish: function() { licarea.style.display='none';},duration:0.5});
	  }	
	}	
}

function ClickRelease()
{
	var releasearea = $("releasearea");
	if (releasearea) {
	  if (releasearea.getAttribute("status") != "expanded") {
	    ExpandReleaseArea();     
	  } else {
	    CollapseReleaseArea();	
	  }	
	}
}

function ExpandReleaseArea()
{  
	var ph = parseInt(document.body.clientHeight);
	var pw = parseInt(document.body.clientWidth);
	var releasearea = $("releasearea");
	if (releasearea) {
		if (releasearea.getAttribute("status") != "expanded") {
			Proxy.SingleInstance.Show("releasearea");
	    releasearea.setAttribute("status","expanded");
	    releasearea.style.display = "";
	    new Effect.Move(releasearea, { x:(pw-Element.getWidth(releasearea)-4), y:(ph - Element.getHeight(releasearea)), mode:'absolute', duration:0.5});
	  }
	}
}

function CollapseReleaseArea()
{
	var ph = parseInt(document.body.clientHeight);
	var pw = parseInt(document.body.clientWidth);
	var releasearea = $("releasearea");
	if (releasearea) {
		if (releasearea.getAttribute("status") != "collapsed") {
	    releasearea.setAttribute("status","collapsed");	    
	    new Effect.Move(releasearea, { x:(pw-Element.getWidth(releasearea)-4), y:ph, mode: 'absolute', afterFinish: function() { releasearea.style.display='none';},duration:0.5});
	  }	
	}	
}

function OnOverLinkButton(obj)
{
  obj.className = obj.className + "_hover";	
}

function OnOutLinkButton(obj)
{
	obj.className = obj.className.substr(0,obj.className.indexOf("_hover"));	
}


 function OnMainSearhKeyPress(event) 
{    
  if (event.keyCode == 13) {                  
    event.returnValue = false;
	  if (event.preventDefault) {
		  event.preventDefault();
	  }
	  try {			
  	  event.keyCode = 0;
	  } catch(e) {
	  }  
        
    OnMainSearch();      
  }
}

function OnMainSearch()
{
  var query;
  var queryfield = $("queryTextMain");    
  if (queryfield) {
    if (queryfield.GetValue) {
      query = queryfield.GetValue();
    } else if (queryfield.value) {
      query =  queryfield.value;
    }
  }  
  
  ShowSearchPage(query);    
}

function CollapseDocTree()
{
  var pvframe = frames["publicationviewerframe"];
  if (pvframe) {
    var fs = pvframe.$("publicationviewerframeset");
    if (fs) {
    	var ibic = $("infobarimage_collapsedoctoc");
    	var ibie = $("infobarimage_expanddoctoc");
    	if ((ibic) && (ibie)) {
    		Element.hide(ibic);
    		ibic.setAttribute("status","invisible");
    		Element.show(ibie);
    		ibie.setAttribute("status","visible");
        fs.cols = "0,*";	
      }
    }  	
  } 	
}

function ExpandDocTree()
{
  var pvframe = frames["publicationviewerframe"];
  if (pvframe) {
    var fs = pvframe.$("publicationviewerframeset");
    if (fs) {
      var ibic = $("infobarimage_collapsedoctoc");
    	var ibie = $("infobarimage_expanddoctoc");
    	if ((ibic) && (ibie)) {    		
    		Element.hide(ibie);
    		ibie.setAttribute("status","invisible");
    		Element.show(ibic);
    		ibic.setAttribute("status","visible");
        fs.cols = pvframe.oldcols;
      }
    }  	
  }   	
}

//  Show search page and start with optional query
function ShowSearchPage(query)
{
  var frame = null;
  var searchframe = Proxy.Frames.ByName("searchframe");
  var searchserviceframe = Proxy.Frames.ByName("searchserviceframe");      
    
  if ((Proxy.GetContext().UPlatform.Release.GetValues().Release.SearchServiceAvailable) &&
      (searchserviceframe != null)) {       
    frame = searchserviceframe;
    if (searchframe != null) {
      Element.hide(Proxy.Frames.ToObject(searchframe));
    }
    Element.show(Proxy.Frames.ToObject(searchserviceframe));    
  } else if (searchframe != null) {
    frame = searchframe;
    if (searchserviceframe != null) {
      Element.hide(Proxy.Frames.ToObject(searchserviceframe));
    }
    Element.show(Proxy.Frames.ToObject(searchframe));
  }
  
  if (frame != null) {    
    if ((typeof query == "string") && (query !== "") && (frame.$)) {
      var queryfield = frame.$("queryText");
      if (queryfield) {
        if (queryfield.SetValue) {
          queryfield.SetValue(query);
        } else if (queryfield.value) {
          queryfield.value = query;
        }
                
        if (frame.Execute) {
          frame.Execute();
        }        
      }
    }
    
    ShowPage("search");
  }
}