// Does some basic client-side validation of a shortcut name
// (This function was not authored by me)
function validateShortcut(shortcut) {
	prohibited = [ "http://", "https://", "/", "?", "=" ];
	if (shortcut != "" && shortcut.length < 3 ) {
		alert("Shortcuts must be at least " + 3 + " characters");
		return false;
	}
	for (var i=0; i < prohibited.length; i++) {
		bad = prohibited[i];
		if (shortcut.indexOf(bad) != -1) {
			alert("Shortcuts cannot contain \"" + bad + "\"");
			return false;
		}
	}
	return true;
}

// Remembers the last outgoing query to prevent unnecessry outgoing calls
var LAST_SEARCH_ = null;

// Call when a search/suggestion should be updated
function submitQuery() {
  var query = document.getElementById('query');
  var popular = document.getElementById('popular');
  var div = document.getElementById('searchresults');
  if (query && popular && div) {
    var request = popular.checked ? "popular=true&query=" : "query=";
    request += query.value;
    var html = '<iframe frameborder=0 src="/content.py?mode=QUERY&' + 
        request + '"/>';
    if (LAST_SEARCH_ != html) {
      LAST_SEARCH_ = html;
      div.innerHTML = html;
    }      
  }
}


