$(function(){
	// add jquery date picker to all date fields, using min/max dates if present
	if (!Modernizr.inputtypes.date)
	{
		$("input[type='date']").datepicker({dateFormat: 'yy-mm-dd', numberOfMonths: 3 });
		
		$("input[type='date']").each(function(index){
			if($(this).attr('min'))
			{
				var minDateText = $(this).attr('min');
				$(this).datepicker('option', 'minDate', new Date(minDateText.substring(0, 4), minDateText.substring(4, 6) - 1, minDateText.substring(6, 8)));
			}
			
			if($(this).attr('max'))
			{
				var maxDateText = $(this).attr('max');
				$(this).datepicker('option', 'maxDate', new Date(maxDateText.substring(0, 4), maxDateText.substring(4, 6) - 1, maxDateText.substring(6, 8)));
			}					  
			});
	}
	
	// log to console
	jQuery.fn.log = function (msg) {
	  console.log("%s: %o", msg, this);
	  return this;
	};
	
	// disable submit button when form is submitted
	jQuery.fn.preventDoubleSubmit = function () {
		var alreadySubmitted = false;
		return jQuery(this).submit(function () {
		if (alreadySubmitted)
		return false;
		else
		alreadySubmitted = true;
		});
	};
	
	jQuery('form').preventDoubleSubmit();
	
	$('.requireConfirmation').click(function(){
	  var answer = confirm('Are you sure?');
	  return answer // answer is a boolean
	});  
	
	// open external links in new window, excluding absolute links to own site
	$("#content a[href^=http]").each(
    function(){
      if(this.href.indexOf(location.hostname) == -1) {
        $(this).attr('target', '_blank').addClass('externalLink');
      }
    }
  );
  
});

