﻿var plugInNameRC = "WPI Application Detector";
var plugInNameRTW = "WPI Detector 1.1";

IsReleaseCandidateInstalled = function(rcDetector)
{
    var result = false;
    if ((typeof(rcDetector) != "undefined") && (rcDetector != null))
    {
        var detectedInIE = (typeof(rcDetector.IsWebPIInstalled) != "undefined") && rcDetector.IsWebPIInstalled();
        var detectedInMoz = (typeof(navigator.plugins) != "undefined") && (typeof(navigator.plugins[plugInNameRC]) != "undefined") && (navigator.plugins[plugInNameRC] != null);
        
        if (detectedInIE || detectedInMoz)
        {        
            result = true;
        }
    }
    return result;
}

TryWebAppInstallation = function(url, rcDetector, rtwDetector)
{    
    var result = false;
    if ((typeof(rcDetector) != "undefined") && (rcDetector != null) &&
        (typeof(rtwDetector) != "undefined") && (rtwDetector != null))
    {
        var detectedInIE = ((typeof(rcDetector.IsWebPIInstalled) != "undefined") && rcDetector.IsWebPIInstalled()) ||
                           ((typeof(rtwDetector.IsWebPIInstalled) != "undefined") && rtwDetector.IsWebPIInstalled());
        var detectedInMoz = (typeof(navigator.plugins) != "undefined") && 
                            (((typeof(navigator.plugins[plugInNameRC]) != "undefined") && (navigator.plugins[plugInNameRC] != null)) ||
                             ((typeof(navigator.plugins[plugInNameRTW]) != "undefined") && (navigator.plugins[plugInNameRTW] != null)));
        
        if (detectedInIE || detectedInMoz)
        {        
            window.location.href = url;
            result = true;
        }
    }
    return result;
}
