$( function () {
	$("#calculate").click(function(){
		
		$(".jq_info").remove();
		
		var isOK = true;
		
		var width = $("input#width").val();
		if (width == '') {
			$("#width_lbl").before('<img src="/wp-content/themes/membranes/images/ui/error.gif" alt="error!" class="jq_info" />');
			isOK = false;
		};
		
		var length = $("input#length").val();
		if (length == '') {
			$("#length_lbl").before('<img src="/wp-content/themes/membranes/images/ui/error.gif" alt="error!" class="jq_info" />');
			isOK = false;
		};
		
		var depth = $("input#depth").val();
		if (depth == '') {
			$("#depth_lbl").before('<img src="/wp-content/themes/membranes/images/ui/error.gif" alt="error!" class="jq_info" />');
			isOK = false;
		};
		
		var edge = $("input#edge").val();
		if (edge == '') {
			edge = '0';
			$("input#edge").val('0');
		};
		
		var mlen = (parseInt(length) + (2*parseInt(edge)) + (2 * parseInt(depth))) / 100;
		var mwid = (parseInt(width) + (2*parseInt(edge)) + (2 * parseInt(depth))) / 100;
		
		if (isOK) {
			$("#calculator_sidebar").append('<p class="message jq_info">You will require a ' + mlen + ' metre x ' + mwid + ' metre Beutyliner to suit your pond.  <a href="http://www.membranes.com.au/about-us/contact/">Enquire about this liner</a></p> ');
		} else {
			$("#calculator_sidebar").append('<p class="error jq_info">You have not supplied enough information to calculate a liner size.</p>')
		};
		return false;
	});
});
