//open a pop-up window
function openWin(url,winWidth,winHeight){
aWindow=window.open(url,"thewindow","toolbar=no,width=" + winWidth + ",height=" + winHeight + ",status=no,scrollbars=yes,resizable=yes,menubar=no,top=40,left=170");
}

//open a pop-up window at the centre of the screen
function openWinCen(url,winWidth,winHeight){
	var winl = (screen.width - winWidth) / 2;
	var wint = (screen.height - winHeight) / 2;
	aWindow=window.open(url,"newWindow","toolbar=no,width=" + winWidth + ",height=" + winHeight + ",status=no,scrollbars=yes,resizable=yes,menubar=no,left=" + winl + ",top=" + wint);
	aWindow.focus();
}

function openWinExit(url,winWidth,winHeight){
aWindow=window.open(url,"thewindow","toolbar=no,width=" + winWidth + ",height=" + winHeight + ",status=no,scrollbars=yes,resizable=yes,menubar=no,top=0,left=0");
}

//open a pop-up window at the centre of the screen
function openAudio(url,winWidth,winHeight){
	//var winl = (screen.width - winWidth) / 2;
	//var wint = (screen.height - winHeight) / 2;
	//var winl = screen.width - winWidth;
	//var wint = winHeight;
	//aWindow=window.open(url,"audioWin","toolbar=no,width=" + winWidth + ",height=" + winHeight + ",status=no,scrollbars=yes,resizable=yes,menubar=no,left=" + winl + ",top=" + wint);
	aWindow=window.open(url,"audioWin","toolbar=no,width=" + winWidth + ",height=" + winHeight + ",status=no,scrollbars=yes,resizable=yes,menubar=no,left=0,top=0");
	aWindow.focus();
}

if (document.layers) {
  visible = 'show';
  hidden = 'hide';
} else if (document.all) {
  visible = 'visible';
  hidden = 'hidden';
}

//open a pop-up window
function openWin2(url,winWidth,winHeight){
	var winl = (screen.width - winWidth) / 2;
	var wint = (screen.height - winHeight) / 2;
	aWindow=window.open(url,"audioWin","toolbar=no,width=" + winWidth + ",height=" + winHeight + ",status=no,scrollbars=yes,resizable=yes,menubar=no,left=" + winl + ",top=" + wint);
}

if (document.layers) {
  visible = 'show';
  hidden = 'hide';
} else if (document.all) {
  visible = 'visible';
  hidden = 'hidden';
}

// function revealSubLearning and menuItem in templateMisc.js

function opwin(url)
{
   theHeight = screen.availHeight * 0.8;
   window.open(url, "_self", "toolbar=yes,menubar=no,scrollbars=yes,resizable=yes,location=top,status=no,width=680,height="+theHeight+",ScreenX=0,ScreenY=0,Top=0,Left=0");
   
}

//search for a word in the Resources - Abbreviations, American/British and British/American page
var NS4 = (document.layers);
var IE4 = (document.all);

var win = this;
var n   = 0;

function findInPage(str) {
	var txt, i, found;

	if (str == "")
		return false;

	if (NS4) {
		if (!win.find(str)) {	
			while(win.find(str, false, true))
				n++;
		} else {
			n++;
		}

		if (n == 0) alert("The word " + str + " is not found on this page.");
	}
	
	if (IE4) {
		txt = win.document.body.createTextRange();

		for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
			txt.moveStart("character", 1);
			txt.moveEnd("textedit");
		}

		if (found) {
			txt.moveStart("character", -1);
			txt.findText(str);
			txt.select();
			txt.scrollIntoView();
			n++;
		} else {
			if (n > 0) {
				n = 0;
				findInPage(str);
			} else {
				alert("The word " + str + " is not found on this page.");
			}
		}
	}
return false;
}

// This script is used in admin/adm_insert_flash.asp
// Flash's file name is automatically generated when the skill, level and topic are selected
function setName(selVal, folderName, unitName, levelTopic) {
	var fileName;
	switch (selVal.value) {
		case "Intro": fileName = "../flash/IM/IM" + levelTopic + "/" + unitName + "IM.swf"; break;
		case "LO1": fileName = folderName + unitName + "Learning1.swf"; break;
		case "LO2": fileName = folderName + unitName + "Learning2.swf"; break;
		case "LO3": fileName = folderName + unitName + "Learning3.swf"; break;
		case "LO4": fileName = folderName + unitName + "Learning4.swf"; break;
		case "LO5": fileName = folderName + unitName + "Learning5.swf"; break;
		case "FunTime": fileName = folderName + unitName + "Funtime.swf"; break;
	}
	form1.ContName.value = fileName;
}

// This script is used in adm_check_credits.asp
// to add the current number of credits with the paid credits
function addCredits(newCredits, curCredits) {
	var totalCredits;
	totalCredits = parseInt(newCredits) + parseInt(curCredits);
	form1.CurrentCredit.value = totalCredits;
}

// This function adds a preloader text to the content page
// While waiting for the Flash movies to load, users will see the text
function clearPreloadPage() { //DOM
	/*
	if (document.getElementById){
		document.getElementById('prepage').style.visibility='hidden';
	} else {
		if (document.layers) { //NS4
			document.prepage.visibility = 'hidden';
		} else { //IE4
			document.all.prepage.style.visibility = 'hidden';
		}
	}
	*/
	if (document.myFlash.PercentLoaded() >= 100) {
		if (document.layers) { //NS4
			document.prepage.visibility = 'hidden';
		} else { //IE4
			document.all.prepage.style.visibility = 'hidden';
		}
	}
}

// This function checks whether a client already IEB Sound Recorder installed on
// his/her machine
function checkSound() {
	//var fso = new ActiveXObject("Scripting.FileSystemObject");
	//fileBool = fso.FileExists("C:\Program%20Files\Sound%20Recording\one.exe");
	//if (!fileBool) {
		//alert("You do not have IEB Sound Recorder program installed on your computer. Please choose to run the application when the next dialogue box appears to install the program. If you are concerned about the security issue, click Cancel. However, cancelling the installation process will not enable you to use the recording function.");
		//location.href = "../library/IEBSoundRecorder.exe";
	//} else {
		location.href = "file:///C:/Program%20Files/Sound%20Recording/one.exe";
	//}
}

function testSound() {
	var fso = new ActiveXObject("Scripting.FileSystemObject");
	fileBool = fso.FileExists("C:\Program Files\Sound Recording\one.exe");
	if (fso.FileExists("C:\Program Files\Sound Recording\one.exe")) {
		location.href = "file:///C:/Program Files/Sound Recording/one.exe";
	} else {
		location.href = "../library/IEBSoundRecorder.exe";
	}
}

function openRecorder() {
	var winl = (screen.width - 200) / 2;
	var wint = (screen.height - 50) / 2;
	aWindow = window.open("../recorder.htm","recorderWin","toolbar=no,width=200,height=50,status=no,scrollbars=no,resizable=yes,menubar=no,left=" + winl + ",top=" + wint);
}

function openRecorder2() {
	var winl = (screen.width - 200) / 2;
	var wint = (screen.height - 100) / 2;
	aWindow = window.open("../../recorder.htm","recorderWin","toolbar=no,width=200,height=100,status=no,scrollbars=no,resizable=yes,menubar=no,left=" + winl + ",top=" + wint);
}

function loadRecorder() {
	openRecorder();
}

function loadRecorder2() {
	openRecorder2();
}

function dloadRecorder() {
	var winl = (screen.width - 400) / 2;
	var wint = (screen.height - 140) / 2;
	aWindow = window.open("flash/speaking/recorder.asp","dloadRecorder","toolbar=no,width=400,height=140,status=no,scrollbars=no,resizable=yes,menubar=no,left=" + winl + ",top=" + wint);
}

// If learner closes browser without logging out, display this alert
function falseExit() {
	//window.open("killSession.asp");
	openWinExit("killSession.asp",50,50);
}

//open a pop-up window at the centre of the screen
//open a Word Power popup
function openWpDef(url){
	var winWidth = 400;
	var winHeight = 200;
	var winl = (screen.width - winWidth) / 2;
	var wint = (screen.height - winHeight) / 2;
	window.open(url,"resourceWin","toolbar=no,width=" + winWidth + ",height=" + winHeight + ",status=no,scrollbars=yes,resizable=yes,menubar=no,left=" + winl + ",top=" + wint);
}

// For Voice Manager 
function viewAct(actNum) {
	window.location = "index.asp?fileName=" + actNum.value;
}

// From Unit Summary page, confirm if user has installed the speaking package
// Is called when user selects a Speaking unit only
function confirmView() {
	var agree =	confirm("Please ensure that you have installed the programs required for some activities in the speaking units. Click OK to continue or Cancel to stay on this page and install the programs.");
	if (agree)
		return true ;
	else
		return false ;
}




