//##################################################     T R I M     M E T H O D S     #############################
// http://www.developingskills.com/ds.php?article=jstrim&page=1
function strltrim() {
	//Match spaces at beginning of text and replace with a null string
	return this.replace(/^\s+/,'');
}

function strrtrim() {
	//Match spaces at end of text and replace with a null string
	return this.replace(/\s+$/,'');
}

function strtrim() {
	//Match spaces at beginning and end of text and replace with null strings
	//return this.replace(/^\s+/,'').replace(/\s+$/,'');
	return this.ltrim().rtrim();
}

String.prototype.ltrim = strltrim;
String.prototype.rtrim = strrtrim;
String.prototype.trim  = strtrim;

//########################################     O P E N S     A     N E W     W I N D O W     #########################
function NewWindow(url, winname, w, h, popunder) {
	try {
		var winl = (screen.availWidth  - w) / 2;
		var wint = (screen.availHeight - h) / 2;

		var win = window.open( url, winname, "width="+w+",height="+h+",resizable=1,menubar=0,scrollbars=1,toolbar=0,location=0,top="+wint+",left="+winl );
		if (popunder) win.blur();
		return win;
	}
	catch(e) {
		alert('window open failed');
		return false;
	}
}


//#####################################     V A L I D A T E S      D D     D E T A I L S     #########################
function checkDDlookup( oButton ) {
	var oForm = oButton.form;
	var retval = true;		// don't stop if we can't check things properly

	if (oForm) {
		var sortcode =	oForm.lookupDDsortCode1.value.trim() +
										oForm.lookupDDsortCode2.value.trim() +
										oForm.lookupDDsortCode3.value.trim();
		var accountno =	oForm.lookupDDaccountNumber.value.trim();

		if (accountno.match(/\w{7,9}/)==null) {
			retval = false;
			oForm.lookupDDaccountNumber.focus();
			oForm.lookupDDaccountNumber.select();
			alert( 'Please enter/correct your account number' );
		}
		else if (sortcode.match(/\d{6}/)==null) {
			retval = false;
			oForm.lookupDDsortCode1.focus();
			alert( 'Please enter/correct your sort code' );
		}
	}

	return retval;
}

function swap(targetId) {
	
	if (document.getElementById) {
		target = document.getElementById(targetId);
		if (target.style.display == "none") {
			target.style.display = "block";
		} else {
			target.style.display = "none";	
		}
	}
}