// JavaScript Document

function checkForm(){

	var myX = document.subscribeForm.email.value;
	var filter  = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;
	var hotmailFilter = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@hotmail.com$/; 
	var original = document.subscribeForm.name.value;
	var o_split = original.split(" ");
	//this probably isn't a complete list of words that shouldn't be capitalized
	var special_words = new Array('and', 'the', 'to', 'for', 'is', 'in', 'a', 'at', 'an', 'from', 'by', 'if', 'of');

	if (document.subscribeForm.name.value ===""){
		alert("Please provide your name.");
		document.subscribeForm.name.focus();
		return false;
	}

	if (document.subscribeForm.name.value !==""){
		for (i=0;i<o_split.length;i++) {
			if (i == 0) {
				//always capitalize the first word
				o_split[i] = (o_split[i].substring(0,1)).toUpperCase() + o_split[i].substring(1);
			}
			else if(special_words.indexOf(o_split[i]) < 0) { 
			  	o_split[i] = (o_split[i].substring(0,1)).toUpperCase() + o_split[i].substring(1);
			}
		}
		retval = o_split.join(' ');
		document.subscribeForm.name.value = retval;
	}

	if (document.subscribeForm.email.value === ""){
		alert("Please enter your email address.");
		document.subscribeForm.email.focus();
		return false;
	}

	if (document.subscribeForm.email.value !==""){
		if (hotmailFilter.test(myX)) {
		alert("We're sorry, Hotmail addresses are not accepted. Please enter another email address.");
		document.subscribeForm.email.focus();
		return false;
		}
	}

	if (document.subscribeForm.email.value !==""){
		if (!filter.test(myX)) {
		alert("Oops, looks like there's a problem with your email address.");
		document.subscribeForm.email.focus();
		return false;
		}
	}
	
	if (document.subscribeForm.permission.checked !== true){
		alert("You must agree to receiving our newsletter to enter the draw.");
		return false;
	}
	return (true);
	
}