/* Against quirksmode.com */
if (self != top) {
	/*top.location.replace(location.href);*/
}

/* QUIRKSMODE JAVASCRIPT */
var blogs = ['/blog/','/bugreports/','/elsewhere/'];
var archivedText = 'You\'re looking at outdated content that is no longer maintained. Use with care.';
var advancedJavaScriptSupport = createXMLHTTPObject() && document.createElement && document.getElementsByTagName;
if (advancedJavaScriptSupport)
//	document.write('<style>body {padding-top: 161px;}</style>'); 	// make room for headers

window.onunload = function () {

	// execute unload routine of page, if present
	if (self.exit)
		exit();
	
	// execute unload routine for blog pages, if present
	if (self.exitBlogs)
		exitBlogs();
}

window.onload = function () {
	
	if (navigator.userAgent.indexOf('WidgetManager') != -1) {
		document.body.style.fontSize = '2em';
	}

	/* See if browser supports advanced interface */
	if (!advancedJavaScriptSupport) return;
	
	/* Load advanced interface */
	/*sendRequest('header.txt',setHeader);
	sendRequest('nav.txt',setNavigation);
	sendRequest('footer.txt',setFooter);*/

	//zebraLists();
	
	/* Miscellaneous */
	
	/*	setScreenShots();
	setCompTables();
	sizePres();
	redirectExternalLinks();*/
	window.onresize = sizePres;

	if (Preferences.siteNavPos && Preferences.siteNavPos != 'fixed') {
		document.getElementById('floating_sender').style.position = Preferences.siteNavPos;
	}
	else {

		setMenuOffset.initialPos = getStyle('floating_sender','top');
		window.onscroll = document.documentElement.onscroll = setMenuOffset;
		setMenuOffset();
		/* in Moz 1.7.12/FF 1.5 window.onscroll is wiped when you use the mouse wheel while 
		the pointer is NOT above a true page element (ie. when it is above the naked documentElement)
		 ... or something ...
		Of course Safari doesn't accept document.documentElement.onscroll; Op and IE 7 do */
	}
	/* Initialise blog and bilingual scripts, if they're there */
}




function setMenuOffset() { 

	$div_total=$("#floating_sender").height();

	var header = document.getElementById('floating_sender');
	if (!header){ 
	return;
	};

	var $size_footer= $(document).height()-$div_total;
	
	if (whichBrs()=='chrome'){
		$size_footer=$size_footer-200;
		$scroll_final=document.body.scrollTop;
	}
	
	if (whichBrs()=='Internet Explorer'){
			$size_footer=$size_footer-200;
			$scroll_final=document.documentElement.scrollTop;
	}
	
	if (whichBrs()=='Firefox'){
		$size_footer=$size_footer-200;
		$scroll_final=document.documentElement.scrollTop;
	}
	
	if ($size_footer <=$scroll_final){
		header.style.position='absolute';
		header.style.top=$size_footer+'px';
	
		return;	
	}
	else{
		header.style.position='fixed';
	}
		
	var currentOffset = document.documentElement.scrollTop || document.body.scrollTop; // body for Safari
	var startPos = parseInt(setMenuOffset.initialPos) || 2070; //1900
	
	var desiredOffset = startPos - currentOffset;
	
	if (desiredOffset < 10){
		desiredOffset = 10;
	}
	
	if (desiredOffset != parseInt(header.style.top)) {
			header.style.top = desiredOffset + 'px';
	}
}

function sizePres() {

	/* Stretch pres to right edge of browser window */
	var pres = document.getElementsByTagName('pre');
	if (!pres.length) return;
	var testPre;
	for (var i=0;i<pres.length;i++) {
		if (pres[i].parentNode.nodeName == 'BODY') {
			testPre = pres[i];
			break;
		}
	}
	if (!testPre) return;
	testPre.style.marginRight = 'auto';
	var docWidth = document.documentElement.clientWidth;
	var preWidth = testPre.offsetWidth;
	var rightMargin = docWidth - preWidth;
	if (rightMargin < 0)
		rightMargin = 0;
	for (var i=0;i<pres.length;i++) {
		if (pres[i].parentNode.nodeName == 'BODY') {
			pres[i].style.marginRight = '-' + rightMargin + 'px';	
		}
	}
}

function sendRequest(url,callback,postData) {
	var req = createXMLHTTPObject();
	if (!req) return;
	var method = (postData) ? "POST" : "GET";
	req.open(method,url,true);
	req.setRequestHeader('User-Agent','XMLHTTP/1.0');
	if (postData)
		req.setRequestHeader('Content-type','application/x-www-form-urlencoded');
	req.onreadystatechange = function () {
		if (req.readyState != 4) return;
		if (req.status != 200 && req.status != 304) {
		//	alert('HTTP error ' + req.status);
			return;
		}
		callback(req);
	}
	if (req.readyState == 4) return;
	req.send(postData);
}

function XMLHttpFactories() {
	return [
		function () {return new XMLHttpRequest()},
		function () {return new ActiveXObject("Msxml2.XMLHTTP")},
		function () {return new ActiveXObject("Msxml3.XMLHTTP")},
		function () {return new ActiveXObject("Microsoft.XMLHTTP")}
	];
}

function createXMLHTTPObject() {
	var xmlhttp = false;
	var factories = XMLHttpFactories();
	for (var i=0;i<factories.length;i++) {
		try {
			xmlhttp = factories[i]();
		}
		catch (e) {
			continue;
		}
		break;
	}
	return xmlhttp;
}

function getStyle(el,styleProp) {
	var x = document.getElementById(el);
	if (!x) return;
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

var Cookies = {
	init: function () {
		var allCookies = document.cookie.split('; ');
		for (var i=0;i<allCookies.length;i++) {
			var cookiePair = allCookies[i].split('=');
			this[cookiePair[0]] = cookiePair[1];
		}
	},
	create: function (name,value,days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires="+date.toGMTString();
		}
		else var expires = "";
		document.cookie = name+"="+value+expires+"; path=/";
		this[name] = value;
	},
	erase: function (name) {
		this.create(name,'',-1);
		this[name] = undefined;
	}
};
Cookies.init();

var Preferences = {
	init: function () {
		if (!Cookies.sitePrefs) return;
		sitePrefs = Cookies.sitePrefs.split(',,');
		for (var i=0;i<sitePrefs.length;i++) {
			var oneSitePref = sitePrefs[i].split(':');
			this[oneSitePref[0]] = oneSitePref[1];
		}	
	}
};
Preferences.init();


// Browser Detection Javascript
// copyright 1 February 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.
function showHeight(ele, h) {
	$("div").text("The height for the " + ele + 
                    " is " + h + "px.");
}


function whichBrs() {
var agt=navigator.userAgent.toLowerCase();
if (agt.indexOf("opera") != -1) return 'Opera';
if (agt.indexOf("staroffice") != -1) return 'Star Office';
if (agt.indexOf("webtv") != -1) return 'WebTV';
if (agt.indexOf("beonex") != -1) return 'Beonex';
if (agt.indexOf("chimera") != -1) return 'Chimera';
if (agt.indexOf("netpositive") != -1) return 'NetPositive';
if (agt.indexOf("phoenix") != -1) return 'Phoenix';
if (agt.indexOf("firefox") != -1) return 'Firefox';
if (agt.indexOf("chrome") != -1) return 'chrome';
if (agt.indexOf("safari") != -1) return 'Safari';
if (agt.indexOf("skipstone") != -1) return 'SkipStone';
if (agt.indexOf("msie") != -1) return 'Internet Explorer';
if (agt.indexOf("netscape") != -1) return 'Netscape';
if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
if (agt.indexOf('\/') != -1) {
if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
return navigator.userAgent.substr(0,agt.indexOf('\/'));}
else return 'Netscape';} else if (agt.indexOf(' ') != -1)
return navigator.userAgent.substr(0,agt.indexOf(' '));
else return navigator.userAgent;
}

