function pageInit() {
	window.setTimeout("externaLinks();",0);
	document.getElementById("jsMsg").style.display = 'none';
	fadein("content",200,100);
	if(document.getElementById("masterWaitDummyContainer")) {
		fadein('theContainer',400,500);
		fadeout('masterWait',400,500);
		// var dummyImg = document.createElement("img");
		// 		dummyImg.onLoad = function() {
		// 			fadein('theContainer',400,500);
		// 			fadeout('masterWait',400,500);
		// 		}
		// 		dummyImg.src = "/ui/img/dummy.png";
		// 		
		// 		document.getElementById("masterWaitDummyContainer").appendChild(dummyImg);
	}
}

function debugAjaxReturn(responseText) {
	var ajaxDebugDiv = document.createElement("pre");
	ajaxDebugDiv.innerHTML = ''+responseText+'';
	ajaxDebugDiv.id = 'ajaxDebug';
	document.body.appendChild(ajaxDebugDiv);
}


function externaLinks() {
	var anchors = document.getElementsByTagName("a"); 
	for (var i=0; i<anchors.length; i++) {
		if (anchors[i].getAttribute("rel") == "external") { anchors[i].target = "_blank"; }
	}
}

function getBrowserDims() {
	if (window.innerWidth) {	//if browser supports window.innerWidth
		return Array(window.innerWidth,window.innerHeight);
	}
	else if (document.all) {	//else if browser supports document.all (IE 4+)
		return Array(document.body.clientWidth,document.body.clientHeight);
	}
	
}


var ANIMATION_FPS = 15.0; 					// frames per second
var ANIM_DELAY = 1000/ANIMATION_FPS;		// milliseconds per frame, i.e. time of delay

function fadein(id,fadetime,delaytime) {
	// take a hidden/transparent element with id and fade it in over fadetime milliseconds
	initializeFadein(id);
	if(!fadetime) { var fadetime = 400; }
	if(!delaytime) { var delaytime = 0; }
	var dOp = ANIM_DELAY/fadetime;
	window.setTimeout("fader('"+id+"',"+dOp+");",2*ANIM_DELAY+delaytime);
	window.setTimeout("initializeFadeout('"+id+"');",2*ANIM_DELAY+fadetime+delaytime);
}
function fadeout(id,fadetime,delaytime) {
	// take a hidden/transparent element with id and fade it in over fadetime milliseconds
	initializeFadeout(id);
	if(!fadetime) { var fadetime = 400; }
	if(!delaytime) { var delaytime = 0; }
	var dOp = -ANIM_DELAY/fadetime;
	
	window.setTimeout("fader('"+id+"',"+dOp+");",2*ANIM_DELAY+delaytime);
	window.setTimeout("finishFadeout('"+id+"');",2*ANIM_DELAY+fadetime+delaytime);
}

function fader(id,dOp) {
 	var elStyle = document.getElementById(id).style;		// convenience definition
	var curOp = parseFloat(elStyle.opacity);
	
	if ( ((dOp > 0) && (curOp < 1)) || ((dOp < 0) && (curOp > 0)) ) {
		newOp = (curOp + dOp);
		
		elStyle.opacity = newOp; 				// css compliant
		elStyle.MozOpacity = newOp; 			// supposedly outdated
		elStyle.KhtmlOpacity = newOp;			// probably outdated
		elStyle.filter = "alpha(opacity=" + Math.round(newOp*100) + ")";
		
		window.setTimeout("fader('"+id+"',"+dOp+");",ANIM_DELAY);
		// document.getElementById("jsdebug").innerHTML = ''+newOp+'';
	}
}

function initializeFadein(id) {
	document.getElementById(''+id+'').style.visibility='visible';
	document.getElementById(''+id+'').style.opacity=0;
	document.getElementById(''+id+'').style.MozOpacity=0;
	document.getElementById(''+id+'').style.KhtmlOpacity=0;
	document.getElementById(''+id+'').style.filter = "alpha(opacity=0)";
}
function initializeFadeout(id) {
	document.getElementById(''+id+'').style.visibility='visible';
	document.getElementById(''+id+'').style.opacity=1;
	document.getElementById(''+id+'').style.MozOpacity=1;
	document.getElementById(''+id+'').style.KhtmlOpacity=1;
	document.getElementById(''+id+'').style.filter = "alpha(opacity=100)";
}
function finishFadeout(id) {
	document.getElementById(''+id+'').style.visibility='hidden';
	document.getElementById(''+id+'').style.opacity=0;
	document.getElementById(''+id+'').style.MozOpacity=0;
	document.getElementById(''+id+'').style.KhtmlOpacity=0;
	document.getElementById(''+id+'').style.filter = "alpha(opacity=100)";
}

function GetXmlHttpObject() {
	var xmlHttp = null;
	try {
		xmlHttp = new XMLHttpRequest();
		// if (xmlHttp.overrideMimeType) {
			xmlHttp.overrideMimeType('text/html');
		// }
	}	// Firefox, Opera 8.0+, Safari
	catch (e) {								//Internet Explorer
		try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	}
	return xmlHttp;
}

jsonParse=(function(){var at,ch,escapee={'"':'"','\\':'\\','/':'/',b:'\b',f:'\f',n:'\n',r:'\r',t:'\t'},text,error=function(m){throw{name:'SyntaxError',message:m,at:at,text:text};},next=function(c){if(c&&c!==ch){error("Expected '"+c+"' instead of '"+ch+"'");} ch=text.charAt(at);at+=1;return ch;},number=function(){var number,string='';if(ch==='-'){string='-';next('-');} while(ch>='0'&&ch<='9'){string+=ch;next();} if(ch==='.'){string+='.';while(next()&&ch>='0'&&ch<='9'){string+=ch;}} if(ch==='e'||ch==='E'){string+=ch;next();if(ch==='-'||ch==='+'){string+=ch;next();} while(ch>='0'&&ch<='9'){string+=ch;next();}} number=+string;if(isNaN(number)){error("Bad number");}else{return number;}},string=function(){var hex,i,string='',uffff;if(ch==='"'){while(next()){if(ch==='"'){next();return string;}else if(ch==='\\'){next();if(ch==='u'){uffff=0;for(i=0;i<4;i+=1){hex=parseInt(next(),16);if(!isFinite(hex)){break;} uffff=uffff*16+hex;} string+=String.fromCharCode(uffff);}else if(typeof escapee[ch]==='string'){string+=escapee[ch];}else{break;}}else{string+=ch;}}} error("Bad string");},white=function(){while(ch&&ch<=' '){next();}},word=function(){switch(ch){case't':next('t');next('r');next('u');next('e');return true;case'f':next('f');next('a');next('l');next('s');next('e');return false;case'n':next('n');next('u');next('l');next('l');return null;} error("Unexpected '"+ch+"'");},value,array=function(){var array=[];if(ch==='['){next('[');white();if(ch===']'){next(']');return array;} while(ch){array.push(value());white();if(ch===']'){next(']');return array;} next(',');white();}} error("Bad array");},object=function(){var key,object={};if(ch==='{'){next('{');white();if(ch==='}'){next('}');return object;} while(ch){key=string();white();next(':');if(Object.hasOwnProperty.call(object,key)){error('Duplicate key "'+key+'"');} object[key]=value();white();if(ch==='}'){next('}');return object;} next(',');white();}} error("Bad object");};value=function(){white();switch(ch){case'{':return object();case'[':return array();case'"':return string();case'-':return number();default:return ch>='0'&&ch<='9'?number():word();}};return function(source,reviver){var result;text=source;at=0;ch=' ';result=value();white();if(ch){error("Syntax error");} return typeof reviver==='function'?(function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}} return reviver.call(holder,key,value);}({'':result},'')):result;};}());