﻿// JScript File
var BeHelpVersion = "26.24";
var BcHelpVersion = "24.74";
var BeVersion = "26.24.36";
var BePublishDate = "January 27, 2010";
var sBeSetupSizeExe = "5.29 MB";
var sBeSetupSizeZip = "5.23 MB";

var iTopicID;
var sTopicTitle;

function rDisplayNews() {
           
      var ProductVer;
      var ProductVerText;
      var topicDivNode;
      var divParentNode = document.getElementById('TopicContentsNews');
      
      if (divParentNode == null) return;
      
      var divNoJavaScript = document.getElementById('NoJavaScript');
      if (divNoJavaScript != null){divNoJavaScript.innerHTML = '';}
      
      var objSelect = document.getElementById('bever');
      
      if (objSelect.value == "allver")
      {
        
        for (i=1;i < objSelect.options.length;i++) 
        {
           ProductVer = objSelect.options[i].value;
           ProductText = objSelect.options[i].text;
           topicDivNode = document.getElementById('verid_' + ProductVer);
	       if (topicDivNode == null){
             if(!AddNewsNodeAjaxSinc(ProductVer,ProductText,divParentNode)){
                 alert("Failed to load version=" + ProductVer);
                 return;
              }
	       }
        }
        DisplayAllDivWithPatt ('verid_',divParentNode);   
       } 
       else
       {
         ProductVer = objSelect.value;
         ProductText = objSelect.options[objSelect.selectedIndex].text;
         topicDivNode = document.getElementById('verid_' + ProductVer);
	     if (topicDivNode == null){
             if(!AddNewsNodeAjaxSinc(ProductVer,ProductText,divParentNode)){
                 alert("Failed to load version=" + ProductVer);
                 return;
              }
	     }
          
         DisplayDivWithPatt (ProductVer,'verid_',divParentNode);   
       }
}

function rDisplayTopic(TopicId,TopicTitle,NodeId,fToReplaceJs){
  var objNode = document.getElementById(NodeId);
  if (objNode == null)return;
  AddTopicTextAssinc(TopicId,objNode,TopicTitle,fToReplaceJs);
}

function rSetBeVersionAndDateDiv(xurl){
 
 
 if (xurl.substr(0,4) != "/be/") return;
 
 var div = document.getElementById("BeVerAndDate");
 if (div == null)return;
 
 var kiskos = "<img border=\"0\" src=\"/images/kiskoc.gif\" width=\"19\" height=\"20\" />"
 div.innerHTML = kiskos + "Version " + BeVersion + ", " + BePublishDate;


 if (xurl != "/be/bedownload.html") return;
 
 var div = document.getElementById("BeSetupSizeExe");
 

 if (div != null){div.innerHTML = sBeSetupSizeExe;}
 
 var div = document.getElementById("BeSetupExePublishDate");
 if (div != null){div.innerHTML = BePublishDate;}
 
 var div = document.getElementById("BeSetupSizeZip");
 if (div != null){div.innerHTML = sBeSetupSizeZip;}
 
 var div = document.getElementById("BeSetupZipPublishDate");
 if (div != null){div.innerHTML = BePublishDate;}
 
 // if url bever is set call download function right away
 var downloadBeVer = rGetUrlParameter("bever");
 if (downloadBeVer != ""){
   DownloadProductIdVerAjaxSinc('9060','',downloadBeVer);
 }
 
}

function rAddNewsSelectOptions(){
 var selNode = document.getElementById("bever");
 if (selNode == null)return;
 AddNewsSelectOptionsNodeAjaxSinc(selNode);
}

function rDisplayTopicContents() {

 var div = document.getElementById("TopicContents");
 if (div == null)return;
 
 if (div.innerHTML == ""){ 
  div.innerHTML = "<div id=\"PleaseWait\"><h2>Please wait: <img src=\"/images/ajax-loader.gif\" title=\"Loading...\"/></h2></div>";
 }
 
 if (iTopicID != null && sTopicTitle != null) {
 AddTopicTextAssinc(iTopicID,div,sTopicTitle,"1");
 }
 
}

function rDisplayContactLink(){
  var li = document.getElementById("liContactus");
  if (li == null)return;
  
  var sHtml;
  if (rGetCookie("LoggedIn") == "1") {
    sHtml = "<A href=\"/userprofile/updateinfo.aspx\">My Profile</A>";
  }
  else {
    sHtml = "<A href=\"/clickthrough/contactus.aspx\">Contact</A>";
  }
  
  li.innerHTML = sHtml;
  
  //alert("innerHTML: " + li.innerHTML);
  
}

function rGetTopicIdFromCookie(xurl) {
  // this is for BeHelp.html to display correct topic after refresh
  
  if (xurl != "/be/behelp.html") return ;
  TopicIdCur = rGetCookie("TopicID");
  
  if (TopicIdCur == null){
    TopicIdCur = 30; // introduction
  }
}

function rGetCatIdAndLibIdFromCookie(xurl) {
  
  if (xurl != "/belibraries/beexchange.html") return ;
  
  // get it from parameter first
  var LibOrCatId = rGetUrlParameter("LibOrCatID");
  
  if (LibOrCatId == ""){
    LibOrCatId = rGetCookie("LibOrCatID");
  }
  
  if (LibOrCatId == null) {
    CatIdCur=14;
    LibIdCur=0;
    
    return;
  }
  
  var arCookie = LibOrCatId.split("_");
  
  if (arCookie[0] == "LibID"){
    LibIdCur=arCookie[1];
    CatIdCur=0;
    //alert("LibIdCur=" + LibIdCur);
  }
  else {
    CatIdCur=arCookie[1];
    LibIdCur=0;
    //alert("CatIdCur=" + CatIdCur);
  }
}

function AdjustLogoDivs(){

 /*
  if (rfIsMSIE()) {
    var horizdiv = document.getElementById("HorizDiv");
    if (horizdiv == null) return;
    
    if (horizdiv.clientWidth < 480){
       horizdiv.style.width = 480;
    }
    else {
      horizdiv.style.width = "";
    }
    
    return false;
  }
  */
  if (rfIsMSIE()) return false;
  
  var xwidth = document.body.clientWidth; 
  
  var xdiv1 = document.getElementById("mbgLogo");
  
  if (xdiv1 == null) {
    xdiv1 = document.getElementById("BeLogo");
  }
  
  if (xdiv1 == null) {
    xdiv1 = document.getElementById("ExchLogo1");
  }
  
  if (xdiv1 == null) {
    xdiv1 = document.getElementById("BcLogo1");
  }

  if (xdiv1 == null) return;
  
  
  var xdiv2 = document.getElementById("HorizDiv");

  xdiv2.style.width = xwidth - xdiv1.offsetWidth;
}

function rOnDocumentLoad() {

  
  var xurl = GetCurrentDocumentName().toLowerCase();
  
  AdjustLogoDivs();
  
  rSetBeVersionAndDateDiv(xurl);
//  rDisplayTopicContents();
  rDisplayContactLink();
  //rDisplayNews();
  //rGetTopicIdFromCookie(xurl);
  //rGetCatIdAndLibIdFromCookie(xurl);
  
  
  var el = document.getElementById("HelpVer");
  if (el != null){el.value = BeHelpVersion;}
  
  rActivateTopRightArea(xurl);
  TraceUserActivityAjaxAsinc(xurl);
  rAddHelpContentsTree(xurl);
  rAddLibContentsTree(xurl);
}

function rAddProductToBasket(ProductID,quant,termid) {
   //alert("rAddProductToBasket ProductID: " + ProductID + "\nquant: " + quant + "\ntermid: " + termid); 
   if ((AddProductToBasketSinc(ProductID,quant,termid)) == true){
   
     rActivateTopRightArea();
     if (confirm("ProductID: " + ProductID + " was added to your shopping cart.\n\n Do you want to switch to shopping cart view?")){
     
       document.location.href="/store/viewcart.aspx";
       return;
     }
   }
   else {
       alert("Error adding product to shopping cart");
   }
}

function rActivateTopRightArea (xurl) {
  

  var div = document.getElementById("TopRightArea");
  if (div == null) return;
 
  var fHasShoppingCart = rGetCookie("HasShoppingCart");
      
  var fIsLoggedIn = rGetCookie("LoggedIn");
  
  if (xurl == null){
     xurl = GetCurrentDocumentName().toLowerCase();
  }
  
  var sHtml = "<a href=\"javascript:PrintThisPage();\" title=\"Print this content\"><img src=\"/images/printer.gif\" width=\"16\" height=\"16\"> Print</a> | ";
  
    
 if (fHasShoppingCart == "1") {
     sHtml = sHtml + "<a href=\"/store/viewcart.aspx\" title=\"View your shopping cart\"><img src=\"/mbgnav/style2/basket.gif\" width=\"18\" height=\"16\"> Shopping Cart</a> | ";
  }
     
 if (fIsLoggedIn == "1") {
      sHtml = sHtml + "<a href=\"javascript:rSignOff();\" title=\"Log out\">Log out</a>";
 }
 else {
     
     if (xurl == "/default.html" || xurl == "default.html"){xurl = "/be/../default.html";}
     sHtml = sHtml + "<a href=\"/userprofile/IdCurrentVisitor.aspx?RedirectTo=" + xurl + "\" title=\"Log in to view your profile\">Log in</a>";
 }

  div.innerHTML = sHtml;
  //alert("div.innerHTML" + div.innerHTML);
  
}

function rSignOff() {
  // delete cookie LoggedIn
  if (confirm("Do you want to log out from your account?")){
    rSetCookie("LoggedIn","0",0,"/");
  
    rActivateTopRightArea();
    rDisplayContactLink();
    var xurl = GetCurrentDocumentName().toLowerCase();
    if (xurl.substr(0,13) == "/userprofile/"){
      //window.history.forward(1);
      document.location.href = "/be/../default.html";
    }
    alert("You were logged out");
  }
}

// do we still use this ???
function PopTopicVer(xTopic, hlpver) {
   var HelpUrlScr;
   HelpUrlScr = "/products/DisplayHelpTopic.aspx?helptab=" + xTopic + "&hlpver=" + hlpver;
   
   if ((parent.frames.length > 0) && (top.frames[1].name == "header")) {
     document.location.href = HelpUrlScr;
   }
   else {
	 rPopUpAWindowWithHeight( "", "", HelpUrlScr, 600,500);
   }
}
  
function PopTopicIdVer(TopicID, hlpver,fPrint) {
    var HelpUrlScr;
    HelpUrlScr = "/products/DisplayHelpTopicId.aspx?topicid=" + TopicID + "&hlpver=" + hlpver + "&fPrint=" + fPrint;
   
    rPopUpAWindowWithHeight( "", "", HelpUrlScr, 600,500);
}
  
function PopVerTopicId(hlpver,TopicID) {
    var HelpUrlScr;
    HelpUrlScr = "/products/DisplayHelpTopicId.aspx?topicid=" + TopicID + "&hlpver=" + hlpver;
   
    rPopUpAWindowWithHeight( "", "", HelpUrlScr, 600,500);
}
  
function DisplayTab(xTab,iNoGUI) {
    var HelpUrlScr= "/be/be.html"
    
    if (xTab != '') HelpUrlScr = HelpUrlScr + "?tab=" + xTab;
   
    document.location.href = HelpUrlScr;
}

// do we still use this ???
function PopTopic(xTopic) {
   PopTopicVer(xTopic, BcHelpVersion); 
}
  
function PopTopicID(TopicID,fPrint) {
   PopTopicIdVer(TopicID, BeHelpVersion,fPrint); 
}

// do we still use this ???
function PopTip(tipno) {
   var HelpUrlScr;
   HelpUrlScr = "/products/DisplayHelpTopic.aspx?tipno=" + tipno + "&hlpver=" + BeHelpVersion;
   
   if ((parent.frames.length > 0) && (top.frames[1].name == "header")) {
     document.location.href = HelpUrlScr;
   }
   else {
	 rPopUpAWindowWithHeight( "", "", HelpUrlScr, 550,400);
   }
}

function PopFlashMovie(movid) {
   var HelpUrlScr;
   HelpUrlScr = "/bc/bcflash.aspx?movid=" + movid;
   rPopUpAWindowWithHeight( "", "", HelpUrlScr, 850,600 );
}
  
//=============== for behelp.html =====================
    
function rAddHelpContentsTree(xurl) {
  

    if (xurl != "/be/behelp.html") return ;
    
    var parentNode =  document.getElementById("treeRoot");

    if (parentNode == null)return;
    
    if (parentNode.childNodes.length > 0) return;
    
    var divNoJavaScript = document.getElementById('NoJavaScript');
    if (divNoJavaScript != null){divNoJavaScript.innerHTML = '';}
  
    parentNode.innerHTML = "<div id=\"PleaseWait\"><h2>Please wait: <img src=\"/images/ajax-loader.gif\" title=\"Loading...\"/></h2></div>";
 
    // call ajax to populate tree
    AddBeHelpTreeNodesAssinc("-1",parentNode);
    
    if (parentNode.childNodes.length > 0){
      
      rGetTopicIdFromCookie(xurl);
      
      DisplayTopic(TopicIdCur);
      
      //alert("CatIdCur: " + CatIdCur);

    }

}
  
function rAddHelpIndexNodes() {
  
    //if (xurl != "/belibraries/beexchange.html") return ;
    var parentNode =  document.getElementById("indexRoot");
    
    if (parentNode == null)return;
    
    if (parentNode.childNodes.length > 0) return;
        
    parentNode.innerHTML = "<div id=\"PleaseWait\"><h2>Please wait: <img src=\"/images/ajax-loader.gif\" title=\"Loading...\"/></h2></div>";
 
    // call ajax to populate tree
    return AddBeHelpTreeNodesAssinc("-2",parentNode);

}
  //=============== for beexchange.html =================
  
function rAddLibContentsTree(xurl) {
    if (xurl != "/belibraries/beexchange.html") return ;
    
    var parentNode =  document.getElementById("treeRoot");
    
    if (parentNode == null)return;
    
        
    if (parentNode.childNodes.length > 0) return;
    
    var divNoJavaScript = document.getElementById('NoJavaScript');
    if (divNoJavaScript != null){divNoJavaScript.innerHTML = '';}
  
    parentNode.innerHTML = "<div id=\"PleaseWait\"><h2>Please wait: <img src=\"/images/ajax-loader.gif\" title=\"Loading...\"/></h2></div>";
 
    // call ajax to populate tree
    AddLibOrCatTreeNodesAssinc("-1",parentNode);
    
    if (parentNode.childNodes.length > 0){
    
      if (CatIdCur == null && LibIdCurr == null){
        CatIdCur = 14;
      }
      
      //alert("CatIdCur: " + CatIdCur);
      rGetCatIdAndLibIdFromCookie(xurl);
      
      if (CatIdCur > 0)     DisplayCategory(CatIdCur);
      if (LibIdCur > 0)     DisplayLib(LibIdCur);
    }

}
  
function rAddLibIndexNodes() {
  
    //if (xurl != "/belibraries/beexchange.html") return ;
    var parentNode =  document.getElementById("indexRoot");
    
    if (parentNode == null)return;
    
    if (parentNode.childNodes.length > 0) return;
        
    parentNode.innerHTML = "<div id=\"PleaseWait\"><h2>Please wait: <img src=\"/images/ajax-loader.gif\" title=\"Loading...\"/></h2></div>";
 
    // call ajax to populate tree
    return AddLibOrCatTreeNodesAssinc("-2",parentNode);

}
  
    
function AddProductToBasket(ProductID){
	  		  
	  //var ProdIndex =  document.getElementById(ProductID + '_prodindex').value;
	  var TermID =  document.getElementById(ProductID + '_termid').value;
	  var Quant =  document.getElementById(ProductID + '_quant').value;
	  
	  rAddProductToBasket(ProductID,Quant,TermID);
	
	 //var xform =  document.getElementById(ProductID + '_recfrm');
	 // if (xform == null){
//		    return;
	//  }
	  	  
	  //xUrl = "/store/ViewCart.aspx?_action=additem&ProdIndex=" + ProdIndex +
	//	     "&ProductQuantity=" + Quant + "&SubscriptionTermID=" + TermID;
		  
	 // xform.action = xUrl;   
	 // xform.submit();
}
  
function DownloadProdID(ProductID) {
    DownloadProductIDAjaxSinc(ProductID);
}
  
function PopLibMovie(ProdIndex,WinWidth,WinHeight) {
   var LibUrlScr = "/Products/DisplayProductMovie.aspx?ProdIndex=" + ProdIndex;
   rPopUpAWindowWithHeight( "", "", LibUrlScr, WinWidth + 50,WinHeight + 120);
}
  
function PopLibrary(LibID, fPrint) {
    var HelpUrlScr;
    HelpUrlScr = "/belibraries/DisplayLibrary.aspx?ProductID=" + LibID + "&fNoGUI=1&fPrint=" + fPrint;
    rPopUpAWindowWithHeight( "", "", HelpUrlScr, 600,500);
}

// darken main screen and display specified div as panel

function DarkenDiv(divid) {
  var maindiv = document.getElementById(divid);
  
  if (rfIsMSIE()){
   maindiv.style.filter = "alpha(opacity=50)";
  }
  else {
   maindiv.style.opacity = "0.5";
  }
  
  //maindiv.style.background = 'Gray';
}

function RestoreDivOpacity(divid){
  var maindiv = document.getElementById(divid);
  
  if (rfIsMSIE()){
   maindiv.style.filter = "alpha(opacity=100)";
  }
  else {
   maindiv.style.opacity = "1";
  }
  //maindiv.style.background = '#FFFFFF';
}

function ShowDistictPanel(TopicID)
{
    var panelid = "topicid_" + TopicID;
    var xpanel = document.getElementById(panelid);
    var maindiv = document.getElementById('main');
    
    
    if (xpanel == null){
      // create div and load by ajax
      
      var divTopic = document.createElement('DIV');
      maindiv.appendChild(divTopic);
      divTopic.id= panelid;
      divTopic.style.display= "none";
      
      TagToTip(panelid);
    
      if (!AddTopicNodeAjaxAsinc2(TopicID,'',divTopic)){
         return;
      }
      
      UnTip();
    }
    
    
    TagToTip(panelid,WIDTH, 400,HEIGHT,450);
    
    //xpanel.style.display= 'none';
    
    
    DarkenMainDiv();
    return;

} 


