// JavaScript Document

 	function calculate_new_total()
 	{
		var total_positive_values = 0;
	 	var total_price = 0;
	 	var status = new Array();
		var details = new Array;
	 
	 	//Count how many of the 1st 4 options are set to type.
	 	if ($('epc_yes').get('checked')) 
	 	{ 
			total_positive_values++; 
			status['epc'] = true; 
			details['epc'] = $('epc_yes').get('src');
		} 
		else 
		{ 
			status['epc'] = false; 
		}
		
	 	if ($('floor_plan_yes').get('checked')) 
		{ 
			total_positive_values++; 
			status['floor_plan'] = true; 
			details['floor_plan'] = $('floor_plan_yes').get('src');
		}
		else
		{
			status['floor_plan'] = false; 
		}
		
	 	if ($('photography_yes').get('checked')) 
		{ 
			total_positive_values++; 
			status['photography'] = true; 
			details['photography'] = $('photography_yes').get('src');
		}
		else
		{
			status['photography'] = false; 
		}
		
	 	if ($('inventory_yes').get('checked')) 
		{ 
			total_positive_values++; 
			status['inventory'] = true; 
			details['inventory'] = $('inventory_yes').get('src');
		}
		else
		{
			status['inventory'] = false; 
		}
	 
	 	//If count is > 1 then we need to use the discount prices
	 	if (total_positive_values > 1)
	 	{
			 var use_discount_price = true;
	 	}
	 	else
	 	{
		 	var use_discount_price = false; 
	 	}
	 
	 	//If inventory true and bedrooms too great then return a message so no point 
		if (status['inventory'] == true && $('bedrooms').get('value') == "larger")
		{
			display_total('message', "Please Call 0800 756 56 53");
			return;
		}
		
		//Add the value for epc if required.
		if (status['epc'] == true)
		{
			var details_parts = details['epc'].split(',');
			
			if (use_discount_price == true)
			{
				var price_parts = details_parts[1].split('=');
				total_price += parseFloat(price_parts[1]);
			}
			else
			{
				var price_parts = details_parts[0].split('=');
				total_price += parseFloat(price_parts[1]);
			}
		}
		
		//Add the value for floor_plan if required.
		if (status['floor_plan'] == true)
		{
			var details_parts = details['floor_plan'].split(',');
			
			if (use_discount_price == true)
			{
				var price_parts = details_parts[1].split('=');
				total_price += parseFloat(price_parts[1]);
			}
			else
			{
				var price_parts = details_parts[0].split('=');
				total_price += parseFloat(price_parts[1]);
			}
		}
		
		//Add the value for photography if required.
		if (status['photography'] == true)
		{
			var details_parts = details['photography'].split(',');
			
			if (use_discount_price == true)
			{
				var price_parts = details_parts[1].split('=');
				total_price += parseFloat(price_parts[1]);
			}
			else
			{
				var price_parts = details_parts[0].split('=');
				total_price += parseFloat(price_parts[1]);
			}
		}
		
		//Add the value for inventory if required.
		if (status['inventory'] == true)
		{
			var price_parts = details['inventory'].split('=');
			total_price += parseFloat(price_parts[1]);
			
			//Add the bedroom values
			var number_of_bedrooms = $('bedrooms').get('value');
			var bedroom_details = $('bedrooms').get('src');
			var bd_array = bedroom_details.split(',');
			var bdroom = bd_array[number_of_bedrooms].split('=')
			total_price += parseFloat(bdroom[1]);
			
			//Add the funished type.
			var furnished_type = $('furnished_type').get('value');
			var furnished_details = $('furnished_type').get('src');
			var furnished_array = furnished_details.split(',');
			
			if (furnished_type == 'unfunished')
			{
				var furnished_part = furnished_array[0].split('=');
				total_price += parseFloat(furnished_part[1]);
			} 
			
			if (furnished_type == 'part_furnished')
			{
				var furnished_part = furnished_array[1].split('=');
				total_price += parseFloat(furnished_part[1]);
			}
			
			if(furnished_type == 'fully_furnished')
			{
				var furnished_part = furnished_array[2].split('=');
				total_price += parseFloat(furnished_part[1]);
			}
			
			//Add the extra area values
			
			var number_of_areas = $('extra_areas').get('value');
			var area_details = $('extra_areas').get('src');
			var area_array = area_details.split(',');
			var exarea = area_array[number_of_areas].split('=')
			total_price += parseFloat(exarea[1]);
			
		}
	 
	 display_total('price', total_price)
 }
 
 
 function display_total(type, value)
 {
	 if(type=="message")
	 {
		 $('update_quote_value').set('html', value); 
	 }
	 else
	 {
		 $('update_quote_value').set('html', 'Total - &#163;' + value + ' + VAT');
	 }
	 
 }
