
var bInsObj   = false;
var isLinux   = (navigator.userAgent.indexOf("Linux") >= 0);
var isMacFF   = (navigator.userAgent.indexOf("Firefox") >= 0 && navigator.userAgent.indexOf("Mac") >= 0);
var isSafari  = (navigator.userAgent.indexOf("Safari") >= 0);
var isSolaris = (navigator.userAgent.indexOf("Sun") >= 0);
var isWinFF   = (navigator.userAgent.indexOf("Firefox") >= 0 && navigator.userAgent.indexOf("Windows") >= 0);
var isIE7     = (navigator.userAgent.indexOf("MSIE 7") >= 0);
var isIE8     = (navigator.userAgent.indexOf("MSIE 8") >= 0);			

function doLoad() {
var bDocReady = false;        
    return;
}

var dlmObject;
var dlmTarget;

function closeIt() {
    return;
}

    
function nuaHas(txt) {
    if (navigator.userAgent.indexOf(txt) >= 0) {
        return true;
    } else {
        return false;
    }
}

function javaPluginString() {
    if (nuaHas("MSIE")) {
        return "MSIE";
    }

    var npdesc = "None";

    for (var i=0; i < navigator.plugins.length; i++) {
        var npname = navigator.plugins[i].name;
        if (npname.indexOf("Java") >= 0) {
            npdesc = navigator.plugins[i].description;
            if (javaVersionOKHelper(javaPluginVersionHelper(npdesc))) {
                return npdesc;
            }
        }
    }

    return npdesc;
}

function javaPluginName() {
    var npstring = javaPluginString();
    npstring = npstring.replace(/<[^>]*>/, "");

    if (npstring.length > 75) {
        npstring = npstring.substring(0, 72) + "...";
    }

    return npstring;
}

function javaPluginVersionHelper(npstring) {
    if ((npstring == "MSIE") || (npstring == "None")) {
        return "None";
    }

    if (npstring.indexOf("1.3") >= 0) {
        return "1.3";
    } else if (npstring.indexOf("1.4") >= 0) {
        return "1.4";
    } else if (npstring.indexOf("1.5") >= 0) {
        return "1.5";
    } else if (npstring.indexOf("1.6") >= 0) {
        return "1.6";
    } else {
        try {
            var propVersion = java.lang.System.getProperty("java.version");

            if (propVersion.indexOf("1.4") >= 0) {
                return "1.4";
            } else if (propVersion.indexOf("1.5") >= 0) {
                return "1.5";
            } else if (propVersion.indexOf("1.6") >= 0) {
                return "1.6";
            }
        } catch (e) {
        }
    }

    if ((npstring.indexOf("Java Switchable") >= 0) && (npstring.indexOf("Cocoa") >= 0)) {
        return "1.4";
    }

    return "None";
}

function javaPluginVersion() {
    var npstring = javaPluginString();

    return javaPluginVersionHelper(npstring);
}

function javaVersionOKHelper(npversion) {
    if (npversion == "None") {
        return false;
    }

    if ((npversion == "1.4") || (npversion == "1.5") || (npversion == "1.6")) {
        return true;
    }

    return false;
}

function javaVersionOK() {
    if ((nuaHas("MSIE") && nuaHas("Win")) && (!nuaHas("Windows 3.1"))) {
        return true;
    }

    var npversion = javaPluginVersion();
    return javaVersionOKHelper(npversion);
}

function startDLM_Java() {

    if (!javaVersionOK()) {
      show_dlm(arguments[0], arguments[1]);
        //document.location.replace("http://demo.dlm.tools.akamai.com/akdlm/testfiles/test50m.bin?startType=manual&window=list&fileExt=.bin");
      return;
    }

    insertObj_Java(arguments[0], arguments[1]);
    checkClose(arguments[0]);
}

function checkClose() {
    // This method doesn't work on Mac
    if (isSafari || isMacFF) {
        return;
    }

    if ((dlmObject == null) || (dlmTarget == null)) {
        setTimeout("checkClose();", 500);
        return;
    }

    if (dlmObject.shouldClose()) {
        dlmTarget.close();
    
        if (dlmObject.missingPrivileges()) {
            document.getElementById("ifr_download").src = arguments[0];
            //document.location.replace("http://demo.dlm.tools.akamai.com/akdlm/testfiles/test50m.bin?startType=manual&window=list&fileExt=.bin");
        }
        
    } else {
        setTimeout("checkClose();", 100);
    }
}



// Check if the document is fully loaded
function docReady() {
    if (document.readyState == "complete") {
        bDocReady = true;
    } else {
        bDocReady = false;
    }
}

// Insert the code to create the DM object
function insertObj_Java() {
    // Only insert the object once

    if (true) {
        bInsObj = true;
        var userLang = (navigator.language) ? navigator.language : navigator.userLanguage;

        //Get the URL
        var s = location.href;
        var i = s.indexOf("download_item_");
        s = s.substring(0,i);

        // Create object tag
        var winWidth = 380;
        var winHeight = 300;
        var popOffset = 32; // The size (px) of the pop-up blocker infobar

        var sObjHTML = "<applet " +
            "   code=\"com.akamai.dm.ui.applet.DMApplet.class\" " +
//            "   codebase=\"../common/\" " +
            "   codebase=\"http://dlm.tools.akamai.com/dlmanager/versions/java/\" " +
            "   archive=\"dlm-java-2.2.5.7.jar\" " +
            "   name=\"Download Manager\" " +
            "   id=\"dm\" " +
            "   width=\"100%\" " +
            "   height=\"100%\" " +
            "   style=\"position: absolute; top: 0px; left: 0px;\" " +
            "   mayscript >" +
            "    <PARAM name=\"jscomm\" value=\"true\"/> " +
            "    <PARAM name=\"codebaseURL\" value=\"http://dlm.tools.akamai.com/dlmanager/versions/java/dlm-java-2.2.5.7.jar\"/> " +
            "    <PARAM name=\"userAgent\" value=\""+navigator.userAgent+"\"/> " +
            "    <PARAM name=\"cookies\" value=\"" + document.cookie + "\"/> " +
            "    <PARAM name=\"version\" value=\"2.2.5\"/> " +
            "    <PARAM name=\"URL\" value=\""+arguments[0]+"\"/> " +
            "    <PARAM name=\"recoveryURL\" value=\""+ s +"download_item_dlm.aspx?file="+arguments[0]+ "&type=java" + "&SLanguage=" + arguments[1]+ "\"/> " +
            "    <PARAM name=\"language\" value=\""+userLang+"\"/> " +
            "    <PARAM name=\"providerName\" value=\"ASUSTek Computer Inc. \"/> " +
            "    <PARAM name=\"maxCon\" value=\"6\"/> " +
            "    <PARAM name=\"maxConn\" value=\"6\"/> " +
            "    <PARAM name=\"requestSize\" value=\"1024\"/> " +
            "    <PARAM name=\"flushSize\" value=\"32\"/> " +
            "    <PARAM name=\"initialView\" value=\"single\"/> " +
            "    <PARAM name=\"referer\" value=\"http://support.asus.com/\"/> " +
            "    <PARAM name=\"icon\" value=\"true\"/> " +
            "    <PARAM name=\"logoURL\" value=\"http://support.asus.com/images/LOGO-asus-dlm2.gif\"/> " +
            "    <PARAM name=\"launch\" value=\"no\"/> " +
            "    <PARAM name=\"sWhenDone\" value=\"no\"/> " +
            "    <PARAM name=\"useStateReporting\" value=\"true\"/> " +
            "    <PARAM name=\"stateReportingVersion\" value=\"1\"/> " +
            "</applet> ";

        objdiv = document.getElementById("objectDIV");
        if (objdiv == null) {
            document.getElementById("ifr_download").src = arguments[0];
            return;
        }

        // The default size values need to be adjusted on various platforms
        if (isMacFF || isLinux || isSolaris) {
            winHeight += 3;
        }
        if (isSafari) {
            winWidth -= 2;
            winHeight -= 2;
        }

        var dlmWin = null;

        if (!isSafari) {
            var winId = (new Date()).getTime();
            dlmWin = window.open("", winId, "width=" + winWidth + ", height=" + winHeight + ", resizable=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no");
        }

        if (dlmWin != null) {
            lava_loading = "";
            if(document.getElementById("hld_JavaLoading").value)
              lava_loading = document.getElementById("hld_JavaLoading").value;
            else
              lava_loading = "Loading Java Applet. Please wait.";
              
            
            dlmWin.document.write("<html><head><title>ASUSTek Computer Inc. -Akamai Download Manager-</title></head><body>"+lava_loading+"<br>" + sObjHTML + "</body></html>");

            // This quiets the loading bar on Firefox, but breaks Safari
            if (!isSafari) {
                dlmWin.document.close();
            }

            dlmObject = dlmWin.document.getElementById("dm");
            dlmTarget = dlmWin;

            // In Safari, we need to manually force a window repaint
            if (isSafari) {
                dlmObject.innerHTML += " ";
            }
        } else {
            // A pop-up blocker was used, so we have to open the
            //   DLM into the start-up page, accounting for the
            //   space taken up by the pop-up blocker information
            //   bar which will often appear in this case.

            document.body.innerHTML = sObjHTML;
            self.innerWidth = winWidth;
            self.innerHeight = winHeight + popOffset;

            dlmObject = document.getElementById("dm");
            dlmTarget = window;

            if (isSafari) {
                window.resizeTo(winWidth, winHeight + 100);
            }
        }

        try {
            dlmTarget.focus();
        } catch (e) {
        }


    }
}


