function editlogin()
{
	if (GetElement("LoginName") == "")
	{
		SetElementFocus("LoginName");
		alert("Login Name is required");
		return false;
	}
	if (GetElement("Password") == "")
	{
		SetElementFocus("Password");
		alert("Password is required");
		return false;
	}
}

function editinput()
{
	if (GetElement("ClassSelect") == "0")
	{
		SetElementFocus("ClassSelect");
		alert("Class Selection is required");
		return false;
	}
	if (GetElement("FirstName") == "")
	{
		SetElementFocus("FirstName");
		alert("First Name is required");
		return false;
	}
	if (GetElement("LastName") == "")
	{
		SetElementFocus("LastName");
		alert("Last Name is required");
		return false;
	}
	if (GetElement("Address") == "")
	{
		SetElementFocus("Address");
		alert("Address is required");
		return false;
	}
	if (GetElement("City") == "")
	{
		SetElementFocus("City");
		alert("City is required");
		return false;
	}
	if (GetElement("State") == "")
	{
		SetElementFocus("State");
		alert("State is required");
		return false;
	}
	if (GetElement("Zip") == "")
	{
		SetElementFocus("Zip");
		alert("Zip Code is required");
		return false;
	}
	if (GetElement("AssnSelect") == "0")
	{
		SetElementFocus("AssnSelect");
		alert("Association is required");
		return false;
	}
	if (GetElement("RegType") == "0")
	{
		SetElementFocus("RegType");
		alert("Registration Type is required");
		return false;
	}
	if (GetElement("PrimaryPhone") == "")
	{
		SetElementFocus("PrimaryPhone");
		alert("Primary Phone Number is required");
		return false;
	}
}

function editclass()
{
	if (GetElement("ClassDate") == "")
	{
		SetElementFocus("ClassDate");
		alert("Class Date is required");
		return false;
	}
	if (!dateValid(GetElement("ClassDate")))
	{
		SetElementFocus("ClassDate");
		alert("Class Date is not a valid date!");
		return false;
	}
	if (GetElement("ClassTime") == "")
	{
		SetElementFocus("ClassTime");
		alert("Class Time is required");
		return false;
	}
	if (!IsValidTime(GetElement("ClassTime")))
	{
		SetElementFocus("ClassTime");
		alert("Class Time is not a valid time!");
		return false;
	}
	if (GetElement("ExpireDate") == "")
	{
		SetElementFocus("ExpireDate");
		alert("Expire Date is required");
		return false;
	}
	if (!dateValid(GetElement("ExpireDate")))
	{
		SetElementFocus("ExpireDate");
		alert("ExpireDate Date is not a valid date!");
		return false;
	}
	if (GetElement("ExpireTime") == "")
	{
		SetElementFocus("ExpireTime");
		alert("Expire Time is required");
		return false;
	}
	if (!IsValidTime(GetElement("ExpireTime")))
	{
		SetElementFocus("ExpireTime");
		alert("Expire Time is not a valid time!");
		return false;
	}
	if (GetElement("Duration") == "")
	{
		SetElementFocus("Duration");
		alert("Duration is required");
		return false;
	}
	if (GetElement("Location") == "")
	{
		SetElementFocus("Location");
		alert("Location is required");
		return false;
	}
	if (GetElement("Seats") == "")
	{
		SetElementFocus("Seats");
		alert("Seats is required");
		return false;
	}
	var canceledOptVal = "";
	for (i=0;i<document.forms[0].canceled.length;i++)
	{
		if (document.forms[0].canceled[i].checked)
		{
			canceledOptVal = document.forms[0].canceled[i].value;
		}
	}
	alert(canceledOptVal);
	if (canceledOptVal == "")
	{
		alert("Canceled is required");
		return false;
	}
}


function editadmin(val)
{
	var classOptVal = "";
	for (i=0;i<document.forms[0].classopt.length;i++)
	{
		if (document.forms[0].classopt[i].checked)
		{
			classOptVal = document.forms[0].classopt[i].value;
		}
	}
	SetElement("ButtonPressed", val);
	if (((val == 1) | (val == 2) | (val == 5)  | (val == 6)) & (classOptVal == ""))
	{
		alert("Class Selection is required");
	}
	else
	{
  		document.forms[0].submit();
	}
}

function GetElement(elementName)
{
	if (document.all[elementName])
		return document.all[elementName].value;
	return;
}

function SetElement(elementName, text)
{
	document.all[elementName].value = text;

}
function SetElementFocus(elementName)
{
	document.all[elementName].focus();

}

function dateValid(objName) {
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var intElementNr;
// var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
//strDate = datefield.value;
strDate = objName;
if (strDate.length < 1) {
return true;
}
for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
strDateArray = strDate.split(strSeparatorArray[intElementNr]);
if (strDateArray.length != 3) {
err = 1;
return false;
}
else {
strDay = strDateArray[0];
strMonth = strDateArray[1];
strYear = strDateArray[2];
}
booFound = true;
   }
}
if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}
//Adjustment for short years entered
if (strYear.length == 2) {
strYear = '20' + strYear;
}
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}
if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
   }
}
else {
if (intday > 28) {
err = 10;
return false;
      }
   }
}
return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}

function IsValidTime(timeStr) 
{
	// Checks if time is in HH:MM:SS AM/PM format.
	// The seconds and AM/PM are optional.

	var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;

	var matchArray = timeStr.match(timePat);
	if (matchArray == null) 
	{
		alert("Time is not in a valid format.");
		return false;
	}
	hour = matchArray[1];
	minute = matchArray[2];
	second = matchArray[4];
	ampm = matchArray[6];

	if (second=="") { second = null; }
	if (ampm=="") { ampm = null }

	if (hour < 0  || hour > 23) 
	{
		alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
		return false;
	}
	if (hour <= 12 && ampm == null) 
	{
		if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) 
		{
			alert("You must specify AM or PM.");
			return false;
		}
	}
	if  (hour > 12 && ampm != null) 
	{
		alert("You can't specify AM or PM for military time.");
		return false;
	}
	if (minute<0 || minute > 59) 
	{
		alert ("Minute must be between 0 and 59.");
		return false;
	}
	if (second != null && (second < 0 || second > 59)) 
	{
		alert ("Second must be between 0 and 59.");
		return false;
	}
	return true;
}


function SelectItemByValueInListBox(listboxOptions,valueToSelect)
{	
		try
		{
			for (cntr=0;cntr < listboxOptions.length;cntr++)
				{
					if (listboxOptions[cntr].value == valueToSelect)
					{
						listboxOptions[cntr].selected = true;
						break;
					}
				}
		}
		catch(e){}
}

