/*
====================================================================================================
Stylesheet load functions for text-only display
====================================================================================================
*/
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;
  var active = "default";
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) {
		active = a.getAttribute("title");
	}
  }
  return active;
}

function createCookie(value) {
	deleteCookie();
	var date = new Date();
	date.setTime(date.getTime()+(7*24*60*60*1000));
	var expires = date.toGMTString();
	var foo = "css=" + value + "; expires=" + expires + "; path=/";
	document.cookie = foo;
}

function deleteCookie() {
	var date = new Date();
	date.setTime(date.getTime()-(365*24*60*60*1000));
	var expires = date.toGMTString();
	var foo = "css=; expires=" + expires + "; path=/";
	document.cookie = foo;
}

function readCookie() {
	var cn;
	var nameEQ = "css=";
	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) {
			cn = c.substring(nameEQ.length,c.length);
		}
	}
	return (cn != "null") ? cn : "default";
}

window.onload = function(e) {
	if(!readCookie()) {
		createCookie("default");
	}
	var title = readCookie();
	setActiveStyleSheet(title);
}

window.onunload = function(e) {
	var title = getActiveStyleSheet();
	createCookie(title);
}

// initialise
if(!readCookie()) {
	createCookie("default");
}
var title = readCookie();
setActiveStyleSheet(title);




var newWindow;

function myVoid(){;}

function makeNewWindow(w,h,mytitle,myurl) {
  var ht =+ h + 25;
  var wd =+ w + 20;
  newWindow = window.open(myurl,"","status,height=" + ht + ",width=" + wd + ",toolbar=0,location=0,menubar=0,resizable=1")
}
function makeNewQTWindow(w,h,myurl){
  newWindow = window.open(myurl,"","status,height=" + h + ",width=" + w + ",toolbar=0,location=0,menubar=0,resizable=1")
}

var UniqueID = 314;
var newWinOffset = 0;

function makeNewAudioWindow(mytitle,myurl) {
  var title = (mytitle!=null) ? mytitle : "Audio File";
  PlayWin = window.open('',UniqueID,'width=340,height=190,top=' + newWinOffset + ',left=0,resizable,scrollbars');
  PlayWin.focus();

  var winContent = "<HTML><HEAD><TITLE>" + title + "</TITLE></HEAD><BODY bgcolor='#CEE6FF'>";
  winContent += "<p style='font-size:14px;font-family:Verdana,sans-serif;text-align:center'><b>" + title + "</b></p>";

  winContent += "<OBJECT id='MediaPlayer' width='300' height='42'classid='CLSID:22D6f312-B0F6-11D0-94AB-0080C74C7E95' type='application/x-oleobject' codebase='mms://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,4,7,1112'>";
  winContent += "<param name='SRC' value='" + myurl + "'>";
  winContent += "<param name='AUTOPLAY' VALUE='true'>";
  winContent += "<param name='Showcontrols' value='True'>";
  //winContent += "<param name='BGCOLOR' VALUE='#FF9900'>";
  winContent += "<EMBED type='application/x-mplayer2' name='MediaPlayer' SRC='" + myurl + "' AUTOSTART='true' LOOP='FALSE' WIDTH='300' HEIGHT='42' CONTROLLER='TRUE'></EMBED>";
  winContent += "</OBJECT>";

  winContent += "<p style='font-size:12px;font-family:Verdana,sans-serif;text-align:center'><a href='" + myurl +"'>Download file</a> <SPAN style='font-size:10px'>(right-click and 'Save Target')</SPAN></p>";
  winContent += "<DIV align='center'><INPUT type='button' value='Close this window' onclick='javascript:window.close();'></DIV>";
  winContent += "</BODY></HTML>";

  PlayWin.document.write(winContent);
  PlayWin.document.close();
  UniqueID = UniqueID + 1;
  newWinOffset = newWinOffset + 20;
}

// hide address from spam robots
function doMail(user,domain){
var at = String.fromCharCode(64);
var linkStr = 'mai' + 'lto:' + user + at + domain;
document.write('<a href="' + linkStr + '">' + user + at + domain +'</a>');
}

function RunObjectTag(ID, Name, Height, Width, BGcolour){

	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="' + Width + '" height="' + Height + '" id="' + ID + '" align="middle">\n');
  document.write('<param name="movie" value="' + Name + '" /><param name="quality" value="high" /><param name="bgcolor" value="' + BGcolour + '" />\n');
 	document.write('<embed name = "' + ID + '" src="' + Name + '" quality="high" swLiveConnect="true"  pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash"  width="' + Width + '" height="' + Height + '">');
 	document.write('</embed></object>\n');

}


/*
====================================================================================================
Base64 encode / decode http://www.webtoolkit.info/
====================================================================================================
*/

var Base64 = {

	// private property
	_keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",

	// public method for encoding
	encode : function (input) {
		var output = "";
		var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
		var i = 0;

		input = Base64._utf8_encode(input);

		while (i < input.length) {

			chr1 = input.charCodeAt(i++);
			chr2 = input.charCodeAt(i++);
			chr3 = input.charCodeAt(i++);

			enc1 = chr1 >> 2;
			enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
			enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
			enc4 = chr3 & 63;

			if (isNaN(chr2)) {
				enc3 = enc4 = 64;
			} else if (isNaN(chr3)) {
				enc4 = 64;
			}

			output = output +
			this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) +
			this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4);

		}

		return output;
	},

	// public method for decoding
	decode : function (input) {
		var output = "";
		var chr1, chr2, chr3;
		var enc1, enc2, enc3, enc4;
		var i = 0;

		input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");

		while (i < input.length) {

			enc1 = this._keyStr.indexOf(input.charAt(i++));
			enc2 = this._keyStr.indexOf(input.charAt(i++));
			enc3 = this._keyStr.indexOf(input.charAt(i++));
			enc4 = this._keyStr.indexOf(input.charAt(i++));

			chr1 = (enc1 << 2) | (enc2 >> 4);
			chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
			chr3 = ((enc3 & 3) << 6) | enc4;

			output = output + String.fromCharCode(chr1);

			if (enc3 != 64) {
				output = output + String.fromCharCode(chr2);
			}
			if (enc4 != 64) {
				output = output + String.fromCharCode(chr3);
			}

		}

		output = Base64._utf8_decode(output);

		return output;

	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}

function addFlash() {
	// dummy
}