

//FUNCTION TO USE AJAX TO SUBMIT DATA TO THE SERVER AND GET A RESPONSE WITHOUT RELOADING THE PAGE
//********* Params **************
//pageToCall:       Name of the page to call including extension (ex. getShippingMethod.aspx, suggestSearchOption.aspx)
//eventName:        Name of the event that we are processing on the server.  This just gets included in the param string as "EventName=" - broken out for clarity
//paramString:      String of paramters in the same format at a query string (ex. customerID=87;customerName=chris)
//callBackFunction: Name of the function to call when Ajax responds.  (ex. "showResults")  NOTE: You will need to define the script as taking one paramter (ex. showResults( Ajax_Response ) {...})

//function ajaxFunction(pageToCall, paramString, callBackFunction)
function ajaxFunction(pageToCall, eventName, callbackFunctionName, paramString)
{
    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)
            {      
                alert("Your browser does not support AJAX!");      
                return false;
            }    
        }
    }
    
    //SET UP CALL BACK FUNCTION
    xmlHttp.onreadystatechange=function()
    {
        if(xmlHttp.readyState==4)
        {
            //EVAL THE SCRIPT RESPONSE FROM THE SERVER
            eval(callbackFunctionName + "(\"" + xmlHttp.responseText + "\");" );
        }
    }
    
    //HIT THE SERVER
    xmlHttp.open("GET", pageToCall + "?" + "EventName=" + eventName + "&" + paramString  ,true);
    xmlHttp.send(null);  
}

