var textbuffer = '';
var textbuffer2 = '';
function checkEmail(emailAddress) {

	var foundAtSymbol = 0;
	var foundDot = 0;
	var md;

	// Go through each character in the email address.
	for (var x=0; x<emailAddress.length - 1; x++) {
		md = emailAddress.substr(x, 1);
	
		// Is the character an @ symbol?
		if (md == '@') foundAtSymbol++;
	
		// Count how many dots there are after the @ symbol.
		if (md == '.' && foundAtSymbol == 1) foundDot++;
	}

	// Is there only one @ symbol, and are there more than one dots?
	if (foundDot > 0 && foundAtSymbol == 1) {
		return true;
	} else {
		return false;
	}
}
function checkSearchForm() {
	if(document.getElementById('s').value == '') {
		alert('\nError: Required Field Empty.\n\nPlease enter one or more words to search for.\n\n');
		document.getElementById('s').focus();
		return false;
	}
}
function checkRegisterForm() {
	if(document.getElementById('e').value == '') {
		alert('\nError: Required Field Empty.\n\nPlease enter your email address.\n\n');
		document.getElementById('e').focus();
		return false;
	}
	if(!checkEmail(document.getElementById('e').value)) {
		alert('\nError: Invalid Email Address.\n\nPlease enter a valid email address.\n\n');
		document.getElementById('e').select();
		return false;
	}
}
function getNews(obj) {
	$.ajax({
		url: obj.href,
		cache: false,
		dataType: "html",
		scriptCharset: "iso-8859-1",
		success: function(text){
			textbuffer = text;
			$('.newsandhappeningsinner').fadeOut('fast',function() {
					document.getElementById('newsajaxcontainer').innerHTML = textbuffer;
					$('.newsandhappeningsinner').fadeIn('fast');	
			});
	 	},
		error: function(text) {
			alert('An unexpected error has occurred while fetching news items');
		}
	});
}
function getWIP(obj) {
	$.ajax({
		url: obj.href,
		cache: false,
		success: function(text){
			textbuffer2 = text;
			$('.summary').fadeOut('fast',function() {
					document.getElementById('homeajaxcontainer').innerHTML = textbuffer2;
					$('.summary').fadeIn('fast');	
			});
	 	},
		error: function(text) {
			alert('An unexpected error has occurred while fetching blog items');
		}
	});
}
function getNews_old(obj) {
	$.ajax({
		url: obj.href,
		cache: false,
		success: function(text){
			document.getElementById("newsajaxcontainer").innerHTML = text;
	 	},
		error: function(text) {
			alert('An unexpected error has occurred while fetching news items');
		}
	});
}
function getWIP_old(obj) {
	$.ajax({
		url: obj.href,
		cache: false,
		success: function(text){
			document.getElementById("homeajaxcontainer").innerHTML = text;
	 	},
		error: function(text) {
			alert('An unexpected error has occurred while fetching blog items');
		}
	});
}
