function GetXmlHttpObject()
{
	var objXMLHttp=null
 	if (window.XMLHttpRequest)
 	{
	    objXMLHttp=new XMLHttpRequest()
	 }
	 else if (window.ActiveXObject)
	 {
	    objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	 }
	 return objXMLHttp
}

function makePOSTRequest(url, parameters, map) {
   http_request = false;
   if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
	    //http_request.overrideMimeType('text/xml');
	    http_request.overrideMimeType('text/html');
	 }
   } else if (window.ActiveXObject) { // IE
	 try {
	    http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
	    try {
	       http_request = new ActiveXObject("Microsoft.XMLHTTP");
	    } catch (e) {}
	 }
   }
   if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
   }

   if( url == "pictureBig.php" ){
   	http_request.onreadystatechange = alertPicture;
   }
   else if( url == "checkform.php" )
   {
   	http_request.onreadystatechange = alertForm;
   }
   else if( url == "movePic.php" || url == "delPic.php" )
   {
   	http_request.onreadystatechange = alertPic;
   } 
   else if( url == "delNews.php" )
   {
   	http_request.onreadystatechange = alertNews;
   }    
   http_request.open('POST', url, true);
   http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http_request.setRequestHeader("Content-length", parameters.length);
   http_request.setRequestHeader("Connection", "close");
   http_request.send(parameters);
}

function alertPicture() {
   if (http_request.readyState == 4) {
		 if (http_request.status == 200) {
			document.getElementById("pictureBig").style.display = "inline";
			document.getElementById("background").style.display = "inline";
			document.getElementById("pictureBig").innerHTML=http_request.responseText
		 } else {
			alert('There was a problem with the request.');
		 }
   }
}
function alertForm() {
   if (http_request.readyState == 4) {
		 if (http_request.status == 200) {
			document.getElementById("results").style.display = "inline";
			document.getElementById("results").innerHTML=http_request.responseText
		 } else {
			alert('There was a problem with the request.');
		 }
   }
}
function alertPic() {
   if (http_request.readyState == 4) {
		 if (http_request.status == 200) {
			location.href = 'index.php?page=orderpics&map=' + Uri.uitlezen('map');
		 } else {
			alert('There was a problem with the request.');
		 }
   }
}
function alertNews() {
   if (http_request.readyState == 4) {
		 if (http_request.status == 200) {
			location.href = 'index.php?page=news';
		 } else {
			alert('There was a problem with the request.');
		 }
   }
}

function get(obj)
{
	   var poststr = "";
	   var count = 0;
	   var lijst = document.getElementById(obj);

	   for (i=0; i<lijst.length; i++) {
		if (lijst[i].type == "text") {
		   poststr += lijst[i].name + "=" + lijst[i].value + "&";
		}
		if (lijst[i].type == "hidden") {
		   poststr += lijst[i].name + "=" + lijst[i].value + "&";
		}
		if( lijst[i].type == "radio" )
		{
			if (lijst[i].checked)
			{
			   	poststr += lijst[i].name + "=" + lijst[i].value + "&";
			}
		}
		if( lijst[i].type == "checkbox" )
		{
			if (lijst[i].checked)
			{
			   	poststr += lijst[i].name + "=" + lijst[i].value + "&";
			}
			else
			{
				poststr += lijst[i].name + "=&";
			}
		}
		if (lijst[i].tagName == "SELECT") {
		  	var sel = lijst[i];
		  	poststr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
		}
		if (lijst[i].tagName == "TEXTAREA"){
			var sel = lijst[i];
			poststr += sel.name + "=" + lijst[i].value + "&";
		}
	   }

	   makePOSTRequest("checkform.php", poststr);
}

function showPicture(id, width, height)
{
	makePOSTRequest("pictureBig.php", "&id=" + id + "&height=" + height + "&width=" + width);
}

function changeMap(obj)
{
	var poststr = "";
	var lijst = document.getElementById(obj);
	for (i=0; i<lijst.length; i++) {
		if (lijst[i].tagName == "SELECT") {
		  	var sel = lijst[i];
		  	poststr = "&id=" + obj + "&value=" + sel.options[sel.selectedIndex].value;
		  	makePOSTRequest("movePic.php", poststr);
		}
	}	   
	   
}

function del(id)
{
	if (confirm("Are you sure you want to delete this picture?")) {
		makePOSTRequest("delPic.php", "&id="+id);
	}
	return;
}

function delNews(id)
{
	if (confirm("Are you sure you want to delete this Newsitem?")) {
		makePOSTRequest("delNews.php", "&id="+id);
	}
	return;
}
