﻿var BaseXLUrl = ''; // used by the help system
var MinFlashVer = '9,0,115,0';
var XhReq;

function doHelp(topicname, target) {
    // Comment 9841 - ignoring uppercase HTTPS.  should never happen due to our redirect
    var url = BaseXLUrl + "/info/Help.aspx?topic=imath_" + escape(topicname);
    if (url.indexOf("https") > -1)
        url = url.replace("https", "http");
    if (target) url += "&target=" + escape(target);
    popupWindow("help", url, { Width: 600, Height: 600, AutoClose: false });
}

function doPrint() {
    window.print();
}

function changeCover(drp) {
    var bookImage;
    
    var selval = drp.options[drp.selectedIndex].value;
    var seltext = drp.options[drp.selectedIndex].text;
    if (drp.selectedIndex < 1) {
        bookImage = "images/covers/logo_pearsonbook.gif";
        seltext = selval;
    }
    else {
        var sarr = new String(selval).split(",");
        var bookId = sarr[0];
        
        bookImage = sarr[1];
        if (bookId == -1)
            bookImage = "images/covers/logo_pearsonbook.gif";
        else
            bookImage = "books/images/" + bookImage;
    }
    var bookCover = document.getElementById('bookcover');
    bookCover.src = bookImage;
    bookCover.alt = seltext;
}

function hasFlash() {
    if (PluginDetect) {
        var v = PluginDetect.isMinVersion('Flash', MinFlashVer);
        if (v == 1) {
            return true;
        }
    }
    return false;
}

function isIE6Up() {
    if (PluginDetect && PluginDetect.isIE && PluginDetect.IEver >= 6)
        return true;
    return false;
}

function doBrowserCheck(url, bookId) {
    popupWindow("wizard", url + "&bookId=" + bookId, { Width: 780, AutoClose: false });
}

function doSystemRequirements(url, bookId) {
    popupWindow("sysreq", url + "&bookId=" + bookId, { Width: 550, AutoClose: false });
}

function doInstallWizard(url, bookId) {
    if (bookId > -1)
        popupWindow("wizard", url + escape("&bookId=" + bookId), { Width: 790, Height: 540, AutoClose: false });
    else
        popupWindow("wizard", url + escape("&forceWiz=1"), { Width: 790, Height: 540, AutoClose: false }); // all wizard
}

function insertPlayer(param) {
    document.write(param);
}


function KeepSession(timeout) // in minutes
{
    //document.getElementById('ImageSessionKeeper').src = "Service/KeepSession.ashx?r=" + Math.random();
    if (typeof(XhReq) == 'undefined')
        XhReq = createXMLHttpRequest();

    XhReq.open("GET", "Service/KeepSession.ashx?r=" + Math.random(), true);
    XhReq.send(null);

    InitKeepSession(timeout);
}

function InitKeepSession(timeout) // in minutes
{
    setTimeout('KeepSession(' + timeout + ');', timeout * 60 * 1000);
}

function createXMLHttpRequest() {
   try { return new XMLHttpRequest(); } catch(e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   //alert("XMLHttpRequest not supported");
   return null;
}
