	$(function() {
		
		var email = $("#test_newsletterUserName"),
			allFields = $([]).add(email),
			tips = $("#validateTips");

		function updateTips(t) {
			tips.text(t).effect("highlight",{},1500);
		}

		function checkLength(o,n,min,max) {

			if ( o.val().length > max || o.val().length < min ) {
				o.addClass('ui-state-error');
				updateTips("Length of " + n + " must be between "+min+" and "+max+".");
				return false;
			} else {
				return true;
			}

		}

		function checkRegexp(o,regexp,n) {

			if ( !( regexp.test( o.val() ) ) ) {
				o.addClass('ui-state-error');
				updateTips(n);
				return false;
			} else {
				return true;
			}

		}
		
		$("#dialog").dialog({
			bgiframe: true,
			autoOpen: true,
			width: 450,
			modal: true,
			close: function() {
				allFields.val('').removeClass('ui-state-error');
			}
		});
		
		$('.openPopup').removeAttr('href');
		
		$('#hereLink').click(function() {
			$('input#test_newsletterSubscribeOff').removeAttr('checked');
			$('input#test_newsletterSubscribeOn').val(['1']);
			$('#dialog').dialog('open');
		})
		$('#removeLink').click(function() {
			$('input#test_newsletterSubscribeOn').removeAttr('checked');
			$('input#test_newsletterSubscribeOff').val(['0']);
			$('#dialog').dialog('open');
		})
		.hover(
			function(){ 
				$(this).addClass("ui-state-hover"); 
			},
			function(){ 
				$(this).removeClass("ui-state-hover"); 
			}
		).mousedown(function(){
			$(this).addClass("ui-state-active"); 
		})
		.mouseup(function(){
				$(this).removeClass("ui-state-active");
		});

	});
