/* Common website functions 
 *
 * 20-09-06 Initial version
*/

// disable this script on development server because of https
/*
var strPath = location.pathname + location.search;

if (strPath > "") {
    strPath = strPath.toLowerCase();
    //alert(strPath);
    if ((strPath.indexOf("member") > -1)||(strPath.indexOf("order") > -1))
    {
        // Redirect to a secure page
        if (location.protocol != 'https:')
             window.location= 'https://' + location.host + location.pathname + location.search;
    }
    else
    {
        // Revert back to normal http if we have a secure connection
        if (location.protocol == 'https:')
            window.location= 'http://' + location.host + location.pathname + location.search;
    }
}
*/
function setFooter() {
	var newHeight = document.getElementById("navLeft").offsetHeight;
	var moduleHeight = document.getElementById("modules").offsetHeight;
	
	if (newHeight < moduleHeight) 
		newHeight = moduleHeight;
	
	if (newHeight > document.getElementById("content").offsetHeight)
		document.getElementById("content").style.height = newHeight + 'px';
		
	var top = document.getElementById("main").offsetHeight;
	document.getElementById("footer").style.top = top + 111 + "px";
}
function expand(obj,id) {
        return;
        var ctl = document.getElementById("expand" + id);
        if (ctl.style.display == "block") {
            ctl.style.display = "none";
            obj.className = "plusItem";
            
        }
        else
        {
            ctl.style.display = "block";
            obj.className = "minItem";
        }
        // +30 px because H1 before subGroupNav div //
        if (document.getElementById("content").offsetHeight < (document.getElementById('subGroupNav').offsetHeight + 50)){
                document.getElementById("content").style.height = document.getElementById('subGroupNav').offsetHeight + 50 + 'px';
        }
        setFooter();
                
    }
function setActiveStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

window.onload = function(e) {
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title);
}

window.onunload = function(e) {
  var title = getActiveStyleSheet();
  createCookie("style", title, 365);
}

var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);

// Random flash banner
var theImages = new Array()

theImages[0] = "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='131' height='302'><param name='movie' value='includes/swf/accucheck.swf' /><param name='quality' value='high' /><embed src='includes/swf/accucheck.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='131' height='302'></embed></object>";
theImages[1] = "<a href='http://www.bosman.com/webwinkel/Products.aspx?pid=4111&name=&brand=&article=10058793'><img src='includes/swf/OTUE.gif' border='0' /></a>";


var j = 0
var p = theImages.length;
var preBuffer = new Array()
for (i = 0; i < p; i++){
   preBuffer[i] = new Image()
   preBuffer[i].src = theImages[i]
}
var whichImage = Math.round(Math.random()*(p-1));
function showImage(){
document.write(theImages[whichImage]);
}

