function main() {
  createDropDown("modelnum");
	}

// This function creates the master dropdown list to select search by part # or model #, etc.
function createDropDown(option) {
	switch( option ) {
    case "partnum":
			txt = "<select id=\"list\" onchange=\"createDropDown(document.getElementById('list').value)\">\n";
      txt = txt + "<option selected=\"selected\" value=\"partnum\">Search by Part Number</option>\n";
      txt = txt + "<option value=\"modelnum\">Search by Model</option>";
	    txt = txt + "</select>\n";
	    txt = txt + "<p style=\"margin-top: 15px; text-align: center\">Enter a part number to check pricing and availability.</p>\n";
			txt = txt + "<div class=\"container\">\n";
			txt = txt + "<div class=\"floatform\" style=\"text-align: right\">\n";
			txt = txt + "<b>Part Number:</b>\n";
			txt = txt + "</div>\n";
			txt = txt + "<div class=\"floatform\">\n";
			txt = txt + "<input type=\"text\" maxlength=\"20\" onKeyUp=\"autoComplete(event,'box','partnum','part','partnum')\" id=\"partnum\" size=\"20\"/>\n"; 
			txt = txt + "<div id=\"box\"></div>";
			txt = txt + "</div>\n";
	    txt = txt + "<div class=\"floatform\" style=\"text-align: left\">\n";
			txt = txt + "<input type=\"button\" value=\"Search\" onclick=\"partSearch(document.getElementById('partnum').value,'part','scripts/partsquery.php')\" />\n";
			txt = txt + "</div>\n";
			txt = txt + "</div>\n";
      break;
    case "modelnum":
		  txt = "<select id=\"list\" onchange=\"createDropDown(document.getElementById('list').value)\">\n";
      txt = txt + "<option value=\"partnum\">Search by Part Number</option>\n";
      txt = txt + "<option selected=\"selected\" value=\"modelnum\">Search by Model</option>";
	    txt = txt + "</select>\n";
	    txt = txt + "<p style=\"margin-top: 15px; text-align: center\">Enter a model number to check pricing and availability.</p>\n";
	    txt = txt + "<div class=\"container\">\n";
			txt = txt + "<div class=\"floatform\" style=\"text-align: right\">\n";
			txt = txt + "<b>Model Number:</b>\n";
			txt = txt + "</div>\n";
			txt = txt + "<div class=\"floatform\">\n";
			txt = txt + "<input type=\"text\" maxlength=\"20\" onKeyUp=\"autoComplete(event,'box','partnum','model','partnum')\" id=\"partnum\" size=\"20\"/>\n";
			txt = txt + "<div id=\"box\"></div>";
			txt = txt + "</div>\n";
	    txt = txt + "<div class=\"floatform\" style=\"text-align: left\">\n";
			txt = txt + "<input type=\"button\" value=\"Search\" onclick=\"partSearch(document.getElementById('partnum').value,'model','scripts/partsquery.php')\" />\n";
			txt = txt + "</div>\n";
			txt = txt + "</div>\n";
			break;
  }
	updateHTML(txt, 'searchmethod')
}

// This is the main search function call to load the PHP search script
function partSearch(str1, type, script) {
 	xmlHttp=GetXmlHttpObject();
 	if (xmlHttp==null) {
 		alert ("Browser does not support HTTP Request");
 		return;
  } 
	
	// Hide the autocomplete box
	box('0');
	
	// Convert to uppercase.
	str1 = str1.toUpperCase();
	
  // If any fields are blank, does not continue.
  if (!(validate_required(str1))) {
 		return;
	}

	script=script+"?id="+str1;
	script=script+"&type="+type;
	script=script+"&sid="+Math.random();
  xmlHttp.onreadystatechange = function() {stateChanged("txtHint", xmlHttp);}
	xmlHttp.open("GET",script,true);
	xmlHttp.send(null);
}

function validate_required(id) {
 	// Verify the field is not blank
	if (id==null || id=="") {
		document.getElementById("txtHint").innerHTML = "<b>A part number must be entered!</b>";
		return false;
  }
	return true;			
}

function updateHTML(txt, div) {
	document.getElementById(div).innerHTML=txt;
}

function submitEnter(e,type) {
  var keycode;
  if (window.event) keycode = window.event.keyCode;
  else if (e) keycode = e.which;
  else return true;
  if (keycode == 13) {
	  box('0');
		if (type == 'part') {
      partSearch(document.getElementById('partnum').value,'part','scripts/partsquery.php')
			}
		else {
      partSearch(document.getElementById('partnum').value,'model','scripts/partsquery.php')
			}		
		return false;
  }
  else
    return true;
}
