function validate(advanced) {

 var returnval;

	returnval = true;
	if (advanced){
		formname='advancedform';
	} else {
		formname='basicform';
	}
	
	returnval = true;

    //Begin Validation logic.
    
	// Strip off any leading spaces
	while(''+document.forms[formname].forename.value.charAt(0)==' ')
	{
		document.forms[formname].forename.value=document.forms[formname].forename.value.substring(1,document.forms[formname].forename.value.length);
	}
	
	while(''+document.forms[formname].surname.value.charAt(0)==' ')
	{
		document.forms[formname].surname.value=document.forms[formname].surname.value.substring(1,document.forms[formname].surname.value.length);
	}

	

	// Make sure at least one is present. Does not matter if we are in advanced or basic search
    	if (document.forms[formname].forename.value == "" &&
   		document.forms[formname].surname.value == "")
   		{
 			document.forms[formname].forename.focus();
    		alert("You must enter at least one of:\n\tForename\n\tSurname");
	    	returnval = false;
	    	return ;
   		}
   	
  
    	
    	
    	nonWild = false;
   		
   		if (document.forms[formname].forename.value.indexOf('*') == -1 && document.forms[formname].forename.value != "") nonWild=true;
   		if (document.forms[formname].surname.value.indexOf('*') == -1 && document.forms[formname].surname.value != "") nonWild=true;
 //  		if (document.forms[formname].street.value.indexOf('*') == -1 && document.forms[formname].street.value != "") nonWild=true;
   		
   		if(formname =='basicform'){
   		
   		if (document.forms[formname].location.value.indexOf('*') == -1 && document.forms[formname].location.value != "") nonWild=true;
   		
   		}
   		else{
   		//	if (document.forms[formname].forename2.value.indexOf('*') == -1 && document.forms[formname].forename2.value != "") nonWild=true;
	   	//	if (document.forms[formname].surname2.value.indexOf('*') == -1 && document.forms[formname].surname2.value != "") nonWild=true;
	   		if (document.forms[formname].town.value.indexOf('*') == -1 && document.forms[formname].town.value != "") nonWild=true;
	 		if (document.forms[formname].county.value.indexOf('*') == -1 && document.forms[formname].county.value != "") nonWild=true;
			if (document.forms[formname].postcode.value.indexOf('*') == -1 && document.forms[formname].postcode.value != "") nonWild=true;		
   		}
   		
		if (!nonWild) {
 			document.forms[formname].forename.focus();
    		alert("You must enter a non wildcard value for the search fields.");
	    	returnval = false;
	    	return ;
		}
      	
      

    if (returnval == true)
    {
    	document.forms[formname].submit();
    }
    		
}

function resetBasicForm(){
	document.forms['basicform'].forename.value='';
	document.forms['basicform'].surname.value='';
	document.forms['basicform'].location.value='';
}	
function resetAdvancedForm(){
	document.forms['advancedform'].forename.value='';
	document.forms['advancedform'].surname.value='';
	document.forms['advancedform'].street.value='';
	document.forms['advancedform'].town.value='';
	document.forms['advancedform'].county.value='';
	document.forms['advancedform'].postcode.value='';
}

function showHelp() {
	help = window.open("AboutSearching.jsp?noNav=1#P2","Help","status, top=50,left=50,scrollbars=yes,resizable=yes,width=650,height=400");
	help.focus();
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}