// global variable for storing the current language
var language;

// global variable for storing the current language ID
var langID;

// global variable for storing NLS array
var arrayID;
                    
// variables to store language IDs
var eng = "eng";
var por = "por";
var ita = "ita";
var esp = "esp";
var fra = "fra";
var ger = "ger";
var chi = "chi";
var tch = "tch";
var jap = "jap";
var kor = "kor";


// this array contains the language names
var arrayLanguages = new Array("English", "Portugues", "Italiano", "Espanol", "Francais", "Deutsch", 
                               "Chinese", "Traditional Chinese", "Japanese", "Korean");

//the following arrays contain the names of the guides in the NLS names
var arrayGuideNameEng = new Array("SDK Guide", "Installation Guide", "Runtime Environment Guide", 
                         "Redistribution Guide", "Java Security Guide", "Readmefirst", "JavaComm API Guide*", "Information for Japanese Users", "RMI-IIOP Programmer's Guide");

var arrayGuideNamePor = new Array("SDK Guide", "Installation Guide", "Runtime Environment Guide", 
                         "Redistribution Guide", "Java Security Guide", "Readmefirst", "JavaComm API Guide*", "Information for Japanese Users", "RMI-IIOP Programmer's Guide");

var arrayGuideNameIta = new Array("SDK Guide", "Installation Guide", "Runtime Environment Guide", 
                         "Redistribution Guide", "Java Security Guide", "Readmefirst", "JavaComm API Guide*", "Information for Japanese Users", "RMI-IIOP Programmer's Guide");

var arrayGuideNameEsp = new Array("SDK Guide", "Installation Guide", "Runtime Environment Guide", 
                         "Redistribution Guide", "Java Security Guide", "Readmefirst", "JavaComm API Guide*", "Information for Japanese Users", "RMI-IIOP Programmer's Guide");

var arrayGuideNameFra = new Array("SDK Guide", "Installation Guide", "Runtime Environment Guide", 
                         "Redistribution Guide", "Java Security Guide", "Readmefirst", "JavaComm API Guide*", "Information for Japanese Users", "RMI-IIOP Programmer's Guide");

var arrayGuideNameGer = new Array("SDK Guide", "Installation Guide", "Runtime Environment Guide", 
                         "Redistribution Guide", "Java Security Guide", "Readmefirst", "JavaComm API Guide*", "Information for Japanese Users", "RMI-IIOP Programmer's Guide");

var arrayGuideNameChi = new Array("SDK Guide", "Installation Guide", "Runtime Environment Guide", 
                         "Redistribution Guide", "Java Security Guide", "Readmefirst", "JavaComm API Guide*", "Information for Japanese Users", "RMI-IIOP Programmer's Guide");

var arrayGuideNameTch = new Array("SDK Guide", "Installation Guide", "Runtime Environment Guide", 
                         "Redistribution Guide", "Java Security Guide", "Readmefirst", "JavaComm API Guide*" , "Information for Japanese Users", "RMI-IIOP Programmer's Guide");

var arrayGuideNameJap = new Array("SDK Guide", "Installation Guide", "Runtime Environment Guide", 
                         "Redistribution Guide", "Java Security Guide", "Readmefirst", "JavaComm API Guide*" , "Information for Japanese Users", "RMI-IIOP Programmer's Guide");

var arrayGuideNameKor = new Array("SDK Guide", "Installation Guide", "Runtime Environment Guide", 
                         "Redistribution Guide", "Java Security Guide", "Readmefirst", "JavaComm API Guide*", "Information for Japanese Users", "RMI-IIOP Programmer's Guide");

//the following function chooses the language in which to display the guides, based on the choice the user made in the
//startHere.htm page - the language is selected depending on the URL of the container page (index.en.html?language)
function chooseLanguage() {
    
    loc = parent.location.href; // get URL of the container page, index.en.html
    
    var langPath;
    //the following if..else block check which language the guides should be displayed in, and sets the variables
    // language, langId, and arrayID to the appropriate values
    if(loc.indexOf(eng) != -1) {
        language = arrayLanguages[0];
        langId = eng;
        arrayID = arrayGuideNameEng;
        langPath="en";
    }
    else if(loc.indexOf(por) != -1){
        language = arrayLanguages[1];
        langId = por;
        arrayID = arrayGuideNamePor;
        langPath="br";
    }
    else if(loc.indexOf(ita) != -1){
        language = arrayLanguages[2];
        langId = ita;
        arrayID = arrayGuideNameIta;
        langPath="it";
    }
    else if(loc.indexOf(esp) != -1){
        language = arrayLanguages[2];
        langId = esp;
        arrayID = arrayGuideNameEsp;
        langPath="es";
    }
    else if(loc.indexOf(fra) != -1){
        language = arrayLanguages[3];
        langId = fra;
        arrayID = arrayGuideNameFra;
        langPath="fr";
    }
    else if(loc.indexOf(ger) != -1){
        language = arrayLanguages[4];
        langId = ger;
        arrayID = arrayGuideNameGer;
        langPath="de";
    }
    else if(loc.indexOf(chi) != -1) {
        language = arrayLanguages[5];
        langId = chi;
        arrayID = arrayGuideNameChi;
        langPath="cn";
    }
    else if(loc.indexOf(tch) != -1) {
        language = arrayLanguages[6];
        langId = tch;
        arrayID = arrayGuideNameTch;
        langPath="tw";
    }
    else if(loc.indexOf(jap) != -1) {
        language = arrayLanguages[7];
        langId = jap;
        arrayID = arrayGuideNameJap;
        langPath="jp";
    }
    else if(loc.indexOf(kor) != -1){
        language = arrayLanguages[8];
        langId =  kor;
        arrayID = arrayGuideNameKor;
        langPath="ko";
    }
//alert("The chosen language is: " + language + "\nLanguage ID: " + langId + "\narrayId: " + arrayID);
    
    return langPath;
}
    
function createAssocArray(guidesArray) {
    chooseLanguage();
    var twoDimArray = new Array;
    for(i=0; i<guidesArray.length; i++) {
        
        if(guidesArray[i].indexOf("sdkguide") != -1) {
            twoDimArray[i] = new Array(2);
            twoDimArray[i][0] = guidesArray[i];
            twoDimArray[i][1] = arrayID[0];
        }                  
        else if (guidesArray[i].indexOf("installguide") != -1){
            twoDimArray[i] = new Array(2);
            twoDimArray[i][0] = guidesArray[i];
            twoDimArray[i][1] = arrayID[1];
        }
        else if (guidesArray[i].indexOf("runtimeguide") != -1){
            twoDimArray[i] = new Array(2);
            twoDimArray[i][0] = guidesArray[i];
            twoDimArray[i][1] = arrayID[2];
        }
        else if (guidesArray[i].indexOf("distguide") != -1){
            twoDimArray[i] = new Array(2);
            twoDimArray[i][0] = guidesArray[i];
            twoDimArray[i][1] = arrayID[3];
        }
        else if (guidesArray[i].indexOf("securityguide") != -1){
            twoDimArray[i] = new Array(2);
            twoDimArray[i][0] = guidesArray[i];
            twoDimArray[i][1] = arrayID[4];
        }
        else if (guidesArray[i].indexOf("readmefirst") != -1){
            twoDimArray[i] = new Array(2);
            twoDimArray[i][0] = guidesArray[i];
            twoDimArray[i][1] = arrayID[5];
        }
        else if (guidesArray[i].indexOf("javacomm") != -1){
            twoDimArray[i] = new Array(2);
            twoDimArray[i][0] = guidesArray[i];
            twoDimArray[i][1] = arrayID[6];
        }
        else if (guidesArray[i].indexOf("japanese") != -1){
            if ( (langId.indexOf("jap") != -1) || (langId.indexOf("eng") != -1) ) {
                twoDimArray[i] = new Array(2);
                twoDimArray[i][0] = guidesArray[i];
                twoDimArray[i][1] = arrayID[7];
            }
            else {
                twoDimArray[i] = null;
                //twoDimArray[i][0] = "";
                //twoDimArray[i][1] = "";

            }
        }   
        else if (guidesArray[i].indexOf("rmi") != -1){
            twoDimArray[i] = new Array(2);
            twoDimArray[i][0] = guidesArray[i];
            twoDimArray[i][1] = arrayID[8];
        }

    }
    //alert("The chosen language is: " + language + "\nLanguage ID: " + langId + "\narrayId: " + arrayID);
    return twoDimArray;
}

//the following function writes the TOC in the toc.htm file
//first it calls the function createAssocArray() on an array that has a list of the
//file paths to the various user guides. this results in a 2-dimensional array that has the
//path of the user guide and the name to display in the browser. 
//after writing the opening <UL> tag, this function iterates through the 2-dimensional array to
//create the links to the various user guides
function writeToc(arrayGuidePaths) {
    var twoDim = createAssocArray(arrayGuidePaths); // create 2-dimensional array from array containing user guide paths
    document.write("<UL>"); // write opening <UL> tag
    
    //iterate through 2-dim array and write links in toc.htm file  
    for (i=0; i<twoDim.length; i++){
        if(twoDim[i] == null)
            continue;
        document.write("<LI><A href='" + twoDim[i][0] + "' target='Content' title='" + twoDim[i][1] + "' onClick='parent.Content.focus()'>" + twoDim[i][1] + "</A></LI>");
    }
    
    document.write("</UL>"); // write closing </UL> tag

    

}
        

// the following function automatically loads the index page with the table of contents
// use it with the onLoad attribute of the opening <BODY> tag when there are no translations
// (e.g. "<BODY onLoad="loadIndex()">

function loadIndex() {
    location.href = "navigation/index.en.htm?eng"
    //alert(location.href);
}
