function help(topic, project) {
  var w = window.open('/birdmon/' + project + '/help.jsp?topic='+topic, 'Help', "toolbar=no,status=no,width=750,height=500,directories=no,scrollbars=yes,location=no,resizable=yes,menubar=no");
  w.focus();
}
function NewWindow(mypage, myname, w, h, myurl) {
   var winl = (screen.width - w) / 2;
   var wint = (screen.height - h) / 2;
   winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars=yes,resizable, toolbar=no, status=yes';
   win1 = window.open(mypage, myname, winprops)
   win1.location=myurl;
   win1.focus();
}
function NewWindow2(mypage, myname, w, h) {
   var winl = (screen.width - w) / 4;
   var wint = (screen.height - h) / 4;
   winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl;
   win2 = window.open(mypage, myname, winprops)
   win2.document.close();
   win2.focus();
}
function notavailable() {
  alert('Sorry, this option is not yet available');
}
function toggleRows(rowId) {
   var thisTable = document.getElementById("table1");
   var el = thisTable.getElementsByTagName("tr");
   for (i = 0; i < el.length; i++) {
     if (el[i].id.substr(0,rowId.length + 4) == "row" + rowId + ".") {
       var div1 = document.getElementById("expand" + rowId);
       if (el[i].style.display == "none") {
         el[i].style.display = "";
         div1.src = "/monitoring/images/collapse.gif";
       } else {
         el[i].style.display = "none";
         div1.src = "/monitoring/images/expand.gif";
       }
     }
   }
   return false;
}
var collapsed = false;
function toggleAllRows() {
  var thisTable = document.getElementById("table1");
  var el = thisTable.getElementsByTagName("tr");
  for (i = 0; i < el.length; i++) {
    if (el[i].className == "subsite") {
       if (collapsed) el[i].style.display = "";
       else el[i].style.display = "none";
    }
  }
  var el = thisTable.getElementsByTagName("img");
  for (i = 0; i < el.length; i++) {
    if (el[i].id.substr(0,6) == "expand") {
       if (collapsed) el[i].src = "/monitoring/images/collapse.gif";
       else el[i].src = "/monitoring/images/expand.gif";
    }
  }
  var div1 = document.getElementById("expandall");
  if (collapsed) div1.innerHTML = "Collapse sites";
  else div1.innerHTML = "Expand sites";
  collapsed = !collapsed;
}
function checkValue(v, t, mn, mx, l) {
  if (l == '' || typeof(l) == 'undefined') l = langJS;
  if (l != 'FR') l = 'EN';

  if (v.value == '') return true;
  if (t == 'number' || t == 'float') {
     v.value = getCleanNumber(v);
     if (isNaN(v.value)) {
        if (l == 'EN') alert('You must enter a valid number.');
        else alert('Vous devez entrer un chiffre');
        v.value = '';
        v.focus();
        return false;
     }
     else if (t == 'number' && parseFloat(v.value) != parseInt(v.value)) {
        if (l == 'EN') alert('You must enter a valid integer number.');
        else alert('Vous devez entrer un chiffre entier');
     }
     else if (!(parseFloat(v.value) < parseFloat(mn) || parseFloat(v.value) > parseFloat(mx))) return true;
//   else if (t == 'number') v.value = parseInt(v.value);
//   else if (t == 'float') v.value = parseFloat(v.value);
  }
  else {
     v.value = getCleanString(v);
     if (!(v.value < mn || v.value > mx)) return true;
  }
  if (mn != null && mx == null) {
    if (l == 'EN') alert('This value is smaller than\nthe minimum allowed: ' + mn);
    else alert('Cette valeur est plus petite que\nle minimum permis: ' + mn);
  }
  else if (mn == null && mx != null) {
    if (l == 'EN') alert('This value is larger than\nthe maximum allowed: ' + mx);
    else alert('Cette valeur est plus grande que\nle maximum permis: ' + mx);
  }
  else if (mn != null && mx != null) {
     if (l == 'EN') alert('This value is outside the \nallowed range ' + mn + '-' + mx +'.');
     else alert('Cette valeur doit être\ncomprise entre ' + mn + '-' + mx +'.');
  }
  v.value = '';
  v.focus();
  return false;
}
function getCleanNumber(b) {
   if (b.value=='') return '';
   while (b.value.length > 0 && b.value.substr(0,1) == ' ') b.value = b.value.substr(1,b.value.length);
   while (b.value.length > 0 && b.value.substr(b.value.length-1,b.value.length) == ' ') b.value = b.value.substr(0,b.value.length-1);
   while (b.value.length > 1 && b.value.substr(0,1) == '0') b.value = b.value.substr(1,b.value.length);
   i = b.value.indexOf(',');
   if (i >= 0) b.value = b.value.substr(0,i)+"."+b.value.substr(i+1,b.value.length);
   return b.value;
}
function getCleanString(b) {
   while (b.value.length > 0 && b.value.substr(0,1) == ' ') b.value = b.value.substr(1,b.value.length);
   while (b.value.length > 0 && b.value.substr(b.value.length-1,b.value.length) == ' ') b.value = b.value.substr(0,b.value.length-1);
   return b.value;
}

