/* var request = null; */
/* var queryString = "";*/

/* Initialize a Request object that is already constructed */



function initReq(request, reqType,url,bool,respHandle)
{


    try{
        /* Specify the function that will handle the HTTP response */
        request.onreadystatechange=respHandle;

        request.open(reqType,url,bool);
        //if the reqType parameter is POST, then the
        //5th argument to the function is the POSTed data

         if( arguments[5])      
        
//       if(reqType.toLowerCase() == "post") 
        {
            request.setRequestHeader("Content-Type",
                        "application/x-www-form-urlencoded; charset=UTF-8");
            request.send(arguments[5]);    
        }   
        else 
        {
            request.send(null);
        }
    } 
    catch (errv) 
    {
        alert(
                "The application cannot contact "+
                "the server at the moment. "+
                "Please try again in a few seconds.\n"+
                "Error detail: "+errv.message);
    }
}


/* Wrapper function for constructing a Request object.
 Parameters:
  reqType: The HTTP request type such as GET or POST.
  url: The URL of the server program.
  asynch: Whether to send the request asynchronously or not.
  respHandle: The name of the function that will handle the response.
  Any fifth parameters represented as arguments[4] are the data a
  POST request is designed to send. 

  if a form is being submitted, the function will fetch the
  form variables, THIS HAS NOT BEEN TESTED AND MAY NOT
  WORK FOR FORMS WITH MULTIPLE PAGES.  

*/


function httpRequest(request,reqType,url,asynch,respHandle)
{
var query_string = "";
var frm = document.forms[0];


    //if the reqType parameter is POST, then the
    //6th argument to the function is the POSTed data
    if(reqType.toLowerCase() == "get") 
    {
        initReq(request,reqType,url,asynch,respHandle, "");
    }
    else if(arguments[5] )
        initReq(request,reqType,url,asynch,respHandle, arguments[5]);
    else if(frm)
    {   
     
        var num_elements = frm.elements.length;
        for(var i=0; i < num_elements; i++)
        {
	    if(i < (num_elements-1))
		query_string += frm.elements[i].name + "=" +
                                encodeURIComponent(frm.elements[i].value) + "&";
            else 
		query_string += frm.elements[i].name + "=" +
                                encodeURIComponent(frm.elements[i].value); 


	}    

        initReq(request,reqType,url,asynch,respHandle,query_string);
    }
    else 
        initReq(request,reqType,url,asynch,respHandle, "");

//      alert("Check for errors in the httpRequest() function");

}


function make_httpRequest_object()
{
var request;

     if(window.XMLHttpRequest)
        request = new XMLHttpRequest();
     else 
     {
        request=new ActiveXObject("Msxml2.XMLHTTP");
        if (! request)
            request=new ActiveXObject("Microsoft.XMLHTTP");
        
     }
     
    if(request)
        return request;
     else
        alert("Your browser does not permit the use of all "+
              "of this application's features!");
}


