window.onload = function() {
	document.onmousemove = moveCoords;
}

function mouseCoords(evt) {
	var coords = new Object();
	
	if (!evt) {
		var evt = window.event;
		}
		
	if (evt.pageX || evt.pageY) { //Firefox and crew
		coords.x = evt.pageX;  //x position of the mouse
		coords.y = evt.pageY; //Y position of the mouse
	} else if (evt.clientX || evt.clientY) { //Internet Explorer
		coords.x = evt.clientX + document.body.scrollLeft - document.body.clientLeft;
		coords.y = evt.clientY + document.body.scrollTop - document.body.clientTop;
	
	}
	writeCoords(coords);
	}
	
function writeCoords(coords) {
	var xPos = document.getElementById("xPos");
	var yPos = document.getElementById("yPos");
	
	if (!xPos.firstChild) {
		var xPosText = document.createTextNode("x:" + coords.x);
		xPos.appendChild(xPosText);
	} else {
		xPos.firstChild.nodeValue = "x:" + coords.x;
	}
	if (!yPos.firstChild) {
		var yPosText = document.createTextNode("y:" + coords.y);
		yPos.appendChild(yPosText);
	} else {
		yPos.firstChild.nodeValue = "y:" + coords.y;
		}
	}
