<!--
//  Title:       Region Summary
//  Developer:   Wade McDonough
//  Verion:      1.0
//  Date:        3 Nov 2006
//  Description: 
// 
/////////////////////////////

function report_1_summary_onclick(x_button)
{
	if (x_button == 'apply')
	{
		ajax_showdiv('div_result');

		var url = 'modules/report_1/report_1_summary.php';

		var param = 'filter_client=' 	+ encodeURIComponent(document.getElementById('filter_client').value);
		param += '&filter_client_id=' 	+ document.getElementById('filter_client_id').value;
		param += '&filter_status=' 		+ document.getElementById('filter_status').value;
//		param += '&filter_print=' 		+ document.getElementById('filter_print').value;
//		param += '&filter_email=' 		+ document.getElementById('filter_email').value;
		param += '&filter_i_string='	+ document.getElementById('filter_i_string').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 = "report_1_summary_onload();";
		ajax_processRequestPost(url,param,div,callback)
		return false;
	}
	else if (x_button == 'reset')
	{
		ajax_showdiv('div_result');

		var url = 'modules/report_1/report_1_summary.php';

		var param = 'filter_client='		+ '';
		param += '&filter_client_id=' 		+ '0';
		param += '&filter_status=' 			+ '1';
		param += '&filter_i_string='		+ '';
//		param += '&filter_print=' 			+ '1';
//		param += '&filter_email=' 			+ '0';
		param += '&filter_from='			+ '';
		param += '&filter_to='				+ '';
	
		var div = 'div_body';
		var callback = "report_1_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

		// Print
		if (with_selected == 1)
		{
			// Reset Starting Position
			document.getElementById('with_selected').value = 0;

			// Clear Checkboxes
			for (var i=1; i<document.forms[0].elements.length; i++) 
			{
				if ((document.forms[0].elements[i].type == "checkbox") && (document.forms[0].elements[i].name == "checkbox_id[]")) 
				{
					document.forms[0].elements[i].checked = false;
				}
			}
			// Display Invoice
			report_1_summary_action('print',checkbox_string);
		}
		// Email
		if (with_selected == 2)
		{
			// Reset Starting Position
			document.getElementById('with_selected').value = 0;
			
			// Clear Checkboxes
			for (var i=1; i<document.forms[0].elements.length; i++) 
			{
				if ((document.forms[0].elements[i].type == "checkbox") && (document.forms[0].elements[i].name == "checkbox_id[]")) 
				{
					document.forms[0].elements[i].checked = false;
				}
			}

			// Send email(s)
			report_1_summary_action('email',checkbox_string)
		}
		// Print (No Header)
		if (with_selected == 3)
		{
			// Reset Starting Position
			document.getElementById('with_selected').value = 0;

			// Clear Checkboxes
			for (var i=1; i<document.forms[0].elements.length; i++) 
			{
				if ((document.forms[0].elements[i].type == "checkbox") && (document.forms[0].elements[i].name == "checkbox_id[]")) 
				{
					document.forms[0].elements[i].checked = false;
				}
			}

			// Display Invoice
			report_1_summary_action('print_no_header',checkbox_string);
		}
	}
	return false;
}
function report_1_summary_pdf(id)
{
	var url = 'modules/report_1/report_1_summary_pdf.php';
	url += '?mode=print';
	url += '&checkbox_id=' 	+ id;
	newWindow = window.open(url,'report','width=900,height=700,resizable=yes,scrollbars=yes');
	newWindow.focus();
}
function report_1_summary_action(mode,id)
{
	if (mode == 'edit_inline')
	{
		ajax_showdiv('div_result');
		
		var url 		= 'modules/report_1/report_1_summary.php';
		var div 		= 'div_body';
		var param   	= 'mode=' + mode;
		param   		+= '&edit_inline_id=' + id;
		param   		+= '&return_id=' + id;
		var callback 	= "report_1_summary_onload('" + mode + "');";
		
		ajax_processRequestPost(url,param,div,callback)
	}
	if (mode == 'update_inline')
	{
		ajax_showdiv('div_result');
		
		var url 		= 'modules/report_1/report_1_summary.php';
		var div 		= 'div_body';
		var param   	= 'mode=' + mode;
		param   		+= '&invoice_id=' + id;
		param 			+= '&invoice_date=' + document.getElementById('invoice_date').value;
		param   		+= '&return_id=' + id;
		var callback 	= "report_1_summary_onload('" + mode + "');";
		
		ajax_processRequestPost(url,param,div,callback)
	}
	if (mode == 'print')
	{
		report_1_summary_print(mode,id);
		
		ajax_showdiv('div_result');
		
		var url 		= 'modules/report_1/report_1_summary.php';
		var div 		= 'div_body';
		var param   	= 'mode=' + mode;
		param   		+= '&invoice_id=' + id;
		var callback 	= "report_1_summary_onload('" + mode + "');";
		
		ajax_processRequestPost(url,param,div,callback)
	}
	if (mode == 'print_no_header')
	{
		report_1_summary_print(mode,id);

		ajax_showdiv('div_result');
		
		var url 		= 'modules/report_1/report_1_summary.php';
		var div 		= 'div_body';
		var param   	= 'mode=' + mode;
		param   		+= '&invoice_id=' + id;
		var callback 	= "report_1_summary_onload('" + mode + "');";
		
		ajax_processRequestPost(url,param,div,callback)
	}
	if (mode == 'preview')
	{
		report_1_summary_print('print',id);
	}
	if (mode == 'email')
	{
		ajax_showdiv('div_result');
		
		var answer = confirm("Selected Invoices are about to be emailed to Clients\n\n Click OK to continue or CANCEL to quit.")
		if (answer)
		{
			var url 		= 'modules/report_1/report_1_summary.php';
			var div 		= 'div_body';
			var param   	= 'mode=' + mode;
			param   		+= '&invoice_id=' + id;
			var callback 	= "report_1_summary_onload('" + mode + "');";
			
			ajax_processRequestPost(url,param,div,callback)
		}
		else
		{
			ajax_hidediv('div_result');	
	
		}
	}
	if (mode == 'delete')
	{
		ajax_showdiv('div_result');
		
		var answer = confirm("This item will be permanently deleted\n\n Click OK to continue or CANCEL to quit.")
		if (answer)
		{
			var url 		= 'modules/report_1/report_1_summary.php';
			var div 		= 'div_body';
			var param   	= 'mode=' + mode;
			param   		+= '&invoice_id=' + id;
			var callback 	= "report_1_summary_onload('" + mode + "');";
			
			ajax_processRequestPost(url,param,div,callback)
		}
		else
		{
			ajax_hidediv('div_result');	
	
		}
	}
}
function report_1_summary_print(mode,id)
{
	// Display Invoice
	var url = 'modules/report_1/report_1_summary_pdf.php';
	url += '?mode=' 		+ mode;
	url += '&checkbox_id=' 	+ id;

	newWindow = window.open(url,'report','width=900,height=700,resizable=yes,scrollbars=yes');
	newWindow.focus();
}
function report_1_summary_onload(x_mode)
{
	// Onload
	if (x_mode == 'edit_inline')
	{
		Calendar.setup({
			inputField     	:    "invoice_date",
			ifFormat       	:    "%d-%m-%Y",
			button         	:    "invoice_date_link",
			align          	:    "BR",
			singleClick    	:    true
		});
	}
	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
	});	
}
-->
