// LensCalcLite 1.0 JavaScript Library
// Version 1.0 / 25 december 2003
var InternetExplorer;
var myFlashObj;
var calcLoaded = false;

// lens id
var lID = 0;

// sensor id
var sID = 0;

// direction (reading) id
var dID = 0;

var rowWithMouse = null;

function init() {
	// get ref to lens calc
	InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;
	myFlashObj = (InternetExplorer) ? window.myFlash : document.myFlash;
	timerID = window.setTimeout("checkIfLoaded()", 100);
}

function checkIfLoaded() {
	if (myFlashObj.PercentLoaded() == 100) {
		calcLoaded = true;
		rowToggle('l', 0);
		rowToggle('s', 0);
		rowToggle('d', 0);
		window.clearTimeout(timerID);
	} else {
		timerID = window.setTimeout("checkIfLoaded()", 100);
	}
}
function start() {
	// set inital selection

}
function changeLens(arg){
	lID = arg;
	update();
}
function changeSensor(arg){
	sID = arg;
	update();
}
function changeDirection(arg){
	dID = arg;
	update();
}

function update() {
	if (calcLoaded) {
        myFlashObj.SetVariable("input", lID + " " + sID + " " + dID);
	} else {
		alert("Please wait for the lens calculator to load.");
	}
}

function rowRollover(type, myId, isInRow) {
	var row = document.getElementById(type + '_' + myId);
	rowWithMouse = (isInRow) ? row : null;
	rowUpdateBg(type, row);
}
function rowUpdateBg(type, row) {
	// is it the selected row?
	if ((row.id == 'l_' + lID) || (row.id == 's_' + sID) ||(row.id == 'd_' + dID)) {
		row.style.backgroundColor = "#FFEEEE";
		row.style.borderColor = "#990000";
	} else {
		row.style.backgroundColor = (row == rowWithMouse)   ? '#CCFFCC' : '#F2F2F2';
		row.style.borderColor = (row == rowWithMouse) ? "#009900" : "#ffffff";
	}	
}
function rowToggle(type, myId) {
	// unselect old row, select new row.
	if(type == "l") {
		var oldrow = document.getElementById('l_' + lID);
		var newrow = document.getElementById('l_' + myId);
		lID = myId;
	} else if(type == "s") {
		var oldrow = document.getElementById('s_' + sID);
		var newrow = document.getElementById('s_' + myId);
		sID = myId;
	} else {
		var oldrow = document.getElementById('d_' + dID);
		var newrow = document.getElementById('d_' + myId);
		dID = myId;
	}
	rowUpdateBg(type, oldrow);
	rowUpdateBg(type, newrow);
	
	// update lens calc
	if(type == 'l') {
		changeLens(myId)
	} else if (type =='s') {
		changeSensor(myId)
	} else {
		changeDirection(myId)
	}
}
