var NS4 = (document.layers) ? true : false;
var IE4 = (document.all) ? true : false;
var NS4MAC = NS4 && (navigator.appVersion.indexOf("Macintosh") > -1);

var size = 8;

// select index style:
//   1. Standard
//      Selects an option if a substring match is found.
//      If no match is found, selects the closest match
//      from the bottom. For example, if the string is
//      "cz", it will match "cy...", "cx...", etc.
//   2. Explorer
//      Simulates the new index in Internet Explorer's
//      help. If the string is empty, selects the first
//      option. Otherwise, if no substring match is found
//      the selection doesn't change.
var style = 1;
var lasttime = 0;
var str = "";
var active = false;

function select(list, i) {
  if (list.selectedIndex != i) 
  list.selectedIndex = i;
}

function getCurrentTimeMillis() {
	var now = new Date();
	return now.getHours()*60*60*1000 + now.getMinutes()*60*1000 + now.getSeconds()*1000 + now.getMilliseconds();
}

function checkKey() {
  if (!active) return;
  var form = document.forms["form_provbomull"];
  var list = form.farg;
  var t = getCurrentTimeMillis();
  if (t - lasttime > 2000) str = "";
  lasttime = t;
  if (document.layers)
     key = e.which;
  else
     key = window.event.keyCode;
  if (key < 32) return;
  if (key == 190) key = 46;
  if (key >= 96 && key <= 105) key = key - 48;
  str =  str + String.fromCharCode(key);
 
  for (var i = 0; i < list.options.length; ++i) {
    if (list.options[i].text.toUpperCase().indexOf(str) == 0) {
      select(list, i);
      return;
    }
  }
  if (style == 1) {
    for (i = list.options.length - 1; i >= 0; --i) {
      if (str > list.options[i].text.toUpperCase()) {
        select(list, i);
        return;
      }
    }
    select(list, 0);
  }
}


function startsb() {
  if (NS4) document.captureEvents(Event.KEYUP);
  document.onkeyup = checkKey;
  document.forms["form_provbomull"].farg.focus();
}

// Inhibit the add-button when user have changed Item
var addActive = true;

function changeItem() {
	if (document.images)
	{
	  preload_image = new Image(25,25); 
	  preload_image.src="../../images/ajax-loader.gif"; 
	}

	addActive = false;
	if ( T = document.getElementById('btnAddSpan') ) {
		T.innerHTML = "&nbsp;&nbsp;<img src='../../images/ajax-loader.gif' />";
	}
	
	document.form_provbomull.action.value = 'load_vkod';
	document.form_provbomull.submit();
}

function addItem() {
	if (document.images)
	{
	  preload_image = new Image(25,25); 
	  preload_image.src="../../images/ajax-loader.gif"; 
	}

	if (addActive) {
		//document.form_provbomull.add.value = true;
		document.form_provbomull.action.value = 'add';
	}

	document.form_provbomull.submit();

	if ( T = document.getElementById('btnAddSpan') ) {
		T.innerHTML = "&nbsp;&nbsp;<img src='../../images/ajax-loader.gif' />";
	}

	/*document.getElementById('typ').style.display = 'block';
	document.getElementById('typ').disabled = true;*/
	
}
