/* Common website functions 
 *
 * 20-09-06 Initial version
*/

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 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 popup(page,title,width,height) {
     var winl = (screen.width - width) / 2;
     var wint = (screen.height - height) / 2; 
     window.open(''+page,''+title,'width='+width+',height='+height+',top='+wint+',left='+winl+',resizable=no,scrollbars=no,toolbar=no'); 
}

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);


function setOtherTextArea() {
    var ctlText = document.getElementById("ctl00_cphContent_ctl00_CMSFormsModule_ctl00_txtQuestion");
    var ctlRadio = document.getElementById("ctl00_cphContent_ctl00_CMSFormsModule_ctl00_rbWhat_4");
    if (ctlRadio.checked)
    {
        ctlText.readOnly = false;
         ctlText.style.backgroundColor = '#FFFFFF';
    }
    else
    {
        ctlText.readOnly = true;
        ctlText.style.backgroundColor = '#f6f6f6';
        ctlText.value = '';
    }
}

// Random flash banner
var theImages = new Array()

theImages[0] = "<object style='border:1px solid #b2b2b2;' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='130' height='300'><param name='movie' value='includes/swf/roche_banner.swf' /><param name='quality' value='high' /><embed src='includes/swf/roche_banner.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='130' height='300'></embed></object>"
theImages[1] = "<object style='border:1px solid #b2b2b2;' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='130' height='300'><param name='movie' value='includes/swf/onetouch_ultra.swf' /><param name='quality' value='high' /><embed src='includes/swf/onetouch_ultra.swf' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='130' height='300'></embed></object>"


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]);
}

//Show/Hide menu in cms
function showMenu(menuItem) {
    if(document.getElementById(menuItem).style.display == 'block') {
        document.getElementById(menuItem).style.display = 'none';
    }else{
        document.getElementById(menuItem).style.display = 'block';
    }
}

