﻿$(document).ready(function() {
	var contentHeight = getMaxHeight();

	$('#comm_services_zip_code').css('height', '');

	var sidebarHeight = $('#comm_services_zip_code').height();
	var sidebarPos = $('#comm_services_zip_code').position().top;
	var sidebarBottom = sidebarHeight + sidebarPos;

	if (sidebarBottom < contentHeight) {
		var diff = contentHeight - sidebarBottom;

		$('#comm_services_zip_code').height(sidebarHeight + diff);
		$('#comm_services_zip_code').css('margin-top', '-3px');
	}
});

function getMaxHeight() {
	var contentHeight = getContentHeight();
	var docHeight = getDocumentHeight() - 40;

	if (contentHeight > docHeight) {
		return contentHeight;
	} else {
		return docHeight;
	}
}

function getContentHeight() {
	var c_height = $('#content_pane').height();
	var c_pos = $('#content_pane').position().top;
	var content_height = c_height + c_pos - 40;

	return content_height;
}

function getDocumentHeight() {
	var docHeight = $(document).height();
	var winHeight = $(window).height() - 40;

	if (winHeight > docHeight) {
		return winHeight;
	} else {
		return docHeight;
	}
}