var xhr = false;

function getImage(img,destination,section) {
	if (window.XMLHttpRequest){
		xhr = new XMLHttpRequest();
	} else {
		if (window.ActiveXObject) {
			try {
				xhr = new ActiveXObject("Microsoft,XMLHTTP")
			
			}
			catch (e) { }
		}
	}

	dest = destination;
	var url = "/php/getimage.php?id="+img+"&section="+section;

	if (xhr) {
		xhr.onreadystatechange = showImage;
		xhr.open("GET", url, true);
		xhr.send(null);
	} else {
		document.getElementByID(destination).innerHtml = "Sorry, but I couln'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;
    }
}


function showFile(num){
	var inputfield = "image"+num;
	var field = document.getElementById(inputfield);
	field.setAttribute("style","display:inline;");
	var plus = document.getElementById("plus");
	if (num < 5){
		var nextnum = num+1;
		plus.setAttribute("onclick","showFile("+nextnum+")");
	} else {
		plus.setAttribute("style","display:none;");
	}
}

function clearPH(el,val){
	var name = el.value;
	if (name == val){
		el.value = "";
		el.setAttribute("style","color:#000000;");
	}
	
}

function addPH(el,val){
	var name = el.value;
	if (name == ""){
		el.value = val;
		el.setAttribute("style","color:#666666;");
	}
	
}


