//*****************************************************************
// 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("Annual Reports","Corporate Plan Summary", "Farmland Values", "AgriSuccess Journal", "Knowledge Insider");
var VER1=0;
//////////////////////////////////////////
arrayAnnualReports = new Array("Annual Reports           ",
                               "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 + "AR2009-10_LO_e.pdf",
            ar_path + "AR_E_2008_09_full_locked.pdf",
            ar_path + "ar_2007_08_full_e.pdf",                        
            ar_path + "ar_2006_07_full_e.pdf",
                        ar_path + "ar_2005_06_full_e.pdf",
                        ar_path + "ar_2004_05_full_e.pdf",
                        ar_path + "ar_2003_04_full_e.pdf",
                           path + "ar_2003_complete_e.pdf",
                           path + "FCC_Eng.pdf",
                           path + "ar_2001_e.pdf",
                           path + "fccAR2000.pdf",
                           path + "enganrpt.pdf");

//////////////////////////////////////////
arrayCorpSummary = new Array("Corporate Plan Summary",
                             "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_e.pdf",
                     cps_path + "cps_2008_09_e.pdf",
                     cps_path + "cps_2007_08_e.pdf",
                     cps_path + "cps_2006_07_e.pdf",
                     cps_path + "cps_2005_06_e.pdf",
                     cps_path + "cps_2004_05_e.pdf",
                     cps_path + "cps_2003_04_e.pdf",
                     cps_path + "cps_2002_03_e.pdf",
                     cps_path + "cps_2001_02_e.pdf");

//////////////////////////////////////////
arrayFarmLandValues = new Array("Farmland Values       ",
				"Spring 2010",
                                "Fall 2009",
                		"Spring 2009",
                                "Fall 2008",
                                "Spring 2008",
                                "Fall 2007",
                                "Spring 2007",
                                "Fall 2006",
                                "Spring 2006",
                                "Fall 2005",
                                "Spring 2005",
                                "Fall 2004",
                                "Spring 2004",
                                "Fall 2003",
                                "Spring 2003",
                                "Fall 2002",
                                "Spring 2002",
                                "Fall 2001",
                                "Spring 2001",
                                "Fall 2000",
                                "Spring 2000",
                                "Fall 1999");
arrayPDFFarmLandValues = new Array(
                                   "/en/Products/Property/FLV/Spring2010/index.asp",
                                   "/en/Products/Property/FLV/Fall2009/index.asp",
                                   "/en/Products/Property/FLV/Spring2009/index.asp",
                                   "/en/Products/Property/FLV/Fall2008/index.asp",
                                   "/en/Products/Property/FLV/Spring2008/index.asp",
                                   "/en/Products/Property/FLV/Fall2007/index.asp",
                                   "/en/Products/Property/FLV/Spring2007/index.asp",
                                   "/en/Products/Property/FLV/Fall2006/index.asp",
                                   "/en/Products/Property/FLV/Spring2006/index.asp",
                                   "/en/Products/Property/FLV/Fall2005/index.asp",
                                   "/en/Products/Property/FLV/Spring2005/index.asp",
                                   "/en/Products/Property/FLV/Fall2004/index.asp",
                                   path + "flv_spring_2004_e.pdf",
                                   path + "FVLFall03_e.pdf",
                                   path + "FLVSpring03.pdf",
                                   path + "Fall02e.pdf",
                                   path + "2002_spring_farmlandvalues.pdf",
                                   path + "Fall_2001.pdf",
                                   path + "Spring_01_E.pdf",
                                   path + "fvoctober52000.pdf",
                                   path + "farmeng.pdf",
                                   path + "FallEng99.pdf");

//////////////////////////////////////////
arrayJournal = new Array("AgriSuccess Journal");
arrayPDFJournal = new Array();


//////////////////////////////////////////
arrayKnowledge = new Array("Knowledge Insider",
                           "Winter 2010",
                           "Summer 2009",
                           "Winter 2009",
                           "Winter 2008",
                           "Summer 2008"
                          );
arrayPDFKnowledge = new Array(
                              "/en/LearningCentre/Knowledge/doc/KI_green_value_e.pdf",
                              "/en/LearningCentre/Knowledge/doc/KI-Consumer_Trends_e.pdf",
                              "/en/LearningCentre/Knowledge/doc/Knowledge_Insider_Energy_en.PDF",
                              "/en/LearningCentre/Knowledge/doc/Knowledge_Globalization_e.pdf",
                              "/en/LearningCentre/Knowledge/doc/Knowledge_Connect_e.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") == "en")
                    {
                        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 = "/en/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 = arrayCorpSummary ; arrayPDFs = arrayPDFCorpSummary;break;
        case 2:listReports = arrayFarmLandValues ; arrayPDFs = arrayPDFFarmLandValues;break;
        case 3:listReports = arrayJournal ; arrayPDFs = arrayPDFJournal; break;
        case 4: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);
        }

    }

}
