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

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

		var url = 'modules/invoice_c_pre/invoice_c_pre_summary.php';

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

		// Change to MYSQL format
		var temp_date = document.getElementById('filter_from').value;
		if (temp_date != '')
		{
			temp_date = temp_date.substring(6) + '-' + temp_date.substring(3,5) + '-' + temp_date.substring(0,2);
		}		
		param += '&filter_from='	+ temp_date;

		// Change to MYSQL format
		var temp_date = document.getElementById('filter_to').value;
		if (temp_date != '')
		{
			temp_date = temp_date.substring(6) + '-' + temp_date.substring(3,5) + '-' + temp_date.substring(0,2);
		}		
		param += '&filter_to='			+ temp_date;

		var div = 'div_body';
		var callback = "invoice_c_pre_summary_onload();";
		ajax_processRequestPost(url,param,div,callback)
		return false;
	}
	if (x_button == 'reset')
	{
		ajax_showdiv('div_result');
		var url = 'modules/invoice_c_pre/invoice_c_pre_summary.php';

		var param 	 = 'filter_client=' 	+ '';
		param 		+= '&filter_client_id=' + '0';
		param 		+= '&filter_from='		+ '';
		param 		+= '&filter_to='		+ '';

		var div = 'div_body';
		var callback = "invoice_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 a \'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
		document.getElementById('with_selected').value = 0; // Reset Starting Position

		// Assign Invoice
		if (with_selected == 1)
		{
			ajax_showdiv('div_result');
			
			var url = 'modules/invoice_c_pre/invoice_c_pre_summary.php';

			var param = 'mode=assign_invoice';
			param += '&invoice_id=' 	+ checkbox_string;

			var div = 'div_body';
			var callback = "invoice_c_pre_summary_onload();";
			ajax_processRequestPost(url,param,div,callback)
			return false;
		}
	}
	return false;
}
function invoice_c_pre_summary_onload()
{
	// Onload
	Calendar.setup({
		inputField     	:    "filter_from",
		ifFormat       	:    "%d-%m-%Y",
		button         	:    "filter_from_link",
		align          	:    "BR",
		singleClick    	:    true
	});
	Calendar.setup({
		inputField     	:    "filter_to",
		ifFormat       	:    "%d-%m-%Y",
		button         	:    "filter_to_link",
		align          	:    "BR",
		singleClick    	:    true
	});	
}
-->
