function validate_course(form)
{
	var status = true;
	var message = "The following input errors were found:\n";

	if(form.facultyid.selectedIndex ==0)
	{
		message = message + "\nYou must enter in an instructor.";
		status = false;
	}
	if((form.course.value == null)||(form.course.value == ""))
	{
		message = message + "\nYou must enter in the course name.";
		status = false;
	}
	if((form.department.value == null)||(form.department.value == ""))
	{
		message = message + "\nYou must enter in the department for this course.";
		status = false;
	}
	if((form.coursenumb.value == null)||(form.coursenumb.value == ""))
	{
		message = message + "\nYou must enter in the course number.";
		status = false;
	}
	if((form.sectionnumb.value == null)||(form.sectionnumb.value == ""))
	{
		message = message + "\nYou must enter in the section number.";
		status = false;
	}
	if((form.semester_yearid == null)||(form.semester_yearid.value == 0))
	{
		message = message + "\nYou must select a semester & year for this course";
		status = false;
	}
	
	if(status == false)
		alert(message);
	return status;
}

function validate_password(form)
{
	var status = true;
	var message = "The following input errors were found:\n";

	if((form.oldpassword.value == null)||(form.oldpassword.value == ""))
	{
		message = message + "\nPlease enter your old password.";
		status = false;
	}
	if((form.newpassword1.value == null)||(form.newpassword1.value == ""))
	{
		message = message + "\nPlease enter a new password.";
		status = false;
	}
	else if(form.newpassword1.value != form.newpassword2.value)
	{
		message = message + "\nThe new password fields do not match.";
		status = false;
	}
	
	if(status == false)
		alert(message);
	return status;
}

function validate_instructor(form)
{
	var status = true;
	var message = "The following input errors were found:\n";
	var email_regex = /^.+@.+\..+$/;

	if((form.fname.value == null)||(form.fname.value == ""))
	{
		message = message + "\nYou must enter in a first name.";
		status = false;
	}
	if((form.lname.value == null)||(form.lname.value == ""))
	{
		message = message + "\nYou must enter in a last name.";
		status = false;
	}
	if((form.phone.value == null)||(form.phone.value == ""))
	{
		message = message + "\nYou must enter in a phone number.";
		status = false;
	}
	if((form.email.value == null)||(form.email.value == ""))
	{
		message = message + "\nYou must enter in an email address.";
		status = false;
	}
	else if(!email_regex.test(form.email.value))
	{
		message = message + "\nThe email address you've entered is invalid.";
	}
	if((form.password.value == null)||(form.password.value == ""))
	{
		message = message + "\nYou must enter in a password.";
		status = false;
	}
	
	if(status == false)
		alert(message);
	return status;
}

function validate_activity(form)
{
	var status = true;
	var message = "";
	if((form.agencyid.selectedIndex ==0))
	{
		message = message + "\nYou must select a community partner.";
		status = false;
	}
	if((form.activity_name.value == null)||(form.activity_name.value == ""))
	{
		message = message + "\nYou must enter in a name for the activity.";
		status = false;
	}
	if((form.begin_date.value == null)||(form.begin_date.value == ""))
	{
		message = message + "\nYou must enter in a beginning date.";
		status = false;
	}
	if((form.end_date.value == null)||(form.end_date.value == ""))
	{
		message = message + "\nYou must enter in an ending date.";
		status = false;
	}
	if((form.begin_time.value == null)||(form.begin_time.value == ""))
	{
		message = message + "\nYou must enter in a start time.";
		status = false;
	}
	if((form.end_time.value == null)||(form.end_time.value == ""))
	{
		message = message + "\nYou must enter in an end time.";
		status = false;
	}
	
	if((form.maxstu.value == null)||(form.maxstu.value == ""))
	{
		message = message + "\nYou must enter a max participants.";
		status = false;
	}

	if(status == false)
		alert(message);
	return status;

}

function check(){
	var agencyid=document.activity.agencyid.value;
	if((agencyid==null)||(agencyid=="")){
		alert('You must select a community partner.');
		document.activity.agencyid.focus();
	return false;
	}
	var activityname=document.activity.activity_name.value;
	if((activityname==null)||(activityname=="")){
		alert('You must enter an activity name.');
		document.activity.activity_name.focus();
	return false;
	}
	var bdate=document.activity.begin_date.value;
	if((bdate==null)||(bdate=="")){
		alert('You must enter in a beginning date.');
		document.activity.begin_date.focus();
	return false;
	}
	var edate=document.activity.end_date.value;
	if((edate==null)||(edate=="")){
		alert('You must enter in an ending date even if it is the same as the beginning date.');
		document.activity.end_date.focus();
	return false;
	}
	var btime=document.activity.begin_time.value;
	if((btime==null)||(btime=="")){
		alert('You must enter in a beginning time.');
		document.activity.begin_time.focus();
	return false;
	}
	var etime=document.activity.end_time.value;
	if((etime==null)||(etime=="")){
		alert('You must enter in an ending time.');
		document.activity.end_time.focus();
	return false;
	}		

}

function validate_semester_year(form)
{
	var status = true;
	var message = "";
	if((form.semester.value == null)||(form.semester.value == ""))
	{
		message = message + "\nYou must enter in a semester.";
		status = false;
	}
	if((form.year.value == null)||(form.year.value == ""))
	{
		message = message + "\nYou must enter in a year.";
		status = false;
	}
	if((form.start_date.value == null)||(form.start_date.value == ""))
	{
		message = message + "\nYou must enter in a start date.";
		status = false;
	}
	if((form.end_date.value == null)||(form.end_date.value == ""))
	{
		message = message + "\nYou must enter in an end date.";
		status = false;
	}

	if(status == false)
		alert(message);
	return status;

}

function validateform(form){			
	//text only validation so far
	for(i=0; i<form.elements.length; i++){
		if(form.elements[i].getAttribute('rel') == "required" && form.elements[i].value == ""){
			alert('Please fill in all required fields');
			return false;
		}
	}
	return true;
}
// JavaScript Document
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope with old IE versions.
// and security blocked creation of the objects.
 try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
  try {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (E) {
   xmlhttp = false;
  }
 }
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
  xmlhttp = new XMLHttpRequest();
}
function hourEdit(hourid){
	xmlhttp.open("GET", "/service/thunder/participant/hour_edit.asp?hourid="+ hourid +"",true);
	 document.getElementById('hour' + hourid).innerHTML = "loading....";
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			 document.getElementById('hour' + hourid).innerHTML = xmlhttp.responseText;
		}
	}
	//document.getElementById('plus' + id).innerHTML = "";
	//document.getElementById('minus' + id).innerHTML = "<img src=/content/thunder/images/minus.gif border=0>";
	xmlhttp.send(null);
	
}

function hourSave(hourid){
	var numbhours = document.getElementById('hourtext'+hourid).value;
	xmlhttp.open("GET", "/service/thunder/participant/hour_save.asp?hourid="+ hourid +"&numbhours=" + numbhours,true);
	 document.getElementById('hour' + hourid).innerHTML = "loading....";
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			 document.getElementById('hour' + hourid).innerHTML = xmlhttp.responseText;
		}
	}
	//document.getElementById('plus' + id).innerHTML = "";
	//document.getElementById('minus' + id).innerHTML = "<img src=/content/thunder/images/minus.gif border=0>";
	xmlhttp.send(null);
	
	
}

function commentEdit(memberid){
	xmlhttp.open("GET", "/service/thunder/participant/comment_edit.asp?memberid="+ memberid +"",true);
	 document.getElementById('comments').innerHTML = "loading....";
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			 document.getElementById('comments').innerHTML = xmlhttp.responseText;
		}
	}
	//document.getElementById('plus' + id).innerHTML = "";
	//document.getElementById('minus' + id).innerHTML = "<img src=/content/thunder/images/minus.gif border=0>";
	xmlhttp.send(null);
	
}

function commentSave(memberid){
	var comments = document.getElementById('commentstext').value;
	xmlhttp.open("GET", "/service/thunder/participant/comment_save.asp?memberid="+ memberid +"&comments=" + comments,true);
	 document.getElementById('comments').innerHTML = "loading....";
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			 document.getElementById('comments').innerHTML = xmlhttp.responseText;
		}
	}
	//document.getElementById('plus' + id).innerHTML = "";
	//document.getElementById('minus' + id).innerHTML = "<img src=/content/thunder/images/minus.gif border=0>";
	xmlhttp.send(null);
	
	
}

function RegcommentEdit(registeredid){
	xmlhttp.open("GET", "/service/thunder/participant/reg_comment_edit.asp?workdateid="+ registeredid +"",true);
	 document.getElementById('comments' + registeredid).innerHTML = "loading....";
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			 document.getElementById('comments' + registeredid).innerHTML = xmlhttp.responseText;
		}
	}
	//document.getElementById('plus' + id).innerHTML = "";
	//document.getElementById('minus' + id).innerHTML = "<img src=/content/thunder/images/minus.gif border=0>";
	xmlhttp.send(null);
	
}

function RegcommentSave(registeredid){
	var comments = document.getElementById('commentstext').value;
	xmlhttp.open("GET", "/service/thunder/participant/reg_comment_save.asp?workdateid="+ registeredid +"&comments=" + comments,true);
	 document.getElementById('comments' + registeredid).innerHTML = "loading....";
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			 document.getElementById('comments' + registeredid).innerHTML = xmlhttp.responseText;
		}
	}
	//document.getElementById('plus' + id).innerHTML = "";
	//document.getElementById('minus' + id).innerHTML = "<img src=/content/thunder/images/minus.gif border=0>";
	xmlhttp.send(null);
	
	
}

//function to edit and save the appropriate applied for courses and campus activities on registration detail page
function appliedEdit(registeredid){
	xmlhttp.open("GET", "/service/thunder/participant/reg_applied_edit.asp?registeredid="+ registeredid +"",true);
	 document.getElementById('applied').innerHTML = "loading....";
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			 document.getElementById('applied').innerHTML = xmlhttp.responseText;
		}
	}
	//document.getElementById('plus' + id).innerHTML = "";
	//document.getElementById('minus' + id).innerHTML = "<img src=/content/thunder/images/minus.gif border=0>";
	xmlhttp.send(null);
	
}
function appliedSave(registeredid){
	var courseOneDrop = document.getElementById('courseid');
	var courseTwoDrop = document.getElementById('coursetwoid');
	
	var organizationOneDrop = document.getElementById('organizationid');
	var organizationTwoDrop = document.getElementById('organizationtwoid');
	
	var courseid = courseOneDrop.options[courseOneDrop.selectedIndex].value;
	var coursetwoid = courseTwoDrop.options[courseTwoDrop.selectedIndex].value;
	
	var organizationid = organizationOneDrop.options[organizationOneDrop.selectedIndex].value;
	var organizationtwoid = organizationTwoDrop.options[organizationTwoDrop.selectedIndex].value;
	
	xmlhttp.open("GET", "/service/thunder/participant/reg_applied_save.asp?registeredid="+ registeredid +"&courseid=" + courseid + "&coursetwoid=" + coursetwoid + "&organizationid=" + organizationid + "&organizationtwoid=" + organizationtwoid,true);
	 document.getElementById('applied').innerHTML = "loading....";
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			 document.getElementById('applied').innerHTML = xmlhttp.responseText;
		}
	}
	//document.getElementById('plus' + id).innerHTML = "";
	//document.getElementById('minus' + id).innerHTML = "<img src=/content/thunder/images/minus.gif border=0>";
	xmlhttp.send(null);
	
}
//---------------------------------------------------------------------------------------

function copylist(){
	xmlhttp.open("GET", "/service/thunder/activity/past.asp",true);
	
	document.getElementById('oldactivity').innerHTML = "loading....";
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			 document.getElementById('oldactivity').innerHTML = xmlhttp.responseText;
		}
	}
	
	
	
	xmlhttp.send(null);
	
	
}

//function to take the activityid selected and then redirect
function dupActivity(dropdown){
	var selected = dropdown.selectedIndex;
	var activityid = dropdown.options[selected].value;
	
	window.location = 'add_activity.asp?oldactivityid=' + activityid;
}


//function to get appropriate courses to choose from dependent on semester selection
function courseShuffleRestricted(){
	//activityid if there is one
	var activityid = document.activity.id.value;
	
	var dropdown = document.activity.semester_yearid;
	var myindex  = dropdown.selectedIndex;
    var semester_yearid = dropdown.options[myindex].value;
		
	xmlhttp.open("GET", "/service/thunder/course/select.asp?activityid=" + activityid + "&name=restricted&semester_yearid="+ semester_yearid +"",true);
	
	document.getElementById('restricted').innerHTML = "loading....";
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			 document.getElementById('restricted').innerHTML = "<select name='restricted' multiple size='5'>" + xmlhttp.responseText + "</select>";
			  document.getElementById('preferred').innerHTML = "<select name='preferred' multiple size='5'>" + xmlhttp.responseText + "</select>";
		}
	}
	
	
	
	xmlhttp.send(null);
	
	//courseShufflePreferred()
	
}

function courseShufflePreferred(){
	//activityid if there is one
	var activityid = document.activity.id.value;
	
	var dropdown = document.activity.semester_yearid;
	var myindex  = dropdown.selectedIndex;
    var semester_yearid = dropdown.options[myindex].value;
		
	xmlhttp.open("GET", "/service/thunder/course/select.asp?activityid=" + activityid + "&name=preferred&semester_yearid="+ semester_yearid +"",true);
	
	document.getElementById('preferred').innerHTML = "loading....";
	
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			 document.getElementById('preferred').innerHTML = xmlhttp.responseText;
		}
	}
	
	xmlhttp.send(null);
	
	
}

function checkit(day,daycheck){
	if(daycheck.checked){
		document.getElementById(day).checked = true;
	}
	
}
function checktop(day){
	var morning = document.getElementById(day+'am');
	var afternoon = document.getElementById(day+'aft');
	var evening = document.getElementById(day+'pm');
	if(morning.checked||afternoon.checked||evening.checked){
		document.getElementById(day).checked = true;
	}
}
function acceptForm(){
	var accepted = document.getElementById('acceptance');
	if(accepted.checked){
		document.getElementById('submit').disabled = false;
	}
	else{
		document.getElementById('submit').disabled = true;
	}
}

//function to edit and save the preferred and restricted courses for an activity
function courseEdit(activityid,cell,what){
	xmlhttp.open("GET", "/service/thunder/activity/course_edit.asp?what=" + what + "&activityid="+ activityid +"",true);
	 document.getElementById(cell).innerHTML = "loading....";
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			 document.getElementById(cell).innerHTML = xmlhttp.responseText;
		}
	}
	//document.getElementById('plus' + id).innerHTML = "";
	//document.getElementById('minus' + id).innerHTML = "<img src=/content/thunder/images/minus.gif border=0>";
	xmlhttp.send(null);
	
}
function courseSave(activityid,cell,what){
	var selected = ""; 
	var ob = document.getElementById(what + 'drop');
	for (var i = 0; i < ob.options.length; i++) {
		if (ob.options[i].selected) {
			selected = selected + ',' + ob.options[i].value ;
		}
	}
	
	xmlhttp.open("GET", "/service/thunder/activity/course_save.asp?activityid="+ activityid +"&what=" + what + "&values=" + selected,true);
	 document.getElementById(cell).innerHTML = "loading....";
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			 document.getElementById(cell).innerHTML = xmlhttp.responseText;
		}
	}
	//document.getElementById('plus' + id).innerHTML = "";
	//document.getElementById('minus' + id).innerHTML = "<img src=/content/thunder/images/minus.gif border=0>";
	xmlhttp.send(null);
	
}


