function checkImageExists(image)  {
	if (image == "")  {
		document.getElementById("loadimage").value = "no";
	} else {
		processImage(image);
	}
}


function processImage(image)  {
	if (xmlHttp)  {
		try  {
			xmlHttp.open("GET","getimage.php?image="+image,true);
			xmlHttp.onreadystatechange = handleRequestStateChangeImage;
			xmlHttp.send(null);
		}
		catch (e)  {
			alert("Can't connect to the server: \n" + e.toString());
		}
	}
}

function handleRequestStateChangeImage()  {
	if (xmlHttp.readyState == 4)  {
		if (xmlHttp.status == 200)  {
			try  {
				handleServerResponseImage();
			}
			catch (e)  {
				alert("Error reading the response: " + e.toString());
			}
		} else {
			alert("There was a problem retrieving the data: \n" + xmlHttp.statusText);
		}
	}
}


function handleServerResponseImage()  {
	var xmlResponse = xmlHttp.responseXML;
	if (!xmlResponse || !xmlResponse.documentElement)  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);
	}
	var rootNodeName = xmlResponse.documentElement.nodeName;
	if (rootNodeName == "parsererror")  {
		throw("Invalid XML structure:\n" + xmlHttp.responseText);
	}
	xmlRoot = xmlResponse.documentElement;
	valueArray = xmlRoot.getElementsByTagName("value");
	for (var x=0;x<valueArray.length;x++)  {
		if (valueArray.item(x).firstChild.data == "a")  {
			document.getElementById("loadimage").value = "yes";
		} else {
			document.getElementById("loadimage").value = "no";
		}
	}
}
