//    Misc. variable assignment
var timer = 0;

//    Assembles the email POST request
function sendEmail(name,from,subj,body) 
  {
  var url = "../scripts/sendmail.php";
  var name = document.contact.name.value;
  var from = document.contact.from.value;
  var body = document.contact.body.value;
  var params = 'to=' + toaddress + '&from=' + from + '&body=' + body + '&name=' + name;
  post(url,params);
  timer = 1;
  clearDiv();
}

//    Creates the email form
function popMail(to) 
  {
  toaddress = to;
  var url = "../scripts/mail.php";
  var params = "";
  post(url,params);
}

//    Updates the page to reflect the returned info
function updatePage() 
{
  if (request.readyState == 4) 
  {
    if (request.status == 200) 
	{
	  var response = request.responseText;
	  var newelement = document.getElementById('mail');
	  var newdiv = document.createElement('div');
	  var newdivID = 'form';
	  var newdivStyle = 'visible';
	  newdiv.setAttribute('id',newdivID);
	  newdiv.innerHTML = response;
	  newelement.appendChild(newdiv);
	  if (timer == 1)
	  {
	    setTimeout('clearDiv()',3000);
		timer = 0;
	  }
    }
  }
}


//    Remove the email form
function clearDiv() 
  {
  parentdiv = document.getElementById('mail');
  olddiv = document.getElementById('form');
  parentdiv.removeChild(olddiv);
}