// JavaScript Document

// only run this on ie6 and above
if (is_ie6up) {

	document.writeln("<div id=\"loadingMsg\">Page is loading, please wait...</div>");

	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}

	addLoadEvent(function() {
		document.getElementById("loadingMsg").style.display="none";
	});

}

function isValidEmail(s) 
{
  var PNum = new String(s);
  var regex = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
  return regex.test(PNum);
}

function isAllWhitespace(s) 
{
  var whitespace = " \t\n\r";
  for (var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if (whitespace.indexOf(c) == -1) {
      return false;
    }
  }
  return true;
}

function isEmpty(s) 
{ 
  return (s == null || s.length == 0 || isAllWhitespace(s)); 
}

function validateForm(f) 
{	
	if (isEmpty(f.MyName.value)) {
		alert('Please enter your name.');
		f.MyName.select();
		return false;
	}
	
	if (isEmpty(f.MyCity.value)) {
		alert('Please enter your home city.');
		f.MyCity.select();
		return false;
	}
	
	if (isEmpty(f.MyState.value)) {
		alert('Please enter your home state.');
		f.MyState.select();
		return false;
	}
	
	if ( isEmpty(f.MyWorkPhone.value) && isEmpty(f.MyHomePhone.value) ) {
		alert('Please enter your home and or work telephone number(s).');
		f.MyWorkPhone.select();
		return false;
	}
	
	if ( isEmpty(f.FromEmail.value) || !isValidEmail(f.FromEmail.value) ) {
		alert('Please enter your email address.');
		f.FromEmail.select();
		return false;
	}
	
	if (isEmpty(f.Event.value)) {
		alert('Please enter the event name.');
		f.Event.select();
		return false;
	}
	
	if (isEmpty(f.Date.value)) {
		alert('Please enter the event date.');
		f.Date.select();
		return false;
	}
	
	if (isEmpty(f.City.value)) {
		alert('Please enter the event city.');
		f.City.select();
		return false;
	}
	
	if (isEmpty(f.State.value)) {
		alert('Please enter the event state.');
		f.State.select();
		return false;
	}
	
	if (isEmpty(f.Section.value)) {
		alert('Please enter the event section.');
		f.Section.select();
		return false;
	}
	
	if (isEmpty(f.Row.value)) {
		alert('Please enter the event row(s).');
		f.Row.select();
		return false;
	}
	
	if (isEmpty(f.Seats.value)) {
		alert('Please enter the event seat number(s).');
		f.Seats.select();
		return false;
	}
	
	return true;	
}
