/* Soak Site JavaScript */

window.addEvent('domready', function() {
	
	if ($('subscribeForm')) { 
		
		checkSubscribeForm = function() {
			
			var original = $('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 ($('name').value ==""){
				alert("Please provide your name.");
				$('name').focus();
				return false;
			}
			
			if ($('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(' ');
				$('name').value = retval;
			}

		
			if ($('emailAddress').value ==""){
				alert("Please enter your email address.");
				$('emailAddress').focus();
				return false;
			}
		
			if ($('emailAddress').value !=""){
				var x = $('emailAddress').value;
				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.");
						$('emailAddress').focus();
						return false;
					}
			}
		
			if ($('postalCode').value ==""){
				alert("Please provide your Postal Code.");
				$('postalCode').focus();
				return false;
			}
			
			if ($('postalCode').value !=""){
				var myPC = $('postalCode').value;
				var filter  = /^[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1} *\d{1}[A-Z]{1}\d{1}$/;
					if (!filter.test(myPC)) {
						alert("Oops, looks like your postal code is not formatted correctly. A1B 2C3 or A1B2C3");
						$('postalCode').focus();
						return false;
					}
			}
			
			if ($('permissionCheck').checked !== true){
				alert("You must agree to receive our newsletter to be eligible for the draw.");
				return false;
			}
			
			return (true);
			
		} //end checkForm function
		
	} //end if subscribeForm
	
	
	
	
	
	if ($('contractorSubscribeForm')) { 
		
		checkContractorSubscribeForm = function() {
			
			if ($('companyName').value ==""){
				alert("Please provide the company name.");
				$('companyName').focus();
				return false;
			}
			
			var original = $('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 ($('name').value ==""){
				alert("Please provide the name of the contact at the company.");
				$('name').focus();
				return false;
			}
			
			if ($('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(' ');
				$('name').value = retval;
			}

		
			if ($('emailAddress').value ==""){
				alert("Please enter the contact's email address.");
				$('emailAddress').focus();
				return false;
			}
		
			if ($('emailAddress').value !=""){
				var x = $('emailAddress').value;
				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.");
						$('emailAddress').focus();
						return false;
					}
			}
					
			return (true);
			
		} //end checkForm function
		
	} //end if contractorSubscribeForm
	
	

// Close DomReady function
});








