function ajax_object() {
	try {
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
		return ajaxRequest;
	} catch (e) {
		// Internet Explorer Browsers
		try {
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			return ajaxRequest;
		} catch (e) {
			try {
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				return ajaxRequest;
			} catch (e) {
				// Something went wrong
				alert("Your browser broke!");
				return false;
			}
		}
	}
}

function ajaxBlogComment(form) {
	ao = ajax_object();
	if (validateBlogComment(form)) {
		ao.onreadystatechange = function() {
			if (ao.readyState == 4) {
				document.getElementById("blogCommentForm").innerHTML = ao.responseText;
			}
		}
		with (form) {
			ao.open("GET", "/ajax/process_blog_comment.php?comment="
					+ comment.value + "&blog_id=" + blogID.value, true);
			ao.send(null);
		}
	}
}

function validateBlogComment(form) {
	with (form) {
		// alert(comment);
		if (!validate_string(comment)) {
			document.getElementById('blogCommentErrors').innerHTML = ("<p>Please enter a comment!</p>");
			comment.focus();
			return false;
		}
	}
	return true;
}

function validate_string(field) {
	with (field) {
		if (value == "" || value == null) {
			return false;
		} else {
			return true;
		}
	}
}

function alterComment(comment, blog, mode) {
	ao = ajax_object();
	ao.onreadystatechange = function() {
		if (ao.readyState == 4) {
			document.getElementById('blogComments').innerHTML = ao.responseText;
		}
	}
	request = "/ajax/alter_blog_comment.php?blog_id=" + blog
			+ "&blog_comment_id=" + comment + "&mode=" + mode;
	// alert(request);
	ao.open("GET", request, true);
	ao.send(null);
}

function ajaxNewsletter(form) {
	ao = ajax_object();
	with (form) {
		if (validate_email(email)) {
			ao.onreadystatechange = function() {
				if (ao.readyState == 4) {
					document.getElementById("newsletterForm").innerHTML = ao.responseText;
				}
			}
			ao.open("GET", "/ajax/process_newsletter.php?email="
						+ email.value, true);
			ao.send(null);
		} else {
			email.focus();
		}
	}
}
function validate_email(field) {

	str = field.value;
	var at = "@"
	var dot = "."
	var lat = str.indexOf(at)
	var lstr = str.length
	var ldot = str.indexOf(dot)
	if (str.indexOf(at) == -1) {
		return false
	}

	if (str.indexOf(at) == -1 || str.indexOf(at) == 0
			|| str.indexOf(at) == lstr) {
		return false
	}

	if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0
			|| str.indexOf(dot) == lstr) {
		return false
	}

	if (str.indexOf(at, (lat + 1)) != -1) {
		return false
	}

	if (str.substring(lat - 1, lat) == dot
			|| str.substring(lat + 1, lat + 2) == dot) {
		return false
	}

	if (str.indexOf(dot, (lat + 2)) == -1) {
		return false
	}

	if (str.indexOf(" ") != -1) {
		return false
	}
	//alert("Email validation passed!")
	return true
}