jQuery(document).ready(function(){
	if(jQuery('textarea#comment').html() == ''){
		jQuery('textarea#comment').html('Enter text right here!');
	}
	
	jQuery('textarea#comment').focus(function(){
		if(jQuery('textarea#comment').html() == 'Enter text right here!'){
			jQuery('textarea#comment').html('');
		}
	});
	
	jQuery('textarea#comment').blur(function(){
		if(jQuery('textarea#comment').html() == ''){
			jQuery('textarea#comment').html('Enter text right here!');
		}
	});
	
	jQuery('#offer').css('height',jQuery(document).height());
	jQuery('iframe.twitter-share-button').css('width','98px');
	
	var content_position = jQuery('.single-post').position();
	if(content_position) jQuery('#sharebar').css('top',(content_position.top + 15 )+'px');
	jQuery('#sharebar').css('position','fixed');
	
	var options = { 
        target:        '#msf',
        beforeSubmit:  form_showRequest,
        success:       form_showResponse
    }; 
	
	jQuery('#mogoSubscribeForm').submit(function() { 
        jQuery(this).ajaxSubmit(options); 
        return false; 
    }); 
});

function validateEmail(email) { 
    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,}))$/;
    return re.test(email);
} 

function form_showRequest(){
	if( !validateEmail(jQuery('#msf form input[type="text"]').val()) ){
		alert("Please enter a valid email address!");
		return false;
	}
}

function form_showResponse(responseText, statusText, xhr, $form){
	if(responseText != 0){
		jQuery('#msf').html('<span>Thank you for subscribing.</span>');
	}else{
		jQuery('#msf').html('<span style="color:red">Error while adding your email.</span>');
	}
}

