﻿/*
Common code used on all Blanco Canada Web pages
Copyright 2003 Digital Commerce SLW Inc. Toronto Canada
*/
var qString = window.location.search;
var noFrames = qString.indexOf("noFrames") != -1;
var printerFriendly = qString.indexOf("printerFriendly") != -1;
var noPFHeader, noNavHeader;
var myurl = self.location.href.toLowerCase();


if (!window.isMainPage) {
  showInFrames(); 
  window.onload = onPageLoad
}

function onPageLoad() {
  if (self.mtmtrack) mtmtrack(); // synchonizes left-side navigation
  if (self.setTitleColour) setTitleColour();
}

function showInFrames() {
  if (self != top) {
    // working inside of a frame, suppress headers
    noPFHeader = true;
    noNavHeader = true;
    if (self.name == "Workarea") {
      //top.location.hash = self.location.pathname + self.location.search
      top.setHash(self.location.pathname + self.location.search) //2011-12-18
    }
  }
  else { // not in frame
    if (printerFriendly) {
      // this page for printing only, supress navigation bar
      noPFHeader = false;
      noNavHeader = true;
    }
    else if (noFrames) {
      // operating in noframe mode, show all headers, allow navigation
      noPFHeader = false;
      noNavHeader = false;
    }
    else if ((myurl.indexOf("file:") == -1) && (myurl.indexOf("/templates/") == -1)) {
      // reload in frame
      var pn = self.location.pathname
      var srch = self.location.search
      if (pn.indexOf("/fr/") == -1 && srch.indexOf("lang=fr") == -1) 
        self.location.replace("../frames/BlancoStart.htm#" + self.location.pathname +  self.location.search);
      else 
        self.location.replace("../frames/BlancoFr.htm#" + self.location.pathname +  self.location.search);
    }
  }
}

function onClickA(aLink) {
  // checks if operating in noFrame mode and
  // or printer friendly modes
  if (noFrames) {
    if (aLink.href.indexOf("?") == -1) aLink.href = aLink.href + "?noFrames"
    else if (aLink.search.indexOf("noFrames") == -1) aLink.href = aLink.href + "&noFrames"
    return true;
  }
  else if (printerFriendly) {
    // printer preview page, supress navigation
    return false;
  }
  else {
    return true;
  }
}


function getBackgroungColor(el) {
  if (el) {
    if (window.getComputedStyle) { // firefox
      return document.defaultView.getComputedStyle(el, '').getPropertyValue('background-color');
    }
    else if (el.currentStyle) { // ie
      return el.currentStyle.backgroundColor;
    }
    else {
      return el.style.backgroundColor;
    }
  }
}

function setTitleColour() {
  // sets subframe title colours to match this frames colours
  // test if a frame exists and getElementById supported
  if ((parent != self) && document.getElementById) {
    // test if subheader available
    if (parent.Subheader) {
      var footer = document.getElementById("footer")
      if (footer) {
        if (window.getComputedStyle) { // firefox
          colour = document.defaultView.getComputedStyle(footer, '').getPropertyValue('color');
          bgColour = document.defaultView.getComputedStyle(footer, '').getPropertyValue('background-color');
        }
        else if (footer.currentStyle) { // ie
          var colour = footer.currentStyle.color
          var bgColour = footer.currentStyle.backgroundColor
        }
        else {
          var colour = footer.style.color
          var bgColour = footer.style.backgroundColor
        }
      }
      var cell
      if (colour && bgColour) {
        for (var i = 1; i < 5; i++) {
          cell = parent.Subheader.document.getElementById("subheader" + i)
          if (cell) {
            cell.style.backgroundImage = "none";
            cell.style.backgroundColor = bgColour;
            cell.style.color = colour;
          }
        }
      }
    }
  }
}

//Hover menu for feature pages
// jQuery onload
if (self.$) {
  $(document).ready(function() {
    // drop menu
    var hm = $(".hoverMenu")
    if (hm) {
      $(".hoverSubmenu", hm).hide();
      hm.hover(showHoverMenu, hideHoverMenu)
      hm.click(showHoverMenu)
    }
  });
}
function showHoverMenu() {
  $(".hoverSubmenu", this).show(100);
  $(".hoverBullet", this).html("▼")
  $(".hoverItem", this).addClass("hoverBg")
}

var objectToHide
function hideHoverMenu() {
  //$(".hoverItem", this).css("background-image", "none")
  $(".hoverItem", this).removeClass("hoverBg")
  $(".hoverBullet", this).html("►")
  objectToHide = $(".hoverSubmenu", this)
  objectToHide.hide(0);
  // make sure it stays hidden even if show was triggered at same time
  setTimeout("objectToHide.hide(0);", 100)
}

function queryString(key) {
  var page = new QueryString(window.location.search);
  return unescape(page.getValue(key));
}
function QueryString(qs) {
  if (qs.length > 1) qs = qs.substring(1, qs.length);
  //else this.qs = null;
  this.keyValuePairs = [];
  if (qs) {
    this.keyValuePairs = qs.split("&")
    //var qss = this.qs.split("&")
    //for (var i = 0; i < qss.length; i++) {
    //  this.keyValuePairs[i] = qss[i];
    //}
  }
  this.getValue = function(key) {
    for (var j = 0; j < this.keyValuePairs.length; j++) {
      if (this.keyValuePairs[j].split("=")[0] == key)
        return this.keyValuePairs[j].split("=")[1];
    }
    return false;
  }
}

