/* Most Javascript is reusable globally. However, different pages will have
   different Javascript requirement. The purpose of this file is to hold several
   init function variations to load different resources for specific pages. */

function init_officesolutions ()
{
  attachExternals();
  attachExpands();  
}
/* Added by Anne Minford 10th April 2008 for savings landing page */

function getElementsByClassName(classname) {
  var rl = new Array();
  var re = new RegExp('(^| )'+classname+'( |$)');
  var ael = document.getElementsByTagName('*');
  var op = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;
  if (document.all && !op) ael = document.all;
  for (i=0, j=0; i<ael.length; i++) {
    if (re.test(ael[i].className)) {
      rl[j]=ael[i];
      j++;
    }
  }
  return rl;
}

function attachExternals() {
  if (document.getElementsByTagName('a')) {
    as = document.getElementsByTagName('a');
    for (var i=0; i<as.length; i++) {
      if (as[i].className.indexOf('external') >= 0) {
        as[i].target = '_blank';
      }
    }
  }
}

function attachExpands() {
  if (document.getElementsByTagName('span')) {
    var spans = document.getElementsByTagName('span');
    for (var i=0; i<spans.length; i++) {
      if (spans[i].className == 'expander') {
        spans[i].onmouseover = function() {
          expands = this.parentNode.getElementsByTagName('div');
          for (var j=0; j<expands.length; j++) {
            if (expands[j].className == 'expand') expands[j].style.display = 'block';
          }
        }
        spans[i].onmouseout = function() {
          expands = this.parentNode.getElementsByTagName('div');
          for (var j=0; j<expands.length; j++) {
            if (expands[j].className == 'expand') expands[j].style.display = 'none';
          }
        }
      }
    }
  }
}


function hideLocations()
{
  tables = getElementsByClassName('locationshide');
  for (var i=0; i<tables.length; i++) {
    tables[i].style.display = 'none';
  }
}

function showLocation(loc)
{
  hideLocations();
  tables = getElementsByClassName('locationshide');
  for (var i=0; i<tables.length; i++) {
    if (tables[i].id == loc)
    {
      styletochange = tables[i].style;
      styletochange.display = 'block';
    }
  }
  return false;
}

function attachPopup(el) {
  el.onclick = function() {
    if (el.className.indexOf('size') != -1) {
      dimensions = (((el.className.replace('popup','')).replace('size','')).replace(' ','')).split('x');
      elwidth = dimensions[0];
      elheight = dimensions[1];
	} else {
      elwidth = '640';
      elheight = '480';
	}
    popup = window.open(el.href,'popup','width='+elwidth+',height='+elheight+',resizable=yes,scrollbars=yes,toolbar=no,status=no,directories=no');
	if (window.focus) popup.focus();
	return false;
  }
}
function attachPopups() {
  if (document.getElementsByTagName) {
    var links = document.getElementsByTagName('a');
    for (var i=0; i<links.length; i++) {
      if (links[i].className.indexOf('popup') != -1) {
        attachPopup(links[i]);
      }
    }
  }
}

function init() {
  attachExternals();
  attachExpands();
  hideLocations();
  attachPopups();
  attachSIFR();
}

function fixIeDropDown(select){

			var select = (typeof select == "string") ? document.getElementById(select) : select;

			// THIS FUNCTION IS ONLY CONCERNED WITH INTERNET EXPLORER NON-MULTIPLE SELECT NODES THAT HAVE A SPECIFIC WIDTH DEFINED
			if(!select.attachEvent || navigator.userAgent.indexOf("Opera") > -1 || select.multiple || select.currentStyle.width == "auto") { return; }

			var body = document.getElementsByTagName("body").item(0);

			var si = select.selectedIndex;

			var clone = select.cloneNode(true);
			clone.style.position = "absolute";
			clone.style.visibility = "hidden";
			clone.style.width = "auto";
			body.appendChild(clone);

			clone._initialOffsetWidth = select.offsetWidth;
			clone._initialOffsetHeight = select.offsetHeight;
			clone._autoWidth = clone.offsetWidth;

			clone = body.removeChild(clone);
			clone.style.visibility = "visible";
			clone.style.width = clone._initialOffsetWidth + "px";

			var span = document.createElement("span");
			span._isIeDropDownContainer = true;
			span.style.position = "relative";
			span.style.width = clone._initialOffsetWidth + "px";
			span.style.height = clone._initialOffsetHeight + "px";
			span.style.marginBottom = "-4"; //hmm...quirky...
			span.appendChild(clone);

			if (select.parentNode._isIeDropDownContainer){
				select.parentNode.parentNode.replaceChild(span, select.parentNode);
			}else{
				select.parentNode.replaceChild(span, select);
			}

			if (clone._autoWidth > clone._initialOffsetWidth){
				var expand = function(){
					event.srcElement.parentNode.style.zIndex = 1;
					event.srcElement.style.width = "auto";
					if (event.srcElement.offsetWidth > event.srcElement._initialOffsetWidth){
						event.srcElement.style.width = "auto";
					}else{
						event.srcElement.style.width = event.srcElement._initialOffsetWidth + "px";
					}
				};
				var contract = function(){
					event.srcElement.parentNode.style.zIndex = 0;
					event.srcElement.style.width = event.srcElement._initialOffsetWidth + "px";
				};
				clone.attachEvent("onactivate", expand);
				clone.attachEvent("ondeactivate", contract);
			}
			clone.selectedIndex = si;
		}

		window.onload = function(){
			fixIeDropDown("oCF_howdidyouhear");
		};
