String.prototype.format = function() {
  var args = arguments;
  return this.replace(/{(\d+)}/g, function(match, number) { 
    return typeof args[number] != 'undefined'
      ? args[number]
      : match
    ;
  });
};

$(document).ready(function() {
	if (window.location.hash == '#email') {
		var e = $('#email');
		if (!e.is(':visible'))
			e.prepend('<hr>').show();
	} 
	var a = $('a[href*="/_email/"]').click(function() {
		var e = $('#email');
		if (!e.is(':visible'))
			e.prepend('<hr>').show();
	}).each(function() {
		this.href = '#email';
	});
	$('#email form').submit(function(e) {
		if (this.beenSubmitted) return false;
		e.preventDefault();
		var self = this;
		var data = $(this).serializeArray();
		data.push({name:'page', value: window.location.pathname});
		//console.log(data);
		$.post(window.location.origin+'/', data)
		.success(function(ret, status, jq) {
			$('.ok').show();
		})
		.error(function(ret, status, jq) {
			$('.error').show();
			$('input, textarea', self).prop('disabled', false);
			self.beenSubmitted = false;
		});
		this.beenSubmitted = true;
		$('input, textarea', this).prop('disabled', true);
		return false;
	});
});




