//<![CDATA[
		   
$(document).ready(function(){
	//Adds class to body to confirm JS is enabled (used in CSS)
	$('body').addClass("jsenabled");
	//Clears inital form field values on focus	
	$(".clearonfocus").focus(function() {
		if(this.value == this.defaultValue) {
			this.value = "";
		}
	}).blur(function() {
		if(!this.value.length) {
			this.value = this.defaultValue;
		}
	});
	//Launch links in new window where rel="popup"
	$('a[rel~=external]').click(function(){
		window.open(this.href);
		return false;
	});
	//Launch fancybox when required
	$('a[rel~=modal]').fancybox({
		'transitionIn' : 'fade', 
		'titlePosition' : 'over',
		'showNavArrows' : false
	});
	//Stripe tables
	//$('tr:nth-child(odd)').addClass('odd');
	//Homepage Functions
	if ($('#home').length > 0) {
				
	}

	//-------------------------------------------- Campaign Monitor Form --------------------------------//
/*
	$('#subForm input[type=submit]').live('click', function() {
		alert("Submit");
		return false;
		
		$('.error').remove();
	
		var $name = $('input[name="cm-name"]');
		var $email = $('input[name="cm-phrhrr-phrhrr"]');
		var errors = 0;
		
		if($name.val() == "") {
			$name.after('<span class="error">Please include your name</span>');
			errors++;	
		}
			
		if(!isValidEmailAddress($email.val())) {
			$email.after('<span class="error">Please include a valid email address</span>');
			errors++;	
		}

		if(errors > 0) {
			return false;
		}
		
		$.fancybox.showActivity();

		var dataString = 'cm-name=' + $name.val() + '&cm-phrhrr-phrhrr=' + $email.val() + '&action=' + $(this).attr('action');  
	
	 	$.ajax({  
	   		type: "POST",  
	   		url: "/includes/subscribe.php",  
	   		data: dataString,  
	   		success: function() { 
				$('#subForm fieldset').html('<h3>Thank You</h3><p>We have sent an email to the address you provided. Please click the link in the email to complete the signup process.</p>');
				$.fancybox.hideActivity();
				$.fancybox.resize();
	   		},
			error: function(a, b, c) {
				alert(a + ', ' + b + ', ' + ', ' + c);
				$.fancybox.hideActivity();
				$.fancybox.resize();	
			}
		});
		
		return false;  
	
	});*/
	
});

function sendForm(form) {
	$('.error').remove();
	
	var $name = $('input[name="cm-name"]');
	var $email = $('input[name="cm-phrhrr-phrhrr"]');
	var errors = 0;
		
	if($name.val() == "") {
		$name.after('<span class="error">Please include your name</span>');
		errors++;	
	}
			
	if(!isValidEmailAddress($email.val())) {
		$email.after('<span class="error">Please include a valid email address</span>');
		errors++;	
	}

	if(errors > 0) {
		return false;
	}
		
	$.fancybox.showActivity();

	var dataString = 'cm-name=' + $name.val() + '&cm-phrhrr-phrhrr=' + $email.val() + '&action=' + $('#subForm').attr('action');  
	
 	$.ajax({  
   		type: "POST",  
   		url: "/includes/subscribe.php",  
   		data: dataString,  
   		success: function(data) {
			$('#subForm fieldset').html('<h3>Thank You</h3><p>We have sent an email to the address you provided. Please click the link in the email to complete the signup process.</p>');
			$.fancybox.hideActivity();
			$.fancybox.resize();
   		},
		error: function(a, b, c) {
			alert(a + ', ' + b + ', ' + ', ' + c);
			$.fancybox.hideActivity();
			$.fancybox.resize();	
		}
	});
		
	return false;  	
}

function isValidEmailAddress(emailAddress) { 
var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i); 
return pattern.test(emailAddress); 
}

//]]>
