//my definition of an ajax handler
function  ajaxConfig ( argCommand, argContainer, argQueryString, argNextFunction, argASynch, argPassResponseToNextFunction  ) {
     //httpXML
     var obj = new Object();
     
     //There is a front of house controller and a back of house controller.  These need to be seperate because of the authentication layer.
     // I also want to keep box tracker functionality seperate from cairn apps functionality
     
     var loc = window.location.pathname;
     obj.controller = '/commands/controller.html'; // this is front of house - no apache authorization required  TODO clean up the sloppy elseif shiti
     obj.container = argContainer; 
     obj.command = argCommand;
     obj.queryString = argQueryString; 
     obj.nextFunction = argNextFunction;
     obj.aSynch = argASynch; 
     obj.passResponseToNextFunction = argPassResponseToNextFunction ? true : false; 
     obj.method = "POST"; 
     //Build post values
     obj.post = "command="+obj.command;
     if (obj.queryString) {
          obj.post = obj.post + "&" + obj.queryString;     
     }

     return obj; 
     
}

//-------------------------------------

function  getLongLat ( argAddress, argNextFunction  ) {
     // Specieal request object that gets longitude and latitude from google

     var obj = new Object();
     
     obj.controller = "http://maps.googleapis.com/maps/api/geocode/xml?address="+argAddress+"&sensor=false"; 
     obj.nextFunction = argNextFunction;
     obj.aSynch = true; 
     obj.passResponseToNextFunction = true; 

     //Build post values
     obj.method = "GET"; 
     return obj; 
     
}

//-------------------------------------

function runQuery( aHandler) {
     
          
          //build the browser agnostic XMLHTTPRequest object
	     objAjax = getXMLHTTPReqObject();
	     objAjax.onreadystatechange = function ( ) {
		     if (objAjax.readyState == 4){
                    if (aHandler.container) {     //will populate a container if there isone
                         document.getElementById(aHandler.container).innerHTML = objAjax.responseText; 
                    }

                    if (aHandler.nextFunction) {  //will run a function if there  is one
                         aHandler.nextFunction(); 
                    }
                    spinner(0); 
		     }
	     }

          spinner(1);
          
	     objAjax.open (aHandler.method, aHandler.controller, aHandler.aSynch);
          objAjax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
          objAjax.send(aHandler.post);
 }


//-------------------------------------

function spinner(argOnOff) { 
      //accepts a boolean and shows or hides the spinner 
      if (argOnOff) { 
           document.getElementById('ajax_loader').style.display = 'inline'; 
      } else { 
           document.getElementById('ajax_loader').style.display = '';      //revert back to css style 
      } 
 }


