function MM_openBrWindow(theURL,winName,features) { //v2.0
  win=window.open(theURL,winName,features);
  win.focus();
}


function focusit(o){
	winname=o.target
	win=window.open("",winname,"")
	win.focus()
}

function resize() {
	window.resizeTo(600,400);
}

function email(a,b){
	document.location = "mailto:" + a + "\x40" + b;
}

function email2(addr){
	//addr is the address with a @ sign replaced by an image
	//find the first <
	str=addr.innerHTML
	//alert (str)
	bit=str.split(/[<>]/)
	a=bit[0]
	b=bit[2]
	document.location = "mailto:" + a + "\x40" + b + "?subject=Via ContactAnAuthor website";
}

function checkinfosearch(){
	if (document.form1.distance.value!="10000"){
		//alert ("pretending to check")
		pc=document.form1.postcode.value
		if (pc.length<2 || pc.length>8){
			msg="A valid postcode format is required if you want to limit travel distances"
			if (pc.length >4){ // expect to find a space
				re=/\s/
				if (pc.search(re)==-1){
					msg="A valid postcode format is required if you want to limit travel distances\nYou must include a space in your postcode as we only use the first half for your location"; 
				}
			}
			if (msg!=""){
				alert(msg)	
				return;
			}
		}
	}
	
	document.form1.searchtype.value="info"
	document.form1.submit()
}
function checknamesearch(){
	if (document.form1.authorname.value.length<=2){
		alert("Invalid Author name entry, at least 3 characters needed");
		return
	}
	
	document.form1.searchtype.value="authorname"
	document.form1.submit()
}

function view(o){
	aid=o.id.substr(1)
	
	document.form1.id.value=aid
	document.form1.action="authorpage.php"
	//alert (aid)
	document.form1.submit()
}

function add(o){
	try{  //the id might already be in the id input tag if it comes from the author page
		aid=o.id.substr(1)
		document.form1.id.value=aid
	}
	
	catch(e){//don't do anything
	}
	
	document.form1.nextaction.value="add"
	document.form1.action="shortlist.php"
	//alert (aid)
	document.form1.submit()
}

function remove(o){
	aid=o.id.substr(1)
	
	document.form1.id.value=aid
	document.form1.nextaction.value="remove"
	document.form1.action="shortlist.php"
	//alert (aid)
	document.form1.submit()

}

function gotolonglist(){
		
	document.form1.returning.value="yes"
	document.form1.action="longlist.php"
	document.form1.submit()
}

function clearlogin(){
	document.form1.nextaction.value="exit"
	document.form1.submit()	
}

function cleardirect(){
	//used when forms don't call themselves.
	document.form1.action="authormenu.php"
	clearlogin()
}
	
/**
*
*  Javascript trim, ltrim, rtrim
*  http://www.webtoolkit.info/
*
*
**/

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}