

/**
 * Handles transparency section transactions
 * @author Shawn Haworth
 * @date 2008-04-21
 */
window.onload = function() {
	// Not required as of yet
}
/**
 * Performs and Ajax.Request call using Prototype lib
 * Callbacks act as a return
 * @return void
 */
function doCityChange() {
	var cities = document.getElementById('cities');
	var currentCity = cities.options[cities.selectedIndex].value;
	new Ajax.Request('/controller.php?func=getBranchOptions&city=' + currentCity,
					{
						method: 'get', // Required for responseText
						onSuccess: callbackDoCityChange,
						onFailure: callbackDoCityChangeError
						
					}
	);
}
/**
 * Callback for city change event
 */
function callbackDoCityChange(response) {
	document.getElementById('branchesText').innerHTML = response.responseText;
	document.getElementById('btnChangeBranch').enable();
	document.getElementById('sections').disable();
	document.getElementById('btnChangeSection').disable();
}
/**
 * Callback for city change event error
 */
function callbackDoCityChangeError(response) {
	alert('There was an internal error: Please contact the webmaster.');
}
/**
 * Performs and Ajax.Request call using Prototype lib
 * Callbacks act as a return
 * @return void
 */
function doBranchChange() {
	var branches = document.getElementById('branches');
	var currentBranch = branches.value;
	new Ajax.Request('/controller.php?func=getSectionOptions&branch=' + currentBranch,
					{
						method: 'get', // Required for responseText
						onSuccess: callbackDoBranchChange,
						onFailure: callbackDoBranchChangeError
						
					}
	);
}
function disableSections() {
	document.getElementById('sections').disable();
	document.getElementById('btnChangeSection').disable();	
}
/**
 * Callback for branch change event
 */
function callbackDoBranchChange(response) {
	document.getElementById('sectionsText').innerHTML = response.responseText;
	document.getElementById('btnChangeSection').enable();
}
/**
 * Callback for branch change event error
 */
function callbackDoBranchChangeError(response) {
	alert('There was an internal error: Please contact the webmaster.');
}
/**
 * Performs and Ajax.Request call using Prototype lib
 * Callbacks act as a return
 * @return void
 */
function doChangeSection() {
	var sections = document.getElementById('sections')	;
	var currentSection = sections.value;
		new Ajax.Request('/controller.php?func=displaySection&section=' + currentSection,
					{
						method: 'get', // Required for responseText
						onSuccess: callbackDoSectionDisplay,
						onFailure: callbackDoSectionDisplayError
						
					}
	);
}
/**
 * Callback for section display event
 */
function callbackDoSectionDisplay(response) {
	document.getElementById('sectionsDisplay').innerHTML = response.responseText;
}

/**
 * Callback for section display event error
 */
function callbackDoSectionDisplayError(response) {
	alert('There was an internal error: Please contact the webmaster.')	;
}

function searchDocuments() {
	var searchString = document.getElementById('searchField').value;
	new Ajax.Request('/controller.php?func=searchDocuments&searchField=' + searchString,
			{
				method: 'get', // Required for responseText
				onSuccess: callbackSearchDocuments,
				onFailure: callbackSearchDocumentsError
			}
	);
}

function callbackSearchDocuments(response) {
	document.getElementById('sectionsDisplay').innerHTML = response.responseText;
}

function callbackSearchDocumentsError(response) {
	alert(response.responseText);
}

function captureKeyStroke(e) {
		var code;
		if (!e) 
			var e = window.event;
		if (e.keyCode) { 
			code = e.keyCode;
			switch(e.keyCode) {
				case Event.KEY_RETURN: 
					searchDocuments();
					break;
			}
		}
		else if (e.which) {
			code = e.which;
			switch(e.which) {
				case Event.KEY_RETURN: 
					searchDocuments();
					break;
			}
		}
		var character = String.fromCharCode(code);
		//alert('Character was ' + character);
}












