var xhr = false;

function makeXhr(){
	if (window.XMLHttpRequest){
		xhr = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP")
			}
			catch (e) {
				try {
					xhr = new ActiveXObject("Microsoft.XMLHTTP")
				
				}			
			catch (e) {}
			}
		}
	}	
}

function getImg(imgnumber,project,destination) {
	makeXhr();
	dest = destination;
	var url = "/php/getimage.php?id="+imgnumber+"&p="+project+"";
	if (xhr) {
		xhr.onreadystatechange = showImage;
		xhr.open("GET", url, true);
		xhr.send(null);
	} else {
		document.getElementByID(destination).innerHtml = "Sorry, but I couldnt create an XMLHttpRequest";
	}
}


function getDesc(project,destination) {
	makeXhr();
	dest = destination;
	var url = "/php/getdesc.php?p="+project+"";
	if (xhr) {
		xhr.onreadystatechange = showImage;
		xhr.open("GET", url, true);
		xhr.send(null);
	} else {
		document.getElementByID(destination).innerHtml = "Sorry, but I couldn't create an XMLHttpRequest";
	}
}


function showImage() {
	if (xhr.readyState == 4) {
        if (xhr.status == 200) {
			var markup = (xhr.responseXML && xhr.responseXML.contentType == "text/xml") ? xhr.responseXML.getElementsByTagName("choices")[0].textContent : xhr.responseText;
        } else {
            var markup = "There was a problem with the request " + xhr.status;
        }
        document.getElementById(dest).innerHTML = markup;
    }
}
