﻿/*********************************************************************************************************************
Bus Strategy IMap Application Common AJAX Functions JavaScript File
Author : Mark Mackenzie
Date   : December 2009

History:
FileVersion     AppVersion	Who     When                Why
----------------------------------------------------------------------------------------------------------------------
1.0.0.0         0.0.0.0     MM      December 2009       Created file

1.0.0.0         1.0.0.0     MM      18th March 2010     Version 1.

**********************************************************************************************************************/

/****** global vars *******/
var xmlHttp = null;
/**************************/

/**
 * Gets an instance of an XmlHttpObject.
 * Used to send and receive HTTP streams to/from server
 */
function GetXmlHttpObject(handler)
{ 
    //local vars
    var objXmlHttp = null;

    //depending on the browser, try to create the xmlHttp object 
    if (IsIE() && !IsIE7())
    { 
        //the object to create depends on version of IE (under v7.0)
        //if it isn't ie5, then default to the MSXML2.XMLHTTP.3.0 object 
        var strObjName = (IsIE5()) ? 'Microsoft.XMLHTTP' : 'MSXML2.XMLHTTP.3.0';         
         
        //attempt to create the object 
        try
        { 
            objXmlHttp = new ActiveXObject(strObjName); 
            objXmlHttp.onreadystatechange = handler; 
        } 
        catch(e)
        { 
            //object creation errored 
            alert('AJAX - IE detected, but object could not be created. Verify that active scripting and activeX controls are enabled'); 
            return; 
        } 
    } 
    else if (IsOpera())
    { 
        //opera has some issues with xmlHttp object functionality 
        alert('Opera detected. The page may not behave as expected.'); 
        return; 
    } 
    else
    { 
        // Mozilla | Netscape | Safari | IE7
        objXmlHttp = new XMLHttpRequest(); 
        if (IsIE7()) objXmlHttp.onreadystatechange = handler; 
        objXmlHttp.onload = handler; 
        objXmlHttp.onerror = handler; 
    } 
     
    //return the object 
    return objXmlHttp; 
}

//XMLHttp send GET request 
function xmlHttp_Get(xmlhttp, url)
{ 
    xmlhttp.open('GET', url, true);     
    xmlhttp.send(null); 
}
