<!--
function connote_detail_onclick(x_button)
{
	if ((x_button == 'save') || (x_button == 'save_next') || (x_button == 'save_new')) 
	{
		var x_id 	= document.getElementById('connote_id').value;
		var url 	= 'modules/connote/connote_detail.php';;
		var param 	= '';
		
		if(connote_detail_validate(x_button) == false)
			return;

		ajax_showdiv('div_form_1');

		if (x_button == 'save') 
		{
			param += 'mode=update';
		}
		else if (x_button == 'save_next') 
		{
			param += 'mode=update_next';
		}
		else if (x_button == 'save_new') 
		{
			param += 'mode=update_new';
		}
		
		param += '&return_id=' + document.getElementById('connote_id').value;
		param += index_param('null','connote_gen_ref_client');

		param += index_param('null','connote_pick_company');
		param += index_param('null','connote_pick_address');
		param += index_param('null','connote_pick_suburb');
		param += index_param('null','connote_pick_area_id');
		param += index_param('null','connote_pick_state');
		param += index_param('null','connote_pick_postcode');

		param += index_param('null','connote_del_company');
		param += index_param('null','connote_del_address');
		param += index_param('null','connote_del_suburb');
		param += index_param('null','connote_del_area_id');
		param += index_param('null','connote_del_state');
		param += index_param('null','connote_del_postcode');

		param += index_param('null','connote_freight_items');
		param += index_param('null','connote_freight_volume');
		param += index_param('null','connote_freight_weight');

		param += index_param('null','connote_pod_recipient');

		param += index_param('null','connote_client_id');
		param += index_param('null','connote_client_company');

		param += index_param('null','connote_id');
		param += index_param('null','connote_status_id');

		param += index_param('null','connote_gen_type_id');
		param += index_param('null','connote_gen_date');

		// Cost
		if (document.getElementById('connote_cost_freight_flag').checked == true)
			param += '&connote_cost_freight_flag=' 		+ 'checked';
		else
			param += '&connote_cost_freight_flag=' 		+ '';

		param += index_param('null','connote_cost_freight');
		param += index_param('null','connote_cost_other');
		param += index_param('null','connote_cost_total');
		param += index_param('null','connote_cost_gst');
		param += index_param('null','connote_cost_total_gst');
		param += index_param('null','connote_cost_paid');
		param += index_param('null','connote_cost_bal');
		param += index_param('null','connote_cost_notes');
		
		// Rates (Client)
		param += index_param('null','connote_rate_low');
		param += index_param('null','connote_rate_high');
		param += index_param('null','connote_rate_flat');
		param += index_param('null','connote_rate_kg');
		param += index_param('null','connote_rate_item');
		param += index_param('null','connote_rate_message');

		var div = 'div_popup_1';
		if (x_button == 'save') 
		{
			var callback = "index_location('connote','connote','summary','"+x_id+"')";
		}
		else if ((x_button == 'save_next') || (x_button == 'save_new'))
		{
			var callback = "ajax_processRequestPost('modules/connote/connote_summary.php','','div_body','connote_summary_onload();');connote_detail_onload('');";
		}
		ajax_processRequestPost(url,param,div,callback)
		return false;
	}
	if (x_button == 'close') 
	{
		ajax_showdiv('div_form_1');

		ajax_showdiv('div_result');
		
		var url 	= 'modules/connote/connote_summary.php';
		var param   = 'return_id=' + document.getElementById('connote_id').value;
		var div 	= 'div_body';
		var	callback = ''
		callback += "Popup.hide('div_popup_1');";
		callback += "connote_summary_onload();";
		ajax_processRequestPost(url,param,div,callback)
		return false;
	}
	return false;
}

function connote_detail_validate(x_button)
{
	// Status Based Validation
	// 1 = 'Draft'; 
	// 2 = 'New Booking'; 
	// 3 = 'Delivery'; 
	// 4 = 'POD'; 
	// 5 = 'Completed'; 
	// 6 = 'Cancelled'; 
	
	var x_status = document.getElementById('connote_status_id').value;

	if ((x_status == 1) || (x_status == 7))
		return true;	

	if (!isEmpty('connote_gen_date', 'Please enter a \'Date\''))
		return false;

	if (!isEmpty('connote_gen_ref_client', 'Please enter a \'Con-Note\'  Number'))
		return false;

	if (!isEmpty('connote_pick_company', 'Please enter a \'Sender Company\''))
		return false;

	if (document.getElementById('connote_gen_type_id').value == '2') // Pickup
	{
		if (!isSelected('connote_pick_area_id', 'Please select a \'Sender Suburb\' from the provided list'))
			return false;
	}
	
	if (!isEmpty('connote_del_company', 'Please enter a \' Recipient Company\''))
		return false;

	if (document.getElementById('connote_gen_type_id').value == '1') // Delivery
	{
		if (!isSelected('connote_del_area_id', 'Please select a \'Recipient Suburb\' from the provided list'))
			return false;
	}
	if (document.getElementById('connote_client_id').value == 0)
	{
		alert('Please select a CLIENT COMPANY');
		document.getElementById('connote_client_id').focus();
		return false;
	}

	if ((x_status == 4) || (x_status == 5))
	{
		if (document.getElementById('connote_freight_items').value == '0')
		{
			alert('Please enter a non-zero ITEMS');
			document.getElementById('connote_freight_items').focus();
			return false;
		}
/*
		if (document.getElementById('connote_freight_weight').value == '0.0')
		{
			alert('Please enter a non-zero WEIGHT');
			document.getElementById('connote_freight_weight').focus();
			return false;
		}
*/		
		if (!isEmpty('connote_pod_recipient', 'Please enter a \'POD Recipient\''))
			return false;
	}
	
	// All Good.
	return true;
}

function connote_detail_fill_address(
					obj_company,value_company,
					obj_area_id,value_area_id,
					obj_address,value_address,
					obj_suburb,value_suburb,
					obj_div_state,value_div_state,
					obj_state,value_state,
					obj_div_postcode,value_div_postcode,
					obj_postcode,value_postcode,
					div)
{
	$('#' + obj_company).val(value_company);
	$('#' + obj_address).val(value_address);
	$('#' + obj_suburb).val(value_suburb);
	$('#' + obj_area_id).val(value_area_id);
	document.getElementById(obj_div_state).innerHTML = value_div_state;	
	$('#' + obj_state).val(value_state);
	document.getElementById(obj_div_postcode).innerHTML = value_div_postcode;	
	$('#' + obj_postcode).val(value_postcode);
	setTimeout("$('#" + div + "').hide();", 200);
	
	// Refresh Rates/Costs
	connote_detail_action('calculate_rate','');
}

function connote_detail_fill_area(
					obj_area_id,value_area_id,
					obj_suburb,value_suburb,
					obj_div_state,value_div_state,
					obj_state,value_state,
					obj_div_postcode,value_div_postcode,
					obj_postcode,value_postcode,
					div)
{
	$('#' + obj_area_id).val(value_area_id);
	$('#' + obj_suburb).val(value_suburb);
	document.getElementById(obj_div_state).innerHTML = value_div_state;	
	$('#' + obj_state).val(value_state);
	document.getElementById(obj_div_postcode).innerHTML = value_div_postcode;	
	$('#' + obj_postcode).val(value_postcode);
	setTimeout("$('#" + div + "').hide();", 200);
	
	// Refresh Rates/Costs
	connote_detail_action('calculate_rate','');	
}

function connote_detail_fill_client(
					obj_client_id,value_client_id,
					obj_client_company,value_client_company,
					div)
{
	$('#' + obj_client_id).val(value_client_id);
	$('#' + obj_client_company).val(value_client_company);
	
	connote_detail_action('calculate_rate','');
}

// Overwrite
function connote_detail_overwrite_cost()
{
	connote_detail_action('calculate_rate','');
	/*
	if (document.getElementById('connote_cost_freight_flag').checked == true)
	{
		document.getElementById('connote_cost_freight').readOnly = false;
		document.getElementById('connote_cost_freight').style.backgroundColor = '#99FF99';
		connote_detail_action('calculate_rate','');
	}
	else
	{
		document.getElementById('connote_cost_freight').readOnly = true;
		document.getElementById('connote_cost_freight').style.backgroundColor = '#FFFFFF';
		connote_detail_action('calculate_rate','');
	}
	*/
}

function connote_detail_action(x_mode, x_id)
{
	if (x_mode == 'calculate')	
	{
		connote_detail_format();
		connote_detail_highlight();
		
		// Client Charges
		var freight = document.getElementById('connote_cost_freight').value;
		var other = document.getElementById('connote_cost_other').value;
	
		var total = parseFloat(freight) + parseFloat(other); 
		
		total = parseFloat(total).toFixed(2);
		var gst = (parseFloat(total) * 0.1).toFixed(2);
		var total_gst = (parseFloat(total) + parseFloat(gst)).toFixed(2);
	
		document.getElementById('connote_cost_freight').value = parseFloat(freight).toFixed(2);
		document.getElementById('connote_cost_other').value = parseFloat(other).toFixed(2);
		document.getElementById('connote_cost_total').value = total;
		document.getElementById('connote_cost_gst').value = gst;
		document.getElementById('connote_cost_total_gst').value = total_gst;
		document.getElementById('connote_cost_bal').value = total_gst;
	}
	if (x_mode == 'calculate_rate')	
	{
		connote_detail_format();
		connote_detail_highlight();

		ajax_showdiv('div_connote_detail_rate_load');
		
		var url 	 = 'modules/connote/connote_detail_rate.php';
		var param    = 'mode=edit';
		param 		+= '&connote_id=' + document.getElementById('connote_id').value;
		param 		+= '&connote_client_id=' + document.getElementById('connote_client_id').value;
		param 		+= '&connote_gen_type_id=' + document.getElementById('connote_gen_type_id').value;
		param 		+= '&connote_pick_area_id=' + document.getElementById('connote_pick_area_id').value;
		param 		+= '&connote_del_area_id=' + document.getElementById('connote_del_area_id').value;
		param 		+= '&connote_freight_items=' + document.getElementById('connote_freight_items').value;
		param 		+= '&connote_freight_weight=' + document.getElementById('connote_freight_weight').value;
		if (document.getElementById('connote_cost_freight_flag').checked == true)
			param += '&connote_cost_freight_flag=' 		+ 'checked';
		else
			param += '&connote_cost_freight_flag=' 		+ '';
		param 		+= '&connote_cost_freight=' + document.getElementById('connote_cost_freight').value;
		param 		+= '&connote_cost_other=' + document.getElementById('connote_cost_other').value;
		param 		+= '&connote_cost_notes=' + encodeURIComponent(document.getElementById('connote_cost_notes').value);
		param 		+= '&connote_cost_paid=' + document.getElementById('connote_cost_paid').value;
		param 		+= '&connote_cost_bal=' + document.getElementById('connote_cost_bal').value;

		var div 	= 'div_connote_detail_rate';
		var	callback = 'connote_detail_highlight();'
		ajax_processRequestPost(url,param,div,callback)
		return false;
	}
}

function connote_detail_highlight()
{
	// Get Status
	var x_status = document.getElementById('connote_status_id').value;

	// Set to Off
	x_color = '#FFFFFF';

	index_bg_color('connote_gen_ref_client',x_color);
	
	index_bg_color('connote_pick_company',x_color);
	index_bg_color('connote_pick_suburb',x_color);
	
	index_bg_color('connote_del_company',x_color);
	index_bg_color('connote_del_suburb',x_color);

	index_bg_color('connote_freight_items',x_color);
	index_bg_color('connote_freight_weight',x_color);

	index_bg_color('connote_pod_recipient',x_color);

	index_bg_color('connote_client_company',x_color);
	index_bg_color('connote_gen_date',x_color);

	// Status Based Validation
	// 1 = Draft
	// 2 = New Booking
	// 4 = Delivery
	// 5 = POD
	// 6 = Complete
	// 7 = Cancelled

	if ((x_status == 1) || (x_status == 7)) // Draft or Cancelled
		return;

	x_color = '#99FF99'; // Green

	if (document.getElementById('connote_gen_ref_client').value == '')
		index_bg_color('connote_gen_ref_client',x_color);

	if (document.getElementById('connote_pick_company').value == '')
		index_bg_color('connote_pick_company',x_color);

	if (document.getElementById('connote_gen_type_id').value == '2') // Pickup
	{
		if (document.getElementById('connote_pick_suburb').value == '')
			index_bg_color('connote_pick_suburb',x_color);
		if (document.getElementById('connote_pick_area_id').value == '0')
			index_bg_color('connote_pick_suburb',x_color);
	}
	
	if (document.getElementById('connote_del_company').value == '')
		index_bg_color('connote_del_company',x_color);

	if (document.getElementById('connote_gen_type_id').value == '1') // Delivery
	{
		if (document.getElementById('connote_del_suburb').value == '')
			index_bg_color('connote_del_suburb',x_color);
		if (document.getElementById('connote_del_area_id').value == '0')
			index_bg_color('connote_del_suburb',x_color);
	}
	
	if (document.getElementById('connote_freight_items').value == '0')
		index_bg_color('connote_freight_items',x_color);

//	if (document.getElementById('connote_freight_weight').value == '0.0')
//		index_bg_color('connote_freight_weight',x_color);

	if (document.getElementById('connote_client_id').value == '')
		index_bg_color('connote_client_company',x_color);

	if (document.getElementById('connote_gen_date').value == '')
		index_bg_color('connote_gen_date',x_color);

	if ((x_status == 4) || (x_status == 5))
	{
		if (document.getElementById('connote_pod_recipient').value == '')
			index_bg_color('connote_pod_recipient',x_color);
	}
}

function connote_detail_format()
{
	index_conv_dec('connote_pick_area_id','0');
	index_conv_dec('connote_del_area_id','0');

	index_conv_dec('connote_freight_items','0');
	index_conv_dec('connote_freight_volume','3');
	index_conv_dec('connote_freight_weight','1');

	index_conv_dec('connote_cost_freight','2');
	index_conv_dec('connote_cost_other','2');
	index_conv_dec('connote_cost_total','2');
	index_conv_dec('connote_cost_gst','2');
	index_conv_dec('connote_cost_total_gst','2');
	index_conv_dec('connote_cost_paid','2');
	index_conv_dec('connote_cost_bal','2');

	index_conv_dec('connote_rate_low','1');
	index_conv_dec('connote_rate_high','1');
	index_conv_dec('connote_rate_flat','2');
	index_conv_dec('connote_rate_kg','2');
	index_conv_dec('connote_rate_item','2');
}
function connote_detail_focus()
{
	document.getElementById('connote_gen_ref_client').focus();
}
function connote_detail_onload(mode)
{
	if ((mode == 'insert') || (mode == 'edit') || (mode == 'view'))
		ajax_showpopup('div_popup_1','div_result');

	Calendar.setup({
		inputField     	:    "connote_gen_date",
		ifFormat       	:    "%d-%m-%Y",
		button         	:    "connote_gen_date_link",
		align          	:    "BR",
		singleClick    	:    true
	});

	connote_detail_format();
	connote_detail_highlight();
//	connote_detail_focus();
	return;
}
-->
