function generateRandomString(stringLength) {
    var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
    var randomstring = '';
    for (var i = 0; i < stringLength; i++) {
        var rnum = Math.floor(Math.random() * chars.length);
        randomstring += chars.substring(rnum, rnum + 1);
    }
    return randomstring;
}

function CallWebClickTracker(bannerOSURL, application, placement, clickObjType, params) {
    var script_object = document.createElement('SCRIPT');
    // NOTE: the URL is connecting to a foreign site (and not a js file either)
    script_object.src = bannerOSURL + "webClickTracker.js?placement=" + application + "|" + placement + "&clickobjtype=" + clickObjType + params + "&request_id=" + generateRandomString(10);
    script_object.type = 'text/javascript';

    var head = document.getElementsByTagName('HEAD')[0];

    head.appendChild(script_object);    
}

function CallWebClickTrackerRedirect(redirectURL, bannerOSURL, application, placement, clickObjType, params) {
    CallWebClickTracker(bannerOSURL, application, placement, clickObjType, params);
    setTimeout("timeoutRedirect('" + redirectURL + "')", 1000);
    return false;
}

function timeoutRedirect(redirectURL) {
    window.location = redirectURL;
}

function CallWebClickTrackerPopupRedirect(redirectURL, bannerOSURL, application, placement, clickObjType, params) {
    CallWebClickTracker(bannerOSURL, application, placement, clickObjType, params);
    setTimeout("timeoutPopupRedirect('" + redirectURL + "')", 1000);
    return false;
}

function timeoutPopupRedirect(redirectURL) {
    window.open(redirectURL, "", "", "");
}
