/**
 * Name: dojoRequest
 * Purpose: Sends an ajax request to the specified server.
 * Parameter: p_sRequestUrlWithParams - desired server with parameters and values
 * Parameter: p_sResponseDivId - the div for displaying the server's response
 */
function dojoRequest(p_sRequestUrlWithParams, p_sResonseDivId, p_sHandleAs){
  if(p_sHandleAs == null){
    p_sHandleAs = "text";
  }
  
  dojo.xhrGet( {
    url: p_sRequestUrlWithParams,
    handleAs: p_sHandleAs,
    preventCache: true,
    load: function(response){ 
      dojo.byId(p_sResonseDivId).innerHTML = response;
    }
  }); // end dojo.xhrGet
}

/**
 * Name: dojoRequest
 * Purpose: Sends an ajax request to the specified server.
 * Parameter: p_sRequestUrlWithParams - desired server with parameters and values
 */
function dojoRequestNoResults(p_sRequestUrlWithParams){
  dojo.xhrGet( {
    url: p_sRequestUrlWithParams,
    preventCache: true
  }); // end dojo.xhrGet
}

/**
 * Name: dojoRequestPost
 * Purpose: Sends an ajax request (post) to the specified server.
 */
function dojoRequestPost(p_FormId, p_sRequestUrlNoParams, p_sResonseDivId) {  
  //The form data is sent to the given URL using a POST method, 
  //rather than a GET by using the dojo.xhrPost function.
  dojo.xhrPost({
    url: p_sRequestUrlNoParams,
    load: function(response, data){
      dojo.byId(p_sResonseDivId).innerHTML = response;
      
      //Dojo recommends that you always return(response); to propagate 
      //the response to other callback handlers. Otherwise, the error 
      //callbacks may be called in the success case.
      return response;
    },
    error: function(response, data){
      dojo.byId(p_sResonseDivId).innerHTML = 
        "An error occurred, with response: " + response;
      return response;
    },
    
    //Setting the 'form' parameter to the ID of a form on the page
    //submits that form to the specified URL
    form:p_FormId
  });
}

/**
* Create an ajax request without Dojo.
*/
function getAjaxRequest(){
  var xmlHttp;
  try{
    // Firefox, Opera 8.0+, Safari
    xmlHttp = new XMLHttpRequest();
  }catch (e){
    // Internet Explorer
    try{
      xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch (e){
      try{
        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
      }catch (e){
        xmlHttp = null;
      }
    }
  }
  return xmlHttp;
}