
var X;
function getX() {
    var http_request = false;

    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            //http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) {
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) { }
        }
    }
    return http_request;
}

function doOpen(sURL, bNewWindow, id) {
    if (X && X.readyState != 0) {
        X.abort()
    }
    X = getX();

    if (X) {
        // use if POST... X.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

        //calls another aspx file that will save the hits to the DB

        X.open("GET", "saveHits.aspx?action=saveHits&id=" + id, true);

        //after executing saveHits.aspx, it will display the return value of saveHits.aspx (calling a javascript function displayData)
        X.onreadystatechange = function() { displayData(sURL, bNewWindow); };
        X.send(null); // if POST... put the querystring instead of null
    }
}

function displayData(sURL, bNewWindow) {

    //checking if theres no error
    if (X.readyState == 4) {

        //checking if the return value is valid (without errors)
        if (X.status == 200) {
            if (bNewWindow == "True")
                window.open(sURL);
            else
                document.location.href = sURL;
            //include the code below if you want to display the hits in the main page
            //showText(X.responseText,"divContent");
        } else {
            //  showText('There was a problem with the request.',"divInfoBody");
        }
    }
}

//function to display the return value of saveHits.aspx
function showText(text, divId) {
    divObj = document.getElementById(divId);
    if (divObj) {
        divObj.innerHTML = "&nbsp;";
        divObj.innerHTML = text;
    }
}  