
		/* const variables */
		var CURRENCY_PREFIX = "$",

			PLIMUS_CHECKOUT_PAGE = "https://secure.plimus.com/jsp/checkout.jsp?developerId=88706&submitAction=buynow",
			PLIMUS_CONTRACT_ID_1 = "2585586",
			PLIMUS_CONTRACT_ID_2 = "2267133",
			
			price_1_1 = 39.95,
			price_1_2 = 25.97,
			price_1_3 = 21.97,
			price_1_4 = 19.97,
			price_1_5 = 15.98,
						
			price_2_1 = 59.95,
			price_2_2 = 38.97,
			price_2_3 = 32.97,
			price_2_4 = 29.97,
			price_2_5 = 23.98,

			/* GUI controls */
			ctrl_unit_price_1 = null,
			ctrl_unit_price_2 = null,
			
			ctrl_quantity_1 = null,
			ctrl_quantity_2 = null,

			ctrl_total_1 = null,
			ctrl_total_2 = null,
			ctrl_total = null;


		var get_gui_controls = function(){

			ctrl_unit_price_1 = document.getElementById("unit_price_1");
			ctrl_unit_price_2 = document.getElementById("unit_price_2");
			
			ctrl_quantity_1 = document.getElementById("quantity_1");
			ctrl_quantity_2 = document.getElementById("quantity_2");
			
			ctrl_total_1 = document.getElementById("total_1");
			ctrl_total_2 = document.getElementById("total_2");
			
			ctrl_total = document.getElementById("total");
			
			/* make sure they are correct */
			if (null == ctrl_unit_price_1 || null == ctrl_unit_price_2 
					|| null == ctrl_quantity_1 || null == ctrl_quantity_2 
					|| null == ctrl_total_1 || null == ctrl_total_2 
					|| null == ctrl_total){
					
				return false;
			}
			
			return true;
		}

		var increase_product_quantity = function(product_number){

			/* try to get GUI controls */
			if (false == get_gui_controls()){
				return;
			}

			/* increase proper product quantity */
			if (1 == product_number){
				ctrl_quantity_1.value++;
			} else if (2 == product_number){
				ctrl_quantity_2.value++;
			}

			/* update cart */
			update_cart();
		}

		var decrease_product_quantity = function(product_number){

			/* try to get GUI controls */
			if (false == get_gui_controls()){
				return;
			}

			/* decrease proper product quantity */
			if (1 == product_number){

				if (ctrl_quantity_1.value > 0)
					ctrl_quantity_1.value--;

			} else if (2 == product_number){

				if (ctrl_quantity_2.value > 0)
					ctrl_quantity_2.value--;
			}

			/* update cart */
			update_cart();
		}

		var update_cart = function(){

			/* try to get GUI controls */
			if (false == get_gui_controls()){
				return;
			}
			
			/* prepare data for calculations */
			var quantity_1 = ctrl_quantity_1.value,
				quantity_2 = ctrl_quantity_2.value,
				total_1  = 0,
				total_2 = 0;
			
			/* select price per unit value for product 1 */
			if (quantity_1 >= 1 && quantity_1 < 2){
				
				total_1  = price_1_1;

			} else if (quantity_1 >= 2 && quantity_1 < 7){

				total_1 = price_1_1 + ((quantity_1-1) * price_1_2);

			} else if (quantity_1 >= 7 && quantity_1 < 21){

				total_1 = price_1_1 + 5*price_1_2 + ((quantity_1-6) * price_1_3);

			} else if (quantity_1 >= 21 && quantity_1 < 51){

				total_1 = price_1_1 + 5*price_1_2 + 14*price_1_3 + ((quantity_1-20) * price_1_4);

			} else if (quantity_1 >= 51){

				total_1 = price_1_1 + 5*price_1_2 + 14*price_1_3 + 30*price_1_4 + ((quantity_1-50) * price_1_5);
			}
			
			/* select price per unit value for product 2 */
			if (quantity_2 >= 1 && quantity_2 < 2){
				
				total_2 = price_2_1;

			} else if (quantity_2 >= 2 && quantity_2 < 7){

				total_2 = price_2_1 + ((quantity_2-1) * price_2_2);

			} else if (quantity_2 >= 7 && quantity_2 < 21){
				
				total_2 = price_2_1 + 5*price_2_2 + ((quantity_2-6) * price_2_3);

			} else if (quantity_2 >= 21 && quantity_2 < 51){

				total_2 = price_2_1 + 5*price_2_2 + 14*price_2_3 + ((quantity_2-20) * price_2_4);

			} else if (quantity_2 >= 51){

				total_2 = price_2_1 + 5*price_2_2 + 14*price_2_3 + 30*price_2_4 + ((quantity_2-50) * price_2_5);
			}
			
			/* calculate total amounts */
			var total = total_1 + total_2;

			/* calculate price per unit */
			var pp_unit_1 = quantity_1 > 0 ? total_1 / quantity_1 : price_1_1;
			var pp_unit_2 = quantity_2 > 0 ? total_2 / quantity_2 : price_2_1;
			
			/* update GUI controls */
			ctrl_unit_price_1.innerHTML = CURRENCY_PREFIX + pp_unit_1.toFixed(2);
			ctrl_unit_price_2.innerHTML = CURRENCY_PREFIX + pp_unit_2.toFixed(2);
			
			ctrl_total_1.innerHTML = CURRENCY_PREFIX + total_1.toFixed(2);
			ctrl_total_2.innerHTML = CURRENCY_PREFIX + total_2.toFixed(2);
			ctrl_total.innerHTML = CURRENCY_PREFIX + total.toFixed(2);
		}


		var ensure_quantity_is_filled = function(){

			/* try to get GUI controls */
			if (false == get_gui_controls()){
				return;
			}

			/* there should be at least one item in the cart */
			if (ctrl_quantity_1.value <= 0 && ctrl_quantity_2.value <= 0){
				ctrl_quantity_1.value = 1;
			}
			
			if (ctrl_quantity_2.value <= 0){
				ctrl_quantity_2.value = 0;
			}
			
			update_cart();
		}


		var get_purchase_link = function(){

			/* try to get GUI controls */
			if (false == get_gui_controls()){
				return;
			}
			
			/* get quantity */
			var quantity_1 = ctrl_quantity_1.value;
			var quantity_2 = ctrl_quantity_2.value;	

			/* there should be at least one item in the cart */
			if (quantity_1 <= 0 && quantity_2 <= 0){
				quantity_1 = 1;
			}
			
			var ret_link = PLIMUS_CHECKOUT_PAGE;
			var number_of_contracts = 0;
			
			if (quantity_1 > 0){
				number_of_contracts++;
				ret_link += "&" + "contractId" + number_of_contracts + "=" + 
					PLIMUS_CONTRACT_ID_1 + "&quantity" + number_of_contracts + "=" + quantity_1;		
			}
			
			if (quantity_2 > 0){
				number_of_contracts++;
				ret_link += "&" + "contractId" + number_of_contracts + "=" + 
					PLIMUS_CONTRACT_ID_2 + "&quantity" + number_of_contracts + "=" + quantity_2;
			}	
			
			ret_link += "&numberOfContracts=" + number_of_contracts;
			
			return ret_link;
		}


		var navigate_to_registrator = function(){

			ensure_quantity_is_filled();

			if (document.getElementById("proceed_to_checkout"))
				document.getElementById("proceed_to_checkout").disabled = 1;
			
			window.location = get_purchase_link();
		}
		
		window.onload = function(){
		
			if (document.getElementById("proceed_to_checkout")){
				document.getElementById("proceed_to_checkout").disabled = 0;
			}
				
			update_cart();
		}