function showEmail() {
	var emailBox = document.getElementById('emailBox');
	document.getElementById('emailProcessBox').innerHTML = "<p><img src='/images/114/yellow-onblue/emailLoader.gif' /> Sending email... Please wait.</p>";
	document.getElementById('emailProcessBox').style.display = "none";
	
	if ( emailBox.style.display == "block" ) {
		emailBox.style.display = "none";
	} else {
		emailBox.style.display = "block";
	}
	
	document.getElementById('message').value = "Type your message here, the link will be automatically included.";
}

function clearMessage( dom ) {
	if ( dom.value == "Type your message here, the link will be automatically included." ) {
		dom.value = "";
	}
}

function validateEmailToSend() {
	var emailForm = document.getElementById("emailThisPageForm");
	var recipients = emailForm.recipients.value;
	var recArray = recipients.split(',');
	if ( emailForm.elements['host'].value.length <= 0 ) { alert("Please enter your name."); return false; }
	for ( ctr=0;ctr<recArray.length;ctr++ ) {
		var emailExp = new RegExp(".@.","g");
		if ( !emailExp.test(recArray[ctr]) ) {
			alert("Please type-in only valid email address in your recipients.");
			return false;
		}
	}
	
	sendEmail(document.location);
	return true;
}

function sendEmail(url) {
	// swap emailBox
	document.getElementById('emailProcessBox').style.display = "block";
	document.getElementById('emailBox').style.display = "none";
	
	// start ajax call to send the email
	var emailReqObj = getRequest();
	var emailForm = document.getElementById("emailThisPageForm");
	emailReqObj.onreadystatechange=function() {
		if(emailReqObj.readyState==4) {
			if ( emailReqObj.responseText.indexOf('sending failed') ) {
				document.getElementById('emailProcessBox').innerHTML = "<p class='infoFailed'>Sorry but your email has not been sent.</p>";
			} else {
				document.getElementById('emailProcessBox').innerHTML = "<p class='infoSuccess'>Your email has been sent.</p>";
			}
		}
	}
	var sender = emailForm.host.value.split(' ').join('');
	var recipients = emailForm.recipients.value;
	var message = emailForm.message.value;
	
	emailReqObj.open("GET",url + "&useajax=yes&recipients=" + recipients + "&message=" + message + "&host=" + sender,true);
	emailReqObj.send(null);
}