function rdp_web_order_submit(recap_button) {
	if (recap_button.value == "Recap") {
		rdp_web_order_recap(recap_button);
		alert('You must first view a Recap before submitting.\n\nFor your convenience this has been done for you.\n\nPlease click Submit again after reviewing order.');
		return false;
	}
	else {
		return true;
	}
}

function rdp_web_order_update(product_number) {

	var qty_obj = $('qty_'+product_number);
	var price_obj = $('price_'+product_number);
	var ext_obj = $('ext_'+product_number);

	if (qty_obj.value.match(/^\d+$/) || (qty_obj.value == "")) {
		var num = qty_obj.value * price_obj.value;
	
		ext_obj.value = num.toFixed(2);
	
		var pieces = 0;
		var total = 0;
	
		var count = 0;
		var inputs = $A(Form.getElements('order_guide_form'));
		inputs.each( function(theInput) {
			//alert(theInput.name);
			if (theInput.id.match(/^ext_\d+$/)) {
				total = total + parseFloat(theInput.value);
			}
			if (theInput.id.match(/^qty_\d+$/)) {
				if (parseInt(theInput.value) > 0 ) {
					pieces = pieces + parseInt(theInput.value);
				}
			}
			count++;
		});
	
	
		var pieces_obj = $('order_pieces');
		var total_obj = $('order_total');
	
	
		pieces_obj.value = pieces;
		total_obj.value = total.toFixed(2);
		
		if (qty_obj.value > 50) {
			alert('Warning: Quantity Entered is greater than 50 units. Please double check entry for accuracy.');
		}
		qty_obj.value = qty_obj.value.replace(/^0+/,'');
	}
	else if (!(qty_obj.value.match(/^$/))) {
		alert('Invalid Entry');
		qty_obj.value = "";
	}
	//alert(pieces);
}

function rdp_web_inventory_update(product_number) {

	var qty_obj = $('qty_'+product_number);
	var price_obj = $('price_'+product_number);
	var ext_obj = $('ext_'+product_number);

	if (qty_obj.value.match(/^\d*(\.\d+)?$/) || (qty_obj.value == "")) {
		var num = qty_obj.value * price_obj.value;
	
		ext_obj.value = num.toFixed(2);
	
		var pieces = 0;
		var total = 0;
	
		var count = 0;
		var inputs = $A(Form.getElements('order_guide_form'));
		inputs.each( function(theInput) {
			//alert(theInput.name);
			if (theInput.id.match(/^ext_\d+(_nonrdp)?$/)) {
				total = total + parseFloat(theInput.value);
			}
			if (theInput.id.match(/^qty_\d+(_nonrdp)?$/)) {
				if (parseInt(theInput.value) > 0 ) {
					pieces = pieces + parseInt(theInput.value);
				}
			}
			count++;
		});
	
	
		var pieces_obj = $('order_pieces');
		var total_obj = $('order_total');
	
	
		pieces_obj.value = pieces;
		total_obj.value = total.toFixed(2);
		
		if (qty_obj.value > 50) {
			alert('Warning: Quantity Entered is greater than 50 units. Please double check entry for accuracy.');
		}
		qty_obj.value = qty_obj.value.replace(/^0+/,'');
	}
	else if (!(qty_obj.value.match(/^$/))) {
		alert('Invalid Entry');
		qty_obj.value = "";
	}
	//alert(pieces);
}

function rdp_web_order_recap(recap_button) {
	
	if (recap_button.value == "Recap") {
		recap_button.value = "Show All";
		
		var inputs = $A(Form.getElements('order_guide_form'));
		inputs.each( function(theInput) {
			if (theInput.id.match(/^qty_\d+$/)) {
				if (!(parseInt(theInput.value) > 0) ) {
					$('line_' + theInput.id.match(/\d+/)).hide();
				}
			}
		});
		
	}
	else {
		recap_button.value = "Recap";
		var inputs = $A(Form.getElements('order_guide_form'));
		inputs.each( function(theInput) {
			if (theInput.id.match(/^qty_\d+$/)) {
				$('line_' + theInput.id.match(/\d+/)).show();
			}
		});
	}
	
}

function po_request_totaler(line) {
	$('po_line_'+line+'_ext').value = ($('po_line_'+line+'_line_price').value * $('po_line_'+line+'_line_qty').value).toFixed(2);
 	//$('po_line_'+line+'_price').value = $('po_line_'+line+'_price').value.toFixed(2);

	var i;
	var total = 0;
	for (i=1;i<10;i++) {
		if ($('po_line_'+i+'_ext').value) {
			total = total + ($('po_line_'+i+'_ext').value * 1);
		}
	}
	$('po_total').value = total.toFixed(2);
	return true	
}