function showContent(a){
  var e=$(a); if(!e)return true;
  e.style.display="block";
  return true;
}

function hiddenContent(a){
  var e=$(a); if(!e)return true;
  e.style.display="none"
  return true;
}

function lookup(search) {

	if ($('where_search').value=='fulltext') return;

	if(search.length == 0) {

    hiddenContent('suggestions');
    
    // For future - Mootols 2.12
		// $('suggestions').hide();
	} else {
	
    var jSonRequest = new Json.Remote(
        "/ajax-devices.php", {
          onComplete: function(data) {
            if(data.ERROR)
            { alert(data.ERROR) }            
            if(data.response && data.response.length >0) {				        
               showContent('suggestions');
               $('autoSuggestionsList').innerHTML=data.response;
            }
    }}).send({'search': ""+search+""});

    // For future - Mootols 2.12
		//$.post("/ajax-devices.php", {search: ""+search+""}, function(data){
		/*	if(data.length >0) {
				$('suggestions').show();
				$('autoSuggestionsList').html(data);
			}*/
		//});
	}
}
	
function fill(thisValue) {
  // For future - Mootols 2.12
	// $('search').val(thisValue);
	
	if ($('where_search').value=='fulltext') return;
	
	if(thisValue) 
	{
    $('search').value = thisValue;
		var forms = document.getElementsByTagName('form');
		forms = $("top_search");
		//forms[0].where_search.value = "beginnings";
		forms.submit();
	}

  // For future - Mootols 2.12	
	// setTimeout("$('suggestions').hide();", 200);	
	
  setTimeout("hiddenContent('suggestions');", 200);		
}

function getElementHeight(Elem) {
	if (typeof(ns4) != "undefined") {
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (typeof(op5) != "undefined") { 
			xPos = elem.style.pixelHeight;
		} else {
			xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}

function setElementHeight(Elem,height) {
	if (typeof(ns4) != "undefined") {
		var elem = getObjNN4(document, Elem);
		elem.clip.height = height + "px";
	} else {
		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		if (typeof(op5) != "undefined") { 
			xPos = elem.style.pixelHeight = height + "px";
		} else {
			xPos = elem.style.height = height + "px";
		}
		return xPos;
	} 
}

function strpos(haystack, needle, offset) {

  if (!Array.prototype.indexOf) {  
      Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {  
          "use strict";  
          if (this === void 0 || this === null) {  
              throw new TypeError();  
          }  
          var t = Object(this);  
          var len = t.length >>> 0;  
          if (len === 0) {  
              return -1;  
          }  
          var n = 0;  
          if (arguments.length > 0) {  
              n = Number(arguments[1]);  
              if (n !== n) { // shortcut for verifying if it's NaN  
                  n = 0;  
              } else if (n !== 0 && n !== Infinity && n !== -Infinity) {  
                  n = (n > 0 || -1) * Math.floor(Math.abs(n));  
              }  
          }  
          if (n >= len) {  
              return -1;  
          }  
          var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);  
          for (; k < len; k++) {  
              if (k in t && t[k] === searchElement) {  
                  return k;  
              }  
          }  
          return -1;  
      }  
  }  

  var i = (haystack+'').indexOf(needle, (offset || 0));
  return i === -1 ? false : i;
}

function showSelected(val,lang){
  document.getElementById
  if (lang=="sk") var please = "Vyberte prosím...";
  if (lang=="en") var please = "Please select...";
  
  if (strpos(val, "BPx")===0 && strpos(val, "SP2")===false){
    document.getElementById("selectedResult").innerHTML = "<select name=\"wanted_prog\"><option value=\"\">"+please+"</option><option value=\"\">-------------------------</option><option value=BP2>BeeProg2</option><option value=BPP>BeeProg+</option></select>";
  }
  else if (strpos(val, "BPxSP2_SP")===0) {
    document.getElementById("selectedResult").innerHTML = "<select name=\"wanted_prog\"><option value=\"\">"+please+"</option><option value=\"\">-------------------------</option><option value=BP2>BeeProg2</option><option value=BPP>BeeProg+</option><option value=SP2>SmartProg2</option></select>";
  }
  else if (strpos(val, "SP2")===0 && strpos(val, "BPx")===false) {
    document.getElementById("selectedResult").innerHTML  = "<select name=\"wanted_prog\"><option value=\"\">"+please+"</option><option value=\"\">-------------------------</option><option value=SP2>SmartProg2</option></select>";
  }
  else {
    document.getElementById("selectedResult").innerHTML  = "";
  }
}
