//*****************************************************************
// 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","Quarterly Financial Report","Corporate Plan Summary", "Farmland Values", "AgriSuccess Journal", "Knowledge Insider");
var VER1=0;
//////////////////////////////////////////
arrayAnnualReports = new Array("Annual Reports           ",
                               "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_e.pdf",
            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");
                           
///////////////////////////////////////////                                   

arrayQuarterlyFinancialReport = new Array("","First Quarter 2011-12", "Second Quarter 2011-12");
arrayQuarterlyPDFFinancialReport = new Array(path + "2011-12_quarterlyFinancialReport_e.pdf",path + "Q2_2011_E.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       ",
				"Fall 2011",
				"Spring 2011",
				"Fall 2010",
				"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",
                                "Spring 1999",
                                "Fall 1998",
                                "Spring 1998",
                                "Fall 1997",
                                "Spring 1997",
                                "Fall 1996",
                                "Spring 1996",
                                "Fall 1995",
                                "Spring 1995",
                                "Fall 1994",
                                "Spring 1994",
                                "Fall 1993",
                                "Spring 1993",
                                "Fall 1992",
                                "Spring 1992",
                                "Fall 1991",
                                "Spring 1991",
                                "Fall 1990",
                                "Spring 1990",
                                "Fall 1989",
                                "Fall 1988",
                                "Fall 1987",
                                "Fall 1986",
                                "Fall 1985",
                                "Fall 1984");
arrayPDFFarmLandValues = new Array(
				   "/en/Products/Property/FLV/Fall2011/index.asp",
				   "/en/Products/Property/FLV/Spring2011/index.asp",
				   "/en/Products/Property/FLV/Fall2010/index.asp",
                                   "/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",
                                   path + "Spring_E_1999.pdf",
                                   path + "Fall_E_1998.pdf",
                                   path + "Spring_E_1998.pdf",
                                   path + "Fall_E_1997.pdf",
                                   path + "Spring_E_1997.pdf",
                                   path + "Fall_E_1996.pdf",
                                   path + "Spring_E_1996.pdf",
                                   path + "Fall_E_1995.pdf",
                                   path + "Spring_E_1995.pdf",
                                   path + "Fall_E_1994.pdf",
                                   path + "Spring_E_1994.pdf",
                                   path + "Fall_E_1993.pdf",
                                   path + "Spring_E_1993.pdf",
                                   path + "Fall_E_1992.pdf",
                                   path + "Spring_E_1992.pdf",
                                   path + "Fall_E_1991.pdf",
                                   path + "Spring_E_1991.pdf",
                                   path + "Fall_E_1990.pdf",
                                   path + "Spring_E_1990.pdf",
                                   path + "Fall_E_1989.pdf",
                                   path + "Fall_E_1988.pdf",
                                   path + "Fall_E_1987.pdf",
                                   path + "Fall_E_1986.pdf",
                                   path + "Fall_E_1985.pdf",
                                   path + "Fall_E_1984.pdf");
                                   			

//////////////////////////////////////////
arrayJournal = new Array("AgriSuccess Journal");
arrayPDFJournal = new Array();


//////////////////////////////////////////
arrayKnowledge = new Array("Knowledge Insider",
			   "Summer 2011",
                           "Winter 2011",			   
			   "Summer 2010",
                           "Winter 2010",
                           "Summer 2009",
                           "Winter 2009",
                           "Winter 2008",
                           "Summer 2008"
                          );
arrayPDFKnowledge = new Array(
			      
			      "/en/LearningCentre/Knowledge/doc/Knowledge_Globalization2_e.PDF",                              
                              "/en/LearningCentre/Knowledge/doc/KI_grow_idea_full_e.pdf",
			      "/en/LearningCentre/Knowledge/doc/KI_summer_2010_e.pdf",                              
                              "/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 = 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);
        }

    }

}

