var menuObjYPos = -1;

function ajax_adapt_to_browser() {
	var xmlhttp = null;
	if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp = new XMLHttpRequest();
	} else {// code for IE6, IE5
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	return xmlhttp;
}

function requestbanner(category) {
	var xmlhttp = ajax_adapt_to_browser();
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4) {
			document.getElementById('banner').innerHTML = xmlhttp.responseText;
		}
	};
	xmlhttp.open("GET", "getbanner.php?cat=" + category, true);
	xmlhttp.send(null);
}

function load_menu_item(category) {
	var parsedCat = category.substring(8);
	var xmlhttp = ajax_adapt_to_browser();
	var xmlhttp2 = ajax_adapt_to_browser();
	var count = 0;
	var label = document.getElementById("statuslabel"); 
	label.innerHTML = "<span style='background: white;'>Loading...</span>";
	label.style.display = "block";
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4) {
			document.getElementById('content').innerHTML = xmlhttp.responseText;
			count++;
			if (count == 2)
			{
				label.innerHTML = "";
				label.style.display = "none";
			}
		}
	};
	xmlhttp2.onreadystatechange = function()
	{
		if (xmlhttp2.readyState == 4) {
			document.getElementById('subsections').innerHTML = xmlhttp2.responseText;
			count++;
			if (count == 2)
			{
				label.innerHTML = "";
				label.style.display = "none";
			}
		}
	};
	
	xmlhttp.open("GET", "getcontent.php?cat=" + parsedCat, true);
	xmlhttp.send(null);
	xmlhttp2.open("GET", "getsectionslist.php?cat=" + parsedCat, true);
	xmlhttp2.send(null);
}

function ajax_login()
{
	
	//document.getElementById("form_login").submit();
	
	
	var url = "login.php";
	var label = document.getElementById("statuslabel"); 
	var username = document.getElementById("myusername");
	var password = document.getElementById("mypassword");
	var checkbox = document.getElementById("rememberCheckbox");
	var remember = checkbox.checked ? 1 : 0;
	var params = "myusername=" + username.value + "&mypassword=" + password.value + "&remember="+remember;
	var xmlhttp = ajax_adapt_to_browser();
	xmlhttp.open("POST", url, true);
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
	label.innerHTML = "<span style='background: white;'>Logging in...</span>";
	label.style.display = "block";
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4) {
			document.getElementById('loginBox').innerHTML = xmlhttp.responseText;
			label.innerHTML = "";
			label.style.display = "none";
		}
	};
	
}

function ajax_loadmanager(userid)
{
	var url = "getmanager.php";
	var username = userid;
	var params = "userid=" + userid;
	var xmlhttp = ajax_adapt_to_browser();
	xmlhttp.open("POST", url, true);
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
	var label = document.getElementById("statuslabel"); 
	label.innerHTML = "<span style='background: white;'>Loading...</span>";
	label.style.display = "block";
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById('content').innerHTML = xmlhttp.responseText;
			label.innerHTML = "";
			label.style.display = "none";
		}
	};
}

function loadmanagerchoice (choice)
{
	switch (choice)
	{
		case 1:
			url = "addnewcontent.php";
			break;
		case 2:
			url = "modifycontent.php";
			break;
		case 3:
			url = "deletecontent.php";
			break;
		case 4:
			url = "createnewuser.php";
			break;
		default:
				return;
	}

	var params = ""
	var xmlhttp = ajax_adapt_to_browser();
	xmlhttp.open("POST", url, true);
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
	var label = document.getElementById("statuslabel"); 
	label.innerHTML = "<span style='background: white;'>Loading...</span>";
	label.style.display = "block";
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById('content').innerHTML = xmlhttp.responseText;
			label.innerHTML = "";
			label.style.display = "none";
		}
	};
};

function contenttoggle(item) {
	//var ele = document.getElementById("toggle_"+item);
	var text = document.getElementById("display_" + item);
	var toggle = document.getElementById("toggle_" + item);
	if(text.style.display == "block")
	{
		toggle.style.borderWidth = "4px";
		text.style.display = "none";
		toggle.style.marginBottom = "10px";
		toggle.style.textShadow = "";
  	}
	else
	{
		toggle.style.borderWidth = "2px";
		toggle.style.borderBottomWidth = "0px";
		text.style.display = "block";
		toggle.style.marginBottom = "0px";
		toggle.style.textShadow = "#3E5F7A 2px -2px 2px";
	}
} 


function clearusername(elem)
{
	// only clear input if it is default
	if (elem.value != "Username")
		return;
	elem.value = '';
}

function hide_overlay(elem)
{
	var id = elem.id.substr(8);
	document.getElementById(id).style.display = "inline-block";
	document.getElementById(id).focus();
	elem.style.display = "none";
}

function show_overlay(elem)
{
	// only show overlay if no password was typed in
	if (elem.value != '')
		return;
	var id = "overlay_"+elem.id;
	document.getElementById(id).style.display = "inline-block";
	elem.style.display = "none";
}

function defaultusername(elem)
{
	if (elem.value == '')
	{
		elem.value = "Username";
	}
}

function initLogoUpload()
{
	_divForm = document.getElementById('divImgUpload');
	_spanUploading = document.getElementById('spanUploading');
    _divUploadMessage = document.getElementById('divUploadMessage');
    _divUploadProgress = document.getElementById('divUploadProgress');
    _ifrPhoto = document.getElementById('ifrPhoto');

    var btnUpload = _ifrPhoto.contentWindow.document.getElementById('btnUpload');

    // HANDLING SUBMIT
    btnUpload.onclick = function(event)
    {
        var filPhoto = _ifrPhoto.contentWindow.document.getElementById('filPhoto');

        //Baisic validation for Photo
        _divUploadMessage.style.display = 'none';

        if (filPhoto.value.length == 0)
        {
            _divUploadMessage.innerHTML = '<span style=\"color:#ff0000\">Please specify the file.</span>';
            _divUploadMessage.style.display = 'block';
            filPhoto.focus();
            return;
        }

        //var regExp = /^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.jpg|.JPG|.gif|.GIF|.png|.PNG|.bmp|.BMP)$/;

        //if (!regExp.test(filPhoto.value)) //Somehow the expression does not work in Opera
        if (!validateImageUpload(filPhoto.value))
        {
            _divUploadMessage.innerHTML = '<span style=\"color:#ff0000\">Invalid file type. Only supports jpg, gif, png and bmp.</span>';
            _divUploadMessage.style.display = '';
            filPhoto.focus();
            return;
        }

        _ifrPhoto.contentWindow.document.getElementById('photoUpload').submit();
        _spanUploading.style.display = 'block';
        _divForm.style.display = 'none';
    }
}

function validateImageUpload(theForm) {
	var extensions = new Array("jpg", "jpeg", "gif", "png", "bmp");

	/*
	 * // Alternative way to create the array
	 * 
	 * var extensions = new Array();
	 * 
	 * extensions[1] = "jpg"; extensions[0] = "jpeg"; extensions[2] = "gif";
	 * extensions[3] = "png"; extensions[4] = "bmp";
	 */

	var image_file = theForm.image.value;

	var image_length = image_file.length;

	var pos = image_file.lastIndexOf('.') + 1;

	var ext = image_file.substring(pos, image_length);

	var final_ext = ext.toLowerCase();

	for (i = 0; i < extensions.length; i++) {
		if (extensions[i] == final_ext) {
			return true;
		}
	}

	alert("You must upload an image file with one of the following extensions: "
			+ extensions.join(', ') + ".");
	return false;
}

function uploadNewContent(userid)
{
	var url = "manageContent.php";
	var form = document.getElementById("newcontent");
	var requestType = escape(encodeURI("1"));
	var source =  escape(encodeURI(userid));
	var contentTitle = escape(encodeURI(form.contenttitle.value));
	var category = escape(encodeURI(form.categoryPicker.options[form.categoryPicker.selectedIndex].value));
	var highlightType = escape(encodeURI(form.highlightTypePicker.options[form.highlightTypePicker.selectedIndex].value));
	var htmlText = escape(encodeURI(document.getElementById("contenthtmltext").value));
	htmlText = htmlText.replace(/%250A/g, "<br />");
	var imageKey = 0;
	var myObject = document.getElementById("uploadedImageKey");
	if (myObject !== null && typeof(myObject) !== 'undefined')
	{
		imageKey = escape(encodeURI(myObject.innerHTML));
	}
	var params = "requestType="+requestType+"&source=" + source + "&contentTitle="+contentTitle+"&category="+category+"&htmlText="+htmlText+"&highlightType="+highlightType+"&imageKey="+imageKey;
	var xmlhttp = ajax_adapt_to_browser();
	xmlhttp.open("POST", url, true);
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
	var label = document.getElementById("statuslabel"); 
	label.innerHTML = "<span style='background: white;'>Creating content...</span>";
	label.style.display = "block";
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById('content').innerHTML = xmlhttp.responseText;
			label.innerHTML = "";
			label.style.display = "none";
		}
	};
}

function modifyContent(userid)
{
	var url = "manageContent.php";
	var form = document.getElementById("modifyContent");
	var requestType = escape(encodeURI("2"));
	var contentId = escape(encodeURI(form.contentPicker.options[form.contentPicker.selectedIndex].value));
	var source =  escape(encodeURI(userid));
	var contentTitle = escape(encodeURI(form.contenttitle.value));
	var category = escape(encodeURI(form.categoryPicker.options[form.categoryPicker.selectedIndex].value));
	var highlightType = escape(encodeURI(form.highlightTypePicker.options[form.highlightTypePicker.selectedIndex].value));
	var htmlText = escape(encodeURI(document.getElementById("contenthtmltext").value));
	htmlText = htmlText.replace(/%250A/g, "<br />");
	var imageKey = escape(encodeURI(document.getElementById("uploadedImageKey").innerHTML));
	var params = "requestType="+requestType+"&contentId=" + contentId + "&source=" + source + "&contentTitle="+contentTitle+"&category="+category+"&htmlText="+htmlText+"&highlightType="+highlightType+"&imageKey="+imageKey;
	var xmlhttp = ajax_adapt_to_browser();
	xmlhttp.open("POST", url, true);
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
	var label = document.getElementById("statuslabel"); 
	label.innerHTML = "<span style='background: white;'>Modifying content...</span>";
	label.style.display = "block";
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById('content').innerHTML = xmlhttp.responseText;
			label.innerHTML = "";
			label.style.display = "none";
		}
	};
}

function loadContentById(userId)
{
	var url = "loadContentById.php";
	var form = document.getElementById("modifyContent");
	var content = escape(encodeURI(form.contentPicker.options[form.contentPicker.selectedIndex].value));
	var params = "userId="+escape(encodeURI(userId))+"&idContent="+content;
	var xmlhttp = ajax_adapt_to_browser();
	xmlhttp.open("POST", url, true);
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
	var label = document.getElementById("statuslabel"); 
	label.innerHTML = "<span style='background: white;'>Fetching content data...</span>";
	label.style.display = "block";
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			label.innerHTML = "";
			label.style.display = "none";
			var responseDoc = xmlhttp.responseText.split(";;;;;");
			if (responseDoc.length < 2)
			{
				document.getElementById("fieldset_contentinfo").style.display = "none";
				document.getElementById("fieldset_contenttitle").style.display = "none";
				document.getElementById("fieldset_contenttext").style.display = "none";
				document.getElementById("fieldset_contenthighlighttype").style.display = "none";
				document.getElementById("modifycontent_submit").style.display = "none";
				document.getElementById("fieldset_logoUpload").style.display = "none";
			}
			else
			{
				var contentId = responseDoc[0];
				var contentSource = responseDoc[1]; // Name
				var contentHtmlText = responseDoc[2];
				var contentCreationTime = responseDoc[3]; // Probably have to convert from SQL Datetime
				var contentTitle = responseDoc[4];
				var contentHighlightType = responseDoc[5];
				document.getElementById("contentsource").innerHTML = "Source: " + contentSource;
				document.getElementById("contentcreationtime").innerHTML = "Creation Time: " + contentCreationTime;
				document.getElementById("contenttitle").value = contentTitle;
				document.getElementById("contenthtmltext").value = contentHtmlText.replace(/<br \/>/g, "\n");
				var highlightTypes = document.getElementById("modify_highlightTypePicker").options;
				for (var i=0;i<highlightTypes.length;i++)
				{
					if (highlightTypes[i].value == contentHighlightType)
					{
						highlightTypes[i].selected = "selected";
						break;
					}
				}
				if (contentHighlightType > 1)
				{
					document.getElementById("fieldset_logoUpload").style.display = "block";
				}
				else
				{
					document.getElementById("fieldset_logoUpload").style.display = "none";
				}
				
				document.getElementById("fieldset_contentinfo").style.display = "block";
				document.getElementById("fieldset_contenttitle").style.display = "block";
				document.getElementById("fieldset_contenttext").style.display = "block";
				document.getElementById("fieldset_contenthighlighttype").style.display = "block";
				document.getElementById("modifycontent_submit").style.display = "block";
			}
		}
	};
}

function toggleImageUpload(userid, theSelect)
{
	var highlightType = theSelect.options[theSelect.selectedIndex].value;
	var uploadFieldset = document.getElementById("fieldset_logoUpload");
	if (highlightType > 1)
	{
		//toggle
		uploadFieldset.style.display = "block";
	}
	else
	{
		//untoggle
		uploadFieldset.style.display = "none";
	}
}

function loadContentsByCat(userid)
{
	var url = "loadContentsByCat.php";
	var form = document.getElementById("modifyContent");
	var category = escape(encodeURI(form.categoryPicker.options[form.categoryPicker.selectedIndex].value));
	var contentsSelect = form.contentPicker;
	
	//clear stuff
	contentsSelect.options.length = 0;
	document.getElementById("fieldset_contentinfo").style.display = "none";
	document.getElementById("fieldset_contenttitle").style.display = "none";
	document.getElementById("fieldset_contenttext").style.display = "none";
	document.getElementById("fieldset_contenthighlighttype").style.display = "none";
	document.getElementById("modifycontent_submit").style.display = "none";
	//end clear stuff
	var params = "userId="+escape(encodeURI(userid))+"&idContentCategory="+category;
	var xmlhttp = ajax_adapt_to_browser();
	xmlhttp.open("POST", url, true);
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
	var label = document.getElementById("statuslabel"); 
	label.innerHTML = "<span style='background: white;'>Fetching contents...</span>";
	label.style.display = "block";
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			label.innerHTML = "";
			label.style.display = "none";
			var responseDoc = xmlhttp.responseText;
			var arrContents = responseDoc.split(";");
			var fail = 0;
			if (arrContents.length == 1) // Yeah.
			{
				contentsSelect.disabled = true;
				var elOptNew = document.createElement('option');
			    elOptNew.value = 0;
				elOptNew.text = "You can not modify any contents in this category."; 
			    try {
			    	contentsSelect.add(elOptNew, null); // standards compliant; doesn't work in IE
			    }
			    catch(ex) {
			    	contentsSelect.add(elOptNew); // IE only
			    }
			}
			else
			{
				var elOptNew = document.createElement('option');
			    elOptNew.value = 0;
				elOptNew.text = ""; 
			    try {
			    	contentsSelect.add(elOptNew, null); // standards compliant; doesn't work in IE
			    }
			    catch(ex) {
			    	contentsSelect.add(elOptNew); // IE only
			    }
				for (var i=0;i<arrContents.length-1;i++)
				{
					var content = arrContents[i];
					var contentData = content.split(":");
					elOptNew = document.createElement('option');
				    elOptNew.value = contentData[0];
					elOptNew.text = contentData[1]; 
				    try {
				    	contentsSelect.add(elOptNew, null); // standards compliant; doesn't work in IE
				    }
				    catch(ex) {
				    	contentsSelect.add(elOptNew); // IE only
				    }
				}
				contentsSelect.disabled = false;
			}
			var contentsFieldset = document.getElementById("fieldset_contents");
			contentsFieldset.style.display = "block";
		}
	};
}

function createNewUser()
{
	var theForm = document.getElementById("newuser");
	var userName = escape(encodeURI(theForm.username.value));
	var password = escape(encodeURI(theForm.password.value));
	var isAdmin = escape(encodeURI(theForm.isAdmin.checked?"1":"0"));
	var strCats = "";
	var cats = theForm.categoryPermissionsPicker.options;
	for (var i=0;i<cats.length;i++)
	{
		
		if (cats[i].selected == true)
		{
			strCats = strCats + cats[i].value + ";";
		}
	}
	cats = escape(encodeURI(cats));
	var url = "insertNewUser.php";
	var params = "username="+userName+"&password="+password+"&isAdmin="+isAdmin+"&cats="+strCats;
	alert("params: "+params);
	var xmlhttp = ajax_adapt_to_browser();
	xmlhttp.open("POST", url, true);
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
	var label = document.getElementById("statuslabel"); 
	label.innerHTML = "<span style='background: white;'>Creating user...</span>";
	label.style.display = "block";
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			document.getElementById('content').innerHTML = xmlhttp.responseText;
			label.innerHTML = "";
			label.style.display = "none";
		}
	};
}

function ajax_logout(userid)
{
	load_menu_item("menuitem1");
	var url = "logout.php";
	var username = userid;
	var label = document.getElementById("statuslabel"); 
	var params = "userid=" + userid;
	var xmlhttp = ajax_adapt_to_browser();
	xmlhttp.open("POST", url, true);
	//Send the proper header information along with the request
	xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlhttp.setRequestHeader("Content-length", params.length);
	xmlhttp.setRequestHeader("Connection", "close");
	xmlhttp.send(params);
	label.innerHTML = "<span style='background: white;'>Logging out...</span>";
	label.style.display = "block";
	xmlhttp.onreadystatechange = function()
	{
		if(xmlhttp.readyState == 4) {
			document.getElementById('loginBox').innerHTML = xmlhttp.responseText;
			label.innerHTML = "";
			label.style.display = "none";
		}
	};
}

function setbg(elem, color)
{
	elem.style.background=color
}

function refresh_calendar(type, _o, _c, _m, _a, _y, _w) {
	var xmlhttp = ajax_adapt_to_browser();
	var label = document.getElementById("statuslabel"); 
	label.innerHTML = "<span style='background: white;'>";
	switch (type)
	{
	case "view":
		label.innerHTML += "Loading calendar view...";
		break;
	case "year":
		label.innerHTML += "Loading year...";
		break;
	case "month":
		label.innerHTML += "Loading month...";
		break;
	case "week":
		label.innerHTML += "Loading week...";
		break;
	case "day":
		label.innerHTML += "Loading day...";
		break;
	}
	label.innerHTML += "</span>";
	label.style.display = "block";
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4) {
			document.getElementById('content').innerHTML = xmlhttp.responseText;
			label.innerHTML = "";
			label.style.display = "none";
		}
	};
	
	xmlhttp.open("GET", "calendar/index.php?o=" + _o + "&c=" + _c + "&m=" + _m + "&a=" + _a + "&y=" + _y + "&w=" + _w, true);
	xmlhttp.send(null);
}

function highlight_list(theList, mode)
{
	///TODO: parentNode stuff, theRow.type is undefined!
	//alert ("thistype: "+typeof theRow);
	//alert ("thisParenttype: "+typeof theRow.parentNode);
	//alert ("grandgrandparent.innerHTML: "+theObj.parentNode.parentNode.parentNode.innerHTML);
	//var theRow = theObj.parentNode.parentNode.parentNode;
	var num = theList.length;
	//alert ("length: "+cols);
	for (i=0; i<num; i++)
	{
		//alert("theId: "+theList[i].id);
		if (theList[i].id != "today" && i != 0)
		{
			if (mode == 1)
			{
				//alert (c.innerHTML);
				theList[i].style.backgroundColor = "moccasin";
			}
			else
			{
				//alert (c.innerHTML);
				theList[i].style.backgroundColor = "white";
			}
		}
		if (mode == 1)
		{
			theList[i].style.textDecoration = "underline";
		}
		else
		{
			theList[i].style.textDecoration = "none";
		}
	}
}

function highlightDay (dayTopNode, mode)
{
	var retArr = [];
	var count = 0;
	var sib = dayTopNode;
	retArr[count] = dayTopNode;
	count++;
	while (sib = sib.nextSibling)
	{
		if (sib.nodeType != 1)
			continue;
		retArr[count] = sib;
		count++;
	}
	highlight_list(retArr, mode);
}

function loadContent (url, params, caption)
{
	//alert("test");
	var xmlhttp = ajax_adapt_to_browser();
	var label = document.getElementById("statuslabel");
	if (caption == undefined)
		caption = "Loading page...";
	label.innerHTML = "<span style='background: white;'>"+caption+"</span>";
	label.style.display = "block";
	xmlhttp.onreadystatechange = function()
	{
		if (xmlhttp.readyState == 4) {
			document.getElementById('content').innerHTML = xmlhttp.responseText;
			label.innerHTML = "";
			label.style.display = "none";
		}
	};
	
	xmlhttp.open("GET", url+"?"+params, true);
	xmlhttp.send(null);
}

function updateDateTime (theId)
{
	alert(theId);
	var timeDiv = document.getElementById(theId + "_time");
	var dateDiv = document.getElementById(theId + "_date");
	
	var theInput = document.getElementById(theId);

	var theDay = parseInt(theInput.value.substring(0,2));
	var theMonth = parseInt(theInput.value.substring(3,5));
	var theYear = parseInt(theInput.value.substring(6,10));
	var theTime = theInput.value.substring(11);
	
	var month=new Array(12);
	month[0]="January";
	month[1]="February";
	month[2]="March";
	month[3]="April";
	month[4]="May";
	month[5]="June";
	month[6]="July";
	month[7]="August";
	month[8]="September";
	month[9]="October";
	month[10]="November";
	month[11]="December";
	
	dateDiv.innerHTML = month[theMonth] + " " + theDay + ", " + theYear;
	timeDiv.innerHTML = "at " + theTime;
}
