
//-- -------------------------------------------
//-- FUNCTION TO CLEAR THE SEARCH BOX TEXT
//-- -------------------------------------------
function clearField(Field,fieldValue) {
	if (Field.value	== fieldValue) {
		Field.value = '';
	}
}





//-- -------------------------------------------
//-- FUNCTION TO RESET THE SEARCH BOX TEXT
//-- -------------------------------------------
function resetField(Field,fieldValue) {
	if (Field.value	== '') {
		Field.value = fieldValue;
	}
}





//-- -------------------------------------------
//-- FUNCTION TO PRINT PAGE
//-- -------------------------------------------
function printpage() {
	if (window.print) { window.print(); }
	else {
		alert ("To print this page please select the 'Print' option from your browser's 'File' menu.")
	}
	return;
}





//-- -------------------------------------------
//-- ADD ON LOAD EVENT
//-- -------------------------------------------
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
		func();
		}
	}
}




function syncDate(sourceObj,target) {
	var sourceValue = sourceObj.options[sourceObj.selectedIndex].value;
	var targetObj = document.getElementById(target);
	targetObj.value = sourceValue;
}





//-- -------------------------------------------
//-- GENERIC ACCESSIBLE POPUP SCRIPT
//-- -------------------------------------------
var _POPUP_FEATURES = 'width=790,height=525,scrollbars=no';

function raw_popup(url, target, features) {
	if (isUndefined(features)) features = _POPUP_FEATURES;
	if (isUndefined(target)) target = '_blank';
	var theWindow = window.open(url, target, features);
	theWindow.focus();
	return theWindow;
}

function link_popup(src, features) {
	return raw_popup(src.getAttribute('href'), src.getAttribute('target') || '_blank', features);
}


function isUndefined(v) {
	var undef;
	return v===undef;
}








//-- -------------------------------------------
//-- CREATE ROLLOVERS FOR PAGE LIST ITEMS
//-- -------------------------------------------
function pageItemRollovers(parentObject, childObjectType, childObjectClasses, exceptionClass) {
	if (document.getElementById(parentObject)) {
		var theParent = document.getElementById(parentObject);
		var theChildren = theParent.getElementsByTagName(childObjectType);
		for (var i = 0; i < theChildren.length; i++) {
			if (childObjectClasses.length) {

				// Create an array out of the childObjectClasses value(s)
				cObjClasses = new Array();
				if (childObjectClasses.indexOf("|") != -1) {
					cObjClasses = childObjectClasses.split("|");
				}
				else {
					cObjClasses[0] = childObjectClasses;
				}
				theChildren[i].onmouseover = function() {
					for(u=0; u<cObjClasses.length; u++) {
						if (this.className.indexOf(cObjClasses[u]) != -1) {
							if(exceptionClass.length != 0) {
								if (this.className.indexOf(exceptionClass) == -1) {
									this.className += " sfhover";
								}
							}
							else {
								this.className += " sfhover";
							}
						}
					}
				}
				theChildren[i].onmouseout=function() {
					for(u=0; u<cObjClasses.length; u++) {
						if (this.className.indexOf(cObjClasses[u]) != -1) {
							this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
						}
					}
				}
			}
			else {
				theChildren[i].onmouseover = function() {
					this.className += " sfhover";
				}
				theChildren[i].onmouseout=function() {
					this.className = this.className.replace(new RegExp(" sfhover\\b"), "");
				}
			}
		}
	}
}

function initRollovers() {
	pageItemRollovers('cmsFileList','div','Fodd|Feven', '');
	pageItemRollovers('cmsPublicationList','div','Fodd|Feven', '');
	pageItemRollovers('cmsEventList','div','Eodd|Eeven|featuredEvent','');
}









fixImageCaptionWidths = function() {
	if (!document.getElementById) return;
	var allDefLists = document.getElementsByTagName("dl");
	for (var i=0; i<allDefLists.length; i++) {
		var theDefList = allDefLists[i]
		if (hasClass(theDefList, "epImgCaption")) {
			var theImage = theDefList.childNodes[0].childNodes[0];
			if (document.all) {
				var theWidth = theImage.width;
			} else {
				var theWidth = theImage.width + 8;
			}
			theDefList.style.width = theWidth +"px";
			if (hasClass(theDefList, "capright")) {
				removeClass(theDefList, "capright");
				addClass(theDefList, "flRight");
			}
			if (hasClass(theDefList, "capleft")) {
				removeClass(theDefList, "capleft");
				addClass(theDefList, "flLeft");
			}
		}
	}
};




function deselectAllOptions($parentObj) {
	$parentObj = document.getElementById($parentObj);
	$allCheckboxes = $parentObj.getElementsByTagName("input");
	for (i = 0; i < $allCheckboxes.length; i++)
	{
		$allCheckboxes[i].checked = false ;
	}
	return false;
}






// Create closed namespace for jQuery code.
(function($) {
	$(document).ready(function() {

		var $parameters = "location=0,menubar=0,height=600,width=600,toolbar=0,scrollbars=1,status=0,resizable=1";

		$('a.pdfFile.').each(function(i) {
			var $this = $(this);
			updateTitleAttr($this);
			$this.click(function() {
				$href = $this.attr('href')
				window.open($href,"FileWin", $parameters);
				return false;
			});
		});

		$('a.docFile.').each(function(i) {
			var $this = $(this);
			updateTitleAttr($this);
			$this.click(function() {
				$href = $this.attr('href')
				window.open($href,"FileWin", $parameters);
				return false;
			});
		});

		$('a.popup.').each(function(i) {
			var $this = $(this);
			updateTitleAttr($this);
			$this.click(function() {
				$href = $this.attr('href')
				window.open($href,"FileWin", "location=0,menubar=0,height=600,width=800,toolbar=0,scrollbars=1,status=0,resizable=1");
				return false;
			});
		});


		$('#sitesearch').each(function () {
      		$(this).replaceWith("\
      		<form id=\"sitesearch\" class=\"ep-validate\" action=\"" + websiteURL + "search.asp\">\
      		<input type=\"hidden\" name=\"cx\" value=\"009456713982566622073:zezpvpadlro\" />\
      		<input type=\"hidden\" name=\"cof\" value=\"FORID:11\" />\
      		<input type=\"hidden\" name=\"ie\" value=\"UTF-8\" />\
      		<fieldset>\
      		<legend>Search the site</legend>\
      		<label for=\"q\">Enter keyword</label>\
      		<input id=\"q\" type=\"text\" value=\"\" name=\"q\" alt=\"Search term\" />\
      		<button id=\"sa\" name=\"sa\" type=\"submit\" value=\"search\">Search</button>\
      		</fieldset>\
      		</form>\
      		<script type=\"text/javascript\" src=\"http://www.google.com/coop/cse/brand?form=sitesearch&lang=en\"></script>");
		 });


		function updateTitleAttr($obj) {
			$title = $obj.html() + $obj.attr('title') + ' - opens in new window';
			$obj.attr('title',$title);
		}



		$(".de-select-specialisms").each(function()
		{
			var $this = $(this);
			var $parent = $this.parent().get(0).getAttribute("id");

			$this.removeClass("hide");
			$this.addClass("frmInputs-button");

			$this.html("<a href=\"#\" onclick=\"deselectAllOptions('"+$parent+"');return false;\">De-select all specialisms</a>");
		});


	});
})(jQuery);






addLoadEvent(initRollovers);
addLoadEvent(fixImageCaptionWidths);


