
///////////////////////////////////////////////////////////////////////////////////////////////////
// SELECTS/TOGGLES A SERVICE (FROM CLIENT INVOICES) ///////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

function selectClientService(idService, mode) {

	// MODE = BULK ////////////////////////////////////////////////////////////////////////////////
	if (mode=='bulk') {

		// SERVICE IS ALREADY SELECTED - UNCHECK IT -----------------------------------------------
		if ( $('serviceTr_'+idService).hasClassName('selectedRow') ) {

			// update row class
			$('serviceTr_'+idService).removeClassName('selectedRow');

			// switch buttons
			$('checkServiceButton_'+idService).show();
			$('uncheckServiceButton_'+idService).hide();
		}
		// SERVICE IS NOT SELECTED - CHECK IT -----------------------------------------------------
		else {

			// update row class
			$('serviceTr_'+idService).addClassName('selectedRow');

			// switch buttons
			$('checkServiceButton_'+idService).hide();
			$('uncheckServiceButton_'+idService).show();
		}

		// remotely add/remove this row
		ajaxIframeReload('balanceManagementDiv', 'balanceManagement.php?idService='+idService);

	}

	// MODE = SIMPLE //////////////////////////////////////////////////////////////////////////////
	else {

		// CHECK NEW ROW --------------------------------------------------------------------------
		if (idService && idService!='0' && idService!=selectedClientService) {

			// highlight new row
			$('serviceTr_'+idService).addClassName('selectedRow');

			// hide the check button and display the uncheck button
			$('checkServiceButton_'+idService).hide();
			$('uncheckServiceButton_'+idService).show();

		}

		// UNCHECK OLD ROW ------------------------------------------------------------------------
		if ( selectedClientService && selectedClientService!='0' && $('serviceTr_'+selectedClientService) ) {

			// remove row highlight
			$('serviceTr_'+selectedClientService).removeClassName('selectedRow');

			// hide the uncheck button and display the check button
			$('uncheckServiceButton_'+selectedClientService).hide();
			$('checkServiceButton_'+selectedClientService).show();

		}

		// SET SELECTED SERVICE
		if (idService==selectedClientService) selectedClientService=0;
		else selectedClientService=idService;

		// ajax reload
		ajaxIframeReload('balanceManagementDiv', 'balanceManagement.php?idService='+idService);

	}

}

///////////////////////////////////////////////////////////////////////////////////////////////////
// SELECTS/TOGGLES AN INVOICE ROWS (FROM SUPPLIER INVOICES) ///////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
function selectSupplierRow(idRow) {

	// ROW IS ALREADY SELECTED - UNCHECK IT ///////////////////////////////////////////////////////
	if ( $('rowTr_'+idRow).hasClassName('selectedRow') ) {

		// update row class
		$('rowTr_'+idRow).removeClassName('selectedRow');

		// switch buttons
		$('checkRowButton_'+idRow).show();
		$('uncheckRowButton_'+idRow).hide();
	}
	// ROW IS NOT SELECTED - CHECK IT /////////////////////////////////////////////////////////////
	else {

		// update row class
		$('rowTr_'+idRow).addClassName('selectedRow');

		// switch buttons
		$('checkRowButton_'+idRow).hide();
		$('uncheckRowButton_'+idRow).show();
	}

	// remotely add/remove this row
	ajaxIframeReload('balanceManagementDiv', 'balanceManagement.php?idSupplierRow='+idRow);

}

///////////////////////////////////////////////////////////////////////////////////////////////////
// DESTROYS THE CURRENT BALANCE ///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
function destroyBalance(mode) {

	if (mode=='services')
		ajaxIframeReload('clientServicesListDiv', 'clientServicesList.php?destroyBalance');
	else
		ajaxIframeReload('clientInvoicesListDiv', 'clientInvoicesList.php?destroyBalance');

	ajaxIframeReload('supplierInvoicesListDiv', 'supplierInvoicesList.php?destroyBalance');

	ajaxIframeReload('balanceManagementDiv', 'balanceManagement.php?destroyBalance');

}


///////////////////////////////////////////////////////////////////////////////////////////////////
// CREATE THE CURRENT BALANCE /////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
function createBalance() {
	new Popup('./../balanceCreate/?parent=balanceManual&src=ses', 800, 450, 'createManualBalance');
}

