/* Site specific JS */


$(document).ready(function()
{	
	
	// Open external links in a new window
	$("a[href^='http:']").not("[href*='jentlehands.ca']").attr('target','_blank');
	
	
	// Check the newsletter subscribe form
	checkForm = function() 
	{
		var original = $('#name').val();
		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 ($('#name').val() ==""){
			alert("Please provide your name.");
			$('#name').focus();
			return false;
		}
		
		if ($('#name').val() !==""){
			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(' ');
			$('#name').val(retval);
		}
	
		if ($('#email').val() ==""){
			alert("Please enter your email address.");
			$('#email').focus();
			return false;
		}
	
		if ($('#email').val() !=""){
			var x = $('#email').val();
			var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
				if (!filter.test(x)) {
					alert("Oops, looks like there's a problem with your email address.");
					$('#email').focus();
					return false;
				}
		}
			
		if ($('#permission').is(':checked')){
			// It's good
		}else{
			alert("Please agree to receiving our newsletter to be eligible for the draw.");
			return false;
		}
		
		return (true);
	} // End checkSubscribeForm

		
}); // End document.ready



