$(document).ready(function(){
	// Redirects
	$('#donate').click(function(){
		window.open('https://secure.yourpatriot.com/ou/turner/donate.aspx');
		return false;
	});

	$('#volunteer').click(function(){
		window.open('https://secure.yourpatriot.com/ou/turner/volunteersignup.aspx');
		return false;
	});

	$('#home').click(function(){
		window.location.href = '/Home.aspx';
		return false;
	});

	$('#about').click(function(){
		window.location.href = '/About_Bob.aspx';
		return false;
	});

	$('#issues').click(function(){
		window.location.href = '/Issues.aspx';
		return false;
	});

	$('#events').click(function(){
		window.location.href = '/Events.aspx';
		return false;
	});

	$('#news').click(function(){
		window.location.href = '/News.aspx';
		return false;
	});

	$('#district').click(function(){
		window.location.href = '/The_9th_District.aspx';
		return false;
	});

	$('#contact').click(function(){
		window.location.href = '/Contact.aspx';
		return false;
	});


	$('#twitter').click(function(){
		window.open('http://twitter.com/Bobturner9th');
		return false;
	});

	$('#facebook').click(function(){
		window.open('http://www.facebook.com/bobturnerforcongress');
		return false;
	});

	$('#youtube').click(function(){
		window.open('http://www.youtube.com/user/BobTurner9th#p/u');
		return false;
	});


	// Newsletter
	$('#signup').click(function()  {
		if (isValidEmailAddress($('#email').val()))  {
			$.post(
				'/Domains/turner/files/newsletterhandler.php',
				'email=' + $('#email').val(),
				function(data)  {
					$('#email').removeClass('error');
					$('#email').addClass('success');
					$('#email').val('Success!');
					setTimeout(function() {
						$('#email').val('Email Address');
						$('#email').removeClass('success');
					}, 3000);
				}
			);
		}
		else  {
			$('#email').addClass('error');
		}
		return false;
	});

	$('#email').focus(function()  {
		if(this.value == this.defaultValue)  {
			this.select();
		}
	});
});

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);
}

if (window.location.pathname == '/Donate.aspx' || window.location.pathname == '/donate.aspx')  {
	window.location.href = 'https://secure.yourpatriot.com/ou/turner/donate.aspx';
}
if (window.location.pathname == '/Volunteer.aspx' || window.location.pathname == '/volunteer.aspx')  {
	window.location.href = 'https://secure.yourpatriot.com/ou/turner/volunteersignup.aspx';
}
