/* Simon Willison's addLoadEvent function allows you to stack up 'window.onload' events 
without them stepping on each other's toes. 
It's explained here - http://www.sitepoint.com/blog-post-view.php?id=171578 */

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function addEvent(elm, evType, fn, useCapture)
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
// By Scott Andrew
{
  if (elm.addEventListener){
    elm.addEventListener(evType, fn, useCapture);
    return true;
  } else if (elm.attachEvent){
    var r = elm.attachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be added");
  }
}

// Date Display Function
function displayDate(){
    var this_month = new Array(12);
    this_month[0]  = 'January';
    this_month[1]  = 'February';
    this_month[2]  = 'March';
    this_month[3]  = 'April';
    this_month[4]  = 'May';
    this_month[5]  = 'June';
    this_month[6]  = 'July';
    this_month[7]  = 'August';
    this_month[8]  = 'September';
    this_month[9]  = 'October';
    this_month[10] = 'November';
    this_month[11] = 'December';
    var today = new Date();
    var day   = today.getDate();
    var month = today.getMonth();
    var year  = today.getYear();
    if (year < 1900){
        year += 1900;
    }
    return(this_month[month]+' '+day+', ' +year);
}

function ValidateContactForm(theForm)
{
  if (theForm.Name.value == '')
  {
    alert('Please enter a value for the "Name" field.');
    theForm.Name.focus();
    return (false);
  }

  var checkOK = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz \t\r\n\f';
  var checkStr = theForm.Name.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0; j < checkOK.length; j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert('Please enter only letter and whitespace characters in the "Name" field.');
    theForm.Name.focus();
    return (false);
  }

  if (theForm.Email.value == '')
  {
    alert('Please enter a value for the "Email" field.');
    theForm.Email.focus();
    return (false);
  }

  var checkOK = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-.,@_- \t\r\n\f';
  var checkStr = theForm.Email.value;
  var allValid = true;
  var validGroups = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert('Please enter only letter, digit, whitespace and ".,@_-" characters in the "Email" field.');
    theForm.Email.focus();
    return (false);
  }

  return (true);
}

function confirmDelete(text)
{return confirm('Are you sure you want to delete [' + text + ']?');}