var xmlHttpEmail;

function sendEmail(){
	if(dojo.byId("name").value == ""){
		dojo.byId("emailWarning").innerHTML = "Please enter your name.";
		dojo.byId("name").focus();
		abort();
	}
	else if(dojo.byId("email").value == ""){
		dojo.byId("emailWarning").innerHTML = "Please enter your email address.";
		dojo.byId("email").focus();
		abort();
	}
	else if(dojo.byId("subject").value == ""){
		dojo.byId("emailWarning").innerHTML = "Please enter a subject line.";
		dojo.byId("subject").focus();
		abort();
	}

	xmlHttpEmail = GetXmlHttpObject();
	if(xmlHttpEmail == null)
 	{
 		alert ("Browser does not support HTTP Request");
 		return;
 	}

	var url = "ofphp/mailsender.php";  //not sure why we don't backout a folder
	url += "?sid=" + Math.random();
	url += "&title=" + dijit.byId('emailDialog').titleNode.innerHTML;
	url += "&name=" + dijit.byId('name').value;
	url += "&email=" + dijit.byId('email').value;
	url += "&phone=" + dijit.byId('phone').value;
	url += "&subject=" + dijit.byId('subject').value;
	if(dijit.byId('cb1').checked)
		url += "&copy=true";
	else
		url += "&copy=false";

	var postData = "postData=" + dojo.byId('msg').value; 
	
	xmlHttpEmail.open("POST", url, true);
	xmlHttpEmail.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttpEmail.setRequestHeader("Content-length", postData.length);
	xmlHttpEmail.setRequestHeader("Connection", "close");
	xmlHttpEmail.onreadystatechange = stateChangedEmail; 
	xmlHttpEmail.send(postData);			
}

function stateChangedEmail()
{ 
	if(xmlHttpEmail.readyState==4 || xmlHttpEmail.readyState=="complete"){ 
/*		if(!checkErrors(xmlHttp0))
	{
		clearMySQLTimeout();
	}
*/
		alert(xmlHttpEmail.responseText);
	}	
}

function openEmailDlg(eAccount){
	dojo.byId("emailWarning").innerHTML = "";
	dijit.byId("name").attr("value", "");
	dijit.byId("email").attr("value", "");
	dijit.byId("phone").attr("value", "");
	dijit.byId("subject").attr("value", "");
	dijit.byId("cb1").attr("checked", "true");
	dojo.byId("msg").value = "";

	dijit.byId("emailDialog").titleNode.innerHTML = "Send email to " + eAccount;
	dojo.byId("dlgTable").style.visibility = "visible";
	dijit.byId("emailDialog").show();
}

function closeEmailDlg(){
	dijit.byId("emailDialog").hide();
}
