// color button text changes to when you mouse over it
var highlightColor = "cc6600";
var highlightBg = "666633";

// captures current color of button text then sets text color to above specified highlight color
function buttonRollOn(which) {
	if (which.style) {
		colorBuffer = which.style.color;
		bgBuffer = which.style.background;
		which.style.backgroundColor = highlightBg;
		which.style.color = '#' + highlightColor;
	}
}

// sets color of button text back to original value
function buttonRollOff(which) {
	if (which.style) {
		which.style.color = colorBuffer;
		which.style.backgroundColor = bgBuffer;
	}
}

//javascript for check all/none
var checkState = false;
function checkAll(myCheckboxes){
	if(checkState == false){
		checkState = true;
	} else {
		checkState = false;
	}
	for(i = 0; i < document.forms[0].elements.length; i++) {
		elm = document.forms[0].elements[i]
		if (elm.type == 'checkbox') {
			if((elm.name == myCheckboxes)||(!myCheckboxes)){
				elm.checked = checkState;
			}
		}
	}
}




// confirmation utility
function confirmSubmit(msg) {
	var agree=confirm(msg);
	if (agree)
		return true;
	else
		return false;
}

// scripts for roll overs found in tables of information

// holder for toggle state of row
// holder for init state
var inited = 0;
rowColors = new Array();
tables = new Array();
var rowhighlightColor = "#FFFFAA";

// sets the roll off and click off colors to the current background colors of the table, allows you to update style of table without having to worry about roll off color not matching
function initColors( originalCellOneColor, originalRowColor ){
	if (inited == 0){
		inited = 1;
		cellonedefColor = originalCellOneColor;
		rowdefaultColor = originalRowColor;
	}
}

// assigns titles to each cell of a table based on the inner text of column header
function init_titles(thisTable){
	this_row = thisTable.rows;
	titles = this_row[0].cells;
	var i = 1;
	while (this_row[i]){
		current_cells = this_row[i].cells;
		j = 0;
		while (current_cells[j]){
			if(titles[j].innerText != ' '){
				current_cells[j].title = titles[j].innerText;
			}
			j++;
		}
		i++;
	}
}
	
function changecolor(rownumber,thisTable,which) {  
	var x=thisTable.rows;  
	var rowdefaultColor;
	if ((event.srcElement.tagName != 'A') && (event.srcElement.tagName != 'INPUT') && (event.srcElement.tagName != 'SELECT')) {  
		if (!(which.name=='active')) {  
			which.name='active';
			y = x[rownumber].cells;
			i=0;
			while(y[i]) {
				y[i].style.borderRightColor = rowhighlightColor;
				y[i].style.borderLeftColor = rowhighlightColor;
				y[i].style.backgroundColor = rowhighlightColor;
				i++;
			}
		} else {  
			which.name = '';  
			y = x[rownumber].cells;
			i=0;
			while(y[i]) {
				y[i].style.borderRightColor = thisTable.style.backgroundColor;
				y[i].style.borderLeftColor = thisTable.style.backgroundColor;
				y[i].style.backgroundColor = thisTable.style.backgroundColor;
				i++;
			}
		}  
	}  
}  
	
// changes color on roll over (if not toggled to on) and triggers initialization of default colors if hasn't been initialized yet
function rollon(rownumber, thisTable, which) {
	var x = thisTable.rows;
	if (which.name != 'active') {
		y = x[rownumber].cells;
		i=0;
		while(y[i]) {
			y[i].style.borderRightColor = rowhighlightColor;
			y[i].style.borderLeftColor = rowhighlightColor;
			y[i].style.backgroundColor = rowhighlightColor;
			i++;
		}
	}
}

// changes color back to default colors (if not toggled to on)
function rolloff(rownumber, thisTable, which) {
	var x = thisTable.rows;
	if (which.name != 'active') {
		//alert(rowdefaultColor);
		y = x[rownumber].cells;
		i=0;
		while(y[i]) {
			y[i].style.borderRightColor = thisTable.style.backgroundColor;
			y[i].style.borderLeftColor = thisTable.style.backgroundColor;
			y[i].style.backgroundColor = thisTable.style.backgroundColor;
			i++;
		}
	}
}

// functions for hiding/showing roll over notes/descriptions
function show_note(container, alignment){
	x = event.clientX + 30;
	if (navigator.appName == "Microsoft Internet Explorer"){
		y = event.clientY - 15 + document.body.scrollTop;
	} else {
		y = event.clientY - 15;
	}
	if(alignment == 'left'){
		container.style.left = x - 280;
	} else {
		container.style.left = x;
	}
	container.style.top = y;
	container.style.visibility='visible';
}

function hide_note(container){
	container.style.visibility='hidden';
}

//COOKIE FUNCTIONS FOR COLLAPSABLE BOXES
//tries to get a cookie with a particular name
function getCookie(name) {
   var start = document.cookie.indexOf(name+"=");
   var len = start+name.length+1;
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
   if (start == -1) return null;
   var end = document.cookie.indexOf(";",len);
   if (end == -1) end = document.cookie.length;
   return unescape(document.cookie.substring(len,end));
}
//creates a cookie with hidden/visible value
function setCookie(name,value,expires,path,domain,secure) {
   document.cookie = name + "=" +escape(value) +
   ((expires) ? ";expires=" + expires.toGMTString() : "") +
   ((path) ? ";path=" + path : "") + 
   ((domain) ? ";domain=" + domain : "") +
   ((secure) ? ";secure" : "");
}

//creates the expire date and sets it to 1 year from creation
var expireDate = new Date();
expireDate.setFullYear(expireDate.getFullYear() + 1);

//VISIBILITY FUNCTIONS
//sets the element to hidden and changed it's toggle image
function setHidden(whichID){
	elementID = document.getElementById(whichID);
	elementImage = document.getElementById(whichID + 'Image');
	//elementIndicator = document.getElementById(whichID + 'Indicator');
	functionFooter = document.getElementById(whichID + 'Footer');

	elementID.style.display = 'none';
	if(functionFooter){
		if (navigator.appName == "Microsoft Internet Explorer"){
			functionFooter.style.display = '';
		} else {
			functionFooter.style.display = 'table-row';
		}
		
	}
	//elementIndicator.innerText = '+';
	elementImage.src = '/expand.gif';
	setCookie(whichID, "hidden", expireDate);
}
//sets the element to visible and changed it's toggle image
function setVisible(whichID){
	elementID = document.getElementById(whichID);
	elementImage = document.getElementById(whichID + 'Image');
	//elementIndicator = document.getElementById(whichID + 'Indicator');
	functionFooter = document.getElementById(whichID + 'Footer');
	
	if(functionFooter){
		functionFooter.style.display = 'none';
	}
	if (navigator.appName == "Microsoft Internet Explorer"){
		elementID.style.display = '';
	} else {
		elementID.style.display = 'table-row';
	}
	//elementIndicator.innerText = '-';
	elementImage.src = '/collapse.gif';
	setCookie(whichID, "visible", expireDate);
}
//toggles visibility based on current state
function toggleVisible(whichID){
	elementID = document.getElementById(whichID);
	if((elementID.style.display == '')||(elementID.style.display == 'table-row')){
		setHidden(whichID);
	} else {
		setVisible(whichID);
	}
}
//tests to see if there is an existing value on the element, as default is to alway be visible this only takes action when it's set to hidden
function checkCookie(whichID){
	tempCookie = getCookie(whichID);
	if(tempCookie=="hidden"){
		setHidden(whichID);
	} else if (tempCookie=="visible") {
		setVisible(whichID);
	}
}

//code for scrolling to first row beggining with pressed key on iframe boxes
var lastSelected;
var myLetterIndex = new Array();

function initLookAhead(thisTable){
	this_row = thisTable.rows;
	i = 1;
	while (this_row[i]){
		current_cells = this_row[i].cells;
		myLetterIndex[this_row[i].rowIndex] = current_cells[0].innerText.substring(0,1).toLowerCase();
		i++;
	}
}

function scrollToKey(which,thisTable) {
	if(!which.modifiers){
		myLetter = String.fromCharCode(which.keyCode);
		if(lastSelected){
			currRow = lastSelected + 1;
		} else {
			currRow = 1;
		}
		while((myLetterIndex[currRow]) && (myLetterIndex[currRow] != myLetter)){
			currRow++;
		}
		if(myLetterIndex[currRow] != myLetter){
			if(lastSelected){
				currRow = 1;
				while((myLetterIndex[currRow]) && (myLetterIndex[currRow] != myLetter)){
					currRow++;
				}
			}
		}
		if(myLetterIndex[currRow] == myLetter){
			yPosition = findPosY(thisTable.rows[currRow].cells[0]);
			scrollMe(yPosition);
			if(lastSelected){
				myRow = thisTable.rows[lastSelected];
				rolloff(lastSelected, thisTable, myRow);
			}
			lastSelected = currRow;
			rollon(currRow, thisTable, thisTable.rows[currRow]);
		}
	}
}
 
function scrollMe(myY){
	window.scrollTo(0,myY);
}
 
function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

//hide show for credit history
var myHistoryIndex = new Array();
function hideShowHistory(myHistoryID){
	elementID = document.getElementById("myhistory" + myHistoryID);
	linkElementID = document.getElementById("hideShow" + myHistoryID);
	if(myHistoryIndex[myHistoryID] != "show"){
		elementID.style.display = 'block';
		linkElementID.innerHTML="Hide Comments";
		myHistoryIndex[myHistoryID] = "show";
	} else {
		elementID.style.display = 'none';
		myHistoryIndex[myHistoryID] = "hide";
		linkElementID.innerHTML="Show Comments";
	}
}