/*
// +----------------------------------------------------------------------+
// | Copyright (c) 2004 Bitflux GmbH                                      |
// +----------------------------------------------------------------------+
// | 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.                       |
// +----------------------------------------------------------------------+
// | Author: Bitflux GmbH <devel@bitflux.ch>                              |
// +----------------------------------------------------------------------+

*/


var liveSearchReq = false;
var t = null;
var liveSearchLast = "";
var scriptloaded = 0;

function liveSearchHideDelayed( ms ) {
	window.setTimeout("liveSearchHide()", (ms == undefined || ms == 0) ? 400 : undefined);
}

function liveSearchHide() {
	document.getElementById("LSResult").style.display = "none";
	//speziell fuer Livesuche ausgeblendet:
	var hm = document.getElementById("hidemely1");
	if (hm != null) {hm.style.visibility = "visible"};
	var hm = document.getElementById("cgiad");
	if (hm != null) {hm.style.visibility = "hidden"};
	sh_sel("visible", 0, document.getElementById("liveSearchResults") );
}

function liveSearchStart() {
	if (t) {
		window.clearTimeout(t);
	}
	t = window.setTimeout("liveSearchDoSearch()",0); // vorher 200
}

function liveSearchDoSearch() {
	if (liveSearchLast != document.forms.search.companysearchtextsmall.value) {
		if (liveSearchReq && liveSearchReq.readyState < 4) {
			liveSearchReq.abort();
		}
		if ( document.forms.search.companysearchtextsmall.value == "") {
			liveSearchHide();
			return false;
		}

		try {
			liveSearchReq=new ActiveXObject("Msxml2.XMLHTTP")
		} catch(e) {
			try {
				liveSearchReq=new ActiveXObject("Microsoft.XMLHTTP")
			} catch(oc) {
				liveSearchReq=null
			}
		}
		if (!liveSearchReq && typeof XMLHttpRequest != "undefined") {
			liveSearchReq=new XMLHttpRequest()
		}
		if(!liveSearchReq) { return }
	
		liveSearchReq.onreadystatechange= liveSearchProcessReqChange;
		 var myUrlVariable = 'http://'+location.hostname+"/wp-content/themes/financial/companysearch.php?companysearchtext=" + document.forms.search.companysearchtextsmall.value
		liveSearchReq.open("GET", myUrlVariable);
		liveSearchLast = document.forms.search.companysearchtextsmall.value;
		liveSearchReq.send(null);
	}
}

function liveSearchProcessReqChange() {
	
	if (liveSearchReq.readyState == 4) {
		hide_em('hidden');
	        var hm = document.getElementById("hidemely1");
		if (hm != null) {hm.style.visibility = "hidden"};
		var hm = document.getElementById("cgiad");
		if (hm != null) { hm.style.visibility = "hidden" };
		sh_sel("visible", 1, document.getElementById("liveSearchResults") );
		var res = document.getElementById("LSResult");
		res.style.display = "block";
		res.innerHTML = '<div>'+liveSearchReq.responseText+'</div>';
		window.status = "Fertig";
	}
}


function hide_em(stat, elem, menu) {
  chk_pos = 1; 
  over_div = menu ? menu : document.getElementById("liveSearchResults");
  if ( !menu && (document.getElementById("liveSearchResults").style.visibility == "hidden" || !document.getElementById("liveSearchResults").style.visibility) ) { chk_pos = 0; }
  sh_sel(stat, chk_pos, over_div);
  for ( i=0;i<=5;i++ ) {
    if ( document.getElementById("hidemely" + i) ) {
      if ( elem ) {
        while ( elem != null ) {
          if ( elem.id && elem.id.match(/hidemely/) ) { return; }
          elem = elem.parentNode;
        }
      }
      if ( chk_pos ) {
        if ( check_liveSearchResults(document.getElementById("hidemely" + i), over_div) ) { document.getElementById("hidemely" + i).style.visibility = stat; }
        else { document.getElementById("hidemely" + i).style.visibility = stat == "hidden" ? "visible" : "hidden"; } 
      }
      else { document.getElementById("hidemely" + i).style.visibility = "visible"; }
    }
  }
}

function sh_sel(stat, chk_pos, over_div) {
	var agent = navigator.userAgent.toLowerCase();
	var ie_found = agent.indexOf( 'msie' );
	if ( ie_found > -1 && 0+agent.substring( ie_found+5, ie_found+6 ) <7 ) {	//IE bis Version 6.x
		var sel = document.getElementsByTagName("select");
		for (var i=0;i<sel.length;i++) {
			if ( chk_pos ) {
				if ( check_overdiv(sel[i], over_div) ) { 
					sel[i].style.visibility = stat; 
				}else{ 
					sel[i].style.visibility = stat == "hidden" ? "visible" : "hidden"; 
				}  
			}else{ 
				sel[i].style.visibility = "visible"; 
			}
		}
	}
}

function liveSearchStartExt() { 
    //if (scriptloaded) {
        liveSearchStart();
    //}
};
function getObject(name) {
  if(document.getElementById) return document.getElementById(name);
  else if(document.all) return document.all[name];
  else if(document.layers) return document.layers[name];
}
