// General JS functions

$(function () {
	
	$('#email-signup').find('a')
		.click(function () {
			return popup_window($(this).attr('href'), $(this).html(), 600, 250);
		});
	
	$('#email-signup').find('input')
		.focus(function () { focus_field(this, 'Email Address') })
		.blur(function () { blur_field(this, 'Email Address') });
		
		
	$('#email-signup').find('form')
		.submit(function () {
			var form = this;			
			$.ajax({
				url     : '/emailSignUp/ajax',
				type    : 'POST',
				data    : { email : $(this).find('input[name="email"]').val() },
				success : function (msg) {
					$(form).find('span').html(msg);					
				}
			});
		return false;			
		});
	
});


function popup_window (href, title, width, height) {
	var new_win = window.open(href, title, 'width='+width+',height='+height+',status=false,location=false,toolbar=false,menubar=false');
	return false;
}

function focus_field (field, defaultValue) {
	if (field.value === defaultValue) field.value = "";
}

function blur_field (field, defaultValue) {
	if (field.value === "") field.value = defaultValue;
}
