function BrowserCheck() {
    var b = navigator.appName;
    if (b == "Netscape") this.b = "NS";
    else if (b == "Microsoft Internet Explorer") this.b = "IE";
    else this.b = b;
    this.v = parseInt(navigator.appVersion);
    this.NS = (this.b == "NS" && this.v>=4);
    this.NS4 = (this.b == "NS" && this.v == 4);
    this.NS5 = (this.b == "NS" && this.v == 5);
    this.IE = (this.b == "IE" && this.v>=4);
    this.IE4 = (navigator.userAgent.indexOf('MSIE 4')>0);
    this.IE5 = (navigator.userAgent.indexOf('MSIE 5')>0);
    if (this.IE5 || this.NS5) this.VER5 = true;
    if (this.IE4 || this.NS4) this.VER4 = true;
    this.OLD = (! this.VER5 && ! this.VER4) ? true : false;
    this.min = (this.NS||this.IE);
}
is = new BrowserCheck();
var isNN4up = (window.Event)? true : false;

function keyp(e,from,to)
{

    var acceptedkey = false;

    if (isNN4up) {
        var whichKey = e.which;
        if (whichKey == 8 || whichKey == 0)
            acceptedkey = true;
    }
    else
    { var whichKey = window.event.keyCode; }

    return ((whichKey >= from && whichKey <= to)|| acceptedkey);
}
function key_press_event_handler(e,kmezo)
{
     if (isNN4up)
     {
        var whichKey = e.which;
     }
     else
     {
        var whichKey = window.event.keyCode;
     }
     var realKey = String.fromCharCode(whichKey);
     if (whichKey=="13"){
         kmezo.focus()
     }

}
function autoTab(input,len, e) {
         var keyCode = (is.NS) ? e.which : e.keyCode;
         var filter  = (is.NS) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
         if(input.value.length >= len ){
            input.value = input.value.slice(0, len);
            input.form[(getIndex(input)+1) % input.form.length].focus();
         }

         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 maxLength(field,maxChars)
{
      if(field.value.length >= maxChars) {
         event.returnValue=false;
         return false;
      }
}

function maxLengthPaste(field,maxChars)
{
      event.returnValue=false;
      if((field.value.length +  window.clipboardData.getData("Text").length) > maxChars) {
        return false;
      }
      event.returnValue=true;
}

function move(fbox,tbox,hidden) {
        var i = 0;
        if(fbox.value != "") {
                var no = new Option();
                no.value = hidden.value;
                no.text = fbox.value;
                tbox.options[tbox.options.length] = no;
                fbox.value = "";
                hidden.value="";
           }
}

function remove(tbox,box,hidden) {
        for(var i=0; i<box.options.length; i++) {
                if(box.options[i].selected && box.options[i] != "") {
                        tbox.value= box.options[i].text;
                        hidden.value=box.options[i].value;
                        box.options[i].value = "";
                        box.options[i].text = "";
                }
        }
        BumpUp(box);
}

function BumpUp(abox) {
        for(var i = 0; i < abox.options.length; i++) {
                if(abox.options[i].value == "")  {
                        for(var j = i; j < abox.options.length - 1; j++)  {
                                abox.options[j].value = abox.options[j + 1].value;
                                abox.options[j].text = abox.options[j + 1].text;
                        }
                        var ln = i;
                        break;
                   }
        }
        if(ln < abox.options.length)  {
                abox.options.length -= 1;
                BumpUp(abox);
           }
}

function put(fbox,tbox,button,hidden){


        if (button.value=="<"){
            remove(fbox,tbox,hidden);
            button.value='>';
        }else{
            move(fbox,tbox,hidden);
            button.value='<';
        }
}
