
String.prototype.trim = function() { 
  // Strip leading and trailing white-space
  return this.replace(/^\s*|\s*$/g, "");
}

// adaped from http://www.codelifter.com/main/javascript/emailaddresschecker1.html
function CheckValidEmail(email) {
  // Note: The next expression must be all on one line... allow no spaces, linefeeds, or carriage returns!
  var email_test = email.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
  if (email_test) {
    return true;
  } else {
    return false;
  } // end if email_test
} 

var popUpWin;
function popUpWindow(name, URLStr, width, height, vars) {
  var left = screen.availWidth/2 - width/2;
  var top = screen.availHeight/2 - height/2;

  var toolbar = (/toolbar=yes/.test(vars) == true) ? "yes" : "no";
  var location = (/location=yes/.test(vars) == true) ? "yes" : "no";
  var directories = (/directories=yes/.test(vars) == true) ? "yes" : "no";
  var status = (/status=yes/.test(vars) == true) ? "yes" : "no";
  var menubar = (/menubar=yes/.test(vars) == true) ? "yes" : "no";
  var scrollbars = (/scrollbars=yes/.test(vars) == true) ? "yes" : "no";
  var resizable = (/resizable=yes/.test(vars) == true) ? "yes" : "no";
  var copyhistory = (/copyhistory=yes/.test(vars) == true) ? "yes" : "no";

  if ((typeof popUpWin) == 'object') {
  }
  popUpWin = open(URLStr, name, 'toolbar=' + toolbar + ',location=' + location + ',directories=' + directories + ',status=' + status + ',menubar=' + menubar + ',scrollbars=' + scrollbars + ',resizable=' + resizable + ',copyhistory=' + copyhistory + ',width=' + width + ',height=' + height + ',left=' + left + ', top=' + top + ',screenX=' + left + ',screenY=' + top);
  //popUpWin.focus();
}


function ValidateFieldText(field, field_label, line_break) {

  var msg = "";
  var strValue = '';

  // Text type fields

  if (field.type == 'hidden' || field.type == 'text' || field.type == 'textarea' || field.type == 'file' || field.type == 'password') {
    strValue = field.value.trim();
  } // end if field.type

  // Checkbox Field - use validate_field_radio()

  // Select Box Fields
  if (field.type == 'select-one') {
    var si = field.selectedIndex;
    if (si >= 0) {
      strValue = field.options[si].value;
    } // end if si
  } // end if field.type
	
  if (strValue.trim() == '') {
    msg += field_label;
    if (line_break == true) {
      msg += "\n"; 
    } // end if line_break
  } // end if strValue

  if (msg != '') {
    msg = "- " + msg;
  } // end if msg

  return msg;
}

function ValidateFieldRadio(field, field_label, line_break) {
  var msg = "";
  var strValue = '';

  for (i=0; i<field.length; i++) {
    if (field[i].checked==true) {
      strValue = field[i].value;
    }
  }

  if (strValue.trim() == '') {
    msg += field_label;
    if (line_break == true) {
      msg += "\n";
    }
  }

  if (msg != '') {
    msg = "- " + msg;
  } // end if msg

  return msg;
}

