<!--
function remit_detail_action(mode,id)
{
	if (mode == 'close')
	{
		ajax_hidepopup('div_popup_1','');
		index_location('t_account', 'remit', 'summary', id);
		return;
	}
	if (mode == 'save')
	{
		var remain = document.getElementById('remit_remain').value;
		if (remain != '0.00')
		{
			alert("Cannot Save Changes as the 'Amount Received' has not been completely applied.");
			return;	
		}
	
		if(remit_detail_validate() == false)
			return;
// Exit
//alert('This feature is not currently installed');
//return

		// Test for at least one checked checkbox
		var item_count = 0;
		var item_string_id = '';
		var item_string_val = '';
		for (var i=1; i<document.forms[0].elements.length; i++) 
		{
			// Look for all matches
			if ((document.forms[0].elements[i].type == "text") || (document.forms[0].elements[i].type == "hidden"))
			{
				if (document.forms[0].elements[i].name == "remit_id[]")
				{
					item_count++;
					temp_id = document.forms[0].elements[i].value;
					item_string_id  += temp_id + ',';
					item_string_val += document.getElementById('remit_pay_' + temp_id).value  + ',';
				}
			}
		}
//alert(item_count);

		item_string_id  = item_string_id.slice(0, -1)
		item_string_val = item_string_val.slice(0, -1)

		ajax_showdiv('div_load_remit_detail');

		var x_id = document.getElementById('remit_id').value;

		var url = 'modules/remit/remit_detail.php';

		var param = 'mode=update';
		param += '&remit_client_id=' 	+ id;

		var temp_date = document.getElementById('remit_date').value;
		if (temp_date != '')
		{
			temp_date = temp_date.substring(6) + '-' + temp_date.substring(3,5) + '-' + temp_date.substring(0,2);
		}		
		param += '&remit_date=' 		+ temp_date;

		param += '&remit_ref=' 			+ encodeURIComponent(document.getElementById('remit_ref').value);
		param += '&remit_apply=' 		+ encodeURIComponent(document.getElementById('remit_apply').value);

		param += '&remit_string_id=' 	+ item_string_id;
		param += '&remit_string_val=' 	+ item_string_val;

		var div = 'div_popup_1';
		var callback = "index_location('t_account', 'remit', 'summary', '" + id + "')";
//		var callback = "";
//alert(param);
//return;
		ajax_processRequestPost(url,param,div,callback)
		return false;
	}
	if (mode == 'payment_received')
	{
		index_conv_dec('remit_amount','2');
		
		// adjust remain based on apply
		var amount = document.getElementById('remit_amount').value;
		var apply = document.getElementById('remit_apply').value;
		var remain = document.getElementById('remit_remain').value;

		var new_remain = parseFloat(amount) - parseFloat(apply);
		new_remain = parseFloat(new_remain).toFixed(2);
		document.getElementById('remit_remain').value = new_remain;
	}
	if (mode == 'payment_blur')
	{
		// Format Py amount
		index_conv_dec('remit_pay_' + id,'2');

		// add current OLD amount back to remain
		var remain = parseFloat(document.getElementById('remit_remain').value) + parseFloat(document.getElementById('remit_pay_old_' + id).value);
		remain = parseFloat(remain).toFixed(2);
		document.getElementById('remit_remain').value = remain;

		// remove amount from apply
		var apply = parseFloat(document.getElementById('remit_apply').value) - parseFloat(document.getElementById('remit_pay_old_' + id).value);
		apply = parseFloat(apply).toFixed(2);
		document.getElementById('remit_apply').value = apply; 

		// if new amount is more than remain or balance, then set to zero and exit
		var new_pay = document.getElementById('remit_pay_' + id).value;
		var remain = document.getElementById('remit_remain').value;
		var balance = document.getElementById('remit_bal_' + id).value;
		if ((parseFloat(new_pay) > parseFloat(remain)) || 
		(parseFloat(new_pay) > parseFloat(balance)))
		{
			// set to zero and exit
			document.getElementById('remit_pay_old_' + id).value = "0.00";
			document.getElementById('remit_pay_' + id).value = "0.00";
			return;
		}
		
		new_pay = parseFloat(new_pay).toFixed(2);

		document.getElementById('remit_pay_' + id).value = new_pay;
		document.getElementById('remit_pay_old_' + id).value = new_pay;

		// and re-adjust apply... 
		var apply = parseFloat(document.getElementById('remit_apply').value) + parseFloat(new_pay);		
		apply = parseFloat(apply).toFixed(2);
		document.getElementById('remit_apply').value = apply;

		// ...and remain
		var remain = parseFloat(document.getElementById('remit_remain').value) - parseFloat(new_pay);		
		remain = parseFloat(remain).toFixed(2);
		document.getElementById('remit_remain').value = remain;
	}
	if (mode == 'payment_click')
	{
		// add current amount back to remain
		var remain = parseFloat(document.getElementById('remit_remain').value) + parseFloat(document.getElementById('remit_pay_' + id).value);
		remain = parseFloat(remain).toFixed(2);
		document.getElementById('remit_remain').value = remain;

		// remove amount from apply
		var apply = parseFloat(document.getElementById('remit_apply').value) - parseFloat(document.getElementById('remit_pay_' + id).value);
		apply = parseFloat(apply).toFixed(2);
		document.getElementById('remit_apply').value = apply; 

		// apply the balance due or the remain, whichever is less, 
		var balance = document.getElementById('remit_bal_' + id).value
		if (parseFloat(remain) < parseFloat(balance))
		{
			var new_pay = parseFloat(remain).toFixed(2);
		}
		else
		{
			var new_pay = parseFloat(balance).toFixed(2);
		}
		
		document.getElementById('remit_pay_' + id).value = new_pay;
		document.getElementById('remit_pay_old_' + id).value = new_pay;

		// and re-adjust apply... 
		var apply = parseFloat(document.getElementById('remit_apply').value) + parseFloat(new_pay);		
		apply = parseFloat(apply).toFixed(2);
		document.getElementById('remit_apply').value = apply;

		// ...and remain
		var remain = parseFloat(document.getElementById('remit_remain').value) - parseFloat(new_pay);		
		remain = parseFloat(remain).toFixed(2);
		document.getElementById('remit_remain').value = remain;
	}
}

function remit_detail_validate()
{
	if (!isEmpty('remit_ref', 'Please enter a \'Reference\''))
		return false;

	if (!isEmpty('remit_date', 'Please enter a \'Date\''))
		return false;

	// All Good.
	return true;
}

function remit_detail_highlight()
{
	if (document.getElementById('remit_ref').value == '')
		index_bg_color('remit_ref','#99FF99');
	else
		index_bg_color('remit_ref','#FFFFFF');	
}

function remit_detail_format(x_id)
{
	index_conv_dec('remit_amount','2');
	index_conv_dec('remit_apply','2');
	index_conv_dec('remit_remain','2');
}

function remit_detail_onload(id)
{
	if ((id == 'insert')  || (id == 'edit') || (id == 'view'))
	{
		ajax_showpopup('div_popup_1','div_result');

		Calendar.setup({
			inputField     	:    "remit_date",
			ifFormat       	:    "%d-%m-%Y",
			button         	:    "remit_date_link",
			align          	:    "BR",
			singleClick    	:    true
		});
	}
	remit_detail_highlight();
	remit_detail_format();
}

-->
