// Copyright (c) 2000-2001 LUGNET.  All rights reserved.
// http://www.lugnet.com/

function UrlEscape(u) {
	// It _sure would be nice_ simply to use the built-in escape() function
	// for this, but escape() only encodes [^\*\+\-\.\/0-9A-Z_a-z].  In other
	// words, it fails to encode "+" to "%2B"!!!  :-(  Other than that, it
	// would've been great!  (I guess escape() wasn't specifically designed
	// for URL-style encoding...bummer.)   --TSL

	var e = "";
	var i;
	for (i = 0; i < u.length; i++) {
		var c = u.charAt(i);
		e += (c == "+")?  "%2B" : (c == " ")?  "+" : escape(c);
	}
	return e;
}

function UrlPaste(u,s,q) {
	return (q == "")?  u : u+s+q;
}

function IsNumber(q) {
	var i;

	return parseInt(q, 10) + "" == q;

	if (q == "") return false;
	for (i = 0; i < q.length; i++) {
		if (!isDigit(q.charAt(i)))
			return false;
	}
	return true;
}

function MetaSearch(form) {
	var sel = form.scope.options[form.scope.selectedIndex].value;
	var cat = form.category.value;
	var q = UrlEscape(form.query.value);
	var u = "";

	if (sel == "QuickSet") {
		u = UrlPaste("http://www.lugnet.com/quickset/search.cgi", "?q=", q);
		window.open(u, "_blank",
			"width=" + 220 + ",height=" + 280 +
			"toolbar=0,location=0,directories=0,status=0,menubar=0," +
			"scrollbars=1,resizable=1,copyhistory=0");
		return false;  // Cancel form submission
	} else if (sel == "SetGuide") {
		u = UrlPaste("http://guide.lugnet.com/set/", IsNumber(q)? "":"?q=", q);
	} else if (sel == "PartsRef") {
		u = UrlPaste("http://guide.lugnet.com/partsref/", "search.cgi?q=", q);
	} else if (sel == "News") {
		u = UrlPaste("http://news.lugnet.com/", "?q=", q);
	} else if (sel == "NewsRel") {
		u = UrlPaste("http://news.lugnet.com" + cat, "?q=", q);
	}

	if (u != "") {
		document.location.href = u;
		return false;  // Cancel form submission
	} else {
		return true;  // Proceed with form submission
	}
}

