var DivPositionsSet = false;
// the following vars act as constant values (for colours)
var NavItemFontColour     = '#072997';
var NavItemSelectedColour = '#D3E4D9'; 

/* This functions handles the onbeforeprint event for the window object */
window.onbeforeprint = function(evt) {
  if(navigator.appName.indexOf("Explorer") != -1)
  {
    //Hide all menu's before printing the page (IE only)
    document.getElementById('divServicesItems').style.visibility = "hidden";
    document.getElementById('ServicesText').style.backgroundColor = "";
    document.getElementById('ServicesText').style.color = NavItemFontColour;
    
    document.getElementById('divSolutionItems').style.visibility = "hidden";
    document.getElementById('SolutionsText').style.backgroundColor = "";
    document.getElementById('SolutionsText').style.color = NavItemFontColour;
    
    document.getElementById('divSupportItems').style.visibility = "hidden";
    document.getElementById('SupportText').style.backgroundColor = "";
    document.getElementById('SupportText').style.color = NavItemFontColour;

    document.getElementById('divCaseStudyItems').style.visibility = "hidden";
    document.getElementById('CaseStudyText').style.backgroundColor = "";
    document.getElementById('CaseStudyText').style.color = NavItemFontColour;
        
    document.getElementById('divCompanyItems').style.visibility = "hidden";
    document.getElementById('CompanyText').style.backgroundColor = "";
    document.getElementById('CompanyText').style.color = NavItemFontColour;    
    
    document.getElementById('NewsAndViewsText').style.backgroundColor = "";
    document.getElementById('NewsAndViewsText').style.color = NavItemFontColour;  
    
    document.getElementById('divContactItems').style.visibility = "hidden";
    document.getElementById('ContactText').style.backgroundColor = "";
    document.getElementById('ContactText').style.color = NavItemFontColour; 
    
    document.getElementById('VacanciesText').style.backgroundColor = "";
    document.getElementById('VacanciesText').style.color = NavItemFontColour; 
  }//if
}//window.onbeforeprint = function(evt)

/*if(navigator.appName.indexOf("Explorer") != -1)
{
  // This functions handles the onbeforeprint event for the window object
  function window.onbeforeprint()
  {
      //Hide all menu's before printing the page (IE only)
      document.getElementById('divServicesItems').style.visibility = "hidden";
      document.getElementById('divSolutionItems').style.visibility = "hidden";
      document.getElementById('divSupportItems').style.visibility = "hidden";
      document.getElementById('divCaseStudyItems').style.visibility = "hidden";
      document.getElementById('divCompanyItems').style.visibility = "hidden";
      document.getElementById('divContactItems').style.visibility = "hidden";
  }//window.onbeforeprint
}//if*/  

/* This functions is used to hide the navigation menu's */
document.onmousemove = function(evt) {
  var theElement;

  if(DivPositionsSet)
  {
    evt=evt||window.event;
    //IE uses srcElement & mozilla/firefox uses target
    theElement = evt.srcElement||evt.target;

    //Hide 'Services' menu & restore main link
    if (document.getElementById('divServicesItems').style.visibility == "visible")
    {
      if((theElement.id != "ServicesText") &&
         (theElement.id != "tabledivServicesItems") &&
         (theElement.id != "tdOverview") &&
         (theElement.id != "tdProjAud") &&
         (theElement.id != "tdProcessRev") &&
         (theElement.id != "tdDesignRev") &&
         (theElement.id != "tdFMEAs") &&
         (theElement.id != "tdFeas") &&
         (theElement.id != "tdArchEval") &&
         (theElement.id != "tdReqCapt") &&
         (theElement.id != "tdProjMgt") &&
         (theElement.id != "tdSysAnalysis&Des"))
      {
        document.getElementById('divServicesItems').style.visibility = "hidden";
        document.getElementById('ServicesText').style.backgroundColor = "";
        document.getElementById('ServicesText').style.color = NavItemFontColour;
      }//if((evt.srcElement.id != ...
    }//if (document.getElementById('divServicesItems')....
        
    //Hide 'Solution' menu & restore main link
    if (document.getElementById('divSolutionItems').style.visibility == "visible")
    {
      if((theElement.id != "SolutionsText") &&
         (theElement.id != "tabledivSolutionItems") &&
         (theElement.id != "tdSolOverview") &&
         (theElement.id != "tdBanknoteSorters") &&
         (theElement.id != "tdBanknoteCounters") &&
         (theElement.id != "tdElectionSys") &&
         (theElement.id != "tdATMs") &&
         (theElement.id != "tdDocHandling") &&
         (theElement.id != "tdWebUI") &&
         (theElement.id != "tdMechCtrl") &&
         (theElement.id != "tdDatAcqu") &&
         (theElement.id != "tdAlgProcess") &&
         (theElement.id != "tdDBDesign"))
      {
        document.getElementById('divSolutionItems').style.visibility = "hidden";
        document.getElementById('SolutionsText').style.backgroundColor = "";
        document.getElementById('SolutionsText').style.color = NavItemFontColour;
      }//if((if((theElement.id != ...
    }//else if 

    //Hide 'Support' menu & restore main link
    if (document.getElementById('divSupportItems').style.visibility == "visible")
    {
      if((theElement.id != "SupportText") &&
         (theElement.id != "tabledivSupportItems") &&
         (theElement.id != "tdLegacySupport"))
      {
        document.getElementById('divSupportItems').style.visibility = "hidden";
        document.getElementById('SupportText').style.backgroundColor = "";
        document.getElementById('SupportText').style.color = NavItemFontColour;
      }//if((if((theElement.id != ...
    }//if     
        
    //Hide 'Case Study' menu & restore main link
    if (document.getElementById('divCaseStudyItems').style.visibility == "visible")
    {
      if((theElement.id != "CaseStudyText") &&
         (theElement.id != "tabledivCaseStudyItems") &&
         (theElement.id != "tdCaseOverview") &&
         (theElement.id != "tdFMEA") &&
         (theElement.id != "tdTimeRec") &&
         (theElement.id != "tdPPSCS") &&
         (theElement.id != "tdInfraRedCS") &&
         (theElement.id != "tdOCRCS"))
      {
        document.getElementById('divCaseStudyItems').style.visibility = "hidden";
        document.getElementById('CaseStudyText').style.backgroundColor = "";
        document.getElementById('CaseStudyText').style.color = NavItemFontColour;
      }//if((if((theElement.id != ...
    }//else if 
        
    //Hide 'Company' menu & restore main link
    if (document.getElementById('divCompanyItems').style.visibility == "visible")
    {
      if((theElement.id != "CompanyText") &&
         (theElement.id != "tabledivCompanyItems") &&
         (theElement.id != "tdCoOverview") &&
         (theElement.id != "tdProfile") &&
         (theElement.id != "tdAssociates") &&
         (theElement.id != "tdPartners"))
      {
        document.getElementById('divCompanyItems').style.visibility = "hidden";
        document.getElementById('CompanyText').style.backgroundColor = "";
        document.getElementById('CompanyText').style.color = NavItemFontColour;
      }//if((if((theElement.id != ...
    }//else if  
        
    //Hide 'Contact Us' menu & restore main link
    if (document.getElementById('divContactItems').style.visibility == "visible")
    {
      if((theElement.id != "ContactText") &&
         (theElement.id != "tabledivContactItems") &&
         (theElement.id != "tdEnquForm") &&
         (theElement.id != "tdLocation") &&
         (theElement.id != "tdSupport"))
      {
        document.getElementById('divContactItems').style.visibility = "hidden";
        document.getElementById('ContactText').style.backgroundColor = "";
        document.getElementById('ContactText').style.color = NavItemFontColour;
      }//if((if((theElement.id != ...
    }//else if
  }//if(DivPositionsSet)
};//document.onmousemove = function(evt) ...

/* Adds the mouseover/mouseout events for the navigation titles */
function AddCellMouseEvents()
{
  if(DivPositionsSet)
  {
    // Set onmouseover event for 'ServicesText' cell & display it's menu
    document.getElementById('ServicesText').onmouseover=function(evt){
      document.getElementById('ServicesText').style.backgroundColor = '#316AC5'; 
      document.getElementById('ServicesText').style.color = NavItemSelectedColour; 
      document.getElementById('divServicesItems').style.visibility = 'visible';};
      
    // Set onmouseover event for 'SolutionsText' cell & display it's menu
    document.getElementById('SolutionsText').onmouseover=function(evt){
      document.getElementById('SolutionsText').style.backgroundColor = '#316AC5'; 
      document.getElementById('SolutionsText').style.color = NavItemSelectedColour; 
      document.getElementById('divSolutionItems').style.visibility = 'visible';};
      
    // Set onmouseover & onmouseout events for 'SupportText'
    document.getElementById('SupportText').onmouseover=function(evt){
      document.getElementById('SupportText').style.backgroundColor = '#316AC5'; 
      document.getElementById('SupportText').style.color = NavItemSelectedColour; 
      document.getElementById('divSupportItems').style.visibility = 'visible';};    
    
    // Set onmouseover event for 'CaseStudyText' cell & display it's menu
    document.getElementById('CaseStudyText').onmouseover=function(evt){
      document.getElementById('CaseStudyText').style.backgroundColor = '#316AC5'; 
      document.getElementById('CaseStudyText').style.color = NavItemSelectedColour; 
      document.getElementById('divCaseStudyItems').style.visibility = 'visible';};
      
    // Set onmouseover event for 'CompanyText' cell & display it's menu
    document.getElementById('CompanyText').onmouseover=function(evt){
      document.getElementById('CompanyText').style.backgroundColor = '#316AC5'; 
      document.getElementById('CompanyText').style.color = NavItemSelectedColour; 
      document.getElementById('divCompanyItems').style.visibility = 'visible';};
      
    // Set onmouseover & onmouseout events for 'NewsAndViewsText'
    document.getElementById('NewsAndViewsText').onmouseover=function(evt){
      document.getElementById('NewsAndViewsText').style.backgroundColor = '#316AC5'; 
      document.getElementById('NewsAndViewsText').style.color = NavItemSelectedColour;}; 
    document.getElementById('NewsAndViewsText').onmouseout=function(evt){
      document.getElementById('NewsAndViewsText').style.backgroundColor = ''; 
      document.getElementById('NewsAndViewsText').style.color = NavItemFontColour;};       
      
    // Set onmouseover event for 'ContactText' cell & display it's menu
    document.getElementById('ContactText').onmouseover=function(evt){
      document.getElementById('ContactText').style.backgroundColor = '#316AC5'; 
      document.getElementById('ContactText').style.color = NavItemSelectedColour; 
      document.getElementById('divContactItems').style.visibility = 'visible';};
      
    // Set onmouseover & onmouseout events for 'VacanciesText'
    document.getElementById('VacanciesText').onmouseover=function(evt){
      document.getElementById('VacanciesText').style.backgroundColor = '#316AC5'; 
      document.getElementById('VacanciesText').style.color = NavItemSelectedColour;}; 
    document.getElementById('VacanciesText').onmouseout=function(evt){
      document.getElementById('VacanciesText').style.backgroundColor = ''; 
      document.getElementById('VacanciesText').style.color = NavItemFontColour;};                      
  }//if(DivPositionsSet)    
}//AddCellMouseEvents

/* Handles the initialisation of the page. */
function InitialisePage()
{
  if(!DivPositionsSet)
  {
    SetDivPosition();
  }//if
  AddCellMouseEvents();
}//InitialisePage

    
/* Returns the top position for all menu div's */
function getDivTop(element) 
{
  var elementOffsetTop = 0;
  var divTop           = 0;
  var verticalOffset   = 0;
  var cellHeight       = 0;
      
  //Check browser type to determine offset for div menu's
  if(navigator.appName.indexOf("Explorer") == -1)
  {
    // non-IE
    verticalOffset = 9;
  }//if(navigator.appName ...
  else
  {
    // IE
    verticalOffset = 16;
  }//else
      
  elementOffsetTop = (element.offsetTop);
  cellHeight = document.getElementById("ServicesText").height;
  divTop = (elementOffsetTop*1) + (cellHeight*1) + verticalOffset;
  return divTop;
}//getDivTop
    
/* Returns the left position for an individual menu div */
function getScreenLeft(element) 
{
  var screenLeft     = 0;
  var bodyScreenLeft = 0;

  if(element.parentNode == document.body)
  {
    bodyScreenLeft = (element.offsetLeft);
    return bodyScreenLeft;
  }//if(element.parentNode == document.body)
  else
  { 
    screenLeft = element.offsetLeft + getScreenLeft(element.parentNode);
    return screenLeft;
  }//else
}//getScreenLeft

/* Sets the position of all menu div's */
function SetDivPosition()
{
  var divTopPos = 0;
  
  divTopPos = getDivTop(document.getElementById("ServicesText"));

  // Services Items
  document.getElementById("divServicesItems").style.left = 
    getScreenLeft(document.getElementById("ServicesText"));
  document.getElementById("divServicesItems").style.top = divTopPos;
  // If the width of the menu is less than its title, increase its width
  if (document.getElementById("divServicesItems").clientWidth <
      document.getElementById("ServicesText").clientWidth){
    document.getElementById("divServicesItems").style.width =
    document.getElementById("ServicesText").clientWidth;     
  }//if  
       
  // Solution Items
  document.getElementById("divSolutionItems").style.left = 
    getScreenLeft(document.getElementById("SolutionsText"));
  document.getElementById("divSolutionItems").style.top = divTopPos;
  if (document.getElementById("divSolutionItems").clientWidth <
      document.getElementById("SolutionsText").clientWidth){
    document.getElementById("divSolutionItems").style.width =
    document.getElementById("SolutionsText").clientWidth;     
  }//if 
  
  // Support Items
  document.getElementById("divSupportItems").style.left = 
    getScreenLeft(document.getElementById("SupportText"));
  document.getElementById("divSupportItems").style.top = divTopPos;
  if (document.getElementById("divSupportItems").clientWidth <
      document.getElementById("SupportText").clientWidth){
    document.getElementById("divSupportItems").style.width =
    document.getElementById("SupportText").clientWidth;     
  }//if     
      
  // Case Study Items
  document.getElementById("divCaseStudyItems").style.left = 
    getScreenLeft(document.getElementById("CaseStudyText"));
  document.getElementById("divCaseStudyItems").style.top = divTopPos;
  if (document.getElementById("divCaseStudyItems").clientWidth <
      document.getElementById("CaseStudyText").clientWidth){
    document.getElementById("divCaseStudyItems").style.width =
    document.getElementById("CaseStudyText").clientWidth;     
  }//if             
      
  // Company Items
  document.getElementById("divCompanyItems").style.left = 
    getScreenLeft(document.getElementById("CompanyText"));
  document.getElementById("divCompanyItems").style.top = divTopPos;         
  if (document.getElementById("divCompanyItems").clientWidth <
      document.getElementById("CompanyText").clientWidth){
    document.getElementById("divCompanyItems").style.width =
    document.getElementById("CompanyText").clientWidth;     
  }//if   
      
  // Contact Us Items
  document.getElementById("divContactItems").style.left = 
    getScreenLeft(document.getElementById("ContactText"));
  document.getElementById("divContactItems").style.top = divTopPos;         
  if (document.getElementById("divContactItems").clientWidth <
      document.getElementById("ContactText").clientWidth){
    document.getElementById("divContactItems").style.width =
    document.getElementById("ContactText").clientWidth;     
  }//if   

  DivPositionsSet = true;
}//SetDivPosition


/* Configures and opens the 'call me' dialog. */
function OpenCallMeDlg(){
  var dlgLeft      = 0;
  var dlgTop       = 0;
  var dlgHeight    = 230;
  var dlgWidth     = 450;
  var dlgFeatures  = "";
  
  //set position of dialog
  dlgLeft = ((document.body.clientWidth / 2) - (dlgWidth / 2)) 
  dlgTop = ((document.body.clientHeight / 2) - (dlgHeight / 2)) 
  dlgFeatures = "height="+dlgHeight+",width="+dlgWidth+",left="+dlgLeft+",top="+dlgTop+",modal=yes"; 
  //open the dialog
  window.open('CallMeDlg.php','dlog',dlgFeatures)
}//OpenCallMeDlg

    


