function Caller2Student() {
	if(document.forms[0].copy.checked) {
		document.forms[0].stdnt_fname.value = document.forms[0].call_fname.value;
		document.forms[0].stdnt_lname.value = document.forms[0].call_lname.value;
	} else {
		document.forms[0].stdnt_fname.value = null;
		document.forms[0].stdnt_lname.value = null;
	}
}

// expand/collapse content script
function getObject(id) {
	if(document.getElementById) {
		return document.getElementById(id);
	} else if (document.all) {
		return document.all[id];
	} else if (document.layers) {
		return document.layers[id];
	}
}

function toggleExpand(link, divId) {
	var l = getObject(link);
	var d = getObject(divId);

	if(d.style.display == 'none') {
		d.style.display = 'block';
	} else {
		d.style.display = 'none';
	}
}

function toggleExpand2(divId, link) {
	var d = getObject(divId);
	var l = getObject(link);

	if(d.style.display == 'none') {
		d.style.display = 'block';
		l.className = 'arrowexpand2';
	} else {
		d.style.display = 'none';
		l.className = 'arrowexpand';
	}
}

function Expand(divId) {
	var d = getObject(divId);

	if(d.style.display == 'none') {
		d.style.display = 'block';
	}
}

function Collapse(divId) {
	var d = getObject(divId);

	if(d.style.display == 'block') {
		d.style.display = 'none';
	}
}

function checkSelect(id, num) {
	var obj = getObject(id);
	var i = num;

	if(obj.value != '')	// hall selected, show next option
		Expand('move_bt_halls_xtra' + num);
	
	else {			// hall is blank, collapse all divs under it
		while(i <= 5) {
			Collapse('move_bt_halls_xtra' + i);
			// clear all values of collapsed divs
			clearCollapseValue('move_bt_halls' + i);
			clearCollapseValue('move_bt_specific' + i);
			clearCollapseValue('move_bt_specific' + i + '_floor_num');
			clearCollapseValue('move_bt_specific' + i + '_room_num');
			clearCollapseValue('move_bt_specific' + i + '_roommate');
			clearCollapseValue('move_bt_anywhere' + i);
			clearCollapseValue('move_bt_specific' + i + '_floor_num');
			i++;
		}
	}
}

function clearCollapseValue(id) {
	var obj = getObject(id);
	
	if(obj.value != '')
		obj.value = '';
	
	if(obj.checked)
		obj.checked = '';
}

function toggleHighlight(id, form_id, status) {
	if(status == 'on') {
		document.forms[form_id].elements[id].style.backgroundColor = '#ffffe5';
	} else {
		document.forms[form_id].elements[id].style.backgroundColor = '#ffffff';
	}
}

function collapseOthers(id, form_id) {
	var t = getObject('trade');
	var s = getObject('specific');
	if(id == 'move_w_anywhere') {
		document.forms[form_id].elements[t].style.display = 'none';
		document.forms[form_id].elements[s].style.display = 'none';
	}
}

function clearValue(id, form_id) {
	document.forms[form_id].elements[id].value = '';
}

function getHallName(hid) {
	var hall = new Object();
	var hallname;
	
	hall[2] = 'Cramer';
	hall[4] = 'Discovery';
	hall[5] = 'Excellence';
	hall[7] = 'Gillett';
	hall[9] = 'Hatch';
	hall[10] = 'Hudson';
	hall[11] = 'Johnston';
	hall[12] = 'Jones';
	hall[13] = 'Lathrop';
	hall[14] = 'Laws';
	hall[15] = 'Mark Twain';
	hall[16] = 'McDavid';
	hall[17] = 'Respect';
	hall[18] = 'Responsibility';
	hall[19] = 'Schurz';
	hall[20] = 'Stafford';
	hall[21] = 'Wolpers';
	hall[22] = 'North';
	hall[23] = 'Center';
	hall[24] = 'South';
	hall[25] = 'College Avenue';
	hall[26] = 'Mizzou Quads';
	hall[27] = 'Tiger Diggs';
	hall[28] = 'Defoe-Graham';
	hall[29] = 'Dogwood';
	hall[30] = 'Galena';
	hall[31] = 'Hawthorn';
	
	for (index in hall) {
		if (index == hid) {
			hallname = hall[index];
		}
	}
	return hallname;
}

function showOfferEmails(id1, id2, form_id, stdnt_name, admin_name, admin_email, admin_phone){
	var email1 = getObject(id1);
	var email2 = getObject(id2);
	var room_num = document.forms[form_id].elements['room_num'].value;
	if (document.forms[form_id].elements['room_part'].value != '') 
		var room_num = room_num + ' ' + document.forms[form_id].elements['room_part'].value;
	var room_part = document.forms[form_id].elements['room_part'].value;
	var hall = document.forms[form_id].elements['hall'].value;
	hall = getHallName(hall);
	var roommate = document.forms[form_id].elements['roommate'].value;
	var roommate2 = document.forms[form_id].elements['roommate2'].value;
	var roommate3 = document.forms[form_id].elements['roommate3'].value;
	var roommate_email = document.forms[form_id].elements['roommate_email'].value;
	var roommate_email2 = document.forms[form_id].elements['roommate_email2'].value;
	var roommate_email3 = document.forms[form_id].elements['roommate_email3'].value;
	var phone1 = document.forms[form_id].elements['phone1'].value;
	var phone2 = document.forms[form_id].elements['phone2'].value;
	var phone3 = document.forms[form_id].elements['phone3'].value;
	var date_yr = document.forms[form_id].elements['date_yr'].value;
	var date_mo = document.forms[form_id].elements['date_mo'].value;
	var date_day = document.forms[form_id].elements['date_day'].value;
	var d = new Date(date_yr, date_mo - 1, date_day);
	
	// check required fields
	if (room_num == '' || hall == '' || ((date_yr == '' || date_yr == 'yyyy') && (date_mo == '' || date_mo == 'mm') && (date_day == '' || date_day == 'dd'))) {
		alert('Please fill out all required fields.');
		return 0;
	}
	
	// get day name
	var weekdays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];
	var day_deadline = weekdays[d.getDay()];
	// get month name
	var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
	var date_deadline = months[d.getMonth()] + ' ' + date_day;
	
	var phone_num = '(' + phone1 + ') ' + phone2 + '-' + phone3;
	
	// remove backslash from names
	re = /\\/g;
	stdnt_name = stdnt_name.replace(re, "");
	admin_name = admin_name.replace(re, "");
	roommate = roommate.replace(re, "");
	roommate2 = roommate2.replace(re, "");
	roommate3 = roommate3.replace(re, "");
	
	// check roommate fields, store # of roommates
	var num_roommates = 0;
	if (roommate != '' && roommate_email != '') {
		num_roommates += 1;
	}
	if (roommate2 != '' && roommate_email2 != '') {
		num_roommates += 1;
	}
	if (roommate3 != '' && roommate_email3 != '') {
		num_roommates += 1;
	}
	
	// email to student
	email1.value = stdnt_name + ',' + "\n\n" + 'I have reviewed your room move request and I am happy to tell you I have room # ' + room_num + ' in ' + hall + ' Hall to offer to you.' + "\n\n";
	if (num_roommates > 0) {		
		email1.value = email1.value + 'You are welcome to try to meet your potential new ';
		if (num_roommates == 1) {
			email1.value = email1.value + 'roommate';
		} else {
			email1.value = email1.value + 'roommates';
		}
		email1.value = email1.value + ' to make sure it is a good fit for you. Your potential ';
		if (num_roommates == 1) {
			email1.value = email1.value + 'roommate\'s name is ' + roommate;
		} else {
			email1.value = email1.value + 'roommates\' names are ' + roommate;
			if (num_roommates == 2) {
				email1.value = email1.value + ' and ' + roommate2;
			} else {
				email1.value = email1.value + ', ' + roommate2 + ' and ' + roommate3;
			}
		}
		email1.value = email1.value + '. You may be able to find their contact information on the MU Web site directory. I have also contacted them to let them know you may be stopping by.' + "\n\n";
	}
	email1.value = email1.value + 'Please let me know by noon on ' + day_deadline + ', ' + date_deadline + ' whether or not you would like to move to this room. If so, I will e-mail you an approval to move as soon as I can, so you could begin moving immediately. If you decline the offer or if I do not hear from you by the deadline, I will offer the space to the next person on the list and keep looking for you.' + "\n\n" + 'Please let me know if you have any questions, and I look forward to hearing from you soon.' + "\n\n" + admin_name + "\n" + admin_email + "\n" + admin_phone;
	
	// email to roommate(s)
	if (num_roommates > 0) {
		if (roommate != '' && roommate_email != '') {
			email2.value = roommate;
		}
		if (roommate2 != '' && roommate_email2 != '') {
			if (roommate != '' && roommate_email != '') {
				email2.value = email2.value + ', ';
			}
			email2.value = email2.value + roommate2;
		}
		if (roommate3 != '' && roommate_email3 != '') {
			if ((roommate != '' && roommate_email != '') || (roommate2 != '' && roommate_email2 != '')) {
				email2.value = email2.value + ', ';
			}
			email2.value = email2.value + roommate3;
		}
		email2.value = email2.value + ',' + "\n\n" + 'This is a notice to inform you that you may have a new roommate soon. I have offered room # ' + room_num + ' in ' + hall + ' Hall as a potential new room to ' + stdnt_name + '. They may be contacting you or stopping by to see the room and meet you. Please be considerate and maintain a space that would be welcoming to a new resident who could move into the space at any time (See p. 99 of the Tiger Guide). Please make sure their side of the room is empty and clear of any of your belongings.' + "\n\n" + 'Thank you, in advance, for helping make another resident\'s experience positive! If you have comments, questions or concerns, please do not hesitate to contact me.' + "\n\n" + admin_name + "\n" + admin_email + "\n" + admin_phone;
	} else {
		email2.value = '';
	}
}

function showApproveEmails(id1, id2, form_id, room_num, hall, roommate, roommate2, roommate3, roommate_email, roommate_email2, roommate_email3, phone_num, day_deadline, date_deadline, stdnt_room_num, stdnt_hall, stdnt_name, admin_name, admin_email, admin_phone) {
	var email1 = getObject(id1);
	var email2 = getObject(id2);
	
	// remove backslash from names
	re = /\\/g;
	stdnt_name = stdnt_name.replace(re, "");
	admin_name = admin_name.replace(re, "");
	roommate = roommate.replace(re, "");
	roommate2 = roommate2.replace(re, "");
	roommate3 = roommate3.replace(re, "");
	
	// check roommate fields, store # of roommates
	var num_roommates = 0;
	if (roommate != '' && roommate_email != '') {
		num_roommates += 1;
	}
	if (roommate2 != '' && roommate_email2 != '') {
		num_roommates += 1;
	}
	if (roommate3 != '' && roommate_email3 != '') {
		num_roommates += 1;
	}
	
	// email to student
	email1.value = stdnt_name + ',' + "\n\n" + 'You have been approved to move from ' + stdnt_room_num + ' ' + getHallName(stdnt_hall) + ' Hall to ' + room_num + ' ' + getHallName(hall) + ' Hall.' + "\n\n";
	if (num_roommates > 0) {
		email1.value = email1.value + 'Please check with your new roommate';
		if (num_roommates > 1) {
			email1.value = email1.value + 's';
		}
		email1.value = email1.value + ' to coordinate your move-in. ';
	}
	email1.value = email1.value + 'If you have not done so already, please let your current roommate(s) know you are planning to move.' + "\n\n" + 'You may check into your new space before checking out of your current assignment.  Please be aware moving to another hall may result in an adjustment to billing charges.  You may begin your move on ' + day_deadline + ', ' + date_deadline + '.' + "\n\n" + 'Checking into your new space:' + "\n" + 'When you are ready to begin your move, come to the front desk for your new hall to check in. The Desk Attendant will provide the key and mailbox combination for your new room. We will create an emergency card for you. The DA will also give you a new Room Inventory and Condition Check (RICC) for your new room, and I recommend completing the check-in side of the RICC thoroughly and prior to moving anything into the room, so you can see any damages easier.' + "\n\n" + 'Checking out of your old space:' + "\n" + 'You must remove all your belongings out of your old space before you can check out. When you have all your belongings out of the space, please visit the front desk to officially check out. The DA will find a student staff member to complete the check-out side of your RICC. You will also confirm some myZou information and provide your forwarding address at the desk. We will update your emergency card, and you will turn in your key.  Please keep in mind you are not considered checked out--meaning you are still paying room and board charges--until you visit the front desk.' + "\n\n" + 'Unless you make prior arrangements with me, you will have until 8:00pm on ' + day_deadline + ', ' + date_deadline + ' to complete your move, including paperwork.' + "\n\n" + 'Please let me know if you choose to decline this authorization or if I can assist you in any other way. Good luck, and happy moving!' + "\n\n" + admin_name + "\n" + admin_email + "\n" + admin_phone;
	
	// email to roommate(s)
	if ((roommate != '' && roommate_email != '') || (roommate2 != '' && roommate_email2 != '') || (roommate3 != '' && roommate_email3 != '')) {
		if (roommate != '' && roommate_email != '') {
			email2.value = roommate;
		}
		if (roommate2 != '' && roommate_email2 != '') {
			if (roommate != '' && roommate_email != '') {
				email2.value = email2.value + ', ' + roommate2;
			}
		}
		if (roommate3 != '' && roommate_email3 != '') {
			if ((roommate != '' && roommate_email != '') || (roommate2 != '' && roommate_email2 != '')) {
				email2.value = email2.value + ', ' + roommate3;
			}
		}
		email2.value = email2.value + "\n\n" + 'A new roommate, ' + stdnt_name + ', has been approved to move into ' + room_num + ' ' + getHallName(hall) + ' Hall.  I don\'t yet know when they plan to move in, but I will let you know if I find out. Please be considerate and maintain a space that would be welcoming to a new resident, who could move in at any time (See p. 99 of the Tiger Guide). Thank you, in advance, for helping make another resident\'s experience positive!' + "\n\n" + 'If you have comments, questions or concerns, please do not hesitate to contact me.' + "\n\n" + admin_name + "\n" + admin_email + "\n" + admin_phone;
	}
}

function currentHallCheck(obj, obj2, obj3, curtime, targettime) {
	var hall = getObject(obj);
	var move_type_bt = getObject(obj2);

	if (hall.value == 7) {  // Hudson
		if (move_type_bt.disabled == true) {
			move_type_bt.disabled = false;
		}
	} else {
		if (curtime < targettime) {
			move_type_bt.disabled = true;
		}
	}
}
