// Legacy error messages
function remoteTP(){
	//win2=window.open("custom_content/popuploginTP.asp","",'toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,width=180,height=220,');
	//win2.creator=self;
	requiresTeachitWorks();
}

function ShowTPWarning() {
	//alert("This resource is only available to Teachit.plus members");
	requiresTeachitPlus();
}

function ShowNMWarning() {
	//alert("This resource is only available to Teachit members");
	requiresTeachitPlus();
}

// New error functions
function requiresRegistration(intWidth,intHeight) {
	if(intWidth === undefined){
		intWidth=180;
	}
	if(intHeight === undefined){
		intHeight=220;
	}
	openWindow("applocal/popupErrorRegistrationReq.html", intWidth, intHeight);
}

function requiresTeachitPlus(intWidth,intHeight) {
	if(intWidth === undefined){
		intWidth=180;
	}
	if(intHeight === undefined){
		intHeight=220;
	}
	//openWindow("applocal/popupErrorL1Req.html", intWidth, intHeight);
	if(!g_isAQA && !g_isResult && (g_GroupID == 52 || g_GroupID == 53 || g_GroupID == 54 || g_GroupID == 55 || g_GroupID == 71 ||g_GroupID == 79))
		redirectToLapsedPage();
	else	
		window.location.href = "?currmenu=1000&referer=" + encodeURIComponent(window.location);
}

function requiresTeachitWorks(intWidth,intHeight) {
	if(intWidth === undefined){
		intWidth=180;
	}
	if(intHeight === undefined){
		intHeight=220;
	}
	//openWindow("applocal/popupErrorL2Req.html", intWidth, intHeight);
	if(!g_isAQA && !g_isResult && (g_GroupID == 52 || g_GroupID == 53 || g_GroupID == 54 || g_GroupID == 55 || g_GroupID == 71 || g_GroupID == 79))
		redirectToLapsedPage();
	else
		window.location.href = "?currmenu=1014&referer=" + encodeURIComponent(window.location);
}

function requiresTeachitLanguage(intWidth,intHeight) {
	if(intWidth === undefined){
		intWidth=180;
	}
	if(intHeight === undefined){
		intHeight=220;
	}
	//openWindow("applocal/popupErrorL3Req.html", intWidth, intHeight);
	if(!g_isAQA && !g_isResult && (g_GroupID == 52 || g_GroupID == 53 || g_GroupID == 54 || g_GroupID == 55 || g_GroupID == 71 || g_GroupID == 79))
		redirectToLapsedPage();
	else		
		window.location.href = "?currmenu=1019&referer=" + encodeURIComponent(window.location);
}

function requiresLevel0(intWidth,intHeight) {
	if(intWidth === undefined){
		intWidth=360;
	}
	if(intHeight === undefined){
		intHeight=300;
	}
	if(!g_isAQA && !g_isResult && (g_GroupID == 52 || g_GroupID == 53 || g_GroupID == 54 || g_GroupID == 55 || g_GroupID == 71 || g_GroupID == 79))
		redirectToLapsedPage();
	else{		
		if(!g_isAQA && !g_isResult && g_siteID == 1)
			window.location.href = "?currmenu=982&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID == 2)
			window.location.href = "?currmenu=1060&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID == 3)
			window.location.href = "?currmenu=1064&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID > 5)
			window.location.href = "?currmenu=oops0&referer=" + encodeURIComponent(window.location);
		else
			openWindow("applocal/popupErrorL0Req.html", intWidth, intHeight);
	}
}
function requiresLevel0a(intWidth,intHeight) {
	if(intWidth === undefined){
		intWidth=360;
	}
	if(intHeight === undefined){
		intHeight=300;
	}
	if(!g_isAQA && !g_isResult && (g_GroupID == 52 || g_GroupID == 53 || g_GroupID == 54 || g_GroupID == 55 || g_GroupID == 71 || g_GroupID == 79))
		redirectToLapsedPage();
	else{		
		if(!g_isAQA && !g_isResult && g_siteID == 1)
			window.location.href = "?currmenu=982&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID == 2)
			window.location.href = "?currmenu=1060&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID == 3)
			window.location.href = "?currmenu=1064&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID > 5)
			window.location.href = "?currmenu=oops0&referer=" + encodeURIComponent(window.location);
		else
			openWindow("applocal/popupErrorL0aReq.html", intWidth, intHeight);
	}
}

function requiresLevel1(intWidth,intHeight) {
	if(intWidth === undefined){
		intWidth=180;
	}
	if(intHeight === undefined){
		intHeight=220;
	}
	if(!g_isAQA && !g_isResult && (g_GroupID == 52 || g_GroupID == 53 || g_GroupID == 54 || g_GroupID == 55 || g_GroupID == 71 || g_GroupID == 79))
		redirectToLapsedPage();
	else{	
		if(!g_isAQA && !g_isResult && g_siteID == 1)
			window.location.href = "?currmenu=1000&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID == 2)
			window.location.href = "?currmenu=1061&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID == 3)
			window.location.href = "?currmenu=1065&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID > 5)
			window.location.href = "?currmenu=oops1&referer=" + encodeURIComponent(window.location);
		else
			openWindow("applocal/popupErrorL1Req.html", intWidth, intHeight);
	}
}

function requiresLevel2(intWidth,intHeight) {
	if(intWidth === undefined){
		intWidth=180;
	}
	if(intHeight === undefined){
		intHeight=220;
	}
	if(!g_isAQA && !g_isResult && (g_GroupID == 52 || g_GroupID == 53 || g_GroupID == 54 || g_GroupID == 55 || g_GroupID == 71 || g_GroupID == 79))
		redirectToLapsedPage();
	else{
		if(!g_isAQA && !g_isResult && g_siteID == 1)
			window.location.href = "?currmenu=1014&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID == 2)
			window.location.href = "?currmenu=1062&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID == 3)
			window.location.href = "?currmenu=1066&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID > 5)
			window.location.href = "?currmenu=oops2&referer=" + encodeURIComponent(window.location);
		else
		openWindow("applocal/popupErrorL2Req.html", intWidth, intHeight);
	}
}

function requiresLevel3(intWidth,intHeight) {
	if(intWidth === undefined){
		intWidth=180;
	}
	if(intHeight === undefined){
		intHeight=220;
	}
	if(!g_isAQA && !g_isResult && (g_GroupID == 52 || g_GroupID == 53 || g_GroupID == 54 || g_GroupID == 55 || g_GroupID == 71 || g_GroupID == 79))
		redirectToLapsedPage();
	else{
		if(!g_isAQA && !g_isResult && g_siteID == 1)
			window.location.href = "?currmenu=1019&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID == 2)
			window.location.href = "?currmenu=1063&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID == 3)
			window.location.href = "?currmenu=1067&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID > 5)
			window.location.href = "?currmenu=oops3&referer=" + encodeURIComponent(window.location);
		else
		openWindow("applocal/popupErrorL3Req.html", intWidth, intHeight);
	}
}

function upgradeLevel2(intWidth,intHeight) {
	if(intWidth === undefined){
		intWidth=180;
	}
	if(intHeight === undefined){
		intHeight=220;
	}
	if(!g_isAQA && !g_isResult && (g_GroupID == 52 || g_GroupID == 53 || g_GroupID == 54 || g_GroupID == 55 || g_GroupID == 71 || g_GroupID == 79))
		redirectToLapsedPage();
	else{
		if(!g_isAQA && !g_isResult && g_siteID == 1)
			window.location.href = "?currmenu=1014&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID == 2)
			window.location.href = "?currmenu=1062&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID == 3)
			window.location.href = "?currmenu=1066&referer=" + encodeURIComponent(window.location);
		else if(!g_isAQA && !g_isResult && g_siteID > 5)
			window.location.href = "?currmenu=oops2&referer=" + encodeURIComponent(window.location);
		else
			openWindow("applocal/popupErrorL2Upgrade.html", intWidth, intHeight);
	}
}

function openWindow(url, width, height) {
	var wh = window.open(url, "test", 'toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,width='+width+',height='+height);
	wh.creator = self;
}

function openResizableWindow(url, width, height) {
	var wh = window.open(url, "", 'toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=yes,width='+width+',height='+height);
	wh.creator = self;
}

function openScrollableResizableWindow(url, width, height) {
	var wh = window.open(url, "", 'toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,width='+width+',height='+height);
	wh.creator = self;
}

function openMenu(item, anchor) {
	if (document.getElementById) {
		var elem = document.getElementById("MENUDIV" + item);
		if (elem) {
			var tl = getParentMenuDiv(elem);
			closeMenus(tl);
			elem.style.display = "block";
			if(elem.classname)
				document.body.className = elem.className;
		}
	}
}

function closeMenus(notitem) {
	var divs = document.getElementsByTagName("div");
	for (var i = 0; i < divs.length; i++) {
		if (divs[i].id.substring(0, 7) == "MENUDIV") {
			if (getParentMenuDiv(divs[i]) != notitem) {
				divs[i].style.display="none";
			}
		}
	}
}

function getParentMenuDiv(elem) {
	var rv;
	if (elem.id && elem.id.substring(0, 7) == "MENUDIV")
		rv = elem.id;
	if (elem.parentNode)
		return getParentMenuDiv(elem.parentNode) || rv;
	return rv;
}

function positionUserMsg(message_width) {
	if (!document.getElementById) return;
	var elem = document.getElementById("divUserMsg");
	if (!elem) return;
	elem.style.display = "block";
	var scrollX = 0, scrollY = 0;
	if (document.body && typeof document.body.scrollTop != "undefined") {
		scrollX+= document.body.scrollLeft;
		scrollY+= document.body.scrollTop;
		if (document.body.parentNode && typeof document.body.parentNode.scrollTop != "undefined") {
			scrollX+= document.body.parentNode.scrollLeft;
			scrollY+= document.body.parentNode.scrollTop;
		}
	} else if (typeof window.pageXOffset != "undefined") {
		scrollX+= window.pageXOffset;
		scrollY+= window.pageYOffset;
	}
	var x = Math.round((getInsideWindowWidth()/2) - (document.getElementById("tblUserMsg").clientWidth / 2)) + scrollX;
	var y = Math.round((getInsideWindowHeight()/2) - 200) + scrollY;
	elem.style.top = y + "px";
	elem.style.left = x + "px";
}
function getInsideWindowHeight() {
	if (window.innerHeight) {
		return window.innerHeight;
	} else if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) {
		return document.body.parentElement.clientHeight;
	} else if (document.body && document.body.clientHeight) {
		return document.body.clientHeight;
	}
	return 800;
}
function getInsideWindowWidth() {
	if (window.innerWidth) {
		return window.innerWidth;
	} else if (document.compatMode && document.compatMode.indexOf("CSS1") >= 0) {
		return document.body.parentElement.clientWidth;
	} else if (document.body && document.body.clientWidth) {
		return document.body.clientWidth;
	}
	return 800;
}
function closeUserMsg() {
	document.getElementById("divUserMsg").style.display = "none";
}
var xLoad = window.onload;
window.onload = function () { positionUserMsg(); if (xLoad) xLoad(); };
var xResize = window.onresize;
window.onresize = function () { positionUserMsg(); if (xResize) xResize(); };

//Firefox & Chrome & Safari & IE9
if (document.addEventListener){
	document.addEventListener("DOMContentLoaded", usernameFocus, false );
	document.addEventListener("DOMContentLoaded", addImageTitles, false );
}
// IE7 & IE8
else if (document.attachEvent){
	document.attachEvent("onreadystatechange", usernameFocus, false );
	document.attachEvent("onreadystatechange", addImageTitles, false );
}


function calculateInstitutionPrice(intTeachers){
		bolEmail = 0
		if(intTeachers>=0){
			if(intTeachers<=100){
				if(intTeachers<=10){
					fltPrice = 25;
					fltNormalPrice = 25;
				}else if(intTeachers<=50){
					fltPrice = 17.5;
					fltNormalPrice = 17.5;
				}else{
					fltPrice = 15;
			 		fltNormalPrice = 15;
				}
				fltTotalPrice = fltPrice * intTeachers;
				fltTotalPrice = fltTotalPrice.toFixed(2);
				fltTotalNormalPrice = fltNormalPrice * intTeachers;
				fltTotalNormalPrice = fltTotalNormalPrice.toFixed(2);
				strText = "*Special Offer* - Total price for 1st year = £" + fltTotalPrice;
				strText2 = "Total price per year = £" + fltTotalNormalPrice;
			}else{ 
				strText = 'Please e-mail <a href="mailto:membership@teachitworld.com">membership@teachitworld.com</a> for bespoke quotation';
				//strText = "Please e-mail "
				strText2 = ""
				//bolEmail = 1
			}
		}else{
			strText = "Invalid number of teachers";
			strText2 = "";
		}

	document.getElementById("institution_price_span").innerHTML = strText;
	document.getElementById("institution_normal_price_span").innerHTML = strText2;

}

var g_siteDesc = "My Content";
function addToMyTeachit(intResource, intSite, strDesc){
	g_siteDesc = strDesc;
	utilFetchXML('application/favourites/addtomyteachitxml.asp?resource=' + intResource + '&works=0&site=' + intSite,addToMyTeachitPopup,null);
	return false;
}

function addAllToMyTeachit(strResources, intRelatedID, strDesc){
	g_siteDesc = strDesc;
	utilFetchXML('index.asp?action=addsearchtomycontent&relatedid=' + intRelatedID + '&resources=' + strResources,addAllToMyTeachitPopup,null);
	return false;
}

function addToMyTeachitWorks(intResource, intSite, strDesc){
	g_siteDesc = strDesc;
	utilFetchXML('application/favourites/addtomyteachitxml.asp?resource=' + intResource + '&works=1&site=' + intSite,addToMyTeachitPopup,null);
	return false;
}

function addToMyLea(intResource, intSite, intGroup, strDesc){
	g_siteDesc = strDesc;
	utilFetchXML('application/favourites/addtomyteachitxml.asp?resource=' + intResource + '&works=2&site=' + intSite + "&group=" + intGroup,addToMyLeaPopup,null);
	return false;
}

function addAllToMyTeachitPopup(){
	var strDiv = 'content';

	popShowWindow(strDiv, 'over', '<div id="resourcepop" style="position:absolute; width: 200px; border: 1px solid #000; text-align: center; padding: 20px; background-color: #FFF">Resources added to ' + g_siteDesc + '</div>', "ADDTOTEACHIT");

	if (!document.getElementById) return;
	var elem = document.getElementById("resourcepop");
	if (!elem) return;
	elem.style.display = "block";
	var scrollX = 0, scrollY = 0;
	if (document.body && typeof document.body.scrollTop != "undefined") {
		scrollX+= document.body.scrollLeft;
		scrollY+= document.body.scrollTop;
		if (document.body.parentNode && typeof document.body.parentNode.scrollTop != "undefined") {
			scrollX+= document.body.parentNode.scrollLeft;
			scrollY+= document.body.parentNode.scrollTop;
		}
	} else if (typeof window.pageXOffset != "undefined") {
		scrollX+= window.pageXOffset;
		scrollY+= window.pageYOffset;
	}
	var x = Math.round((getInsideWindowWidth()/2) - (elem.clientWidth / 2)) + scrollX;
	var y = Math.round((getInsideWindowHeight()/2) - 200) + scrollY;
	elem.style.top = y + "px";
	elem.style.left = x + "px";

	setTimeout('document.getElementById("resourcepop").style.display = "none"',4000);
}

function addToMyTeachitPopup(p1,p2,p3){
	var intSite = p1.firstChild.firstChild.nodeValue;
	var strDiv = 'content';
	if(intSite == 2 && g_siteDesc == "My Teachit Primary"){
		strDiv = 'content_home';
	}

	popShowWindow(strDiv, 'over', '<div id="resourcepop" style="position:absolute; width: 200px; border: 1px solid #000; text-align: center; padding: 20px; background-color: #FFF">Resource added to ' + g_siteDesc + '</div>', "ADDTOTEACHIT");

	if (!document.getElementById) return;
	var elem = document.getElementById("resourcepop");
	if (!elem) return;
	elem.style.display = "block";
	var scrollX = 0, scrollY = 0;
	if (document.body && typeof document.body.scrollTop != "undefined") {
		scrollX+= document.body.scrollLeft;
		scrollY+= document.body.scrollTop;
		if (document.body.parentNode && typeof document.body.parentNode.scrollTop != "undefined") {
			scrollX+= document.body.parentNode.scrollLeft;
			scrollY+= document.body.parentNode.scrollTop;
		}
	} else if (typeof window.pageXOffset != "undefined") {
		scrollX+= window.pageXOffset;
		scrollY+= window.pageYOffset;
	}
	var x = Math.round((getInsideWindowWidth()/2) - (elem.clientWidth / 2)) + scrollX;
	var y = Math.round((getInsideWindowHeight()/2) - 200) + scrollY;
	elem.style.top = y + "px";
	elem.style.left = x + "px";

	setTimeout('document.getElementById("resourcepop").style.display = "none"',4000);
}

function addToMyLeaPopup(p1,p2,p3){
	
	var intGroup = p1.firstChild.firstChild.nodeValue;
	var strDiv = 'content';
	
	popShowWindow(strDiv, 'over', '<div id="resourcepop" style="position:absolute; width: 200px; border: 1px solid #000; text-align: center; padding: 20px; background-color: #FFF">Resource added to ' + g_siteDesc + '</div>', "ADDTOTEACHIT");

	if (!document.getElementById) return;
	var elem = document.getElementById("resourcepop");
	if (!elem) return;
	elem.style.display = "block";
	var scrollX = 0, scrollY = 0;
	if (document.body && typeof document.body.scrollTop != "undefined") {
		scrollX+= document.body.scrollLeft;
		scrollY+= document.body.scrollTop;
		if (document.body.parentNode && typeof document.body.parentNode.scrollTop != "undefined") {
			scrollX+= document.body.parentNode.scrollLeft;
			scrollY+= document.body.parentNode.scrollTop;
		}
	} else if (typeof window.pageXOffset != "undefined") {
		scrollX+= window.pageXOffset;
		scrollY+= window.pageYOffset;
	}
	var x = Math.round((getInsideWindowWidth()/2) - (elem.clientWidth / 2)) + scrollX;
	var y = Math.round((getInsideWindowHeight()/2) - 200) + scrollY;
	elem.style.top = y + "px";
	elem.style.left = x + "px";

	setTimeout('document.getElementById("resourcepop").style.display = "none"',4000);
}

function changeImg(imgId, imgSrc) {
	var elem = document.getElementById(imgId);
	if (elem)
		elem.src = "/custom_content/images/" + imgSrc;
}

function ChangeImageOnRollover(image,file){
    image.src = file;
}

function redirectToLapsedPage(){
	if(g_GroupID == 52)
		window.location.href = "?currmenu=892&referer=" + encodeURIComponent(window.location);
	else if(g_GroupID == 53)
		window.location.href = "?currmenu=893&referer=" + encodeURIComponent(window.location);
	else if(g_GroupID == 54)
		window.location.href = "?currmenu=894&referer=" + encodeURIComponent(window.location);
	else if(g_GroupID == 71)
		window.location.href = "?currmenu=1620&referer=" + encodeURIComponent(window.location);
	else if(g_GroupID == 79)
		window.location.href = "?currmenu=1531&referer=" + encodeURIComponent(window.location);
	else
		window.location.href = "?currmenu=895&referer=" + encodeURIComponent(window.location);
}	

function TogglePrivacy(){
	var username = document.getElementById('usernamespan');
	var privacy = document.getElementById('privacy');
	var toggleprivacy = document.getElementById('toggleprivacy');
	var usernametb = document.getElementById('username');

	if(privacy.value.length > 0){
		privacy.value = '';
		username.innerHTML = "<input type=\"text\" title=\"Username\"  style=\"width:120px; margin-right:10px; margin-left:14px;\" name=\"username\" id=\"username\" onfocus='this.select();' value=\"" + usernametb.value + "\" />";
		toggleprivacy.innerHTML = 'Hide username';
	}
	else{
		privacy.value = 1;
		username.innerHTML = "<input type=\"password\" title=\"Username\"  style=\"width:120px; margin-right:10px; margin-left:14px;\" name=\"username\" id=\"username\" onfocus='this.select();' value=\"" + usernametb.value + "\" />";
		toggleprivacy.innerHTML = 'Show username'
	}

}

function usernameFocus(){
	if(document.getElementById('username')){
		document.getElementById('username').focus();
		document.getElementById('username').select();
	}
}

function addImageTitles(){
	var contentdiv;
	if(!g_isAQA && !g_isResult && g_siteID == 2)
		contentdiv = "middleholder";
	else if(g_isAQA)
		contentdiv = "pagemain";
	else
		contentdiv = "centrepanel";
	var images = document.getElementById(contentdiv).getElementsByTagName('img');
	var i;
	for (i=0;i<images.length;i++){
		if(images[i].title.length == 0 && images[i].alt.length > 0)
			images[i].title = images[i].alt;
	}
}



