// create a function that displays one tab of a four tab set prefixed 'table'.
// eg: element names are table1, table2 etc.
var makeMenu = _ClosureShowSelectedElement(2,"table");
var makeItem = _ClosureShowSelectedElement(7,"item");
 
// Populate second select element on demand
var all_platforms = 0;
function populatePlatformsSelect(product, targetElement) {
    var platform_select = document.getElementById('platform_select');
	var platform_select_title = document.getElementById('platform_select_title');
    var find_it_button_product = document.getElementById('find_it_button_product');
    var find_it_button_platform = document.getElementById('find_it_button_platform');
    all_platforms = 0;
    var list = new Array(); 
    list[0] = new Array();
    list[0][0] = '';
    list[0][1] = 'Please choose:';
    // No product has been selected. Hide everything.
    if (product == '') {
        simpleSetOptionsList(targetElement, list);
        platform_select.style.visibility = 'hidden';
		platform_select_title.style.visibility = 'hidden';
        find_it_button_product.style.display = 'none';
        find_it_button_platform.style.display = 'none';
        targetElement.selectedIndex = 0;
        targetElement.disabled = true;
    } else {
        // A product has been selected. 
        var list_index = 1;
        var platforms = product_platform_relationships[product].platforms;
        for (var i=0;i<platforms.length;i++) {
            var filename = platforms[i].file;
            // There are no platforms to choose from. Show the find it button.
            if (filename == 'all') {
                all_platforms = 1;
                simpleSetOptionsList(targetElement, list);
                platform_select.style.visibility = 'hidden';
				platform_select_title.style.visibility = 'hidden';
                find_it_button_product.style.display = 'inline';
                find_it_button_platform.style.display = 'none';
                targetElement.selectedIndex = 0;
                targetElement.disabled = true;
                return 0;
            }
            // There are platforms to choose from so build the array then carry on
            var display = platforms[i].display;
            list[list_index] = new Array();
            list[list_index][0] = filename;
            list[list_index][1] = display;
            list_index++;				
        }
        simpleSetOptionsList(targetElement, list);
        platform_select.style.visibility = 'visible';
		platform_select_title.style.visibility = 'visible';
        // Show the second find it button
        find_it_button_product.style.display = 'none';
        find_it_button_platform.style.display = 'inline';
        targetElement.selectedIndex = 0;
        targetElement.disabled = false;
    }
}

function simpleSetOptionsList (targetObj,newlist) {
    if (targetObj.options) {
        var list = targetObj.options;
        list.selectedIndex = -1;
        list.length = newlist.length;
        for (var i = 0 ; i < list.length ; i++) {
            list[i].value = newlist[i][0];
            list[i].text  = newlist[i][1];
        }    
    }
}

var product_platform_relationships = { Sophos_Anti_Virus_Small_Business_Edition: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Sophos Anti-Virus Small Business Edition" }, MailMonitor: { platforms: [ { precedence: 100, file: "SMTP_on_Windows_NT", display: "SMTP on Windows NT" }, { precedence: 110, file: "SMTP_on_UNIX", display: "SMTP on UNIX" } ], display: "MailMonitor" }, utimaco_support_docs: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Sophos SafeGuard" }, SAV_Interface: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "SAV Interface" }, EM_Library: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "EM Library" }, PureMessage: { platforms: [ { precedence: 70, file: "Microsoft_Exchange", display: "Microsoft Exchange" },  { precedence: 140, file: "UNIX_PM", display: "UNIX" }, { precedence: 170, file: "Lotus_Domino", display: "Lotus Domino" }, { precedence: 190, file: "Windows_Exchange", display: "Windows/Exchange" } ], display: "PureMessage" }, Sophos_Anti_Virus: { platforms: [ { precedence: 10, file: "Windows_2000_XP_2003", display: "Windows 2000/XP/2003/Vista" }, { precedence: 20, file: "Windows_95_98", display: "Windows 95/98" }, { precedence: 30, file: "Windows_NT", display: "Windows NT" }, { precedence: 40, file: "Mac_OS_X", display: "Mac OS X" }, { precedence: 60, file: "Linux", display: "Linux" }, { precedence: 120, file: "NetWare", display: "NetWare" }, { precedence: 130, file: "NetApp_Storage_Systems", display: "NetApp Storage Systems" }, { precedence: 150, file: "UNIX", display: "AIX" }, { precedence: 160, file: "UNIX", display: "FreeBSD" }, { precedence: 170, file: "UNIX", display: "OpenBSD" }, { precedence: 180, file: "UNIX", display: "HP-UX" }, { precedence: 190, file: "UNIX", display: "SCO 8.0" }, { precedence: 200, file: "UNIX", display: "Solaris" }, { precedence: 220, file: "Open_VMS", display: "OpenVMS" }, { precedence: 230, file: "OS_2", display: "OS/2" } ], display: "Sophos Anti-Virus" }, Enterprise_Console: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Enterprise Console" }, Enterprise_Manager: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Enterprise Manager" }, Email_Security_Appliance: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Sophos Email Security Appliances" }, Web_Security_Appliance: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "WS1000 Web Security Appliance" }, Sophos_Client_Firewall: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Sophos Client Firewall" }, Sophos_for_SharePoint: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Sophos for Microsoft SharePoint" }, Anti_Rootkit: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Sophos Anti-Rootkit" }, Sophos_Security_Suite: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Sophos Security Suite" }, Sophos_Computer_Security: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Sophos Computer Security" }, Sophos_Mobile_Security: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Sophos Mobile Security" }, Sophos_NAC: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Sophos NAC" }, Endpoint_Security_Control: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Endpoint Security and Control" }, Email_Security_Control: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Email Security and Control" }, Web_Security_Control: { platforms: [ { precedence: 1, file: "all", display: "all" } ], display: "Web Security and Control" }  };

function visit_specific_documentation_page() {
    var frm = document.forms['filterDocs'];
    var product = frm.elements['product'];
    if (product.selectedIndex == 0) { return false; }
    var product_text = product[product.selectedIndex].value;
    var platform_text;
    if (all_platforms == 1) {
        platform_text = 'all';
    }  else {
        var platform = frm.elements['platforms'];
        if (platform.selectedIndex == 0) { return false; }
        platform_text = platform[platform.selectedIndex].value;
    }
    document.location = "/support/docs/" + product_text + "-" + platform_text + ".html";
}



  
function show_all_docs_section(listItem) {
    var list = document.getElementById('all_documents_list');
    var lists = list.getElementsByTagName('ul');
    for (i=0;i<lists.length;i++) {
        if (
            (lists[i].parentNode == listItem) &&
            (lists[i].style.display != 'block')
            ) {
            lists[i].style.display = 'block';
            lists[i].parentNode.style.listStyleImage = 'url(/images/interface/arrow_list_link_down.gif)';
        } else {
            lists[i].style.display = 'none';
            lists[i].parentNode.style.listStyleImage = '';
        }
    }
}



function show_all_documents_section(listItem, listName, linkedList) {
  if (listName) {
    var list_name = listName;
  }
  else {
    var list_name = 'all_documents_list';
  }

  open_close_list (list_name, listItem);

  if (linkedList) {
    open_close_list (linkedList, listItem);
  }
}

function open_close_list (listName, listItem) {
    var list = document.getElementById(listName);
    if ( list == undefined) {
      return;
    }
    var lists = list.getElementsByTagName('div');
	var imgs  = list.getElementsByTagName('img');
    for (i=0;i<lists.length;i++) {
        if (
            (lists[i].parentNode == listItem) &&
			(lists[i].style.display != 'block')	
            ) {
            lists[i].style.display = 'block';
			imgs[i].src = '/images/interface/box-link-open.gif';
        } else {
            lists[i].style.display = 'none';
			imgs[i].src = '/images/interface/box-link-closed.gif';
        }
    }
}

function show_first_section() {
	var first_section = document.getElementById('first_section');
	var first_section_image = document.getElementById('first_section_image');
	first_section.style.display = 'block';
	first_section_image.src  = '/images/interface/box-link-open.gif';
}

function reset_menu() {
    var product_menu = document.getElementById('product_menu');
    if (product_menu.value != "") { 
        populatePlatformsSelect(product_menu.value, product_menu.form.elements['platforms'] );
    }
}

/* Onload Handler */
/* First we check to see if there is an onload handler already,
   if there is, we preserve it.
*/
var doc_old_onload;                    /* Prepare a variable for it */
if (window.onload) {                   /* Test for onload */
    doc_old_onload = window.onload;    /* Assign current onload to
                                          variable */
}
/* Then we assign our own function to onload, overwriting any existing one
   but this is OK since we made a backup in the doc_old_onload variable
*/
window.onload = function () {
    if (doc_old_onload) {
        doc_old_onload();
    }
	
	
    /* Then we run the funcion to generate the platform menu
       based on the product menu
    */
	if (document.getElementById('product_menu')) {
    var sel = document.getElementById('product_menu'); /* Get the select
                                                          element */
    populatePlatformsSelect(sel.value, sel.form.elements['platforms']);
	
	}
}

/* This checks for a query string on the URL and changes the destination of the link to history.back if the query string 'refer' has the value 'docs'
*/


function documentationBackLink() {
        if (QueryString['refer'] == 'docs') {
                var link = document.getElementById('main-docs');
                link.onclick = function(){history.back(); return false; }
        }
}

var pre_doc_onload;
if (window.onload) {
        pre_doc_onload = window.onload;
}
window.onload = function() {
        documentationBackLink();
        if (pre_doc_onload) {
                pre_doc_onload();
        }
}
