// JavaScript Document// 
N=(navigator.appName.substring(0,1) == 'N');
function findObj(theObj) {
	return document.getElementById(theObj)
}
function canMove(obj) {
	with (theObj.style) {
		if (!(position == 'absolute' || position == 'relative')) position = 'absolute';
		if (!left) left = '0px';
		if (!top) top = '0px';
	}
}
function mv(obj,x,y) {
	with (obj.style) {
		left = (parseInt(left) + parseInt(x)) + 'px';
		top = (parseInt(top) + parseInt(y)) + 'px';
	}
}
function mvTo(obj,x,y) {
	with (obj.style) {
		left = x + 'px';
		top = y + 'px';
	}
}
function showcollection(divListings) {
	var divListTest = divListings.split(",");
	if (divListTest[0] == 0) {
		divList = divListTest
	} else {
		var useList = divListings
	}
	for (var i in divList) {	
		if (divList[i] != 0) {
			theObj = findObj(divList[i]);
			theObj.style.display = "none";
		}
	}
	if (useList) {	
		theObj = findObj(useList);
		theObj.style.display = "block";
	}
}
function fade() {
	correctObj.style.color = colors[color];
	color += stepnum; 
	if (color >= colors.length-1) {
		stepnum = -1;
	}
	if (color == 0) {
		if (stepnum == -1) {
			if (fadeStyleType != 0) {
				correctObj.style.display = 'none';
				if (mainbodyObj) {
					mainbodyObj.style.display = 'block';
				}
				if (document.quizform) {
					document.quizform.quizanswer.focus()
				}
				return;
			} else {
				document.location = 'allex.php';
			}
		} else {
			stepnum = 1;
		}
	}
	setTimeout("fade()", (color == colors.length-2 && stepnum == -1) ? show : ((color == 1 && stepnum == 1) ? sleep : 50));
}

function getFadeColors(ColorA, ColorB, Colors) {
	len = Colors.length; 
	
	var r = HexToInt(ColorA.substring(0,2));
	var g = HexToInt(ColorA.substring(2,4));
	var b = HexToInt(ColorA.substring(4,6));
	var r2 = HexToInt(ColorB.substring(0,2));
	var g2 = HexToInt(ColorB.substring(2,4));
	var b2 = HexToInt(ColorB.substring(4,6));
	
	var rStep = Math.round((r2 - r) / len);
	var gStep = Math.round((g2 - g) / len);
	var bStep = Math.round((b2 - b) / len);
	
	for (var i = 0; i < len-1; i++) {
		Colors[i] = "#" + IntToHex(r) + IntToHex(g) + IntToHex(b);
		r += rStep;
		g += gStep;
		b += bStep;
	}
	Colors[len-1] = ColorB;
}

function IntToHex(n) {
	var result = n.toString(16);
	if (result.length==1) result = "0"+result;
	return result;
}

function HexToInt(hex) {
	return parseInt(hex, 16);
}

function hideCorrect(whatStyle, noneObj) {
	correctObj = findObj('correctdiv');
	if (whatStyle) {
		fadeStyleType = whatStyle;
	} else {
		fadeStyleType = 0;
	}
	if (noneObj) {
		mainbodyObj = findObj(noneObj);
	} else {
		mainbodyObj = 0;
	}
	if (correctObj) {
		if (mainbodyObj != 0) {
			mainbodyObj.style.display = 'none';
		}
		bgcolor = "ffffff"; // background color, must be valid browser hex color (not color names)
		fcolor = "0000ff";  // foreground or font color
		steps = 20; // number of steps to fade
		show = 500; // milliseconds to display message
		sleep = 30; // milliseconds to pause inbetween messages
		colors = new Array(steps);
		getFadeColors(bgcolor,fcolor,colors);
		color = 0;
		text = 0;
		stepnum = 1;
		fade(whatStyle);
	}
}