String.prototype.trim = function() {
	a = this.replace(/^\s+/, '');
	return a.replace(/\s+$/, '');
} // end String.prototype.trim

String.prototype.validEmail = function() {
	emailRegex = /^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z_])*@([0-9a-zA-Z]([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$/;
	return emailRegex.test(this);
} // end String.prototype.validEmail

function selectOption (selectId, selectValue) {
	var selectObj = document.getElementById(selectId);
	var optionsLength = selectObj.options.length;
	for (i = 0; i < optionsLength; i++) {
		optionVal = selectObj.options[i].value;
		if (optionVal == selectValue) {
			selectObj.options[i].selected = true;
			return;
		}
	}
} // end function selectOption

function showPopup(url, W, H) {
	var target = '_new';
	var X = (screen.width / 2) - (W / 2);
	var Y = (screen.height / 2) - (H / 2);
	if (window.popupWin && !popupWin.closed) {
		popupWin.location.replace(url);
	}
	else {
		destroyPopup();
		var winPref = 'width=' + W + ',height=' + H + ',left=' + X + ',top=' + Y + ',scrollbars=yes,resizable=yes';
		popupWin = window.open (url, target, winPref); 
	}
	popupWin.resizeTo (1 * W, 1 * H);
	popupWin.moveTo (X, Y);
	popupWin.focus();
	addEvent(popupWin, 'unload', destroyPopup, false);
} // end function showPopup

function destroyPopup() {
	if (window.popupWin) popupWin = null;
} // end function destroyPopup

function showSecondaryPopup(url, W, H) {
	var target = '_blank';
	var X = (screen.width / 2) - (W / 2);
	var Y = (screen.height / 2) - (H / 2);
	if (window.secondaryPopupWin && !secondaryPopupWin.closed) {
		secondaryPopupWin.location.replace(url);
	}
	else {
		destroySecondaryPopup();
		var winPref = 'width=' + W + ',height=' + H + ',left=' + X + ',top=' + Y + ',scrollbars=yes,resizable=yes';
		secondaryPopupWin = window.open (url, target, winPref); 
	}
	secondaryPopupWin.resizeTo (1 * W, 1 * H);
	secondaryPopupWin.moveTo (X, Y);
	secondaryPopupWin.focus();
	addEvent(secondaryPopupWin, 'unload', destroySecondaryPopup, false);
} // end function showSecondaryPopup

function destroySecondaryPopup() {
	if (window.secondaryPopupWin) secondaryPopupWin = null;
} // end function destroySecondaryPopup

function addEvent (elm, evType, fn, useCapture) {
	if (!elm) return;
	if (elm.addEventListener) {
		elm.addEventListener (evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		var r = elm.attachEvent ('on' + evType, fn);
		return r;
	}
	else {
		elm['on' + evType] = fn;
	}
} // end function addEvent

function cancelDefault (e) {
	if (window.event && window.event.returnValue) {
		window.event.returnValue = false;
	}
	if (e && e.preventDefault) {
		e.preventDefault();
	}
} // end function cancelDefault

$(document).ready(function(){ 
	$('ul.sf-menu').supersubs({ 
		minWidth:    12,   // minimum width of sub-menus in em units 
		maxWidth:    27,   // maximum width of sub-menus in em units 
		extraWidth:  1     // extra width can ensure lines don't sometimes turn over 
		// due to slight rounding differences and font-family 
	}).superfish();  // call supersubs first, then superfish, so that subs are 
	// not display:none when measuring. Call before initialising 
	// containing tabs for same reason. 
	$('ul.sf-menu > li:last > a:first').addClass('last_parent');
	$(':checkbox, :radio').addClass('no_border');
	$('a[rel=external][href]').attr('target', '_blank');
}); 
