function search(){
		brief = "issue";	// "coin" or "issue"
	//	if(document.form1.brief[1].checked) brief = "coin";
	//	if (document.form1.xmlOnly.checked) {document.form1.xsl.value ="";}
		  
		document.form1.xml.value = "";
		document.form1.debug.value = "";
		document.form1.showtab.value = "";
		document.form1.id.value = "";
		document.form1.query.value = ""
		document.form1.query2.value = ""
		
		if (document.form1.idCoin.value != ""){
			showCoin(document.form1.idCoin.value, "");
			return;
		}
		if (document.form1.idIssue.value != ""){
			showIssue(document.form1.idIssue.value, "");
			return;
		}
		
		donor = document.form1.donor.value;
		department = document.form1.department.value;
		denomination = document.form1.denomination.value;
		metal = document.form1.metal.value;
		issueRegion = document.form1.issueRegion.value;
		issueState = document.form1.issueState.value;
		issueCity = document.form1.issueCity.value;
		findRegion = document.form1.findRegion.value;
		findState = document.form1.findState.value;
		findCity = document.form1.findCity.value;
		ruler = document.form1.ruler.value;
		artist = document.form1.artist.value;
		laterThan = document.form1.laterThan.value;
		earlierThan = document.form1.earlierThan.value;
		
		where = "";
		if (department.length) where += " and departmentID = " + department;
		if (denomination.length) where += " and denominationID = " + denomination;
		if (metal.length) where += " and metalID = " + metal;
		if (issueCity.length) where += " and issue.placeID = " + issueCity;
		else if (issueState.length) where += " and Place.StateID = " + issueState;
		else if (issueRegion.length) where += " and Place.RegionID = " + issueRegion;
		if (findCity.length){
			where += " and coins.FindplaceID = " + findCity;
			brief = "coin";
		}
		else if (findState.length){
			where += " and Place_1.StateID = " + findState;
			brief = "coin";
		}
		else if (findRegion.length){
			where += " and Place_1.RegionID = " + findRegion;
			brief = "coin";
		}
		if (donor.length){
			where += " and AccPersonID = " + donor;
			brief = "coin";
		}
		if (ruler.length) where += " and rulerID = " + ruler;
		if (artist.length) where += " and personID = " + artist;
		if (laterThan.length) where += " and CE1 > " + laterThan;
		if (earlierThan.length) where += " and CE1 < " + earlierThan;

		word = document.form1.word.value;
		re = /\*/g;
		word = word.replace(re, "%");
		
		sqlIssue = "SELECT distinct Issue.issueid FROM (Issue LEFT JOIN Place ON Issue.PlaceID = Place.PlaceID) LEFT JOIN IssueArtist on Issue.IssueID = IssueArtist.IssueID Where ";
		sqlCoin = "SELECT distinct CoinID FROM ((((Issue LEFT JOIN Place ON Issue.PlaceID = Place.PlaceID) LEFT JOIN IssueArtist on Issue.IssueID = IssueArtist.IssueID) ";
		sqlCoin += "INNER JOIN Coins ON Issue.IssueID = Coins.IssueID) LEFT JOIN Accessions ON Coins.AccessionID = Accessions.AccessionID) LEFT JOIN Place AS Place_1 ON Coins.FindPlaceID = Place_1.PlaceID Where ";
		if (brief == "coin"){
			document.form1.recname.value = "briefCoin";
			document.form1.xsl.value ="/Numismatics/briefCoin.xsl";
			sql = sqlCoin;
		}
		else{	
			document.form1.recname.value = "briefIssue";
			document.form1.xsl.value ="/Numismatics/briefIssue.xsl";
			sql = sqlIssue;
		}
		
		if (where.length){
			where = where.substr(5);
			sql += where;
			document.form1.query.value = sql;
			if (word.length) document.form1.query2.value = "SELECT records FROM words Where word like '" + word + "'";
		}
		else if(word.length) document.form1.query.value = "SELECT records FROM words Where word like '" + word + "'";
		else return;
		send();
	}
	
	function showIssue(id, button){
		document.form1.button.value = button;
		document.form1.id.value = id;
		document.form1.recname.value = "Issue";
		document.form1.xsl.value = "/Numismatics/issue.xsl";
		document.form1.xml.value = "";
		document.form1.debug.value = "";
		document.form1.showtab.value = "";
		send();
	}
	
	function showCoin(id, button){
		document.form1.button.value = button;
		document.form1.id.value = id;
		document.form1.recname.value = "coin";
		document.form1.xsl.value = "/Numismatics/coin.xsl";
		document.form1.xml.value = "";
		document.form1.debug.value = "";
		document.form1.showtab.value = "";
		send();
	}
	
	function showMonograms(mtype){
		document.form1.query.value = "Select * from attributes where imagefilename like '" + mtype + "%'";
		document.form1.recname.value = "monogram";
		document.form1.xsl.value = "/Numismatics/monogram.xsl";
		switch (mtype){
			case "m" :
				document.form1.title.value = "Princeton Numismatics Monogram Search";
				document.form1.heading.value = "Click a monogram to view issues with that monogram.";
				break;
			case "a" :
				document.form1.title.value = "Princeton Numismatics Archaic Letters Search";
				document.form1.heading.value = "Click a symbol to view issues with that symbol.";
				break;
			case "c" :
				document.form1.title.value = "Princeton Numismatics Chinese Character Search";
				document.form1.heading.value = "Click a character to view issues with that character.";
				break;
		}
		document.form1.xml.value = "";
		document.form1.debug.value = "";
		document.form1.showtab.value = "";
		document.form1.id.value = "";
		document.form1.query2.value = ""
		mwin = window.open("", "mwin");
		document.form1.target= "mwin";
		document.form1.submit();
		mwin.focus();
	}
	
	function searchMonogram(id){
		document.form1.xml.value = "";
		document.form1.debug.value = "";
		document.form1.showtab.value = "";
		document.form1.recname.value = "briefIssue";
		document.form1.xsl.value = "/Numismatics/briefIssue.xsl";
		document.form1.id.value = "";
		document.form1.query.value = "SELECT IssueID FROM IssueAttributes WHERE AttributeID=" + id;
		document.form1.query2.value = ""
		send();
	}
	
	function showCoinIds(){
		document.form1.xml.value = "";
		document.form1.debug.value = "";
		document.form1.showtab.value = "";
		document.form1.recname.value = "coinId";
		document.form1.xsl.value = "/Numismatics/coinIds.xsl";
		document.form1.id.value = "";
		document.form1.query.value = "select coinid, '' as dummy from coins";
		document.form1.query2.value = "";
		document.form1.app.value="1";
		send();
	}
	
	function showConfig(){
		document.form1.showtab.value = "1";
		send();
	}
	
	function send(){
		//document.form1.xsl.value = "";
		//document.form1.debug.value = "1";
		win = window.open("", "numismaticsResults");
		document.form1.target= "numismaticsResults";
		document.form1.submit();
		win.focus();
	}
	
	var newId = "";
	
	function resetId(){newId = ""; }
	
	function checkId(id, state, region){
		oldId = newId;
		newId = id;
		if (newId != oldId){ 
			s = "<option value='" + id + "'>";
	      if (state != "") s += state +  "&#160;";
	      if (region != "") s += region;
	      s += "</option>";
	      document.write(s);
   	}
		
	}
	
	function showCoinIds(){
		document.form1.xml.value = "";
		document.form1.debug.value = "";
		document.form1.showtab.value = "";
		document.form1.recname.value = "coinId";
		document.form1.xsl.value = "/Numismatics/coinIds.xsl";
		document.form1.id.value = "";
		document.form1.query.value = "SELECT CoinID, CoinId as coin FROM Coins";
		document.form1.query2.value = ""
		send();
	}
