	/* "GLOBAL" VARIABLES *********************************************** */
	var obox;
	var gbox;
	var cbox;
	var cpbox;
	
	var organVal;
	var groupVal;
	var charVal;
	var chapVal;

	var chaptersLookup = new Array("preface_contributors.htm","chapter_i_ar_cd.htm","chapter_ii_ar_cd.htm","chapter_iii_ar_cd.htm","chapter_iv_ar_cd.htm","chapter_v_ar_cd.htm","chapter_vi_ar_cd.htm","chapter_vii_ar_cd.htm","chapter_viii_ar_cd.htm","chapter_ix_ar_cd.htm");
	/* END "GLOBAL" VARIABLES ******************************************* */




	/* "PUBLIC" FUNCTIONS *********************************************** */
	function OnLoad() {		

		var form = document.forms[0];

		obox = form.organ;
		gbox = form.group;
		cbox = form.characteristic;
		cpbox = form.chapter;

		gbox.disabled=true;
		cbox.disabled=true;

		cpbox.selectedIndex = 0;

		getPreselectedValues();		
		
		setPlugins();
		
		
	}

    function setPlugins()
    {
        var links;
        var hasPdf = false;
        var hasDoc = false;
        var pdfLink, docLink;
        
            links = document.getElementsByTagName("a");
            hasPdf = checkFileType(links, ".pdf");
            hasDoc = checkFileType(links, ".doc");
            if (!hasPdf)
            {               
                if (document.getElementById("pdfPluginLink") != null)
                    document.getElementById("pdfPluginLink").style.display = "none";
                if (document.getElementById("pdfPluginLink1") != null)
                    document.getElementById("pdfPluginLink1").style.display = "none";
            }                                       
            
    }
    
    function checkFileType(links, fileType)
    {
        var hasFile = false;
        for(i=0; i < links.length; i++)
        {
            var link = links[i].href.toLowerCase();
            if (link.indexOf(fileType) > 0)
            {
                hasFile = true;
                break;
            }   
        }
        return hasFile;
    }
    
	function PopulateDropdowns() {
		// This function gets called whenever the organ or the group 
		// selection changes. This function performs DLL option changes.

		// Get selected values.
		LoadSelections();

		// whenever organ or group changes, that is, whenever this function gets called,
		// empty characteristics dropdown list
		EmptyDDL(cbox);		

		// if organ selection changed to '' then empty the Groups ddl
		if (!organVal) {
			EmptyDDL(gbox);
			//EmptyDDL(cbox);
		} else {
			if (IsEmptyDDL(gbox)) {
				// else make sure that the Group ddl gets 
				// populated if currently empty
				LoadGroupBox();
			} else {
				gbox.disabled=false;
			}
		}

		// if criteria set, load the Characteristics ddl
		if (organVal && groupVal) LoadCharacteristics();
	}

	function OnSubmit() {
		// Get selected values.		
		LoadSelections();		
		//if (organVal && !groupVal && !charVal) IndexPageSelection();
		//alert(cbox[GetSelectedIndex(cbox)].value + "-");		
		//if (cbox[GetSelectedIndex(cbox)].value + "-" != "-") {
			if ((organVal && groupVal && charVal) ) {
				CharacteristicSelection();
			}
			else {
				MakeSelectionAlert();
			}
		//}
		//else {
			//MakeSelectionAlert();
		//}
	}

	function OnChapterChange() {
		chapVal = getChapter();

		if (chapVal) ChapterSelection();
	}

	function showLookup(query, title) {
		// Function used by worksheets
	
		strURL = 'showLookup.htm?query=' + query + '&title=' + title;
		window.open(strURL, 'Lookup' ,'scrollbars,resizable,menubar,dependent,screenX=0,screenY=0,height=450,width=600');
	}
	
		function open_window(url,width,height) {
	
			  agent = navigator.userAgent;
			  windowName = "_blank";

			  params  = "";
			  params += "toolbar=0,";
			  params += "location=0,";
			  params += "directories=0,";
			  params += "status=0,";
			  params += "menubar=0,";
			  params += "scrollbars=1,";
			  params += "resizable=1,";

			  params += "width=" + width + ",";
			  params += "height=" + height;

			  win = window.open(url, windowName , params);

			  if (agent.indexOf("Mozilla/2") != -1 && agent.indexOf("Win") == -1) {
				  win = window.open(url, windowName , params); 
			  }

			  if (!win.opener) {
				  win.opener = window;
			  }
		}
		
		
		function open_win(url)
		{
			window.open(url,'ustranswin','');
	    }
	    
	    function get_ppt(chapter_num)
	    {
	    	open_win("http://" + window.location.hostname + "/ar_ppt/Chapter-" + chapter_num + "_2008-Annual-Report.ppt"); 
    	}
    	
	/* END "PUBLIC" FUNCTIONS ******************************************* */






	/* USER SELECTION ACTIONS *********************************************** */
	function IndexPageSelection() {
		redirect(indexPages[organVal]);
	}

	function CharacteristicSelection() {
		var red;
		red = charVal + '?o=' + GetSelectedIndex(obox) + '&g=' + GetSelectedIndex(gbox) + '&c=' + GetSelectedIndex(cbox);
		
		redirect(red);
	}

	function ChapterSelection() {
		var red;
		red = chapVal + '?cp=' + GetSelectedIndex(cpbox);
		
		redirect(red);
	}

	function MakeSelectionAlert() {
		alert("Please make a selection.");
		obox.focus();
	}	
	/* END USER SELECTION ACTIONS ******************************************* */








	/* "PRIVATE" FUNCTIONS *********************************************** */
	function GetSelectedIndex(box) {
		if (!IsEmptyDDL(box)) {
			return box.selectedIndex;
		}
		return null;
	}

	function GetSelection(box) {
		if (box) {
			var Val = '';

			if (box.options[0]) {
				if (box.selectedIndex != null) {
					if (box.options[box.selectedIndex] != null) {
						if (box.options[box.selectedIndex].value != null) {
							Val = box.options[box.selectedIndex].value;														
						}
					}
				}
			}

			if (Val.length > 0) return Val;
		}
		return false;
	}

	function getOrgan() {
		return GetSelection(obox);
	}

	function getGroup() {
		return GetSelection(gbox);
	}

	function getCharacteristic() {
		return GetSelection(cbox);
	}

	function getChapter() {
		return GetSelection(cpbox);
	}

	function LoadGroupBox() {
		NewOption( gbox, '', '' );
		NewOption( gbox, 'Candidates', 'Candidate' );
		NewOption( gbox, 'Recipients', 'Recipients' );
		NewOption( gbox, 'Donors, All', 'All' );
		NewOption( gbox, 'Donors, Deceased', 'Deceased'  );
		NewOption( gbox, 'Donors, Living', 'Living' );
		gbox.disabled=false;
	}

	function NewOption(box, displayText, Value) {
		var option = new Option( displayText, Value );
		if (box) {
			if (box.options[0]) {
				box.options[box.length] = option;
			} else {
				box.options[0] = option;
			}
		}
	}

	function LoadCharacteristics() {
		var linksArr = links[organVal][groupVal];		
		// To loop through an associative array you have to use a for in loop.		
		i=0;		
		for(i in linksArr){			
			var optArr = linksArr[i].split('|');
			// Create a new drop down option with the
			// display text and value from the links array
			// and add to the end of the existing options
			NewOption( cbox, optArr[0], optArr[1] );
		}		
		//if (i<1 && linksArr[0]=="") {
		if (i<1) {
			if ((linksArr[0]=="") || !(linksArr[0])) {
				EmptyDDL(cbox);
				NewOption( cbox, 'No characteristic available', '' );
			}
		}
		else {
			cbox.disabled=false;
		}

		// Preselect option 0
		cbox.selectedIndex=0;
	}

	function EmptyDDL(box) {
		// This function goes through the options for the given
		// drop down box and removes them (by setting each option to null) 
		// in preparation for a new set of values
				
		//box.options.length = 0;
		if (box) {
			if (box.options[0]) {
				var i = 0;

				//while ( box.options.length ) box.options[0] = null;

				i = box.options.length - 1 ;
				while ( i >= 0 ) {
					box.options[i] = null;
					i--;
				}

				box.disabled=true;
			}
		}
	}

	function IsEmptyDDL(box) {
		if (box) {
			if (box.options[0] == null)
				return true;
		}
		return false;
	}

	function LoadSelections() {		
		organVal = getOrgan();
		groupVal = getGroup();
		charVal = getCharacteristic();
	}

	function redirect(url) {
		if (url) {
			url = strRoot + url;
			window.location.href = url;
		}
	}

	function QueryString(key) { 
		var value = null; 
		for (var i=0;i<QueryString.keys.length;i++) { 
			if (QueryString.keys[i]==key) { 
				value = QueryString.values[i]; 
				break; 
			} 
		} 
		return value; 
	} 

	function QueryString_parse() { 
		var query = window.location.search.substring(1); 
		var pairs = query.split("&"); 

		for (var i=0;i<pairs.length;i++) { 
			var pos = pairs[i].indexOf('='); 
			if (pos >= 0) { 
				var argname = pairs[i].substring(0,pos); 
				var value = pairs[i].substring(pos+1); 
				QueryString.keys[QueryString.keys.length] = argname; 
				QueryString.values[QueryString.values.length] = value; 
			} 
		} 
	}

	function getPreselectedValues() {
		QueryString.keys = new Array(); 
		QueryString.values = new Array(); 
		QueryString_parse();

        // Changed by Jack: set the chapter index based on URL rather than query string
//		if (QueryString('cp') != null) {
//			cpbox.selectedIndex = QueryString('cp');
//		}
        var url = window.location.href;
        setChapterPageIndex(url);

		if (QueryString('o') != null) {
			obox.selectedIndex = QueryString('o');
			PopulateDropdowns();

			if (QueryString('g') != null) {
				gbox.selectedIndex = QueryString('g');
				PopulateDropdowns();

				if (QueryString('c') != null) {
					cbox.selectedIndex = QueryString('c');
				}
			}

		} else {
			obox.selectedIndex = 0;
		}
	}

	function DoHighlight(theRow){if (isIE() != 1) {return;} theRow.style.backgroundColor = "#ffff99";} 
	function ClearHighlight(theRow){if (isIE() != 1) {return;} theRow.style.backgroundColor = "#ffffff";} 

	function isIE(){
		var browserName=navigator.appName; 
		if (browserName=="Microsoft Internet Explorer")
			return 1
	}
// added by Jack on 4/7/08: set the chapter dropdown by looking up the current URL
	function setChapterPageIndex(url) {
	    for(var i=0; i < chaptersLookup.length; i++) {
	        if(url.toLowerCase().indexOf(chaptersLookup[i]) > -1)
	            cpbox.selectedIndex = i + 1;
	    }
	}
	/* END "PRIVATE" FUNCTIONS ******************************************* */