// JavaScript Document

function dialogSetup()
{
	DialogManager = new DialogManagerObject();
	
	registerListener('keydown', closeTopDialog);
}

function closeTopDialog(event)
{
	var keycode = getKeyCode(event);
	
	if(keycode == 27 && DialogManager.closeTopDialog()) //Esc
	{
		stopEventPropagation(event);
	}
}

function DialogManagerObject()
{
	var me = this;
	this.dialogBase = document.getElementById('dialog_base');
	var dialogs = new Array();
	dialogs.get = function(id)
	{
		for(var i = 0; i < this.length; ++i)
		{
			if(this[i].id == id)
			{
				return this[i];
			}
		}
		return null;
	};
	
	this.getDialog = function(id)
	{
		return dialogs.get(id);
	};
	this.dialogCompare = function(d1, d2) //top dialog first
	{
		return d2.dialog.style.zIndex - d1.dialog.style.zIndex;
	};
	this.registerDialog = function(dialogObject)
	{
		me.dialogBase.appendChild(dialogObject.dialog);
		dialogs.push(dialogObject);
	};
	this.unregisterDialog = function(dialogObject)
	{
		me.dialogBase.removeChild(dialogObject.dialog);
		dialogs.remove(dialogObject);
	};
	this.destroyDialog = function(dialogObject)
	{
		me.unregisterDialog(dialogObject);
		delete dialogObject;
	};
	this.closeTopDialog = function()
	{
		if(dialogs.length > 0)
		{
			dialogs.sort(me.dialogCompare);
			dialogs[0].close();
			return true;
		}
		return false;
	};
	this.closeDialog = function(dialogObject, delay)
	{
		var closeTimeoutID = setTimeout('DialogManager.getDialog(\''+dialogObject.id+'\').close()', delay ? delay : 0);
		dialogObject.setVariable('closeTimeoutID', closeTimeoutID);
	};
}

function DialogObject(id, title, dBody, buttons, modal, width, top)
{
	var me = this;
	
	var oldDialog = DialogManager.getDialog(id);
	if(oldDialog)
	{
		DialogManager.destroyDialog(oldDialog);
	}
	
	// Main dialog
	this.dialog = document.createElement('div');
	this.modal = modal ? true : false;
	this.id = id;
	this.dialog.id = id;
	this.dialog.className = 'dialog_wrapper';
	this.dialog.style.width = width ? width  : '300px';
	this.dialog.style.top = top ? top : '200px';
	this.dialog.style.visibility = 'hidden';
	this.visible = false;
	this.setFixedPosition = function(fixed)
	{
		me.dialog.style.position = fixed ? 'fixed' : 'absolute';
	};
	
	var onmousedown = function(event)
	{
		if(me.dialog.style.zIndex < DragManager.zIndex)
		{
			me.dialog.style.zIndex = ++DragManager.zIndex;
		}
	};
	registerListener('mousedown', onmousedown, this.dialog);
	this.show = function()
	{
		if(me.modal)
		{
			me.modalScreen.style.zIndex = ++DragManager.zIndex;
			me.modalScreen.style.visibility = 'visible';
		}
		me.center();
		me.dialog.style.zIndex = ++DragManager.zIndex;
		me.dialog.style.visibility = 'visible';
		
		this.visible = true;
	};
	this.hide = function()
	{
		if(me.modal)
		{
			me.modalScreen.style.visibility = 'hidden';
		}
		me.dialog.style.visibility = 'hidden';
		
		this.visible = false;
	};
	this.close = function()
	{
		clearTimeout(me.getVariable('closeTimeoutID'));
		me.onclose();
		if(me.modal)
		{
			me.closeModalScreen();
		}
		DialogManager.destroyDialog(me);
	};
	this.collapsed = false;
	this.collapse = function()
	{
		me.hideBody();
		me.hideButtonZone();
		me.collapsed = true;
	};
	this.expand = function()
	{
		me.showBody();
		me.showButtonZone();
		me.collapsed = false;
	};
	this.collapseToggle = function()
	{
		if(me.collapsed)
		{
			me.expand();
		}
		else
		{
			me.collapse();
		}
	};
	this.center = function()
	{
		var width = parseInt(me.dialog.style.width, 10);
		//var height = parseInt(me.dialog.style.height, 10);
		var windowWidth = getWindowWidth();
		//var windowHeight = getWindowHeight();
		
		me.dialog.style.left = ((windowWidth/2) - (width/2))+'px';
		//me.dialog.style.top = ((windowHeight/2) - (height/2))+'px';
	};
	
	// Close button
	var closeButton = document.createElement('img');
	closeButton.src = 'images/resources/dialog_close.png';
	closeButton.style.cursor = 'pointer';
	closeButton.title = 'Close';
	function closeButtonClick(event)
	{
		me.close();
		stopEventPropagation(event);
	}
	registerListener('click', closeButtonClick, closeButton);
	closeButton.style.position = 'absolute';
	//resizeImage(closeButton, 10);
	closeButton.style.top = '0px';
	closeButton.style.marginTop = '-4px';
	closeButton.style.marginLeft = '-4px';
	
	this.onclose = function() {}
	
	// Collapse button
	/*
	var collapseButton = document.createElement('img');
	collapseButton.src = 'images/resources/dialog_collapse.png';
	collapseButton.style.cursor = 'pointer';
	var collapseClick = function(event)
	{
		me.collapseToggle();
		stopEventPropagation(event);
	};
	registerListener('click', collapseClick, collapseButton);
	collapseButton.style.position = 'absolute';		
	resizeImage(collapseButton, 10);
	collapseButton.style.top = '0px';
	collapseButton.style.marginLeft = '-2px';
	*/
	
	this.ondrag = function(event)
	{
		dragStart(event, me.id);
	};
	
	// Top border	
	var topLeft = document.createElement('td');
	topLeft.className = 'dialog_top_left';
	topLeft.appendChild(closeButton);
	var topMiddle = document.createElement('td');
	topMiddle.className = 'dialog_border';
	//topMiddle.appendChild(collapseButton);
	var topRight = document.createElement('td');
	topRight.className = 'dialog_top_right';
	
	this.topBorder = document.createElement('tr');
	this.topBorder.appendChild(topLeft);
	this.topBorder.appendChild(topMiddle);
	this.topBorder.appendChild(topRight);
	
	// left border
	this.leftBorder = document.createElement('td');
	this.leftBorder.className = 'dialog_border';
	
	// title
	this.titleBar = document.createElement('td');
	this.titleBar.className = 'dialog_title';
	if(title)
	{
		this.titleBar.appendChild(document.createTextNode(title));
	}
	this.clearTitle = function()
	{
		removeChildren(me.titleBar);
	};
	this.hideTitle = function()
	{
		me.titleBar.style.display = 'none';
	};
	this.showTitle = function()
	{
		me.titleBar.style.display = 'table-cell';
	};
	this.setTitle = function(title)
	{
		removeChildren(me.titleBar);
		me.titleBar.appendChild(document.createTextNode(title));
		me.showTitle();
	};
	
	// body
	this.dialogBody = document.createElement('td');
	this.dialogBody.className = 'dialog_body';
	this.statusDiv = document.createElement('div');
	this.clearStatus = function()
	{
		me.statusDiv.className = '';
		removeChildren(me.statusDiv);
	};
	this.setStatus = function(text)
	{
		removeChildren(me.statusDiv);
		me.statusDiv.className = 'calign';
		me.statusDiv.appendChild(document.createTextNode(text));
	};
	this.setNotificationStatus = function(text)
	{
		removeChildren(me.statusDiv);
		me.statusDiv.className = 'notification';
		me.statusDiv.appendChild(document.createTextNode(text));
	};
	this.setErrorStatus = function(text)
	{
		removeChildren(me.statusDiv);
		me.statusDiv.className = 'error';
		me.statusDiv.appendChild(document.createTextNode(text));
	};
	this.setInfoStatus = function(text)
	{
		removeChildren(me.statusDiv);
		me.statusDiv.className = 'info';
		me.statusDiv.appendChild(document.createTextNode(text));
	};
	this.dialogBody.appendChild(this.statusDiv);
	this.dialogBodyContent = document.createElement('div');
	this.appendBodyContent = function(element)
	{
		me.dialogBodyContent.appendChild(element);
	};
	this.dialogBody.appendChild(this.dialogBodyContent);
	if(dBody)
	{
		this.dialogBodyContent.appendChild(dBody);
	}
	this.clearBodyContent = function()
	{
		removeChildren(me.dialogBodyContent);
	};
	this.hideBodyContent = function()
	{
		me.dialogBodyContent.style.display = 'none';
	};
	this.showBodyContent = function()
	{
		me.dialogBodyContent.style.display = 'block';
	};
	this.hideBody = function()
	{
		me.dialogBody.style.display = 'none';
	};
	this.showBody = function()
	{
		me.dialogBody.style.display = 'table-cell';
	};
	
	// button zone
	this.buttonZone = document.createElement('td');
	this.buttonZone.className = 'dialog_button_zone';
	this.clearButtonZone = function()
	{
		removeChildren(me.buttonZone);
	};
	this.hideButtonZone = function()
	{
		me.buttonZone.style.display = 'none';
	};
	this.showButtonZone = function()
	{
		me.buttonZone.style.display = 'table-cell';
	};
	this.addButton = function(button)
	{
		me.buttonZone.appendChild(button);
		me.showButtonZone();
	};
	if(buttons)
	{
		for(var i = 0; i < buttons.length; ++i)
		{
			this.buttonZone.appendChild(buttons[i]);
		}
	}
	
	// content table (title, body, button zone)
	var contentTable = document.createElement('table');
	var contentTbody = document.createElement('tbody');
	contentTable.appendChild(contentTbody);
	var contentTopRow = document.createElement('tr');
	contentTopRow.appendChild(this.titleBar);
	contentTbody.appendChild(contentTopRow);
	var contentMiddleRow = document.createElement('tr');
	contentMiddleRow.appendChild(this.dialogBody);
	contentTbody.appendChild(contentMiddleRow);
	var contentBottomRow = document.createElement('tr');
	contentBottomRow.appendChild(this.buttonZone);
	contentTbody.appendChild(contentBottomRow);
	
	// right border
	this.rightBorder = document.createElement('td');
	this.rightBorder.className = 'dialog_border';
	
	// content
	var content = document.createElement('td');
	content.className = 'dialog_content';
	content.appendChild(contentTable);

	// Middle row
	var middleRow = document.createElement('tr');
	middleRow.appendChild(this.leftBorder);
	middleRow.appendChild(content);
	middleRow.appendChild(this.rightBorder);
	
	// Bottom border
	this.bottomBorder = document.createElement('tr');
	var bottomLeft = document.createElement('td');
	var bottomMiddle = document.createElement('td');
	var bottomRight = document.createElement('td');
	bottomLeft.className = 'dialog_bottom_left';
	bottomMiddle.className = 'dialog_border';
	bottomRight.className = 'dialog_bottom_right';
	this.bottomBorder.appendChild(bottomLeft);
	this.bottomBorder.appendChild(bottomMiddle);
	this.bottomBorder.appendChild(bottomRight);
	
	var table = document.createElement('table');
	var tbody = document.createElement('tbody');
	tbody.appendChild(this.topBorder);
	tbody.appendChild(middleRow);
	tbody.appendChild(this.bottomBorder);
	table.appendChild(tbody);
	
	this.dialog.appendChild(table);
	
	
	if(!this.titleBar.firstChild)
	{
		this.hideTitle();
	}
	if(!this.buttonZone.firstChild)
	{
		this.hideButtonZone();
	}
	
	this.onresize = function(event)
	{
		me.center();
	};
	this.makeModal = function(modal)
	{
		if(modal)
		{
			registerListener('resize', me.onresize, window);
			
			me.modalScreen = document.createElement('div');
			me.modalScreen.className = 'modal_screen';
			me.modalScreen.id = id+'_modal_screen';
			me.modalScreen.style.visibility = 'hidden';
			var onclick = function(event)
			{
				me.close();
			};
			//registerListener('click', onclick, me.modalScreen);
			me.closeModalScreen = function()
			{
				DialogManager.dialogBase.removeChild(me.modalScreen);
			};
			DialogManager.dialogBase.appendChild(me.modalScreen);
			
			me.topBorder.style.cursor = 'default';
			unregisterListener('mousedown', me.ondrag, me.topBorder);
			me.leftBorder.style.cursor = 'default';
			unregisterListener('mousedown', me.ondrag, me.leftBorder);
			me.rightBorder.style.cursor = 'default';
			unregisterListener('mousedown', me.ondrag, me.rightBorder);
			me.bottomBorder.style.cursor = 'default';
			unregisterListener('mousedown', me.ondrag, me.bottomBorder);
			
			if(me.visible)
			{
				me.modalScreen.style.zIndex = ++DragManager.zIndex;
				me.modalScreen.style.visibility = 'visible';
				me.center();
				me.dialog.style.zIndex = ++DragManager.zIndex;
			}
		}
		else
		{
			unregisterListener('resize', me.onresize, window);
			
			if(me.modalScreen)
			{
				me.closeModalScreen();
			}
			
			me.topBorder.style.cursor = 'move';
			registerListener('mousedown', me.ondrag, me.topBorder);
			me.leftBorder.style.cursor = 'move';
			registerListener('mousedown', me.ondrag, me.leftBorder);
			me.rightBorder.style.cursor = 'move';
			registerListener('mousedown', me.ondrag, me.rightBorder);
			me.bottomBorder.style.cursor = 'move';
			registerListener('mousedown', me.ondrag, me.bottomBorder);
		}
		
		me.modal = modal;
	};
	
	this.makeModal(modal);
	
	DialogManager.registerDialog(this);
}

function showErrorDialog(message)
{
	var id = getCurrentTimestamp();	
	var dialog = new DialogObject(id, '', null, null, true);
	dialog.setFixedPosition(true);
	dialog.setErrorStatus(message);
	dialog.show();
}

function showConfirmDialog(message, callback)
{
	var noButton = document.createElement('input');
	noButton.type = 'button';
	noButton.value = 'No';
	noButton.style.width = '50px';
	noButton.onclick = function()
	{
		dialog.close();
	};
	
	var yesButton = document.createElement('input');
	yesButton.type = 'button';
	yesButton.value = 'Yes';
	yesButton.style.width = '50px';
	yesButton.onclick = function()
	{
		callback();
		dialog.close();
	}
	
	var id = getCurrentTimestamp();	
	var dialog = new DialogObject(id, 'Confirm', null, [noButton, yesButton], true);
	dialog.setFixedPosition(true);
	dialog.setStatus(message);
	dialog.show();
}

// Specific Dialog Functions

function showLoginDialog(title, action, url)
{	
	var login = function(dialog)
	{
		dialog.setStatus('Please wait...');
		
		var usernameField = dialog.getVariable('usernameField');
		if(usernameField.value == usernameField.defaultValue)
		{
			dialog.setErrorStatus('Please enter your username');
			usernameField.focus();
			return;
		}
		
		var passwordField = dialog.getVariable('passwordField');
		if(passwordField.value == passwordField.defaultValue)
		{
			dialog.setErrorStatus('Please enter your password');
			passwordField.focus();
			return;
		}
		
		var username = usernameField.value;
		var password = passwordField.value;
		passwordField.value = '';
		
		var submitButton = dialog.getVariable('submitButton')
		submitButton.disabled = true;
		
		var action = dialog.getVariable('action');
		
		var ajax = new AjaxObject();
		ajax.callback = function(ajax)
		{
			var dialog = ajax.getVariable('dialog');
			
			if(!ajax.success)
			{
				var submitButton = dialog.getVariable('submitButton');
				submitButton.disabled = false;
				dialog.setErrorStatus(ajax.message);
				return;
			}
			
			dialog.setInfoStatus(ajax.message);
			dialog.hideTitle();
			dialog.hideBodyContent();
			dialog.hideButtonZone();
			
			var url = dialog.getVariable('url');
			setTimeout('doNav(\''+url+'\')', 1*SECOND);
		};
		ajax.setVariable('dialog', dialog);
		ajax.update('action='+action+'&username='+username+'&password='+password);
	};

	// username field
	var usernameField = document.createElement('input');
	usernameField.type = 'text';
	usernameField.width = '50px';
	usernameField.onEnterFn = function()
	{
		if(this.value != '')
		{
			passwordField.focus();
		}
	};
	registerListener('keypress', onEnter, usernameField);
	setupInputField(usernameField);
	
	// password field
	var passwordField = document.createElement('input');
	passwordField.type = 'password';
	passwordField.width = '50px';
	passwordField.onEnterFn = function()
	{
		login(dialog);
	};
	registerListener('keypress', onEnter, passwordField);
	setupInputField(passwordField);
	
	// form
	var form = document.createElement('form');
	form.style.textAlign = 'center';
	form.appendChild(usernameField);
	form.appendChild(document.createElement('br'));
	form.appendChild(passwordField);
	
	// submit button
	var submitButton = document.createElement('input');
	submitButton.type = 'button';
	submitButton.value = 'Login';
	submitButton.onclick = function()
	{
		login(dialog);
	};
	
	var id = 'login_dialog';
	var width = '250px';
	var dialog = new DialogObject(id, title, form, [submitButton], true, width);
	dialog.setFixedPosition(true);
	dialog.setVariable('usernameField', usernameField);
	dialog.setVariable('passwordField', passwordField);
	dialog.setVariable('submitButton', submitButton);
	dialog.setVariable('action', action);
	dialog.setVariable('url', url);
	
	dialog.show();
	usernameField.focus();
}

function showFeedbackDialog()
{
	var id = 'feedback_dialog';
	var title = 'Feedback';
	
	var div = document.createElement('div');
	div.className = 'calign';
	var textarea = document.createElement('textarea');
	textarea.style.width = '250px';
	textarea.maxRows = 10;
	setupTextarea(textarea);
	div.appendChild(textarea);
	
	var submitButton = document.createElement('input');
	submitButton.type = 'button';
	submitButton.value = 'Send';
	submitButton.onclick = function()
	{
		if(textarea.value == '')
		{
			dialog.setErrorStatus('Please enter your feedback before sending');
			return;
		}
		
		dialog.clearStatus();
		textarea.disabled = true;
		var ajax = new AjaxObject();
		ajax.callback = function(ajax)
		{
			var dialog = ajax.getVariable('dialog');
			
			if(!ajax.success)
			{
				dialog.setErrorStatus(ajax.message);
				textarea.disabled = false;
				return;
			}
			
			dialog.setInfoStatus(ajax.message);
			dialog.hideTitle();
			dialog.hideBodyContent();
			dialog.hideButtonZone();
			DialogManager.closeDialog(dialog, 3*SECOND);
		};
		ajax.setVariable('dialog', dialog);
		ajax.update('action=send_feedback&feedback='+textarea.value);
	};
	
	var dialog = new DialogObject(id, title, div, [submitButton], false);
	dialog.setFixedPosition(true);
	dialog.show();
	textarea.focus();
}

function showCompanyContactDialog()
{
	var form = document.createElement('form');
	form.className = 'calign';
	
	var nameField = document.createElement('input');
	nameField.type = 'text';
	nameField.defaultValue = 'Name';
	nameField.style.width = '200px';
	nameField.onEnterFn = function()
	{
		if(this.value != '')
		{
			companyField.focus();
		}
	};
	registerListener('keypress', onEnter, nameField);
	setupInputField(nameField);
	form.appendChild(nameField);
	
	var companyField = document.createElement('input');
	companyField.type = 'text';
	companyField.defaultValue = 'Company';
	companyField.style.width = '200px';
	companyField.onEnterFn = function()
	{
		if(this.value != '')
		{
			emailField.focus();
		}
	};
	registerListener('keypress', onEnter, companyField);
	setupInputField(companyField);
	form.appendChild(document.createElement('br'));
	form.appendChild(companyField);
	
	var emailField = document.createElement('input');
	emailField.type = 'text';
	emailField.defaultValue = 'Your Email';
	emailField.style.width = '200px';
	emailField.onEnterFn = function()
	{
		if(this.value != '')
		{
			messageArea.focus();
		}
	};
	registerListener('keypress', onEnter, emailField);
	setupInputField(emailField);
	form.appendChild(document.createElement('br'));
	form.appendChild(emailField);
	
	var messageArea = document.createElement('textarea');
	messageArea.defaultValue = 'Message';
	messageArea.style.width = '200px';
	setupTextarea(messageArea);
	form.appendChild(document.createElement('br'));
	form.appendChild(messageArea);
	
	var submitButton = document.createElement('input');
	submitButton.type = 'button';
	submitButton.value = 'Submit';
	submitButton.onclick = function()
	{
		if(nameField.value == nameField.defaultValue || companyField.value == companyField.defaultValue || 
		   emailField.value == emailField.defaultValue || messageArea.value == messageArea.defaultValue)
		{
			dialog.setErrorStatus('Please complete all fields');
			return;
		}
		
		if(!validateEmail(emailField.value))
		{
			dialog.setErrorStatus('Invalid email address');
			emailField.select();
			return;
		}
		
		var ajax = new AjaxObject();
		ajax.callback = function(ajax)
		{
			if(!ajax.success)
			{
				dialog.setErrorStatus(ajax.message);
				return;
			}
			
			dialog.hideBodyContent();
			dialog.setInfoStatus(ajax.message);
			DialogManager.closeDialog(dialog, 3*SECOND);
		};
		
		var name = nameField.value;
		var company = companyField.value;
		var email = emailField.value;
		var message = messageArea.value;
		
		ajax.update('action=company_contact&name='+name+'&company='+company+'&email='+email+'&message='+message);
	};
	
	var id = 'company_contact_dialog';
	var title = 'Contact Us';
	var dialog = new DialogObject(id, title, form, [submitButton]);
	dialog.setFixedPosition(true);
	dialog.setVariable('nameField', nameField);
	dialog.setVariable('companyField', companyField);
	dialog.setVariable('emailField', emailField);
	dialog.setVariable('messageArea', messageArea);
	dialog.show();
}

function showPassChangeDialog(action)
{
	var changePassword = function(dialog)
	{
		var oldField = dialog.getVariable('oldField');
		var newField = dialog.getVariable('newField');
		var confirmField = dialog.getVariable('confirmField');
		
		var oldPassword = oldField.value;
		var newPassword = newField.value;
		var confirmPassword = confirmField.value;
		
		oldField.value = '';
		newField.value = '';
		confirmField.value = '';
		
		if(!oldPassword || !newPassword || !confirmPassword)
		{
			dialog.setErrorStatus('Please complete all fields');
			return;
		}
		else if(newPassword != confirmPassword)
		{
			dialog.setErrorStatus('Passwords do not match');
			return;
		}
		
		var action = dialog.getVariable('action', action);
		
		var ajax = new AjaxObject();
		ajax.callback = function(ajax)
		{
			var dialog = ajax.getVariable('dialog');	
			
			if(!ajax.success)
			{
				dialog.setErrorStatus(ajax.message);
				var oldField = ajax.getVariable('oldField');
				oldField.focus();
				return;
			}
			
			dialog.setInfoStatus(ajax.message);
			dialog.hideTitle();
			dialog.hideBodyContent();
			dialog.hideButtonZone();
			
			DialogManager.closeDialog(dialog, 1*SECOND);
		};
		ajax.setVariable('dialog', dialog);
		ajax.setVariable('oldField', oldField);
		ajax.update('action='+action+'&old='+oldPassword+'&new='+newPassword+'&confirm='+confirmPassword);
	};

	var dBody = document.createElement('div');
	dBody.className = 'calign';
	
	var form = document.createElement('form');
	dBody.appendChild(form);
	
	var table = document.createElement('table');
	form.appendChild(table);
	var tbody = document.createElement('tbody');
	table.appendChild(tbody);
	
	var tr1 = document.createElement('tr');
	tbody.appendChild(tr1);
	var tr1_td1 = document.createElement('td');
	tr1_td1.align = 'right';
	tr1_td1.style.verticalAlign = 'middle';
	tr1_td1.style.paddingRight = '5px';
	tr1.appendChild(tr1_td1);
	var oldLabel = document.createElement('strong');
	oldLabel.appendChild(document.createTextNode('Old Password:'));
	tr1_td1.appendChild(oldLabel);
	var tr1_td2 = document.createElement('td');
	tr1_td2.align = 'left';
	tr1.appendChild(tr1_td2);
	var oldField = document.createElement('input');
	oldField.onEnterFn = function()
	{
		if(oldField.value != '')
		{
			newField.focus();
		}
	};
	registerListener('keypress', onEnter, oldField);
	setupInputField(oldField);
	oldField.type = 'password';
	tr1_td2.appendChild(oldField);
	
	var tr2 = document.createElement('tr');
	tbody.appendChild(tr2);
	var tr2_td1 = document.createElement('td');
	tr2_td1.align = 'right';
	tr2_td1.style.verticalAlign = 'middle';
	tr2_td1.style.paddingRight = '5px';
	tr2.appendChild(tr2_td1);
	var newLabel = document.createElement('strong');
	newLabel.appendChild(document.createTextNode('New Password:'));
	tr2_td1.appendChild(newLabel);
	var tr2_td2 = document.createElement('td');
	tr2_td2.align = 'left';
	tr2.appendChild(tr2_td2);
	var newField = document.createElement('input');
	newField.onEnterFn = function()
	{
		if(newField.value != '')
		{
			confirmField.focus();
		}
	};
	registerListener('keypress', onEnter, newField);
	setupInputField(newField);
	newField.type = 'password';
	tr2_td2.appendChild(newField);
	
	var tr3 = document.createElement('tr');
	tbody.appendChild(tr3);
	var tr3_td1 = document.createElement('td');
	tr3_td1.align = 'right';
	tr3_td1.style.verticalAlign = 'middle';
	tr3_td1.style.paddingRight = '5px';
	tr3.appendChild(tr3_td1);
	var confirmLabel = document.createElement('strong');
	confirmLabel.appendChild(document.createTextNode('Confirm New:'));
	tr3_td1.appendChild(confirmLabel);
	var tr3_td2 = document.createElement('td');
	tr3_td2.align = 'left';
	tr3.appendChild(tr3_td2);
	var confirmField = document.createElement('input');
	confirmField.onEnterFn = function()
	{
		changePassword(dialog);
	};
	registerListener('keypress', onEnter, confirmField);
	setupInputField(confirmField);
	confirmField.type = 'password';
	tr3_td2.appendChild(confirmField);
	
	// submit button
	var subtmitButton = document.createElement('input');
	subtmitButton.type = 'button';
	subtmitButton.value = 'Change Password';
	subtmitButton.onclick = function()
	{
		changePassword(dialog);
	};
	
	var id = 'pass_change_dialog';
	var title = 'Change Your Password';
	var dialog = new DialogObject(id, title, dBody, [subtmitButton], true);
	dialog.setFixedPosition(true);
	dialog.setVariable('oldField', oldField);
	dialog.setVariable('newField', newField);
	dialog.setVariable('confirmField', confirmField);
	dialog.setVariable('action', action);
	dialog.show();
	oldField.focus();
}

function showFileDownloadDialog(fileID)
{
	var downloadButton = document.createElement('input');
	downloadButton.type = 'button';
	downloadButton.value = 'Download';
	downloadButton.onclick = function()
	{
		doNav('dl.php?id='+fileID);
	};
	
	var id = 'file_dialog_'+fileID;
	var title = '';
	var dialog = new DialogObject(id, title, null, [downloadButton], true);
	dialog.show();
	
	getFileInfo(fileID, dialog, true);
}

function showCalendarDialog()
{
	var id = 'calendar_dialog';
	var title = 'NSBE Calendar';

	var div = document.createElement('div');
	div.className = 'calign';
	var calendarFrame = document.createElement('iframe');
	calendarFrame.src = CALENDAR_ADDRESS;
	calendarFrame.style.width = '700px';
	calendarFrame.style.height = '500px';
	calendarFrame.frameBorder = 0;
	calendarFrame.style.scrolling = 'no';
	div.appendChild(calendarFrame);
	
	var width = '750px';
	var top = '25px';
	var dialog = new DialogObject(id, title, div, null, true, width, top);	
	dialog.show();
}

function showRequestDialog()
{
	var submitEmailRequest = function(dialog)
	{
		var email = dialog.getVariable('email');
		if(!validateEmail(email.value))
		{
			dialog.setErrorStatus('Invalid email address');
			email.select();
			return;
		}
		
		dialog.clearStatus();
		var action = dialog.getVariable('action');
		var ajax = new AjaxObject();
		ajax.callback = function(ajax)
		{
			var dialog = ajax.getVariable('dialog');
			
			if(!ajax.success)
			{
				dialog.setErrorStatus(ajax.message);
				return;
			}
			
			dialog.setInfoStatus(ajax.message);
			dialog.hideTitle();
			dialog.hideBodyContent();
			dialog.hideButtonZone();
			DialogManager.closeDialog(dialog, 3*SECOND);
		};
		ajax.setVariable('dialog', dialog);
		ajax.update('action=email_request&email='+email.value+'&request='+action);
	};
	
	var dialogBody = document.createElement('div');
	dialogBody.className = 'calign';
	
	var emailInput = document.createElement('input');
	emailInput.className = 'text';
	emailInput.type = 'text';
	emailInput.defaultValue = 'Email';
	emailInput.id = 'email';
	setupInputField(emailInput);
	dialogBody.appendChild(emailInput);
	
	// buttons
	var addButton = document.createElement('input');
	addButton.type = 'button';
	addButton.value = 'Add';
	addButton.onclick = function()
	{
		dialog.setVariable('action', 'add');
		submitEmailRequest(dialog, 'add');
	};
	
	var removeButton = document.createElement('input');
	removeButton.type = 'button';
	removeButton.value = 'Remove';
	removeButton.onclick = function()
	{
		dialog.setVariable('action', 'remove');
		submitEmailRequest(dialog);
	};
	
	var id = 'request_form_dialog';
	var title = 'NSBE Mailing List';
	var width = '250px';
	var dialog = new DialogObject(id, title, dialogBody, [addButton, removeButton], false, width);
	dialog.setFixedPosition(true);
	dialog.setVariable('email', emailInput);
	dialog.show();
}

function showUserProfileDialog(position, userID)
{
	var id = 'user_profile_dialog_'+userID;
	var width = '400px';
	var top = '150px';
	var dialog = new DialogObject(id, position, null, null, false, width, top);
	
	var ajax = new AjaxObject();
	ajax.callback = function(ajax)
	{
		var dialog = ajax.getVariable('dialog');
		
		if(!ajax.success)
		{
			dialog.setErrorStatus(ajax.message);
			return;
		}
		
		var userNode = ajax.xmlDoc.getElementsByTagName('user')[0];
		
		var table = document.createElement('table');
		dialog.appendBodyContent(table);
		var tbody = document.createElement('tbody');
		table.appendChild(tbody);
		var topRow = document.createElement('tr');
		tbody.appendChild(topRow);
		
		var imageCell = document.createElement('td');
		imageCell.style.verticalAlign = 'top';
		imageCell.style.width = '100px';
		imageCell.style.maxHeight = '100px';
		var photo_id = getTagValue(userNode, 'photo_id');
		var img = document.createElement('img');
		img.src = 'img.php?id='+photo_id;
		imageCell.appendChild(img);
		topRow.appendChild(imageCell);
		
		var infoCell = document.createElement('td');
		infoCell.style.verticalAlign = 'top';
		infoCell.style.paddingLeft = '10px';
		topRow.appendChild(infoCell);
		
		var name = document.createElement('h2');
		name.appendChild(document.createTextNode(getTagValue(userNode, 'name')));
		infoCell.appendChild(name);
		var hr = document.createElement('div');
		hr.className = 'hr_slim';
		infoCell.appendChild(hr);
		
		var email = getTagValue(userNode, 'username');
		email += '@umich.edu';
		var emailLink = document.createElement('a');
		emailLink.href = 'mailto:'+email;
		emailLink.appendChild(document.createTextNode(email));
		infoCell.appendChild(emailLink);
		
		var majorNodes = userNode.getElementsByTagName('major');
		for(var i = 0; i < majorNodes.length; ++i)
		{
			infoCell.appendChild(document.createElement('br'));
			infoCell.appendChild(document.createTextNode(getTagValue(majorNodes.item(i), 'name')));
		}
		
		var extraInfo = document.createElement('div');
		
		var bioText = getTagValue(userNode, 'bio');
		if(bioText)
		{
			extraInfo.appendChild(document.createElement('br'));
			var bioLabel = document.createElement('h4');
			bioLabel.appendChild(document.createTextNode('Bio'));
			extraInfo.appendChild(bioLabel);
			var bio = document.createElement('p');
			bio.className = 'jalign';
			bio.appendChild(document.createTextNode(bioText));
			extraInfo.appendChild(bio);
		}
		
		var experienceText = getTagValue(userNode, 'experience');
		if(experienceText)
		{
			extraInfo.appendChild(document.createElement('br'));
			var experienceLabel = document.createElement('h4');
			experienceLabel.appendChild(document.createTextNode('Experience'));
			extraInfo.appendChild(experienceLabel);
			var experience = document.createElement('p');
			experience.className = 'jalign';
			experience.appendChild(document.createTextNode(experienceText));
			extraInfo.appendChild(experience);
		}
		
		var quoteText = getTagValue(userNode, 'quote');
		if(quoteText)
		{
			extraInfo.appendChild(document.createElement('br'));
			var quoteLabel = document.createElement('h4');
			quoteLabel.appendChild(document.createTextNode('Quote'));
			extraInfo.appendChild(quoteLabel);
			var quote = document.createElement('p');
			quote.className = 'jalign';
			quote.appendChild(document.createTextNode(quoteText));
			extraInfo.appendChild(quote);
		}
		
		if(extraInfo.firstChild)
		{
			dialog.appendBodyContent(extraInfo);
		}
		
		dialog.clearStatus();
	};
	ajax.setVariable('dialog', dialog);
	ajax.update('action=get_user&id='+userID);
	
	dialog.setStatus('Loading...');
	dialog.show();
}

function showUploadDialog(category, text)
{
	var div = document.createElement('div');
	
	var uploadButton = document.createElement('input');
	uploadButton.type = 'button';
	uploadButton.value = 'Upload';
	uploadButton.onclick = function()
	{
		var fileInput = document.getElementById('file'); //IE8
		if(fileInput.value == '')
		{
			dialog.setErrorStatus('Please select a file to upload');
			return;
		}
		
		dialog.setStatus('Uploading...');
		form.style.display = 'none';
		
		form.submit();
	};
	
	var id = 'upload_dialog';
	var title = 'Upload';
	var dialog = new DialogObject(id, title, div, [uploadButton], true);
	dialog.setFixedPosition(true);
	
	//IE8 renames 'enctype' attribute to 'encType' and 'name' to 'propdescname'
	div.innerHTML = '<form class="calign" id="upload_form" action="upload.php" target="upload_target" method="post" enctype="multipart/form-data"></form>';
	var form = document.getElementById('upload_form');
	/*
	var form = document.createElement('form');
	form.className = 'calign';
	form.id = 'upload_form';
	form.action = 'upload.php';
	form.target = 'upload_target';
	form.method = 'post';
	form.enctype = 'multipart/form-data';
	*/
	div.appendChild(form);
	dialog.setVariable('form', form);	
	
	var maxFileSize = document.createElement('input');
	maxFileSize.type = 'hidden';
	maxFileSize.name = 'MAX_FILE_SIZE';
	maxFileSize.value = '10485760'; // 10MB
	//form.appendChild(maxFileSize);
	form.innerHTML += '<input type="hidden" name="MAX_FILE_SIZE" value="10485760" />'; //IE8
	
	var fileInput = document.createElement('input');
	fileInput.type = 'file';
	fileInput.name = 'file';
	fileInput.id = 'file';
	//form.appendChild(fileInput);
	form.innerHTML += '<input type="file" name="file" id="file" />'; //IE8
	
	var caption = document.createElement('p');
	caption.className = 'calign caption';
	caption.appendChild(document.createTextNode(text));
	form.appendChild(caption);
	
	if(category == '*')
	{
		var categoryLabel = document.createElement('label');
		categoryLabel.appendChild(document.createTextNode('Category: '));
		form.appendChild(categoryLabel);
		
		var categorySelect = document.createElement('select');
		categorySelect.name = 'category';
		var categories = [
		'resource',
		'corporate',
		'documentation',
		'publication',
		'presentation',
		'image',
		'miscellaneous'
		];
		categories.sort();
		for(var i = 0; i < categories.length; ++i)
		{
			var option = document.createElement('option');
			option.appendChild(document.createTextNode(categories[i]));
			categorySelect.appendChild(option);
		}
		form.appendChild(categorySelect);
	}
	else
	{
		var categoryInput = document.createElement('input');
		categoryInput.type = 'hidden';
		categoryInput.name = 'category';
		categoryInput.value = category;
		form.appendChild(categoryInput);
	}
	
	var uploadTarget = document.createElement('iframe');
	uploadTarget.id = 'upload_target';
	uploadTarget.name = 'upload_target';
	//form.appendChild(uploadTarget);
	form.innerHTML += '<iframe id="upload_target" name="upload_target" />'; //IE8
	
	dialog.show();
}

function showResumeUploadDialog()
{
	var div = document.createElement('div');
	
	var uploadButton = document.createElement('input');
	uploadButton.type = 'button';
	uploadButton.value = 'Upload';
	uploadButton.onclick = function()
	{
		var fileInput = document.getElementById('file'); //IE8
		if(fileInput.value == '')
		{
			dialog.setErrorStatus('Please select a file to upload');
			return;
		}
		
		dialog.setStatus('Uploading...');
		form.style.display = 'none';
		
		form.submit();
	};
	
	var id = 'resume_upload_dialog';
	var title = 'Resume Upload';
	var dialog = new DialogObject(id, title, div, [uploadButton], true);
	dialog.setFixedPosition(true);
	
	//IE8 renames 'enctype' attribute to 'encType' and 'name' to 'propdescname'
	div.innerHTML = '<form class="calign" id="resume_upload_form" action="upload_resume.php" target="upload_target" method="post" enctype="multipart/form-data"></form>';
	var form = document.getElementById('resume_upload_form');
	/*
	var form = document.createElement('form');
	form.className = 'calign';
	form.id = 'resume_upload_form';
	form.action = 'upload.php';
	form.target = 'upload_target';
	form.method = 'post';
	form.enctype = 'multipart/form-data';
	*/
	div.appendChild(form);
	dialog.setVariable('form', form);	
	
	/*
	var maxFileSize = document.createElement('input');
	maxFileSize.type = 'hidden';
	maxFileSize.name = 'MAX_FILE_SIZE';
	maxFileSize.value = '10485760'; // 10MB
	form.appendChild(maxFileSize);
	*/
	form.innerHTML += '<input type="hidden" name="MAX_FILE_SIZE" value="10485760" />'; //IE8
	
	/*
	var fileInput = document.createElement('input');
	fileInput.type = 'file';
	fileInput.name = 'file';
	fileInput.id = 'file';
	form.appendChild(fileInput);
	*/
	form.innerHTML += '<input type="file" name="file" id="file" />'; //IE8
	
	/*
	var uploadTarget = document.createElement('iframe');
	uploadTarget.id = 'upload_target';
	uploadTarget.name = 'upload_target';
	form.appendChild(uploadTarget);
	*/
	form.innerHTML += '<iframe id="upload_target" name="upload_target" />'; //IE8
	
	dialog.show();
}

function showEventDialog(eventID)
{
	var info = document.createElement('p');
	info.className = 'lalign';
	info.appendChild(document.getElementById(eventID+'_info').cloneNode(true));
	info.style.marginBottom = '5px';
	
	var textbox = new TextboxObject();
	
	var description = document.createElement('p');
	description.className = 'lalign';
	description.innerHTML = document.getElementById(eventID+'_description').innerHTML;
	textbox.appendChild(description);
	
	var dBody = document.createElement('div');
	dBody.appendChild(info);
	textbox.appendTo(dBody);
	
	var id = eventID+'_event_dialog';
	var title = document.getElementById(eventID+'_title').firstChild.nodeValue;
	var width = '300px';
	var dialog = new DialogObject(id, title, dBody, null, false, width);
	dialog.setFixedPosition(true);
	
	dialog.show();
}

function showAddMemberDialog()
{
	function addMember()
	{
		if(nameField.value == nameField.defaultValue || uniqnameField.value == uniqnameField.defaultValue)
		{
			dialog.setErrorStatus('Please complete all fields');
			return;
		}
		
		var ajax = new AjaxObject();
		ajax.callback = function(ajax)
		{
			PanelManager.updatePanelObjectByName('member_list_panel');
			if(!ajax.success)
			{
				dialog.setErrorStatus(ajax.message);
				return;
			}
			
			dialog.setInfoStatus(ajax.message);
			dialog.hideTitle();
			dialog.hideBodyContent();
			dialog.hideButtonZone();
			
			DialogManager.closeDialog(dialog, 1*SECOND);
		};
		dialog.setStatus('Please wait...');
		ajax.update('action=add_member&name='+nameField.value+'&uniqname='+uniqnameField.value);
	}
	
	var form = document.createElement('form');
	
	var nameField = document.createElement('input');
	nameField.type = 'text';
	nameField.defaultValue = 'Name';
	nameField.onEnterFn = function()
	{
		if(this.value != '')
		{
			uniqnameField.focus();
		}
	};
	registerListener('keypress', onEnter, nameField);
	setupInputField(nameField);
	form.appendChild(nameField);
	
	form.appendChild(document.createElement('br'));
	
	var uniqnameField = document.createElement('input');
	uniqnameField.type = 'text';
	uniqnameField.defaultValue = 'uniqname';
	uniqnameField.onEnterFn = function()
	{
		if(this.value != '')
		{
			addMember();
		}
	};
	registerListener('keypress', onEnter, uniqnameField);
	setupInputField(uniqnameField);
	form.appendChild(uniqnameField);
	
	var dBody = document.createElement('div');
	dBody.className = 'calign';
	dBody.appendChild(form);
	
	var submitButton = document.createElement('input');
	submitButton.type = 'submit';
	submitButton.value = 'Add';
	submitButton.onclick = addMember;
	
	var id = 'add_member';
	var title = 'Add Member';
	var width = '250px';
	var dialog = new DialogObject(id, title, dBody, [submitButton], true, width);
	dialog.setFixedPosition(true);
	dialog.show();
}

function showAddUserDialog()
{
	//$zone, $position, $name, $username
	function addUser()
	{
		if(nameField.value == nameField.defaultValue || usernameField.value == usernameField.defaultValue ||
		   zoneField.value == zoneField.defaultValue || positionField.value == positionField.defaultValue)
		{
			dialog.setErrorStatus('Please complete all fields');
			return;
		}
		
		var ajax = new AjaxObject();
		ajax.callback = function(ajax)
		{
			PanelManager.updatePanelObjectByName('user_list_panel');
			if(!ajax.success)
			{
				dialog.setErrorStatus(ajax.message);
				return;
			}
			
			dialog.setInfoStatus(ajax.message);
			dialog.hideTitle();
			dialog.hideBodyContent();
			dialog.hideButtonZone();
			
			DialogManager.closeDialog(dialog, 1*SECOND);
		};
		dialog.setStatus('Please wait...');
		ajax.update('action=add_user&name='+nameField.value+'&username='+usernameField.value+'&zone='+zoneField.value+'&position='+positionField.value);
	}
	
	var form = document.createElement('form');
	
	var nameField = document.createElement('input');
	nameField.type = 'text';
	nameField.defaultValue = 'Name';
	nameField.onEnterFn = function()
	{
		if(this.value != '')
		{
			usernameField.focus();
		}
	};
	registerListener('keypress', onEnter, nameField);
	setupInputField(nameField);
	form.appendChild(nameField);
	
	form.appendChild(document.createElement('br'));
	
	var usernameField = document.createElement('input');
	usernameField.type = 'text';
	usernameField.defaultValue = 'Username';
	usernameField.onEnterFn = function()
	{
		if(this.value != '')
		{
			zoneField.focus();
		}
	};
	registerListener('keypress', onEnter, usernameField);
	setupInputField(usernameField);
	form.appendChild(usernameField);
	
	form.appendChild(document.createElement('br'));
	
	var zoneField = document.createElement('input');
	zoneField.type = 'text';
	zoneField.defaultValue = 'Zone';
	zoneField.onEnterFn = function()
	{
		if(this.value != '')
		{
			positionField.focus();
		}
	};
	registerListener('keypress', onEnter, zoneField);
	setupInputField(zoneField);
	form.appendChild(zoneField);
	
	form.appendChild(document.createElement('br'));
	
	var positionField = document.createElement('input');
	positionField.type = 'text';
	positionField.defaultValue = 'Position';
	positionField.onEnterFn = function()
	{
		if(this.value != '')
		{
			addUser();
		}
	};
	registerListener('keypress', onEnter, positionField);
	setupInputField(positionField);
	form.appendChild(positionField);
	
	var dBody = document.createElement('div');
	dBody.className = 'calign';
	dBody.appendChild(form);
	
	var submitButton = document.createElement('input');
	submitButton.type = 'submit';
	submitButton.value = 'Add';
	submitButton.onclick = addUser;
	
	var id = 'add_user';
	var title = 'Add User';
	var width = '250px';
	var dialog = new DialogObject(id, title, dBody, [submitButton], true, width);
	dialog.setFixedPosition(true);
	dialog.show();
}

function showPDFDialog(title, src)
{
	var iframe = document.createElement('iframe');
	iframe.className = 'pdf';
	
	var id = 'pdf_dialog';
	var width = '800px';
	var top = '50px';
	var dialog = new DialogObject(id, title, iframe, null, true, width, top);
	dialog.setFixedPosition(true);
	dialog.show();
	iframe.src = src;
}

function showSurveyDialog(key)
{
	var iframe = document.createElement('iframe');
	iframe.className = 'survey';
	
	var id = 'survey_dialog';
	var title = 'Survey';
	var width = '600px';
	var top = '50px';
	var dialog = new DialogObject(id, title, iframe, null, true, width, top);
	dialog.setFixedPosition(true);
	dialog.show();
	iframe.src = 'http://spreadsheets.google.com/embeddedform?key='+key;
}

function showMajorSelectionDialog(elementID, action)
{
	var selectButton = document.createElement('input');
	selectButton.type = 'button';
	selectButton.value = 'Select';
	selectButton.onclick = function()
	{
		var majors = dialog.getVariable('majors');
		var action = dialog.getVariable('action');
		var element = dialog.getVariable('element');
		var editID = dialog.getVariable('editID');
		
		var ajax = new AjaxObject();
		ajax.callback = function(ajax)
		{
			var dialog = ajax.getVariable('dialog');
			
			if(!ajax.success)
			{
				dialog.setErrorStatus(ajax.message);
				return;
			}
			
			removeChildren(element);
			majors.sort();
			element.setAttribute('property_value', majors.join(','));
			var majorNames = new Array();
			for(var i = 0; i < majors.length; ++i)
			{
				majorNames.push(document.getElementById('major_'+majors[i]+'_name').firstChild.nodeValue);
			}
			if(majorNames.length > 0)
			{
				majorNames.sort();
				var ul = document.createElement('ul');
				element.appendChild(ul);
				for(var i = 0; i < majorNames.length; ++i)
				{
					var li = document.createElement('li');
					li.appendChild(document.createTextNode(majorNames[i]));
					ul.appendChild(li);
				}
			}
			
			dialog.close();
		};
		ajax.setVariable('dialog', dialog);
		ajax.update('action='+action+'&id='+editID+'&property=majors&value='+majors.join(','));
	};
	
	var element = document.getElementById(elementID);
	var currentMajors = element.getAttribute('property_value');
	var editID = element.getAttribute('edit_id');
	
	var id = 'major_selection_dialog';
	var title = 'Select Majors';
	var width = '400px';
	var top = '100px';
	var dialog = new DialogObject(id, title, null, [selectButton], true, width, top);
	dialog.setFixedPosition(true);
	dialog.setStatus('Loading...');
	dialog.show();
	dialog.setVariable('majors', currentMajors != '' ? currentMajors.split(',') : Array());
	dialog.setVariable('action', action);
	dialog.setVariable('element', element);
	dialog.setVariable('editID', editID);
	
	var ajax = new AjaxObject();
	ajax.callback = function(ajax)
	{
		var dialog = ajax.getVariable('dialog');
		var majors = dialog.getVariable('majors');
		
		if(!ajax.success)
		{
			dialog.setErrorStatus(ajax.message);
			return;
		}
		
		var majorContainer = document.createElement('div');
		//majorContainer.style.maxHeight = '200px';
		majorContainer.style.height = '200px'; //IE7
		majorContainer.style.overflowY = 'auto';
		majorContainer.style.overflowX = 'hidden';
		majorContainer.style.border = '1px solid #EEEEEE';
		majorContainer.style.padding = '2px';
		dialog.appendBodyContent(majorContainer);
		
		var table = document.createElement('table');
		table.className = 'mouseover_light';
		majorContainer.appendChild(table);
		var tbody = document.createElement('tbody');
		table.appendChild(tbody);
		
		var checkboxes = new Array();
		function updateList(checkbox)
		{
			if(checkbox.checked)
			{
				if(!majors.contains(checkbox.value))
				{
					majors.push(checkbox.value);
				}
			}
			else
			{
				majors.remove(checkbox.value);
			}
		}
		var majorNodes = ajax.xmlDoc.getElementsByTagName('major');
		for(var i = 0; i < majorNodes.length; ++i)
		{
			var major = majorNodes.item(i);
			var id = getTagValue(major, 'id');
			var name = getTagValue(major, 'name');
			
			var checkbox = document.createElement('input');
			checkboxes.push(checkbox);
			checkbox.type = 'checkbox';
			checkbox.id = 'major_'+id;
			checkbox.value = id;
			checkbox.defaultChecked = majors.contains(checkbox.value);
			checkbox.onchange = function()
			{
				updateList(this);
			};
			
			var label = document.createElement('label');
			label.id = 'major_'+id+'_name';
			label.setAttribute('for', checkbox.id);
			label.appendChild(document.createTextNode(name));
			label.style.cursor = 'pointer';
			
			var checkTD = document.createElement('td');
			checkTD.appendChild(checkbox);
			var labelTD = document.createElement('td');
			labelTD.style.verticalAlign = 'middle';
			labelTD.appendChild(label);
			
			var tr = document.createElement('tr');
			tr.appendChild(checkTD);
			tr.appendChild(labelTD);
			
			tbody.appendChild(tr);
		}
		
		var buttonTable = document.createElement('table');
		dialog.appendBodyContent(buttonTable);
		var buttonTableBody = document.createElement('tbody');
		buttonTable.appendChild(buttonTableBody);
		var buttonTR = document.createElement('tr');
		buttonTableBody.appendChild(buttonTR);
		
		var selectAllTD = document.createElement('td');
		selectAllTD.className = 'lalign';
		buttonTR.appendChild(selectAllTD);
		var selectAll = document.createElement('a');
		selectAll.appendChild(document.createTextNode('Select All'));
		selectAll.onclick = function()
		{
			for(var i = 0; i < checkboxes.length; ++i)
			{
				checkboxes[i].checked = true;
				updateList(checkboxes[i]);
			}
		};
		selectAllTD.appendChild(selectAll);
		
		var resetAllTD = document.createElement('td');
		resetAllTD.className = 'calign';
		buttonTR.appendChild(resetAllTD);
		var resetAll = document.createElement('a');
		resetAll.appendChild(document.createTextNode('Reset'));
		resetAll.onclick = function()
		{
			for(var i = 0; i < checkboxes.length; ++i)
			{
				checkboxes[i].checked = checkboxes[i].defaultChecked;
				updateList(checkboxes[i]);
			}
		};
		resetAllTD.appendChild(resetAll);
		
		var clearAllTD = document.createElement('td');
		clearAllTD.className = 'ralign';
		buttonTR.appendChild(clearAllTD);
		var clearAll = document.createElement('a');
		clearAll.appendChild(document.createTextNode('Clear All'));
		clearAll.onclick = function()
		{
			for(var i = 0; i < checkboxes.length; ++i)
			{
				checkboxes[i].checked = false;
				updateList(checkboxes[i]);
			}
		};
		clearAllTD.appendChild(clearAll);
		
		var div = document.createElement('div');
		div.className = 'notification';
		majorContainer.appendChild(div);
		div.appendChild(document.createTextNode('If your major is not listed '));
		var feedbackLink = document.createElement('a');
		feedbackLink.appendChild(document.createTextNode('let us know'));
		feedbackLink.onclick = showFeedbackDialog;
		div.appendChild(feedbackLink);
		
		dialog.clearStatus();
	};
	ajax.setVariable('dialog', dialog);
	ajax.update('action=get_majors');
}

function showMemberSelectionDialog(elementID, action)
{
	var selectButton = document.createElement('input');
	selectButton.type = 'button';
	selectButton.value = 'Select';
	selectButton.onclick = function()
	{
		var members = dialog.getVariable('members');
		var action = dialog.getVariable('action');
		var element = dialog.getVariable('element');
		var editID = dialog.getVariable('editID');
		
		var ajax = new AjaxObject();
		ajax.callback = function(ajax)
		{
			var dialog = ajax.getVariable('dialog');
			
			if(!ajax.success)
			{
				dialog.setErrorStatus(ajax.message);
				return;
			}
			
			removeChildren(element);
			members.sort();
			element.setAttribute('property_value', members.join(','));
			var memberNames = new Array();
			for(var i = 0; i < members.length; ++i)
			{
				memberNames.push(document.getElementById('member_'+members[i]+'_name').firstChild.nodeValue);
			}
			
			var countLabel = document.createElement('strong');
			countLabel.appendChild(document.createTextNode(memberNames.length));
			countLabel.appendChild(document.createTextNode(' members'));
			element.appendChild(countLabel);
			element.appendChild(document.createElement('br'));
			if(memberNames.length > 0)
			{
				var listWrapper = document.createElement('p');
				listWrapper.className = 'indent';
				element.appendChild(listWrapper);
				
				memberNames.sort();
				var memberNameList = memberNames.join(', ');
				listWrapper.appendChild(document.createTextNode(memberNameList));
			}
			
			dialog.close();
		};
		ajax.setVariable('dialog', dialog);
		dialog.setStatus('Please wait...');
		ajax.update('action='+action+'&id='+editID+'&property=members&value='+members.join(','));
	};
	
	var element = document.getElementById(elementID);
	var currentMembers = element.getAttribute('property_value');
	var editID = element.getAttribute('edit_id');
	
	var id = 'member_selection_dialog';
	var title = 'Select Members';
	var width = '300px';
	var top = '100px';
	var dialog = new DialogObject(id, title, null, [selectButton], true, width, top);
	dialog.setFixedPosition(true);
	dialog.setStatus('Loading...');
	dialog.show();
	dialog.setVariable('members', currentMembers != '' ? currentMembers.split(',') : Array());
	dialog.setVariable('action', action);
	dialog.setVariable('element', element);
	dialog.setVariable('editID', editID);
	
	var ajax = new AjaxObject();
	ajax.callback = function(ajax)
	{
		var dialog = ajax.getVariable('dialog');
		var members = dialog.getVariable('members');
		
		if(!ajax.success)
		{
			dialog.setErrorStatus(ajax.message);
			return;
		}
		
		var memberContainer = document.createElement('div');
		//memberContainer.style.maxHeight = '200px';
		memberContainer.style.height = '200px'; //IE7
		memberContainer.style.overflowY = 'auto';
		memberContainer.style.overflowX = 'hidden';
		memberContainer.style.border = '1px solid #EEEEEE';
		memberContainer.style.padding = '2px';
		dialog.appendBodyContent(memberContainer);
		
		var table = document.createElement('table');
		table.className = 'mouseover_light';
		memberContainer.appendChild(table);
		var tbody = document.createElement('tbody');
		table.appendChild(tbody);
		
		var checkboxes = new Array();
		function updateList(checkbox)
		{
			if(checkbox.checked)
			{
				if(!members.contains(checkbox.value))
				{
					members.push(checkbox.value);
				}
			}
			else
			{
				members.remove(checkbox.value);
			}
		}
		var memberNodes = ajax.xmlDoc.getElementsByTagName('member');
		for(var i = 0; i < memberNodes.length; ++i)
		{
			var member = memberNodes.item(i);
			var id = getTagValue(member, 'id');
			var name = getTagValue(member, 'name');
			var uniqname = getTagValue(member, 'uniqname');
			
			var checkbox = document.createElement('input');
			checkboxes.push(checkbox);
			checkbox.type = 'checkbox';
			checkbox.id = 'member_'+id;
			checkbox.value = id;
			checkbox.defaultChecked = members.contains(checkbox.value);
			checkbox.onchange = function()
			{
				updateList(this);
			};
			
			var label = document.createElement('label');
			label.id = 'member_'+id+'_name';
			label.setAttribute('for', checkbox.id);
			label.appendChild(document.createTextNode(name));
			label.style.cursor = 'pointer';
			
			var checkTD = document.createElement('td');
			checkTD.appendChild(checkbox);
			var labelTD = document.createElement('td');
			labelTD.style.verticalAlign = 'middle';
			labelTD.appendChild(label);
			
			var tr = document.createElement('tr');
			tr.title = uniqname;
			tr.appendChild(checkTD);
			tr.appendChild(labelTD);
			
			tbody.appendChild(tr);
		}
		
		var buttonTable = document.createElement('table');
		dialog.appendBodyContent(buttonTable);
		var buttonTableBody = document.createElement('tbody');
		buttonTable.appendChild(buttonTableBody);
		var buttonTR = document.createElement('tr');
		buttonTableBody.appendChild(buttonTR);
		
		var selectAllTD = document.createElement('td');
		selectAllTD.className = 'lalign';
		buttonTR.appendChild(selectAllTD);
		var selectAll = document.createElement('a');
		selectAll.appendChild(document.createTextNode('Select All'));
		selectAll.onclick = function()
		{
			for(var i = 0; i < checkboxes.length; ++i)
			{
				checkboxes[i].checked = true;
				updateList(checkboxes[i]);
			}
		};
		selectAllTD.appendChild(selectAll);
		
		var resetAllTD = document.createElement('td');
		resetAllTD.className = 'calign';
		buttonTR.appendChild(resetAllTD);
		var resetAll = document.createElement('a');
		resetAll.appendChild(document.createTextNode('Reset'));
		resetAll.onclick = function()
		{
			for(var i = 0; i < checkboxes.length; ++i)
			{
				checkboxes[i].checked = checkboxes[i].defaultChecked;
				updateList(checkboxes[i]);
			}
		};
		resetAllTD.appendChild(resetAll);
		
		var clearAllTD = document.createElement('td');
		clearAllTD.className = 'ralign';
		buttonTR.appendChild(clearAllTD);
		var clearAll = document.createElement('a');
		clearAll.appendChild(document.createTextNode('Clear All'));
		clearAll.onclick = function()
		{
			for(var i = 0; i < checkboxes.length; ++i)
			{
				checkboxes[i].checked = false;
				updateList(checkboxes[i]);
			}
		};
		clearAllTD.appendChild(clearAll);
		
		dialog.clearStatus();
	};
	ajax.setVariable('dialog', dialog);
	ajax.update('action=get_members');
}

function showCompanyDialog(companyID)
{
	var id = 'company_dialog';
	var width = '850px';
	var top = '50px';
	var dialog = new DialogObject(id, '', null, null, true, width, top);
	
	dialog.setStatus('Loading...');
	dialog.show();
	
	var ajax = new AjaxObject('ajax.php?company='+companyID);
	ajax.htmlResponse = true;
	ajax.callback = function(ajax)
	{
		var dialog = ajax.getVariable('dialog');
		if(!ajax.success)
		{
			dialog.setErrorStatus(ajax.message);
			return;
		}
		dialog.dialogBodyContent.innerHTML = ajax.getVariable('responseText');
		runPostProcessing(dialog.dialogBodyContent);
		dialog.clearStatus();
	};
	ajax.setVariable('dialog', dialog);
	ajax.update('html=1&action=include&path=corporate/company.php');
	
	var header = document.createElement('div');
	header.id= 'header';
	dialog.titleBar.appendChild(header);
	dialog.titleBar.style.background = '#E9EEF5';
	dialog.titleBar.style.borderBottom = '1px solid #CCCCCC';
	dialog.titleBar.style.padding = '0px';
	dialog.showTitle();
	
	var footer = document.createElement('p');
	footer.className = 'calign';
	footer.innerHTML = 'Copyright &copy; 2009 National Society of Black Engineers - University of Michigan Chapter';
	dialog.buttonZone.appendChild(footer);
	dialog.buttonZone.style.backgroundColor = '#E9EEF5';
	dialog.buttonZone.style.borderTop = '1px solid #CCCCCC';
	dialog.showButtonZone();
}

function showPageViewDialog(title, path, params, width, top)
{
	var id = 'page_view_dialog';
	width = width ? width : '500px';
	top = top ? top : '50px';
	var dialog = new DialogObject(id, title, null, null, true, width, top);
	
	dialog.setStatus('Loading...');
	dialog.show();
	
	var ajax = new AjaxObject('ajax.php?'+params);
	ajax.htmlResponse = true;
	ajax.callback = function(ajax)
	{
		var dialog = ajax.getVariable('dialog');
		if(!ajax.success)
		{
			dialog.setErrorStatus(ajax.message);
			return;
		}
		dialog.dialogBodyContent.innerHTML = ajax.getVariable('responseText');
		runPostProcessing(dialog.dialogBodyContent);
		dialog.clearStatus();
	};
	ajax.setVariable('dialog', dialog);
	ajax.update('html=1&action=include&path='+path);
}

function showNewActivityDialog()
{
	function createActivity()
	{
		if(nameInput.value == nameInput.defaultValue)
		{
			dialog.setErrorStatus('Please enter a name for your activity');
			return;
		}
		
		var ajax = new AjaxObject();
		ajax.callback = function(ajax)
		{
			PanelManager.updatePanelObjectByName('activity_list_panel');
			if(!ajax.success)
			{
				dialog.setErrorStatus(ajax.message);
				return;
			}
			
			var eventID = getTagValue(ajax.xmlDoc, 'id');
			showActivityEditorDialog(eventID);
			
			dialog.close();
		};
		ajax.update('action=create_activity&name='+nameInput.value+'&date='+datePicker.getTimestamp());
	}
	
	var div = document.createElement('div');
	div.className = 'calign';
	var nameInput = document.createElement('input');
	nameInput.type = 'text';
	nameInput.defaultValue = 'Activity Name';
	nameInput.style.width = '180px';
	setupInputField(nameInput);
	div.appendChild(nameInput);
	
	div.appendChild(document.createElement('br'));
	var datePicker = new DropdownDatePickerObject();
	datePicker.appendTo(div);
	
	var createButton = document.createElement('input');
	createButton.type = 'button';
	createButton.value = 'Create';
	createButton.onclick = function()
	{
		createActivity();
	};
	
	var id = 'new_activity_dialog';
	var title = 'Create New Activity';
	var width = '250px';
	var dialog = new DialogObject(id, title, div, [createButton], false, width);
	dialog.setFixedPosition(true);
	dialog.show();
}

function showActivityEditorDialog(eventID)
{
	var doneButton = document.createElement('input');
	doneButton.type = 'button';
	doneButton.value = 'Done';
	doneButton.onclick = function()
	{
		dialog.close();
	};
	
	var id = 'activity_editor_dialog';
	var title = 'Edit Activity';
	var width = '500px';
	var top = '100px';
	var dialog = new DialogObject(id, title, null, [doneButton], true, width, top);
	dialog.setFixedPosition(true);
	dialog.onclose = function()
	{
		PanelManager.updatePanelObjectByName('activity_list_panel');
	};
	dialog.setStatus('Loading...');
	dialog.show();
	
	var ajax = new AjaxObject();
	ajax.htmlResponse = true;
	ajax.callback = function(ajax)
	{
		if(!ajax.success)
		{
			dialog.setErrorStatus(ajax.message);
			return;
		}
		
		dialog.clearStatus();
		
		dialog.dialogBodyContent.innerHTML = ajax.getVariable('responseText');
		runPostProcessing(dialog.dialogBodyContent, true);
	};
	ajax.update('html=1&action=edit_activity&id='+eventID);
}

function showImageSelectorDialog(elementID, action)
{
	var box = document.createElement('div');
	box.style.height = '300px';
	box.style.padding = '0px';
	box.style.border = '1px solid #EEEEEE';
	box.style.overflowX = 'hidden';
	box.style.overflowY = 'auto';
	
	var id = 'image_selector_dialog';
	var title = 'Select Image';
	var width = '510px';
	var top = '100px';
	var dialog = new DialogObject(id, title, box, null, true, width, top);
	dialog.setFixedPosition(true);
	dialog.setStatus('Loading...');
	dialog.show();
	
	var ajax = new AjaxObject();
	ajax.setVariable('dialog', dialog);
	ajax.setVariable('element', document.getElementById(elementID));
	ajax.callback = function(ajax)
	{
		var element = ajax.getVariable('element');
		if(!ajax.success)
		{
			dialog.setErrorStatus(ajax.message);
			return;
		}
		
		var table = document.createElement('table');
		table.className = 'auto_width';
		table.style.borderCollapse = 'separate';
		table.style.borderSpacing = '10px';
		table.style.padding = '0px';
		table.style.margin = 'auto';
		box.appendChild(table);
		var tbody = document.createElement('tbody');
		table.appendChild(tbody);
		
		var tr = document.createElement('tr');
		
		var imageNodes = ajax.xmlDoc.getElementsByTagName('file');
		dialog.setNotificationStatus(imageNodes.length+' images');
		for(var i = 0; i < imageNodes.length; ++i)
		{
			var imageNode = imageNodes.item(i);
			var id = getTagValue(imageNode, 'id');
			var filename = getTagValue(imageNode, 'filename');
			
			var td = document.createElement('td');
			td.className = 'outline_light mouseover_outline calign';
			//td.style.width = '100px';
			td.style.cursor = 'pointer';
			td.title = filename;
			td.id = 'image_selector_td_'+id;
			td.onclick = function()
			{
				var id = this.id.substring(this.id.lastIndexOf('_')+1);
				
				var ajax = new AjaxObject();
				ajax.callback = function(ajax)
				{
					if(!ajax.success)
					{
						dialog.setErrorStatus(ajax.message);
						return;
					}
					
					element.src =  'img.php?id='+id;
					dialog.close();
				};
				
				var editID = element.getAttribute('edit_id');
				ajax.update('action=update_user&id='+editID+'&property=photo_id&value='+id);
			};
			tr.appendChild(td);
			
			var img = document.createElement('img');
			img.id = 'image_selector_img_'+id;
			img.onload = function()
			{
				var id = this.id.substring(this.id.lastIndexOf('_')+1);
				var container = document.getElementById('image_selector_td_'+id);
				if(!container)
				{
					return;
				}
				var sizeText = this.width+' x '+this.height;
				resizeImage(this, 100);
				
				var table = document.createElement('table');
				container.appendChild(table);
				var tbody = document.createElement('tbody');
				table.appendChild(tbody);
				var imgRow = document.createElement('tr');
				tbody.appendChild(imgRow);
				var imgTD = document.createElement('td');
				imgTD.style.height = '100px';
				imgTD.style.padding = '0px';
				imgTD.style.verticalAlign = 'middle';
				imgTD.appendChild(this);
				imgRow.appendChild(imgTD);
				var textRow = document.createElement('tr');
				tbody.appendChild(textRow);
				var textTD = document.createElement('td');
				//textTD.style.height = '20px';
				textTD.style.backgroundColor = '#CCCCCC';
				textTD.appendChild(document.createTextNode(sizeText));
				textRow.appendChild(textTD);
			};
			img.src = 'img.php?id='+id;
			
			if(!((i+1) % 4))
			{
				tbody.appendChild(tr);
				tr = document.createElement('tr');
			}
		}
		tbody.appendChild(tr);
		
		dialog.clearStatus();
	};
	ajax.update('action=get_images');
}

function showEmailDialog(from, users)
{
	from = 'NSBE '+from;
	
	var form = document.createElement('form');
	var table = document.createElement('table');
	table.style.width = 'auto';
	table.style.margin = 'auto';
	form.appendChild(table);
	var tbody = document.createElement('tbody');
	table.appendChild(tbody);
	
	var fromRow = document.createElement('tr');
	tbody.appendChild(fromRow);
	
	var fromLabelTD = document.createElement('td');
	fromLabelTD.align = 'right';
	fromLabelTD.style.verticalAlign = 'top';
	fromLabelTD.style.paddingTop = '2px';
	fromLabelTD.style.paddingRight = '5px';
	//fromRow.appendChild(fromLabelTD);
	var fromLabel = document.createElement('strong');
	fromLabel.appendChild(document.createTextNode('From:'));
	fromLabelTD.appendChild(fromLabel);
	
	var fromInputTD = document.createElement('td');
	fromInputTD.style.padding = '2px 0px 2px 0px';
	fromRow.appendChild(fromInputTD);
	var fromInputField = document.createElement('input');
	fromInputField.type = 'text';
	fromInputField.value = 'NSBE Telecommunications Chair <nsbe.telecom@umich.edu>';
	fromInputField.title = 'From';
	fromInputField.style.width = '400px';
	setupInputField(fromInputField);
	//fromInputTD.appendChild(fromInputField);
	
	var toRow = document.createElement('tr');
	tbody.appendChild(toRow);
	
	var toLabelTD = document.createElement('td');
	toLabelTD.align = 'right';
	toLabelTD.style.verticalAlign = 'top';
	toLabelTD.style.paddingTop = '2px';
	toLabelTD.style.paddingRight = '5px';
	//toRow.appendChild(toLabelTD);
	var toLabel = document.createElement('strong');
	toLabel.appendChild(document.createTextNode('To:'));
	toLabelTD.appendChild(toLabel);
	
	var toInputTD = document.createElement('td');
	toInputTD.style.padding = '2px 0px 2px 0px';
	toRow.appendChild(toInputTD);
	var toSelect = document.createElement('select');
	var toOptions = [
	//'Membership <nsbeum@umich.edu>',
	'Executive Board <nsbe.eboard@umich.edu>',
	'Programs Zone <nsbe.pzone@umich.edu>',
	'Junior Executive Board <nsbe.jeb@umich.edu>',
	'Executive Board <nsbe.eboard@umich.edu>, Programs Zone <nsbe.pzone@umich.edu>',
	'Executive Board <nsbe.eboard@umich.edu>, Programs Zone <nsbe.pzone@umich.edu>, Junior Executive Board <nsbe.jeb@umich.edu>'
	];
	for(var i = 0; i < toOptions.length; ++i)
	{
		var option = document.createElement('option');
		option.value = toOptions[i];
		option.appendChild(document.createTextNode(toOptions[i]));
		toSelect.appendChild(option);
	}
	if(users)
	{
		userOptions = users.split(',');
		for(var i = 0; i < userOptions.length; ++i)
		{
			var option = document.createElement('option');
			option.value = userOptions[i];
			option.appendChild(document.createTextNode(userOptions[i]));
			toSelect.appendChild(option);
		}
	}
	toSelect.title = 'To';
	toSelect.style.width = '406px';
	toInputTD.appendChild(toSelect);
	
	var subjectRow = document.createElement('tr');
	tbody.appendChild(subjectRow);
	
	var subjectLabelTD = document.createElement('td');
	subjectLabelTD.align = 'right';
	subjectLabelTD.style.verticalAlign = 'top';
	subjectLabelTD.style.paddingTop = '2px';
	subjectLabelTD.style.paddingRight = '5px';
	//subjectRow.appendChild(subjectLabelTD);
	var subjectLabel = document.createElement('strong');
	subjectLabel.appendChild(document.createTextNode('Subject:'));
	subjectLabelTD.appendChild(subjectLabel);
	
	var subjectInputTD = document.createElement('td');
	subjectInputTD.style.padding = '2px 0px 2px 0px';
	subjectRow.appendChild(subjectInputTD);
	var subjectInputField = document.createElement('input');
	subjectInputField.type = 'text';
	subjectInputField.defaultValue = 'Subject';
	subjectInputField.title = 'Subject';
	subjectInputField.style.width = '400px';
	setupInputField(subjectInputField);
	subjectInputTD.appendChild(subjectInputField);
	
	var messageRow = document.createElement('tr');
	tbody.appendChild(messageRow);
	
	var messageLabelTD = document.createElement('td');
	messageLabelTD.align = 'right';
	messageLabelTD.style.verticalAlign = 'top';
	messageLabelTD.style.paddingTop = '2px';
	messageLabelTD.style.paddingRight = '5px';
	//messageRow.appendChild(messageLabelTD);
	var messageLabel = document.createElement('strong');
	messageLabel.appendChild(document.createTextNode('Message:'));
	messageLabelTD.appendChild(messageLabel);
	
	var messageInputTD = document.createElement('td');
	messageInputTD.style.padding = '2px 0px 2px 0px';
	messageRow.appendChild(messageInputTD);
	var messageTextarea = document.createElement('textarea');
	messageTextarea.defaultValue = 'Message';
	messageTextarea.title = 'Message';
	messageTextarea.style.width = '400px';
	messageTextarea.maxRows = 10;
	setupTextarea(messageTextarea);
	messageInputTD.appendChild(messageTextarea);
	
	var p = document.createElement('p');
	p.className = 'calign';
	p.appendChild(document.createTextNode('Email will be sent as: '+from));
	form.appendChild(p);
	
	var sendButton = document.createElement('input');
	sendButton.type = 'button';
	sendButton.value = 'Send';
	sendButton.onclick = function()
	{
		dialog.setStatus('Sending...');
		
		if(subjectInputField.value == subjectInputField.defaultValue)
		{
			dialog.setErrorStatus('Please enter a subject for your email');
			subjectInputField.focus();
			return;
		}
		if(messageTextarea.value == messageTextarea.defaultValue)
		{
			dialog.setErrorStatus('You cannot send an empty message');
			messageTextarea.focus();
			return;
		}
		
		var to = 'NSBE '+toSelect.value;
		var subject = subjectInputField.value;
		var message = messageTextarea.value;
		
		var ajax = new AjaxObject();
		ajax.callback = function(ajax)
		{
			if(!ajax.success)
			{
				dialog.setErrorStatus(ajax.message);
				return;
			}
			
			dialog.hideTitle();
			dialog.hideBodyContent();
			dialog.hideButtonZone();
			dialog.setInfoStatus('Message successfully sent');
			
			DialogManager.closeDialog(dialog, 1*SECOND);
		};
		ajax.update('action=send_email&to='+to+'&subject='+subject+'&message='+message+'&from='+from);
	};
	
	var id = 'send_email_dialog';
	var title = 'Send Email';
	var width = '475px';
	var top = '100px';
	var dialog = new DialogObject(id, title, form, [sendButton], true, width, top);
	dialog.setFixedPosition(true);
	dialog.show();
}
