/*******************************************************************/
// Error handling routine
/*******************************************************************/
function nl_error()
{
  var e = "\nSorry, an error has occurred!\n\n";
  e += "This error may have occured if you started an exercise before the page has finished loading. " +
    "Please ensure that the page has completely finished loading (images included) before clicking on any of the exercises. " +
    "The easiest way to know if the page has finished loading is " +
    "to wait until your browser's icon (in the top righthand corner) stops moving.\n\n" +
    "If this error occured even after the page had finished loading please contact its-magazine with this error and version information:\n\n";
  e += "Error Information:\n";
	if (null != arguments)
  {
    if (null != arguments.length)
    {
      e += "      Desc:"+" " + arguments[0] + "\n";
      e += "      File:"+" " + arguments[1] + "\n";
      e += "      Line:"+" " + arguments[2] + "\n";
    }
    else
      e += "      Error :!\n";
  }
  else
    e += "      No error information found!\n";

  e += "Browser Information:\n";
  e += "      "+navigator.appName+" - "+navigator.appVersion+" - "+navigator.appCodeName+"\n";
  e += "\nThank-you!\n";
  alert(e);
  return true;
}

window.onerror = nl_error;
/*******************************************************************/



/*******************************************************************/
function its_popupWindow(url,target,width,height,opts)
/*
	Returns: (nothing)

	Required parameters:
	·	url: address of page to load in popup window, usually: this.href
	·	target: the name to give to the new window (for reusing windows)

	Optional parameters:
	·	width: (integer) only used if height is also specified
	·	height: (integer)
	·	opts: (string) specify which elements to display in the window:
			l - location (or address) bar
			m - menu bar (useful for access to the file menu for printing)
			r - resizable (usually this should be specified)
			s - scroll bars (usually this should be specified)
			t - tool bar (back, forward, reload, stop, etc)
			x - status bar

			e.g. 'mrs' means display menu bar, allow window to be resized
			and display scrollbars if content is too big for window
********************************************************************/
{
	var p = null;
	if (width == null || height == null) {
		p = null
	}
	else if (opts == null) {
		p = "width="+width+",height="+height
	}
	else
	{
		p = "width="+width+",height="+height

		opts = opts.toString().toLowerCase();

		if (opts.indexOf("l") >= 0) p += ",location=1"
		if (opts.indexOf("m") >= 0) p += ",menubar=1"
		if (opts.indexOf("r") >= 0) p += ",resizable=1"
		if (opts.indexOf("s") >= 0) p += ",scrollbars=1"
		if (opts.indexOf("t") >= 0) p += ",toolbar=1"
		if (opts.indexOf("x") >= 0) p += ",statusbar=1"
	}

	var x = window.open(url,target,p)
	if (x.focus) x.focus();
}//function its_popupWindow
/*******************************************************************/

/*******************************************************************/
// functions to open popup window (deprecated)
/*******************************************************************/
function ac_openPopupWindow(theURL,winName,features) {
	var x = window.open(theURL,winName,features);
	if (x.focus) x.focus();
}
function its_openWindow(url,winName,params) {
  var newWin = window.open(url,winName,params);
  if (newWin.focus) newWin.focus();
}
/*******************************************************************/


/*******************************************************************/
// Event Binding Code
if (null == versionID) var versionID = new Array(); versionID[versionID.length] = ("Event Binding: v1.0\n");

function nl_onLoad() {
  if (null == document.nl_config) { alert("General initialisation failed!  Please contact info@its-online.com."); return; }
  if (null == document.nl_config.onload) { alert("ONLOAD initialisation failed!  Please contact info@its-online.com."); return; }
  eval (document.nl_config.onload);
  document.nl_config.loaded = true;
}
function nl_onUnload() {
  if (null == document.nl_config) { alert("General initialisation failed!  Please contact info@its-online.com."); return; }
  if (null == document.nl_config.onunload) { alert("ONUNLOAD initialisation failed!  Please contact info@its-online.com."); return; }
  eval (document.nl_config.onunload);
}
function nl_wrap(nl_code) {
  if (null == document.nl_config) { alert("General initialisation failed!  Please contact info@its-online.com."); return; }
  if (! document.nl_config.loaded) { alert("Please wait until the page has finished loading before doing the exercises!"); return; }
  eval(nl_code);
}
function _addEvent(ev,code) {
  if (ev.toLowerCase() == "onload") this.onload += code + "; ";
  else if (ev.toLowerCase() == "onunload") this.onunload += code; else alert("Event '"+ev+"' not supported\nCould not bind '"+code+"'.");
}

document.nl_config = new Object();
document.nl_config.loaded=false; document.nl_config.onload="";
document.nl_config.onunload=""; document.nl_config.add = _addEvent;
window.onload=nl_onLoad;
window.onunload=nl_onUnload;
// End of Event Binding Code
/*******************************************************************/

/*******************************************************************/
// Generic debugging function
function debug(obj)
{
	var t = "";
	for (var x in obj)
	{
		t += x + ":" + obj[x] + "\n";
	}
}
/******************************************************************/


/*
 * Set up popup window object to hold references to all
 * popup windows.
 */
if (null == versionID) var versionID = new Array();
versionID[versionID.length] = ("Popup Script: v1.3\n");

function NL_popupWindow(bgcolor)
{
this.win = null;
this.color = bgcolor;
}

var nl_popup = new Array();
nl_popup["text"]     = new NL_popupWindow("#FFFFFF");
nl_popup["answer"]   = new NL_popupWindow("#FFFFFF");
nl_popup["grammar"]  = new NL_popupWindow("#FFFFFF");
nl_popup["wordlist"] = new NL_popupWindow("#FFFFCC");
nl_popup["tape"]     = new NL_popupWindow("#FFCC99");

function openPopupWindowSpecURL(winArray,linkHref,linkTarget,settings)
{
  if (navigator.appVersion.indexOf("MSIE 3") >= 0) return;

  var theURL = linkHref;
  var theTarget = linkTarget;
  if (null == settings)
    settings = 'scrollbars=yes,width=300,height=200,menubar=yes,resizable=yes';

  if (null == winArray[theTarget].win) {//    alert("New window or was closed programmatically");
    winArray[theTarget].win = window.open(theURL,theTarget,settings)
  }
  else if (!winArray[theTarget].win.closed) {//    alert("Already open, load new document");
    winArray[theTarget].win.location.assign(theURL)
    winArray[theTarget].win.focus();
  }
  else {//    alert("Closed manually");
    winArray[theTarget].win = window.open(theURL,theTarget,settings)
  }
}

function openPopupWindowURL(winArray,theLink,settings)
{
  if (navigator.appVersion.indexOf("MSIE 3") >= 0) return;

  var theURL = theLink.href;
  var theTarget = theLink.target;

  openPopupWindowSpecURL(winArray,theURL,theTarget,settings);
}

function openPopupWindowSameDir(winArray,theLink,settings)
{
  if (navigator.appVersion.indexOf("MSIE 3") >= 0) return;

  var theURL = theLink.href;
  var theFile = theURL.substring(theURL.lastIndexOf("/"),theURL.length);
  var theDocument = document.location.href.toString();
  var theDirectory = theDocument.substring(0,theDocument.lastIndexOf("/"));
  theURL = theDirectory + theFile;
  var theTarget = theLink.target;

  openPopupWindowSpecURL(winArray,theURL,theTarget,settings);
}

function openPopupWindowHTML(winArray,winName,title,content,settings)
{
  var tophtml = "<html><head><title>";
  var midhtml = "</title></head><body background=\"/common/images/backie.jpg\" bgcolor="+winArray[winName].color+" text=#000000>";
  var bothtml = "<form onsubmit='return false'><center><input type=button onclick='window.close()' value='OK'></center></form></body></html>";

  if (null == settings) settings = 'scrollbars=yes,width=300,height=400,menubar=yes,resizable=yes';

  if (navigator.appVersion.indexOf("MSIE 3") >= 0)
  {
    var win = window.open("",winName,settings);
    win.document.open();
    win.document.write(tophtml + title + midhtml + content + bothtml);
    win.document.close();
    return;
  }

  if (winArray[winName].win == null) {//    alert("New window or was closed programmatically");
    winArray[winName].win = window.open("",winName,settings)
    winArray[winName].win.document.open();
    winArray[winName].win.document.write(tophtml + title + midhtml + content + bothtml);
    winArray[winName].win.document.close();
  }
  else if (!winArray[winName].win.closed) {//    alert("Already open, write new document");
    winArray[winName].win.document.open();
    winArray[winName].win.document.write(tophtml + title + midhtml + content + bothtml);
    winArray[winName].win.document.close();
    if (navigator.appVersion.indexOf("MSIE 3") < 0) winArray[winName].win.focus();
  }
  else {//    alert("Closed manually");
    winArray[winName].win = window.open("",winName,settings)
    winArray[winName].win.document.open();
    winArray[winName].win.document.write(tophtml + title + midhtml + content + bothtml);
    winArray[winName].win.document.close();
  }
}

function openPopupWindowFrames(winArray,leftContent,rightContent,winName,title,settings)
{
  if (null == settings) settings = 'scrollbars=yes,width=500,height=250,menubar=yes,resizable=yes';
  if (null == title) title = 'its-english FAQ';
  if (null == winName) winName = 'grammar';

  var tophtml = "<html><head><title>"+title+"</title></head>\n" +
    "<frameset cols=\"156,*\" bordercolor=\"#000000\" border=\"0\">\n<frame src=\"";
  var midhtml = "\" scrolling=\"YES\" bordercolor=\"#FFFFFF\" frameborder=\"NO\" name=\"left\">\n" +
    "<frame src=\"";
  var bothtml = "\" scrolling=\"AUTO\" frameborder=\"NO\" bordercolor=\"#FFFFFF\" name=\"right\">"+
    "</frameset></html>";

  if (navigator.appVersion.indexOf("MSIE 3") >= 0)
  {
    var win = window.open("",winName,settings);
    win.document.open();
    win.document.write(tophtml + leftContent + midhtml + rightContent + bothtml);
    win.document.close();
    return;
  }

  if (winArray[winName].win == null) {//    alert("New window or was closed programmatically");
    winArray[winName].win = window.open("",winName,settings)
    winArray[winName].win.document.open();
    winArray[winName].win.document.write(tophtml + leftContent + midhtml + rightContent + bothtml);
    winArray[winName].win.document.close();
  }
  else if (!winArray[winName].win.closed) {//    alert("Already open, write new document");
    winArray[winName].win.document.open();
    winArray[winName].win.document.write(tophtml + leftContent + midhtml + rightContent + bothtml);
    winArray[winName].win.document.close();
    if (navigator.appVersion.indexOf("MSIE 3") < 0) winArray[winName].win.focus();
  }
  else {//    alert("Closed manually");
    winArray[winName].win = window.open("",winName,settings)
    winArray[winName].win.document.open();
    winArray[winName].win.document.write(tophtml + leftContent + midhtml + rightContent + bothtml);
    winArray[winName].win.document.close();
  }
}

function closePopupWindows(popupArray)
{
if (navigator.appVersion.indexOf("MSIE 3") >= 0) return;

if (popupArray["text"].win != null)
  if (!popupArray["text"].win.closed)
    popupArray["text"].win.close();
popupArray["text"].win = null;

if (popupArray["answer"].win != null)
  if (!popupArray["answer"].win.closed)
    popupArray["answer"].win.close();
popupArray["answer"].win = null;

if (popupArray["grammar"].win != null)
  if (!popupArray["grammar"].win.closed)
    popupArray["grammar"].win.close();
popupArray["grammar"].win = null;

if (popupArray["wordlist"].win != null)
  if (!popupArray["wordlist"].win.closed)
    popupArray["wordlist"].win.close();
popupArray["wordlist"].win = null;

if (popupArray["tape"].win != null)
  if (!popupArray["tape"].win.closed)
    popupArray["tape"].win.close();
popupArray["tape"].win = null;
}

document.nl_config.add("onunload","closePopupWindows(nl_popup);");


/*******************************************************************/
// functions for logging in to the sites
/*******************************************************************/
function itsSubmit (form){
	return verifyForm(form)
}

function verifyForm(form){
	if (form.subscribernumber.value == "") {
		 alert("Please enter your subscriber number.");
		 form.subscribernumber.focus();
		 return false;
	}

	if (form.password.value == "") {
		 alert("Please enter your password.");
		 form.password.focus();
		 return false;
	}

	return true;
}
/*******************************************************************/


/*******************************************************************/
// function to transfer login before linking to other sites
/*******************************************************************/
function addTransferFunctions()
{
	// only do it if logged in
	if (document.ITS_loggedIn) {

	//	alert("Altering links to other sites...");

		var thisURL = document.location.href.substring(0,document.location.href.indexOf("/",7));
		var linkURL;

		for(var x=0; x < document.links.length; x++)
		{
			linkURL = document.links[x].href.substring(0,document.links[x].href.indexOf("/",7))
			if (linkURL != thisURL)
			{
				if (linkURL.indexOf("its-teachers.") >= 0) {
					document.links[x].href = "/transfer-submit.asp?site=its-teachers&redirect=" + escape(document.links[x].href)
				} else if (linkURL.indexOf("its-english.") >= 0) {
					document.links[x].href = "/transfer-submit.asp?site=its-english&redirect=" + escape(document.links[x].href)
				} else if (linkURL.indexOf("its-myworld.") >= 0) {
					document.links[x].href = "/transfer-submit.asp?site=its-myworld&redirect=" + escape(document.links[x].href)
//				} else if (linkURL.indexOf("its-open.") >= 0) {
//					document.links[x].href = "/transfer-submit.asp?site=its-open&redirect=" + escape(document.links[x].href)
				} else if (linkURL.indexOf("3sixty5.") >= 0) {
					document.links[x].href = "/transfer-submit.asp?site=3sixty5&redirect=" + escape(document.links[x].href)
				} else if (linkURL.indexOf("its-online.") >= 0) {
					document.links[x].href = "/transfer-submit.asp?site=its-online&redirect=" + escape(document.links[x].href)
				}
			}
		}
	}
}
document.nl_config.add("onload","addTransferFunctions();");

/*******************************************************************/


/*******************************************************************/
// customised popup functions
/*******************************************************************/
function itsPersonPopup(url) {
	its_popupWindow(url,'personpopup',500,350,'xrs');
}
function itsContactUsPopup(url) {
	its_popupWindow(url,'contactus',500,450,'xrs');
}
/*******************************************************************/


/*******************************************************************/
// functions for searching on the site
/*******************************************************************/
function submitSearchForm(form) {
	if (form.QUERY.value == "" || form.QUERY.value == "Search")
	{
		alert("Please enter the words you want to search for.");
		form.QUERY.focus();
		return false;
	}
	return true;
}
function searchFocus(text) {
	if (text.style)
	{
		text.style.background = "#fff";
	}
	if (text.value == "Search")
	{
		text.value = "";
	}
}
function searchBlur(text) {
	if (text.style)
	{
		text.style.background = "";
	}
	if (text.value == "")
	{
		text.value = "Search";
	}
}
/*******************************************************************/


/*******************************************************************/
// functions for navigating on the site
/*******************************************************************/
function submitAddressForm(form) {
	if (form.HOMEPAGE_ID.value == "" || form.HOMEPAGE_ID.value == "Address")
	{
		alert("Please enter the address of the site to go to.");
		form.HOMEPAGE_ID.focus();
		return false;
	}
	return true;
}
function addressFocus(text) {
	if (text.style)
	{
		text.style.background = "#fff";
	}
	if (text.value == "Address")
	{
		text.value = "";
	}
}
function addressBlur(text) {
	if (text.style)
	{
		text.style.background = "";
	}
	if (text.value == "")
	{
		text.value = "Address";
	}
}
/*******************************************************************/


/***********************************************
* AnyLink Drop Down Menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

// Use as follows:
// <a href="link.htm" onMouseover="dropdownmenu(this, event, menu1, '')" onMouseout="delayhidemenu()">

//Contents for menu 1
var menu1=new Array()
menu1[menu1.length]='<a href="/catalogue/default.asp">Catalogue Home</a>'
menu1[menu1.length]='<a href="/catalogue/younglearners/young-learners-go.asp">&nbsp; Young Learners Go!</a>'
menu1[menu1.length]='<a href="/catalogue/general/just-right.asp">&nbsp; The Just Right Course</a>'
menu1[menu1.length]='<a href="/catalogue/business/for-business.asp">&nbsp; English for Business Life</a>'
menu1[menu1.length]='<a href="/catalogue/exams/bulats.asp">&nbsp; Achieve BULATS</a>'
menu1[menu1.length]='<a href="/catalogue/exams/ielts.asp">&nbsp; Achieve IELTS</a>'
menu1[menu1.length]='<a href="/catalogue/grammar/real-english.asp">&nbsp; Real English Grammar</a>'
menu1[menu1.length]='<a href="/catalogue/skills/just-skills.asp">&nbsp; Just Skills</a>'

var menuwidth='150px' //default menu width
var menubgcolor='#aaaaaa'  //menu bgcolor
var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editing needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

//if (ie4||ns6)
//document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top=-500
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth){
if (window.event) event.cancelBubble=true
else if (e.stopPropagation) e.stopPropagation()
clearhidemenu()
dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
populatemenu(menucontents)

if (ie4||ns6){
showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
dropmenuobj.x=getposOffset(obj, "left")
dropmenuobj.y=getposOffset(obj, "top")
dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
}

return clickreturnvalue()
}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
document.onclick=hidemenu