<!--
var checks_first_time = true;
var expense_first_time = true;

var counter = -1;
function moreFields()
{
		counter++;

		var newFields = document.getElementById('readroot').cloneNode(true);
		newFields.id  = counter;
		newFields.style.display = 'block';
		var newField = newFields.childNodes;
		for (var i=0; i<newField.length; i++)
		{
			var field_id = newField[i].id + counter;
			//var field_name = newField[i].name + '[' + counter + ']';
			/*if (newField[i].type == 'text')*/
			if (field_id && newField[i].type != 'button')
			{
				newField[i].id = field_id;
				//newField[i].name = field_name;
			}
		}
		var insertHere = document.getElementById('writeroot');
		var invoice_type = document.getElementById('invoice_type').value;
		
		// for regular invoices the items are added to the bottom of the list
		// POS invoices the items are added to the top
		if (invoice_type == 'touchPOS_invoice' || invoice_type == 'POS_invoice' || invoice_type == 'purchase_order')
			insertHere.parentNode.insertBefore(newFields, insertHere.nextSibling);
		else
			insertHere.parentNode.insertBefore(newFields, insertHere);
		
		return counter;
}

function removeRow(oCell, POS)
{
	if (!POS)
	{
		// get the sub_total and the Row that is been removed's total
		var sub_total = document.getElementById('sub_total').value;
		var sub_tax = document.getElementById('sub_tax').value;
		
		var item_total = document.getElementById('t_' + oCell.parentNode.id).value;
			item_total = item_total.replace("$",""); // take out the money sign
		var item_tax = document.getElementById('m_' + oCell.parentNode.id).value;
			item_tax = item_tax.replace("$",""); // take out the money sign
		
		// Subtract the row's total from the sub total
		sub_total = parseFloat(sub_total) - parseFloat(item_total);
		sub_tax = parseFloat(sub_tax) - parseFloat(item_tax);
		
		// Check if the math was done right
		if (parseFloat(sub_total)) {
			document.getElementById('sub_total').value = CurrencyFormatted(sub_total);
			document.getElementById('sub_tax').value = CurrencyFormatted(sub_tax);
		} else {
			document.getElementById('sub_total').value = '0.00';
			document.getElementById('sub_tax').value = '0.00';
		}
		
	} else {
		var item_total = document.getElementById('t_' + oCell.parentNode.id).value;
		var item_tax = document.getElementById('ta_' + oCell.parentNode.id).value;
		var sub_total = document.getElementById('sub_total').value;
		var sub_tax = document.getElementById('sub_tax').value;

		sub_total = parseFloat(sub_total) - parseFloat(item_total);
		sub_tax = parseFloat(sub_tax) - parseFloat(item_tax);
		
		// fix the totals displayed to the user
		document.getElementById('sub_total').value = CurrencyFormatted(sub_total);
		document.getElementById('sub_tax').value = CurrencyFormatted(sub_tax);
		
		// if this is a wic item, fix the wic totals aswell
		if ( document.getElementById('wic_' + oCell.parentNode.id).value == 1 )
		{
			var wic_total = document.getElementById('wic_total').value;
			wic_total = parseFloat(wic_total) - parseFloat(item_total);
			
			document.getElementById('wic_total').value = CurrencyFormatted(wic_total);
			
			// if the wic sales are 0 then hide the display
			/*if (wic_total <= 0)
				document.getElementById('pos_wic_sales').style.display = 'none';*/
		}
		
		// if this is an ebt item, fix the ebt totals aswell
		if ( document.getElementById('ebt_' + oCell.parentNode.id).value == 1 )
		{
			var ebt_total = document.getElementById('ebt_total').value;
			ebt_total = parseFloat(ebt_total) - parseFloat(item_total);
			
			document.getElementById('ebt_total').value = CurrencyFormatted(ebt_total);
			
			// if the wic sales are 0 then hide the display
			/*if (ebt_total <= 0)
				document.getElementById('pos_ebt_sales').style.display = 'none';*/
		}

	}
	
	// Get rid of the Row
	oCell.parentNode.parentNode.removeChild(oCell.parentNode);
	
	// recalculate the due amount
	if (!POS)
		check_due();
	else
		check_due(true);

}

function total(id_num)
{
	var QTY = document.getElementById('q_' + id_num).value;
	var COST = document.getElementById('c_' + id_num).value;
		COST = COST.replace(",","");
	var TAX = document.getElementById('x_' + id_num).value;
		TAX = eval(TAX / 100);
	
	// vars to update the Sub Total
	var item_total = document.getElementById('t_' + id_num).value;
		item_total = item_total.replace("$",""); // take out the money sign
	var item_tax = document.getElementById('m_' + id_num).value;
		item_tax = item_tax.replace("$",""); // take out the money sign
	
	var sub_total = document.getElementById('sub_total').value;
	var sub_tax = document.getElementById('sub_tax').value;
	
	// error handeling var
	var result = true;
	
	// reset the value of subtotal and subtax
	sub_total = parseFloat(sub_total) - parseFloat(item_total);
	sub_tax = parseFloat(sub_tax) - parseFloat(item_tax);
	
	// Check if QTY is emty or if its a number
	if ( (QTY == '') || (!parseFloat(QTY)) )
	{
		result = false;
		document.getElementById('q_' + id_num).value = '';
	}
	
	// Check if COST is emty or if its a number
	if ( (COST == '') || (!parseFloat(COST)) )
	{
		result = false;
		document.getElementById('c_' + id_num).value = '';
	}
	
	// Check if TAX is emty or if its a number
	if ((TAX == '') || (!parseFloat(TAX)) )
	{
		TAX = 0;
		document.getElementById('x_' + id_num).value = '';
	}
	
	if (result)
	{
		var TOTAL 		= (QTY * COST);
		var TOTAL_TAX 	= TOTAL*TAX;
			TOTAL 		+= TOTAL_TAX;
		// Check if the Math returned a number
		if (parseFloat(TOTAL) && TOTAL != 0)
		{
		  document.getElementById('t_' + id_num).value = CurrencyFormatted(TOTAL);
		  document.getElementById('m_' + id_num).value = CurrencyFormatted(TOTAL_TAX);
		  document.getElementById('sub_total').value = CurrencyFormatted( parseFloat(sub_total) + parseFloat(TOTAL) );
		  document.getElementById('sub_tax').value = CurrencyFormatted( parseFloat(sub_tax) + parseFloat(TOTAL_TAX) );
		}
		else
		{
		  document.getElementById('t_' + id_num).value = '0.00';
		  document.getElementById('c_' + id_num).value = '0.00';
		  document.getElementById('m_' + id_num).value = '0.00';
		  document.getElementById('sub_total').value = CurrencyFormatted(sub_total);
		  document.getElementById('sub_tax').value = CurrencyFormatted(sub_tax);
		}
		  
	// Error Handleing VAR returned false
	} else {
		document.getElementById('t_' + id_num).value = '0.00';
		document.getElementById('c_' + id_num).value = '0.00';
		document.getElementById('m_' + id_num).value = '0.00';
		document.getElementById('sub_total').value = CurrencyFormatted(sub_total);
		document.getElementById('sub_tax').value = CurrencyFormatted(sub_tax);
	}
	
	// mark the invoice as been changed
	made_changes = true;
	
	// change the due amount
	check_due();
} // total

function check_due(POS, updatePoleFinal)
{
	var TOTAL = document.getElementById('sub_total').value;
	var TENDERED = document.getElementById('paid').value;
	var DUE;
	
	if (POS == true)
	{
		var discount_percent = document.getElementById('other_3').value;
		var discount_amount = document.getElementById('other_2').value;
		
		if (discount_amount != '')
			TOTAL -= discount_amount;
		else if (discount_percent != '')
			TOTAL = TOTAL - (TOTAL*(discount_percent/100));
	}
	
	DUE = TOTAL - TENDERED;
	
	if ( document.getElementById('invoice_type').value == 'touchPOS_invoice' )
	{
		if (DUE >= 0)
		{
			document.getElementById('pos_change_due').style.display = 'none';
			document.getElementById('due').value = '0.00';
		}
		else
		{
			document.getElementById('pos_change_due').style.display = '';
			document.getElementById('due').value = CurrencyFormatted(DUE * -1);
			
			// hide the wic/ebt sale, because a change needs to be display, which means wic/ebt was paid
			document.getElementById('pos_wic_sales').style.display = 'none';
			document.getElementById('pos_ebt_sales').style.display = 'none';
		}
		
		// print the subtotal on the pole
		//if (updatePoleFinal)
			//updatePole(true);
		//else
			//updatePole(false);
	} else
		document.getElementById('due').value = CurrencyFormatted(DUE);
		
	// change the total incase there is a discount : TODO
	//document.getElementById('sub_total').value = CurrencyFormatted(TOTAL);
}

function CurrencyFormatted(amount)
{
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}
// end of function CurrencyFormatted()

function gain_focus(ref_id)
{

	if ( isNaN(ref_id.parentNode.nextSibling.getAttribute("id")) ) {
		document.getElementById('q_' + moreFields()).focus();
	} else {
		var current_id = ref_id.parentNode.id;
		current_id++;
		while( !document.getElementById('q_' + current_id) )
		{
			current_id++;
		}
		document.getElementById('q_' + current_id).focus()
	}
}

function copy_address(from, to) {
	document.getElementById(to + '_name').value = document.getElementById(from + '_name').value;
	document.getElementById(to + '_address').value = document.getElementById(from + '_address').value;
	document.getElementById(to + '_city').value = document.getElementById(from + '_city').value;
	document.getElementById(to + '_state').value = document.getElementById(from + '_state').value;
	document.getElementById(to + '_zip').value = document.getElementById(from + '_zip').value;
	document.getElementById(to + '_id').value = document.getElementById(from + '_id').value;
	document.getElementById(to + '_area').value = document.getElementById(from + '_area').value;
	document.getElementById(to + '_phone1').value = document.getElementById(from + '_phone1').value;
	document.getElementById(to + '_phone2').value = document.getElementById(from + '_phone2').value;
}


function changedProd(id) {
	document.getElementById('product_id_' + id).value = '0';
	made_changes=true;
}
function changedAddress(which) {
	document.getElementById(which + '_id').value = '0';
	made_changes=true;
	
	if (which == 'pos' && document.getElementById('invoice_type').value == 'touchPOS_invoice')
		document.getElementById('customer_address').value = '';
}

function ship_lines(cell) {
	var newLines = cell.value.split("\n");
	var rows = newLines.length;
	
	if (rows >= 3)
		cell.value = newLines[0] + "\n" + newLines[1];
		//alert('this');
}

function noteResize( cell ) {
	var MIN_ROWS = 3;
	var txtLength = cell.value.length;
	var numRows = 0 ;
	
	//Split the textarea value at each linebreak.
	var arrNewLines = cell.value.split("\n");
	
	// check how many rows ther based on the \n
	for(var i=0; i<=arrNewLines.length; i++){
		numRows++;
	} 
	
	// do the resize
	if (numRows > MIN_ROWS) {
		cell.rows = numRows;
	} else {
		cell.rows = MIN_ROWS;
	}
}

// a script that puuses the script for the specified milli seconds
function pauseScript(Amount)
{
	d = new Date(); // Time when the function started
	
	// this routine will continue unless its manually stop it
	while (1) {
		mill = new Date();	// Date Now
		diff = mill-d;		// difference between time now and time the function was called
		if( diff > Amount ) { break; } // if the difference is larger than what we suggested, break out the while
	}
}

// this function hides all the non needed divs (ie: messages, loading... )
function hideAll() {
	document.getElementById('loading').style.display = 'none';
	//document.getElementById('messages').style.display = 'none';
	return true;
}

function printPage() {
	if (document.getElementById('readonly').value)
	{
		//if (document.getElementyById('invoice_type').value == 'invoice_type')
		// its read-only so just print
		hideAll();
		window.print();
	}
	else
	{
		// its not read only ask to save
		if( saveInvoice(true) ) 
		{
			hideAll();
			window.print();
		}
	}
}

function printReceipt(id, type, reprint)
{
	if (!id)
		return false;
		
	if (reprint)
		reprint = 1;
	else
		reprint = 0;
		
	if (type == null || type == '' || !type)
		type = print_type;
		
	try {
		var invoice_type = document.getElementById('invoice_type').value;
	} catch (err) {
		var invoice_type = 'POS_invoice';
	}

	if (invoice_type == 'touchPOS_invoice')
	{
		
		parent.bottomFrame.document.location = 'printReceipt.php?reprint='+ reprint +'&id='+id;
//		pausecomp(1000); // allow the receipt to load
		parent.window.setTimeout("window.bottomFrame.focus(); window.bottomFrame.print();", 1000); //bottomFrame.window.setTimeout("print()", 1000);
		
		/*if (open_after_save)
		{
			window.location = 'touchInvoice.php?open='+id;
		}
		else
			window.location = 'touchInvoice.php';*/
	}
	else
	{
		var iframe = document.getElementById('invoice_hiddenFrame');
		
		switch(type)
		{
			case 'receipt':
				iframe.src = 'printReceipt.php?reprint='+ reprint +'&id='+id;
				break;
			case 'invoice':
				iframe.src = 'printPosInvoice.php?id='+id;
				break;
		}
		
		window.setTimeout("printReceipt2("+id+")", 2000);
	}
}

// this function is used for POS printing after saving
function printReceipt2(id)
{
	window.frames['invoice_hiddenFrame'].focus();
	window.frames['invoice_hiddenFrame'].print();
}

function invoiceSearchFields()
{
	var cat = document.getElementById('category').value;
	var dropDown = document.getElementById('matching');
	
	var opt1 = "<option value='start'>"+ LANG_starts_with +"</option><option value='is'>"+ LANG_is +"</option><option value='contains'>"+ LANG_contains + "</option><option value='end'>"+ LANG_ends_with +"</option>";
	var opt2 = "<option value='on'>"+ LANG_on +"</option><option value='before'>"+ LANG_before +"</option><option value='after'>"+ LANG_after +"</option>";
	var opt3 = "<option value='equal'>"+ LANG_equal +"</option><option value='less'>"+ LANG_less_then +"</option><option value='more'>"+ LANG_more_then +"</option>";
			
	if (cat == 'id' || cat == 'ship' || cat == 'billed' || cat == 'furgon') {
		dropDown.innerHTML = opt1;
		document.getElementById('cal_click').style.display = 'none';
	} else if (cat == 'date' || cat == 'mod') {
		dropDown.innerHTML = opt2;
		document.getElementById('cal_click').style.display = '';
	} else if (cat == 'total' || cat == 'paid') {
		dropDown.innerHTML = opt3;
		document.getElementById('cal_click').style.display = 'none';
	}
}
	
function setLyr(obj,lyr)
{
	var newX = findPosX(obj);
	var newY = findPosY(obj);
	if (lyr == 'testP') newY -= 50;
	var x = new getObj(lyr);
	x.style.top = newY + 23 + 'px';
	x.style.left = newX + 'px';
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	var printstring = '';
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			printstring += ' element ' + obj.tagName + ' has ' + obj.offsetTop;
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;

	window.status = printstring;
	return curtop;
}


function getObj(name)
{
	if (document.getElementById)
	{
		this.obj = document.getElementById(name);
		this.style = document.getElementById(name).style;
	}
	else if (document.all)
	{
		this.obj = document.all[name];
		this.style = document.all[name].style;
	}
	else if (document.layers)
	{
		if (document.layers[name])
		{
			this.obj = document.layers[name];
			this.style = document.layers[name];
		}
		else
		{
			this.obj = document.layers.testP.layers[name];
			this.style = document.layers.testP.layers[name];
		}
	}
}
hide = true;
function hide_delay(id)
{
	window.setTimeout("show_hide('"+id+"', true)", 200);
}

function show_hide(id, justHide)
{
	if (justHide)
		hide = true;
	else
		hide = !hide;
		
	document.getElementById(id).style.display = (hide) ? 'none' : '';
}

function changePrintOption(type)
{
	if (type === 0)
	{
		document.getElementById('check_buttons_section').style.display = '';
		document.getElementById('schedule_options').style.display = 'none';
		
		document.getElementById('check_layout_top').disabled = true;
		document.getElementById('check_layout_center').disabled = true;
		document.getElementById('check_layout_bottom').disabled = true;
		document.getElementById('check_layout_top').className = 'check_type_button_disabled';
		document.getElementById('check_layout_center').className = 'check_type_button_disabled';
		document.getElementById('check_layout_bottom').className = 'check_type_button_disabled';
		
		document.getElementById('save_check').value = LANG_save_check;
		
		// make sure the right radio button is checked
		document.getElementById('print_type_ltr').checked = true;
	}
	else if (type === 1)
	{
		document.getElementById('check_buttons_section').style.display = '';
		document.getElementById('schedule_options').style.display = 'none';
		
		document.getElementById('check_layout_top').disabled = false;
		document.getElementById('check_layout_center').disabled = false;
		document.getElementById('check_layout_bottom').disabled = false;
		document.getElementById('check_layout_top').className = 'check_type_button';
		document.getElementById('check_layout_center').className = 'check_type_button';
		document.getElementById('check_layout_bottom').className = 'check_type_button';
		
		document.getElementById('check_layout_' + document.getElementById('check_layout').value ).className = 'check_type_button_selected';
		document.getElementById('save_check').value = LANG_print_check;
		
		// make sure the right radio button is checked
		document.getElementById('print_type_now').checked = true;
	}
	else if (type === 2)
	{
		document.getElementById('check_buttons_section').style.display = 'none';
		document.getElementById('schedule_options').style.display = '';
		
		// make sure the right radio button is checked
		document.getElementById('print_type_sch').checked = true;
	}
	
	document.getElementById('check_print_type').value = type;
}

function changeScheduleType(type)
{
	if (!type)
		return;
		
	switch (type)
	{
		case '1':
			document.getElementById('schedule_type_2').style.display = 'none';
			document.getElementById('schedule_type_3').style.display = 'none';
			document.getElementById('schedule_type_4').style.display = 'none';
			break;
		case '2':
			document.getElementById('schedule_type_2').style.display = '';
			document.getElementById('schedule_type_3').style.display = 'none';
			document.getElementById('schedule_type_4').style.display = 'none'
			break;
		case '3':
			document.getElementById('schedule_type_2').style.display = 'none';
			document.getElementById('schedule_type_3').style.display = '';
			document.getElementById('schedule_type_4').style.display = 'none'
			break
		case '4':
			document.getElementById('schedule_type_2').style.display = 'none';
			document.getElementById('schedule_type_3').style.display = '';
			document.getElementById('schedule_type_4').style.display = ''
			break;
	}
}

function changeLayout(layout, allCheck)
{
	if (allCheck)
	{
		document.getElementById('all_check_layout_top').className = 'check_type_button';
		document.getElementById('all_check_layout_center').className = 'check_type_button';
		document.getElementById('all_check_layout_bottom').className = 'check_type_button';
	
		document.getElementById('all_check_layout').value = layout;
		document.getElementById('all_check_layout_'+layout).className = 'check_type_button_selected';
	}
	else
	{
		document.getElementById('check_layout_top').className = 'check_type_button';
		document.getElementById('check_layout_center').className = 'check_type_button';
		document.getElementById('check_layout_bottom').className = 'check_type_button';
	
		document.getElementById('check_layout').value = layout;
		document.getElementById('check_layout_'+layout).className = 'check_type_button_selected';
	}
}

function changePaperType(type)
{
	if (type == 'single')
	{
		document.getElementById('paper_type_single').className = 'check_type_button_selected';
		document.getElementById('paper_type_copies').className = 'check_type_button';
		
		// disable the layout selector
		document.getElementById('all_check_layout_top').disabled = true;
		document.getElementById('all_check_layout_center').disabled = true;
		document.getElementById('all_check_layout_bottom').disabled = true;
		document.getElementById('all_check_layout_top').className = 'check_type_button_disabled';
		document.getElementById('all_check_layout_center').className = 'check_type_button_disabled';
		document.getElementById('all_check_layout_bottom').className = 'check_type_button_disabled';
	}
	else
	{
		document.getElementById('paper_type_single').className = 'check_type_button';
		document.getElementById('paper_type_copies').className = 'check_type_button_selected';
		
		// enable the layout selector
		document.getElementById('all_check_layout_top').disabled = false;
		document.getElementById('all_check_layout_center').disabled = false;
		document.getElementById('all_check_layout_bottom').disabled = false;
		document.getElementById('all_check_layout_top').className = 'check_type_button';
		document.getElementById('all_check_layout_center').className = 'check_type_button';
		document.getElementById('all_check_layout_bottom').className = 'check_type_button';
		
		document.getElementById('all_check_layout_' + document.getElementById('all_check_layout').value ).className = 'check_type_button_selected';
	}
	
	document.getElementById('paper_type').value = type;
}


function check_uncheck_all(guide, checkboxes)
{
	var checked = guide.checked;
	var currentView;
	
	if (document.getElementById('checks_holder').style.display == '')
		currentView = 'printed_checks_holder';
	else
		currentView = 'checks_holder';
	
	for (i = 0; i < checkboxes.length; i++)
	{
		if (checkboxes[i].parentNode.parentNode.parentNode.id == currentView)
			continue;
			
		checkboxes[i].checked = checked;
	}
	
	return true;
}

function check_account_manager()
{
	window.open("checks/account_manager.php", "check_popup", "width=735, height=525, status=0, toolbar=0, resizable=0");
}

function ex_hide_buttons(obj)
{
	for (var i=1; i<obj.childNodes.length; i++)
	{
		obj.childNodes[i].style.display = 'none';
	}
}

function ex_show_buttons(obj)
{
	for (var i=1; i<obj.childNodes.length; i++)
	{
		obj.childNodes[i].style.display = '';
	}
}

function pausecomp(millis)// www.sean.co.uk
{
	date = new Date();
	var curDate = null;
	
	do { var curDate = new Date(); }
	while(curDate-date < millis);
} 

function ShowPaymentWindow(id)
{
	var payment_window = window.open("payments.php?id="+id, "payment_popup", "width=780, height=420, status=0, toolbar=0, resizable=1, menubar=1");
	payment_window.focus();
}

function ShowCreditTerminal(voidNum, returnCredit, returnAmount)
{
	var amount;
	var ebt_amount;
	var type;
	var onInvoice = false;
	var localInstall = 0;
	
	if (CONF_localInstallation == true)
		localInstall = 1;
		
	// if a merchant ID does not exist then this function should not be showing a cc window
	// just highlight the button incase they user is using their own reader
	if (CONF_merchant_id == '')
		return true;
	
	// type of transaction
	if (voidNum)
	{
		if (!returnCredit)
			type = 'void';
		else
			type = 'credit';
	}
	else
	{
		type = 'sale';
		voidNum = '';
	}
		
	// check if we have an amount
	try {
		var invoice_type = document.getElementById('invoice_type').value;
		
		onInvoice = true;
	} catch (err) {
		onInvoice = false;
	}

	if (onInvoice)
	{
		if (invoice_type == 'touchPOS_invoice')
		{
			if (document.getElementById('amount_due').value == '0.00')
				amount = document.getElementById('sub_total').value;
			else
				amount = document.getElementById('amount_due').value;
	
			ebt_amount = document.getElementById('ebt_total').value;
			fromPOS = 1;
		}
		else
		{
			if (document.getElementById('due').value == '0')
				amount = document.getElementById('sub_total').value;
			else
				amount = document.getElementById('due').value;
			
			ebt_amount = '0.00';
			fromPOS = 2;
		}
	}
	else
	{
		if (!returnAmount)
			amount = '';
		else
			amount = returnAmount;
	}
		
	if (amount == '0.00')
		return false;

	if (CONF_merchant_type == 'securepay')
		var credit_window = window.open("https://ssl.perfora.net/accountingonline.us/invoice/ccTerminal/creditCardTerminal.php?MID="+ CONF_merchant_id +"&type="+ type +"&amount="+ amount +"&voidNum="+ voidNum, "creditCardTerminal_popup", "width=500, height=300, status=0, toolbar=0, resizable=1, menubar=0");
	else if (CONF_merchant_type == 'global')
	{
		//var credit_window = window.open("ccTerminal/creditCardTerminal2.php?POS=1&pinPadPort="+ CONF_pinpad_port +"&MID="+ CONF_merchant_id +"&amount="+ amount + "&ebtAmount="+ ebt_amount, "creditCardTerminal_popup", "width=500, height=360, status=0, toolbar=0, resizable=1, menubar=0");
		var credit_window = window.open("https://ssl.perfora.net/accountingonline.us/invoice/ccTerminal_test/creditCardTerminal2.php?debug=3&local="+ localInstall +"&POS="+ fromPOS +"&pinPadPort="+ CONF_pinpad_port +"&MID="+ CONF_merchant_id +"&amount="+ amount + "&ebtAmount="+ ebt_amount, "creditCardTerminal_popup", "width=500, height=360, status=0, toolbar=0, resizable=1, menubar=0");
	}
	//var credit_window = window.open("ccTerminal/creditCardTerminal2.php?POS=1&MID="+ CONF_merchant_id +"&type="+ type +"&amount="+ amount +"&voidNum="+ voidNum, "creditCardTerminal_popup", "width=500, height=360, status=0, toolbar=0, resizable=0, menubar=0");

	credit_window.focus();
	
	return true;
}


function showContactManager()
{
	var contactManager = window.open('contact_manager.php', 'customer_invoices', 'width=780, height=525, status=0, toolbar=0, resizable=0');
	contactManager.focus();
}

function showVendorManager()
{
	var vendorManager = window.open('vendor_manager.php', 'vendor_manager', 'width=780, height=525, status=0, toolbar=0, resizable=0');
	vendorManager.focus();
}

function showInventoryWindow()
{
	var inventory_window = window.open('inventory_management.php', 'inventory_manager', 'width=600, height=530, status=0, toolbar=0, resizable=0');
	inventory_window.focus();
}

function touchNewInvoice()
{
	save_promt();
	window.location = 'touchInvoice.php';
}

function viewTouchPOS()
{
	var touchPOS = window.open("touchInvoiceFrame.html", "touch_pos_popup", "status=0, toolbar=0, resizable=1, menubar=0, scrollbars=1");
	touchPOS.focus();
}

function openInvoice_touch(id)
{
	save_promt();
	window.location = 'touchInvoice.php?open='+id;
	window.focus();
}

function resetCounter(newCounter)
{
	counter = newCounter;
}


/* -------- manual cash register functions --------- */
function manualNum(num)
{
	var pointFilter=/\./;
	var hasPoint = false;
	var multiplying = false;
	var digits = document.getElementById('digitsEntered').value;
	var pointValue = document.getElementById('keypadLCD').value;
	
	if (digits == "" && (num == 0 || num == "00"/* || num == "."*/))
		return false;
	else
	{
		if (document.getElementById('r_xClicked').value == "yes")
			multiplying = true;
			
		if ( pointFilter.test(digits) )
			hasPoint = true;
		
		if (num == "." && hasPoint)
			return false;
		else {
			digits = digits + "" + num;
			
			if (!hasPoint && !multiplying)
				pointValue = digits / 100;
			else
				pointValue = digits;
		}
	}

	// save the values to the form
	document.getElementById('digitsEntered').value = digits;
	document.getElementById('keypadLCD').value = CurrencyFormatted(pointValue) /*pointValue*/;
	
	// play sound
	//soundManager.play('key-press');
	
	//document.getElementById('UPC_scanner').focus();
}

function enterSale(taxable, ebt)
{
	// to give the UPC code focus back
	//window.setTimeout("document.getElementById('UPC_scanner').focus()", 1000);
	
	// reset the name timer incase it has not yet been run
	clearTimeout(poleNameTimeout);
	
	if (document.getElementById('keypadLCD').value == "" && document.getElementById('r_cost').value == 0)
	{
		if (document.getElementById('lastID').value == '')
		{
			//document.getElementById('UPC_scanner').focus();
			return false;
		}
		else
		{
			field_id = document.getElementById('lastID').value;
			updateProdQTY(field_id, parseInt(document.getElementById('q_'+field_id).value) + 1);
			
			//document.getElementById('UPC_scanner').focus();
			return false;
		}
	}
	
	var field_id = moreFields();

	// check if the multiplication button has been clicked
	if (document.getElementById('r_xClicked').value == "no")
	{
		document.getElementById('q_'+field_id).value = 1;
		document.getElementById('c_'+field_id).value = document.getElementById('keypadLCD').value;
	}
	else
	{
		var qty_amount = 1;
		if (document.getElementById('keypadLCD').value != '')
			qty_amount = document.getElementById('keypadLCD').value;
			
		document.getElementById('q_'+field_id).value = qty_amount;
		document.getElementById('c_'+field_id).value = document.getElementById('r_cost').value;
	}
	
	// fill in the product information, if its taxable or not taxable
	if (taxable == true)
	{
		document.getElementById('p_'+field_id).value = 'Taxable Goods';
		document.getElementById('id_'+field_id).value = taxableId;
		document.getElementById('ta_'+field_id).value = CurrencyFormatted( document.getElementById('c_'+field_id).value * document.getElementById('q_'+field_id).value * (CONF_taxRate/100) );
		document.getElementById('tb_'+field_id).value = 1;
		document.getElementById('i_'+field_id).value = 1;
		
		//document.getElementById('sub_tax').value = CurrencyFormatted( parseFloat(document.getElementById('sub_tax').value) + taxamount );
		//document.getElementById('sub_total').value = CurrencyFormatted( parseFloat(document.getElementById('sub_total').value) + parseFloat(document.getElementById('t_'+field_id).value) );
	} else {
		document.getElementById('p_'+field_id).value = 'Non Taxable Goods';
		document.getElementById('id_'+field_id).value = nonTaxableId;
		document.getElementById('ta_'+field_id).value = '0.00';
		document.getElementById('tb_'+field_id).value = 0;
		document.getElementById('i_'+field_id).value = 0;
	}
	
	// fill in the EBT information
	if (ebt == true) {
		document.getElementById('ebt_'+field_id).value = 1;
		
		document.getElementById('ebt_total').value = CurrencyFormatted( parseFloat(document.getElementById('ebt_total').value) + parseFloat(document.getElementById('c_'+field_id).value) );
	
		if (document.getElementById('sale_highlight').value == 'ebt')
			document.getElementById('ebt_'+field_id).parentNode.style.backgroundColor = '#99FFFF';
	}

	// display the totals and the sub total
	document.getElementById('t_'+field_id).value = CurrencyFormatted( document.getElementById('c_'+field_id).value * document.getElementById('q_'+field_id).value );
	document.getElementById('sub_total').value = CurrencyFormatted( parseFloat(document.getElementById('sub_total').value) + parseFloat(document.getElementById('t_'+field_id).value) );
	document.getElementById('sub_tax').value = CurrencyFormatted( parseFloat(document.getElementById('sub_tax').value) + parseFloat(document.getElementById('ta_'+field_id).value) );

	// reset the calculator
	document.getElementById('r_cost').value = '0';
	document.getElementById('r_xClicked').value = 'no';
	document.getElementById('digitsEntered').value = '';
	document.getElementById('keypadLCD').value = '';
	document.getElementById('lastID').value = field_id;
	
	//check_due(true);
	//soundManager.play('key-press');
	updateProdQTY(field_id, document.getElementById('q_'+field_id).value);
	
	// update the pole
	updatePole('item', document.getElementById('t_' + field_id).value, document.getElementById('sub_total').value);

	document.getElementById('UPC_scanner').value = '';
}

function multiSale()
{
	if (document.getElementById('keypadLCD').value == '')
	{
		//document.getElementById('UPC_scanner').focus();
		return true;
	}

	document.getElementById('r_xClicked').value = 'yes';
	document.getElementById('r_cost').value = document.getElementById('keypadLCD').value;
	document.getElementById('digitsEntered').value = '';
	document.getElementById('keypadLCD').value = '';

	//soundManager.play('key-press');
	//document.getElementById('UPC_scanner').focus();
}

function cancelSale()
{
	if (document.getElementById('invoice_type').value != 'touchPOS_invoice')
		return false;

	document.getElementById('r_cost').value = '0';
	document.getElementById('r_xClicked').value = 'no';
	document.getElementById('digitsEntered').value = '';
	document.getElementById('keypadLCD').value = '';
	
	//soundManager.play('key-press');
	//document.getElementById('UPC_scanner').focus();
}

function keypadPay(amount, printAfterSave)
{

	// if the content of the invoice is empty, dont do anything
	if ( isNaN(document.getElementById('writeroot').nextSibling.id) )
		return false;
	
	// if the printAfterSave variable is not been passed in, check the cc transaction print field
	if (!printAfterSave && print_after_save)
		printAfterSave = true;
		
	// if an amount is entered (buttom buttons) then add these insted of the LCD amount
	if (amount)
	{
		// if there is something already in payments then add these payments
		if ( parseFloat(document.getElementById('paid').value) != 0 )
		{
			var new_amount = parseFloat(document.getElementById('paid').value) + amount;
			document.getElementById('paid').value = CurrencyFormatted(new_amount);
		}
		else
		{
			document.getElementById('paid').value = CurrencyFormatted(amount);
		}
	}
	else
	{
		// check if there is something in the LCD display and add that
		if (document.getElementById('keypadLCD').value != "")
		{
			// if there is something already in payments then add these payments
			if ( parseFloat(document.getElementById('paid').value) != 0 )
			{
				var new_amount = parseFloat(document.getElementById('paid').value) + parseFloat(document.getElementById('keypadLCD').value);
				document.getElementById('paid').value = CurrencyFormatted(new_amount);
			}
			else
			{
				document.getElementById('paid').value = document.getElementById('keypadLCD').value;
			}
		}
		else if ( parseFloat(document.getElementById('paid').value) == 0 ) // nothing in the LCD display, so assume exact change is given
		{
			document.getElementById('paid').value = document.getElementById('sub_total').value;
		}
	}
	
	// reset the calculator
	document.getElementById('r_cost').value = '0';
	document.getElementById('r_xClicked').value = 'no';
	document.getElementById('digitsEntered').value = '';
	document.getElementById('keypadLCD').value = '';
	
	//document.getElementById('UPC_scanner').focus();
	//check_due(true);
	
	// if the payments is more than the total, then its ok to save and open the cash register
	if ( parseFloat(document.getElementById('paid').value) >= parseFloat(document.getElementById('sub_total').value) )
	{
		document.getElementById('amont_missing').style.display = 'none';
		
		//parent.bottomFrame.document.location='http://localhost/kick.php';
		//pauseScript(1000);
		//updatePole(true);
		//soundManager.play('register');
		check_due(true);

		if (printAfterSave || CONF_print_after_save == 1)
			saveInvoice(false, true); // do not open, but print after save
		else
			saveInvoice(false);
		
	}
	else // WE NEED MORE MONEY
	{
		document.getElementById('amount_due').value = CurrencyFormatted( document.getElementById('sub_total').value - document.getElementById('paid').value );
		document.getElementById('amont_missing').style.display = '';
	}
}

function noChargePayment()
{
	//document.getElementById('UPC_scanner').focus();
	
	// if the conten of the invoice is empty, dont do anything
	if ( isNaN(document.getElementById('writeroot').nextSibling.id) )
		return false;

	// if no user has been saved, then this could not be a no charge payment
	if ( document.getElementById('pos_id').value == '' || document.getElementById('pos_id').value == '0')
		return false;
	
	//soundManager.play('register');
	//parent.bottomFrame.document.location = 'http://localhost/kick.php';
	saveInvoice(false);
	
}

/*function updatePole(finalizeSale)
{
	
	if (document.getElementById('invoice_type').value != 'touchPOS_invoice')
		return false;
	
	if (!finalizeSale)
	{
		if ( isNaN(document.getElementById('writeroot').nextSibling.id) )
			return false;

		//var lastItemId = document.getElementById('invoice_content').lastChild.previousSibling.id;
		var lastItemId = document.getElementById('writeroot').nextSibling.id;
		var lastItem = CurrencyFormatted( document.getElementById('c_'+lastItemId).value );
	}
	else
	{
		var change = CurrencyFormatted( document.getElementById('due').value );
	}
	
	var total = CurrencyFormatted( document.getElementById('sub_total').value );
	
	if (finalizeSale)
		parent.bottomFrame.document.location = 'http://localhost/pole.php?mode=final&total=' + total + '&change=' + change;
	else
		parent.bottomFrame.document.location = 'http://localhost/pole.php?mode=item&total=' + total + '&item=' + lastItem;
}*/

// CONTACT MANAGER FUNCTIONS
function openContact(id, vendor)
{
	if (!id)
		return false;
	
	// just in case the info was not set correctly
	if (!vendor)
		vendor = false;
	else
		vendor = true;
	
	// open the vendor or the customer information
	if (vendor)
		parent.contact_manager_rightFrame.document.location = 'vendor_purchaseOrder.php?id=' + id;
	else
		parent.contact_manager_rightFrame.document.location = 'customer_invoices.php?id=' + id;
}
function deleteContact(id)
{
	var continueDelete = confirm(LANG_confirmDeleteContact);
	
	if (!continueDelete)
		return false;
	else
	{
		document.location = 'customer_invoices.php?action=delete&id='+id;
	}
	
}

function viewChecks(type)
{
	if (!type)
		return false;
		
	switch (type)
	{
		case 'toPrint':
			document.getElementById('check_num_display').style.display = '';
			document.getElementById('check_date_display').style.display = '';
			document.getElementById('check_field1').style.display = 'none';
			document.getElementById('check_field2').style.display = 'none';
			
			document.getElementById('printed_button').className = 'checksTypeTabDis';
			document.getElementById('toPrint_button').className = 'checksTypeTab';
			document.getElementById('scheduled_button').className = 'checksTypeTabDis';
			document.getElementById('toPrint_button').blur();
			
			document.getElementById('printed_checks_holder').style.display = 'none';
			document.getElementById('scheduled_checks_holder').style.display = 'none';
			document.getElementById('checks_holder').style.display = '';
			document.getElementById('allCheckBox').style.display = '';
			
		break;
		case 'printed':
			document.getElementById('check_num_display').style.display = '';
			document.getElementById('check_date_display').style.display = '';
			document.getElementById('check_field1').style.display = 'none';
			document.getElementById('check_field2').style.display = 'none';
			
			document.getElementById('printed_button').className = 'checksTypeTab';
			document.getElementById('toPrint_button').className = 'checksTypeTabDis';
			document.getElementById('scheduled_button').className = 'checksTypeTabDis';
			document.getElementById('printed_button').blur();
			
			document.getElementById('printed_checks_holder').style.display = '';
			document.getElementById('checks_holder').style.display = 'none';
			document.getElementById('scheduled_checks_holder').style.display = 'none';
			document.getElementById('allCheckBox').style.display = '';
		break;
		case 'scheduled':
			document.getElementById('check_num_display').style.display = 'none';
			document.getElementById('check_date_display').style.display = 'none';
			document.getElementById('check_field1').style.display = '';
			document.getElementById('check_field2').style.display = '';
			
			document.getElementById('printed_button').className = 'checksTypeTabDis';
			document.getElementById('toPrint_button').className = 'checksTypeTabDis';
			document.getElementById('scheduled_button').className = 'checksTypeTab';
			document.getElementById('scheduled_button').blur();
			
			document.getElementById('printed_checks_holder').style.display = 'none';
			document.getElementById('checks_holder').style.display = 'none';
			document.getElementById('scheduled_checks_holder').style.display = '';
			document.getElementById('allCheckBox').style.display = 'none';
		break;
	}
}

function selectScheduleMonthly(dayField, dayValue)
{
	if (!dayField)
		return false;
		
	// clear the previously selected one
	currentSelected = document.getElementById('selectedDay');
	
	if (currentSelected != null)
	{
		currentSelected.id = '';
		currentSelected.className = '';
	}
	
	// mark the new one as selected
	dayField.id = 'selectedDay';
	dayField.className = 'selected';
	
	document.getElementById('monthly_schedule').value = dayValue;
	
}

function switchConfigTab(visableTab)
{
	for (var i = 0; i < 4; i++)
	{
		if (visableTab == i)
		{
			document.getElementById('table' + i).style.display = '';
			document.getElementById('configTab' + i).className= 'checksTypeTab';
		}
		else
		{
			document.getElementById('table' + i).style.display = 'none';
			document.getElementById('configTab' + i).className = 'checksTypeTabDis';
		}
	}
	
	return false;
}

function toogleSales(type)
{
	if (!type)
		return false;

	var color = '';
	var hValue = '';
	var current_hValue = document.getElementById('sale_highlight').value;
	
	switch(type) {
		case 'wic':
		
			if (current_hValue == 'wic'){
				color = '';
				hValue = '';
			} else {
				color = '#FFFF99';
				hValue = 'wic';
			}
			
			break;
		case 'ebt':
		
			if (current_hValue == 'ebt'){
				color = '';
				hValue = '';
			} else {
				color = '#99FFFF';
				hValue = 'ebt';
			}
		
			break;
	}
	
	// set the highlighted type to the new one
	document.getElementById('sale_highlight').value = hValue;

	// show the appropriate totals
	if (hValue == 'ebt') {
		document.getElementById('pos_ebt_sales').style.display = '';
		document.getElementById('pos_wic_sales').style.display = 'none';
	} else if (hValue == 'wic') {
		document.getElementById('pos_ebt_sales').style.display = 'none';
		document.getElementById('pos_wic_sales').style.display = '';
	} else {
		document.getElementById('pos_ebt_sales').style.display = 'none';
		document.getElementById('pos_wic_sales').style.display = 'none';
	}
	
	// hide the Change field if its visible
	document.getElementById('pos_change_due').style.display = 'none';
	
	
	// if there are not rows, then no need to go own
	if ( isNaN(document.getElementById('writeroot').nextSibling.id) )
		return false;
		
	// there are some rows so go thru each one and highligh them to the right color
	var current_row = document.getElementById('writeroot').nextSibling;
	var last_row = document.getElementById('invoice_content').lastChild;
	
	while (true)
	{
		if (type == 'ebt' && document.getElementById('ebt_'+ current_row.id).value == 1)
			current_row.style.backgroundColor = color;
		else if (type == 'wic' && document.getElementById('wic_'+ current_row.id).value == 1)
			current_row.style.backgroundColor = color;
		else
			current_row.style.backgroundColor = '';
			
		// if we reached the last row, break out of the loop
		// otherwise set the current_row to the next row in the list
		if (current_row.id == last_row.id)
			break;
		else
			current_row = current_row.nextSibling;
	}
}

function finishTerminalPayment(type, amount, comment)
{
	// type and amoutn must be set
	if (!type || !amount || type == '' || amount == '')
		return false;

	if (!comment)
		comment = '';

	// check if a different type of payment was set
	var payment_holder = document.getElementById('payments');
	var prev_payments = payment_holder.value;
	
	// if there was a payment then add it to the list, if not then set the new one
	if (prev_payments == '')
		payment_holder.value = type +'|'+ amount +'|'+ comment;
	else
		payment_holder.value = prev_payments + '*' + type +'|'+ amount +'|'+ comment;

	// set the CreditPayment Flag to true
	// so that receipts are printed automaticly
	//document.getElementById('receiptNeeded').value = '1';
	//print_after_save = true;
	
	// submit it and print after save because this is a credit card transaction
	if (document.getElementById('invoice_type').value == 'touchPOS_invoice')
	{
		print_after_save = true;
		keypadPay(parseFloat(amount), true); // print after save
	}
	else
	{
		document.getElementById('paid').value = CurrencyFormatted(document.getElementById('paid').value + amount);
		saveInvoice(true, true, 'invoice'); // save and print
	}
}