function dlNow(file, redUrl) {
    // skip if external url or old browser
    if (document.readyState) {
        // first try to download file in same window
        location.href = file;
        // mozilla readyState is always undefined
        // safari readyState is always complete
        // ie readyState is loading -> interactive -> complete
        if (document.readyState && document.readyState == 'loading') {
            // possible to detect when download dialog starts
            // check readyState every 250ms and
            // redirect to post download page with initiate download disabled
            // this is what IE executes
            setTimeout('dlComplete(\'' + redUrl + '\')', 250);
            return false;
        }
        return false;
    }
    // not possible to detect when download dialog starts
    // go to download page and let it initiate the download
    location.href = redUrl + '?dl';
    return false;
}

function dlComplete(redUrl) {
    if (document.readyState == 'loading') {
        // still loading, check again in 250ms
        setTimeout('dlComplete(\'' + redUrl + '\')', 250);
    } else {
        // readyState = interactive or complete means download dialog started
        // redirect to post download page with initiate download disabled
        location.href = redUrl;
    }
}
