
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function validateQuestion(){

	var frm = document.forms[0];
	var len = frm.answer.length;
	var isValid;

	for(var i = 0; i < len; i++){
		if(frm.answer(i).checked){
			isValid = true;
			break;
		}
	}
	
	if(!isValid){
		alert("Please enter an answer.");
		return false;	
	}else{
		return true;
	}	
}

function openWindow(theURL,w,h)
{
	window.open(theURL,'Title','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + w + ',height=' + h); 
}

// need the clock to count down instead of counting up

var timerID;
var tStart;

function updateTimer(){

	if(timerID){
		clearTimeout(timerID);
		clockID = 0;
	}

	if(!tStart){
		tStart = new Date();
	}

	var tDate = new Date();
	var tDiff = tStart.getTime() - tDate.getTime();

	tDate.setTime(tDiff);

	document.testTimer.timer.value = "" + tDate.getMinutes() + ":" + tDate.getSeconds();
	timerID = setTimeout("updateTimer()", 1000);
}

/*
Chromeless Window (v3.5)- By Gabriel Suchowolski (this credit MUST stay intact)
Author site at http://www.microbians.com
Visit http://www.dynamicdrive.com for this script
*/

//For paramater explanations, see accompanying faq.htm file
function openIT(u,W,H,X,Y,n,b,x,m,r) {
	var cU  ='close.gif'   //gif for close on normal state.
	var cO  ='close.gif'  //gif for close on mouseover.
	var cL  ='clock.gif'      //gif for loading indicator.
	var mU  ='minimize.gif'     //gif for minimize to taskbar on normal state.
	var mO  ='minimize.gif'    //gif for minimize to taskbar on mouseover.
	var xU  ='max.gif'     //gif for maximize normal state.
	var xO  ='max.gif'    //gif for maximize on mouseover.
	var rU  ='restore.gif'     //gif for minimize on normal state.
	var rO  ='restore.gif'    //gif for minimize on mouseover.
	var tH  ='' //<font face=verdana size=2>Chromeless Window</font>'   //title for the title bar in html format.
	var tW  =''   //title for the task bar of Windows.
	var wB  ='#000099'   //Border color.
	var wBs ='#000099'   //Border color on window drag.
	var wBG ='#000099'   //Background of the title bar.
	var wBGs='#000099'   //Background of the title bar on window drag.
	var wNS ='toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0'  //Html parameters for Netscape.
	var fSO ='scrolling=auto noresize'   //Html parameters for main content frame.
	var brd =b||5;   //Extra border size.
	var max =x||false;   //Maxzimize option (true|false).
	var min =m||false;   //Minimize to taskbar option (true|false).
	var res =r||false;   //Resizable window (true|false).
	var tsz =20;   //Height of title bar.
	return chromeless(u,n,W,H,X,Y,cU,cO,cL,mU,mO,xU,xO,rU,rO,tH,tW,wB,wBs,wBG,wBGs,wNS,fSO,brd,max,min,res,tsz)
}

function calcCost()
{
	
	var frm = document.purchaseForm;
	
	var quantity = parseFloat(frm.quantity.value);
	var product = frm.product;
	var price;
	var module;
	var productId;
	var total;
	
	// split the string up into an array
	var temp = GetOptionGroupValue(product);
	temp = temp.split(",");
	
	// get the three values
	module = temp[0];
	productId = temp[1];
	price = temp[2];

	/*document.write("ProductId: " + productId + "<BR>");
	document.write("Module: " + module + "<BR>");
	document.write("Price: " + price);*/
	
	total = quantity * price;
	if(!isNaN(total)){
		frm.amount.value = total + ".00";
	}
	
	frm.module.value = module;
	frm.productId.value = productId;
}
/*
function highlightSelected(){

	if(document.forms){
		
		var frm = document.forms[0];
		
		for(i = 0; i < frm.length; i++){
	
			if(frm.elements[i].checked == true){
				frm.elements[i].parentNode.className = 'checked';
			}
		}
	}else{
		document.write("no forms");
	}	
}
*/

var up, down;
var min1, sec1;
var cmin1, csec1, cmin2, csec2;

function Minutes(data) {

	for(var i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;

	return(data.substring(0,i)); }

function Seconds(data) {

	for(var i=0;i<data.length;i++) if(data.substring(i,i+1)==":") break;

	return(data.substring(i+1,data.length)); }

function Display(min,sec) {

	var disp;

	if(min<=9) disp=" 0";

	else disp=" ";

	disp+=min+":";

	if(sec<=9) disp+="0"+sec;

	else disp+=sec;

	return(disp); }

function timeDown() {

	cmin2=1*Minutes(document.sw.beg.value);

	csec2=0+Seconds(document.sw.beg.value);

	DownRepeat(); }

function DownRepeat() {

	csec2--;

	if(csec2==-1) { csec2=59; cmin2--; }

	// change the colour of the timer to red
	if((cmin2<=5)){
		document.sw.disp.style.color = "red";
	}
	
	// alert the user they have 5mins remaining
	if((cmin2==5)&&(csec2==0)){
		alert("You have 5 minutes remaining.");
	}
	
	document.sw.disp.value=Display(cmin2,csec2);

	if((cmin2==0)&&(csec2==0)){ 
		alert("Your time limit has expired!");
		window.location = "finish.asp?outoftime=true";
	}else down=setTimeout("DownRepeat()",1000); 
}

	
function GetOptionGroupValue(collection)
{
	if (collection == null) return null;

	if (typeof(collection.length) == "undefined") 
	{
		return collection.value;
	}

	for (i = 0; i < collection.length; i++)
	{
		if (collection[i].checked) 
			return collection[i].value;
	}
	
	return "";
}	