
function autoTab(input,len, e) {
  var keyCode = e.keyCode; 
  var filter = [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode)) {
    input.value = input.value.slice(0, len);
    input.value = parseInt(input.value);
    if(input.value > 255) input.value = 255;
    if(input.value < 1 || input.value == 'NaN') input.value = 0;
    next = (getIndex(input)+1) % input.form.length;
    if (next > 8) next = 1;
    //input.form[next].focus();
    if (next < 5) input.form[next].select();
  }

  function containsElement(arr, ele) {
    var found = false, index = 0;

    while(!found && index < arr.length)
    if(arr[index] == ele)
       found = true;
    else
       index++;
    return found;
  }

  function getIndex(input) {
    var index = -1, i = 0, found = false;
    while (i < input.form.length && index == -1)
    if (input.form[i] == input) index = i;
    else i++;
    return index;
  }
  return true;
}

function cidrSubmit(field) {
   form = document.getElementById('cidrForm');
   form.fieldId.value = field;
   form.submit();
}

function cidrUpdate(ip_oct1, ip_oct2, ip_oct3, ip_oct4, bits, mask_oct_inv, network, range) {
   form = document.getElementById('cidrForm');
   form.ip_oct1.value = ip_oct1;
   form.ip_oct2.value = ip_oct2;
   form.ip_oct3.value = ip_oct3;
   form.ip_oct4.value = ip_oct4;
   form.mask_oct[bits].selected = '1';
   form.mask_bits[bits].selected = '1';
   form.addresses[bits].selected = '1';
   form.subnets[bits].selected = '1';
   form.mask_oct_inv.value = mask_oct_inv;
   form.network.value = network;
   form.range.value = range;

}

