var strLocalRootPath = null;


//Load Menu and Ribbon Data
// TODO: Fix for HTML (web-based, and local help file)
//         - change AdDynHelp to provide string of XML content
//              instead of trying to load the XML file
//         - Can continue to use MSXML as ActiveXObject already requires IE
function loadMenuData() 
{
    try 
    {
        //Find atleast one type of dynamic help tag.
        var dynHelps = document.all("divDynamicHelpMenu");
        if(dynHelps == null)
            dynHelps = document.all("divDynamicHelpDashboard");
        if(dynHelps == null)
            dynHelps = document.all("divDynamicHelpDashboardThenMenu");
        //For Backwards compatibility   
        if(dynHelps == null)
            dynHelps = document.all("divDynamicHelp");    
        //If no type of supported DynamicHelp tag exists - Nothing to do !
        if(dynHelps == null)
            return;
        
        //Workaround for loading ActiveX without warning dialog.
        var ocxObject = new ActiveXObject("ADDYNHELP.AdDynHelpCtrl.1");
        if (ocxObject == null)
            return;
        
        var strObj = "<object height=\"0\" width=\"0\" id=\"AdDynHelp\" CLASSID=\"clsid:C4B6CE2E-5743-4450-B798-5BE5CEC3BE9D\"></object>";
        
        //If single entry
        if (dynHelps.innerHTML != null)
            dynHelps.innerHTML = strObj + dynHelps.innerHTML;
        else  // Multiple DynHelp elements in the same page
            dynHelps(0).innerHTML = strObj + dynHelps(0).innerHTML;
        
        //invoke the mothod of ActiveX control
        var xmlFile = (document.getElementById("AdDynHelp")).GetDynHelpFile(getcurpath());
        if (xmlFile == null)
            return;
            
        strLocalRootPath = getcurpath();
        var indexofLastSlash = xmlFile.lastIndexOf("\\");
        if(indexofLastSlash != -1)
            strLocalRootPath = xmlFile.substr(0,indexofLastSlash);
        
        
        //define XMLDOMdocument object to analyse the xml file
        var objxml = new ActiveXObject("MSXML2.DOMDocument.3.0");
        objxml.async=false;
        objxml.load(xmlFile);
        objxml.setProperty("SelectionLanguage","XPath");
        
        // Update tags for all types of dynamic help entries on this page
        if (objxml.parseError.errorCode == 0)
        {
            DoDynamicHelpForMenu(objxml);
            DoDynamicHelpForDashboard(objxml);
            DoDynamicHelpForDashboardThenMenu(objxml);        
        }
    }
    catch(exception)
    {
        // check for "Automation server can't create object"
        if (exception.number & 0x7FFFFFFF == 0x000A01AD)
        {
                  
        }
    }
}

// Call AddOnLoadFunction from adsk.common.js
// TODO: Only for IE ?
AddOnLoadFunction(loadMenuData);

// Gets the Full external path to this CHM File
// TODO: Fix for HTML file path
function getcurpath () 
{
    var path = unescape(location.pathname);
    if( path.indexOf("@MSITStore:") == 0 ) 
    {
        path = path.substring(11,path.length);
    }
    if( path.indexOf("/") == 0 ) 
    {
        path = path.substring(1,path.length);
    }
    var i = path.lastIndexOf("::\\");
    if (i>0)
        path = path.substring(0,i);
    i = path.lastIndexOf("\\")
    path = path.substring(0,i+1);
    return path;
}

function DoDynamicHelpForMenu (objxml)
{
    var dynHelps = document.all("divDynamicHelpMenu");
    //For backwards compatibility
    if(dynHelps == null)
        dynHelps = document.all("divDynamicHelp");
    if(dynHelps == null)
        return;
    if(dynHelps.innerHTML != null)
        DoDynamicHelpForMenuItem(dynHelps,objxml);
    else
    {
        for (j=0; j<dynHelps.length; j++)
        {
            DoDynamicHelpForMenuItem(dynHelps(j),objxml);
        }
    }
}

function DoDynamicHelpForDashboard(objxml)
{
    var dynHelps = document.all("divDynamicHelpDashboard");
    if(dynHelps == null)
        return;
    if(dynHelps.innerHTML != null)
        DoDynamicHelpForDashboardItem(dynHelps,objxml, true);
    else
    {
        for (j=0; j<dynHelps.length; j++)
        {
            DoDynamicHelpForDashboardItem(dynHelps(j),objxml, true);
        }
    }
}

function DoDynamicHelpForDashboardThenMenu(objxml)
{
    var dynHelps = document.all("divDynamicHelpDashboardThenMenu");
    if(dynHelps != null);
    if(dynHelps.innerHTML != null)
    {
        if (DoDynamicHelpForDashboardItem(dynHelps,objxml, false)== false)
            DoDynamicHelpForMenuItem(dynHelps,objxml);
        
    }
    else
    {
        for (j=0; j<dynHelps.length; j++)
        {
            if (DoDynamicHelpForDashboardItem(dynHelps(j),objxml, false)== false)
                DoDynamicHelpForMenuItem(dynHelps(j),objxml);
        }
    }
}
            
function DoDynamicHelpForMenuItem(dynHelp, objxml)
{
    //According to menu's ID in HTML to determine which menu to load in HTML from xml file
    var value = objxml.selectSingleNode("//MenuItem[@ID='" + dynHelp.title.toUpperCase() + "']");
    var defaultContent=dynHelp.parentElement.all("DefaultContent");
    if(value!=null)
    {
        
        var re=/:/g;
        var result=(value.text).replace(re,"&nbsp;<span class=\"glyphArrow\"><img src=\"images\\ac.menuaro.gif\"></span>");
     
        var reDialogEllipses=/\.\.\./g;
        //Within the Default Content Node - there are two types of data
        //  1. uis-unspecified tagged text that needs to be replaced
        //  2. plain text
        if(defaultContent.childNodes != null)
        {
            var children = defaultContent.childNodes;
            for(i=0;i<children.length; i++)
            {
                var thisNode = defaultContent.childNodes[i];
                if(thisNode.className=="uis-unspecified") 
                {
                    defaultContent.removeChild(thisNode);
                }
            }
            var dynText = value.text;
            var indexOfFirstColon = dynText.indexOf(":");
            if(indexOfFirstColon != -1)
            {
                var splitDynText1 = dynText.substr(0,indexOfFirstColon);
                var splitDynText2 = dynText.substr(indexOfFirstColon,dynText.length-1);
                result = splitDynText1 + defaultContent.innerText + splitDynText2;
                result = result.replace(re,"&nbsp;<span class=\"glyphArrow\"><img src=\"images\\ac.menuaro.gif\"></span>");
                result = result.replace(reDialogEllipses,"");

            }
        }
        defaultContent.innerHTML = result;
        return true;
    }
    else 
    {
        var altContent = dynHelp.parentElement.all("AltContent");
        if( altContent != null &&
            altContent.innerHTML !=null &&
            altContent.innerHTML != "" && 
            altContent.innerHTML != " ")
        {
            var relatedContentElements = dynHelp.parentElement.all("RelatedContent");
            relatedContentElements[0].className="RelatedContentHidden";
            relatedContentElements[1].className="RelatedContentHidden";
            altContent.className="RelatedContent";
            defaultContent.className="RelatedContentHidden";
            return false;
        }
    }
    return false;
}


function DoDynamicHelpForDashboardItem(dynHelp, objxml, useAltContent)
{
    //According to menu's ID in HTML to determine which menu to load in HTML from xml file
    var value = objxml.selectSingleNode("//RibbonItem[@ID='" + dynHelp.title.toUpperCase() + "']");
    var defaultContent=dynHelp.parentElement.all("DefaultContent");
    if(value!=null)
    {
        var result;
        var re=/:/g;
        result=(value.text).replace(re,"&nbsp;<span class=\"glyphArrow\"><img src=\"images\\ac.menuaro.gif\"></span>");
        
        var reDialogEllipses=/\.\.\./g;
        //Within the Default Content Node - there are two types of data
        //  1. uis-unspecified tagged text that needs to be replaced
        //  2. plain text
        if(defaultContent.childNodes != null)
        {
            var children = defaultContent.childNodes;
            for(i=0;i<children.length; i++)
            {
                var thisNode = defaultContent.childNodes[i];
                if(thisNode.className=="uis-unspecified") 
                {
                    defaultContent.removeChild(thisNode);
                }
            }
            var dynText = value.text;
            var indexOfFirstColon = dynText.indexOf(":");
            if(indexOfFirstColon != -1)
            {
                var splitDynText1 = dynText.substr(0,indexOfFirstColon);
                var splitDynText2 = dynText.substr(indexOfFirstColon,dynText.length-1);
                result = splitDynText1 + defaultContent.innerText + splitDynText2;
                result = result.replace(re,"&nbsp;<span class=\"glyphArrow\"><img src=\"images\\ac.menuaro.gif\"></span>");
                result = result.replace(reDialogEllipses,"");
                result = result.replace(/expander/g,"<img src=\"images\\ac.ribbonexpander.gif\">");
            }
        }
        defaultContent.innerHTML = result;
        return true;
    }
    else if(useAltContent)
    {
        var altContent = dynHelp.parentElement.all("AltContent");
        if( altContent != null &&
            altContent.innerHTML !=null &&
            altContent.innerHTML != "" && 
            altContent.innerHTML != " ")
        {
            var relatedContentElements = dynHelp.parentElement.all("RelatedContent");
            relatedContentElements[0].className="RelatedContentHidden";
            relatedContentElements[1].className="RelatedContentHidden";
            altContent.className="RelatedContent";
            defaultContent.className="RelatedContentHidden";
            return false;
        }
    }
    return false;
}

// SIG // Begin signature block
// SIG // MIIMzQYJKoZIhvcNAQcCoIIMvjCCDLoCAQExDjAMBggq
// SIG // hkiG9w0CBQUAMGYGCisGAQQBgjcCAQSgWDBWMDIGCisG
// SIG // AQQBgjcCAR4wJAIBAQQQEODJBs441BGiowAQS9NQkAIB
// SIG // AAIBAAIBAAIBAAIBADAgMAwGCCqGSIb3DQIFBQAEEIs+
// SIG // LY8hjh7txm0iWTLLi2ygggoPMIIE/DCCBGWgAwIBAgIQ
// SIG // ZVIm4bIuGOFZDymFrCLnXDANBgkqhkiG9w0BAQUFADBf
// SIG // MQswCQYDVQQGEwJVUzEXMBUGA1UEChMOVmVyaVNpZ24s
// SIG // IEluYy4xNzA1BgNVBAsTLkNsYXNzIDMgUHVibGljIFBy
// SIG // aW1hcnkgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcN
// SIG // MDkwNTIxMDAwMDAwWhcNMTkwNTIwMjM1OTU5WjCBtjEL
// SIG // MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJ
// SIG // bmMuMR8wHQYDVQQLExZWZXJpU2lnbiBUcnVzdCBOZXR3
// SIG // b3JrMTswOQYDVQQLEzJUZXJtcyBvZiB1c2UgYXQgaHR0
// SIG // cHM6Ly93d3cudmVyaXNpZ24uY29tL3JwYSAoYykwOTEw
// SIG // MC4GA1UEAxMnVmVyaVNpZ24gQ2xhc3MgMyBDb2RlIFNp
// SIG // Z25pbmcgMjAwOS0yIENBMIIBIjANBgkqhkiG9w0BAQEF
// SIG // AAOCAQ8AMIIBCgKCAQEAvmcdtGCqEElvVhd8Zslehg3V
// SIG // 8ayncYOOi4n4iASJFQa6LYQhleTRnFBM+9IivdrysjU7
// SIG // Ho/DCfv8Ey5av4l8PTslHvbzWHuc9AG1xgq4gM6+J3Rh
// SIG // ZydNauXsgWFYeaPgFxASFSew4U00fytHIES53mYkZorN
// SIG // T7ofxTjIVJDhcvYZZnVquUlozzh5DaowqNssYEie16oU
// SIG // AamD1ziRMDkTlgM6fEBUtq3gLxuD3KgRUj4Cs9cr/SG2
// SIG // p1yjDwupphBQDjQuTafOyV4l1Iy88258KbwBXfwxh1rV
// SIG // jIVnWIgZoL818OoroyHnkPaD5ajtYHhee2CD/VcLXUEN
// SIG // Y1Rg1kMh7wIDAQABo4IB2zCCAdcwEgYDVR0TAQH/BAgw
// SIG // BgEB/wIBADBwBgNVHSAEaTBnMGUGC2CGSAGG+EUBBxcD
// SIG // MFYwKAYIKwYBBQUHAgEWHGh0dHBzOi8vd3d3LnZlcmlz
// SIG // aWduLmNvbS9jcHMwKgYIKwYBBQUHAgIwHhocaHR0cHM6
// SIG // Ly93d3cudmVyaXNpZ24uY29tL3JwYTAOBgNVHQ8BAf8E
// SIG // BAMCAQYwbQYIKwYBBQUHAQwEYTBfoV2gWzBZMFcwVRYJ
// SIG // aW1hZ2UvZ2lmMCEwHzAHBgUrDgMCGgQUj+XTGoasjY5r
// SIG // w8+AatRIGCx7GS4wJRYjaHR0cDovL2xvZ28udmVyaXNp
// SIG // Z24uY29tL3ZzbG9nby5naWYwHQYDVR0lBBYwFAYIKwYB
// SIG // BQUHAwIGCCsGAQUFBwMDMDQGCCsGAQUFBwEBBCgwJjAk
// SIG // BggrBgEFBQcwAYYYaHR0cDovL29jc3AudmVyaXNpZ24u
// SIG // Y29tMDEGA1UdHwQqMCgwJqAkoCKGIGh0dHA6Ly9jcmwu
// SIG // dmVyaXNpZ24uY29tL3BjYTMuY3JsMCkGA1UdEQQiMCCk
// SIG // HjAcMRowGAYDVQQDExFDbGFzczNDQTIwNDgtMS01NTAd
// SIG // BgNVHQ4EFgQUl9BrqCZwyKE/lB8ILcQ1m6ShHvIwDQYJ
// SIG // KoZIhvcNAQEFBQADgYEAiwPA3ZTYQaJhabAVqHjHMMaQ
// SIG // PH5C9yS25INzFwR/BBCcoeL6gS/rwMpE53LgULZVECCD
// SIG // bpaS5JpRarQ3MdylLeuMAMcdT+dNMrqF+E6++mdVZfBq
// SIG // vnrKZDgaEBB4RXYx84Z6Aw9gwrNdnfaLZnaCG1nhg+W9
// SIG // SaU4VuXeQXcOWA8wggULMIID86ADAgECAhAjTaBL0kKF
// SIG // PErLmuhhwhm7MA0GCSqGSIb3DQEBBQUAMIG2MQswCQYD
// SIG // VQQGEwJVUzEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4x
// SIG // HzAdBgNVBAsTFlZlcmlTaWduIFRydXN0IE5ldHdvcmsx
// SIG // OzA5BgNVBAsTMlRlcm1zIG9mIHVzZSBhdCBodHRwczov
// SIG // L3d3dy52ZXJpc2lnbi5jb20vcnBhIChjKTA5MTAwLgYD
// SIG // VQQDEydWZXJpU2lnbiBDbGFzcyAzIENvZGUgU2lnbmlu
// SIG // ZyAyMDA5LTIgQ0EwHhcNMDkwODI3MDAwMDAwWhcNMTIw
// SIG // OTIwMjM1OTU5WjCByDELMAkGA1UEBhMCVVMxEzARBgNV
// SIG // BAgTCkNhbGlmb3JuaWExEzARBgNVBAcTClNhbiBSYWZh
// SIG // ZWwxFjAUBgNVBAoUDUF1dG9kZXNrLCBJbmMxPjA8BgNV
// SIG // BAsTNURpZ2l0YWwgSUQgQ2xhc3MgMyAtIE1pY3Jvc29m
// SIG // dCBTb2Z0d2FyZSBWYWxpZGF0aW9uIHYyMR8wHQYDVQQL
// SIG // FBZEZXNpZ24gU29sdXRpb25zIEdyb3VwMRYwFAYDVQQD
// SIG // FA1BdXRvZGVzaywgSW5jMIGfMA0GCSqGSIb3DQEBAQUA
// SIG // A4GNADCBiQKBgQC1R1YKdvQF2Rj4+knWfj81afUtVyep
// SIG // GF2P4tcYD53qlYmYi9t9Csc6PMWlUZhMGbOceQKYcBjc
// SIG // mWvyghJnoaEQ6796ZcsLD0pMH2R4SpV/SjxiQ280beig
// SIG // NerJS5X+ftOMCs1qSQ1LXlRFEohaewkNWsIp/+f1Y0vE
// SIG // dGzggnEKOQIDAQABo4IBgzCCAX8wCQYDVR0TBAIwADAO
// SIG // BgNVHQ8BAf8EBAMCB4AwRAYDVR0fBD0wOzA5oDegNYYz
// SIG // aHR0cDovL2NzYzMtMjAwOS0yLWNybC52ZXJpc2lnbi5j
// SIG // b20vQ1NDMy0yMDA5LTIuY3JsMEQGA1UdIAQ9MDswOQYL
// SIG // YIZIAYb4RQEHFwMwKjAoBggrBgEFBQcCARYcaHR0cHM6
// SIG // Ly93d3cudmVyaXNpZ24uY29tL3JwYTATBgNVHSUEDDAK
// SIG // BggrBgEFBQcDAzB1BggrBgEFBQcBAQRpMGcwJAYIKwYB
// SIG // BQUHMAGGGGh0dHA6Ly9vY3NwLnZlcmlzaWduLmNvbTA/
// SIG // BggrBgEFBQcwAoYzaHR0cDovL2NzYzMtMjAwOS0yLWFp
// SIG // YS52ZXJpc2lnbi5jb20vQ1NDMy0yMDA5LTIuY2VyMB8G
// SIG // A1UdIwQYMBaAFJfQa6gmcMihP5QfCC3ENZukoR7yMBEG
// SIG // CWCGSAGG+EIBAQQEAwIEEDAWBgorBgEEAYI3AgEbBAgw
// SIG // BgEBAAEB/zANBgkqhkiG9w0BAQUFAAOCAQEAIfxkh8Fd
// SIG // IHK+qtTf+9Eq5fjkk5gMMTQCOa+2aR7mqDzLfIFRGQzr
// SIG // tcc5/izsb/wPLUwdw1cRpnxO8/qLA2Ol+b99FONTOyyc
// SIG // Y8unwviYhdEjuFmqHkyC5MUYroZEjvTObFkkgN98Y48h
// SIG // C+mG2hdlVKXR0zr9r5q/rmmivVWbojvcYKHoW31O5OcM
// SIG // PsrWuOD305Ygmpck/91iopE3UN4tfeWYhzNj1F6Ai4Xa
// SIG // 5KiaMcs3zmoZ+6SePyI2YUgtff6yvy/rk8KVT41KGD2h
// SIG // fC+QrtVSkoDWP/MDtLjbTPCWElC1NWSEKowRI8t2x594
// SIG // Skjnzu/W5Lh97ixircOuM4IvBzGCAigwggIkAgEBMIHL
// SIG // MIG2MQswCQYDVQQGEwJVUzEXMBUGA1UEChMOVmVyaVNp
// SIG // Z24sIEluYy4xHzAdBgNVBAsTFlZlcmlTaWduIFRydXN0
// SIG // IE5ldHdvcmsxOzA5BgNVBAsTMlRlcm1zIG9mIHVzZSBh
// SIG // dCBodHRwczovL3d3dy52ZXJpc2lnbi5jb20vcnBhIChj
// SIG // KTA5MTAwLgYDVQQDEydWZXJpU2lnbiBDbGFzcyAzIENv
// SIG // ZGUgU2lnbmluZyAyMDA5LTIgQ0ECECNNoEvSQoU8Ssua
// SIG // 6GHCGbswDAYIKoZIhvcNAgUFAKCBsDAZBgkqhkiG9w0B
// SIG // CQMxDAYKKwYBBAGCNwIBBDAcBgorBgEEAYI3AgELMQ4w
// SIG // DAYKKwYBBAGCNwIBFTAfBgkqhkiG9w0BCQQxEgQQJCo7
// SIG // xo/a5L47ZnVmcHS+MTBUBgorBgEEAYI3AgEMMUYwRKAm
// SIG // gCQAQQB1AHQAbwBkAGUAcwBrACAAQwBvAG0AcABvAG4A
// SIG // ZQBuAHShGoAYaHR0cDovL3d3dy5hdXRvZGVzay5jb20g
// SIG // MA0GCSqGSIb3DQEBAQUABIGAtMbf/2KB7Cpgv5IOxn8T
// SIG // m48PF6PwuZrygjZXk04CEwTe4MuBB5jAA+lwksXvavht
// SIG // wu/xe/xRM7Y0gVjc4e9rgp5d67jc56C+c+zKwfTjODEC
// SIG // +xB3aof4fOoxYoy+Bm/YwVR+hAYhRE/PDw/V25s1ibeA
// SIG // p0GTuJfBGQKSZriHxvc=
// SIG // End signature block
