<!--
//	FLAG DIRECTORY JAVASCRIPT INCLUDE LIBRARY
//	By: Shawn Tse
//	Date: September 30, 2004
//  Last Modified: September 30, 2004

//  These are all of the Javascript functions that could possibly be used.
//  One of these is a browser check, another fo these is getting the element by the ID, since 
//  this is a function that varies from browser to browser.

//  Also, various global (not session-wide) variables can be stored here by the website.

// -->

 /*Browsercheck object, by Thomas Brattli*/
 function cm_bwcheck(){
 	//In theory we should use object detection, but this script needs work-arounds for almost every browser...
 	this.ver=navigator.appVersion
 	this.agent=navigator.userAgent.toLowerCase()
 	this.dom=document.getElementById?1:0
 	this.ns4=(!this.dom && document.layers)?1:0;
 	this.op=window.opera
 	this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
 	this.ie=this.agent.indexOf("msie")>-1 && !this.op
 	if(this.op){
 		this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1)
 		this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1)
 		this.op7=this.dom&&!this.op5&&!this.op6 //So all higher opera versions will use it
 	}else if(this.moz) this.ns6 = 1
 	else if(this.ie){
 		this.ie4 = !this.dom && document.all
   	this.ie5 = (this.agent.indexOf("msie 5")>-1)
   	this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
   	this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55
 	}
 	this.mac=(this.agent.indexOf("mac")>-1)
 	this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7)
   this.usedom= this.ns6||this.op7//Use dom creation
   this.reuse = this.ie||this.op7||this.usedom //Reuse layers
   this.px=this.dom&&!this.op5?"px":""
 	return this
 }
 var bw=new cm_bwcheck();
 /*Variable declaration*/


function getElementViaID(divID) {
    if( document.layers ) { //Netscape layers
        return document.layers[divID]; }
    if( document.getElementById ) { //DOM; IE5, NS6, Mozilla, Opera
        return document.getElementById(divID); }
    if( document.all ) { //Proprietary DOM; IE4
        return document.all[divID]; }
    if( document[divID] ) { //Netscape alternative
        return document[divID]; }

    return false;
}

function showElementByID(elementID) {
    thisElement = getElementViaID(elementID);
    thisElement.style.display = "";
    thisElement.style.visibility = "visible";
    thisElement.disabled = false;
}

function hideElementByID(elementID) {
    thisElement = getElementViaID(elementID);
//    thisElement.style.display = "none";
//    thisElement.style.visibility = "hidden";
    if(bw.ie) {
        alert(thisElement.all[0].value);
        alert(thisElement.all[0].name);
    } else if (true) {
        alert(thisElement.layers[0].value);
    }
    thisElement.disabled = true;
}

function showElement(obj) {
    obj.style.display = "";
    obj.style.visibility = "visible";
    obj.disabled = false;
}

function hideElement(obj) {
    obj.style.display = "none";
    obj.style.visibility = "hidden";
    obj.value = "";
}

function updateSelect(inArrayIndex, inArray, inSelectObj,mode) {
	var numOptions = inSelectObj.length;
	for(var j = 1; j < numOptions; j++) {
		inSelectObj.options[1] = null;			
	}
	if (inArrayIndex == 0 && (mode == 0 || mode == 3)) {
		inSelectObj.options[0] = new Option("Any Region",0);
	} else if (mode == 0) {
		inSelectObj.options[0] = new Option("Any Region",0);	
		for (var i = 1; i < inArray[inArrayIndex].length;i++) {
			inSelectObj.options[i] = new Option(inArray[inArrayIndex][i]["name"],inArray[inArrayIndex][i]["id"]);
		}
	} else if (mode ==3) {
		for (var i = 0; i < inArray[inArrayIndex].length - 1;i++) {
			inSelectObj.options[i] = new Option(inArray[inArrayIndex][i+1]["name"],inArray[inArrayIndex][i+1]["id"]);
		}
	} else if (inArrayIndex == 0 && mode == 1) {
		inSelectObj.options[0] = new Option("Any Category",0);
		hideSelect(inSelectObj);
		hideSelect(document.awardSearchFormBean.awardID);
	} else if (mode == 1) {
		inSelectObj.options[0] = new Option("Any Category",0);	
		for (var i = 1; i < inArray[inArrayIndex].length;i++) {
			inSelectObj.options[i] = new Option(inArray[inArrayIndex][i]["name"],inArray[inArrayIndex][i]["id"]);
		}
		showElement(inSelectObj);
	} else if (inArrayIndex == 0 && mode == 2) {
		inSelectObj.options[0] = new Option("Any Date",0);
		hideSelect(inSelectObj);
	} else if (mode == 2) {
		inSelectObj.options[0] = new Option("Any Date",0);	
		for (var i = 1; i < inArray[inArrayIndex].length;i++) {
			inSelectObj.options[i] = new Option(inArray[inArrayIndex][i]["name"],inArray[inArrayIndex][i]["id"]);
		}
		showElement(inSelectObj);
	}
}

function hideSelect(obj) {
    obj.style.display = "none";
    obj.style.visibility = "hidden";
	if (obj.options.length > 0) {
	    obj.options[0].selected = true;
	}
	if (obj.name == "department") {
		var dummyArray = new Array();
		updateSelect(0, dummyArray, obj);
	}
}

function trim(str) {
	// trims the spaces at the beginning and the end of a string
	return str.replace(/^\s*|\s*$/g,"");
}
			
// Starting parameters
var fullPath = document.location.protocol + "//" + document.location.hostname + document.location.pathname;
var isDebug = false;
var includeDir = "includes/";
var imageDir = "images/";
