/* Globals */
var barcodeitems = 1;


function preload() {
	
		var email = 'info';
		email += '@';
		email += 'elekdev';
		email += '.com';
		email = 'email: <a href="' + 'mai' + 'lto' + ':' + email + '">'+ email +'</a>';
		document.getElementById('email').innerHTML = email;

	
	barcode1 = new Image(160,120);
	barcode1.src = 'images/animation/inventory/barcode1.gif';
	barcode2 = new Image(160,120);
	barcode2.src = 'images/animation/inventory/barcode2.gif';
	
	document.onkeypress=KeyPress;
}

function barcode_on() {
	document.getElementById('barcodebox').src = barcode2.src;
}
function barcode_off() {
	document.getElementById('barcodebox').src = barcode1.src;
}
function barcode_click() {
	barcode_on();
	document.getElementById('barcodeentry').value = "Item " + barcodeitems;
	setTimeout("enter_click()",300);
}
function EvalSound(soundobj) {
	var thissound= eval("document."+soundobj);
	thissound.Play();
}
function enter_click() {
	closePrintOut();
	EvalSound('beep');
	var thebox = document.getElementById('barcodetextbox');
	var theentry = document.getElementById('barcodeentry');

	if(theentry.value != "") {
		thebox.value += theentry.value + "\n";
		barcodeitems += 1;
	}
	thebox.scrollTop = 9999;
	theentry.value = "";
	barcode_off();
}
function check_for_return(aEvent) {
//	var myEvent = aEvent ? aEvent : window.event;
// 	deal w/ FireFox later
	closePrintOut();
	
	var code = (window.event) ? event.keyCode : e.which;
	if(code==13) enter_click();
	return code;
}

function viewPrintOut() {
	closePrintOut();
	EvalSound('printer');
	
	var theinventory = document.getElementById('barcodetextbox').value;
	
	while( theinventory.indexOf('\n') > 1 )
		theinventory = theinventory.replace('\n' , '</li> <li>');
	theinventory = '<li> ' + theinventory + ' </li>';
	theinventory = theinventory.replace('<li> </li>' , ' ');
	
	document.getElementById('inventoryitems').innerHTML = theinventory;
	document.getElementById('numinventoryitems').innerHTML = barcodeitems - 1;
	document.getElementById('numinventoryitems').innerHTML += ' item';
	if( barcodeitems - 1 != 1 ) document.getElementById('numinventoryitems').innerHTML += 's';

	setTimeout("document.getElementById('result').style.visibility = 'visible'",1200);
}
function closePrintOut() {
	document.getElementById('result').style.visibility = "hidden";
}
