
	var attachConn;
	var attachUpdate;
	var emailConn
	var mailboxUpdate
	var attachCount=0;
	var attachFiles = new Array();
	var attachCurrent;
	var files;
	var c = 1;
	
	function sendEmail(attach) {   //compatible with FCKeditor
		emailConn = new XHConn();
		mailboxUpdate = function (oXML) { document.getElementById('emailContent').innerHTML = oXML.responseText; }
		var oEditor = FCKeditorAPI.GetInstance('composeText') ;
		var composeText = encodeURIComponent(oEditor.GetXHTML())
		var pars = "email=send&forward=" + attach + "&composeFrom=" + document.getElementById('composeFrom').value + "&composeTo=" + document.getElementById('composeTo').value + "&composeCc=" + document.getElementById('composeCc').value + "&composeBcc=" + document.getElementById('composeBcc').value + "&composeSubject=" + document.getElementById('composeSubject').value  + "&composeText=" +  composeText + "&mode=" + document.getElementById('mode').value;
		mailboxEmail(pars);
		
	}
		
/*	function CKEDITTORsendEmail(attach) {
	  emailConn = new XHConn();
	  mailboxUpdate = function (oXML) { document.getElementById('emailContent').innerHTML = oXML.responseText; }
		var oEditor = CKEDITOR.instances.composeText;
		var composeText = encodeURIComponent(oEditor.getData());  //encodes special characters
  	var pars = "email=send&forward=" + attach + "&composeFrom=" + document.getElementById('composeFrom').value + "&composeTo=" + document.getElementById('composeTo').value + "&composeCc=" + document.getElementById('composeCc').value + "&composeBcc=" + document.getElementById('composeBcc').value + "&composeSubject=" + document.getElementById('composeSubject').value  + "&composeText=" +  composeText + "&mode=" + document.getElementById('mode').value;
		mailboxEmail(pars);
	}*/
	
	function mailboxEmail (pars) {
		if (emailConn) {
			emailConn.connect("webmail/ajax/send.php", "POST", pars, mailboxUpdate);
		}
		else {
			attachError('Unable to connect to server.');	
		}
	}
		
	function mailboxToggleRow (id) {
		if (!document.getElementById('messRow' + id).style.backgroundColor) {
			document.getElementById('messRow' + id).style.backgroundColor = '#FFFFCC';	
		}
		else
		{
			document.getElementById('messRow' + id).style.backgroundColor = '';	
		}	
	}
	
	function mailboxMarkSpam () {
		document.getElementById('mailboxNewFolder').value = 'spam';
		document.forms.messages.submit();
	}
	
	function mailboxNotSpam () {
		document.getElementById('mailboxNewFolder').value = 'inbox';
		document.forms.messages.submit();
	}
	
	function mailboxAttachInit (attach) {
		attachCurrent = attach;
		attachConn = new XHConn();
		attachUpdate = function (aoXML) { document.getElementById('attachments').innerHTML = aoXML.responseText; }
		mailboxAttachAjax ('init=1&current=' + attach);
	}
	
	function mailboxAttachAjax (pars) {
		if (attachConn) {
			attachConn.connect("webmail/ajax/attach.php", "POST", pars, attachUpdate);        //original
		}
		else
		{
			attachError('Unable to connect to server.');	
		}
	}
	
	function mailboxAttachAdd () {
		c = 1;
		while (c <= attachCount) {
			if (document.getElementById('attach' + c)) {
				files = files + '*' + document.getElementById('attach' + c).value;
			}
			c=c+1;
		}
		attachCount = attachCount + 1;
		mailboxAttachAjax ('add=1&count=' + attachCount + '&files=' + files + '&current=' + attachCurrent);
	}
	
	function switchDiv(div_id)
	{
	  var style_sheet = getStyleObject(div_id);
	  if (style_sheet)
	  {
		changeObjectVisibility(div_id, "visible");
	  }
	  else 
	  {
		alert("sorry, this only works in browsers that do Dynamic HTML");
	  }
	}
	
	function getStyleObject(objectId) {
	  // checkW3C DOM, then MSIE 4, then NN 4.
	  //
	  if(document.getElementById && document.getElementById(objectId)) {
		return document.getElementById(objectId).style;
	   }
	   else if (document.all && document.all(objectId)) {  
		return document.all(objectId).style;
	   } 
	   else if (document.layers && document.layers[objectId]) { 
		return document.layers[objectId];
	   } else {
		return false;
	   }
	}
	
	function changeDiv(the_div,the_change)
	{
	  var the_style = getStyleObject(the_div);
	  if (the_style != false)
	  {
		the_style.display = the_change;
	  }
	}
	
	function hideAll()
	{
	   changeObjectVisibility("cc","none");
	   changeObjectVisibility("bcc","none");
	}

