var swf = false;
var swfAllow = (window.location.search.indexOf('flash=0')+1) ? false : true;

// User Preferences code begins

function getCookie(name)
{
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
  } else
        begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
        end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function checkFlashPref() {
  // session preference overrides persistent user preference
  if (getCookie("sessionpref") == 1) {
    swfAllow = false;
    return;
  }
}

//checkFlashPref();

// User Preferences code ends

function hasFlash(ver) {
  if(!swfAllow) return false;
  if(!ver) ver = 0;
	var n = navigator;
  if(n.plugins && n.plugins.length > 0) {
    var m,t,d,v;
    m = n.mimeTypes;
    t = 'application/x-shockwave-flash';
    if(m && m[t] && m[t].enabledPlugin && m[t].enabledPlugin.description) {
      d = m[t].enabledPlugin.description;
      v = d.charAt(d.indexOf('.')-1);
			swf = (v >= ver) ? true : false;
    }
  } else if(n.appVersion.indexOf("Mac") == -1 && window.execScript) {
    for(var i=ver; i<=7&&i!=1&&swf!=true; i++) {
      execScript('on error resume next: swf=IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash'+((i==0)?'':'.'+i)+'"))','VBScript');
    }
	} else {
	  swf = false;
	}
	return swf;
}

function switchFlash() {
  var val = (swfAllow) ? '0' : '1';
	var s = window.location.href.split('#')[0];
  if(window.location.search) {
	  if(s.indexOf('flash=')+1) {
		  s = s.replace('flash='+s.split('flash=')[1].split('&')[0],'flash='+val);
		} else {
		  s += '&flash='+val;
		}
	} else {
	  s += '?flash='+val;
	}
	window.location.href = s;
}

function allowFlash() {
  if((!hasFlash(5)) && (swfAllow)) return '';
  var s = '<a href="#" onclick="switchFlash(); return false;" class="headerLnk">+ ';
	s += (swfAllow) ? 'Non-Flash Version' : 'Flash Version' ;
	s += '</a><br />';
	return s;
}

function newAllowFlash() {
  if((!hasFlash(5)) && (swfAllow)) return '';
  var s = '<a href="#" onclick="switchFlash(); return false;" class="newHeaderLnk">+ ';
	s += (swfAllow) ? 'Non-Flash Version' : 'Flash Version' ;
	s += '</a><br />';
	return s;
}

function moveFocus(id) {
  var o = document.getElementById(id);
	if(o) o.focus();
}

