// AJAX breakz teh fuckn backbuttn of yer browsah, lets taek caer of dat.
// 

var expectedHash = "";

function makeHistory(newHash) {
	window.location.hash = newHash;	
	expectedHash = window.location.hash;
	return true;	
}

function handleHistory() {
	if (window.location.hash != expectedHash) {
		expectedHash = window.location.hash;
		var pageName = expectedHash.substring(1);
		loadPage(pageName);
	}

	return true;
}

function pollHash() {
	handleHistory();
	window.setInterval("handleHistory()", 1000);
	return true;
}


function gid(n) {
	return document.getElementById(n);
}

function checkEnter(k,f) {
	if(k==13) {
		doShout();
	}
}


function getShout(p) {
	jx.load(
		"onel.php?start=" + p, function(data) {
			gid('shoutBox').innerHTML = data;
		}	
	);
}

function doShout() {
	if (gid('nick').value == '') {
		alert('Please enter a nickname!');
		return;
	}

	if (gid('msg').value == '') {
		alert('Please enter a message!');
		return;
	}

	if (gid('msg').length < 10) {
		alert('Please enter a longer message!');
		return;
	}	

	jx.load(
		"s.php?n=" + gid('nick').value + "&m=" + gid('msg').value, function(data) {
			gid('tmp').innerHTML = data;

			gid('nick').value = '';
			gid('msg').value = '';

			getShout(0);
		}
	);
}

function loadPage( pageName ) {
	document.getElementById('inhoud').innerHTML = '<br><br><br><center><b>.. dECRUNChiNG ..</b></center>';

//	e.stop();
	$('inhoud').fade(0); 

//	while($('inhoud')

	jx.load(
		pageName, function(data) {
			document.getElementById('inhoud').innerHTML = data;
			afterInstant();

			if (pageName == 'index_a.php') {
				getShout(0);
			}

			//e.stop();
			$('inhoud').fade(1); 
		}
	);

	//alert('makeHistory('+pageName+');');
	makeHistory(pageName);
	return true;
}

function setName(val) {
	gid('prodName').innerHTML = '<font size=-1>' + val + '</font>';
}


