// Global identifier
function $(id)
{
    if (document.getElementById != null) {
        return document.getElementById(id);
    }

    if (document.all != null) {
        return document.all[id];
    }

    if (document.layers[id] != null) {
        return document.layers[id];
    }

    return null;
}

// XMLHTTP Request Initializer
function GetXmlHttpObject(handler)
{ 
    var objXmlHttp=null;

    if (navigator.userAgent.indexOf("Opera")>=0) {
        alert("This page doesn't work in Opera");
        return;
    }
    if (navigator.userAgent.indexOf("MSIE")>=0) { 
        var strName="Msxml2.XMLHTTP";
        if (navigator.appVersion.indexOf("MSIE 5.5")>=0) {
            strName="Microsoft.XMLHTTP";
        } 
        try { 
            objXmlHttp=new ActiveXObject(strName);
            objXmlHttp.onreadystatechange=handler; 
            return objXmlHttp;
        } 
        catch(e) { 
            alert("Error. Scripting for ActiveX might be disabled");
            return; 
        } 
    } 
    if (navigator.userAgent.indexOf("Mozilla")>=0) {
        objXmlHttp=new XMLHttpRequest();
        objXmlHttp.onload=handler;
        objXmlHttp.onerror=handler; 
        return objXmlHttp;
    }
}

// Excecute an Asynchronous request to a ColdFusion page to check the referrer
function checkReferrer()
{
    //$('loading').style.display='block';
    var url="/checkAuthUrl.cfm?r="+encodeURI(document.referrer); // URL of ColdFusion file
    //alert(document.referrer);
    var handler=function() {
        if (xmlHttp.readyState == 'complete' || xmlHttp.readyState == 4) {
            // Execute the following when the ColdFusion file is finished processing
            var resp = xmlHttp.responseText;
            //alert(resp);
            if (resp == "false") {
                window.location.href="/error.htm";
            }
            //$('loading').style.display='none';
        }
    }
    var xmlHttp = GetXmlHttpObject(handler);
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}

checkReferrer();
