// JavaScript Document

function showMe(id) {
	var obj = document.getElementById(id)
	if (obj.style.display == "none") {
		obj.style.display = "block";
	}
}
function hideMe(id) {
	var obj = document.getElementById(id)
	if (obj.style.display == "block") {
		obj.style.display = "none";
	}
}
	
function validate() {
	var fullname = document.sndMKR.fullname.value;
	var email =  document.sndMKR.email.value;
	var spamcheck = document.sndMKR.spamcheck.value;	

	var fullnameRegExp = /^([a-zA-Z\'. -]+)$/;
	var emailRegExp = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})+(\.([A-Za-z]{2}))?$/;

	if (spamcheck != "safe") {
		window.location = "http://www.rainmakersystems.com/thankyou.html";
		return false;
	}

	// Validate Full Name
	if (fullname == "") {
		showMe("req_fullname");
		return false;
	}
	if (fullname != "") {
		hideMe("req_fullname");
		if (!fullname.match(fullnameRegExp) ) {
			showMe("err_fullname");
			return false;
		}
		if (fullname.match(fullnameRegExp) ) {
			hideMe("err_fullname");
		}
	}
	
	// Validate Email Address
	if (email == "") {
		showMe("req_email");
		return false;
	}
	if (email != "") {
		hideMe("req_email");
		if (!email.match(emailRegExp) ) {
			showMe("err_email");
			return false;
		}
		if (email.match(emailRegExp) ) {
			hideMe("err_email");
			return true;
		}
	}
}
