var xmlHttp;

function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	} else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
}

function handleTagStateChange() {
	if(xmlHttp.readyState == 4) {
		if(xmlHttp.status == 200) {
			changeOpResult();
		}
		else {
			alert ("AJAX error!");
		}
	}
}

function change(iID) {
	
	sCurrVal = document.getElementById("node" + iID).firstChild.nodeValue;
	
	iNewVal = parseInt(sCurrVal) + 1;
	if (iNewVal > 7) {
		iNewVal = 0;	
	}
	
	//sURL = "change.php?id=" + iID + "&v=" + iNewVal;
	//sURL = sURL + "&ts=" + new Date().getTime();
	
	//alert(sURL);
		
	//createXMLHttpRequest();
	//xmlHttp.onreadystatechange = handleTagStateChange;
	//xmlHttp.open("GET", sURL, true);
	//xmlHttp.send(null);
	
	changeOpResult(iNewVal, iID);
}

function changeOpResult(iValue, iID) {
	
	//var responseXML = xmlHttp.responseXML;
	//var iValue = responseXML.getElementsByTagName("value").item(0).firstChild.nodeValue;
	//var iID = responseXML.getElementsByTagName("id").item(0).firstChild.nodeValue;
	
	var nCell = document.getElementById("node" + iID);
	var oCell = document.getElementById("image" + iID);
	var iCell = document.getElementById("input" + iID);
	
	if (iValue == 0) {
		oCell.setAttribute("src","game_data/world_images/black.png");
	}
	if (iValue == 1) {
		oCell.setAttribute("src","game_data/world_images/earth.png");
	}
	if (iValue == 2) {
		oCell.setAttribute("src","game_data/world_images/wood.png");
	}
	if (iValue == 3) {
		oCell.setAttribute("src","game_data/world_images/rocks.png");
	}
	if (iValue == 4) {
		oCell.setAttribute("src","game_data/world_images/grave.png");
	}
	if (iValue == 5) {
		oCell.setAttribute("src","game_data/things_images/coin.png");
	}
	if (iValue == 6) {
		oCell.setAttribute("src","game_data/things_images/fire.png");
	}
	if (iValue == 7) {
		oCell.setAttribute("src","game_data/things_images/mushroom.png");
	}
	
	nCell.firstChild.nodeValue = iValue;
	iCell.setAttribute("value", iValue);
	
	
}