
	function field_limiter(identifier,limit)
	{
		if ($(identifier).value > Number(limit))
			$(identifier).value = Number(limit);
	}

	function saveOrderName()
	{
		var query_url	= '/scripts/ajax/order_name.scr.php';
		new Ajax.Request(query_url, {method: 'post', parameters: $('stage_1').serialize()});
	}

	function selectOrder(sForm)
	{
		var query_url = '/scripts/ajax/order_selection.scr.php?form=' + sForm;
		new Ajax.Request(query_url, {method: 'get'});
	}


	// de-cluter the order screen of fields that are not necessary
	function filter_order_fields(order_type)
	{
		var color_fields 	= ["container_formulation_total","container_packaging_total","container_packaging_type","container_order_qty"];
		var plaque_fields = ["number_of_plaques","total_plaque_cost"];

		if (order_type == 'color')
		{
			for (n = 0; n < plaque_fields.length; n++)
			{
				$(plaque_fields[n]).style.display = "none";
			}

			for (n = 0; n < color_fields.length; n++)
			{
				$(color_fields[n]).style.display = "block";
			}

			generate_order_totals('3');
		}
		else if (order_type == 'plaque')
		{
			for (n = 0; n < color_fields.length; n++)
			{
				$(color_fields[n]).style.display = "none";
			}

			for (n = 0; n < plaque_fields.length; n++)
			{
				$(plaque_fields[n]).style.display = "block";
			}

			set_order_cost();
		}
		else
		{
			for (n = 0; n < color_fields.length; n++)
			{
				$(color_fields[n]).style.display = "block";
			}

			for (n = 0; n < plaque_fields.length; n++)
			{
				$(plaque_fields[n]).style.display = "block";
			}

			generate_order_totals('3');
		}

		$('total_order_cost').style.display 	= "block";

	}


	function set_order_cost()
	{
		$('order_cost_3').innerHTML = $('plaque_cost').innerHTML;
	}


	// pass type in here
	function generate_order_totals(form_type)
	{
		var query_url = '/scripts/ajax/order_update.scr.php?form=' + form_type;

		var form_names = [];
		form_names[1] = 'matchoption';
		form_names[2] = 'priceoption';
		form_names[3] = 'customer_costing';

		var active_form = form_names[form_type];

		var add_plaque = 0;

		if (form_type == 3 && $('sample_type').value == 'both')
			var add_plaque = 1;

		new Ajax.Request(query_url, {method: 'get', parameters: $(active_form).serialize(),
			onSuccess: function(transport)
			{
				var oJSON = transport.responseText.evalJSON();

				if (oJSON.packaging_required > 1)
					$string_packaging = ' packs';
				else
					$string_packaging = ' pack';

				var order_total_cost = 	oJSON.order_final_cost;

				if (add_plaque == 1)
					var order_total_cost = Number(oJSON.order_final_cost) + 75;

				$('order_cost_' + form_type).innerHTML = order_total_cost;
				$('packaging_cost_' + form_type).innerHTML = oJSON.packaging_final_cost;
				$('packaging_required_' + form_type).innerHTML = oJSON.packaging_required + $string_packaging;
				$('formulation_cost_' + form_type).innerHTML = oJSON.formulation_final_cost;
				$('cost_per_tonne_' + form_type).innerHTML = oJSON.cost_per_tonne;
			}});
	}

	function calculateTotalCost(sType)
	{
		if (sType == 'match')
		{
			var sFormId 	= 'matchoption';
			var sResponse = 'matchoptionoutput';
			var sTonne 		= 'cost_tonne_match';
		}
		else if (sType == 'price')
		{
			var sFormId		= 'priceoption';
			var sResponse = 'priceoptionoutput';
			var sTonne	 	= 'cost_tonne_price';
		}
		else
		{
			var sFormId 	= 'customer_costing';
			var sResponse	= 'innerCost';
			var sFormSubmission = 'cost_quoted';
		}

		var query_url = '/scripts/ajax/customer_costing.scr.php';
		new Ajax.Request(query_url, {method: 'get', parameters: $(sFormId).serialize(),
  				onSuccess: function(transport) {
  					var sCosts = transport.responseText;
  					var aCosts = sCosts.split(':');

  					if (sType != 'match' && sType != 'price')
  					{
  						var aCostBreakdown = aCosts[0].split(' ');
  						$(sFormSubmission).value	= aCostBreakdown[0];
  					}

    				$(sResponse).innerHTML 	= aCosts[0];
    				$(sTonne).innerHTML			= aCosts[1];

  				}});
	}

	function sampleType(sSampleType)
	{
		if (sSampleType == 'foc')
		{
			$('foc_sample').style.display 						= 'block';
			$('shipping_selection').style.display 		= 'none';
			$('shipping_options').style.display 			= 'none';
			$('option_order_quantity').style.display	= 'none';
			$('standard_shipping').style.display			= 'none';
		}
		else if (sSampleType == 'production')
		{
			$('foc_sample').style.display 						= 'none';
			$('shipping_selection').style.display 		= 'block';

			if ($('shipping_selection').style.display == 'none')
			{
				$('option_order_quantity').style.display	= 'block';
			}
			else
			{
				$('option_order_quantity').style.display	= 'none';
			}
		}
	}

	function shippingType(sShippingType)
	{
		if (sShippingType == 'custom')
		{
			$('shipping_options').style.display				= 'block';
			$('option_order_quantity').style.display	= 'block';
			$('standard_shipping').style.display			= 'none';
		}
		else
		{
			$('shipping_options').style.display				= 'none';
			$('option_order_quantity').style.display	= 'block';
			$('standard_shipping').style.display			= 'block';
		}
	}

	function limitFoC()
	{
		if ($('foc_order_quantity').value > 3)
		{
			$('foc_order_quantity').value = 3;
			$('foc_quantity_notice').innerHTML = 'Please note there is a 3Kg limit.';
		}
		else
		{
			$('foc_quantity_notice').innerHTML = '';
		}
	}
