// OLC TEST POPUP
function MM_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}

function MM_findObj(n, d) { //v4.0
	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 && document.getElementById) x=document.getElementById(n); return x;
}

function MM_showHideLayers() { //v3.0
	var i,p,v,obj,args=MM_showHideLayers.arguments;
	for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
	obj.visibility=v; }
}

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_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 MM_goToURL() { //v3.0
	var i, args=MM_goToURL.arguments;
	document.MM_returnValue = false;
	for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

// Menu Item Swapper 1.1
// by Pete Fairhurst [rewrite]
function menuPopUp(i,j,k) {
		for (l=j; l<=k; l++) {
			eval ('document.getElementById("linkTable' + l + '").style.visibility = "hidden"');
		}
	eval ('document.getElementById("linkTable' + i + '").style.visibility = "visible"');
}

// Menu Item Swapper 2.1
// by Pete Fairhurst [rewrite]
function menuPopUp2(i) {
		eval("document.getElementById('reveal" + i + "').style.visibility = 'visible'");
}

// Menu Item Swapper 3.1
// by Pete Fairhurst [rewrite]
function menuPopUp3(i,j,k) {
	for (l=j; l<=k; l++) {
		eval ("document.getElementById('answer" + l + "').style.visibility = 'hidden'");
	}
	eval ("document.getElementById('answer" + i + "').style.visibility = 'visible'");
}

function clearText(thefield){
	if (thefield.defaultValue==thefield.value)
		thefield.value = ""
}

// Bubble Image Reveal 1.1
// by Pete Fairhurst [rewrite]
function bubbleView(i) {
	eval ('document.getElementById("thought' + i + '").style.visibility = "visible"');
}

// Bubble Image Hide 1.1
// by Pete Fairhurst [rewrite]
function bubbleHide(i) {
	eval ('document.getElementById("thought' + i + '").style.visibility = "hidden"');
}

// Text Hide 1.1
// by Pete Fairhurst [rewrite]
function textHide(j,k) {
	for (l=j; l<=k; l++) {
		eval ('document.getElementById("answer' + l + '").style.visibility = "hidden"');
	}
}

// Table Item Reveal 1.1
// by Pete Fairhurst [rewrite]
function tableShow(i) {
	eval ('document.getElementById("ans' + i + '").style.visibility = "visible"');
}

function openMyacc(url){
	window.open(url, 'bgWindow', 'width=633,height=480,status,scrollbars,top=24,left=32');
}

function doButtons(objName, imgSource) {
	document[objName].src=imgSource;
}

function rollover(id, state) {
	if (!document.getElementById) return;
	obj = document.getElementById(id);
	obj.src = './_common/images/' + id + '_' + state + '.gif';
}

function printpage(url){
	maccw=window.open(url,"printpage","width=570,height=480,top=40,left=40 scrollbars=yes menubar=no resizable=no status=no toolbar=no");
}

function printOnLoad() {
	window.print();
}

// Image Swapper 1.1
// by Pete Fairhurst [rewrite]
function imgswap(name, num) {
	document.getElementById("pic1").src = myimgs[(num-1)].src;
}

// Lean, Mean Image Swapping Machine 1.4
// by Pete Fairhurst (peterf@sfe-training.co.uk)
function swapImage(objName, imgPath) {
	document[objName].src=imgPath;
}

// THIS IS THE TABBING SCRIPT FOR FLASH SWFs
function makeFocus() {
	var x=document.anchors
	x("exit").focus()
}

// Appendices Window 1.0
// by Pete Fairhurst
// function openApps(url){
// 	appWin=window.open(url,'appWindow','width=640,height=480,top=16,left=16 scrollbars=yes menubar=no resizable=no status=yes toolbar=no');
// }

// Appendices Window 1.1
// by Pete Fairhurst
// function openApps(url){
// 	appWin=window.open(url,'appWindow','width=640,height=480,status,scrollbars,top=24,left=32');
// }

// Show/Hide DHTML Switch 1.1
// by Pete Fairhurst (peterf@sfe-training.co.uk)
function showHide(id) {
	if (!document.getElementById) return;
	var obj = document.getElementById(id);
	var hidden = (obj.style.display != "block");
	var shown = (obj.style.display != "none");
	if (hidden) {
		obj.style.display = "block";
	} else {
		obj.style.display = "none";
	}
}

// Quick 'n' Dirty DHTML Show/Hide Switch 1.3
// by Pete Fairhurst
function showHideState (id,state) {
	if (!document.getElementById) return;
	obj = document.getElementById(id);
	if (state != 'show') {
		obj.style.visibility = "hidden";
	} else {
		obj.style.visibility = "visible";
	}
}

//	function unFocus(x) {
//		if (navigator.appName == 'Microsoft Internet Explorer' || document.all)
//			x.blur();
//	}

// Activities Window 1.0
// by Pete Fairhurst
function openActs(url){
	window.open(url,'actWindow','width=640,height=480,status,scrollbars,resizable,top=24,left=32');
	// return false;
}

// Appendices Window 1.4
// by Pete Fairhurst
function openApps(url){
	window.open(url,'appWindow','width=640,height=480,status,scrollbars,top=24,left=32');
	// return false;
}

// Interviews Window 1.0
// by Pete Fairhurst
function openInts(swf){
	window.open('swf/' + swf + '.cfm','intWindow','height=374,width=661,top=24,left=32');
	// return false;
}

// Previews Window 1.0
// by Pete Fairhurst
function openPres(swf){

	// Subject
	sbj = swf.substring(0,1);
	switch (sbj) {
		// ~~ Literacy ~~
		case("l"):
			var subject = "literacy";
			break;
		// ~~ Numeracy ~~
		case("n"):
			var subject = "numeracy";
			break;
	}

	// Module
	mod = swf.substring(2,3);
	switch (mod) {
		// ~~ Core ~~
		case("c"):
			var module = "core";
			break;
		// ~~ EAL ~~~
		case("e"):
			var module = "eal";
			break;
		// ~~ G&T ~~
		case("g"):
			var module = "gat";
			break;
		// ~~ SEN ~~
		case("s"):
			var module = "sen";
			break;
	}

	// Key Stage
	key = swf.substring(3,4);

	// Open window
	window.open('../' + subject + '/' + module + key + '/swf/' + swf + '.cfm','intWindow','height=356,width=661,top=24,left=32');
}

// Resources Window 1.0
// by Pete Fairhurst
function openRes(url){
	window.open(url,'resWindow','width=640,height=352,scrollbars,top=24,left=32');
	// return false;
}

// Appendices Link Status Bar Msgs 1.0
// by Pete Fairhurst
function appStatusOvr() {
	window.status = 'Opens the appendices window.';
	return true;
}
function appStatusOff() {
	window.status = '';
	return true;
}

// Stores the user agent string as a variable,
// converting it to lowercase in the process.
var agentX = navigator.userAgent.toLowerCase();

//	'SmartLinks' 1.2
//	by Pete Fairhurst
function pf_SmartLinks(id,val) {
	if (!document.getElementById) return;
	// if (agentX.indexOf( 'lynx' || 'links' || 'window-eyes' ) != 1) {
		obj = document.getElementById(id);
		typ = id.substring(0,3);
		switch (typ) {
			// ~~ Activity ~~
			case("act"):
				obj.href = "javascript:openApps('append/" + val + ".cfm');";
				break;
			// ~~ Appendices ~~
			case("app"):
				obj.href = "javascript:openApps('append/" + val + ".cfm');";
				break;
			// ~~ Bibliography ~~
			case("bib"):
				obj.href = "javascript:openMyacc('../../bib_glos/bib_gloss_frameset.cfm?type=bibliography&amp;word=" + val + "');";
				break;
			// ~~ Glossary ~~
			case("glo"):
				obj.href = "javascript:openMyacc('../../bib_glos/bib_gloss_frameset.cfm?type=glossary&amp;word=" + val + "');";
				break;
			// ~~ Resource ~~
			case("res"):
				obj.href = "javascript:openRes('../../../search_moreinfo.cfm?" + val + "');";
				break;
			// ~~ Reviews ~~
			case("rev"):
				obj.href = "javascript:openApps('../../all_reviews.cfm?" + val + "');";
				break;
		}
	// }
}

//	Window Status Messaging 1.4 (for DfES)
//	by Pete Fairhurst
function pf_WinStat(typ) {
	if (typ != "") {
		switch (typ) {
			// ~~ Activities ~~
			case("act"):
				window.status = "Click to open the Activity window";
				break;
			// ~~ Appendices ~~
			case("app"):
				window.status = "Click to open the Appendices window";
				break;
			// ~~ Bibliography ~~
			case("bib"):
				window.status = "Click to open the Bibliography window";
				break;
			// ~~ Glossary ~~
			case("glo"):
				window.status = "Click to open the Glossary window";
				break;
			// ~~ Resources ~~
			case("res"):
				window.status = "Click to view this Lesson Resource in a seperate window";
				break;
			// ~~ Reviews ~~
			case("rev"):
				window.status = "Click to open the Review window";
				break;
		}
	} else {
		window.status = "";
	}
	return true;
}

function popup(url) {
	fileInfo = window.open(url,"popUpInfo","width=400,height=400,top=24,left=32,scrollbars")
}

function openNotepad(url) {
	newNotepad = window.open(url,"myNotepad","width=608,height=405,top=24,left=32,scrollbars=0")
}

function openFeedback(url) {
	newFeedback = window.open(url,'myFeedback','width=600,height=381,status,top=24,left=32');
}

//	function openFeedback(url) {
//		newFeedback = window.open(url,"myNotepad","width=608,height=405,top=24,left=32,scrollbars=0")
//	}

function confirmSubmit(type) {
	if (type != "") {
		switch(type) {
			// ~~ Activities ~~
			case("activity"):
			var msg = "Are you sure you wish to submit this activity/task feedback?\n Click OK to continue, or Cancel to make amendments.";
			break;
			// ~~ New Threads ~~
			case("new"):
			var msg = "Before you submit this message, please confirm the following;\n\n 1. Subject is filled in\n 2. Description has been completed\n 3. Message body has content\n \n If all of the above are true, click OK to continue.\n \n Otherwise, click Cancel to make any necessary amendments.";
			break;
			// ~~ Reply to Thread ~~
			case("reply"):
			var msg = "If you are happy that this Reply is ready, click OK.\n \n Otherwise, click Cancel to make amendments.";
			break;
		}
	}
	var agree = confirm(msg);
	if (agree) return true;
	else return false;
}

// "Required Fields" Form Checker 1.0
// by Pete Fairhurst
function checkRequired(formName) {
	for (var i = 0; i < document[formName].elements.length; i++) {
		if ((document[formName].elements[i].name.indexOf("req_") > -1)) {
			if (document[formName].elements[i].value == "") {
				var title = document[formName].elements[i].title;
				var msg = "WARNING - Information Missing\n\nThe " + title + " field requires content but appears to be empty.\n\nPlease ensure that *all* required fields are completed.";
				var alertMsg = alert(msg);
				document[formName].elements[i].focus();
				return false;
				break;
			}
		} else if ((document[formName].elements[i].name.indexOf("req_") == 0)) {
			var msg = "ERROR - Parameters Missing\n\nYou have not prefixed any field names with \"req_\"\n\n- therefore the checkRequired(); function failed.";
			var alertMsg = alert(msg);
			return false;
		}
	}
}

//	function selectAnswer(num,state) {
//		if (!document.getElementById) return;
//		var id = "select_answer_" + num;
//		var obj = document.getElementById(id);
//		obj.src = "_common/images/icon_" + state + ".gif";
//	}

function selectAnswer(num) {
	if (!document.getElementById) return;
	var select_id = "select_" + num;
	var obj = document.getElementById(select_id);
	var state = obj.value;
	var answer_id = "select_answer_" + num;
	var icon = document.getElementById(answer_id);
	icon.src = "_common/images/icon_" + state + ".gif";
}

function checkScore(formName) {
	var totalScore = 0;
	for (var i = 0; i < document[formName].elements.length; i++) {
		if ((document[formName].elements[i].name.indexOf("q_") > -1)) {
			if ((document[formName].elements[i].checked == true)) {
				totalScore = parseInt(totalScore) + parseInt(document[formName].elements[i].value);
			}
		}
	}
	document[formName].myScore.value = totalScore;
}

function checkScoreType(formName,typeName) {
	var typeScore = 0;
	for (var i = 0; i < document[formName].elements.length; i++) {
		if ((document[formName].elements[i].name.indexOf(typeName + "_") > -1)) {
			// if ((document[formName].elements[i].checked == true)) {
				typeScore = parseInt(typeScore) + parseInt(document[formName].elements[i].value);
			// }
		}
	}
	obj = document.getElementById("myScore_" + typeName);
	obj.value = typeScore;
}

function checkSlideScore(formName) {
	var totalScore = 0;
	for (var i = 0; i < document[formName].elements.length; i++) {
		if ((document[formName].elements[i].name.indexOf("q_") > -1)) {
			totalScore = parseInt(totalScore) + parseInt(document[formName].elements[i].value);
		}
	}
	document[formName].myScore.value = totalScore;
}

function openEditor(url,thread,post) {
	editorUrl = url + "?thread=" + thread + "&post=" + post;
	editWindow = window.open(editorUrl,"editWindow","width=710,height=382,top=24,left=32");
	// if (editWindow.opener == null) {
	// 	editWindow.opener = self;
	// }
}

function closeUpdate() {
	top.opener.window.location.href = top.opener.window.location.href;
	window.close();
}