//mac IE5 sniff
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_mac    = (agt.indexOf("mac")!=-1);
var is_macie5 = (is_mac && is_ie5up)
var checkflag = "false";
function reset(x) {
	for(a=0;a<x.length;a++)x[a].checked=false;
}
function check(field) {
	if (field[0].checked) {
		for (i = 0; i < field.length; i++) {
			field[i].checked = true;}
			checkflag = "true";
			return "Uncheck All"; 
		}
	else {
		for (i = 0; i < field.length; i++) {
			field[i].checked = false; }
			checkflag = "false";
			return "Check All"; 
		}
}

var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	closeWin();
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable,toolbar=no,location=no,scrollbars=yes,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url + "?w=" + strWidth + "&h=" + strHeight, 'newWin', tools);
	newWindow.focus();
}

	function highlight(type, x) {
		if(type=="high"){
			classname="unhigh"+x
			type=" high"
			ftype="find selected"
		} else {
			classname="high"+x
			type=" unhigh"
			ftype = "find"
		}
		var inc=0
		var customcollection = new Array()
		document.getElementById("link" + x).className = ftype
		for (i=0; i<myTags.length; i++){
			if (myTags[i].className.indexOf(classname)>0) {
					left =  myTags[i].className.substring(0, myTags[i].className.indexOf(classname))
					right = myTags[i].className.substring(classname.length + myTags[i].className.indexOf(classname), myTags[i].className.length)
					newclass = left + right + type + x
					myTags[i].className = newclass
				}
		}
	}
	function high(x) {
		if (document.all || document.getElementById){
			highlight("high", x)
		}
	}
	function unhigh(x) {
		if (document.all || document.getElementById){
			flag=true
			for(a=0;a<=prehighlightArr.length;a++) {
				if(prehighlightArr[a] == x) flag=false
			}
			if(flag)highlight("unhigh", x)
		}
	}
	
	function expander(x) {
		if (document.all || document.getElementById){
			var myRow=document.all? document.all["td"+x] : document.getElementById("td"+x)
			var myTable=document.all? document.all["expander_table"+x] : document.getElementById("expander_table"+x)
			
			if(myRow.className.indexOf("expanded")>0) {
				myRow.className = "first contracted"
				myTable.style.display = "none"
			}else{
				myRow.className = "first expanded"
				myTable.style.display = "block"
			}
		}
	}
	function grey(x, prefixx) {
		if ( (document.all || document.getElementById) && (!is_macie5) ) {
			clearTimeout(timeout)
			y=x.replace("_", "")
			//if(x>9) x="_" + x
			var myNoGrey=document.all? document.all["grey"+x] : document.getElementById("grey"+x)
			for(a=1;a<=totalCols;a++) {
				f=a>9 ? f="_" + a : f=a
				var myGrey=document.all? document.all["grey"+prefixx+f] : document.getElementById("grey"+prefixx+f)
				myGrey.style.display="block"
				var myBonus=document.all? document.all["bonus"+a] : document.getElementById("bonus"+a)
				myBonus.style.display="none"
			}
			//alert("bonus"+y)
			y=y.substring(prefixx.length,y.length)
			var myBonus=document.all? document.all["bonus"+y] : document.getElementById("bonus"+y)
			
			myBonus.style.display="block"
			var myBonus=document.all? document.all.bonus0 : document.getElementById("bonus0")
			myBonus.style.display="none"
			
			myNoGrey.style.display="none"
		}
	}
	function ungrey() {
		if ( (document.all || document.getElementById) && (!is_macie5)) {
			timeout=setTimeout('ungreyNow()',1000);
			for(a=0;a<=totalCols;a++) {
				var myBonus=document.all? document.all["bonus"+a] : document.getElementById("bonus"+a)
				myBonus.style.display="none"			
			}
			var myBonus=document.all? document.all.bonus0 : document.getElementById("bonus0")
			myBonus.style.display="block"
		}
			
	}
	
	function ungreyNow() {
		for(a=1;a<=totalCols;a++) {
			f=a>9 ? f="_" + a : f=a
			var myGrey=document.all? document.all["grey"+f] : document.getElementById("grey"+f)
			if(myGrey)myGrey.style.display="none"
			var myGrey=document.all? document.all["greycon"+f] : document.getElementById("greycon"+f)
			if(myGrey)myGrey.style.display="none"
			var myGrey=document.all? document.all["greyother"+f] : document.getElementById("greyother"+f)
			if(myGrey)myGrey.style.display="none"
		}
	}

		function changeValue(obj, val) {
			if (obj) {
				obj.value = val; 
				if (obj.value < 0) {
					obj.value = 0;
				}
			}
		}
		
		
		function swapColors(id, rowtype) {
		if(document.getElementById)
		{
			if(document.getElementById(id).className.indexOf("highlight")>0) {
				document.getElementById(id).className = rowtype
			} else {
				document.getElementById(id).className = rowtype + " highlight"
			}
		}
		/*
			if(typeof(num)=='undefined')num=5
			id=id.substring(3,id.length)
			for (i=id; i<id+num; i++) {
				document.getElementById("row"+i).style.color = col;
			}
		*/
		}
		
function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  alert('Query Variable ' + variable + ' not found');
}

function makeRed(row) {
	if(document.getElementById) {
		myClass = document.getElementById(row).className
		document.getElementById(row).className = myClass + " red"
	}
}

function btnOn(id, button) {
	if(document.getElementById) {
		document.getElementById(id).src = "/images/buttons/btn_" + button + "_d.gif"
	}
}

function btnOff(id, button) {
	if(document.getElementById) {
		document.getElementById(id).src = "/images/buttons/btn_" + button + ".gif"
	}
}

function checkIt(id) {
	if(document.getElementById) {
		document.getElementById(id).checked="true"
	}
}

function strategy_play(x) {
	if(document.getElementById) {
		for(a=1;a<=6;a++) {
			document.getElementById("lesson" + a).className = "lesson contracted";
		}
		document.getElementById("lesson" + x).className = "lesson expanded";
		var fo = new FlashObject("/flash/pl_strategy.swf?vid_num="+x, "pl_strategy", "240", "177", "6", "#ffffff");
		fo.write("strategy_flash");
	}
}





