<!--

// called when submit button clicked
// go to checkit.htm based on the model number entered
function submit_modelnumber_onclick() {
	top.updating = false;
	top.addingfunctionality = false;
	window.location = "checkit.htm";
}

// if the user clicks on the model number text box, enable the submit button
function text_modelnumber_onclick() {
	document.form1.submit_modelnumber.disabled = 0;
}


function text_modelnumber_onchange() {

	// change user's input to upper case
	document.form1.text_modelnumber.value = document.form1.text_modelnumber.value.toUpperCase();

	var val = document.form1.text_modelnumber.value;

	if (top.verifymodelnum(val) == false) {
		// if they enter an invalid model number, reset it to what the combo boxes select
		document.form1.text_modelnumber.value = top.updatemodelnum();
		document.form1.submit_modelnumber.disabled = 1;
		return;
	} else {
		// otherwise, if it's valid, enable the submit button
		document.form1.submit_modelnumber.disabled = 0;
	}

	decodeout_checking(val);

	submit_modelnumber_onclick();
	top.updating = false;
	top.addingfunctionality = false;
	window.location = "checkit.htm";

	// only for netscape, this is the temporary fix to prevent having the parts list output
	// show one module part number but display the parts list for a former one
	if (navigator.appName == "Netscape") {
		var d;
		for (d=0 ; d<100000 ; d++) {
			// do nothing, delay for netscape's sake...
		}
	}
}

function decodeout_checking(input) {

	var east = false;
	var west = false; 
	var dual = false;
	if (input.charAt(2) == "D") dual = true;
	if (input.charAt(2) == "E") east = true;
	if (input.charAt(2) == "W") west = true;

	var five = input.charAt(5);
	var six  = input.charAt(6);
	
	if (five == "X" && six == "X") {
		top.usingxfordecodeout = true;
	} else {
		top.usingxfordecodeout = false;	// just to make sure

		if (five == "B" || six == "B") {
			if (dual == true && !(five == "B" && six == "B")) {
				alert("Invalid part number entered!  East/West modules require both an East and West Decode Output board, and they must be the same type of board.  The part number was changed to include Decode Out (CIC) boards.");
				five = six = "B";
			} else if (east == true && !(five == "B" && six == "X")) {
				alert("Invalid part number entered!  East only modules require only an East Decode Output board.  The part number was changed to include a East Decode Out (CIC) board.");
				five = "B";
				six = "X";
			} else if (west == true && !(five == "X" && six == "B")) {
				alert("Invalid part number entered!  West only modules require only an West Decode Output board.  The part number was changed to include a West Decode Out (CIC) board.");
				five = "X";
				six = "B";
			}
		} else if (five == "A" || six == "A") {
			if (dual == true && !(five == "A" && six == "A")) {
				alert("Invalid part number entered!  East/West modules require both an East and West Decode Output board, and they must be the same type of board.  The part number was changed to include Decode Out (Standard) boards.");
				five = six = "A";
			} else if (east == true && !(five == "A" && six == "X")) {
				alert("Invalid part number entered!  East only modules require only an East Decode Output board.  The part number was changed to include a East Decode Out (Standard) board.");
				five = "A";
				six = "X";
			} else if (west == true && !(five == "X" && six == "A")) {
				alert("Invalid part number entered!  West only modules require only an West Decode Output board.  The part number was changed to include a West Decode Out (Standard) board.");
				five = "X";
				six = "A";
			}
		}
	}

	var c;
	var tempmodelnum = "G";
	for (c=1 ; c<top.numchoices ; c++) {
		if (c==5) {
			tempmodelnum += five;
		} else if (c==6) {
			tempmodelnum += six;
		} else {
			tempmodelnum += input.charAt(c);
		}
	}

	top.mastermodelnum = tempmodelnum;
}

function button_help_onclick(j) {
	// pop-up dialog box with appropriate help message
	confirm(top.helpmessages[j]);
}

function on_pic_click() {
	// if user clicks on title picture, reset everything and return to main screen
	top.mastermodelnum = "GXXXXXXXXXXXXXX";
	var i;
	for (i=1 ; i<top.numchoices ; i++) {
		top.choices[i] = 0;
	}
	top.updating = false;
	top.addingfunctionality = false;
	top.usingxfordecodeout = false;
	window.location = "../genrakode.htm";
}

// taken from mandtbank.com -- enables Netscape Navigator 4.08 and IE 5.0, 5.5, and 6.0 to work

function KeySpy(event)
{
        var ch = event.keyCode
        if(ch == 13)
        {
		text_modelnumber_onchange();
		return false;
        }
        else return true;
}


// taken from 4guysfromrolla.com -- enables Netscape 7 to work

	var isNetscape = false;
	var isIE = false;
	var isWhoKnows = false;

	//This determines which browser the user is using
	if (parseInt(navigator.appVersion) >= 4) {
		if(navigator.appName == "Netscape") {
		  isNetscape = true;
		}else if (navigator.appName == "Microsoft Internet Explorer"){
		  isIE = true;
		}else {
		  isWhoKnows = true;
		}
	}

	//This stuff captures the events of the user
	if(isNetscape) {
		document.captureEvents(Event.KEYUP);
	}
	document.onkeyup = checkValue

	function checkValue(evt){
		var theButtonPressed;
		if (isNetscape) {
			//if(evt.target.type == "text"){ 
				//--> you can specify which type of element you want this to trigger for
			//if(evt.target.name == "myText"){
				//--> or you can specify the actual name of the element
				theButtonPressed = evt.which;
			//}
        	}else if(isIE) {
			//if (window.event.srcElement.type == "text") {
				//--> same as above, but for IE
				theButtonPressed = window.event.keyCode;
			//}
		//}else if(isWhoKnows) {
		//	alert("Please hit the submit button to process form");
		}

		if (theButtonPressed == 13) {
			text_modelnumber_onchange();
		}
	}

//-->

