/*-------------
@desc: an ajax function that can be used for any request
@params:
  request:  the url of the request
  updateId: the id of the element to update the contents of with outputs
  EvalResponse: 0: check for messages/use evals
                1: No matter what the response is, eval(messages)
                   (in this case, a universal eval should be stored in messages
                   instead of messages)
  messages: an array of messages that should be noticed
  evals:    array of code to be evaluated (corresponds to the messages array)
@return: not applicable
-------------*/

function UniversalAjax(request,EvalResponse,messages,evals){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Something's wrong with your browser! Ajax won't work...");
				return false;
			}
		}
	}
  ajaxRequest.onreadystatechange = function(){
  	if(ajaxRequest.readyState == 4){
      if (EvalResponse==1){
        eval(messages);
        return;
      }
  		for (c=0;c<messages.length;c++){
  		  if (ajaxRequest.responseText==messages[c]){
  		    eval(evals[c]);
  		  }
  		}
  	}
  }
	ajaxRequest.open("GET", request, true);
	ajaxRequest.send(null); 

}

function ajaxBlindRequest(request,loadId){
  var ajaxRequest;  // The variable that makes Ajax possible!
	//show loading bar
	if (loadId!=null){
	 document.getElementById(loadId).innerHTML="<img src='ajax-process.gif'>";
	}
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Something's wrong with your browser! Ajax won't work...");
				return false;
			}
		}
	}
	ajaxRequest.open("GET", request, true);
	ajaxRequest.send(null); 
}
