
// Ajax Request By Razor

// Basically runs through all the types of xml request untill it finds one that the browser supports
function ajaxRequest()
{
    
    var xmlHttp;
    
    try
    {
        xmlHttp = new XMLHttpRequest();
    }
    catch(e)
    {
        var XmlHttpVersions = new Array('MSXML2.XMLHTTP.6.0',
                                        'MSXML2.XMLHTTP.5.0',
                                        'MSXML2.XMLHTTP.4.0',
                                        'MSXML2.XMLHTTP.3.0',
                                        'MSXML2.XMLHTTP',
                                        'Microsoft.XMLHTTP');
        
        for (i = 0; i < XmlHttpVersions.length && !xmlHttp; i++)
        {
            try
            {
                xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
            }
            catch(e) {}
        }
    }
    
    if (!xmlHttp)
    {
        alert("Your browser may not support XML Requests");
    }
    else
    {
        return xmlHttp;
    }
}

// Get the random image
function getxml()
{
    // The id of the div you want your images to be displayed in
    var imageDisplayDiv = "xmldiv";
    // The name of the file the images will come from
    var imageFile = "../xml/live_data.xml";
    
    // Starts a new request
    var ajax = ajaxRequest();
    
    // Gets the out put of the image file by sending nothing and just getting its finished product
    ajax.open("GET", imageFile, true);
    ajax.send(null);    
    
    // displayes a loading text so user knows the script is working
    //document.getElementById(imageDisplayDiv).innerHTML = "<span style=\"font-weight:bold;\"></span>";    
    
    // Cycles through the ajax state change
    ajax.onreadystatechange = function()
    {
        // if the ajax request is ready
        if (ajax.readyState == 4)
        {
            // Checks if it really is ready by checking status number , 200 = done
            if (ajax.status == 200)
            {
            // writes the image files output to the div
            document.getElementById(imageDisplayDiv).innerHTML = ajax.responseText;
            }
        }
    }
}

// Runs the script
function runxml()
{
getxml(); // Runs image function once
setTimeout("runxml()",500);
}

