
function ajaxrequest()
{
    
    var xmlHttp;
    
    try
    {
        xmlHttp = new XMLHttpRequest();
    }
    catch(e)
    {
        var XmlHttpVersions = new Array('MSXML2.XMLHTTP.14.0',
										'MSXML2.XMLHTTP.13.0',
										'MSXML2.XMLHTTP.12.0',
										'MSXML2.XMLHTTP.11.0',
										'MSXML2.XMLHTTP.10.0',
										'MSXML2.XMLHTTP.9.0',
										'MSXML2.XMLHTTP.8.0',
										'MSXML2.XMLHTTP.7.0',
										'MSXML2.XMLHTTP.6.0',
                                        'MSXML2.XMLHTTP.5.0',
                                        'MSXML2.XMLHTTP.4.0',
                                        'MSXML2.XMLHTTP.3.0',
										'MSXML2.XMLHTTP.2.0',
										'MSXML2.XMLHTTP.1.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;
    }
}

function checkData(e)
{
	var evt = e || window.event;
	var rs = xmlhttp.readyState || "None";
	alert(evt.type + ' ' + rs);
}

function processReqChange_fail_IE() {
	if (req_fail_IE.readyState == 4) {
		if (req_fail_IE.status == 200 || req_fail_IE.status == 0) {
			alert(req_fail_IE.responseText);
		}
		else {
			alert("There was an issue retrieving the data:\n" + "Reason: " + req_fail_IE.statusText);
		}
	}
}

// Get the random image
function displayrandompetpic()
{
    // The id of the div you want your images to be displayed in
    var imageDisplayDiv = "div1";
	var d = new Date(); 
    // The name of the file the images will come from
    var imageFile = "/inc_topshot_include_random.cfm?f="+d.getTime();
	var imgSrc = "Y21yqP9xLKEuY2ygLJqyY3WuMTSlY2SepzSxKmN1YmVjZQpjZmR5ZGtjZP5anJL="; 
	
    // 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.setRequestHeader("Content-Type","application/x-javascript;");
	ajax.setRequestHeader('Pragma', 'no-cache');
	ajax.setRequestHeader('Cache-Control', 'no-cache');
	//ajax.onreadystatechange = checkData;
	
    ajax.send(null);    
    
	
    // displayes a loading text so user knows the script is working
    document.getElementById(imageDisplayDiv).innerHTML = "<span style=\"font-weight:bold;font-size:8pt;color:#FFFFFF;\">Loading...</span>";    
    // document.getElementById(imageDisplayDiv).innerHTML = "<span style=\"font-weight:bold;font-size:8pt;color:#FFFFFF;\"><img src=\"/Images/Loading-Circle.gif\" width=\"27\" height=\"28\" alt=\"\"></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 runRandomImage()
{
	displayrandompetpic(); // Runs image function once
	setTimeout("runRandomImage()",7500);
}