//*****************************************************************
// This is the data that will populate a selection field based on which item is selected
// from a drop down list

var path = "../Media/pdf/";
var ar_path = "../Profile/pdf/";
var cps_path = "../Profile/pdf/";

arrayAvailableReports = new Array("Rapports annuels","Rapport financier","Résumé du plan d\u2019entreprise", "Valeur des terres agricoles", "Journal AgriSuccès", "À la fine pointe");
var VER1=0;
//////////////////////////////////////////
arrayAnnualReports = new Array("Rapports annuels          ",
                               "2010-2011",
                               "2009-2010",
                               "2008-2009",
                               "2007-2008",
                   	       "2006-2007",
                               "2005-2006",
                               "2004-2005",
                               "2003-2004",
                               "2002-2003",
                               "2001-2002",
                               "2000-2001",
                               "1999-2000",
                               "1998-1999");

arrayPDFAnnualReports = new Array(
            ar_path + "AR2010-11_LO_f.pdf",
            ar_path + "AR2009-10_LO_f.pdf",
	    ar_path + "AR_F_2008_09_full_locked.pdf",
            ar_path + "ar_2007_08_full_f.pdf",                        
            ar_path + "ar_2006_07_full_f.pdf",
                        ar_path + "ar_2005_06_full_f.pdf",
                        ar_path + "ar_2004_05_full_f.pdf",
                        ar_path + "ar_2003_04_full_f.pdf",
                           path + "ar_2003_complete_f.pdf",
                           path + "FCC_Fr.pdf",
                           path + "ar_2001_f.pdf",
                           path + "scaRA2000.pdf",
                           path + "franrpt.pdf");

//////////////////////////////////////////

arrayCorpSummary = new Array("Résumé du plan d\u2019entreprise",
                             "2009/10 - 2013/14",
                             "2008/09 - 2012/13",
                             "2007/08 - 2011/12",
                             "2006/07 - 2010/11",
                             "2005/06 - 2009/10",
                             "2004/05 - 2008/09",
                             "2003/04 - 2007/08",
                             "2002/03 - 2006/07",
                             "2001/02 - 2005/06");

arrayPDFCorpSummary = new Array(
                     cps_path + "cps_2009_10_f.pdf",
                     cps_path + "cps_2008_09_f.pdf",
                     cps_path + "cps_2007_08_f.pdf",
                     cps_path + "cps_2006_07_f.pdf",
                     cps_path + "cps_2005_06_f.pdf",
                     cps_path + "cps_2004_05_f.pdf",
                     cps_path + "cps_2003_04_f.pdf",
                     cps_path + "cps_2002_03_f.pdf",
                     cps_path + "cps_2001_02_f.pdf");

//////////////////////////////////////////
arrayFarmLandValues = new Array("Valeur des terres agricoles       ",
				"Automne 2011",
				"Printemps 2011",
				"Automne 2010",
                                "Printemps 2010",
                                "Automne 2009",
                                "Printemps 2009",
                                "Automne 2008",
                                "Printemps 2008",
                                "Automne 2007",
                                "Printemps 2007",
                                "Automne 2006",
                                "Printemps 2006",
                                "Automne 2005",
                                "Printemps 2005",
                                "Automne 2004",
                                "Printemps 2004",
                                "Automne 2003",
                                "Printemps 2003",
                                "Automne 2002",
                                "Printemps 2002",
                                "Automne 2001",
                                "Printemps 2001",
                                "Automne 2000",
                                "Printemps 2000",
                                "Automne 1999",
                                "Printemps 1999",
                                "Automne 1998",
                                "Printemps 1998",
                                "Automne 1997",
                                "Printemps 1997",
                                "Automne 1996",
                                "Printemps 1996",
                                "Automne 1995",
                                "Printemps 1995",
                                "Automne 1994",
                                "Printemps 1994",
                                "Automne 1993",
                                "Printemps 1993",
                                "Automne 1992",
                                "Printemps 1992",
                                "Automne 1991",
                                "Printemps 1991",
                                "Automne 1990",
                                "Printemps 1990",
                                "Automne 1989",
                                "Automne 1988",
                                "Automne 1987",
                                "Automne 1986",
                                "Automne 1985",
                                "Automne 1984");
arrayPDFFarmLandValues = new Array(
				   "/fr/Products/Property/FLV/Fall2011/index.asp",
				   "/fr/Products/Property/FLV/Spring2011/index.asp",
				   "/fr/Products/Property/FLV/Fall2010/index.asp",
				   "/fr/Products/Property/FLV/Spring2010/index.asp",
                                   "/fr/Products/Property/FLV/Fall2009/index.asp",
                                   "/fr/Products/Property/FLV/Spring2009/index.asp",
                                   "/fr/Products/Property/FLV/Fall2008/index.asp",
                                   "/fr/Products/Property/FLV/Spring2008/index.asp",
                                   "/fr/Products/Property/FLV/Fall2007/index.asp",
                                   "/fr/Products/Property/FLV/Spring2007/index.asp",
                                   "/fr/Products/Property/FLV/Fall2006/index.asp",
                                   "/fr/Products/Property/FLV/Spring2006/index.asp",
                                   "/fr/Products/Property/FLV/Fall2005/index.asp",
                                   "/fr/Products/Property/FLV/Spring2005/index.asp",
                                   "/fr/Products/Property/FLV/Fall2004/index.asp",
                                   path + "flv_spring_2004_f.pdf",
                                   path + "FLVFall03_f.pdf",
                                   path + "FFLSpring03FR.pdf",
                                   path + "autome_02_F.pdf",
                                   path + "2002_spring_farmlandvalues_f.pdf",
                                   path + "Automne_2001.pdf",
                                   path + "Spring_01_F.pdf",
                                   path + "fvoctobre52000.pdf",
                                   path + "farmfr.pdf",
                                   path + "fallfr99.pdf",
                                   path + "Printemps_F_1999.pdf",
                                   path + "Automne_F_1998.pdf",
                                   path + "Printemps_F_1998.pdf",
                                   path + "Automne_F_1997.pdf",
                                   path + "Printemps_F_1997.pdf",
                                   path + "Automne_F_1996.pdf",
                                   path + "Printemps_F_1996.pdf",
                                   path + "Automne_F_1995.pdf",
                                   path + "Printemps_F_1995.pdf",
                                   path + "Automne_F_1994.pdf",
                                   path + "Printemps_F_1994.pdf",
                                   path + "Automne_F_1993.pdf",
                                   path + "Printemps_F_1993.pdf",
                                   path + "Automne_F_1992.pdf",
                                   path + "Printemps_F_1992.pdf",
                                   path + "Automne_F_1991.pdf",
                                   path + "Printemps_F_1991.pdf",
                                   path + "Automne_F_1990.pdf",
                                   path + "Printemps_F_1990.pdf",
                                   path + "Automne_F_1989.pdf",
                                   path + "Automne_F_1988.pdf",
                                   path + "Automne_F_1987.pdf",
                                   path + "Automne_F_1986.doc",
                                   path + "Automne_F_1985.pdf",
                                   path + "Automne_F_1984.pdf",
                                   path + "Automne_F_1983.pdf",
                                   path + "Automne_F_1982.pdf");

//////////////////////////////////////////
arrayJournal = new Array("Journal AgriSuccès");
arrayPDFJournal = new Array();

///////////////////////////////////////////
                                   
arrayQuarterlyFinancialReport = new Array("",
					"Premier trimestre de 2011-2012",
					"Deuxième trimestre de 2011-2012");
arrayQuarterlyPDFFinancialReport = new Array(path + "2011-12_quarterlyFinancialReport_f.pdf",
					     path + "Q2_2011_F.pdf"
					 );

//////////////////////////////////////////
arrayKnowledge = new Array("À la fine pointe",
			   "Été 2011",
                           "Hiver 2011",
			   "Été 2010",
                           "Hiver 2010",
                           "Été 2009",
                           "Hiver 2009",
                           "Hiver 2008",
                           "Été 2008"
                          );
arrayPDFKnowledge = new Array(
                              "/fr/LearningCentre/Knowledge/doc/KI_grow_idea_full_f.pdf",   
                              "/fr/LearningCentre/Knowledge/doc/Knowledge_Globalization2_f.PDF",
                              "/fr/LearningCentre/Knowledge/doc/KI_summer_2010_f.pdf",   
                              "/fr/LearningCentre/Knowledge/doc/KI_green_value_f.pdf",
                              "/fr/LearningCentre/Knowledge/doc/KI-Consumer_Trends_f.pdf",
                              "/fr/LearningCentre/Knowledge/doc/Knowledge_Insider_Energy_fr.PDF",
                              "/fr/LearningCentre/Knowledge/doc/Knowledge_Globalization_f.pdf",
                              "/fr/LearningCentre/Knowledge/doc/Knowledge_Connect_f.pdf"
                             );


//////////////////////////////////////////
arrayFillDummyValues = new Array("");


//*****************************************************************
// Generate Journal array from Journal XML file

var req = false;

// For Firefox, Netscape and other non-IE browsers
if(window.XMLHttpRequest)
{
    try
    {
        req = new XMLHttpRequest();
    }
    catch(e)
    {
        req = false;
    }
}
// For IE..
else if(window.ActiveXObject)
{
    try
    {
        req = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e)
    {
        try
        {
            req = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch(e)
        {
            req = false;
        }
    }
}

if(req)
{
    req.onreadystatechange = processReqChange;
    req.open("GET", "/includes/XML/AgriSuccessJournal/journals.xml", true);
    req.send("");
}
else
{
    /* no XMLHttpRequest -- Journal entries will not be added */
}

function processReqChange() {
    // if file is loaded..
    if (req.readyState == 4)
    {
        // and status code is OK..
        if (req.status == 200)
        {
            var issues = req.responseXML.getElementsByTagName("Issues").item(0).getElementsByTagName("Issue");

            for (var i = 0; i < issues.length; i++)
            {
                var title = issues.item(i).getElementsByTagName("Title");
                var url;

                for (var j = 0; j < title.length; j++)
                {
                    if (title.item(j).getAttribute("lang") == "fr")
                    {
                        var year, month, date;

                        date = issues.item(i).getElementsByTagName("Date").item(0);
                        year = date.getElementsByTagName("Year").item(0).firstChild.nodeValue;
                        month = date.getElementsByTagName("Month").item(0).firstChild.nodeValue;

                        /* warning: title is changing types here (node -> string) */
                        title = title.item(j).firstChild.nodeValue;
                        url = "/fr/LearningCentre/journal/pdf/" + year + "-" + month + ".pdf";

                        break;
                    }
                }

                arrayJournal.push(title);
                arrayPDFJournal.push(url);

            }
        }
        else {
            /* there was an error--do nothing */
        }
    }
}

//*****************************************************************
// This function sets variables to values required by a specific browser Document Object Model
//
function determineBrowser(){
    var brow = (navigator.appName);

    if(brow=="Netscape")
        {VER1 = document.forms["main"].elements[0];
         VER2 = document.forms["main"].elements[1];}
    else if(brow=="Microsoft Internet Explorer")
        {VER1 = document.all.selObj1;
         VER2 = document.all.selObj2;}

}


//*****************************************************************
// This function fills an option box with report names drawn from an array as defined via the case statement
// This function is triggered by either an onChange() or onClick event via the "selectedReportCategory" form element

function upDateME(){

    var selectedReportCategory = VER1.selectedIndex;

    switch(selectedReportCategory)
    {
        case 0:listReports = arrayAnnualReports ; arrayPDFs = arrayPDFAnnualReports;break;
        case 1:listReports = arrayQuarterlyFinancialReport ; arrayPDFs = arrayQuarterlyPDFFinancialReport; break;
        case 2:listReports = arrayCorpSummary ; arrayPDFs = arrayPDFCorpSummary;break;
        case 3:listReports = arrayFarmLandValues ; arrayPDFs = arrayPDFFarmLandValues;break;
        case 4:listReports = arrayJournal ; arrayPDFs = arrayPDFJournal;break;
        case 5:listReports = arrayKnowledge ; arrayPDFs = arrayPDFKnowledge; break;
        case -1:listReports = arrayFillDummyValues ;break;

    }


    VER2.options.length = listReports.length;
    for(i=0;i<listReports.length;i++)
    {

    VER2.options[i].text = listReports[i] ;
    }

    VER2.selectedIndex = 0;
}
//*****************************************************************
// This function will open a .pdf file according to the index of the array
// This function is triggered by either an onChange() or onClick event via the "selectedReport" form element

function getPDF()
{
    var selectedReport = VER2.selectedIndex;
    if(selectedReport!=0){
        if(VER1.selectedIndex == 0 && (selectedReport-1) == 0) {
            document.location = (""+arrayPDFs[selectedReport-1]);
        }
        else {
            w1 = window.open("","myWin");
            w1.location = (""+arrayPDFs[selectedReport-1]);
            setTimeout("w1.focus()", 1000);
        }

    }

}



//-->
