// emails.js
var global_email = 0;

function focus()
{
	document.feedback.conBody.focus();
}

function imposeMaxLength(Object, MaxLen)
{
	return (Object.value.length <= MaxLen);
}

// sends the email
function sendForm()
{
	// Need to add a test to see if the email is allowed to be sent
	if (document.feedback.conEmail.value && global_email == 1)
	{
		if(document.feedback.conSub.value)
		{
			if(document.feedback.conBody.value)
			{
				emailData = "conEmail=" + document.feedback.conEmail.value + "&conSub=" + document.feedback.conSub.value + "&conBody=" + document.feedback.conBody.value;
				doAjax('include/sendmail.php', emailData, 'sentMail', 'get', '0', 'bodyText', '0');
			}
			else
			{
				alert("Please fill out the body of the email")
			}
		}
		else
		{
			alert("Please enter the subject");
		}
	}
	else
	{
		alert("Please enter a valid email address");
	}
}

function sentMail(item)
{
	document.getElementById('bodyText').innerHTML = item;
}

function checkEmail()
{
	// get email
	var fulladdress = document.feedback.conEmail.value;
	// split into parts
	emailParts = fulladdress.split('@');
	var theuser = emailParts[0];
	var thehost = emailParts[1];
	
	// varify email
	var emailparam = 'theuser=' + theuser + "&thehost=" + thehost + '&allemail=' + fulladdress;
	if(document.feedback.conEmail.value != "")
	{
		doAjax('include/email_validation.php', emailparam, 'validatedEmail', 'get', '0', 'goodEmail', '1');
	}
}


// if email is validated
function validatedEmail(item)
{
	if (item == 1)
	{
		document.getElementById('goodEmail').innerHTML = '<img src="res/tick.gif" alt ="valid" width="12" height="8">';
		global_email = 1;
	}
	else
	{
		document.getElementById('goodEmail').innerHTML = '<img src="res/cross.gif" alt ="invaid" width="12" height="8">';
		global_email = 0;
	}
}