
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
function getInternetExplorerVersion() {
	var rv = -1; // Return value assumes failure.
	if (navigator.appName == 'Microsoft Internet Explorer') {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
		rv = parseFloat( RegExp.$1 );
	}
	return rv;
}

function isNumber(n) {
  return !isNaN(parseFloat(n)) && isFinite(n);
}

jQuery(document).ready(function($) {

	if($("#farmer").attr("checked") == "checked") {
		$("#farmBusinessNumberSpan .required").css("visibility", "visible");
	}

	$('a[href^="http://"]').attr("target", "_blank");  //make all external links open in a new tab
	$('a[href$="pdf"]').attr("target", "_blank");  //also PDFs
	$(".privacy").attr("target", "_blank");

	$("#homeLogoLink").click(function() {window.location = "./"});
	$("#promo").click(function() {window.location = "calculator.php"});
	
	$("#farmer").click(function() {
		$("#farmBusinessNumberSpan .required").css("visibility", "visible");
	});

	$("#applicantType input[type='radio']").click(function() {
		var id = $("input[@name=type_of_applicant]:checked").attr('id');
		if(id == "farmer") {
			$("#farmBusinessNumberSpan .required").css("visibility", "visible");
		}
		else {
			$("#farmBusinessNumberSpan .required").css("visibility", "hidden");
		}
	});

	var contentHeight = $("#contentTd").height();
	
	var madeInWindsorHeight = $("#madeInWindsor").height();
	
	var ieVersion = getInternetExplorerVersion();
	
	if(ieVersion > -1 && ieVersion < 8) {
		contentHeight -= 36;	//adjust height for IE < 8
	}
	else {
		contentHeight -= 6;
	}
	
	$("#sideBar").css("display", "block");
	
	var newsHeight = $("#news").height();

	newsHeight = contentHeight - madeInWindsorHeight;
	$("#news").height(newsHeight);
	$("#news").css("height", newsHeight + "px");

	$("#sideBarContainer").css("height", contentHeight + "px");
	$("#sideBar").css("height", contentHeight + "px");
	
	if(contentHeight < 480) {
		$("#news").css("display", "none");
		$("#readMore").css("display", "none");
	}

});
