
/*
 * Function to open new browser window
 */
function openWin(URL){
	aWindow = window.open(URL,'thewindow','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no,scrollbars=yes,width=750,height=500,left=200,top=150');
	if(window.focus) {
		setTimeout('aWindow.focus();',250);
	}
}

/*
 * This function postion the dropdown (select) box to the selected field
 */

function findSelected(thisform, thisfield, thisvalue) {

	// Determine Element in Form
	var elnum = parseInt(-1);
	for (var j=0; j<document.forms[thisform].elements.length; j++) {
		if (document.forms[thisform].elements[j].name == thisfield) {
			elnum = j;
			break;
 	  }
	}

	// Search for value if not null
	var myvar = "";
	menuLength = eval("document." + thisform + "." + thisfield + ".length");
	if (thisvalue != "") {
		for (var i = 0; i < menuLength; i++) {
			myvar = eval("document." + thisform + "." + thisfield + ".options[" + i + "].value.toUpperCase()");
			if (myvar.indexOf(thisvalue) >= 0) {
				document.forms[thisform].elements[elnum].options[i].selected = true;
				break;
	      }
	   }
	}
	return false;
}


function asEmail(emailName, userName) {

	
	var domain = "challenger.com"; 
	document.write('<a href=\"mailto:' + emailName + '@' + domain + '\">');
	document.write(userName + '</a>'); 

}


/*
 * main.jsp
 */

//Inventory Options
	//If Summary report is selected, disable serial/lot#, select ALL, clear text field
	function resetSum() {
		document.mainInvTrkProcess.invTrackType[2].checked = true;
		document.mainInvTrkProcess.invTrackType[1].disabled = true
		document.mainInvTrkProcess.invTrackValue.value="";
		document.mainInvTrkProcess.invTrackValue.focus();
	}

	//If Detail report selected, enable serial/lot# 	
	function resetDetail() {
		document.mainInvTrkProcess.invTrackType[1].disabled = false
		document.mainInvTrkProcess.invTrackValue.focus();
	}
	
	//If ALL radio button is selected, clear Part/Serial
	function resetSel() {
		document.mainInvTrkProcess.invTrackValue.value="";
		document.mainInvTrkProcess.invTrackValue.focus();
	}
	
	//Order Window, select Order text field
	function selOrd() {
		document.mainOrdTrkProcess.ordTrackValue.focus();
	}
	
	function posCursor() {
		document.mainInvTrkProcess.invTrackValue.focus();
	}	

	//I disable the Serial/Lot# radio button BUT it becomes reenabled when the user presses
	//the back button. I tried putting javascript in the html but it would not work. It seemed
	//to find only the default setting of the radio button when the code was run, then the browser
	//would set the field on the screen. Timing is everything!
	function errSerial() {
		for(var i = 0; i < document.mainInvTrkProcess.invRptType.length; i++) {
			if(document.mainInvTrkProcess.invRptType[i].checked == true) {
				someVar = document.mainInvTrkProcess.invRptType[i].value;
				break;
			}
		}
		
		if (someVar == "sum") {
			alert("Select by Serial/Lot# not available for Summary Report");
			resetSum();
		} 
		
		document.mainInvTrkProcess.invTrackValue.focus();
	}

	function posCursor2() {
		document.invhistory.invTrackValue.focus();
	}	


	//Don't allow user to click submit button twice else CRASH
	var bSubmitOverride = false;
	function validateSubmit() {
		if (bSubmitOverride) {
			return false;
		} else {
			bSubmitOverride = true;
			return true;
		}
	}
