var d = "Suchwort(e) hier eingeben";


/*
	value="Suchbegriff"
	onFocus="if(this.value=='Suchbegriff') this.value=''"
	onBlur="if(this.value=='') this.value='Suchbegriff'"
*/

function wakeQuery() {
	var query = id('q');

	if (query.value == d) {
		query.value = "";
		query.className = "active";
	}
}

// whistle
function resetQuery() {
	var query = id('q');

	if (query.value == "") {
		query.className = "inactive";
		query.value = d;
	}
}

function getQueryStrVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  }
	return null;
}

// don't need an entire framework just for this
function id(i) { return document.getElementById(i); }

function setupQuery() {
	var query = id("q");
	var qs = getQueryStrVariable('q');

	query.value = qs;

	if ((query.value == "") || (query.value == "null")) {
		query.value = d;
//		window.location.href = 'index.php';
	} else if (query.value != d) {
		query.className = "active";

		// since there's query data...
		doSearch();
	}
}

function doSearch() {
	var query = id("q");
	url = "";

	// search only if there is something to search with
	if ((query.value.length > 0) && (query.className == "active") && (query.value != d)) {
		// set up rights string, works if user hits "go" or a tab.
		url = 'index.php?op=search&q=' + query.value;
		window.location.href = url;
		}
	else {
		resetQuery();
	}
	return false;
}

