﻿//
// ajax helper routines
//
function createRequest()
{
    try
    {
        return new XMLHttpRequest();
    }
    catch( e1 )
    {
        try
        {
            return new ActiveXObject( "Msxml2.XMLHTTP" );
        }
        catch( e2 )
        {
            return new ActiveXObject( "Microsoft.XMLHTTP" );
        }
    }
}

//
// helper routine for sending xmlhttp requests
//
function xmlhttp( url, data, callback, context )
{
    //
    // create the xmlhttp object
    //
    var http = createRequest();
    
    //
    // register callback if this is going to be async
    //
    var async = ( typeof( callback ) == "function" );
    if( async )
    {
        http.onreadystatechange = function()
        {
            callback( http, context );
        }
    }
    
    //
    // send the request
    //
    var method = ( data == null ) ? "GET" : "POST";
    http.open( method, url, async );
    http.send( data );

    return http;
}
