/*
* Copyright 2002-2006 The Apache Software Foundation or its licensors,
* as applicable.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
 * search-engine script - when included in a html file and called from a form text field, will set the value of this field to ""
 * if the text value is still the standard value.
 *
 * Typical usage:
 * <script type="text/javascript" language="JavaScript" src="getBlank.js"></script>
 * <input type="text" id="query" value="Search the site:" onFocus="getBlank (this, 'Search the site:');" onBlur="getBlank (this, 'Search the site:');"/>
 */
<!--
function searchEngine(id,resultDiv,history){
  var action=$("searchEngineSearchPrefix"+id);
  var actionString = xCleaner(action.value);
  var searchString = $("searchEngineQ"+id).value;
  var provider = action.options[action.selectedIndex].text;
  var url = actionString+searchString;
  if (actionString=="http://?url=")
   url = searchString;
  var resultResponse=$(resultDiv);
  var popup= $("popup"+id);
  var historyOnly="";
  if(history=='true'){
  historyOnly = $("historyOnly"+id);
  }
  if(!historyOnly.checked){
   // only for leave mode
   if(!popup.checked){
      resultResponse.innerHTML='<strong>Stand by, redirecting to <a href="'+url+'">'+provider+' - '+searchString+'</a></strong>';
      location=url;
   }else{
      openWindow(provider+searchString,url);
   }
  }
  // only if in history mode
  if(history=='true'){
    resultResponse.innerHTML= resultResponse.innerHTML+'<p class="seachEngineLink"><a href="'+url+'">'+provider+' -> '+searchString+'</a></p>';
    createCookie("searchHistory", resultResponse.innerHTML, 365);
  }
}

function resetHistory(resultDiv){
  $(resultDiv).innerHTML="";
}

function resetInput(resultDiv){
  $(resultDiv).value="";
}

function xCleaner(toClean){
  var clean = toClean.replace("&amp;",'&');
  return clean;
}

function reportError(request){
  alert('Sorry. There was an error.');
}

function openWindow(name,url){
settings=
"toolbar=yes,location=yes,directories=yes,"+
"status=no,menubar=no,scrollbars=yes,"+
"resizable=yes,width=600,height=300";
newWindow=
window.open(url,name,settings); 
}

/*CookieStuff*/
function createCookie(name, value, days) {
	var date = new Date();
	date.setTime(date.getTime() + (days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function initSearchHistory(resultResponse,history){
  var cookie = readCookie("searchHistory");
  if (cookie==null && history=='true')
    createCookie("searchHistory", "", 365);
  else if (cookie!=null && history=='true')
    $(resultResponse).innerHTML=cookie;
}
//-->

