function toggle(id) 
{
  var e = document.getElementById(id);
  if(e.style.display == 'block') 
   {
    e.style.display = 'none';
   }
  else
   {
    e.style.display = 'block';
   }
   this.className = 'colapse';
 }

function currentpagename(sPath,sLang)
{
	//var sPage = sPath.substring(sPath.lastIndexOf('\\') + 1);
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	var sPage = '/'+ sLang + '/Pages/' + sPage
	return(sPage);
}


function onSilverlightError(sender, args) {

    var appSource = "";
    if (sender != null && sender != 0) {
        appSource = sender.getHost().Source;
    } 
    var errorType = args.ErrorType;
    var iErrorCode = args.ErrorCode;
    
    var errMsg = "Unhandled Error in Silverlight 2 Application " +  appSource + "\n" ;

    errMsg += "Code: "+ iErrorCode + "    \n";
    errMsg += "Category: " + errorType + "       \n";
    errMsg += "Message: " + args.ErrorMessage + "     \n";

    if (errorType == "ParserError")
    {
        errMsg += "File: " + args.xamlFile + "     \n";
        errMsg += "Line: " + args.lineNumber + "     \n";
        errMsg += "Position: " + args.charPosition + "     \n";
    }
    else if (errorType == "RuntimeError")
    {           
        if (args.lineNumber != 0)
        {
            errMsg += "Line: " + args.lineNumber + "     \n";
            errMsg += "Position: " +  args.charPosition + "     \n";
        }
        errMsg += "MethodName: " + args.methodName + "     \n";
    }

    throw new Error(errMsg);
}

function bookmarksite(title, url) {
    if (window.sidebar) // firefox
        window.sidebar.addPanel(title, url, "");
    else if (window.opera && window.print) { // opera
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
    else if (document.all)// ie
        window.external.AddFavorite(url, title);
}


function getSilverlightVersion(errormsg) {
    var version = null;
    var container = null;
    var imgcontent = document.getElementById("imgContent");
    try {
        var control = null;
        var product = 'Silverlight';

        //check for moonlight!
        if (navigator.userAgent.indexOf("Linux") != -1) product = "Moonlight";

        if (window.navigator.userAgent.indexOf('MSIE') >= 0) {
            // For Internet Explorer, Create an ActiveX Object
            // And assign it to the 'control' variable.
            // If Silverlight is not installed, this should throw an error
            control = new ActiveXObject('AgControl.AgControl');
        }
        else {
            // For FireFox/Safari
            // Check to see if the plug-in is present

            if (navigator.plugins['Silverlight Plug-In']) {
                container = document.createElement('div');
                document.body.appendChild(container);
                container.innerHTML = '<embed type="application/x-silverlight" src="data:," />';
                control = container.childNodes[0];
                if (navigator.plugins['Silverlight Plug-In'].description) {
                    version = navigator.plugins['Silverlight Plug-In'].description;
                }
                // If the plug-in is present, then we should have gotten this far
                // without an error. If we threw an error, it is caught later on
            }
            else {
                // plug-in is not present, so we go red
                errormsg = "Plugin not found for Firefox/Safari.";
            }
        }

        if (control) {
            // plug-in is present and we were able to instantiate

            // check the microsoft method
            version = detectAgControlVersion(control);

            // brute force a version number- the control definitley is there.
            if (version == null || version == -1) {
                //iterate through major releases.
                for (var i = 10.0; i > 1.0 && version == null; i = i - 0.1) {
                    //alert(i.toFixed(1));
                    if (control.isVersionSupported(i.toFixed(1))) { version = i.toFixed(1); }
                }
                //if (control.isVersionSupported('2.0')) { version = product + '/2.0'; }             
                //else if (control.isVersionSupported('1.0')) { version = product + '/1.0'; }
            }
            errormsg = version;
        }
        else {
            // we weren't able to instantiate, so we say it isn't present
            errormsg = "Could not instantiate dummy SL control.";
        }
    }
    catch (e) {
        // we hit an error so we say it isn't present
        errormsg = "Unknown exception finding Silverlight Version: " + e.message;
    }


    if (container) {
        // Let's clean up
        document.body.removeChild(container);
    }

    if (version != null) {
        errormsg = 'Success';
        return product + '/' + version;
    }
    return 'Silverlight Not Installed';
}


// ************** Microsoft code here for known SL versions  
// lifted from http://www.microsoft.com/SILVERLIGHT//scripts/silverlight/General.js
var g_agVersion = null;

function detectAgControlVersion(detectionProbe) {
    var agVersion = "-1";
    var agCtrl = null;

    try {
        agCtrl = new ActiveXObject('AgControl.AgControl');
    }
    catch (e) {
        agCtrl = navigator.plugins["Silverlight Plug-In"];
        if ((typeof (agCtrl) != "undefined") && (agCtrl != null)) {
            agVersion = agCtrl.description;
            if (agVersion === "1.0.30226.2") {
                agVersion = "2.0.30226.2";
            }
            else if ((agVersion.split(".").length < 4) && (typeof (detectionProbe) != "undefined") && (detectionProbe != null)) {
                // On the Mac, Gecko-based browsers return only 3 of the 4 parts of the Silverlight version
                // number found in the plug-in's "description" property. If we have one of these partial
                // version strings then we can try to probe further to get a more precise value.

                agVersion = ProbeSilverlightVersion(detectionProbe);
            }
        }
    }

    if ((agCtrl != null) && (agVersion == "-1")) {
        agVersion = ProbeSilverlightVersion(agCtrl);
    }
    agCtrl = null;

    return agVersion;
}

function ProbeSilverlightVersion(agCtrl) {
    var agVersion = "-1";
    try {
        var knownVersions = new Array();

        knownVersions[0] = "0.90.20416.10";
        knownVersions[1] = "0.95.20416.10";

        knownVersions[2] = "1.0.20724.0";
        knownVersions[3] = "1.0.20730.0";
        knownVersions[4] = "1.0.20806.0";
        knownVersions[5] = "1.0.20813.0";
        knownVersions[6] = "1.0.20816.0";
        knownVersions[7] = "1.0.20926.0";
        knownVersions[8] = "1.0.21115.0";
        knownVersions[9] = "1.0.30109.0";
        knownVersions[10] = "1.0.30401.0";
        knownVersions[11] = "1.0.30715.0";
        knownVersions[12] = "1.0.30716.0";

        knownVersions[13] = "1.1.20724.0";
        knownVersions[14] = "1.1.20730.0";
        knownVersions[15] = "1.1.20806.0";
        knownVersions[16] = "1.1.20813.0";
        knownVersions[17] = "1.1.20816.0";
        knownVersions[18] = "1.1.20926.0";
        knownVersions[19] = "2.0.30226";
        knownVersions[20] = "2.0.30523.2";
        knownVersions[21] = "2.0.30523.6";
        knownVersions[22] = "2.0.30523.8";
        knownVersions[23] = "2.0.30523.9";

        var versionCount = knownVersions.length;
        for (var iVer = versionCount - 1; iVer >= 0; iVer--) {
            if (agCtrl.IsVersionSupported(knownVersions[iVer])) {
                agVersion = knownVersions[iVer];
                break;
            }
        }

        // If the installed version of Silverlight is at least as current as version 2.0 Beta 2 (2.0.30523)
        // then we need to further test to see if has an even more recent version number. At this point
        // we are going to switch the guessing game heuristic so we walk through all of the possible
        // version numbers in turn. We do this by knowning a few things (that may need to be tweaked/changed
        // as conditions change in the future)...
        //
        // - All current releases start 2.0.3. This logic will have to be enhanced in the future as Microsoft
        //   releases versions of Silverlight in the family 2.1 or 3.5 or x.y.
        // - Version numbers are formed, in part, by using the number of the month and day when the control was
        //   was compiled/linked (built). That limits the range of possible version numbers sufficiently so we
        //   can programmatically test each one without taking too much time.

        if (agVersion == knownVersions[knownVersions.length - 1]) {
            var scope = "2.0.3";
            for (var iMonth = 9; iMonth < 13; iMonth++) {
                for (var iDay = 1; iDay < 32; iDay++) {
                    for (var iSpecies = 0; iSpecies < 20; iSpecies++) {
                        var possibleVersion = scope + (iMonth < 10 ? "0" : "") + iMonth.toString() + (iDay < 10 ? "0" : "") + iDay.toString() + "." + iSpecies.toString();
                        if (agCtrl.IsVersionSupported(possibleVersion)) {
                            if (RestartRequired(agCtrl)) {
                                // We have apparently just upgraded from SL 1.0 to SL 2.0 RTW.
                                // We ought to close and reopen the browser in order to work reliably with Silverlight.
                                // Until then, there isn't a fully usable version of Silverlight available.
                                agVersion = -1;
                            }
                            else {
                                agVersion = possibleVersion;
                            }

                            break;
                        }
                    }
                }
            }
        }
    }
    catch (e) {
        // Special case for a very early version of 1.1
        if ((agCtrl != null) &&
            (typeof (agCtrl.Settings) != "undefined") && (agCtrl.Settings != null) &&
            (typeof (agCtrl.Settings.version) != "undefined") && (agCtrl.Settings.version != null) &&
            (agCtrl.Settings.version == "0.95.20416")) {
            agVersion = "1.1.20416.10";
        }
    }

    return agVersion;
}

function RestartRequired(agCtrl) {
    // Silverlight 1.0 did not have a terribly robust way to check for its own version
    // number. As a result, when you upgrade from 1.0 to 2.0 RTW (2.0.31005.0) there is
    // a time (before you close and reopen your browser) where you are instantiating
    // Silverlight 1.0 but the in-process control reports that it is actually 2.0.31005.
    // We can detect that by asking if the control supports 2.0.31005.99 which is
    // specially distinguished as supported by the real 2.0.31005.0 control, but not
    // by Silverlight 1.0 instances.
    var retVal = false;
    var version = "2.0.31005";
    try {
        if (agCtrl == null) {
            agCtrl = new ActiveXObject('AgControl.AgControl');
        }

        if (!agCtrl.IsVersionSupported(version + ".99") && agCtrl.IsVersionSupported(version + ".0")) {
            retVal = true;
        }
    }
    catch (e) {
    }
    return retVal;
}
