<!--

function $(element) {
	return document.getElementById(element);
}

/* Taken from http://www.htmldog.com/articles/suckerfish/shoal/ */
function suckerfish(type, tag, parentId) {
	if (window.attachEvent) {
		window.attachEvent("onload", function() {
			var sfEls = (parentId==null)?document.getElementsByTagName(tag):document.getElementById(parentId).getElementsByTagName(tag);
			type(sfEls);
		});
	}
}

sfHover = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}

sfFocus = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" sffocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
}

sfActive = function(sfEls) {
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmousedown=function() {
			this.className+=" sfactive";
		}
		sfEls[i].onmouseup=function() {
			this.className=this.className.replace(new RegExp(" sfactive\\b"), "");
		}
	}
}

sfTarget = function(sfEls) {
	var aEls = document.getElementsByTagName("A");
	document.lastTarget = null;
	for (var i=0; i<sfEls.length; i++) {
		if (sfEls[i].id) {
			if (location.hash==("#" + sfEls[i].id)) {
				sfEls[i].className+=" sftarget";
				document.lastTarget=sfEls[i];
			}
			for (var j=0; j<aEls.length; j++) {
				if (aEls[j].hash==("#" + sfEls[i].id)) aEls[j].targetEl = sfEls[i];
				aEls[j].onclick = function() {
					if (document.lastTarget) docu.lastTarget.className = document.lastTarget.className.replace(new RegExp(" sftarget\\b"), "");
					if (this.targetEl) this.targetEl.className+=" sftarget";
					document.lastTarget=this.targetEl;
					return true;
				}
			}
		}
	}
}

var departmentChange = function() {
	selectObj = $('departmentID');

	if (selectObj.options[selectObj.selectedIndex].value == '0') {
		$('departmentSuggestion').style.display = 'inline';
	} else {
		$('departmentSuggestion').style.display = 'none';
	}
}

var typeChange = function() {
	selectObj = $('type');

	var sType = selectObj.options[selectObj.selectedIndex].value;

	switch (sType) {
		case 'project' :
			$('title-label').innerHTML = 'Project Title';
			$('row-projectID').style.display = '';
			$('row-eligiblity').style.display = '';
			$('row-funding').style.display = '';
			$('row-deadline').style.display = '';
			break;
		case 'programme' :
			$('title-label').innerHTML = 'Programme Title';
			$('row-projectID').style.display = 'none';
			$('row-eligiblity').style.display = 'none';
			$('row-funding').style.display = 'none';
			$('row-deadline').style.display = 'none';
			break;
	}
}

var videoChange = function() {
	selectObj = $('video');

	var sType = selectObj.options[selectObj.selectedIndex].value;

	if (sType == 'new') {
		$('new_video').style.display = 'block';
		$('preview_video').style.display = 'none';
	} else {
		$('new_video').style.display = 'none';

		if (sType > 0) {
			$('preview_video').style.display = 'block';
		} else {
			$('preview_video').style.display = 'none';
		}
	}
}

var initialiseCalendar = function() {
	var deadlineCal = $('deadline-picker');
	deadlineCal.DateChooser = new DateChooser();
	deadlineCal.DateChooser.setUpdateField({'deadline_day':'d', 'deadline_month':'m', 'deadline_year':'Y'});
	deadlineCal.DateChooser.setIcon('/javascript/date/datechooser.png', 'deadline_year');

	return true;
}

var loadDepartments = function() {
	var iInstituteID = $('instituteID').options[$('instituteID').selectedIndex].value;

	$('departmentID').options.length = 0;
	$('departmentSuggestion').style.display = 'none';

	if (iInstituteID == '') {
		$('departmentID').options[$('departmentID').options.length] = new Option('Select a university or institute','');
	} else {
		$('departmentID').options[$('departmentID').options.length] = new Option('Loading departments. Please wait...','');
		var cObj = YAHOO.util.Connect.asyncRequest('GET','/data/ajax.control.php?action=loaddepartments&instituteID='+iInstituteID, depCB);
	}
}

var depCB = {
	success: function(o) {
		var response = o.responseXML;

		$('departmentID').options.length = 0;

		var aDepartments = response.getElementsByTagName('department');

		if (aDepartments.length == 0) {
			$('departmentID').options[$('departmentID').options.length] = new Option('No departments registered. Please type the name of yours below','0');
			$('departmentSuggestion').style.display = 'inline';
		} else {
			$('departmentID').options[$('departmentID').options.length] = new Option('Select...','x');
			$('departmentID').options[$('departmentID').options.length] = new Option('Not listed [please provide separately]','0');

			for (var i=0; i<aDepartments.length; i++) {
				var iDepartmentID = aDepartments[i].getElementsByTagName('departmentID')[0].firstChild.nodeValue;
				var sDepartmentName = aDepartments[i].getElementsByTagName('departmentName')[0].firstChild.nodeValue;
				$('departmentID').options[$('departmentID').options.length] = new Option(sDepartmentName, iDepartmentID);
			}
		}
	},
	failure: function(o) {
		$('departmentID').options.length = 0;
		$('departmentID').options[$('departmentID').options.length] = new Option('Loading failed. Please type your department\'s name below','0');
		$('departmentSuggestion').style.display = 'inline';
	},
	timeout: 5*1000
}

function newContactPopup() {
	var myWindow = window.open(
		'/manage/contacts/editor/small.php', 
		'contact', 
		'height=270,width=430,toolbar=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes'
	);
}

function previewSelectedVideo() {
	var instituteID = $('instituteID').value;

	selectObj = $('video');
	
	var videoID = selectObj.options[selectObj.selectedIndex].value;

	var myWindow = window.open(
		'/manage/video/?i=' + instituteID + '&v=' + videoID, 
		'video', 
		'height=365,width=435,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes'
	);
}

function open_help(anchor) {
	var scrollTo = '';

	if (anchor != null) {
		scrollTo = '#' + anchor;
	}

	var myWindow = window.open(
		'/popup-help/' + scrollTo,
		'help', 
		'height=300,width=500,toolbar=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes'
	);
}

function addContactToSelect(label, id) {
	$('contacts').options[$('contacts').options.length] = new Option(label, id);
	$('contacts').options[$('contacts').options.length-1].selected = true;

	resizeMultiselect('contacts');

	return true;
}

function resizeMultiselect(id) {
	if (!$(id)) { return; }

	if ($(id).options.length > 3) {
		var iMultiple = Math.ceil($(id).options.length/3);
		var iHeight = iMultiple * 50;

		$(id).style.height = iHeight + 'px';
	}
}

function js_test() {
	if ($('cse-search-box')) {
		var form = document.forms['cse-search-box'];
		// form.action = 'put your url here';
		var el = document.createElement("input");
		el.type = "hidden";
		el.name = "js";
		el.value = "1";
		form.appendChild(el);
	}

	if ($('cse-search-box-main')) {
		var form = document.forms['cse-search-box-main'];
		// form.action = 'put your url here';
		var el = document.createElement("input");
		el.type = "hidden";
		el.name = "js";
		el.value = "1";
		form.appendChild(el);
	}
}

-->
