/*
	17-Apr-2008
		Stored procedure call now in place
	
*/

// Creates an activity record in the database
function act(id)
{	
	/*
	if(!(username && (username=="tom1" || username=="tom2"))) // Used when working on a problem only!
		return;
	*/
	
	pageUrl = window.document.location.href;
	url = "/IELTSexpress/scripts/actrec.asp?act_id=" + id + "&page_url=" + pageUrl;
	
	req = createXMLHttpRequest(url, actOnReadyStateChange, true);
	if (req)
		req.send(null);
	else
		alert("Your browser does not support XMLHttpRequest objects.");
	return;
	
	// Internal function
	function actOnReadyStateChange()
	{
		if (req.readyState == 4)
		{
			if (req.status == 200)
			{
				// all good!
			}
			else
			{
				alert("Sorry, an error has occured while recording your activity in the database!");
			}
		}
	}
} 

// Creates the XML request object
function createXMLHttpRequest(url, onReadyStateChange, async)
{
	req = false;
	
	if(window.XMLHttpRequest && !(window.ActiveXObject))	// branch for native XMLHttpRequest object
	{
		try
			{
				req = new XMLHttpRequest();
			}
			catch(e)
			{
				req = false;
			}
	}
	else if(window.ActiveXObject)	// branch for IE/Windows ActiveX version
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
      }
      catch(e)
      {
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
        	}
        	catch(e)
        	{
				req = false;
        	}
		}
	}
	
	if (req)
	{
		req.onreadystatechange = onReadyStateChange;
		req.open("GET", url, async);
	}
	
	return req;
}



// *************************
// Instant feedback
// *************************
function InstaFB( isRight, feedback){
 // Define your responses here
 var responseY ="Yes that's correct.", responseN ="No, that's incorrect. Try again!",  responseN2 ="No, that's incorrect. ";
  //Do the check
  if(isRight==true)	{
			alert(responseY + " " + feedback);}
	if(isRight==false) {
		if(feedback== " "){
			alert(responseN);}
		else{
			alert(responseN2 +" "+ feedback);}
	}
}

	
// *************************
// Audio display
// *************************
function PlayAudio(fname)
{
	var curr_page = new String(window.location.href);
	var parts_array = curr_page.split('/');
	if ((parts_array[3])=="SCRIPT") {
		var module_name = parts_array[4];
	} else {
		var module_name = parts_array[3];
	}
	var player_popup = '/IELTSexpress/js/qtplayer.asp';
	//var audio_file =  '../../audio/' + fname;
	var audio_file =  '/IELTSexpress/audio/' + fname;
	var url = player_popup + '?' + audio_file;
	window.open(url,'default','resizable,scrollbars=no,top=0,left=0,width=400,height=85');
	}


// *************************
// ON Off layer
// *************************
function OnOffFB(whichItem)
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichItem );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichItem];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichItem];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
     vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
     vis.display = (vis.display==''||vis.display=='block')?'none':'block';
}
// *************************
// ON Off visibility
// *************************
function showstuff(boxid){
   document.getElementById(boxid).style.visibility="visible";
}
function showme(boxid){
   document.getElementById(boxid).style.display="block";
}
function hideme(boxid){
   document.getElementById(boxid).style.display="none";
}
function resetStyle(whichItem)
{
  var elem, vis;
  if( document.getElementById ) // this is the way the standards work
    elem = document.getElementById( whichItem );
  else if( document.all ) // this is the way old msie versions work
      elem = document.all[whichItem];
  else if( document.layers ) // this is the way nn4 works
    elem = document.layers[whichItem];
  vis = elem.style;
  // if the style.display value is blank we try to figure it out here
  if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
     vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
     vis.display = (vis.display==''||vis.display=='none')?'none':'none';
}
// *************************
// ON Off words II
// *************************
function presto(id, prop, val){
var el=typeof id=='object'? id : document.all? document.all[id] : document.getElementById(id);
if(el.holder==val)
el.holder=el.style[prop]='';
else
el.style[prop]=el.holder=val;
}


// *************************
// highlighting loops
// *************************
function hl1()
{
  // return array of all span elements
  var hilights = document.getElementsByTagName("SPAN");
  // Iterate through all DIVs in array
  for(var i = 0; i < hilights.length; i++){
    //If its on, turn it off
	if(hilights[i].className == "hl1")
      hilights[i].className = "nhl1";
	//If its off, turn it on
	else if(hilights[i].className == "nhl1")
      hilights[i].className = "hl1";}
}
function hl2(){
  var hilights = document.getElementsByTagName("SPAN");
  for(var i = 0; i < hilights.length; i++){	if(hilights[i].className == "hl2") hilights[i].className = "nhl2";
	else if(hilights[i].className == "nhl2") hilights[i].className = "hl2";}
}
function hl3(){
  var hilights = document.getElementsByTagName("SPAN");
  for(var i = 0; i < hilights.length; i++){if(hilights[i].className == "hl3")hilights[i].className = "nhl3";
	else if(hilights[i].className == "nhl3")hilights[i].className = "hl3";}
}
function hl4(){
  var hilights = document.getElementsByTagName("SPAN");
  for(var i = 0; i < hilights.length; i++){if(hilights[i].className == "hl4")hilights[i].className = "nhl4";
	else if(hilights[i].className == "nhl4")hilights[i].className = "hl4";}
}
function hl5(){
  var hilights = document.getElementsByTagName("SPAN");
  for(var i = 0; i < hilights.length; i++){if(hilights[i].className == "hl5")hilights[i].className = "nhl5";
	else if(hilights[i].className == "nhl5")hilights[i].className = "hl5";}
}
function hl6(){
  var hilights = document.getElementsByTagName("SPAN");
  for(var i = 0; i < hilights.length; i++){if(hilights[i].className == "hl6")hilights[i].className = "nhl6";
	else if(hilights[i].className == "nhl6")hilights[i].className = "hl6";}
}
function hl7(){
  var hilights = document.getElementsByTagName("SPAN");
  for(var i = 0; i < hilights.length; i++){if(hilights[i].className == "hl7")hilights[i].className = "nhl7";
	else if(hilights[i].className == "nhl7")hilights[i].className = "hl7";}
}
function hl8(){
  var hilights = document.getElementsByTagName("SPAN");
  for(var i = 0; i < hilights.length; i++){if(hilights[i].className == "hl8")hilights[i].className = "nhl8";
	else if(hilights[i].className == "nhl8")hilights[i].className = "hl8";}
}
function hl9(){
  var hilights = document.getElementsByTagName("SPAN");
  for(var i = 0; i < hilights.length; i++){if(hilights[i].className == "hl9")hilights[i].className = "nhl9";
	else if(hilights[i].className == "nhl9")hilights[i].className = "hl9";}
}
function hl10(){
  var hilights = document.getElementsByTagName("SPAN");
  for(var i = 0; i < hilights.length; i++){if(hilights[i].className == "hl10")hilights[i].className = "nhl10";
	else if(hilights[i].className == "nhl10")hilights[i].className = "hl10";}
}
function hl11(){
  var hilights = document.getElementsByTagName("SPAN");
  for(var i = 0; i < hilights.length; i++){if(hilights[i].className == "hl11")hilights[i].className = "nhl11";
	else if(hilights[i].className == "nhl11")hilights[i].className = "hl11";}
}
function hl12(){
  var hilights = document.getElementsByTagName("SPAN");
  for(var i = 0; i < hilights.length; i++){if(hilights[i].className == "hl12")hilights[i].className = "nhl12";
	else if(hilights[i].className == "nhl12")hilights[i].className = "hl12";}
}
function hl13(){
  var hilights = document.getElementsByTagName("SPAN");
  for(var i = 0; i < hilights.length; i++){if(hilights[i].className == "hl13")hilights[i].className = "nhl13";
	else if(hilights[i].className == "nhl13")hilights[i].className = "hl13";}
}
function b1(){
  var hilights = document.getElementsByTagName("SPAN");
  for(var i = 0; i < hilights.length; i++){if(hilights[i].className == "b1")hilights[i].className = "nb1";
	else if(hilights[i].className == "nb1")hilights[i].className = "b1";}
}
function b2(){
  var hilights = document.getElementsByTagName("SPAN");
  for(var i = 0; i < hilights.length; i++){if(hilights[i].className == "b2")hilights[i].className = "nb2";
	else if(hilights[i].className == "nb2")hilights[i].className = "b2";}
}

function diaUp(url)
// opens a new window for diagrams;
// pre: url = url;
// post: opens window;
{
	var popup = window.open(url,'dia','scrollbars=1,resizable=1,top=10,left=10,width=780,height=590');
	return popup.focus();
}

// *************************
// Tips - Bought over from old course
// *************************
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

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 flvFTL1(){// v1.0
// Copyright 2003, Marja Ribbers (FlevOOware.nl)
var v1=arguments,v2,v3,v4,v5;for (v3=0;v3<v1.length;v3++){v2=MM_findObj(v1[v3]);if (v2){if (document.layers){v4=v2;v5="show";}else {v4=v2.style;v5="visible";}v4.visibility=(v4.visibility==v5)?"hidden":"visible";}}}
//-->
