//*****************************************************
// Common functions for www.btg.nl
// Martin Mollet
//
// History:
// Date     By   Description
// -----------------------------------------------------
// 07aug07  MCM  Initial release, PrintModDate
// 24jan08  MCM  GetPageName implemented
// 11feb08  MCM  "BTG WebServices" removed
//
//
//
//
//
//******************************************************


//*****************************************************
// Globals
//*****************************************************
// arecExampProjs[] is ook globaal
var szLanguage = "NL";         // uppercase, default "NL"
var szPageName = "index";      // lowercase to prevent problems whit case-sens webservers
var szPageGroup = "HOME"       // uppercase
var szTestStr = "???"


//*****************************************************
// TYPE definition for MenuBar items
//*****************************************************
function TMenuBarItem (szPageId, szPageName, szCaption_NL, szCaption_EN, szCaption_DE)
{
   this.szPageId = szPageId;           // 
   this.szPageName = szPageName;       // HTML-pagename without extention, i.e. index gor index.html
   this.szCaption_NL = szCaption_NL;   // Texts to display
   this.szCaption_EN = szCaption_EN;
   this.szCaption_DE = szCaption_DE;
}


//*****************************************************
// TYPE definition for LeftSide items
//*****************************************************
function TLeftSideItem (szPageId, szPageName, szCaption_NL, szCaption_EN, szCaption_DE)
{
   this.szPageId = szPageId;           // Page group ID is used to determine hat is the currently active page (clickable linke or not) 
   this.szPageName = szPageName;       // HTML-pagename without extention, i.e. index gor index.html
   this.szCaption_NL = szCaption_NL;   // Texts to display
   this.szCaption_EN = szCaption_EN;
   this.szCaption_DE = szCaption_DE;
}


//*****************************************************
// Info for the MenuBar items
//*****************************************************
var arecMenuBarItems = new Array
(                    
   //                PageGroupID  HTML-name    Caption-NL            Caption-EN           Caption-DE
   new TMenuBarItem ("HOME",      "index",     "Home",               "Home",              "Home"),
   new TMenuBarItem ("COMP",      "compten",   "Competenties",       "Key Skills",        "Kompetenzen"),
   new TMenuBarItem ("TECH",      "technol",   "Technologieën",       "Technologies",     "Technologies #DUITS"),
 //new TMenuBarItem ("WERKW",     "werkwijze", "Werkwijze",          "How we Work",       "Arbeitsweise"),
   new TMenuBarItem ("PROJ",      "projects",  "Cases",              "Cases",             "Business-Cases"),
   new TMenuBarItem ("CONT",      "contact",   "Contact",            "Contact",           "Contact"),
   new TMenuBarItem ("JOBS",      "vacatures", "Vacatures",          "Jobs",              "Jobs")
)                                                                


//*****************************************************
// Info for the LeftSideMenu items
//*****************************************************
var arecLeftSideItems = new Array
(                                           
   //                 PageGroupID  HTML-name    Caption-NL            Caption-EN           Caption-DE
   new TLeftSideItem ("HOME",      "index",     "Home",               "Home",              "Home"),
   new TLeftSideItem ("COMP",      "compten",   "Competenties",       "Key Skills",        "Kompetenzen"),
   new TLeftSideItem ("TECH",      "technol",   "Technologieën",       "Technologies",     "Technologies #DUITS"),
 //new TLeftSideItem ("WERKW",     "werkwijze", "Werkwijze",          "How we Work",       "Arbeitsweise"),
   new TLeftSideItem ("PROJ",      "projects",  "Cases",              "Cases",             "Business-Cases"),
   new TLeftSideItem ("CONT",      "contact",   "Contact",            "Contact",           "Contact"),
   new TLeftSideItem ("JOBS",      "vacatures", "Vacatures",          "Jobs",              "Jobs")
)                                                                


//*****************************************************
// Info for the LeftSideMenu items: subs items
// the HTML-name is used as sub-ID
//*****************************************************
var arecLeftSideSubItems = new Array
(                            
   //                 PageGroupID  HTML-name       Caption-NL               Caption-EN              Caption-DE
   new TLeftSideItem ("PROJ",      "expr_agv",     "RFID positionering",    "RFID positioning",     "AGV #Duits"),
   new TLeftSideItem ("PROJ",      "expr_brug",    "Brugwachterspost",      "Remote Bridge control","Bridge #Duits"),
   new TLeftSideItem ("PROJ",      "expr_weigh",   "Etiket printer",        "Label printer",        "Label Printer #Duits"),
   new TLeftSideItem ("PROJ",      "expr_spm",     "Spreader positie",      "Spreader position",    "SPM #Duits"),
 //new TLeftSideItem ("PROJ",      "expr_icat",    "Robot sturing",         "Robot control",        "Robot sturing #Duits"),
   new TLeftSideItem ("PROJ",      "expr_boegs",   "Boegschroef testen",    "Bow thruster testing", "Boegschroef #Duits"),
   new TLeftSideItem ("PROJ",      "expr_kilt",    "Tolsysteem",            "Toll system",          "Tolsysteem #Duits"),
   new TLeftSideItem ("TECH",      "tech_rfid",    "RFID",                  "RFID",                 "RFID #Duits"),
   new TLeftSideItem ("TECH",      "tech_nfc",     "NFC",                   "NFC",                  "NFC #Duits"),
   new TLeftSideItem ("TECH",      "tech_webapp",  "Web applicaties",       "Web applications",     "WebApp #Duits"),
   new TLeftSideItem ("TECH",      "tech_pos",     "POS systemen",          "POS systems",          "POS #Duits")
)                                                                





//*****************************************************
// Set Language
//    valid options: "NL" , "EN" ,"DE""
//    will be translated to uppercase
//    all others will result in "NL"
//*****************************************************
function SetLanguage (szLang)
{
   szLanguage = szLang.toUpperCase();

   if ( (szLanguage!="NL") &&  (szLanguage!="EN") && (szLanguage!="DE") )
      szLanguage = "NL";

   setCookie("BTG_LANGUAGE", szLang, new Date(2020,1,1));
}


//*****************************************************
// Get Language from cookie into global szLanguage
//*****************************************************
function GetLanguage ()
{
   var szLang = getCookie('BTG_LANGUAGE');

   if ( (szLang!="NL") &&  (szLang!="EN") && (szLang!="DE") )
      szLang = "NL";

   szLanguage = szLang;
}


//*****************************************************
// Set Page Name
//
//   szBaseName : used to generate "basename_NL.html"
//   szGroup : determines which menu-item is "blacked-out"
//      szGroup should one of the groupnames used in
//      arecMenuBarItems OR an empty string ("").
//*****************************************************
function SetPageName(szBaseName, szGroup)
{
   szPageName = szBaseName.toLowerCase();
   szPageGroup = szGroup.toUpperCase();

   szPageName = GetPageName(); // test of dit ook automatisch kan ipv mbv deze routine zetten
}


//*****************************************************
//
// Get pagename of HTML page
//   returns HTML pagename "http://www.sever.nl/pagename.html?param=1"
//   returns "index?" if url end with '/' like "http://www.sever.nl/btg/"
//
// not related to the variables of SetPageName !!!
//*****************************************************
function GetPageName ()
{
   //var url = document.URL;
   //var url = window.location.href;
   var url = location.href;
   var iBegin = url.lastIndexOf('/') + 1;
   var iHekje = url.indexOf('#', iBegin);
   var iVraagt = url.indexOf('?', iBegin);
   var iPunt = url.indexOf('.', iBegin);
   var sPageName = "?";

   if (-1 == iHekje)  iHekje = url.length;
   if (-1 == iVraagt) iVraagt = url.length;
   if (-1 == iPunt)   iPunt = url.length;

   if (url.lastIndexOf('/') == url.length-1)
      sPageName = "index?";
   else
      sPageName = url.substring(iBegin, Math.min(iHekje, iVraagt, iPunt));

   //document.writeln( " [>" + sPageName + "<]");
   return (sPageName);
}


//*****************************************************
// Get URL Variables
//*****************************************************
function GetUrlVars()
{
   //Make array of parameterstrings , skip '?' 
   var UrlParameters = location.search.substr(1).split("&"); 

   //Process them one-by one 
   for(var i = 0; i < UrlParameters.length; i++) 
   { 
      // Seperate Teag and Value 
      var UrlParam = UrlParameters[i].split("="); 
     
      if (UrlParam[0] != "")
      {
         switch(UrlParam[0].toUpperCase()) 
         {
            case "LANG":
               szLanguage = UrlParam[1].toUpperCase();
               if ( (szLanguage!="NL") &&  (szLanguage!="EN") && (szLanguage!="DE") )
                  szLanguage = "NL";
               break
   
            case "TEST":
               szTestStr = UrlParam[1];
               break
   
            default:
               alert ("URL-Tag unknown: >" + UrlParam[0] + "<");
         }
      }
   } 
}


//*****************************************************
// Prints Header images
//*****************************************************
function PrintHeaderImages ()
{
  if (szPageGroup == "HOME")
  {         
     document.writeln("<DIV STYLE='width:920px; height:213px; position:relative; background-image:url(images/header_bg_high_strong.jpg); background-repeat:no-repeat;'>");
     document.writeln("<SPAN STYLE='position:absolute; top:5px; left:60px; z-index:99; width:343px; height:212px; background:url(images/transpimg.png) no-repeat !important;;'></SPAN>");
//     document.writeln("<SPAN STYLE='position:absolute; top:12px; left:130px; z-index:98; width:343px; height:212px; background:url(images/tc3.png) no-repeat !important;;'></SPAN>");
     document.writeln("<DIV class='clr'></DIV>");
     document.writeln("</DIV>");
  }
  else
  {
     document.writeln("<DIV STYLE='width:920px; height:110px; position:relative; background-image:url(images/header_bg_low_strong.jpg); background-repeat:no-repeat;'>");
     //document.writeln("<SPAN STYLE='position:absolute; top:17px; left:66px; z-index:99; width:343px; height:212px; background:url(images/transpimg.png) no-repeat !important;;'></SPAN>");
     document.writeln("<DIV class='clr'></DIV>");
     document.writeln("</DIV>");
  }
}


//*****************************************************
// Prints modification date in our format      ###TAAL
// but only if date format seems OK            
//*****************************************************
function PrintModDate ()
{
   var szShortMonthNL = new Array("januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"); 
   var szShortMonthEN = new Array("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december"); 
   var szShortMonthDE = new Array("Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"); 

   iDay   = parseFloat(document.lastModified.substr(3,2));
   iMonth = parseFloat(document.lastModified.substr(0,2));
   iYear =  parseInt(document.lastModified.substr(6,4));

   if ( (iDay>0) && (iDay<=31) && (iMonth>0) && (iMonth<=12) && (iYear>=2000) && (iYear<3000) )
   {
      document.write(iDay + " ");
      switch(szLanguage)
      {
         case "EN": // ###EN
            document.write(szShortMonthEN[iMonth-1]);
            break;
         case "DE": // ###DE
            document.write(szShortMonthDE[iMonth-1]);
            break;
         default: // ###NL
            document.write(szShortMonthNL[iMonth-1]);
            break;
      }
      document.write(" " + iYear);

      /*
      document.writeln(" >>> Lang= " + szLanguage);
      document.writeln(" , PageName= " + szPageName);
      document.writeln(" , PageGroup= " + szPageGroup + " <<<");
      */
      document.write("<BR>");
   }
   else
      document.writeln("Unknown date format:" + document.lastModified);
}


//*****************************************************
// Print language flags
// 
//*****************************************************
function PrintLanguageFlags ()   
{
   if ((szLanguage=="EN") || (szLanguage=="DE"))
      document.writeln("<A HREF='javascript:history.go(0)'> <IMG SRC='images/vlag_nl.png' onclick='SetLanguage(\"NL\");' BORDER=0 TITLE='Nederlands' ALT='Nederlands'></A>");

   if (szLanguage!="EN")
      document.writeln("<A HREF='javascript:history.go(0)'> <IMG SRC='images/vlag_en.png' onclick='SetLanguage(\"EN\");' BORDER=0 TITLE='English' ALT='English'></A>");
/* waiting for German translation 
   if (szLanguage!="DE")
      document.writeln("<A HREF='javascript:history.go(0)'> <IMG SRC='images/vlag_de.png' onclick='SetLanguage(\"DE\");' BORDER=0 TITLE='Deutsch' ALT='Deutsch'></A>");
*/
}


//*****************************************************
// Print Menubar Items
// 
//*****************************************************
function PrintMenuItems ()
{
   var iNumberOfMenuBarItems= arecMenuBarItems.length;
   var i;
   var fValidPageGroup = false;

   document.write("<UL>");

   for (i=0; i < iNumberOfMenuBarItems ;i++)
   {                
      if (arecMenuBarItems[i].szPageId == szPageGroup)
      { // current (active) page
         fValidPageGroup = true;
         document.write("<li class='active'>");
         switch (szLanguage)
         {
            case "EN":  document.write(arecMenuBarItems[i].szCaption_EN); break;
            case "DE":  document.write(arecMenuBarItems[i].szCaption_DE); break;
            default:    document.write(arecMenuBarItems[i].szCaption_NL); break;
         }
         document.writeln("</li>");
      }
      else
      {
         document.write("<li><a href='" + arecMenuBarItems[i].szPageName + ".html'>");
         switch (szLanguage)
         {
            case "EN":  document.write(arecMenuBarItems[i].szCaption_EN); break;
            case "DE":  document.write(arecMenuBarItems[i].szCaption_DE); break;
            default:    document.write(arecMenuBarItems[i].szCaption_NL); break;
         }
         document.writeln("</a></li>");
      }
   }

   if ((!fValidPageGroup) && (szPageGroup!="")) 
      alert("Pagegroup (" + szPageGroup + ") is not a valid groupname !");

   document.write("</UL>");
}


//*****************************************************
// Returns true if LeftSide Menu has sub-items
// 
//*****************************************************
function LeftMenuHasSubItems (szMenuItem)
{
   var iSub; // Submenu Index
   var fHasSubItems = false;

   for (iSub=0; iSub < arecLeftSideSubItems.length ;iSub++)
   {
      if (arecLeftSideSubItems[iSub].szPageId == szMenuItem)
      {  // found submenu item !
         fHasSubItems = true;
      }
   } 
   return fHasSubItems;
}


//*****************************************************
// Returns true if LeftSide Menu has a selected sub-items
// 
//*****************************************************
function LeftMenuHasSelectedSubItem (szMenuItem)
{
   var iSub; // Submenu Index
   var fHasSelectedSubItem = false;

   for (iSub=0; iSub < arecLeftSideSubItems.length ;iSub++)
   {
      if ( (arecLeftSideSubItems[iSub].szPageId == szMenuItem) && (arecLeftSideSubItems[iSub].szPageName==szPageName) )
      {  // found submenu item !
         fHasSelectedSubItem = true;
      }
   } 
   return fHasSelectedSubItem;
}


//*****************************************************
// Print LeftSide Menu-Items
// 
//*****************************************************
function PrintLeftMenuItems ()
{
   var i;
   var iSub; // Submenu Index

   document.writeln("<UL ID='mainlevel'>");

   for (i=0; i < arecLeftSideItems.length ;i++) // print all menu items
   { // for all menu-items           
    
      // check if it's (the current page) AND (item has NO selected subitem)
      if ( (arecLeftSideItems[i].szPageId == szPageGroup) && (!LeftMenuHasSelectedSubItem(arecLeftSideItems[i].szPageId)) )
      { // this item is NOT the currently ACTIVE page: print the menu-item link 
         // print menu item without link
         document.write("<li class='active'>");
         switch (szLanguage) // print the right language menu-item caption
         {
            case "EN":  document.write(arecLeftSideItems[i].szCaption_EN); break;
            case "DE":  document.write(arecLeftSideItems[i].szCaption_DE); break;
            default:    document.write(arecLeftSideItems[i].szCaption_NL); break;
         }
         document.writeln("</li>");
      }
      else
      { // this item is the current (ACTIVE) page: print NOT clickable menu-item  
         // print the menu-item link 
         document.write("<li><a href='" + arecLeftSideItems[i].szPageName + ".html' class='mainlevel'>");
         switch (szLanguage) // print the right langage caption
         {
            case "EN":  document.write(arecLeftSideItems[i].szCaption_EN); break;
            case "DE":  document.write(arecLeftSideItems[i].szCaption_DE); break;
            default:    document.write(arecLeftSideItems[i].szCaption_NL); break;
         }
         document.writeln("</a></li>");
      }

      // any sub-menu-item's in current item?   
      if ( (arecLeftSideItems[i].szPageId == szPageGroup) && (LeftMenuHasSubItems(arecLeftSideItems[i].szPageId)) ) 
      { // print sub-menu items
         document.writeln("<UL>"); 
         for (iSub=0; iSub < arecLeftSideSubItems.length ;iSub++)
         {
            if (arecLeftSideSubItems[iSub].szPageId == szPageGroup)
            {
               // is current sub-menu item the currently ACTIVE one ?
               if (arecLeftSideSubItems[iSub].szPageName==szPageName)
               { // current sub-menu-item is the currently ACTIVE one: print non-clickable caption 
                  document.write("<li class='active'>");
                  switch (szLanguage) // print the right language sub-menu-itemcaption
                  {
                     case "EN":  document.write(arecLeftSideSubItems[iSub].szCaption_EN); break;
                     case "DE":  document.write(arecLeftSideSubItems[iSub].szCaption_DE); break;
                     default:    document.write(arecLeftSideSubItems[iSub].szCaption_NL); break;
                  }
                  document.writeln("</li>");
               }
               else 
               { // item is not the current one: print clcikable link
                  document.write("<li><a href='" + arecLeftSideSubItems[iSub].szPageName + ".html' class='mainlevel'>");
                  switch (szLanguage) // print the right language sub-menu-itemcaption
                  {
                     case "EN":  document.write(arecLeftSideSubItems[iSub].szCaption_EN); break;
                     case "DE":  document.write(arecLeftSideSubItems[iSub].szCaption_DE); break;
                     default:    document.write(arecLeftSideSubItems[iSub].szCaption_NL); break;
                  }
                  document.writeln("</a></li>");
               }
            }
         } 
         document.writeln("</UL>");
      } // print sub-menu items

   } // for all menu-items

   document.writeln("</UL>");
}


//*****************************************************
// Print Address
// 
//*****************************************************
function PrintAddress()
{
   switch (szLanguage) // print the right langage caption
   {
      case "EN": // English address 
         document.writeln("BTG Electronics Design B.V.<BR>");
         document.writeln("Anthony Fokkerstraat 21<BR>");
         document.writeln("3261 LB Oud-Beijerland<BR>");
         document.writeln("The Netherlands<BR>");
         document.writeln("phone +31 (0)186-641250<BR>");
         document.writeln("fax.  +31 (0)186-641251<BR>");
         document.writeln("K.v.K. 24375374<BR>");
         break;

      case "DE": // German address  
         document.writeln("BTG Electronics Design B.V.<BR>");
         document.writeln("Anthony Fokkerstraat 21<BR>");
         document.writeln("3261 LB Oud-Beijerland<BR>");
         document.writeln("Niederlande<BR>");
         document.writeln("tel. +31 (0)186-641250<BR>");
         document.writeln("fax. +31 (0)186-641251<BR>");
         document.writeln("K.v.K. 24375374<BR>");
         break;

      default: // local address
         document.writeln("BTG Electronics Design B.V.<BR>");
         document.writeln("Anthony Fokkerstraat 21<BR>");
         document.writeln("3261 LB Oud-Beijerland<BR>");
         document.writeln("tel. 0186-641250<BR>");
         document.writeln("fax. 0186-641251<BR>");
         document.writeln("K.v.K. 24375374<BR>");
         break;
   }
}


//*****************************************************
// Print Footer Items
// 
//*****************************************************
function PrintFooterItems ()
{
   switch(szLanguage)
   {
      case "EN": // ###EN
         document.writeln("<a href='voorw.html'>Terms & conditions</a> |");
         document.writeln("<a href='contact.html'>Contact</a> |");
         document.writeln("<a href='sitemap.html'>Sitemap</a>");
         break;

      case "DE": // ###DE
         document.writeln("<a href='voorw.html'>Bedingungen</a> |");
         document.writeln("<a href='contact.html'>Contact</a> |");
         document.writeln("<a href='sitemap.html'>Sitemap</a>");
         break;

      default: // ###NL
         document.writeln("<a href='voorw.html'>Voorwaarden</a> |");
         document.writeln("<a href='contact.html'>Contact</a> |");
         document.writeln("<a href='sitemap.html'>Sitemap</a>");
         break;
   }  
}


//*****************************************************
// Print Wrapper Footer Items
// 
//*****************************************************
function PrintWrapperFooterItems ()
{

   switch(szLanguage)
   {
      case "EN": // ###EN
         document.writeln("Design &copy; BTG Electronics Design BV. All rights reserved. Last modification:");
         PrintModDate();
         document.writeln("<BR>");
         break;

      case "DE": // ###DE
         document.writeln("Design &copy; BTG Electronics Design BV. Alle rechten voorbehouden DUITS !!!. Laatste Wijziging:");
         PrintModDate();
         document.writeln("<BR>");
         break;

      default: // ###NL
         document.writeln("Design &copy; BTG Electronics Design BV. Alle rechten voorbehouden. Laatste Wijziging:");
         PrintModDate();
         document.writeln("<BR>");
         break;
   }
}



//*****************************************************
// PrintPagina maakt een nieuwe printvriendelijke pagina
// van alles dat tussen <DIV ID="PrintKlaar"> DIT DUS </DIV> staat
//
// aanroepen met B.V. <a href="javascript:void(PrintPagina())">Print/a>
//
//*****************************************************
function PrintPagina()
{
   if (document.getElementById != null)
   {
      var html = '<HTML>\n<HEAD>\n';      
      if (document.getElementsByTagName != null)
      {
         var headTags = document.getElementsByTagName("head");
         if (headTags.length > 0)
            html += headTags[0].innerHTML;
      }                                     
      html += '\n</HE' + 'AD>\n<BODY>\n';
      var PrintKlaarElem = document.getElementById("PrintKlaar");
      if (PrintKlaarElem != null)
      {
         html += PrintKlaarElem.innerHTML;
      }
      html += '\n</BO' + 'DY>\n</HT' + 'ML>';
      var printWin = window.open("","PrintPagina");
      printWin.document.open();
      printWin.document.write(html);
      printWin.document.close();
      printWin.print();
   }
}







//########################################################################
//
// Example Project routines 
// (to displey random examples in the right column)
//
//########################################################################


//*****************************************************
// TYPE definition for RightSide ExampleProjects
//  Image widths should be 158px
//  NL, EN and DE texts should be the same number of lines !
//*****************************************************
function TExampleProject (szExampCode, szHeader, szImageName, iImageHeight, szImageTitle, szText, iHeight, fDisplayed, szHeader_EN, szImageTitle_EN, szText_EN, szHeader_DE, szImageTitle_DE, szText_DE)
{
   this.szExampCode = szExampCode;           // Example code, used for generating HTML-filename of example project page 
   this.szImageName = szImageName;           // Image filename
   this.iImageHeight = iImageHeight;         // Height of image (if image is not loaded yet and actual height is still unknown)
   this.szHeader = szHeader;                 // Header text placed above the image
   this.szHeader_EN = szHeader_EN;           // Header English
   this.szHeader_DE = szHeader_DE;           // Header German
   this.szImageTitle = szImageTitle;         // Title for image, used for ALT or TITLE text
   this.szImageTitle_EN = szImageTitle_EN;   // Title English
   this.szImageTitle_DE = szImageTitle_DE;   // Title German
   this.szText = szText;                     // Text place below the image 
   this.szText_EN = szText_EN;               // Text English
   this.szText_DE = szText_DE;               // Text German
   this.iHeight = iHeight;                   // Height of total rightside block (title+image+text): see if(0) in DisplayExampleProjects()
   this.fDisplayed = fDisplayed;             // true means that this project has been displayed on this page
}


//*****************************************************
// Info for the example projects
//*****************************************************
var arecExampProjs = new Array
(
   new TExampleProject ("expr_agv"   , "AGV positie bepalen" , "expr_agv.jpg" , 57 , "ECTs Delta terminal, Maasvlakte" , "Met behulp van op RF-ID gebaseerde technieken wordt de positie van een Automatisch Geleid Voertuig op de mm nauwkeurig bepaald." , 168 , false,"AGV Positioning", "ECT Delta-terminal", "Determining position for Automatic Guided Vehicles with millimeter accuracy, based on custom developed RF-ID technologies.", "szHeader_DE", "szImageTitle_DE", "szText_DE"),
   new TExampleProject ("expr_brug"  , "Centrale brug besturing" , "expr_spoorbrug.png", 58 , "Spoorbrug, Alphen a/d Rijn" , "Op afstand meerdere bruggen bedienen met de veiligheid van een lokale noodstopknop." , 143 , false,"Remote Bridge control", "Remoltely controlled bridge", "Controlling several bridges remotely with the safety of a local emergency stop.", "szHeader_DE", "szImageTitle_DE", "szText_DE"),
   new TExampleProject ("expr_weigh" , "Etiket printer" , "expr_weigh.png", 79 , "Kaas, champignons en vleeswaren: verpakt en gewogen" , "Tijdens het productieproces op volle snelheid wegen en etiketteren met een nauwkeurigheid van 0,5 gram." , 177 , false,"Label printer", "Weighed and labeled products", "During full speed production weighing and labeling products without additional wait time when changing product.", "szHeader_DE", "szImageTitle_DE", "szText_DE"),
   new TExampleProject ("expr_spm"   , "Spreader positie meting" , "expr_spm.jpg" , 86 ,  "Spreader met container eronder" , "Een IR optisch meetsysteem om te bepalen waar de container zich bevind maakt het mogelijk om de slingering te compenseren." , 184 , false,"Spreader positioning","A spreader holding a container", "An IR optical measurement- system to determine where a spreader is located used for compensating swinging.", "szHeader_DE", "szImageTitle_DE", "szText_DE"),
// new TExampleProject ("expr_icat"  , "iCat, robot-kat" , "expr_icat.jpg" , 62 , "iCat de robot-kat" , "USB aangestuurde robot kat, onderzoeksplatform voor mens -robot interacties." , 147 , false,"I-Cat the Robot-cat", "I-Cat the Robot-cat", "USB controlled robot-cat as research tool for human-machine interfaces.", "szHeader_DE", "szImageTitle_DE", "szText_DE"),
   new TExampleProject ("expr_boegs" , "Boegschroeven testen" , "expr_boegs.jpg" , 62 , "Boegschroef testen" , "Automatisch boegschroef motoren testen op koppel en stroomopname prestaties." , 147 , false,"Bow thrusters testing", "Bow thruster", "Automated electrical bow thruster motor testing for torque and current performance.", "szHeader_DE", "szImageTitle_DE", "szText_DE"),
   new TExampleProject ("expr_kilt"  , "Tolsysteem Kiltunnel" , "expr_kilt.jpg" , 78 , "Kiltunnel, Dordrecht" , "Met een RF-ID kaart snel en makkelijk betalen: lagere tarieven en hogere doorstroming." , 163 , false,"Kiltunnel toll system", "Kiltunnel, Dordrecht", "Paying fast and easy with a RFID card: Lower prices and higher traffic throughput.", "szHeader_DE", "szImageTitle_DE", "szText_DE")
)
 

//*****************************************************
// Display a list of example projects 
//*****************************************************
function DisplayExampleProjectList ()
{
   var iNumberOfExampProjs= arecExampProjs.length;

   for (i=0; i < iNumberOfExampProjs ;i++)
   {
      document.writeln('<BR>');
      switch (szLanguage)
      {
         case "EN": 
            document.writeln('<A HREF="' + arecExampProjs[i].szExampCode + '.html">' + arecExampProjs[i].szHeader_EN + '</A> - ' + arecExampProjs[i].szText_EN + '<BR>');
            break;

         case "DE": 
            document.writeln('<A HREF="' + arecExampProjs[i].szExampCode + '.html">' + arecExampProjs[i].szHeader_DE + '</A> - ' + arecExampProjs[i].szText_DE + '<BR>');
            break;

         default:   
            document.writeln('<A HREF="' + arecExampProjs[i].szExampCode + '.html">' + arecExampProjs[i].szHeader + '</A> - ' + arecExampProjs[i].szText + '<BR>');
            break;
      }
   }
}


//*****************************************************
// Get print position of RightBlock 
//*****************************************************
function GetUsedHeightRightBlock ()
{
   document.writeln("offsetheight = " + document.getElementById("rightblock").offsetHeight + " scrollheight="+ document.getElementById("rightblock").scrollHeight + ".");
}


//*****************************************************
// Draw one example projects
//*****************************************************
function DisplayExampleProject (iNum)
{
   var iNumberOfExampProjs= arecExampProjs.length;

   if ( (iNum<0) || (iNum>=iNumberOfExampProjs) )
   {
      document.writeln("ExampProjNum [" + iNum + "] is not valid !"); 
   }
   else
   {
      // document.writeln("display[" + iNum + "]<BR>");
      document.writeln('                        <DIV class="module">');
      document.writeln('                           <DIV>');
      document.writeln('                              <DIV>');
      document.writeln('                                 <DIV>');
      switch (szLanguage)
      {
         case "EN":  document.writeln('                                    <h3>' + arecExampProjs[iNum].szHeader_EN + '</h3>'); break;
         case "DE":  document.writeln('                                    <h3>' + arecExampProjs[iNum].szHeader_DE + '</h3>'); break;
         default:    document.writeln('                                    <h3>' + arecExampProjs[iNum].szHeader + '</h3>'); break;
      }
      
      switch (szLanguage)
      {
         case "EN": document.writeln('                                    <A HREF="' + arecExampProjs[iNum].szExampCode + '.html"> <IMG SRC="images/' + arecExampProjs[iNum].szImageName + '" BORDER=0 HEIGHT="' + arecExampProjs[iNum].iImageHeight + '" WIDTH=158 ALIGN="LEFT" ALT="' + arecExampProjs[iNum].szImageTitle_EN + '" TITLE="' + arecExampProjs[iNum].szImageTitle_EN + '"></A>');
            break;
         case "DE": document.writeln('                                    <A HREF="' + arecExampProjs[iNum].szExampCode + '.html"> <IMG SRC="images/' + arecExampProjs[iNum].szImageName + '" BORDER=0 HEIGHT="' + arecExampProjs[iNum].iImageHeight + '" WIDTH=158  ALIGN="LEFT" ALT="' + arecExampProjs[iNum].szImageTitle_DE + '" TITLE="' + arecExampProjs[iNum].szImageTitle_DE + '"></A>');
            break;
         default: document.writeln('                                    <A HREF="' + arecExampProjs[iNum].szExampCode + '.html"> <IMG SRC="images/' + arecExampProjs[iNum].szImageName + '" BORDER=0 HEIGHT="' + arecExampProjs[iNum].iImageHeight + '" WIDTH=158  ALIGN="LEFT" ALT="' + arecExampProjs[iNum].szImageTitle + '" TITLE="' + arecExampProjs[iNum].szImageTitle + '"></A>');
            break;
      }

      document.writeln('                                      <BR CLEAR=ALL>');

      switch (szLanguage)
      {
         case "EN": document.writeln('                                    ' + arecExampProjs[iNum].szText_EN); 
            break;
         case "DE": document.writeln('                                    ' + arecExampProjs[iNum].szText_DE);
            break;
         default: document.writeln('                                    ' + arecExampProjs[iNum].szText); 
            break;
      }

      document.writeln('                                 </DIV>');
      document.writeln('                              </DIV>');
      document.writeln('                           </DIV>');
      document.writeln('                        </DIV>');
      if (arecExampProjs[iNum].fDisplayed) alert ("Afb[" + iNum + "]was al gedisplayed");
      arecExampProjs[iNum].fDisplayed = true;
   }

}


//*****************************************************
// Clear all ExampProjs to "not displayed" 
//*****************************************************
function ClearAllExampleProjectDisplayed()
{
   var iNumberOfExampProjs= arecExampProjs.length;
   var i;

   for (i=0; i < iNumberOfExampProjs ;i++)
   {                
      arecExampProjs[i].fDisplayed = false;
   }

}


//*****************************************************
// Fill RightBlock with example projects 
//*****************************************************
function DisplayExampleProjects ()
{
   var iNumberOfExampProjs= arecExampProjs.length;
   var fDone = false;               // true= filling right block is ready 
   var iDisplayThis = 0;            // Random number, selects one of the projects that is fitting AND not already displayed  
   var iCentreBlockHeight = 0;      // Height of Centreblock (= total available space, use whatever is max)
   var iLeftBlockHeight = 0;        // Height of Leftblock   (= total available space, use whatever is max)
   var iRightBlockHeight = 0;       // space used
   var iAvailableHeight =  0;       // space left
   var iAvailableFitting = 0;       // number of exampleprojects that fit in tha available space AND is not displayed yet

   if (0)
   {  // this is for test !
      // use this to determine height of an example project
      // turn on 2 then 1 more and record the diff in height
      DisplayExampleProject(1);
      DisplayExampleProject(0); 
      //DisplayExampleProject(4); 
      GetUsedHeightRightBlock();
   }
   else
   {  // this is the real deal !
      ClearAllExampleProjectDisplayed();

      for (; fDone == false;)
      {
         // get heights
         iCentreBlockHeight = document.getElementById("centerblock").offsetHeight;
         iLeftBlockHeight = document.getElementById("leftblock").offsetHeight;

         iCentreBlockHeight = Math.max(iCentreBlockHeight,iLeftBlockHeight); // take the biggest

         iRightBlockHeight = document.getElementById("rightblock").offsetHeight;
         iAvailableHeight =  iCentreBlockHeight - iRightBlockHeight;

         // count number of fitting Example-Projects tha ain't display yet already
         iAvailableFitting = 0;
   
         for (i=0; i < iNumberOfExampProjs ;i++)
         {
            if ( (arecExampProjs[i].iHeight < iAvailableHeight) && (!arecExampProjs[i].fDisplayed) )
               iAvailableFitting++;
         }
   
   
         if (iAvailableFitting>0)
         { // display
            // find a number between 0..iAvailableFitting 
            iDisplayThis= Math.floor(Math.random() * (iAvailableFitting+1));

            //alert("Gezocht=" + iDisplayThis + " , Ch=" + iCentreBlockHeight + "  Rh=" + iRightBlockHeight + "  Av-height=" + iAvailableHeight + "  nProjs=" + iNumberOfExampProjs + " Av-fitting=" + iAvailableFitting );

            iAvailableFittingFound = -1;
            for (i=0; (i < iNumberOfExampProjs) && (iAvailableFittingFound < iDisplayThis) ;)
            {
               if ( (arecExampProjs[i].iHeight < iAvailableHeight) && (!arecExampProjs[i].fDisplayed) )
               {
                  if (iAvailableFittingFound<0) iAvailableFittingFound= 1;
                     else iAvailableFittingFound++;
                  //alert("AvailFitting found[" + iAvailableFittingFound + "] = " + i + " Gezocht=" + iDisplayThis);
               }

               if (iAvailableFittingFound < iDisplayThis)
               {
                  i++;
                  //alert("Next (" + i + ") bekijken"); 
               }

            }

            //alert(" Av-fitting=" + iAvailableFitting + "  RndDisplayThis=" + iDisplayThis + "  AvailableFittingFound=" + iAvailableFittingFound + " @I="+ i);
            DisplayExampleProject(i);
         }
         else
         {
            fDone = true; 
            //alert("geen fitting");
         }
      }
   }
}
//########################################################################
// END: Example Project routines
//########################################################################






