function checkEmailForm(){
	var name = document.getElementById('contactName').value;
	var email = document.getElementById('contactEmail').value;
	var subject = document.getElementById('contactSubject').value;
	var message = document.getElementById('contactMessage').value;
	
	if(trim_JD(name).length == 0){
		createPopup_JD({
			popupID:	'errorPopup',
			APIdir:		'/_scripts/popup/',
			type:		'alert',
			width:		350,
			title:		'No Name Specified',
			content:	'<p>Please enter your name first!</p>'
		})
		
		openPopup_JD({
			popupID:	'errorPopup',
			posX:		'middle',
			posY:		'top',
			effect:		'fromTop',
			closeEffect:'toTop',
			closeFocus:	'contactName'
		})	
		return;	
	}
	
	if(trim_JD(subject).length == 0){
		createPopup_JD({
			popupID:	'errorPopup',
			APIdir:		'/_scripts/popup/',
			type:		'alert',
			width:		350,
			title:		'No Subject Specified',
			content:	'<p>Please enter a subject for the message.</p>'
		})
		
		openPopup_JD({
			popupID:	'errorPopup',
			posX:		'middle',
			posY:		'top',
			effect:		'fromTop',
			closeEffect:'toTop',
			closeFocus:	'contactSubject'
		})	
		return;	
	}
	
	
	if(trim_JD(message).length == 0){
		createPopup_JD({
			popupID:	'errorPopup',
			APIdir:		'/_scripts/popup/',
			type:		'alert',
			width:		350,
			title:		'No Message!?',
			content:	'<p>Your going to have to enter a message first......</p>'
		})
		
		openPopup_JD({
			popupID:	'errorPopup',
			posX:		'middle',
			posY:		'top',
			effect:		'fromTop',
			closeEffect:'toTop',
			closeFocus:	'contactMessage'
		})	
		return;	
	}
	
	name = name.replace(/[|]/g,'-');
	email = email.replace(/[|]/g,'-');
	subject = subject.replace(/[|]/g,'-');
	message = message.replace(/[|]/g,'-');
		
	createPopup_JD({
			popupID:	'waitPopup',
			APIdir:		'/_scripts/popup/',
			type:		'wait',
			title:		'Proccessing...',
			content:	'<p>Please wait while your email is being sent...</p>'
		})
		
		openPopup_JD({
			popupID:	'waitPopup',
			posX:		'right',
			posY:		'bottom',
			closeBlanket:'false'
		})	
	
	ajaxRequest_JD({
		script:		'/_scripts/sendEmail.php',
		inputName:	'name|email|subject|message',
		inputData:	name+'|'+email+'|'+subject+'|'+message,
		type:		'POST',
		action:		returnResult,
		onError:	returnError
	})		
}

function returnResult(result){
	if(result == 1){
	document.getElementById('contactName').value = "";
	document.getElementById('contactEmail').value = "";
	document.getElementById('contactSubject').value = "";
	document.getElementById('contactMessage').value = "";
	createPopup_JD({
			popupID:	'successPopup',
			APIdir:		'/_scripts/popup/',
			type:		'success',
			width:		350,
			title:		'Email Sent!',
			content:	'<p>Your email has been sent.</p>'
		})
		
		closePopup_JD({popupID:	'waitPopup'})
		
		openPopup_JD({
			popupID:	'successPopup',
			posX:		'middle',
			posY:		'top',
			effect:		'fromTop',
			closeEffect:'toTop',
			openBlanket:'false'
		})	
	}else{
		createPopup_JD({
			popupID:	'errorPopup',
			APIdir:		'/_scripts/popup/',
			type:		'critical',
			width:		350,
			title:		'Unknown Error',
			content:	'<p>An unknown error has occurred. Please find contact details on the contact page of this site if the problem persists.</p>'
		})
		
		closePopup_JD({popupID:	'waitPopup'})
		
		openPopup_JD({
			popupID:	'errorPopup',
			posX:		'middle',
			posY:		'top',
			effect:		'fromTop',
			closeEffect:'toTop',
			openBlanket:'false',
			closeFocus:	'contactMessage'
		})	
	}
}

function returnError(){
	if(trim_JD(message).length == 0){
		createPopup_JD({
			popupID:	'errorPopup',
			APIdir:		'/_scripts/popup/',
			type:		'critical',
			width:		350,
			title:		'Error!',
			content:	'<p>It appears that the connection has timed-out!</p>'
		})
		
		closePopup_JD({popupID:	'waitPopup'})
		
		openPopup_JD({
			popupID:	'errorPopup',
			posX:		'middle',
			posY:		'top',
			effect:		'fromTop',
			closeEffect:'toTop',
			openBlanket:'false',
			closeFocus:	'contactMessage'
		})	
	}	
}
