// JavaScript Document
// Generate Search Form
function fGen_Search_Form (bVertical, sSite) {
  var CtryList = {'':'all countries',
	  			  AU:'Australia', 
            	  AT:'Austria', 
		    	  CA:'Canada', 
		   		  CN:'China', 
		    	  JP:'Japan', 
		          MX:'Mexico',
				  NZ:'New Zealand',
		    	  ZA:'South Africa',
		    	  CH:'Switzerland', 
		    	  US:'United States'};
  var MetalList = {'':'all metals',
	  			  340:'Platinum', 
	  			  341:'Gold', 
	  			  342:'Silver', 
	  			  343:'Palladium'}; 
  var WeightList = {'':'all weights',
                    Ounces:{
					  338:'1,000 Ounce',
					  319:'100 Ounce',
					  318:'12 Ounce',
					  317:'10 Ounce',
					  316:'5 Ounce',
					  315:'2 Ounce',
					  169:'1 Ounce',
					  170:'1/2 Ounce',
					  171:'1/4 Ounce',
					  172:'1/10 Ounce',
					  314:'1/20 Ounce',
					  313:'1/25 Ounce'
					},
					Grams:{
					  332:'10 Kilo',
					  320:'1 Kilo',
					  321:'1/2 Kilo',
					  322:'100 gm',
					  336:'10 gm',
					  337:'5 gm',
					  323:'2.5 gm',
					  324:'1 gm'
					}};
				  
		   
 // get the current URL
 var url = window.location.toString();
 //get the parameters
 url.match(/\?(.+)$/);
 var params = RegExp.$1;
 // split up the query string and store in an
 // associative array
 var params = params.split("&");
 var queryStringList = {};
 
 for(var i=0;i<params.length;i++)
 {
 	var tmp = params[i].split("=");
 	queryStringList[tmp[0]] = unescape(tmp[1]);
 }

  document.write ("<div id='search'>");
    document.write ("<form action='" + sSite + "mq.asp' method='get' name='newsearch' id='newsearch' onSubmit=''>");
	
//  country
      document.write ("<select name='ctry' id='ctry'>");
		
	  for (var i in CtryList) {
		document.write ("<option value='" + i + "'");
		  if (queryStringList["ctry"] == i) document.write (" selected='selected'");
		document.write (">" + CtryList[i] + "</option>");  
	  };

      document.write ("</select>")
	  
	  if (bVertical) document.write ("<br/>") 
	  else document.write ("&nbsp;");

//  metal
      document.write ("<select name='metalcat' id='metalcat'>");

	  for (var i in MetalList) {
		document.write ("<option value='" + i + "'");
		  if (queryStringList["metalcat"] == i) document.write (" selected='selected'");
		document.write (">" + MetalList[i] + "</option>");  
	  };

      document.write ("</select>")

//      document.write ("<option value=''");
//	  	if (queryStringList["ctry"] = "") document.write (" selected='selected'");
//        document.write ("></option>");
	  
	  if (bVertical) document.write ("<br/>") 
	  else document.write ("&nbsp;");

// weight
      document.write ("<select name='weight' id='weight'>");
	  for (var i in WeightList) {
		 if (i == "") {
		document.write ("<option value='" + i + "'");
		  if (queryStringList["weight"] == i) document.write (" selected='selected'");
		document.write (">" + WeightList[i] + "</option>");
		 } else {
			 document.write ("<optgroup label='" + i + "'>");
			 for (var j in WeightList[i]) {
		       document.write ("<option value='" + j + "'");
		          if (queryStringList["weight"] == j) document.write (" selected='selected'");
		          document.write (">" + WeightList[i][j] + "</option>");
			  };
			 document.write ("</optgroup>");												  
		 }
	  };

      document.write ("</select>")
	  
	  if (bVertical) document.write ("<br/>") 
	  else document.write ("&nbsp;");

//year
      document.write ("<label>Date:&nbsp;</label><input name='modyr' id='modyr' type='text' size='8' maxlength='8' value='")
	  if (! queryStringList["modyr"] == "undefined") 
	    document.write (queryStringList["modyr"]);
	  document.write ("'>");
	  
	  if (bVertical) document.write ("<br/>") 
	  else document.write ("&nbsp;&nbsp;");
	  
//new items
      document.write ("<input name='show' id='show' type='checkbox' value='3'><label>&nbsp;New Coins</label>");

	  if (bVertical) document.write ("<br/>") 
	  else document.write ("&nbsp;");

//search button
      document.write ("<input name='gosearch' id='gosearch' type='image' onClick='document.newsearch.submit();' src='/images/spacer.gif' class='search_button' alt='Go Search' align='absmiddle'><span class='search_text'>[SEARCH]</span>");
	  
    document.write ("</form>")
  document.write ("<!-- #search --></div>");
};
