function IsWinOS () {
    var agent = navigator.userAgent.toLowerCase();
    if (agent.indexOf('windows') != -1){
        return true;
    }
    return false;
}

function O4CFindViewer () {

    if (navigator.appName == 'Microsoft Internet Explorer') {
        try {
            var control = new ActiveXObject ('PIXELPLANSC.PIXELPLANWebViewer.1');
            return true;
        }
        catch (e) {
            return false;
        }
    }
    else {
        navigator.plugins.refresh ();

        var L = navigator.plugins.length;
        for(var i=0; i<L; i++) {
            if (navigator.plugins[i].name == 'Pixelplan Web Viewer') {
                return true;
            }
        }
    }

    return false;
}

var o4c_t;

function O4CEmbed (source, x_size, y_size) {
    var pd = document.getElementById ("O4CDiv");
    var installed = O4CFindViewer ();
    if (installed) {
        var html;
        html = "<object id=\"PixelPlanO4CViewer\" ";
        html += "codebase=\"http://www.pixelplan.pl/o4c/O4CViewer_web_1.2.2.exe\" ";
        html += "type=\"application/x-pixelplanwebviewer\" ";
        /*html += "classid=\"clsid:CEC15225-16F9-5834-BB79-90C75853244A\" ";*/
        html += "width=\"";
        html += x_size;
        html += "\" ";
        html += "height=\"";
        html += y_size;
        html += "\" >";
        html += "<param name=\"source\" value=\"";
        html += source;
        html += "\" /></object>"

        pd.innerHTML = html;
    }
    else {
      
        var whStyle;
        whStyle = "width:" + (x_size-20) + "px;";
        whStyle += "height:" + (y_size-20) + "px;";

        var html = "<div style=\"";
        html += whStyle
//        html += "background:white;border: solid 5px;border-color:#2f2f2f\">";
        html += "background:white;\">";
        html += "<table border='0' style=\""
        html += whStyle;
        html += "\"><tr><th><div style=\"margin: 0 auto\">";
        if (IsWinOS ()) {
          html += "<a href='http://pixelplan.pl/o4c/O4CViewer_web_1.2.2.exe'>";
          html += "<img style=\"border:0px;width:110px;height:196px\" src='http://www.pixelplan.pl/o4c/arrow_down.png' />";
          html += "<img style=\"border:0px\" src='http://www.pixelplan.pl/o4c/o4c_logo.png' />";
          html += "<img style=\"border:0px;width:110px;height:196px\" src='http://www.pixelplan.pl/o4c/arrow_down.png' />";
          html += "</a>";
          html += "<font style=\"font-family: Arial; font-size: 15pt;\"><br>Install O4C Viewer</font>";
        }
        else {
          html += "<img style=\"border:0px\" src='http://www.pixelplan.pl/o4c/o4c_logo.png' />";
          html += "<font style=\"font-family: Arial; font-size: 15pt;\"><br>Sorry, available only on Windows.</font>";
        }
        html += "</div></th></tr></table></div>"

        pd.innerHTML = html;

        // try again
        var again = "O4CEmbed ('";
        again += source;
        again += "', ";
        again += x_size;
        again += ", ";
        again += y_size;
        again += ")";
        //pd.innerHTML += again;
        o4c_t = setTimeout (again, 500);
    }
}

function O4CEmbedViewer (source, x_size, y_size) {
    O4CEmbed (source, x_size, y_size);
}

