function validSelect(selectBox) {
  if (selectBox.selectedIndex == 0) {
    return false
  }
  return true
}

function validEmail(textBox) {
  emails = textBox.value.split(",");
  result = true;
  for (i=0; i < emails.length; i++) {
    index1 = emails[i].indexOf("@");
    index2 = emails[i].lastIndexOf(".");
    index3 = emails[i].indexOf(";");
    if ((index1 <= 0) || (index2 <= (index1 + 1)) || (index2 >= (emails[i].length - 1)) || (index3 >= 0))
      result = false;
  }
  return result
}

function validTva(tvaBox) {
  if (tvaBox.value.length != 9)
    return false
  return validBce(tvaBox)
}

function validBce(bceBox) {
  var modulo, lasttwo, l

  l = bceBox.value.length
  if ((l != 9) && (l != 10))
    return false

  //work around ParseInt bug : convert '08' in 0 instead of 8
  modulo = bceBox.value.substring(0, l-2)
  lasttwo = bceBox.value.substring(l-2, l)
  if (lasttwo.substring(0,1) == '0') {
    lasttwo = lasttwo.substring(1,2)
  }
  if (modulo.substring(0,1) == '0') {
    modulo = modulo.substring(1,l-2)
  }
  modulo = 97-(parseInt(modulo)%97)
  lasttwo = parseInt(lasttwo)

  if (modulo != lasttwo) {
    return false
  } else {
    return true
  }
}

function validFilled(textBox) {
  if (textBox.value == '') {
    return false
  }
  return true
}

function validFilled10(box1, box2, box3, box4, box5, box6, box7, box8, box9, box10) {
  if ((box1.value == '') && (box2.value == '') && (box3.value == '') && (box4.value == '')
   && (box5.value == '') && (box6.value == '') && (box7.value == '') && (box8.value == '')
   && (box9.value == '') && (box10.value == '')) {
    return false
  }
  return true
}

function validTvaEmpty(tvaBox) {
  return (!validFilled(tvaBox) || validTva(tvaBox))
}

function validNum(numBox) {
  num = parseInt(numBox.value);
  if ((num <= 0) || isNaN(num)) {
    return false
  }
  return true
}

function validAsblNum(asblBox) {
  index = asblBox.value.indexOf("/");
  len = asblBox.value.length;
  if ((index != len-3) && (index != len-5)) {
    return false
  }
  return true
}

function isempty(item) {
  for (var i = 0; i <item.length; i++) {
    if (item.charAt (i) != " ") 
      {return false}
    }
  return true
}

function checkAllActs(formObject, allBox) {
  i = 5
  while (i < formObject.elements.length) {
    checkBox = formObject.elements[i]
    checkBox.checked = allBox.checked
    i = i + 1
  }
}

function checkEveActs(formObject, eveBox, actsTable) {
  if (eveBox.selectedIndex != 0) {
    for (i=0; (i < actsTable.length); i++)
      if (actsTable[i][1].indexOf(eveBox.options[eveBox.selectedIndex].value) != -1)
        formObject.elements[i+5].checked = true
  }
}

function checkDateActs(formObject, dateBox, actsTable) {
  yyyy2 = dateBox.value.substring(6)
  mm2 = dateBox.value.substring(3,5)
  dd2 = dateBox.value.substring(0,2)
  for (i=0; (i < actsTable.length); i++) {
    date = actsTable[i][0]
    yyyy = date.substring(6)
    mm = date.substring(3,5)
    dd = date.substring(0,2)
    ok = false
    if (yyyy > yyyy2)
      ok = true
    else
      if ((yyyy == yyyy2) && (mm > mm2))
        ok = true
      else
        if ((yyyy == yyyy2) && (mm == mm2) && (dd >= dd2))
          ok = true
    if (ok) 
      formObject.elements[i+5].checked = true
  }
}

function openWaitPopup(msg) {
  waitWin = open("", "waitWindow", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=300,height=150,left=200,top=200");
  waitWin.document.write("<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'><title>...</title><link rel='stylesheet' type='text/css' href='/style.css'></head>");
  waitWin.document.write("<body><table><tr><td class='center'>"+msg+"</td></tr>");
  waitWin.document.write("<tr><td class='center'>&nbsp;</td></tr>");
  waitWin.document.write("<tr><td class='center'><img src='/images/logoanim.gif'></td></tr></table></body>");
  waitWin.document.write("</html>");
  return waitWin;
}
