function trim(val) {
	return val.replace(/\s*/g, '');
}

function checkLogin(form, select) {
	var username = trim(document.login.username.value);
	var password = trim(document.login.password.value);
	
	if(username.length == 0 || password.length == 0) {
		alert('Please complete both fields.');
		return false;
	}
		
	if(select != "1") {
		form.action = 'http://saybox'+select+'.co.uk/shout.php?action=login';
	}
	return true;
}

/**
 * Removes duplicates in the array 'a'
 * @author Johan Känngård, http://dev.kanngard.net
 */
function unique(a) {
	tmp = new Array(0);
	for(i=0;i<a.length;i++){
		if(!contains(tmp, a[i])){
			tmp.length+=1;
			tmp[tmp.length-1]=a[i];
		}
	}
	return tmp;
}

/**
 * Returns true if 'e' is contained in the array 'a'
 * @author Johan Känngård, http://dev.kanngard.net
 */
function contains(a, e) {
	for(j=0;j<a.length;j++)if(a[j]==e)return true;
	return false;
}

function checkUsername(username, name, age) {
	invalid = username.match(/[^a-z0-9\._\-]/ig);
	(username.length < 3 || username.length > 25 || invalid) ? alert("Please type a valid username to check."+((invalid)?'\nThe following characters you entered are invalid:\n\n'+unique(invalid).join(' '):'')) : window.open("checkuser.php?username="+username+"&name="+name+"&age="+age, 'checkuser', 'width=335,height=175,status=no,scrollbars=auto,resizable=yes,top='+(parseInt((screen.availHeight - 175) / 2))+',left='+(parseInt((screen.availWidth - 335) / 2))).focus();
}

function disableAll() {
	var input = document.signup.getElementsByTagName('input');
	for(x=0; x<input.length; x++) {
		input[x].disabled = "disabled";
	}
}

var ie5 = document.all && document.getElementById;
var ns6 = document.getElementById && !document.all;
 
function showMore(whichid) {
	if (ie5||ns6) { var showid = document.getElementById(whichid); }
	if (showid.style.display == 'none') {
		showid.style.display = '';
	} else {
		showid.style.display='none';
	}
}