String.prototype.trim = function() {
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}

var http_request_return = 'ok';
var req = false;
if (window.XMLHttpRequest)	req = new XMLHttpRequest();
if (window.ActiveXObject) {
	try {
		req = new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try {
			req = new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e) {
			req = false;
		}
	}
}

function processSearchresult() {

	if (req.readyState == 4) {
		if (req.status == 200) {
			return true;
		} else {
			alert("Error fetching script");
			return false;
		}
	}
	return false;
}

function opacity(id, opacStart, opacEnd, millisec) {
	//speed for each frame
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}

	} else if(opacStart < opacEnd) {
		for(i = opacStart; i <= opacEnd; i++)
			{
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}
	}
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
	var object = document.getElementById(id).style; 
	object.opacity = (opacity / 100);
	object.MozOpacity = (opacity / 100);
	object.KhtmlOpacity = (opacity / 100);
	object.filter = "alpha(opacity=" + opacity + ")";
}

function get_url(url) {
	document.body.style.cursor='wait';
	if (!req) { 
		alert("Your browser does not support this game");
		return;
	}

	http_request_return = null;

	req.abort();
	req.onreadystatechange = processSearchresult;
	req.open("GET", url, false);
	req.send("");
	
	document.body.style.cursor='auto';
	if (req.responseText) {
		return req.responseText;
	}

	return false;
}


function fill_html(id, url) {
	var a = get_url(url);


	var e = document.getElementById(id);

	if (!e) return false;

	e.innerHTML = a;
}

function switch_html(id, opacStart, opacEnd, millisec, url) {
	//speed for each frame

	var element = document.getElementById(id);
	var speed = Math.round(millisec / 100);
	var timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	if(opacStart > opacEnd) {
		for(i = opacStart; i >= opacEnd; i--) {
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
			timer++;
		}

		setTimeout('fill_html("dyn_content", "' + url + '")', (timer * speed) );		
		setTimeout("opacity('dyn_content', 0, 100, 2000)",(timer * speed) );

	}
}

