//This action occurs when 'Cancel' is clicked
function cancel_event_posting()
{
	if(confirm('Are you sure you wish to navigate away from this page?  You will lose all changes.')) { history.go(-1); }
}
//When adding
function verify_and_save_event(submit_obj)
{
	if(verify_event_fields()){ jQuery("#post").submit();}
}
//When deleting
function verify_delete_event(submit_obj)
{
	if(typeof(submit_obj) == "number"){ ID = submit_obj; }
	else{ ID = jQuery("#ID").val(); }
	if(confirm("Are you sure you want to delete this event?  This action cannot be undone."))
	{
		window.location = TCT_ADMINLINK+"event_admin.php&action=deletepost&ID="+ID;
	}
}

//This function verifies all the fields in the event for validity
function verify_event_fields()
{
	var isgood = true;
	if(jQuery("#title").val() == "") isgood = false;
	if(jQuery("#track").val() == 0) isgood = false;
	if(jQuery("#start_date").val() == "") isgood = false;
	if(jQuery("#max_seats").val() == "") isgood = false;
	//if(jQuery("#content").val() == "") isgood = false;	

	//Now, if isgood is false display an error and return
	if(!isgood)
	{
		alert("Please fill out all required fields.");
		return false;
	}
	//Now check the money field and the max seats
	if(jQuery("#cost").val() == "") isgood = false;
	if(!jQuery("#cost").val().match(/^\d*\.\d\d$/))
	{
		alert("Please fill out the cost in the proper format '###.##'.");
		return false;
	}
	if(jQuery("#max_seats").val() == "") isgood = false;
	if(jQuery("#max_seats").val().match(/\D/))
	{
		alert("Please fill out the max number of students in the proper format (numbers only).");
		return false;
	}

	return true;
}

//This function is for when  you click view or edit instructors/drivers
function view_edit_class(obj)
{
	var to_edit = obj.id.split('-')[2];
	window.location = TCT_ADMINLINK+"class_admin.php&event_ID="+to_edit;
}

//This function filters the table of users by last name
function filterbylast(letter)
{
	lasts_array = jQuery(".tct_user_last_span");
	if(letter == "all")
	{
		//Show every single element
		for(var x=0; x<lasts_array.length; x++)
		{
			var user_num = lasts_array[x].id.split("_");
			jQuery("#tct_row_"+user_num[user_num.length-1]).show();
		}
	}
	else
	{
		to_hide = new Array();
		to_show = new Array();
		for(var x=0; x<lasts_array.length; x++)
		{
			letter = letter.toLowerCase();
			var t1 = lasts_array[x].innerHTML;
			var t2 = t1.toLowerCase();
			var l2 = t2[0];
			if(letter == l2)
				to_show.push(lasts_array[x]);
			else
				to_hide.push(lasts_array[x]);
		}
		for(var x=0; x<to_show.length; x++)
		{
			var user_num = to_show[x].id.split("_");
			jQuery("#tct_row_"+user_num[user_num.length-1]).show();
		}
		for(var x=0; x<to_hide.length; x++)
		{
			var user_num = to_hide[x].id.split("_");
			jQuery("#tct_row_"+user_num[user_num.length-1]).hide();
		}
			
	}
}

//This function submits the form given, with no questions asked
function submitmyform(formname)
{
	jQuery("#"+formname).submit();
}

//This array deletes a user from the class
function remove_user_from_class(user_ID, event_ID)
{
	if(confirm("Are you sure you want to delete this user?"))
	{
		window.location = TCT_ADMINLINK+"class_admin.php&action=dodelete&user_ID="+user_ID+"&event_ID="+event_ID;
	}
}
