$(function(){
    // newsletter
    $('#iruihh-iruihh').clearingInput();
    $("#newsletter").validate({
        errorPlacement: function(error, element) { 
            if ( element.is("#iruihh-iruihh") ) {
                error.appendTo( element.parent().next().parent() ); 
            }
        }        
    });        
    
    // got questions?
    $('#email').clearingInput();
    $('#question').clearingInput();
    $("#questions").validate({
        errorPlacement: function(error, element) { 
            if ( element.is("#email") ) {
                error.appendTo( element.parent() ); 
            }
            if ( element.is("#question") ) {
                error.appendTo( element.parent() ); 
            }
        }        
    });
    
    // set the location of the redirect to the current page
    $("input[name='redirect']").attr('value', window.location+'?q=1');
    
    // show nice thank you message if questions for submitted
    if ($(document).getUrlParam("q")) {
		$.gritter.add({
			// (string | mandatory) the heading of the notification
			title: 'Thank you for your questions',
			// (string | mandatory) the text inside the notification
			text: "Don't forget to signup for Swipe It Reader availability notification.",
			// (string | optional) the image to display on the left
            // image: 'http://a0.twimg.com/profile_images/59268975/jquery_avatar_bigger.png',
			// (bool | optional) if you want it to fade out on its own or just sit there
			sticky: false, 
			// (int | optional) the time you want it to be alive for before fading out
			time: ''
		});
        // $().message("Thank you for your questions.<br />Don't forget to signup for our newsletter.");        
    }    
    // show nice thank you message if newsletter for submitted
    else if ($(document).getUrlParam("n")) {
		$.gritter.add({
			// (string | mandatory) the heading of the notification
			title: 'Thank you',
			// (string | mandatory) the text inside the notification
			text: "You have just been sent an email to confirm your email address.<br /><br />Please click on the link in this email to confirm your subscription.",
			// (string | optional) the image to display on the left
            // image: 'http://a0.twimg.com/profile_images/59268975/jquery_avatar_bigger.png',
			// (bool | optional) if you want it to fade out on its own or just sit there
			sticky: false, 
			// (int | optional) the time you want it to be alive for before fading out
			time: ''
		});
        // $().message("<b>Thank you</b><br />You have just been sent an email to confirm your email address.<br />Please click on the link in this email to confirm your subscription.");        
    }    
    // show nice thank you message if newsletter confirmed
    else if ($(document).getUrlParam("c")) {
		$.gritter.add({
			// (string | mandatory) the heading of the notification
			title: 'Thank you',
			// (string | mandatory) the text inside the notification
			text: "Your subscription has been confirmed.<br />You will hear from us soon.",
			// (string | optional) the image to display on the left
            // image: 'http://a0.twimg.com/profile_images/59268975/jquery_avatar_bigger.png',
			// (bool | optional) if you want it to fade out on its own or just sit there
			sticky: false, 
			// (int | optional) the time you want it to be alive for before fading out
			time: ''
		});
        // $().message("<b>Thank you</b><br />Your subscription has been confirmed and you have been added to our list.<br />You will hear from us soon.");        
    }    
    
});

