var xmlHttp;
var theBoxType;
var theBoxToChange;

function setBox(str,box_type,box_id) { 
	//alert("box_id: "+box_id);
	
	theBoxType = box_type;
	theBoxToChange = box_id;
	
	xmlHttp=GetXmlHttpObject()
	
	if (xmlHttp==null) {
		alert ("Browser does not support HTTP Request")
		return
	}
	
	var url="boxControlls.php"
	url=url+"?q="+str
	url=url+"&box_type="+box_type
	url=url+"&box_id="+box_id
	url=url+"&sid="+Math.random()
	xmlHttp.onreadystatechange=stateChanged 
	//alert("URL: "+url);
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}

function stateChanged() { 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") { 
		//alert(xmlHttp.responseText);
		//alert(theBoxToChange);
		//alert(theBoxType);
		switch(xmlHttp.responseText) {
			case "show":
				//document.getElementById(theBoxToChange).style.borderWidth = "thick";
				//document.getElementById(theBoxToChange).innerHTML=xmlHttp.responseText;
				document.getElementById(theBoxToChange).style.display = "inline";
				document.getElementById('show'+theBoxToChange).style.display = "none";
				document.getElementById('hide'+theBoxToChange).style.display = "inline";
				if (theBoxType == "page") {
					document.getElementById("page_"+theBoxToChange).style.display = "inline";
				}
				else if (theBoxType == "section") {
					document.getElementById("page_"+theBoxToChange).style.display = "inline";
				}
				//alert(document.getElementById('hide'+theBoxToChange).style.display);
				break;
			case "hide":
				//document.getElementById(theBoxToChange).style.borderWidth = "thick";
				//document.getElementById(theBoxToChange).innerHTML=xmlHttp.responseText;
				document.getElementById(theBoxToChange).style.display = "none";
				document.getElementById('show'+theBoxToChange).style.display = "inline";
				document.getElementById('hide'+theBoxToChange).style.display = "none";
				if (theBoxType == "page") {
					document.getElementById("page_"+theBoxToChange).style.display = "none";
				}
				else if (theBoxType == "section") {
					document.getElementById("page_"+theBoxToChange).style.display = "none";
				}
				break;
			case "remove":
				if (theBoxType == "result") {
					document.getElementById("trBox_"+theBoxToChange).style.display = "none";
				}
				else {
					document.getElementById("controlBox_"+theBoxToChange).style.display = "none";
					if (theBoxType == "page") {
						document.getElementById("page_"+theBoxToChange).style.display = "none";
					}
					else if (theBoxType == "section") {
						document.getElementById("page_"+theBoxToChange).style.display = "none";
					}
					break;
				}
			default:
				//document.getElementById(theBoxToChange).style.borderWidth = "thin";
				//document.getElementById(theBoxToChange).innerHTML=xmlHttp.responseText;
				document.getElementById(theBoxToChange).style.display = "inline";
				break;
		}
	} 
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		//Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}
