/**
 *  functions for input validation
 */
 
/**
 *  checks the pattern of the specified input field value
 */
function input_pattern_validation(name, pattern, message, errorwindow, x, y)
{
  var str = "";
  var elements = document.getElementsByName(name);

  // loop through all input elements in form
  for(var i = 0; i < elements.length; i++)
  {
      var value = elements.item(i).value;

      // validate the value of this element, using its defined pattern
      var offendingChar = value.match(pattern);

      // if an invalid character is found or the element was left emtpy
      if(offendingChar == null && value != "")
      {
        // add up all error messages
        str += message;
      }
  }

  if (str != "")
  {
    errorwindow.moveTo(mouse_pos_x+x, mouse_pos_y+y);
    errorwindow.setContent(message);
    errorwindow.show(true);
    setTimeout(errorwindow.name + '.show(false)',3500);
    return false;
  }
}



function input_lower_range_validation(name, lower, message, errorwindow, x, y)
{
  var str = "";
  
  var elements = document.getElementsByName(name);

  // loop through all input elements in form
  for(var i = 0; i < elements.length; i++)
  {
      var value = elements.item(i).value;
     if (value != "")
     {
     value = value.replace(",", ".");
     if (value < lower) { str = message; }
     }
  }

  if (str != "")
  {
    errorwindow.moveTo(mouse_pos_x+x, mouse_pos_y+y);
    errorwindow.setContent(message);
    errorwindow.show(true);
    setTimeout(errorwindow.name + '.show(false)',3500);
    return false;
  }
}

function input_upper_range_validation(name, upper, message, errorwindow, x, y)
{
  var str = "";
  var elements = document.getElementsByName(name);

  // loop through all input elements in form
  for(var i = 0; i < elements.length; i++)
  {
      var value = elements.item(i).value;
      if (value != "")
      {
     value = value.replace(",", ".");
     if (value > upper) { str = message; }
     }
  }

  if (str != "")
  {
    errorwindow.moveTo(mouse_pos_x+x, mouse_pos_y+y);
    errorwindow.setContent(message);
    errorwindow.show(true);
    setTimeout(errorwindow.name + '.show(false)',3500);
    return false;
  }
}


