function IsEmailValid(in_email) 
{
	checkEmail = in_email;

	if ((checkEmail.indexOf('@') < 0) || ((checkEmail.charAt(checkEmail.length-4) != '.') && (checkEmail.charAt(checkEmail.length-3) != '.'))) 
	{		
		return false;
	}
	
	return true;
} 

function ConfirmLogout()
{
	yesorno = confirm("Are you sure you would like to logout?");	
	
	if (yesorno)
	{
		document.location="logout.asp";
	}
}

function ConfirmDelete()
{
	return confirm("Are you sure you would like to delete this entry?");	
}

function shiftUsers(in_all,in_dir)
{
	var selectFrom = document.UserGroup.avail_users;
	var selectTo = document.UserGroup.group_users;

	if (in_dir == "left")
	{
		selectFrom = document.UserGroup.group_users;
		selectTo = document.UserGroup.avail_users;
	}
	
	// get number in from list
	numOptions = selectFrom.length;

	if (in_all == 1)
	{				
		for (i=0;i<numOptions;i++)
		{
			// move to the to select box
			selectTo.options[selectTo.length] = new Option(selectFrom.options[i].text,selectFrom.options[i].value)
			
		}
		
		// remove all from from list
		for (i=0;i<numOptions;i++)
		{
			selectFrom.options[0] = null;			
		}
	}
	else
	{
		// only shift the selected ones
		for (i=0;i<numOptions;i++)
		{
			if (selectFrom.options[i].selected)
			{
				// move this from from to to
				selectTo.options[selectTo.length] = new Option(selectFrom.options[i].text,selectFrom.options[i].value)
			}
		}
		
		// now remove the selected ones from from list
		// remove all from from list
		for (i=0;i<numOptions;i++)
		{
			if (selectFrom.options[i].selected)
			{
				selectFrom.options[i] = null;
				i--;
				numOptions -= 1;
			}
		}
	}
	
	document.UserGroup.useridlist.value = "";
	
	// update the member id list with comma separated ids
	for (i=0;i<document.UserGroup.group_users.length;i++)
	{
		document.UserGroup.useridlist.value += document.UserGroup.group_users.options[i].value + ",";	
	}	
}

function OnDeptChange()
{
	document.UserGroup.action.value = "dept_change";
	document.UserGroup.submit();
}

function OnUserChange()
{
	document.ViewUserEvents.submit();
}

function CheckEmployeeForm()
{
	myForm = document.AddEmployee;
	
	if (myForm.username.value.length == 0)
	{
		alert('Please specify the username.');
		myForm.username.focus();
		return false;
	}
	else if (!IsEmailValid(myForm.username.value))
	{
		alert('Please provide a valid user name.');
		myForm.username.focus();
		return false;
	}
	else if (myForm.password.value.length == 0)
	{
		alert('Please specify the password.');
		myForm.password.focus();
		return false;
	}
	else if (myForm.password.value != myForm.cpassword.value)
	{
		alert('The two passwords do not match.');
		myForm.password.focus();
		return false;
	}
	else if (myForm.aliasname.value.length == 0)
	{
		alert('Please specify the alias name.');
		myForm.aliasname.focus();
		return false;
	}
	else if (myForm.firstname.value.length == 0)
	{
		alert('Please specify the first name.');
		myForm.firstname.focus();
		return false;
	}
	else if (myForm.lastname.value.length == 0)
	{
		alert('Please specify the last name.');
		myForm.lastname.focus();
		return false;
	}
	else if (myForm.title.value.length == 0)
	{
		alert('Please specify the title.');
		myForm.title.focus();
		return false;
	}	
	
	return true;
}

function EventSelected(in_return,in_eventID,in_month,in_year,in_item_name)
{
	window.opener.location = in_return+"&eventid="+in_eventID+"&c_month="+in_month+"&c_year="+in_year+"&item_name="+in_item_name;
	window.close();
}

function SelectEvent(in_return)
{
	var myForm = document.Training;
	
	item_name = myForm.item_name.value;
	yearIndex = myForm.year.selectedIndex;
	quarterIndex = myForm.quarter.selectedIndex;
	monthIndex = myForm.month.selectedIndex;
	
	sum_1 = yearIndex + quarterIndex + monthIndex;
	sum_2 = quarterIndex + monthIndex;
	
	if (item_name.length == 0)
	{
		//alert("Please specify the item name");
	}
	if (sum_1 == 0)
	{
		alert('Please select from one of the time frame drop down menus');
	}	
	else if (quarterIndex > 0 && sum_2 > quarterIndex)
	{
		alert('Please select either a quarter or a month');
	}
	else if (monthIndex > 0 && sum_2 > monthIndex)
	{
		alert('Please select either a quarter or a month');
	}
	else
	{
		// get the time frame
		c_year = myForm.year.options[yearIndex].value;
		c_month = 0;
		quarter = myForm.quarter.options[quarterIndex].value;
		month = myForm.month.options[monthIndex].value;
		
		if (quarter > month)
		{
			c_month = quarter;
		}
		else if (quarter < month)
		{
			c_month = month;
		}
		
		strOpen = "browse_events.asp?return="+in_return+"&item_name="+item_name+"&c_month="+c_month+"&c_year="+c_year;
		window.open(strOpen,'Events','width=600,height=400,scrollbars=yes');
	}	
}

function CheckAddEventItem()
{
	if (document.AddEventItem.TimeFrame.options[0].selected)
	{
		alert('Please specify a time frame.');
		document.AddEventItem.TimeFrame.focus();
		return false;
	}
	else if (document.AddEventItem.ItemDesc.value.length == 0)
	{
		alert('Please specify the item description.');
		document.AddEventItem.ItemDesc.focus();
		return false;
	}
	
	return true;
}

function OnClickSelectAClass()
{
	if (document.AddEventItem.TimeFrame.options[0].selected)
	{
		alert('Please specify a time frame.');
		document.AddEventItem.TimeFrame.focus();
	}
	else
	{	
		window.open("select_a_class.asp?time_frame="+document.AddEventItem.TimeFrame.value,'Class','width=600,height=400,scrollbars=yes');
	}
}

function OnClickAssignClass(in_eventId,in_eventName)
{
	window.opener.document.AddEventItem.EventName.value = in_eventName;
	window.opener.document.AddEventItem.EventID.value = in_eventId;
	window.opener.document.AddEventItem.AddItem.disabled = false;
	window.close();
}

function LoadFields()
{
	var myForm = document.AddEventItem;
	// select the time frame
	for (i=0;i<myForm.TimeFrame.length;i++)
	{
		if (myForm.TimeFrame.options[i].value == myForm.h_timeFrame.value)
		{
			myForm.TimeFrame.options[i].selected = true;
		}
	}
}

function DeleteTraining(in_type,in_id,in_id2)
{
	yesorno = confirm('Are you sure you would like to delete this training item?');
	if (yesorno)
	{	
		document.location = "edit_training_schedule.asp?type="+in_type+"&id="+in_id+"&action=delete&id2="+in_id2;
	}
}
