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

function connote_summary_onclick(x_button)
{
	if (x_button == 'apply')
	{
		var url = 'modules/connote/connote_summary.php';

		var param = 'filter_string='		+ document.getElementById('filter_string').value;
		param += '&filter_client=' 		+ encodeURIComponent(document.getElementById('filter_client').value);
		param += '&filter_client_id=' 	+ document.getElementById('filter_client_id').value;
		
		// 1
		if (document.getElementById('filter_draft').checked == true)
			param += '&filter_draft=' 		+ 'checked';
		else
			param += '&filter_draft=' 		+ '';

		// 2
		if (document.getElementById('filter_booking').checked == true)
			param += '&filter_booking=' 		+ 'checked';
		else
			param += '&filter_booking=' 		+ '';
		
		// 3
		if (document.getElementById('filter_delivery').checked == true)
			param += '&filter_delivery=' 		+ 'checked';
		else
			param += '&filter_delivery=' 		+ '';
		
		// 4
		if (document.getElementById('filter_pod').checked == true)
			param += '&filter_pod=' 		+ 'checked';
		else
			param += '&filter_pod=' 		+ '';
		
		// 5
		if (document.getElementById('filter_complete').checked == true)
			param += '&filter_complete=' 		+ 'checked';
		else
			param += '&filter_complete=' 		+ '';
		
		// 6
		if (document.getElementById('filter_cancelled').checked == true)
			param += '&filter_cancelled=' 		+ 'checked';
		else
			param += '&filter_cancelled=' 		+ '';
		
		// 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;
		
		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 = "connote_summary_onload();";
		ajax_processRequestPost(url,param,div,callback)
	}
	if (x_button == 'reset')
	{
		var url = 'modules/connote/connote_summary.php';

		var param = 'filter_string=' 		+ '';
		param += '&filter_client=' 				+ '';
		param += '&filter_client_id=' 			+ '0';
		param += '&filter_draft=' 			+ 'checked';
		param += '&filter_booking=' 		+ 'checked';
		param += '&filter_delivery=' 		+ 'checked';
		param += '&filter_pod=' 			+ 'checked';
		param += '&filter_complete=' 		+ 'checked';
		param += '&filter_cancelled='		+ '';

		// From
		param += "&filter_from=" + "";

		// To
		param += "&filter_to="		+ "";

		var div = 'div_body';
		var callback = "connote_summary_onload();";
		ajax_processRequestPost(url,param,div,callback)
	}
	else if (x_button == 'select_apply')
	{
		if (!isSelected('select_action', '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('select_action').value

		// Assign Client and OCR
		if (with_selected == 1)
		{
			if (!isSelected('select_template', 'Please select a \'Template\''))
				return false;
		
			var url = 'modules/connote/connote_assign_detail.php';

			var param = 'mode=assign';
			param += '&id=' 		+ checkbox_string;
			param += '&crop_id=' 	+ document.getElementById('select_template').value;

			var div = 'div_popup_1';
			var callback = "connote_assign_detail_onload('assign');";
			ajax_processRequestPost(url,param,div,callback)

			return false;
		}
		// Delete Jobs
		if (with_selected == 2)
		{
			var answer = confirm("This action will PERMANENTLY DELETE all select jobs\n\n Click OK to continue or CANCEL to quit.")
			if (answer)
			{
				ajax_showdiv('div_result');
		
				var url = 'modules/connote/connote_summary.php';
				var param = 'mode=delete';
				param += '&connote_id=' 				+ checkbox_string;
	
				var div = 'div_body';
				var callback = "connote_summary_onload();";
				ajax_processRequestPost(url,param,div,callback)
				return false;
			}
		}
		// Print
		if (with_selected == 3)
		{
			x_window  = "modules/connote/connote_summary_print.php";
			x_window += "?mode=print";
			x_window += "&checkbox_id=" + checkbox_string;
			var new_window = window.open(x_window,'print','width=950,height=800,resizable=yes,scrollbars=yes');
			new_window.focus();
		}
		return false;
	}
	return false;
}
function connote_summary_print(id)
{
	x_window = "modules/connote/connote_summary_print.php?checkbox_id=" + id;
	var new_window = window.open(x_window,'print','width=900,height=800,resizable=yes,scrollbars=yes');
	new_window.focus();
}

function connote_summary_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
	});	
}
-->
