// AJAX Form Script
(function($){
    $(document).ready(function(){
        $('#signup_form').submit(function(e){
			e.preventDefault();
	        if ($('#newsletter-email').val() != "" && $('#newsletter-email').val() != "Enter Email Address" ) {
	            var action = $('#signup_form').attr('action');
				var parameters = $('#signup_form').serialize();
				$.ajax({
					url: action,
					type: 'post',
	                dataType: 'json',
					data: parameters,
						complete: function(response){
	                        var responseJSON = $.parseJSON(response.responseText);
	                        if(responseJSON.success){
                                if(typeof(pageTracker) != 'undefined'){
                                    pageTracker._trackPageview('/stay-up-to-date-goal');
                                }
                                if(typeof(_gaq) != 'undefined'){
                                    _gaq.push(['_trackPageview', '/stay-up-to-date-goal']);
                                }
								$('#signup_form').fadeOut('slow',function(){
									$('#thank-you').fadeIn('slow', function(){
										setTimeout ( "$('#thank-you').fadeOut(function(){ $('#signup_form').fadeIn();$('#signup_form input[name=email]').attr('value','Enter Email Address'); });", 10000 );
									});
								});
	        				}else{
								
	                        }
						}
				});	    			
	        }
			return false;
        });
	
        $('#blogNewsletter form').submit(function(e){
			e.preventDefault();
	        if ($('#blogNewsletter form input[type=text]').attr('value') != '') {
	            var action = $('#blogNewsletter form').attr('action');
				var parameters = $('#blogNewsletter form').serialize();
				$.ajax({
					url: action,
					type: 'post',
	                dataType: 'json',
					data: parameters,
						complete: function(response){
	                        var responseJSON = $.parseJSON(response.responseText);
	                        if(responseJSON.success){
								if(typeof(pageTracker) != 'undefined'){
    								pageTracker._trackPageview('/stay-up-to-date-goal');
								}
								if(typeof(_gaq) != 'undefined'){
								    _gaq.push(['_trackPageview', '/stay-up-to-date-goal']);
								}
								$('#blogNewsletter form').fadeOut('slow',function(){
									$('#thank-you-newsletter').fadeIn('slow', function(){
										setTimeout ( "$('#thank-you-newsletter').fadeOut(function(){ $('#blogNewsletter form').fadeIn();$('#blogNewsletter form input[name=newsletter]').attr('value','Enter Email'); });", 10000 );
									});
								});
	        				}else{
								
	                        }
						}
				});	    			
	        }
			return false;
        });
    
    	
    	$('#signup_form input[name=email]').focus(function(){
    		if(this.value == 'Enter Email Address'){
    			$('#signup_form input[name=email]').addClass('active');
    			this.value = '';
    		}
    	});
    		
    	$('#signup_form input[name=email]').blur(function(){
    		$(this).removeClass('active');
    		if(this.value == ''){
    			this.value = 'Enter Email Address';
    		}
    	});
    			
    	$('#blogNewsletter input[name=newsletter]').focus(function(){
    		if(this.value == 'Enter Email'){
    			$('#signup_form input[name=email]').addClass('active');
    			this.value = '';
    		}
    	});
    		
    	$('#blogNewsletter input[name=newsletter]').blur(function(){
    		$(this).removeClass('active');
    		if(this.value == ''){
    			this.value = 'Enter Email';
    		}
    	});
    			
    	$('#blogSearch input[name=s]').focus(function(){
    		if(this.value == 'Search'){
    			this.value = '';
    		}
    	});
    		
    	$('#blogSearch input[name=s]').blur(function(){
    		$(this).removeClass('active');
    		if(this.value == ''){
    			this.value = 'Search';
    		}
    	});
    });
})(jQuery);

