var lastclicked = null;
var lastCellIndex = 0;

var ie= (document.all);
if (!ie) {
	var nn=1;
}

//var nn= (document.layers);

//alert (ie,nn);

function clickedhis(j) {
if (ie) {
	lastclicked=j;
	document.all.recid.value = j.recid;
	}
if (nn) {
	lastclicked=j;
	document.sentaiform.recid.value = j.recid;
	}
};

//This function will select the whole row when clicking on a cell in the table
//and will set the hidden field 'recid' = the recid for the row
function clicked(j) { 
if (ie) {
	if (lastclicked != null && (lastclicked != j || (window.event != null &&
	document.all.lookuptable.contains(window.event.srcElement)))) {
	for (i = 0; i < lastclicked.cells.length; i++)
  		lastclicked.cells(i).className = 'inactiveelement'; 
  	} // if
	if (window.event != null && document.all.lookuptable.contains(window.event.srcElement)) {
	lastCellIndex = window.event.srcElement.cellIndex;
	}
	for (i = 0; i < j.cells.length; i++)
	if (j.cells(i).cellIndex == lastCellIndex)
	j.cells(i).className = 'focuselement';
  	else 
	j.cells(i).className = 'activeelement';
	lastclicked=j;
	document.all.recid.value = j.recid;
	}
if (nn) {

	}
};

//This is run when you click on a column header, it orders the table by the columns values
function sortby() { 
if (ie) {
	var tablerows = document.all.lookuptable.rows;
	Index = window.event.srcElement.cellIndex;
	for (i = 1; i <tablerows .length - 1; i++)
	for (j = i + 1; j <tablerows .length; j++) {
	if (tablerows(i).cells(Index).innerText.toLowerCase() >
	tablerows(j).cells(Index).innerText.toLowerCase())
	tablerows(i).swapNode(tablerows(j));
		}
	}
if (nn) {

	}
};
	
	var focusElement = null;

	function dofocus(setup) {
		if (ie) {	
		if (setup == null) setup = false;
		if (focusElement != null && focusElement != window.event.srcElement)
		focusElement.className = 'inactiveelement';
		focusElement = window.event.srcElement;
		focusElement.className = 'focuselement';
		}
if (nn) {
	
	}
};

//this is run when you click on one of the buttons at the bottom of the screen
//it will post the form
function dotlbarclk(anAction) {
if (ie) {
	document.all.sentaiform.action.value = anAction;
	document.all.sentaiform.submit();
	}
if (nn) {
	document.sentaiform.action.value = anAction;
	document.sentaiform.submit();
	}
};

//this is run when you click on something in the blue area on the left and top
//then runs the above function to post the form
function dotlnewclk(newFunction, anAction) {
if (ie) {
	document.all.sentaiform.functiontorun.value = newFunction;
	dotlbarclk(anAction);
	}
if (nn) {
	document.sentaiform.webfunctionid.value = newFunction;
	dotlbarclk(anAction);
	}
};

//This is run when you click on the buy button in the product list screen.
//It ensures the correct values for quantity and unit are submitted along with a buy request.
function dobuyclk(anAction, theRec, myRow) {
if (ie) {
//	alert(document.sentaiform.eval('myqty'+myRow).value);
//	var myindex=(document.all.lookuptable.rows(parseInt(myRow)).cells(2).all.eval('myunit'+myRow).selectedIndex);
//	document.all.unit.value = document.all.lookuptable.rows(parseInt(myRow)).cells(2).all.eval('myunit'+myRow).options[myindex].text;
//	document.all.qty.value = document.all.lookuptable.rows(parseInt(myRow)).cells(3).all.eval('myqty'+myRow).value;
//	var myindex = eval("document.all.myunit"+myRow+".selectedIndex");
//	document.all.unit.value = eval("document.all.myunit"+myRow+".options[myindex].text");
//	document.sentaiform.unit.value = "ea"
	document.sentaiform.qty.value = eval("document.all.myqty"+myRow+".value");
	document.sentaiform.recid.value = theRec;
	document.sentaiform.action.value = anAction;
	document.all.sentaiform.submit();
	}
if (nn) {
//	var myindex=(document.sentaiform.eval('myunit'+myRow).selectedIndex);
//	document.sentaiform.unit.value = document.sentaiform.eval('myunit'+myRow).options[myindex].text;
	document.sentaiform.qty.value = document.sentaiform.eval('myqty'+myRow).value;
	document.sentaiform.recid.value = theRec;
	document.sentaiform.action.value = anAction;
	document.sentaiform.submit();
	}
};

//This is run when a form needs to be submitted with the rec id.
//It can be sent as an argument with this function.
function clickwithrec(anAction, theRec) {
if (ie) {
	document.all.sentaiform.recid.value = theRec;
	document.all.sentaiform.action.value = anAction;
	document.all.sentaiform.submit();
	}
if (nn) {
	document.sentaiform.recid.value = theRec;
	document.sentaiform.action.value = anAction;
	document.sentaiform.submit();
	}
};
function dosearch() {
if (ie) {
	document.all.sentaiform.search.value=document.all.mysearch.value;
	document.all.sentaiform.submit();
   	}
if (nn) {
	document.sentaiform.search.value=document.all.mysearch.value;
	document.sentaiform.submit();
	}
};
var focusElement = null;
function dofocus(setup) {
if (ie) {
	if (setup == null) setup = false;
	if (focusElement != null && focusElement != window.event.srcElement)
	focusElement.className = 'inactiveelement';
	focusElement = window.event.srcElement;
	focusElement.className = 'focuselement';
	}
if (nn) {

	}
};


//This piece of script is used to add a default action to the RETURN key-->
nextfield = "done"; // name of first box on page
netscape = "";
ver = navigator.appVersion; len = ver.length;
for(iln = 0; iln < len; iln++) if (ver.charAt(iln) == "(") break;
netscape = (ver.charAt(iln+1).toUpperCase() != "C");

function keyDown(DnEvents) {
	// determines whether Netscape or Internet Explorer
	k = (netscape) ? DnEvents.which : window.event.keyCode;
	if (k == 13) { // enter key pressed
		if (document.sentaiform.functionid.value != "x"){
		dotlbarclk(document.sentaiform.functionid.value);
		}
		if (nextfield == 'done') return true; // submit, we finished all fields
	else { // we're not done yet, send focus to next box
		eval('document.yourform.' + nextfield + '.focus()');
		return false;
		}
	}
}

	document.onkeydown = keyDown;
	if (netscape) document.captureEvents(Event.KEYDOWN|Event.KEYUP);

