// JavaScript Document
function calculate () {
	
	var rooms = $('#rooms').val();
	var bills = $('#bills').val();
	var exclusive = $("input[name='#exclusive']:checked").val();
	var hours =  $('#hours').val();
	var weeks = $('#weeks_req').val();
	var r = 0;
	var r2 = 0;
	var opinion_msg = "";
	var msg = "<p><span class='ui-icon ui-icon-alert' style='float: left; margin-right: .3em;'></span>Please check the following errors:-<ul>";
	//var msg = "Please check the following errors:-\n\n";
	var res = true;
	
	if(rooms.length == 0 || rooms.length == null)
	{
		msg += "<li>Please provide the number of rooms in your home.</li>";
		//msg += "-Please provide the number of rooms in your home.\n\n";
		res = false;
	}
	if(hours.length == 0 || hours.length == null)
	{
		msg += "<li>Please provide the hours worked from home.</li>";
		//msg += "-Please provide the hours worked from home.\n\n";
		res = false;
	}
	
	if(bills.length == 0 || bills.length == null)
	{
		msg += "<li>Please provide a summary of your annual bills.</li>";
		
		//msg += "-Please provide a summary of your annual bills.\n\n";
		res = false;
	}
	if(exclusive == "")
	{
		msg += "<li>Please tell us whether you have your own office room.</li>";
		//msg += "-Please tell us whether you have your own office room.\n\n";
		res = false;
	}
	
	msg += "</ul></p>";
	if(res == false)
	{
		$('#dialog').html(msg);
		$('#dialog').dialog('open');
		return false;
	}	
	
	
	if (exclusive == 1){	
		r = (bills/rooms);
	}
	else{ 
		r = bills * hours / 168 / rooms;
	}

	r2 = weeks * 3;
	
	//display which result is highest
	if(r > r2){
		opinion_msg = "A claim for actual expenses is more beneficial but you must ensure you retain all recepits for the fuel bills.";
	}
	else if(r < r2){
		opinion_msg = "A claim for &pound;3 per week is more beneficial in this instance.";
	}
	
	$('#act_expenses').html(round(r));
	$('#3pwk').html(round(r2));
	$('#opinion').html(opinion_msg);
	$('#result_area').show('slow');		
	

}
// round to 2 decimal places
function round(x) {
	return Math.round((x*100)/100);
}	