function setFocus() {
  window.focus();
  elementNo=0
  thisForm = document.forms[0];
  if (thisForm != null) {
    thisElement = thisForm.elements[0]
    if (thisElement!=null) {
      while (thisElement!=null & thisElement.type=="hidden") {
        elementNo++;
        thisElement = thisForm.elements[elementNo];
      }
      if (thisElement!=null) {
        thisElement.focus();
      }
    }
  }
}

function cleanNumber(infield) {
  if (isNaN(infield.value)) {
    //alert("Please use only numeric numbers");
    // Replace all non-numeric characters
    res="";
    for(i=0;i<infield.value.length;i++) {
      if (isNaN(infield.value.charAt(i))){
      } else {
        res=res+infield.value.charAt(i);
      }
    }
    infield.value = res;
    return false;
  } else {
    return true;
  }
}

function formatNumber(infield, inminvalue, inmaxvalue, inenforceminmax, inUseCommas) {
  cleanNumber(infield);
  val = new Number(infield.value);
  if (val >= 2147483647 | val <= -2147483648) {
    alert("That number is too big");
    val=0
  }
  if (inminvalue != 0 & inenforceminmax == 'Y' & val < inminvalue) {
    val = inminvalue;
    alert("The minimum value for this is " + inminvalue);
  }
  if (inmaxvalue != 0 & inenforceminmax == 'Y' & val > inmaxvalue) {
    val = inmaxvalue;
    alert("The maximum value for this is " + inmaxvalue);
  }
  infield.value = val;
  dpos = infield.value.indexOf('.');
  if (dpos == -1) {
    dpos=infield.value.length;
  }

  if (inUseCommas=='Y') {
    res="";
    pos=-3;
    for (i=dpos-1; i>=0; i--) {
      pos++;
      if (pos%3 == 1) res = "," + res;
      res = infield.value.charAt(i) + res;
    }
    infield.value = res + infield.value.slice(dpos,infield.value.length);
  }
}

function openWindow(inURL,inWinName,inOptions) {
  thisWin=window.open(inURL,inWinName,inOptions);
  thisWin.focus();
}

function closeAndReturn(inURL) {
  window.opener.document.location.href=inURL;
  window.opener.focus();
  window.close();
}

