$(document).ready(
	function(){
	
		var rsmod = 495;
		var ssmod = 595;
		var npmod = 350;
		var pdmod = 180;
		var ecmod = 845;
		var lunchmod = 40;
	
		//set fields to uneditable and align units to center
		$('#units-ec').attr("readonly", "true");
		$('#units-ec').css("text-align", "center");
		$('#units-rs').attr("readonly", "true");
		$('#units-rs').css("text-align", "center");
		$('#units-ss').attr("readonly", "true");
		$('#units-ss').css("text-align", "center");
		$('#units-np').attr("readonly", "true");
		$('#units-np').css("text-align", "center");
		$('#units-pd').attr("readonly", "true");
		$('#units-pd').css("text-align", "center");
		$('#units-lunch').attr("readonly", "true");
		$('#units-lunch').css("text-align", "center");
		$('#units-cost').attr("readonly", "true");
		$('#units-cost').css("text-align", "center");
		
		function total(){
			//calculate total cost of all units
			
			var rsCost = 0;
			var ssCost = 0;
			var npCost = 0;
			var pdCost = 0;
			var ecCost = 0;
			var lunchCost = 0;
			
			if(!(isNaN($('#units-rs').val())) && $('#units-rs').val()>0)
				rsCost = parseInt($('#units-rs').val());
				
			if(!(isNaN($('#units-ss').val())) && $('#units-ss').val()>0)
				ssCost = parseInt($('#units-ss').val());
			
			if(!(isNaN($('#units-np').val())) && $('#units-np').val()>0)
				npCost = parseInt($('#units-np').val());

			if(!(isNaN($('#units-pd').val())) && $('#units-pd').val()>0)
				pdCost = parseInt($('#units-pd').val());
			
			if(!(isNaN($('#units-lunch').val())) && $('#units-lunch').val()>0)
				lunchCost = parseInt($('#units-lunch').val());
				
			if(!(isNaN($('#units-ec').val())) && $('#units-ec').val()>0)
				lunchCost = parseInt($('#units-ec').val());
			
			var totalCost = rsCost + ssCost + npCost + pdCost + lunchCost + ecCost; 
			
			$("#units-cost").val(totalCost);
		}
	
		//RAWSPACE
		$('#rawspace').click(
			function(){
				if($('#rawspace input').attr('checked')) {
					if(!($('#total-rs').val().length > 0)) {
							//set total-rs value to 1 if 
							//rawspace is clicked and total-rs 
							//has no value yet
							$('#total-rs').val("1");
							$('#total-rs').change();
					}
				}else{
					$('#total-rs').val("");
					$('#units-rs').val("");
					total();
				}
			}
		);
		
		$('#total-rs').change(
			function(){
				//if total-rs value changed
				//multiply total-rs value to rsmod
				//and apply to units-rs
				if(!(isNaN($('#total-rs').val()))) {
					$('#units-rs').val(parseInt($('#total-rs').val()) * rsmod);
					total();
				}else{
					$('#total-rs').val("");
					$('#units-rs').val("");
					total();
				}
			}
		);
		
		//SHELL SCHEME PACKAGE
		$('#sspack').click(
			function(){
				if($('#sspack input').attr('checked')) {
					if(!($('#total-ss').val().length > 0)) {
							//set total-ss value to 1 if 
							//rawspace is clicked and total-ss 
							//has no value yet
							$('#total-ss').val("1");
							$('#total-ss').change();
					}
				}else{
					$('#total-ss').val("");
					$('#units-ss').val("");
					total();
				}
			}
		);
		
		$('#total-ss').change(
			function(){
				//if total-ss value changed
				//multiply total-ss value to rsmod
				//and apply to units-ss
				if(!(isNaN($('#total-ss').val()))) {
					$('#units-ss').val(parseInt($('#total-ss').val()) * ssmod);
					total();
				}else{
					$('#total-ss').val("");
					$('#units-ss').val("");
					total();
				}
			}
		);
		
		//SPECIAL NETWORKING PASS
		$('#snpass').click(
			function(){
				if($('#snpass input').attr('checked')) {
					if(!($('#total-np').val().length > 0)) {
							//set total-np value to 1 if 
							//rawspace is clicked and total-np
							//has no value yet
							$('#total-np').val("1");
							$('#total-np').change();
					}
				}else{
					$('#total-np').val("");
					$('#units-np').val("");
					total();
				}
			}
		);
		
		$('#total-np').change(
			function(){
				//if total-np value changed
				//multiply total-np value to rsmod
				//and apply to units-np
				if(!(isNaN($('#total-np').val()))) {
					$('#units-np').val(parseInt($('#total-np').val()) * npmod);
					total();
				}else{
					$('#total-np').val("");
					$('#units-np').val("");
					total();
				}
			}
		);
		
		//BANNER PLACEMENT
		$('#obplace').click(
			function(){
				if($('#obplace input').attr('checked')) {
					if(!($('#total-pd').val().length > 0)) {
							//set total-pd value to 1 if 
							//rawspace is clicked and total-pd 
							//has no value yet
							$('#total-pd').val("1");
							$('#total-pd').change();
					}
				}else{
					$('#total-pd').val("");
					$('#units-pd').val("");
					total();
				}
			}
		);
		
		$('#total-pd').change(
			function(){
				//if total-pd value changed
				//multiply total-pd value to rsmod
				//and apply to units-pd
				if(!(isNaN($('#total-pd').val()))) {
					$('#units-pd').val(parseInt($('#total-pd').val()) * pdmod);
					total();
				}else{
					$('#total-pd').val("");
					$('#units-pd').val("");
					total();
				}
			}
		);
		
		//LUNCH ONLY
		$('#lunchonly').click(
			function(){
				if($('#lunchonly input').attr('checked')) {
					if(!($('#total-lunch').val().length > 0)) {
							//set total-lunch value to 1 if 
							//rawspace is clicked and total-lunch 
							//has no value yet
							$('#total-lunch').val("1");
							$('#total-lunch').change();
					}
				}else{
					$('#total-lunch').val("");
					$('#units-lunch').val("");
					total();
				}
			}
		);
		
		$('#total-lunch').change(
			function(){
				//if total-lunch value changed
				//multiply total-lunch value to rsmod
				//and apply to units-lunch
				if(!(isNaN($('#total-lunch').val()))) {
					$('#units-lunch').val(parseInt($('#total-lunch').val()) * lunchmod);
					total();
				}else{
					$('#total-lunch').val("");
					$('#units-lunch').val("");
					total();
				}
			}
		);
		
		//EXHIBIT CLINIC
		$('#exhibitclinic').click(
			function(){
				if($('#exhibitclinic input').attr('checked')) {
					if(!($('#total-ec').val().length > 0)) {
							//set total-lunch value to 1 if 
							//rawspace is clicked and total-lunch 
							//has no value yet
							$('#total-ec').val("1");
							$('#total-ec').change();
					}
				}else{
					$('#total-ec').val("");
					$('#units-ec').val("");
					total();
				}
			}
		);
		
		$('#total-ec').change(
			function(){
				//if total-lunch value changed
				//multiply total-lunch value to rsmod
				//and apply to units-lunch
				if(!(isNaN($('#total-ec').val()))) {
					$('#units-ec').val(parseInt($('#total-ec').val()) * ecmod);
					total();
				}else{
					$('#total-ec').val("");
					$('#units-ec').val("");
					total();
				}
			}
		);
	}
);
