<!--
//  Title:       Region Summary
//  Developer:   Wade McDonough
//  Verion:      1.0
//  Date:        3 Nov 2006
//  Description: 
// 
/////////////////////////////

function statement_c_pre_summary_onclick(x_button)
{
	if (x_button == 'apply')
	{
		ajax_showdiv('div_result');

		var url = 'modules/statement_c_pre/statement_c_pre_summary.php';

		var param = 'filter_client=' 	+ encodeURIComponent(document.getElementById('filter_client').value);
		param += '&filter_client_id=' 	+ document.getElementById('filter_client_id').value;

		var div = 'div_body';
		var callback = "statement_c_pre_summary_onload();";
		ajax_processRequestPost(url,param,div,callback)
		return false;
	}
	if (x_button == 'reset')
	{
		ajax_showdiv('div_result');

		var url = 'modules/statement_c_pre/statement_c_pre_summary.php';

		var param 	 = 'filter_client=' 		+ '';
		param 		+= '&filter_client_id=' 	+ '0';
	
		var div = 'div_body';
		var callback = "statement_c_pre_summary_onload();";
		ajax_processRequestPost(url,param,div,callback)
		return false;
	}
	else if (x_button == 'with_select_apply')
	{
		if (!isSelected('with_selected', 'Please select an item from \'With Selected\''))
			return false;
		
		// Test for at least one checked checkbox
		var checkbox_count = 0;
		var checkbox_string = '';
		for (var i=1; i<document.forms[0].elements.length; i++) 
		{
			// Look for check box matches
			if ((document.forms[0].elements[i].type == "checkbox") && (document.forms[0].elements[i].name == "checkbox_id[]")) 
			{
				if (document.forms[0].elements[i].checked == true)
				{
					checkbox_count++;
					checkbox_string += document.forms[0].elements[i].value + ',';
				}
			}
		}
		checkbox_string = checkbox_string.slice(0, -1)

		if (checkbox_count == 0)
		{
			alert('No items selected!\n\nPlease select at least one checkbox');
			return;
		}

		var with_selected = document.getElementById('with_selected').value

		// Assign to Statement
		if (with_selected == 1)
		{
			if (!isSelected('statement_from', 'Please select a \'From Date\''))
				return false;

			if (!isSelected('statement_to', 'Please select a \'To Date\''))
				return false;
		
			// Reset Starting Position
			document.getElementById('with_selected').value = 0;
			ajax_showdiv('div_result');
	
			var url = 'modules/statement_c_pre/statement_c_pre_summary.php';

			var param = 'mode=assign_statement';
			param += '&invoice_id=' 		+ checkbox_string;
			param += '&statement_from=' 	+ document.getElementById('statement_from').value;
			param += '&statement_to=' 	+ document.getElementById('statement_to').value;

			var div = 'div_body';
			var callback = "statement_c_pre_summary_onload();";
			ajax_processRequestPost(url,param,div,callback)
			return false;
		}
	}
	return false;
}
function statement_c_pre_summary_onload()
{
	// Onload
	Calendar.setup({
		inputField     	:    "statement_from",
		ifFormat       	:    "%d-%m-%Y",
		button         	:    "statement_from_link",
		align          	:    "BR",
		singleClick    	:    true
	});
	Calendar.setup({
		inputField     	:    "statement_to",
		ifFormat       	:    "%d-%m-%Y",
		button         	:    "statement_to_link",
		align          	:    "BR",
		singleClick    	:    true
	});
}
-->
