jQuery(document).ready(function() {
	// this is a different format of the same call
	//jQuery('#signup-button').click(function() {
	//	alert('submit form');
	//});
	jQuery('#signup-button').bind('click', function() {
		// Set temaprary variables for the script
		var isError=0;
		// Get the data from the form
		var email=jQuery('#email_signup').val();
		if(email=='') {
			showGenericOverlay('<h3>Error</h3><p>Please enter an email address.</p><br>', false);
			isError=1;
		} else {
			var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
			if(reg.test(email)==false) {
				showGenericOverlay('<h3>Error</h3><p>Please enter a valid email address.</p><br>', false);
				isError=1;
			}
		}
		// Terminate the script if an error is found
		if(isError==1) {
			return false;
		}
		jQuery.ajaxSetup ({
			cache: false
		});

		// Call newsletter web service
		// this is another format for the call
		//'/webservices/user/newsletter.cfc?method=xnews_signup&email=' + email + '&createPgm=' + window.location.href, 
		// also, the return type ('html') is not required
		jQuery.post(
			'/webservices/user/newsletter.cfc',
			{
				method: 'xnews_signup',
				email: email,
				createPgm: window.location.href
			}, 
			function(rtnVal) {
				// Parse JSON
				message = jQuery.parseJSON(rtnVal);
				// If GA is set up and the signup is successful, register the event
				if(typeof _gaq != 'undefined' && message.toLowerCase().indexOf('thank you') >= 0){
					_gaq.push(['_trackEvent', 'General', 'Form', 'eNews Signup']);
				}
				// Call overlay here
				showGenericOverlay(message, false);
			},
			'html'
		);

		return false;

	});

});

function clickclear(thisfield, defaulttext) {
	if (thisfield.value == defaulttext) {
		thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == "") {
		thisfield.value = defaulttext;
	}
}

