var VersionerId = "YVerInfo2";
var myVer = 0;
window.onload = function()
{
    if(isVersionerAvailable() )
    {
        insertVersioner();
        var versioner = document.getElementById(VersionerId);
        if(versioner)
        {
            var version = getVersion(versioner);
            if ( version != null ) {
                //alert('version != null');
                var majorVersion = version.split(',')[0];
                //alert('majorVersion = '+majorVersion);
                if(majorVersion == 4) {
                    // encourage exploration
                    //swapContent('wgtExploreBox','wgtExplore');
                    myVer = 1;
                } else {
                    // engine exists but isn't 4, encourage upgrade
                    //swapContent('wgtUpgradeBox','wgtUpgrade');
                    myVer = 0;
                }
            } else {
                // engine not found
            }
        }
    }
};


function isVersionerAvailable()
{
    //alert('VersionerAvailable');
    try
    {
        if(typeof(ActiveXObject) == "function")
        {
            var versioner = new ActiveXObject("YVerInfo.GetInfo2");
            return versioner && typeof(versioner.ComponentVersion) != "undefined";
        }
    }
    catch(e){}
    return false;
}

function insertVersioner()
{
    //alert('insertVersioner');
    var classid = "B345F37E-6763-433b-BC53-9B526A9B7B8B";
    var tag = '<object id="' + VersionerId + '" type="application/x-oleobject" classid="CLSID:' + classid + '" style="width:0;height:0;display:none;"></object>';
    document.body.insertAdjacentHTML("beforeEnd", tag);
}

function getVersion(versioner)
{

    //alert('getVersion');
    var v = null;
    try
    {
        if(v = versioner.ApplicationGetInfo(6, "HKLM\\SOFTWARE\\Yahoo\\WidgetEngine\\\\InstallPath"))
            return v;
        if(v = versioner.ApplicationGetInfo(6, "HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Yahoo! Widget Engine\\\\DisplayIcon"))
            return v;
        if(v = versioner.fv("C:\\Program Files\\Yahoo!\\Widgets\\YahooWidgetEngine.exe"))
            return v;
        if(v = versioner.fv("C:\\Program Files\\Yahoo!\\Yahoo! Widget Engine\\YahooWidgetEngine.exe"))
            return v;
        if(v = versioner.fv("C:\\Program Files\\Yahoo!\\WidgetEngine\\YahooWidgetEngine.exe"))  // default Y! Widget Engine ver 3.0.2 install location
            return v;
        if(v = versioner.fv("C:\\Program Files\\Yahoo!\\WIDGET~1\\WidgetEngine\\YahooWidgetEngine.exe"))        // default Konfabulator 2 upgrade to Y! Widget Engine ver 3.0.1 install location?? Very rare??
            return v;
        if(v = versioner.fv("C:\\Program Files\\Yahoo!\\Konfabulator\\Konfabulator.exe"))       // default Y! Widget Engine ver 3.0 install location
            return v;
        if(v = versioner.fv("C:\\Program Files\\Pixoria\\Konfabulator\\Konfabulator.exe"))      // default original Pixoria Konfabulator 2 install location
            return v;
    }
    catch(e){}
    return null;
};
