// JavaScript Document
function addLoadEvent(func) 
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function') 
  {
    window.onload = func;
  } 
  else
  {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
function prepareForm() 
{
	//alert("preparing");
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	if (!document.getElementById("msgForm")) return false;
	var myForm = document.getElementById("msgForm");
	var inputs = myForm.getElementsByTagName("input");
	for ( var i=0; i < inputs.length; i++) 
	{
		inputs[i].onchange = function() 
		{
			return updateMsg(this);
		}
	}
		
	taArr = myForm.getElementsByTagName("textarea");
	taArr[0].onchange = function() 
		{
			return updateMsg(this);
		}/**/
}
function updateMsg(whichElement)
{
	var myValue = whichElement.value;
//	alert(myValue);
	switch(whichElement.getAttribute("id"))
	{
		case "urName":
//			alert(whichElement.getAttribute("id"));
			var fromName = document.getElementById("fromName");
			fromName.firstChild.nodeValue = "From "+myValue;
//			alert(fromName.firstChild.nodeValue);
			break;
		case "friendName":
			var toName = document.getElementById("toName");
			toName.firstChild.nodeValue = "Hi "+myValue+",";
			break;
		case "urMsg":
			var custMsg = document.getElementById("custMsg");
			custMsg.firstChild.nodeValue = myValue;
			//alert(custMsg.firstChild.nodeValue);
			break;
	}
}
addLoadEvent(prepareForm);
