
isMac = (navigator.appVersion.indexOf('Mac') != -1) ? true : false;
NS4 = (document.layers) ? true : false;
IEmac = ((document.all) && (isMac)) ? true : false;
IE4plus = (document.all) ? true : false;
IE4 = ((document.all) && (navigator.appVersion.indexOf('MSIE 4.') != -1)) ? true : false;
IE5 = ((document.all) && (navigator.appVersion.indexOf('MSIE 5.') != -1)) ? true : false;
IE6 = ((document.all) && (navigator.appVersion.indexOf('MSIE 6.') != -1)) ? true : false;
IE7 = ((document.all) && (navigator.appVersion.indexOf('MSIE 7.') != -1)) ? true : false;
ver4 = (NS4 || IE4plus) ? true : false;
NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape') != -1) ? true : false;

IE5plus = IE5 || IE6 || IE7;
IEMajor = 0;

if (IE4plus) {
  var start = navigator.appVersion.indexOf('MSIE');
  var end = navigator.appVersion.indexOf('.', start);
  IEMajor = parseInt(navigator.appVersion.substring(start + 5, end));
  IE5plus = (IEMajor >= 5) ? true : false;
}


var img;
var img_mo;
var img_cl;
img = new Array();
img_mo = new Array();
img_cl = new Array();


/*
if (location.href.indexOf('/print=true') == -1 && location.href.indexOf('/singleframe=true') == -1 && top.location.href.indexOf('frameid=') != -1) {
  top.location.href = top.location.href.replace('frameid=', 'framenoid=');
}
*/

if (location.href.indexOf('stepmode') == -1) {
	if (location.href.indexOf('/print=true') == -1 && location.href.indexOf('/singleframe=true') == -1 && top.location.href.indexOf('frameid=') != -1) {
		top.location.href = top.location.href.replace('frameid=', 'framenoid=');
	}
}




function setCookie(name, value, expire) {
  if (expire == '') {
    document.cookie = name + "=" + escape(value);
  } else {
    var expires = new Date();
    expires.setTime(expires.getTime() + expire);

    document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expires.toGMTString())) + "; path=/";
  }
}


function getCookie(name) {
   var search = name + "=";
   var val = "";

   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search) 

      if (offset != -1) { // if cookie exists 
         offset += search.length;

         // set index of beginning of value
         end = document.cookie.indexOf(";", offset) 

         // set index of end of cookie value
         if (end == -1) {
            end = document.cookie.length;
         }

         val = unescape(document.cookie.substring(offset, end));
      } 
   }

   return val;
}



function initMo(uniqueid, origImgSrc, overImgSrc, clickImgSrc) {
  if (origImgSrc != '') {
    img[uniqueid] = new Image();
    img[uniqueid].src = origImgSrc;
  }
  if (overImgSrc != '') {
    img_mo[uniqueid] = new Image();
    img_mo[uniqueid].src = overImgSrc;
  }
  if (clickImgSrc != '') {
    img_cl[uniqueid] = new Image();
    img_cl[uniqueid].src = clickImgSrc;
  }
}


function mov(uniqueid) {
  if (img_mo[uniqueid]) {
    document[uniqueid].src = img_mo[uniqueid].src;
  }
}


function mou(uniqueid) {
  if(img[uniqueid]) {
    document[uniqueid].src = img[uniqueid].src;
  }
}


function md(uniqueid) {
  if (img_cl[uniqueid]) {
    document[uniqueid].src = img_cl[uniqueid].src;
  }
}


function initMouseOver(uniqueid, origImgSrc, overImgSrc, clickImgSrc) {
  img['I' + uniqueid + origImgSrc] = new Image();
  img['I' + uniqueid + origImgSrc].src = origImgSrc;
  img_mo['I' + uniqueid + origImgSrc] = new Image();
  img_mo['I' + uniqueid + origImgSrc].src = overImgSrc;
  img_cl['I' + uniqueid + origImgSrc] = new Image();
  img_cl['I' + uniqueid + origImgSrc].src = clickImgSrc;
}

function MouseOver(imgName) {
  document[imgName].src = img_mo[imgName].src;
}

function MouseOut(imgName) {
  document[imgName].src = img[imgName].src;
}

function MouseDown(imgName) {
  document[imgName].src = img_cl[imgName].src;
}


function showWindow(uniqueid,id,qs,width,height) {
  var windowObj;
  windowObj = eval('top.Info' + uniqueid);

  if (windowObj !=null && (windowObj + "" != "undefined") && !windowObj.closed) {
    windowObj.focus();
  } else {
    windowObj = null;
    windowObj = top.open('/web/show/id=' + id + qs,'Info'+uniqueid,'toolbar=no,width=' + width + ',height=' + height + ',directories=no,status=no,scrollbars=yes,resizable=yes,menubar=no');
    top.name = 'wm';

    if (windowObj != null) {
      windowObj.focus();
    }     
  }
  reload = false;
}
/* FLASH CHECK */

var requiredVersion = 5;      // version the user needs to view site (max is 8, min is 2)
var useRedirect = false;      // "true" loads new flash or non-flash page into browser
                  // "false" embeds movie or alternate html code into current page
var flash2Installed = false;    // boolean. true if flash 2 is installed
var flash3Installed = false;    // boolean. true if flash 3 is installed
var flash4Installed = false;    // boolean. true if flash 4 is installed
var flash5Installed = false;    // boolean. true if flash 5 is installed
var flash6Installed = false;    // boolean. true if flash 6 is installed
var flash7Installed = false;    // boolean. true if flash 7 is installed
var flash8Installed = false;    // boolean. true if flash 8 is installed
var flash9Installed = false;    // boolean. true if flash 9 is installed
var flash10Installed = false;    // boolean. true if flash 10 is installed
var maxVersion = 10;         // highest version we can actually detect
var actualVersion = 0;        // version the user really has
var hasRightVersion = false;    // boolean. true if it's safe to embed the flash movie in the page
var jsVersion = 1.0;        // the version of javascript supported

var isIE = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;   // true if we're on ie
var isWin = (navigator.appVersion.indexOf("Windows") != -1) ? true : false; // true if we're on windows

jsVersion = 1.1;

// FIXME by danielm : what did Arjan mean by this all ?!?

var doRedir = false;
// check for internet explorer
if (!isIE) {
//  doRedir = true;
} 

// check for windows
if (!isWin) {
//  doRedir = true;
} 

// REDIRECTS BROWSER VERSIONS LOWER THAN NETSCAPE OR IE 4 TO AVOID ERRORS IN THE SCRIPT
if (navigator.appVersion.substring(0,1) < 4) { 
  doRedir = true;
} 

if (doRedir) {
  // FIXME by danielm : set correct page
  location.href = '/planet/show/id=317834'; 
} else {

  if(isIE && isWin){ // don't write vbscript tags on anything but ie win
    document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');
    document.write('on error resume next \n');
    document.write('flash2Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.2"))) \n');
    document.write('flash3Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.3"))) \n');
    document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
    document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');
    document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
    document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
    document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
    document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');
    document.write('flash10Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.10"))) \n');
    document.write('</SCR' + 'IPT\> \n'); // break up end tag so it doesn't end our script
  }

  detectFlash();  // call our detector now that it's safely loaded.
}

function detectFlash(){
  if (navigator.plugins){               // does navigator.plugins exist?
    if (navigator.plugins["Shockwave Flash 2.0"]  // yes>> then is Flash 2
    || navigator.plugins["Shockwave Flash"]){   // or flash 3+ installed?

      var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
      var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;
    //var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));
      var tmp1 = flashDescription.split(" ");
      var tmp2 = tmp1[2].split(".");
      var flashVersion = parseInt(tmp2[0]);

      flash2Installed = flashVersion == 2;
      flash3Installed = flashVersion == 3;
      flash4Installed = flashVersion == 4;
      flash5Installed = flashVersion == 5;
      flash6Installed = flashVersion == 6;
      flash7Installed = flashVersion == 7;
      flash8Installed = flashVersion == 8;
      flash9Installed = flashVersion == 9;
      flash10Installed = flashVersion == 0;
    }
  }


  for (var i = 2; i <= maxVersion; i++) {
    if (eval("flash" + i + "Installed") == true) actualVersion = i;
  }


  if(navigator.userAgent.indexOf("WebTV") != -1) actualVersion = 2;

  if (actualVersion >= requiredVersion) {
    hasRightVersion = true;

    if (useRedirect) {
      if(jsVersion > 1.0) {
        window.location.replace(flashPage);
      } else {
        window.location = flashPage;
      }
    }
  } else {  // user doesn't have a new enough version.

    if (useRedirect) {    // if the redirection option is on, load the appropriate alternate page
      if(jsVersion > 1.0) { // need javascript1.1 to do location.replace
        window.location.replace((actualVersion >= 2) ? upgradePage : noFlashPage);
      } else {
        window.location = (actualVersion >= 2) ? upgradePage : noFlashPage;
      }
    }
  }
}

function writeFlash(s,w,h,a) {
  /*
  
    usage example:
    
    writeFlash('swf/flash.swf',500,350,'gif/alternative.gif');
  
  */

  var alternateContent;
  if (a != '') {
    alternateContent = '<img src="'+a+'" border="0" width="'+w+'" height="'+h+'" />';
  } else {
    alternateContent = '';
  }
  var h_str = '';
  if (h != -1) {
    h_str = ' height="'+h+'"';
  }
  var w_str = '';
  if (h != -1) {
    w_str = ' width="'+w+'"';
  }
  var flashContent = '<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"'+w_str+h_str+' CODEBASE="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">'
  + '<PARAM NAME="MOVIE" VALUE="'+s+'">'
  + '<PARAM NAME="PLAY" VALUE="true">'
  + '<PARAM NAME="LOOP" VALUE="true">'
  + '<PARAM NAME="QUALITY" VALUE="high">'
  + '<PARAM NAME="MENU" VALUE="false">'
  + '<EMBED SRC="'+s+'"'+w_str+h_str+' PLAY="true" LOOP="true" QUALITY="high" MENU="false" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>'
  + '<NOEMBED>' + alternateContent + '</NOEMBED></OBJECT>';


  if (hasRightVersion) {
    document.write(flashContent);
  } else {
    document.write(alternateContent);
  }
}

// functions for the homepage element
function changeOptionsFor( target, targetNr ){
  if (target=="line" && currentSelected==sNeeds[targetNr-1]) {
    targetNr+=1;
    target = sNeeds[targetNr];
    if (!NS) var selectObject = document.forms["interestselector"].elements[0];
    else var selectObject = getLayerById("interestselection").document.forms["interestselector"].elements[0];
    for (var i=0; i<selectObject.options.length; i++) {
      selectObject.options[i].selected = false;
    }
    selectObject.options[targetNr].selected = true;
  }
  changeOptionsAtOnce( target, targetNr );
}

function changeOptionsAtOnce( target, targetNr ){
  if ( targetNr < 1 ) targetNr=1;
  currentSelected = target;
  if ( target.toLowerCase() == "line" ){
    if (!NS) var selectObject = document.forms["interestselector"].elements[0];
    else var selectObject = getLayerById("interestselection").document.forms["interestselector"].elements[0];
    for (var i=0; i<selectObject.options.length; i++) 
      selectObject.options[i].selected = false;
    selectObject.options[targetNr-1].selected = true;
    target = sNeeds[targetNr-1];
    currentSelected = sNeeds[targetNr-1];
    currentIndex = 0;
  }
  if ( target.toLowerCase() != "line" ){
    if (!NS) var selectObject = document.forms["needSelector"].elements[0];
    else var selectObject = getLayerById("needselection").document.forms["needSelector"].elements[0];
    eval( "changeEntries( selectObject, "+ target.toLowerCase() +"Options, \""+ target +"\" );" );
  }
}

function changeEntries( selectObject, newEntryArray, target ){
  selectObject.length = 0;
  for ( var i=0; i < newEntryArray.length; i++){
    selectObject.options[i] = new Option( newEntryArray[i], target+i, false, (i==0)?true:false );
  }
  if (NS) selectObject.selectedIndex = 0;
  currentIndex = 0;
}

function goButtonChange( active ){
  if (!goButton.isObject()) goButton = new eMBLayer( "needselection" );
  var imageObject;
  if ( NS ) imageObject = goButton.object.document.images[0];
  else imageObject = document.images["go-mpc"];
  var newGoSource = ( active )?buttonOrangeSource:buttonOnSource;
  imageObject.src = newGoSource;
}