

//
// Search
//
var Search = {

	// init
	init: function() {

		// get it
		var box = d.getElementById('searchBox');

			// add the event
			addEvent( box, 'keyup', Search.suggest, false);
			addEvent( box, 'blur', function() { setTimeout("Search.hideTips()",2000) }, false);
	
	},

	// Suggest
	suggest: function() {

		// get it
		var term = d.search.term.value;
		var bottom = d.getElementById('searchBottom');

		// check for any text other than searc
		if ( term ) {

			// tell them about it
			bottom.innerHTML = "<span style='color:#888'>Loading Data...</span>";

			// run the load
			getXML("http://www.solid-bilt.com/lib/ajax.pl?do=search;term="+term,Search.giveSuggest);

		}

	},

	giveSuggest: function() {

		// bottom
		var bottom = d.getElementById('searchBottom');
		
		// haha... get it from the dom
		if ( req.readyState == 4 && req.status == 200 ) {

			// set the timeout to close it
			setTimeout("Search.hideTips()",20000);

			// get doc
			var dom = req.responseXML;

				// how manuy
				var results = dom.getElementsByTagName('result');

				// number of results
				var num = dom.getElementsByTagName('total')[0].getAttribute('num');

				// number of result
				if ( num > 0 ) {

					// if there's a right
					// hide it
					if ( d.getElementById('c-right') ) {
						d.getElementById('c-right').style.visibility = "hidden";
					}
					
					// html
					var html  = " <h1> Suggestions </h1> ";
						html += "<ul class='list'>";

						// do it
						for ( var i = 0; i < results.length; i++ ) {
							// get stuff
							var id = results[i].getAttribute('id');
							var url = results[i].getAttribute('url');
							var ifor = results[i].getAttribute('for');
							var name = dom.getElementsByTagName('result')[i].firstChild.data;
							// html it
							html += "<li> " + ifor + " - <a href='"+url+"'>"+name+"</a></li>";
						}

					// end
					html += "</ul>";

					// give it a class name
					bottom.className = "tipsBox";

					// set it
					bottom.innerHTML = html;

				}
				else {
					bottom.innerHTML = "Sorry... No Results";
				}

		}

	},

	// tips
	ShowTips: function() {

		// get tips Id
		var box = d.getElementById('searchBottom');

			// if there's a right
			// hide it
			if ( d.getElementById('c-right') ) {
				d.getElementById('c-right').style.visibility = "hidden";
			}

		// do it
		var html  = " <h1> Search Tips </h1> ";
			html += " <ul class='list'> ";
			html += "  <li> <b>Search Suggest:</b> As you type, suggestions for you search will be displayed. To perform a search using that suggestion, just click it. </li> ";
			html += "  <li> <b>Review My Order:</b> To review your order, enter your order number in the search box. </li>";
			html += " </ul> <br/>";
			html += " <a href='javascript:;' onclick='Search.hideTips();'>close [x]</a> ";

		// change it's class name
		box.className = "tipsBox"

		// html
		box.innerHTML = html;

	},

	hideTips: function() {
	
		// get tips Id
		var box = d.getElementById('searchBottom');	

		var html  = " <a href='javascript:;' onclick='Search.ShowTips()'>Tips</a> | ";
			html += " <a href='about-us/search.pl'>Advanced Search</a> ";

		// take away class
		box.className = "";

		// html
		box.innerHTML = html;

			// if there's a right
			// show it
			if ( d.getElementById('c-right') ) {
				d.getElementById('c-right').style.visibility = "visible";
			}

	}


}

	// add an event
	addEvent(window,'load',Search.init,false);