/*
	
	EMERSON COLLEGE
		Javascript
		Event Booking functions
	
*/

var locationDisplayDetailsArray = new Array('_name','_address','_notes');//,'_adminName'


function displayTimeDetail(idcode) {
	
	// Hide details
	if (Element.visible( 'schedule_detailsFull_'+idcode ) === false) {
		
		new Effect.BlindDown('schedule_detailsFull_'+idcode,
			{
				duration:0.6,
				beforeStart:
					function(x) {
						new Effect.BlindUp('schedule_detailsDefault_'+idcode, { duration:0.5 });
					}
			});
		
	} else {
		
		new Effect.BlindUp('schedule_detailsFull_'+idcode,
			{
				duration:0.6,
				beforeStart:
					function(x) {
						new Effect.BlindDown('schedule_detailsDefault_'+idcode, { duration:0.5 });
					}
			});
		
	}
}

function addEvent_locationDisplay() {
	
	var elementValue = $('paappEventsLocation_main').options[$('paappEventsLocation_main').selectedIndex].value;
	var elementDisplay = 'paappEventsLocation_details';
	var elementDisplayAdd = 'paappEventsLocation_add';
	var elementDisplayView = 'paappEventsLocation_view';
	var elementDisplayUpOptions = {direction:'top-left',duration:0.5};
	var elementSubDisplayType;
	
	// If something is selected, display the full details.
	
		// Existing? Show them details
		
		// New? Show the new fields
	
	if (elementValue != "") {
		
		if (Element.visible(elementDisplay) === false) {
			elementSubDisplayType = "show";
		} else {
			elementSubDisplayType = "blind";
		}
		
		if (elementValue == "new") {
			
			for (i=0;i<locationDisplayDetailsArray.length;i++) {
				
				if (Element.visible('paappEventsLocation_add'+locationDisplayDetailsArray[i]) === false) {
					
					// Display element
						if (elementSubDisplayType == "blind") {	
							Effect.BlindDown('paappEventsLocation_add'+locationDisplayDetailsArray[i],elementDisplayUpOptions);
						} else {
							$('paappEventsLocation_add'+locationDisplayDetailsArray[i]).style.display = "block";
						}
						
				}
				
				if (Element.visible('paappEventsLocation_view'+locationDisplayDetailsArray[i]) === true) {
					
					// Hide element
						if (elementSubDisplayType == "blind") {	
							Effect.BlindUp('paappEventsLocation_view'+locationDisplayDetailsArray[i],elementDisplayUpOptions);
						} else {
							$('paappEventsLocation_view'+locationDisplayDetailsArray[i]).style.display = "none";
						}
					
				}
				
			}
			
		} else {
				addEvent_loadSavedLocation();
			
			for (i=0;i<locationDisplayDetailsArray.length;i++) {
				if (Element.visible('paappEventsLocation_view'+locationDisplayDetailsArray[i]) === false) {
					
					// Display element
						if (elementSubDisplayType == "blind") {	
							Effect.BlindDown('paappEventsLocation_view'+locationDisplayDetailsArray[i],elementDisplayUpOptions);
						} else {
							$('paappEventsLocation_view'+locationDisplayDetailsArray[i]).style.display = "block";
						}
					
				}
				
				if (Element.visible('paappEventsLocation_add'+locationDisplayDetailsArray[i]) === true) {
					
					// Hide element
						if (elementSubDisplayType == "blind") {	
							Effect.BlindUp('paappEventsLocation_add'+locationDisplayDetailsArray[i],elementDisplayUpOptions);
						} else {
							$('paappEventsLocation_add'+locationDisplayDetailsArray[i]).style.display = "none";
						}
					
				}
				
			}
			
		}
		
		
		if (Element.visible(elementDisplay) === false) {
			Effect.BlindDown(elementDisplay,{direction:'top-left'});
		}

	} else if (elementValue == "" && Element.visible(elementDisplay) === true) {
		
		Effect.BlindUp(elementDisplay,{direction:'top-left'});
		
	}
	
}

function addEvent_capacityDisplay() {
	
	// Pull out vars for addition
		if ($F('paappEvents_capacityPublic') > 0) {
			publicCap = parseInt($F('paappEvents_capacityPublic'),0);
		} else {
			publicCap = 0;
		}
		if ($F('paappEvents_capacityAdmin') > 0) {
			adminCap = parseInt($F('paappEvents_capacityAdmin'),0);
		} else {
			adminCap = 0;
		}
		totalCap = (publicCap + adminCap);
		
	// Publish updated number
		$('paappEvents_capacityTotal').innerHTML = totalCap;
}

function addEvent_eventTypeChange() {
	
	var selection = "";
	var addEvent_eventTypeChange_duration = 0.4;
	// Check the checked value
		
	if (Element.visible('paappEvents_appTypes_div_default') === true) {
		Effect.BlindUp('paappEvents_appTypes_div_default',{duration:addEvent_eventTypeChange_duration});
	}
	
	if ($('paappEvents_eventType_0').checked == true) {
		var selection = $F('paappEvents_eventType_0');
	} else if ($('paappEvents_eventType_1').checked == true) {
		var selection = $F('paappEvents_eventType_1');
	}
	
	// Loop all majors and hide majors not matching type.
	for (i=0;i<paappEvents_appTypes_paCode.length;i++) {
		
		// Should we show this?
		if (paappEvents_appTypes_paType[i] == selection) {
			//alert("Doing the display "+paappEvents_appTypes_paCode[i]);
			// We should, let's display if we need it
			if (Element.visible('paappEvents_appTypes_div_'+paappEvents_appTypes_paCode[i]) === false) {
				
				Effect.BlindDown('paappEvents_appTypes_div_'+paappEvents_appTypes_paCode[i],{duration:addEvent_eventTypeChange_duration});
				
			}
			
		} else {
			//alert("Not the display "+paappEvents_appTypes_paCode[i]);
			
			// We shouldn't, so hide.
			if (Element.visible('paappEvents_appTypes_div_'+paappEvents_appTypes_paCode[i]) === true) {
				
				Effect.BlindUp('paappEvents_appTypes_div_'+paappEvents_appTypes_paCode[i],{duration:addEvent_eventTypeChange_duration});
				
			}
			
			// Remember to clear our settings.
			$('paappEvents_appTypes_'+paappEvents_appTypes_paCode[i]).checked = false;
			
		}
			
		
	}
	
	
}


function addEvent_loadSavedLocation() {
	
	// Pull selected ID number
	
		var locationID =  $('paappEventsLocation_main').options[$('paappEventsLocation_main').selectedIndex].value;
	
	// Request data from the Ajax
		
		var getLocationInfoAjax = new Ajax.Request(
				
				ajaxurl_root,
				{
					method: 'post',
					parameters: "&id=events_getLocations&keyID="+locationID,
					onComplete: addEvent_loadSavedLocationExport,
					onFailure: function(x) { alert("Something's wrong."); }
				}
				);
		
}

function addEvent_loadSavedLocationExport(originalRequest) {
	
		var addressBlock = "";
	
	// Phaze XML to usable data
		//$('debug').value = originalRequest.responseText;
		var phazed_xml = originalRequest.responseXML.getElementsByTagName('paapp');
		
	// Let's make all the vars managaable:
		if (phazed_xml[0].getElementsByTagName('displayName')[0].firstChild != null) {
			var addEvent_displayName = phazed_xml[0].getElementsByTagName('displayName')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('displayInfo')[0].firstChild != null) {
			var addEvent_displayInfo = phazed_xml[0].getElementsByTagName('displayInfo')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('address_1')[0].firstChild != null) {
			var addEvent_address_1 = phazed_xml[0].getElementsByTagName('address_1')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('address_2')[0].firstChild != null) {
			var addEvent_address_2 = phazed_xml[0].getElementsByTagName('address_2')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('address_3')[0].firstChild != null) {
			var addEvent_address_3 = phazed_xml[0].getElementsByTagName('address_3')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('address_4')[0].firstChild != null) {
			var addEvent_address_4 = phazed_xml[0].getElementsByTagName('address_4')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('city')[0].firstChild != null) {
			var addEvent_city = phazed_xml[0].getElementsByTagName('city')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('state')[0].firstChild != null) {
			var addEvent_state = phazed_xml[0].getElementsByTagName('state')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('zip')[0].firstChild != null) {
			if (phazed_xml[0].getElementsByTagName('zip')[0].firstChild.data.length < 5) {
				var addEvent_zip = zipZeroPad(phazed_xml[0].getElementsByTagName('zip')[0].firstChild.data);
			} else {
				var addEvent_zip = phazed_xml[0].getElementsByTagName('zip')[0].firstChild.data;
			}
		}
		if (phazed_xml[0].getElementsByTagName('viaPhone')[0].firstChild != null) {
			var addEvent_state = phazed_xml[0].getElementsByTagName('viaPhone')[0].firstChild.data;
		}
					
	// Publish findings.

		// Add Maps links
			addressBlock += createLink_allMaps(addEvent_address_1,addEvent_city,addEvent_state,addEvent_zip,addEvent_displayName) + "<br /><br />";
			
		// Build Address Block
			
			addressBlock += addEvent_address_1 + "<br />";
			
			if (addEvent_address2 != null) {
				addressBlock += addEvent_address_2 + "<br />";
			}
			
			if (addEvent_address3 != null) {
				addressBlock += addEvent_address_3 + "<br />";
			}
			
			if (addEvent_address4 != null) {
				addressBlock += addEvent_address_4 + "<br />";
			}
			
			addressBlock += addEvent_city + ", " + addEvent_state + "<br />";
			addressBlock += addEvent_zip;
			
			
			
		// Display Items
			$('paappEventsLocation_view_name_output').innerHTML = addEvent_displayName;
			$('paappEventsLocation_view_address_output').innerHTML = addressBlock;
			$('paappEventsLocation_view_notes_output').innerHTML = addEvent_displayInfo;
		
			
}

function addEvent_addTime() {
	
	// Set standards
		var addEvent_addtime_currentSlots = new Array();
		var tempHTML = "";
		var currentMarker = 0;
		var date_match = false;
		
	// Pull user's entry
		var userYear = $F('paappEvents_dateYear');
		var userMonth = $F('paappEvents_dateMonth');
		var userDay = $F('paappEvents_dateDay');
		var userHour = $F('paappEvents_timeHour');
		var userMin = $F('paappEvents_timeMin');
		
		//alert(userYear+"/"+userMonth+"/"+userDay);
		
	// Check date if it's real.
		if (checkDate(userYear,userMonth,userDay) === false) {
			alert("Date entered doesn't exist. Please enter a real date.");
		} else {
			// Make user's date into a JS datetime
			userFullDate = new Date(userYear,userMonth,userDay,userHour,userMin,0,0);
			
			// Run add new time function.
				tempCount = parseInt($F('paappEvents_addedTimes_total'));
				
				// Pull current added slots (if any)
					for(i=0;i<tempCount;i++) {
						tempDatePull = new Date(parseInt($F('paappEvents_addedTimes_value_'+i)));
						
						addEvent_addtime_currentSlots[i] = tempDatePull;
						currentMarker = i+1;
						
						// Check if time is already entered
							if (tempDatePull.getTime() == userFullDate.getTime()) {
								date_match = true;
							}
						
					}
	
				// Check if date has been entered:
				if (date_match === true) {
					
					// Show alert and be done
					alert("You have already entered this date and time.");
					
				} else {
				
					// Add new time into array
						addEvent_addtime_currentSlots[currentMarker] = userFullDate;
						
					// Sort array by time order
						addEvent_addtime_currentSlots.sort(function(a,b) { return a-b;});
						
					// Publish findings
						for (i=0;i<addEvent_addtime_currentSlots.length;i++) {
							
							// Spit out HTML in to temp var
								tempHTML += addEvent_addTime_htmlAdd(i,addEvent_addtime_currentSlots[i]);
								
						}
						
						$('paappEvents_addedTimes').innerHTML = tempHTML;
						$('paappEvents_addedTimes_total').value = addEvent_addtime_currentSlots.length;
						
				}
					
		}
		
		
	
	
}

function addEvent_removeTime(id) {
	//alert("Running addEvent_removeTime("+id+");");
	var addEvent_addtime_currentSlots = new Array();
	currentMarker = 0;
	tempHTML = "";
	
	// Run add new time function.
		tempCount = parseInt($F('paappEvents_addedTimes_total'));
		
		// Pull current added slots (if any)
			for(i=0;i<tempCount;i++) {
				
				if (i != id) {
					addEvent_addtime_currentSlots[currentMarker] = new Date(parseInt($F('paappEvents_addedTimes_value_'+i)));
					
					currentMarker++;
				}
				
			}
	
	// Sort array by time order
		addEvent_addtime_currentSlots.sort(function(a,b) { return a-b;});
		
		//alert(addEvent_addtime_currentSlots.length);
		
	// Set findings (if there are any left)
		if (addEvent_addtime_currentSlots.length > 0) {
			
			for (i=0;i<addEvent_addtime_currentSlots.length;i++) {
				
				// Spit out HTML in to temp var
					tempHTML += addEvent_addTime_htmlAdd(i,addEvent_addtime_currentSlots[i]);
					
			}
			
		} else {
			
			tempHTML = "Please add a date and time.";
			
		}
		
	// Publish out
		Effect.Puff('paappEvents_addedTimes_'+id,{
					
					beforeStart: function(x) {
						if (addEvent_addtime_currentSlots.length<1) {
							new Insertion.Bottom('paappEvents_addedTimes',tempHTML);
						}
					},
					
					afterFinish: function(x) {
						$('paappEvents_addedTimes').innerHTML = tempHTML;
						$('paappEvents_addedTimes_total').value = addEvent_addtime_currentSlots.length;
					}
					
					});
	
}

function addEvent_addTime_htmlAdd(i,dateValue) {
	
	// date_getRealMonth(dateValue.getMonth())+' '+dateValue.getDate()+', '+dateValue.getFullYear()+' @ '+timeZeroPad(dateValue.getHours())+':'+timeZeroPad(dateValue.getMinutes())+' | '
	
	return '<div id="paappEvents_addedTimes_'+i+'"><a href="javascript:addEvent_removeTime('+i+');">\n<img src="/images/remove_icon.png" alt="Remove" width="15" height="15" style="vertical-align: middle;" title="Click to Remove Date/Time" border="0" /></a> '+date_getRealMonth(dateValue.getMonth())+' '+dateValue.getDate()+', '+dateValue.getFullYear()+' @ '+timeZeroPad(dateValue.getHours())+':'+timeZeroPad(dateValue.getMinutes())+' -'+(dateValue.getTimezoneOffset()/60)*100+' | '+dateValue.toUTCString()+' -'+(dateValue.getTimezoneOffset()/60)*100+'\n<input type="hidden" name="paappEvents_addedTimes_value_'+i+'" id="paappEvents_addedTimes_value_'+i+'" value="'+dateValue.getTime()+'" />\n</div>\n';
	
}

function addEvent_check() {
	
	// Constants
		var check_general = false;
		var check = new Array();
		// - Location
			check[0] = false;
			// - No location selected
				check[13] = false;
			// - Public Display Name
				check[9] = false;
			// - Internal Display Name
				check[10] = false;
			// - Address
				check[11] = false;
			// - Public Information
				check[12] = false;
		// - Date & Time
			check[1] = false;
		// - Event Details
			check[2] = false;
			// - Event Type
				check[3] = false;
			// - Event Size
				check[4] = false;
		// - AppTypes
			check[5] = false;
			// - Majors
				check[6] = true; // Guilty till proven inocent
			// - App Status
				check[7] = false;
		// - Other Options
			check[8] = false;
			
		var areaTypes = new Array('Location','eventDetails','eventTypes','otherOptions');
		var check6_1_array = new Array("enrollType_frosh","enrollType_trans");
		var check6_2_array = new Array("appType_ea","appType_ra");
				
	
	// Location
	
		if ($('paappEventsLocation_main').options[$('paappEventsLocation_main').selectedIndex].value == "new") {
			
			// Process for a new location
			
				// Check display title
					if ($F('paappEventsLocation_displayName') == "") {
						// Fail for not having a display title
							check[0] = true;
							check[9] = true;
					}
					
				/* Check admin title
					if ($F('paappEventsLocation_adminName') == "") {
						// Fail for not having a admin title
							check[0] = true;
							check[10] = true;
					}*/
					
				// Check address
				
					if ($F('paappEventsLocation_address_1') == "" || $F('paappEventsLocation_city') == "" ||  $F('paappEventsLocation_city') == "" || $F('paappEventsLocation_zip') == "") {
						// Fail for not having all address details
							check[0] = true;
							check[11] = true;
					}
					
				// Check Notes
				
					if ($F('paappEventsLocation_notes') == "") {
						// Fail for not having notes included.
							check[12] = true;
							alert($('paappEventsLocation_notes').value);
					}
			
		} else if ($('paappEventsLocation_main').options[$('paappEventsLocation_main').selectedIndex].value != "") {
			// Process for using an existing location
				
		} else {
			// Fail for not selecting a location
				check[0] = true;
				check[13] = true;
		}
		
	// Date & Time
		
		if ($F('paappEvents_addedTimes_total') < 1) {
			// Fail for not having date/times
				check[1] = true;
		}
		
	// Event Details
	
		// Event Type
		
			if ( $('paappEvents_eventType_0').checked === false && $('paappEvents_eventType_1').checked === false ) {
				// Fail for not picking a type
					check[2] = true;
					check[3] = true;
			}
			
		// Event Size
		
			if ( $F('paappEvents_capacityPublic') < 1 && $F('paappEvents_capacityAdmin') < 1) {
				// Fail for not having seats in the event.
					check[2] = true;
					check[4] = true;
			}
			
	// Applicant Types
			
			
			if (check[3] === false) {
				
				// Applicaint Types: Majors
				
					paappEvents_appTypes_paCode.each (
						function (x) {
							
							if ($('paappEvents_appTypes_'+x).checked === true) {
								// We've got one!
								check[6] = false;
								//alert("passed: "+x);
							} else {
								//alert("failed: "+x);
							}
						});
			}
			
			
			
		if ( ($('paappEvents_appStatus_'+check6_1_array[0]).checked === false && $('paappEvents_appStatus_'+check6_1_array[1]).checked === false) || ($('paappEvents_appStatus_'+check6_2_array[0]).checked === false && $('paappEvents_appStatus_'+check6_2_array[1]).checked === false) ) {
			
			// Fail for not having any form of status included.
				check[7] = true;
			
		}
		
		// Check catagory alerts
			// App Types
				if (check[6] === true || check[7] === true) {
					check[5] = true;
				}
		
		if ( check.any (function(x) {if (x === false) {status = false;} else {status = true;}return x;}) === true) {
			
			var alertRun = "";
			var alertRunCount = 0;
			
			alertRun = (check.any (function(x) {if (x === false) {status = false;} else {status = true;}return x;}))+"\n\n";
			
			check.each (function(member) {
								if (member === true) {
									alertRun += "\n"+alertRunCount+": "+member;
									action = 1;
								} else {
									action = 0;
								}
								addEvent_check_displaySwitch(alertRunCount,action);
								alertRunCount++;
							} ) ;
			
			// Something is wrong
			//alert("Failed!\n"+alertRun);
			
			addEvent_alert('paappEvents_general',null,1);
		} else {
			// All is well
				check.each (function(member) {
									addEvent_check_displaySwitch(alertRunCount,0);
									alertRunCount++;
								} ) ;
			addEvent_alert('paappEvents_general',null,0);
			//alert("Passed!");
			addEvent_submit();
		}
	
}

function addEvent_alertDIV(id,action) {
	
	if (action == 1) {
		// Display alert
		$(id).style.backgroundImage = "url(/images/fade_990000.png)";
		$(id).style.backgroundColor = "#BE5D5D";
		$(id).style.color = "#ffffff";
		//new Effect.Highlight(id,{startcolor:'#990000'});
	} else {
		$(id).style.backgroundImage = "";
		$(id).style.backgroundColor = "";
		$(id).style.color = "";
	}
	
}

function addEvent_alert (id,message,action) {
	
	// Check what we're doing
	if (action == 1) {
		// Inject message into alert box
			if (message != null) {
				$(id+"_alert").innerHTML = message;
			} else {
				$(id+"_alert").innerHTML = "Please add the following missing information.";
			}
			
		// Display the alert box
			if (Element.visible(id+"_alert") === false) {
				new Effect.BlindDown(id+"_alert",{duration:0.5});
			} else {
				new Effect.Highlight(id+"_alert",{duration:0.5});
			}
	} else if (Element.visible(id+"_alert") === true) {
		// Let's clean up.
			new Effect.BlindUp(id+"_alert",{duration:0.5,afterFinish:function(x) { $(id+"_alert").innerHTML = ""; } });
	}
		
}

function addEvent_check_displaySwitch(alertID,action,other) {
	
	if (other == undefined) {
		other = 0;
	}
	
	switch(alertID) {
		
		case 0:
			// Global Location
				addEvent_alertDIV('paappEventsLocation',action);
				if (other == 0) {
					addEvent_alert('paappEventsLocation','Please select a location.',action);
				}
				break;
				
		case 1:
			// Date & Time
				addEvent_alertDIV('paappEventsTime',action);
				addEvent_alert('paappEventsTime','Please add at least one date and time slot.',action);
				break;
				
		case 2:
			// Event Details (general)
				addEvent_alertDIV('paappEventsDetails',action);
				break;
				
		case 3:
			// Event Details - Even Type
				addEvent_alert('paappEventsDetails_eventType','Please select an event type.',action);
				break;
			
		case 4:
			// Event Details - Even Size
				addEvent_alert('paappEventsDetails_eventSize','Please include how many seats are available.',action);
				break;
			
		case 5:
			// App Types (general)
				addEvent_alertDIV('paappEventsTypes',action);
				break;
			
		case 6:
			// App Types - Majors
				addEvent_alert('paappEventsTypes_majors','Please select at least one major.',action);
				break;
			
		case 7:
			// App Types - Majors
				addEvent_alert('paappEventsTypes_status','Please select at least one action and one application type.',action);
				break;
			
			
		default:
			// Catch-all
				break;
			
	}
	
}

function addEvent_submit() {
	
	// Collect information and place into vars
		// Location ID Number
			opt_locationID = $F('paappEventsLocation_main');
		// Event Type Code
			if ($('paappEvents_eventType_0').checked == true) {
				opt_eventType = $F('paappEvents_eventType_0');
			} else if ($('paappEvents_eventType_1').checked == true) {
				opt_eventType =  $F('paappEvents_eventType_1');
			}
			
		// Capacity
			if ( isNaN($F('paappEvents_capacityPublic')) || $F('paappEvents_capacityPublic') == "" ) {
				opt_capacityPublic = 0
			} else {
				opt_capacityPublic = parseInt($F('paappEvents_capacityPublic'));
			}
			
			if ( isNaN($F('paappEvents_capacityAdmin')) || $F('paappEvents_capacityAdmin') == "" ) {
				opt_capacityAdmin = 0
			} else {
				opt_capacityAdmin = parseInt($F('paappEvents_capacityAdmin'));
			}
			
			
		// Majors
			var opt_majors = new Array();
			for (i=0;i<array_paMajors.length;i++) {
				if ($('paappEvents_appTypes_'+array_paMajors[i]).checked === true) {
					// Mark var as 1
						opt_majors[i] = 1;
				} else {
					// Mark var as 0
						opt_majors[i] = 0;
				}
			}
			
		// AppStatus
			// Enroll Type
				// Freshman
					if ($('paappEvents_appStatus_enrollType_frosh').checked === true) {
						opt_enrollType_frosh = 1;
					} else {
						opt_enrollType_frosh = 0;
					}
				// Transfer
					if ($('paappEvents_appStatus_enrollType_trans').checked === true) {
						opt_enrollType_trans = 1;
					} else {
						opt_enrollType_trans = 0;
					}
				
			// App Type
				// Early Action
					if ($('paappEvents_appStatus_appType_ea').checked === true) {
						opt_appStatus_ea = 1;
					} else {
						opt_appStatus_ea = 0;
					}
				// Regular Action
					if ($('paappEvents_appStatus_appType_ra').checked === true) {
						opt_appStatus_ra = 1;
					} else {
						opt_appStatus_ra = 0;
					}
					
		// Options
			// Overflow
				if ($('paappEvents_appOptions_overflow').checked === true) {
					opt_options_overflow = 1;
				} else {
					opt_options_overflow = 0;
				}
			
		
		// Date/Time
			// Total Slots
				opt_eventTimeSlots = parseInt($F('paappEvents_addedTimes_total'));
			
			// Options - Event time slots
	
	// Push vars to Ajax form
	
		opt_fullPostVars = "";
		
		opt_fullPostVars += "&locationID="+opt_locationID;
		opt_fullPostVars += "&eventType="+opt_eventType;
		opt_fullPostVars += "&capacityPublic="+opt_capacityPublic;
		opt_fullPostVars += "&capacityAdmin="+opt_capacityAdmin;
		opt_fullPostVars += "&enrollType_frosh="+opt_enrollType_frosh;
		opt_fullPostVars += "&enrollType_trans="+opt_enrollType_trans;
		opt_fullPostVars += "&enrollType_ea="+opt_appStatus_ea;
		opt_fullPostVars += "&enrollType_ra="+opt_appStatus_ra;
		opt_fullPostVars += "&options_overflow="+opt_options_overflow;
		
		for (i=0;i<array_paMajors.length;i++) {
			opt_fullPostVars += "&major_"+array_paMajors[i]+"="+opt_majors[i];
		}
		
		opt_fullPostVars += "&eventTimeSlots="+opt_eventTimeSlots;
		
		for (i=0;i<opt_eventTimeSlots;i++) {
			// directly inject data into the complete vars
			// Pull UNIX Time
				temp_addedTimeUnix = new Date(parseInt($F('paappEvents_addedTimes_value_'+i)));
			// Format tricky parts
				// Month
					if ( (1 + temp_addedTimeUnix.getMonth()) < 10) {
						temp_addedTimeUnix_month = "0"+(temp_addedTimeUnix.getMonth()+1);
					} else {
						temp_addedTimeUnix_month = (temp_addedTimeUnix.getMonth()+1);
					}
				// Date
					if ( temp_addedTimeUnix.getDate() < 10) {
						temp_addedTimeUnix_date = "0"+temp_addedTimeUnix.getDate();
					} else {
						temp_addedTimeUnix_date = temp_addedTimeUnix.getDate();
					}
				// Hour
					if ( temp_addedTimeUnix.getHours() < 10) {
						temp_addedTimeUnix_hours = "0"+temp_addedTimeUnix.getHours();
					} else {
						temp_addedTimeUnix_hours = temp_addedTimeUnix.getHours();
					}
				// Miniues
					if ( temp_addedTimeUnix.getMinutes() < 10) {
						temp_addedTimeUnix_minutes = "0"+temp_addedTimeUnix.getMinutes();
					} else {
						temp_addedTimeUnix_minutes = temp_addedTimeUnix.getMinutes();
					}
									
			// Publish new time entry
				opt_fullPostVars += "&eventTime_"+i+"="+temp_addedTimeUnix.getFullYear()+'-'+temp_addedTimeUnix_month+'-'+temp_addedTimeUnix_date+' '+temp_addedTimeUnix_hours+':'+temp_addedTimeUnix_minutes+':00';
		}
		
		//alert(opt_fullPostVars);
	
	// Post the findings
		var addLocation_submit_ajax = new Ajax.Request(
		ajaxurl_root,
		{
			method: 'post',
			parameters: "&id=events_addEvent"+opt_fullPostVars,
			onComplete: addEvent_loadConfirm,
			onFailure: function(x) { alert("Something's wrong."); $('debug').innerHTML = x.responseText; }
		}
		);
}

function addEvent_loadConfirm(originalRequest) {
	
	// Phaze XML to usable data
		//$('debug').value = originalRequest.responseText;
		var phazed_xml = originalRequest.responseXML.getElementsByTagName('paapp');
		
	// Let's make all the vars managaable:
		if (phazed_xml[0].getElementsByTagName('status')[0].firstChild != null) {
			var addEvent_alert = phazed_xml[0].getElementsByTagName('status')[0].firstChild.data;
		}
	
	alert("Good Load: "+addEvent_alert);
	
	
	
}
function addLocation_check() {
	
	//Bypass Validation - not working
	addLocation_submit();
	
	/*
	// TinyMCE Trigger
		//tinyMCE.triggerSave();

	//alert('trying to validate');
	
	var check = new Array();
	
		check[0] = false; // DisplayName
		check[1] = false; // DisplayInfo
		check[2] = false; // Address 1
		check[3] = false; // City
		check[4] = false; // State
		check[5] = false; // Zip
	
	// Check for not-nulls
	
	if ($F('paappEventsLocation_displayName').length < 4) {
		check[0] = true;
	}
	
	if ($F('paappEventsLocationDisplayInfo').length < 11) {
		check[1] = true;
	}
	
	if ($F('paappEventsLocation_address_1').length < 3) {
		check[2] = true;
	}
	
	if ($F('paappEventsLocation_city').length < 4) {
		check[3] = true;
	}
	
	//if ($('paappEventsLocation_state').options[$('paappEventsLocation_state').selectedIndex].value == "") {
	if ($F('paappEventsLocation_state') == "" || $F('paappEventsLocation_state') == "--") {
		check[4] = true;
	}
	
	if ($F('paappEventsLocation_zip').length < 5) {
		check[5] = true;
	}
	
	
		if ( check.any (function(x) {if (x === false) {status = false;} else {status = true;}return x;}) === true) {
			
			var alertRun = "";
			var alertRunCount = 0;
			
			alertRun = (check.any (function(x) {if (x === false) {status = false;} else {status = true;}return x;}))+"\n\n";
			
			check.each (function(member) {
								if (member === true) {
									alertRun += "\n"+alertRunCount+": "+member;
									action = 1;
								} else {
									action = 0;
								}
								addLocation_check_displaySwitch(alertRunCount,action);
								alertRunCount++;
							} ) ;
			
			// Something is wrong
				alert("Failed!\n"+alertRun);
			
			//addEvent_alert('paappEvents_general',null,1);
		} else {
			// All is well
				check.each (function(member) {
									addLocation_check_displaySwitch(alertRunCount,0);
									alertRunCount++;
								} ) ;
			//addEvent_alert('paappEvents_general',null,0);
			addLocation_submit();
		}
	*/	
	
}

function addLocation_check_displaySwitch(alertID,action,other) {
	
	if (other == undefined) {
		other = 0;
	}
	
	switch(alertID) {
		
		case 0:
			// DisplayName
				addEvent_alert('paappEventsLocation_displayName','Please enter the name of the location.',action);
				break;
				
		case 1:
			// DisplayInfo
				addEvent_alert('paappEventsLocation_displayInfo','Please include information on the location.',action);
				break;
				
		case 2:
			// Address_1
				addEvent_alert('paappEventsLocation_address_1','Please include the full address of the location.',action);
				break;
				
		case 3:
			// City
				addEvent_alert('paappEventsLocation_city','Please include the full address of the location.',action);
				break;
			
		case 4:
			// State
				addEvent_alert('paappEventsLocation_state','Please include the full address of the location.',action);
				break;
			
		case 5:
			// Zip
				addEvent_alert('paappEventsLocation_zip','Please include the full address of the location.',action);
				break;
						
		default:
			// Catch-all
				break;
			
	}
	
}


function addLocation_submit() {

	//alert('trying to submit');
	
	// Gather up all the vars
		var addLocation_opts_displayName = $F('paappEventsLocation_displayName');
		var addLocation_opts_displayInfo = encodeURIComponent($F('paappEventsLocationDisplayInfo'));
		var addLocation_opts_address_1 = $F('paappEventsLocation_address_1');
		var addLocation_opts_address_2 = $F('paappEventsLocation_address_2');
		var addLocation_opts_address_3 = $F('paappEventsLocation_address_3');
		var addLocation_opts_address_4 = $F('paappEventsLocation_address_4');
		var addLocation_opts_city = $F('paappEventsLocation_city');
		var addLocation_opts_state = $F('paappEventsLocation_state');
		var addLocation_opts_zip = $F('paappEventsLocation_zip');
		var addLocation_opts_actionID = $F('location_id_select');

	/* Debug Form Vars
		alert('Form vars in JS' +
		'\n' + addLocation_opts_displayName +
		'\n' + addLocation_opts_displayInfo +
		'\n' + addLocation_opts_address_1 +
		'\n' + addLocation_opts_address_2 +
		'\n' + addLocation_opts_address_3 +
		'\n' + addLocation_opts_address_4 +
		'\n' + addLocation_opts_city +
		'\n' + addLocation_opts_state +
		'\n' + addLocation_opts_zip +
		'\n' + addLocation_opts_actionID);
		*/

	// Create the opts var
		var addLocation_submit_ajax_opts = "&displayName=" + addLocation_opts_displayName +
											"&displayInfo=" + addLocation_opts_displayInfo +
											"&address_1=" + addLocation_opts_address_1 +
											"&address_2=" + addLocation_opts_address_2 +
											"&address_3=" + addLocation_opts_address_3 +
											"&address_4=" + addLocation_opts_address_4 +
											"&city=" + addLocation_opts_city +
											"&state=" + addLocation_opts_state +
											"&zip=" + addLocation_opts_zip +
											"&actionID=" + addLocation_opts_actionID;
	
	// Make the post
		var addLocation_submit_ajax = new Ajax.Request(
				ajaxurl_root,
				{
					method: 'post',
					parameters: "&id=events_addLocation"+addLocation_submit_ajax_opts,
					onComplete: addLocation_loadConfirm,
					onFailure: function(x) { alert("Something's wrong."); $('debug').innerHTML = x.responseText; }
				}
				);

		//alert('Past AJAX Post!');
		
}

function addLocation_reset() {
	// Reseting addLocation form	
}

function addLocation_loadConfirm(originalRequest) {
	
	// Phaze XML to usable data
		//$('debug').value = originalRequest.responseText;
		var phazed_xml = originalRequest.responseXML.getElementsByTagName('paapp');
		
	// Let's make all the vars managaable:
		if (phazed_xml[0].getElementsByTagName('status')[0].firstChild != null) {
			var addLocation_alert = phazed_xml[0].getElementsByTagName('status')[0].firstChild.data;
		}
	
	if (addLocation_alert == 0) {
		paappLocation_action(2);
	} else {
		alert(addLocation_alert);
	}
	
}


function pickEvent(id,locationID, viaPhone) {
	
	// Text Display
		$('pickedSlot_display').innerHTML = $F('slot_'+id) + '<br />' + $('schedule_'+locationID+'_title').innerHTML;
		
	// Input changes
		$('slotID').value = id;
	
	// Special Effects
		new Effect.BlindUp('schedule_listing');
		new Effect.BlindDown('schedule_confirm');
		scrollWindowFix('emerson_body_fix');

	// Display Phone Form or In-Person option
	if(viaPhone){
		//Phone
		pickEventPhone();
	} else {
		//In-Person
		pickEventConfirm();
	}
	
}

function pickEventCancel() {
	
	new Effect.BlindDown('schedule_listing');
	new Effect.BlindUp('schedule_confirm');
	
}

function pickEventConfirm_phone() {
	
	// Check if form is filled out
	if ($F('country_code') == 1 && ($F('phonenumber_area') == "" & $F('phonenumber_main1') == "" & $F('phonenumber_main2') == "") ) {
		// Fail; Not a number
			alert("Please enter your phone number so we can contact you.");
			return false;
	} else if ( $F('country_code') != 1 && $F('phonenumber_nus') == "") {
		// Fail; Not a number
			alert("Please enter your phone number so we can contact you.");
			return false;
	} else {
			return true;
	}
	
}

function pickEvent_countrySelect() {
	
	// Standard vars
		var displayUSPhone = "pickEventConfirmPhone_us";
		var displayNUSPhone = "pickEventConfirmPhone_nus";
		var displayDiv = "pickEventConfirmPhone_nusCode";
		var oldDisplayValue = $(displayDiv).innerHTML;
		var displayVars = {duration:0.2};
		
	// Pull out value
		var countryCode = $F('country_code');
	
	// Inject into HTML
		$(displayDiv).innerHTML = "+ "+countryCode;
	
	// Display
		if (countryCode == 1) {
			// US Number
				if (Element.visible(displayUSPhone) === false) {
					// Show US
						new Effect.BlindDown(displayUSPhone,displayVars);
				}
				if (Element.visible(displayNUSPhone) === true) {
					// Hide Non-US
						new Effect.BlindUp(displayNUSPhone,displayVars);
				}
		} else {
			// Non-US Number
				if (Element.visible(displayUSPhone) === true) {
					// Show US
						new Effect.BlindUp(displayUSPhone,displayVars);
				}
				if (Element.visible(displayNUSPhone) === false) {
					// Hide Non-US
						new Effect.BlindDown(displayNUSPhone,displayVars);
				} else {
					// Highlight phone code change
						new Effect.Highlight(displayNUSPhone);
				}
		}
}

function pickEventConfirm() {
	
	var pickEventConfirm_alert = false;
	
	// Are we gathering extra information?
	if ( $F('slotType') == 1) {
		// Yes, but what country?
			if ($F('country_code') == 1) {
				// US number
				if ($F('phonenumber_area') == "" | $F('phonenumber_main1') == "" | $F('phonenumber_main2') == "") {
					// Fail is not
						alert("Please enter your phone number so we can contact you.");
						pickEventConfirm_alert = true;
				} else {
					// Create full number
						var slotExtra1 = "("+$F('phonenumber_area')+") "+$F('phonenumber_main1')+"-"+$F('phonenumber_main2');
					// Check for an extention and add if present
						if ($F('phonenumber_us_ext') != "") {
							slotExtra1 = slotExtra1 + " ext. " + $F('phonenumber_us_ext');
						}
				}
			} else {
				// Non-US number
					if ($F('country_code') == "") {
						alert("Please enter your phone number so we can contact you.");
						pickEventConfirm_alert = true;
					} else {
						// Create full number
							var slotExtra1 = "[["+$F('country_code')+"]] "+$F('phonenumber_nus');
						// Check for an extention and add if present
							if ($F('phonenumber_nus_ext') != "") {
								slotExtra1 = slotExtra1 + " ext. " + $F('phonenumber_nus_ext');
							}
					}
			}
			
	} else {
		// A regular booking.
			var slotExtra1 = "";
	}
	
	if (pickEventConfirm_alert === false) {
		// Build Ajax Vars string
			opt_pickEventCofirm_keyID = '&major='+$F('major')+'&slotID='+$F('slotID')+'&slotType='+$F('slotType')+'&booked_prop1='+slotExtra1;
		
		// Display Prep
			if (Element.visible('schedule_confirm') === true) {
				new Effect.BlindUp('schedule_confirm');
			}
			if (Element.visible('schedule_process') === false) {
				new Effect.BlindDown('schedule_process');
			} else {
				$('schedule_process_title').innerHTML = "Loading...";
				$('schedule_process_info').innerHTML = "&nbsp;";
				new Effect.Highlight('schedule_process_title');
			}
		
		// Make the post
			var addLocation_submit_ajax = new Ajax.Request(
					ajaxurl_root,
					{
						method: 'post',
						parameters: "&id=events_saveSlot"+opt_pickEventCofirm_keyID,
						onSuccess: pickEventConfirm_success,
						onFailure: pickEventConfirm_failure
					}
					);
	} else {
		//return false;
	}
}

function pickEventConfirm_success(x) {
	
	// Phaze XML to usable data
		var phazed_xml = x.responseXML.getElementsByTagName('paapp');
		
	// Let's make all the vars managaable:
		if (phazed_xml[0].getElementsByTagName('status')[0].firstChild != null) {
			var pickEventConfirm_alert = phazed_xml[0].getElementsByTagName('status')[0].firstChild.data;
		}
	
	// Process the results
		if (pickEventConfirm_alert == 0) {
			// Slot is saved.
				$('schedule_process_title').innerHTML = "<span style='color:#33cc00;'>Success!</span>";
				$('schedule_process_info').innerHTML = "<p>Your registration slot has been saved. <a href='/?id=main'>Please return to your homepage for information about preparing.</a></p>";
		} else if (pickEventConfirm_alert == 1) {
			// Required information not sent
				$('schedule_process_title').innerHTML = "<span style='color:#ff0000;'>Failure! (#1)</span>";
				$('schedule_process_info').innerHTML = "<p>All of the required information wasn't sent. <a href='/?id=booking_list'>Please reload this page and try again.</a></p>";
		} else if (pickEventConfirm_alert == 2) {
			// All slots are filled.
				$('schedule_process_title').innerHTML = "<span style='color:#ff0000;'>Slot Booked!</span>";
				$('schedule_process_info').innerHTML = "<p>The slot you tried to book has reached capacity. <a href='/?id=booking_list'>Please reload this page and select another slot.</a></p>";
		} else if (pickEventConfirm_alert == 3) {
			// All slots are filled.
				$('schedule_process_title').innerHTML = "<span style='color:#ff0000;'>Login Expired!</span>";
				$('schedule_process_info').innerHTML = "<p>Your login session has expired. <a href='/?id=booking_list'>Please login and try again.</a></p>";
		} else if (pickEventConfirm_alert == 4) {
			// Required information not sent
				$('schedule_process_title').innerHTML = "<span style='color:#ff0000;'>Failure! (#1)</span>";
				$('schedule_process_info').innerHTML = "<p>All of the required information wasn't sent. <a href='/?id=booking_list'>Please reload this page and try again.</a></p>";
		} else {
			// Catch-all fail
				$('schedule_process_title').innerHTML = "<span style='color:#ff0000;'>Error #"+pickEventConfirm_alert+"</span>";
				$('schedule_process_info').innerHTML = "<p>A problem has occured. Please check your internet connection, <a href='javascript:pickEventConfirm();'>then try again</a>.</p>";
		}
				
	
}

function pickEventConfirm_failure(x) {
	
	alert("pickEventConfirm(); Failed");
	$('schedule_process_title').innerHTML = "An error has occured.";
	$('schedule_process_info').innerHTML = "<p>A problem has occured. Please check your internet connection, <a href='javascript:pickEventConfirm();'>then try again</a>.</p>";
	$('debug').innerHTML = x.responseText;
	
}

function pickEventPhone() {
	
	// Change hidden value
		$('slotType').value = 1;
	
	// Hide 'In person' link
		if (Element.visible('pickEventConfirmInperson') === true) {
			new Effect.BlindUp('pickEventConfirmInperson',{duration:0.5});
		}
		
	// Display phone instructions and phone slot.
		if (Element.visible('pickEventConfirmPhone') === false) {
			new Effect.BlindDown('pickEventConfirmPhone',{duration:0.8});
		}
		
}

function paappLocation_pullLocationEdit(id) {
	
	var locationID = id;
	
	//Debug Location ID
	//alert('pa_booking.js/paappLocation_pullLocationEdit()\nID:' + locationID);
	
			var getLocationInfoAjax = new Ajax.Request(
				
				ajaxurl_root,
				{
					method: 'post',
					parameters: "&id=events_getLocations&keyID="+locationID,
					onComplete: addEvent_loadEditLocationExport,
					onFailure: function(x) { alert("paappLocation_pullLocationEdit(); Something's wrong. Location ID:" + locationID); }
				}
				);
}

function addEvent_loadEditLocationExport(originalRequest) {
	
	// Phaze XML to usable data
		//$('debug').value = originalRequest.responseText;
		var phazed_xml = originalRequest.responseXML.getElementsByTagName('paapp');
		
	// Let's make all the vars managaable:
		if (phazed_xml[0].getElementsByTagName('displayName')[0].firstChild != null) {
			$('paappEventsLocation_displayName').value = phazed_xml[0].getElementsByTagName('displayName')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('displayInfo')[0].firstChild != null) {
			$('paappEventsLocationDisplayInfo').value = phazed_xml[0].getElementsByTagName('displayInfo')[0].firstChild.data;
			// This wakes up TinyMCE
				//tinyMCE.updateContent('paappEventsLocationDisplayInfo');
		}
		if (phazed_xml[0].getElementsByTagName('address_1')[0].firstChild != null) {
			$('paappEventsLocation_address_1').value = phazed_xml[0].getElementsByTagName('address_1')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('address_2')[0].firstChild != null) {
			$('paappEventsLocation_address_2').value = phazed_xml[0].getElementsByTagName('address_2')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('address_3')[0].firstChild != null) {
			$('paappEventsLocation_address_3').value = phazed_xml[0].getElementsByTagName('address_3')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('address_4')[0].firstChild != null) {
			$('paappEventsLocation_address_4').value = phazed_xml[0].getElementsByTagName('address_4')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('city')[0].firstChild != null) {
			$('paappEventsLocation_city').value = phazed_xml[0].getElementsByTagName('city')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('state')[0].firstChild != null) {
			$('paappEventsLocation_state').value = phazed_xml[0].getElementsByTagName('state')[0].firstChild.data;
		}
		if (phazed_xml[0].getElementsByTagName('zip')[0].firstChild != null) {
			$('paappEventsLocation_zip').value = phazed_xml[0].getElementsByTagName('zip')[0].firstChild.data;
		}

	
}

function paappLocation_action(action) {
	
	var formName = 'paappLocation_form';
	var locationid_id = 'location_id_select';
	var div_formDisplay_1 = 'paappLocation_action';
	var div_formDisplay_2 = 'paappLocation_editing';
	var div_formDisplay_3 = 'paappLocation_message';
	var div_formDisplay_3_title = 'paappLocation_message_title';
	var div_formDisplay_3_message = 'paappLocation_message_message';

	//Debug Action Vars
	//alert('pa_booking.js/paappLocation_action()\naction:' + action+ '\nlocationid_id:' + $F(locationid_id));
	
	
	if (action == 1) {
		/*
			After selection either an existing or new location, either show the current values of the location
				or a clean form for a new location.
		*/
	
		if ( $F(locationid_id) == "new") {
			// New location wanted. Make sure the form is clean and show it.
				
				// Display Form
					new Effect.BlindUp(div_formDisplay_1);
					new Effect.BlindDown(div_formDisplay_2);
					new Effect.BlindUp(div_formDisplay_3);
		} else if ( $F(locationid_id) > 0) {
			// Existing location. Clean form, pull new data, then show it.
				
				// Pull data
					paappLocation_pullLocationEdit($F(locationid_id));
				
				// Display Form
					new Effect.BlindUp(div_formDisplay_1);
					new Effect.BlindDown(div_formDisplay_2);
					new Effect.BlindUp(div_formDisplay_3);
		} else {
			// Catch-all.
			alert('Bad event location ID:' + $F(locationid_id));
		}
	
	} else if ( action == 2 ) {
		
		if ($F(locationid_id) == "new") {
			
			$(div_formDisplay_3_title).innerHTML = "New Location";
			$(div_formDisplay_3_message).innerHTML = "<b>" + $F('paappEventsLocation_displayName')+"</b> is now available. You may <a href='/?id=events_modify'>add new events</a>, <a href='javascript:paappLocation_action();'>add/edit more locations</a>, or <a href='/?id=admin_home'>return to the Admin home</a>.";
			//alert("paappLocation_action(2); && "+$F(locationid_id));
			
		} else {
			
			$(div_formDisplay_3_title).innerHTML = "Location Update";
			$(div_formDisplay_3_message).innerHTML = "<b>" + $F('paappEventsLocation_displayName')+"</b> has been updated. You may <a href='/?id=events_modify'>add new events</a>, <a href='/?id=events_addlocation'>add/edit more locations</a>, or <a href='/?id=admin_home'>return to the Admin home</a>.";
			
		}
		
		// Hide everything but the last display
			new Effect.BlindUp(div_formDisplay_1);
			new Effect.BlindUp(div_formDisplay_2);
			new Effect.BlindDown(div_formDisplay_3);
			
		// Reset the form
			Form.reset('paappLocation_form');
			
	} else {
		/*
			Catch-all. Resets to new orginal state
		*/
		
		// Reset the form
			Form.reset('paappLocation_form');
		// Hide everything but the first display
			new Effect.BlindDown(div_formDisplay_1);
			new Effect.BlindUp(div_formDisplay_2);
			new Effect.BlindUp(div_formDisplay_3);
			
	}
	
}

function cancelEvent() {
	// Hide everything and display the cancel confirm box
	new Effect.BlindUp('schedule_listing');
	new Effect.BlindDown('schedule_cancel');
}

function cancelEventCancel() {
	// Hide confirm and show orginal display
	new Effect.BlindDown('schedule_listing');
	new Effect.BlindUp('schedule_cancel');
}

function cancelEventConfirm() {
	// Gather up vars
		opt_cancelEventConfirm_keyID = '&action=cancel&major='+$F('major');
	
	// Display Prep
		if (Element.visible('schedule_cancel') === true) {
			new Effect.BlindUp('schedule_cancel');
		}
		if (Element.visible('schedule_process') === false) {
			new Effect.BlindDown('schedule_process');
		} else {
			$('schedule_process_title').innerHTML = "Loading...";
			$('schedule_process_info').innerHTML = "&nbsp;";
			new Effect.Highlight('schedule_process_title');
		}
	
	// Make the post
		var addLocation_submit_ajax = new Ajax.Request(
				ajaxurl_root,
				{
					method: 'post',
					parameters: "&id=events_saveSlot"+opt_cancelEventConfirm_keyID,
					onSuccess: cancelEventConfirm_success,
					onFailure: cancelEventConfirm_failure
				}
				);
	
}

function cancelEventConfirm_success(x) {
	
	// Phaze XML to usable data
		var phazed_xml = x.responseXML.getElementsByTagName('paapp');
		
	// Let's make all the vars managaable:
		if (phazed_xml[0].getElementsByTagName('status')[0].firstChild != null) {
			var pickEventConfirm_alert = phazed_xml[0].getElementsByTagName('status')[0].firstChild.data;
		}
	
	// Process the results
		if (pickEventConfirm_alert == 0) {
			// Slot is saved.
				$('schedule_process_title').innerHTML = "Success!";
				$('schedule_process_info').innerHTML = "<p>Your registration slot has been canceled. You may still <a href='/?id=booking_list'>book a new slot</a> or <a href='/?id=main'>return to your checklist</a>.</p>";
		} else {
			// Catch-all fail
				$('schedule_process_title').innerHTML = "<span style='color:#ff0000;'>Error #"+pickEventConfirm_alert+"</span>";
				$('schedule_process_info').innerHTML = "<p>A problem has occured. Please check your internet connection, <a href='javascript:cancelEventConfirm();'>then try again</a>.</p>";
		}
				
	
}

function cancelEventConfirm_failure(x) {
	
	$('schedule_process_title').innerHTML = "An error has occured.";
	$('schedule_process_info').innerHTML = "<p>A problem has occured. Please check your internet connection, <a href='javascript:cancelEventConfirm();'>then try again</a>.</p>";
	$('debug').innerHTML = x.responseText;
	
}

function guidelinesCheck() {
	
	// Loading display
		$('guidelinesCheckStatus_checked').style.display = "none";
		$('guidelinesCheckStatus_unchecked').style.display = "none";
		$('guidelinesCheckStatus_loading').style.display = "inline";
		$('guidelinesCheck_text').innerHTML = "Loading...";
		
	// Vars build
		ajax_guidelinesChecked = $F('guidelinesChecked');
		ajax_checkType = $F('checkType');
		ajax_major = $F('major');
	// Complete var builder
		ajax_opts = "&id=file_guidelines&guidelinesChecked="+ajax_guidelinesChecked+"&checkType="+ajax_checkType+"&major="+ajax_major;
	
	// Make the post
		var guidelinesCheck_submit_ajax = new Ajax.Request(
				ajaxurl_root,
				{
					method: 'post',
					parameters: ajax_opts,
					onSuccess: guidelinesCheck_success,
					onFailure: guidelinesCheck_failure
				}
				);
}

	function guidelinesCheck_success(x) {
	
	// Phaze XML to usable data
		var phazed_xml = x.responseXML.getElementsByTagName('paapp');
		
	// Let's make all the vars managaable:
		if (phazed_xml[0].getElementsByTagName('code')[0].firstChild != null) {
			var xml_code = phazed_xml[0].getElementsByTagName('code')[0].firstChild.data;
			var xml_type = phazed_xml[0].getElementsByTagName('type')[0].firstChild.data;
			//alert("Code: "+xml_code+"\nType: "+xml_type);
		} else {
			//alert("Nope.");
		}
		
		if (xml_code == 0) {
			// Turn off checkmark
				$('guidelinesCheckStatus_checked').style.display = "none";
				$('guidelinesCheckStatus_unchecked').style.display = "inline";
				$('guidelinesCheckStatus_loading').style.display = "none";
				$('guidelinesCheck_text').innerHTML = "You have unchecked this step. You can always visit this page again for a refresher, if needed. <a href='/?id=main'>Please return to your checklist.</a>";
			// Change hidden
				$('guidelinesChecked').value = 0;
		} else if (xml_code == 1) {
			// Turn on checkmark
				$('guidelinesCheckStatus_checked').style.display = "inline";
				$('guidelinesCheckStatus_unchecked').style.display = "none";
				$('guidelinesCheckStatus_loading').style.display = "none";
				$('guidelinesCheck_text').innerHTML = "Thank you for reading the "+xml_type+". You can always visit this page again for a refresher, if needed. <a href='/?id=main'>Please return to your checklist.</a>";
				$('guidelinesChecked').value = 1;
		}
		
			
	}
	
	function guidelinesCheck_failure(x) {
		
		$('debug').innerHTML = x.responseText;
		
	}