// set-up the auto-logout timer
var date = new Date();
var time = date.getTime();
var timeEnd = time + (1000*60*60);

// function that does the timer at the top of each page
function countDown() {
	var dateNow = new Date();
	var timeNow = dateNow.getTime();
	var timeRemaining = timeEnd - timeNow;
	if (timeRemaining > 0) {
		//alert(timeRemaining);
		var dateRemaining = new Date(timeRemaining);
		secondsRemaining = dateRemaining.getSeconds();
		minutesRemaining = dateRemaining.getMinutes();
		hoursRemaining = dateRemaining.getHours();
		var clockString = "";
		if (hoursRemaining) {
			if (hoursRemaining == 1) {
				clockString = hoursRemaining + "hr ";
			} else {
				clockString = hoursRemaining + "hrs ";
			}
		}
		if (minutesRemaining == 1) {
			clockString = clockString + minutesRemaining + "min " + secondsRemaining + "secs";
		} else {
			clockString = clockString + minutesRemaining + "mins " + secondsRemaining + "secs";
		}
		clockString = "auto-logout in: " + clockString;
		document.getElementById("clockString").innerHTML = clockString;
	} else {
		clearInterval(countDownId);
		location.href = "logout.php";
	}
}
// var countDownId = window.setInterval("countDown()",1000);


// toggle the display of the colum selection on the search page
function toggleFieldSelection() {
	myFieldset = document.getElementById("searchFieldSelection");
	myLink = document.getElementById("showFieldsLink");			
	if (myFieldset.style.display == "block") {
		myFieldset.style.display = "none";
		//myLink.innerHTML = "<a href=\"javascript:toggleFieldSelection();\">show fields</a>";
	} else {
		myFieldset.style.display = "block";
		//myLink.innerHTML = "<a href=\"javascript:toggleFieldSelection();\">hide fields</a>";
	}
}


// toggle the display of the column selection on the results page
function toggleResultsFieldSelection() {
	myFieldset = document.getElementById("resultsSearchFieldSelection");
	if (myFieldset.style.display == "block") {
		myFieldset.style.display = "none";
	} else {
		myFieldset.style.display = "block";
	}
}


// function for passing through values to the form when submitted so we know what action to take
function searchSubmit(thisAction) {
	thisForm = document.getElementById("formSearch");
	thisForm.hiddenAction.value = thisAction;
	thisForm.submit();
}


// function for hiding emails from spammers
function mix(name,domain) {
	document.write('<a href=\"mailto:' + name + '@' + domain + '.com' + '\">');
	document.write(name + "@" + domain + '.com' + '</a>');
}

