 // Update loop value

//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else if(window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        alert("Your Browser does not support AJAX!\nIt's about time to upgrade don't you think?");
    }
}


//XmlHttpRequest object to get the auto suggest
//searchReq
var httpRequestObj = getXmlHttpRequestObject();

//0	The request is not initialized
//1	The request has been set up
//2	The request has been sent
//3	The request is in process
//4	The request is complete

//Called from setInterval every X seconds
function getLoopValue(username) {
	
    if (httpRequestObj.readyState == 4 || httpRequestObj.readyState == 0) {

		//Setup the object
        httpRequestObj.open("GET", "bll/getLoopValue.php?username=" + username, true);
		
		//Do not use () for the handler reference
        httpRequestObj.onreadystatechange = handleStateChange; 
		
		//Send GET... null becuase we did not send a POST
        httpRequestObj.send(null);	
    }        
}


//AJAX response handler
function handleStateChange() {
	
    if (httpRequestObj.readyState == 4) {
		// Get a reference to the the loop textbox
        var loop = document.getElementById('txtloop2');
		//var statusSpan = document.getElementById('spanStatus');
		var str = httpRequestObj.responseText.split("\n");
		loop.value = str[0];
		//statusSpan.innerText = str[1];
    }
}

function getInstrumentPanel() {
	
	if (httpRequestObj.readyState == 4 || httpRequestObj.readyState == 0) {

		//Ading the date and time to the querysting does nothing but make the 
		//URL unique so silly IE does not cache try to cache the URL.  Holly crap that was a 
		//pain in ass to figure out!  Thanks IE...
		var url = "../bll/getInstrumentPanel.php?id=iecachefix" + "&ms=" + new Date().getTime();

		//Setup the object
        httpRequestObj.open("GET", url, true);
		
		//Do not use () for the handler reference
        httpRequestObj.onreadystatechange = handleInstrumentChange; 
		
		//Send GET... null becuase we did not send a POST
        httpRequestObj.send(null);	
    } 
}

function handleInstrumentChange() {

    if (httpRequestObj.readyState == 4) {
		// Get a reference to the the loop textbox
        var divInstrumentPanel = document.getElementById('instrumentPanel');

		var str = httpRequestObj.responseText;
		divInstrumentPanel.innerHTML = str;

    }
}

//Button Commands
function executeMove(file) {
	//alert(file + " Test!");
	var httpRequest = getXmlHttpRequestObject();
	
	//The date time function is needed so silly IE does not cache the page.
	var url = "../bll/setMoveRequest.php?filename=" + file + "&ms=" + new Date().getTime();
	
	httpRequest.open("GET", url + file, true);	
	httpRequest.send(null);
	
	//if (httpRequest.readyState == 4 || httpRequest.readyState == 0) {}
	
	
}
