//------------------------------------
//	SIGNUP.JS
//	Author: 	Neil Charlton, Engage Interactive
//	Requires:	jquery, colorbox
//------------------------------------

$(function(){

$(document).ready(function(){
	var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ 
	
	$('#enter-comp').click(function(){
		if($('#email').val().match(re))
		{
			$.post('/signup/checkiscomplete/','email='+$('#email').val(),function(result){
				if(result.status=='missing'){
					$.fn.colorbox({ href: "/signup/enternewsletter/" + $('#email').val() + '/colorbox/' + $('#answer').val(), iframe: true, innerWidth:600, innerHeight:600 } );
					$('#email').val('');
					$('#error').remove();
				}
				if(result.status=='complete'){
					$('#signup').fadeOut(function(){
						$(this).empty().append('<h2>Thanks you have been entered into the competition</h2>').fadeIn();
					});					
				}
			},'json');
		}
		else
		{
			$('#error').remove();
			$('#email').before('<span id="error" style="display: block; background: #f00; -moz-border-radius: 5px; padding: 3px; width: 60%; margin: 0 0 10px 0;">Please enter a valid email address</span>');
		}
	});
});
	
});
