﻿
var cTarget

function transferHandler() {
    /*
    Function : transferHandler() --> null
    Returns  : Nothing
    Params   : None
            
    Author   : Charles Cage
    Euclidean, Inc.
                       
    Date     : 2008-11-10
        
    Purpose  : Installed as handler of XMLHttpRequest send. Called
    on readystate change. Seeks completed result and redirects
    to either final destination or error page upon completed
    call.
        
    */

    // Check for readyState 4 (complete) and status 200 (good HTTP)
    if (client.readyState == 4 && client.status == 200) {

        // We've received a response

        // Check to see if response is not null
        if (client.responseText != null) {

            // We have data.

            // Alert for troubleshooting responseText
            //alert(client.responseText);

            // If responseText is "False" redirect to error page
            if (client.responseText == "False") {
                if (cTarget == '1') { window.location = "error-fanweb.aspx" }
                else if (cTarget == '2') { window.location = "error-vision.aspx" }
                else if (cTarget == '3') { window.location = "error-ajbart.aspx" }
                else if (cTarget == '4') { window.location = "error-prnewswire.aspx" }
                else if (cTarget == '5') { window.location = "error-snl.aspx" }
                else window.location = "error.aspx";
            } else {

                if (cTarget == '1') { document.aspnetForm.submit(); }
                else if (cTarget == '2') { document.aspnetForm.submit(); }
                else if (cTarget == '3') { window.location = "ajbart.aspx" }
                else if (cTarget == '4') { window.location = "http://behringerharvard.mediaroom.com" }
                else if (cTarget == '5') { window.location = "http://www.snl.com/IRWebLinkX/GenPage.aspx?IID=4077658&gkp=202715" }
                else window.location = "error.aspx";

            }
        } else {
            // We either received an error or a null message
            if (client.readyState == 4 && client.status != 200) {
                // Error
                alert("Error");
                test(null);
            } else {
                // Null Message
                alert("Null return");
                test(null);
            }
        }
    }
}

function checkSite(gTarget) {

    // Set cTarget var
    cTarget = gTarget;

    // Make screen blue and show content block for site

    if (gTarget == '1') {

        //$find('MPE2').show();
    }

    else if (gTarget == '2') {


        //$find('MPE1').show();
    }
    else if (gTarget == '3') {

        //$find('MPE2').show();
    }
    else if (gTarget == '4') {

        //$find('MPE2').show();
    }
    else if (gTarget == '5') {
        //popup turned off
        //$find('MPE2').show();
    }


    //
    // Create XMLHttpRequest Object
    //

    // Check for old ActiveX (IE6)
    if (window.XMLHttpRequest) {
        // This is Mozilla/use modern object definition
        client = new XMLHttpRequest();
    } else {
        // Must be old IE/use ActiveX definition
        client = new ActiveXObject("Microsoft.XMLHTTP");
    }

    // If the above fails, the browser can't handle AJAX at all. Let them know.
    if (client == null) {
        alert("Browser doesn't support AJAX.");
    }

    // Sent XMLHttpRequest
    client.onreadystatechange = transferHandler;
    client.open("GET", "/checksite.aspx?target=" + gTarget);
    client.send(null);

}
