﻿/*
Edexcel Core JS developed by Creative SharePoint
Created: 15/07/2009
Developer: David Hendry
*/

function ProcessImn(){

// Initiate the Left Navigation Expandable Menus
$(document).ready(function() {
	createNavigationSelectedState(); //Static Menu Modification - 01/02/2010
     
    //Attach the click to the dropdown arrows
  	  $(".dropdown a").click($toggleLeftNavSection);
	
	//Attach the click to the Expand/Collapse Header
	 $(".cBody").hide();
	 $(".cHeader").click(function()
  		{
  		   $(this).next(".cBody").slideToggle(0);
  		});
	
      $(".edx-LeftNav li.AspNet-Menu-Selected").each(function() {
		var current = $(this);
		
	current.parent('ul').each(function(){
		$(this).show();
		var thebuttonforthisgroup = $(this).parent("li").find("> .dropdown > a");
		$toggleLeftNavSectionButton.call(thebuttonforthisgroup, null);

	});

	current.find('ul').each(function(){
		$(this).show();
	});
    });
    
	 // TweakPageTitle();
	 FindLeftNavParentLI();
	
	});
}


//Left hand menu - add class for CSS
function FindLeftNavParentLI()
{
	var jqo= $(".collapse");
    jqo.parent().parent().addClass("edx-SecondChildLI");
}


//Static Menu Modification - 01/02/2010

function createNavigationSelectedState()
{
	var sNavigationID = '';
	var hostname = window.location.hostname;
	var pearsonhost = 'pearsonwbl.edexcel.com';
	
	sNavigationID = ( hostname == pearsonhost ) ? '#edx-SiteBarPearson' : '#edx-SiteBarEdexcel';

	var sWindowPathName = window.location.pathname;
	sWindowPathName = sWindowPathName.toLowerCase();
	
	var oSecondNavLinks = $(sNavigationID + ' ul li a');
	var sPathName = '';

	oSecondNavLinks.each(function(index) {
    	
    	sPathName = this.pathname;

    	if (sPathName.substr(0,1) != '/') {
    		sPathName = '/' + sPathName;
    	}
    	
	   	if ( sWindowPathName.indexOf(sPathName.toLowerCase()) != -1 && this.hostname == hostname ) {
	        $(this).addClass('selected');
        }


    	
	});
	
	if ( $(sNavigationID + ' ul li a.selected').length > 1 )
	{
		$(sNavigationID + ' ul li a.selected:not(:last)').removeClass('selected');
	}
}
//END: Static Menu Modification - 01/02/2010

function $toggleLeftNavSection(){
	var jqo= $(this);
	$toggleLeftNavSectionButton.call(this);
	
	//Find the UL of the dropdown element and use the SlideToggle Method
    jqo.parent().parent().find("> ul").slideToggle(250);
}

function $toggleLeftNavSectionButton(){
	var jqo= $(this);
    if (jqo.hasClass("expand")){
    	jqo.removeClass("expand").addClass("collapse");
    }
    else if (jqo.hasClass("collapse")){
    	jqo.removeClass("collapse").addClass("expand");
    }
}


function ChangeFontColor(color) {
    alert("test");
    document.body.style.color = color;

}

function bookmarkthis() {

    var title = document.getElementsByTagName("title")[0].text;
    var url = location.href;


    if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {

        window.external.AddFavorite(url, title);

    } else if (navigator.appName == "Netscape") {

        window.sidebar.addPanel(title, url, "");

    } else {

        alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");

    }

}

function mailpage() {
    mail_str = "mailto:?subject= Recommended Edexcel Link";
    mail_str += "&body= " + document.title;
    mail_str += "... at: " + location.href;
    location.href = mail_str;
}

function ShowElement(elementID) {
    var srcElement = document.getElementById(elementID);
    if (srcElement != null) {
        srcElement.style.display = 'block';
    }
}

function HideElement(elementID) {
    var srcElement = document.getElementById(elementID);
    if (srcElement != null) {
        srcElement.style.display = 'none';
    }
}

function ToggleHideElement(contentElementID, displayImageID, hideImageID) {
    var contentElement = document.getElementById(contentElementID);
    var displayImage = document.getElementById(displayImageID);
    var hideImage = document.getElementById(hideImageID);


    if (contentElement != null) {
        if (contentElement.style.display == 'none') {
            contentElement.style.display = 'block';
            displayImage.style.display = 'none';
            hideImage.style.display = 'inline';
        }
        else {
            contentElement.style.display = 'none';
            displayImage.style.display = 'inline';
            hideImage.style.display = 'none';
        }
    }
}

function ExpGroupByNew(formObj, el) {
    // this is the part that prevents it working in Firefox!
    //	if (browseris.nav) {
    //		return;
    //		}

    if ((browseris.w3c) && (!browseris.ie)) {
        docElts = document.getElementsByTagName("body")[0].getElementsByTagName("*")
    }
    else { docElts = document.all; }
    var numElts = docElts.length;
    switch (el) {
        case "img":
            parentNode = formObj.parentNode;
            if (parentNode.nodeName == "TD") {
                paras = parentNode.getElementsByTagName("P");
                titleP = paras[0];
            }
            images = formObj.getElementsByTagName("IMG");
            img = images[0];
            break;
        case "p":
            titleP = formObj;
            parentNode = formObj.parentNode;
            if (parentNode.nodeName == "TD") {
                imgLink = parentNode.firstChild;
                if (imgLink.nodeName == "A") {
                    images = imgLink.getElementsByTagName("IMG");
                    img = images[0];
                }
                else { return; }
            }
            break;
        case "span":
            parentNode = formObj.parentNode;
            if (parentNode.nodeName == "P") {
                titleP = parentNode;
                parentNode = titleP.parentNode;
                imgLink = parentNode.firstChild;
                if (parentNode.nodeName == "TD") {
                    imgLink = parentNode.firstChild;
                    if (imgLink.nodeName == "A") {
                        images = imgLink.getElementsByTagName("IMG");
                        img = images[0];
                    }
                    else { return; }
                }
                else { return; }
            }
            break;
        default:
            return;
            break;
    }
    srcPath = img.src;
    index = srcPath.lastIndexOf("/");
    imgName = srcPath.slice(index + 1);
    if (imgName == 'bluePlus.gif') {
        fOpen = true;
        displayStr = "";
        titleStyle = "openAZgroup";
        // value of displayStr changed from 'none' to prevent 'phantom rows' problem in Firefox
        img.src = '/Style Library/Edexcel/images/blueMinus.gif';
    }
    else {
        fOpen = false;
        displayStr = "none";
        titleStyle = "";
        img.src = '/Style Library/Edexcel/images/bluePlus.gif';
    }
    oldName = img.name;
    img.name = img.alt;
    img.alt = oldName;
    titleP.className = titleStyle;
    spanNode = img;

    while (spanNode != null) {
        spanNode = spanNode.parentNode;
        if (spanNode != null &&
			spanNode.id != null &&
			spanNode.id.length > 5 &&
			spanNode.id.substr(0, 5) == "group")
            break;
    }
    parentNode = spanNode;
    while (parentNode != null) {
        parentNode = parentNode.parentNode;
        if (parentNode != null &&
			parentNode.nodeName == "TABLE")
            break;
    }
    lastNode = null;
    if (parentNode != null) {
        lastNode = parentNode.lastChild;
        if (lastNode != null && lastNode.nodeName == "TBODY")
            lastNode = lastNode.lastChild;
        if (lastNode != null && lastNode.nodeName == "TR" && lastNode.lastChild != null)
            lastNode = lastNode.lastChild;
    }
    for (var i = 0; i < numElts; i++) {
        var childObj = docElts[i];
        if (childObj == spanNode)
            break;
    }
    ID = spanNode.id.slice(5);
    for (var j = i + 1; j < numElts; j++) {
        var childObj = docElts[j];
        if (childObj.id.length > 5 &&
			childObj.id.substr(0, 5) == "group") {
            curID = childObj.id.slice(5);
            if (curID <= ID)
                return;
        }
        parentNode = childObj;
        while (parentNode != null) {
            parentNode = parentNode.parentNode;
            if (parentNode == spanNode)
                break;
        }
        if (parentNode == spanNode)
            continue;
        if (childObj != img &&
			childObj.nodeName == "IMG" &&
			childObj.src &&
			childObj.src.slice(childObj.src.length - 25) == '/Style Library/Edexcel/images/bluePlus.gif') {
            childObj.src = '/images/negative.gif';
            oldName = childObj.name;
            childObj.name = childObj.alt;
            childObj.alt = oldName;
        }
        if (childObj.nodeName == spanNode.nodeName &&
			childObj.id != "footer") {
            childObj.style.display = displayStr;
        }
        if ((childObj.nodeName == "TABLE" && lastNode == null) || childObj == lastNode)
            break;
    }
}


function ExpGroupByNewImgSet2(formObj,el)
{
// this is the part that prevents it working in Firefox!
//	if (browseris.nav) {
//		return;
//		}

	if ((browseris.w3c) && (!browseris.ie)) {
		docElts = document.getElementsByTagName("body")[0].getElementsByTagName("*")
	}
	else { docElts=document.all; }
	var numElts=docElts.length;
	switch(el)
	{
	case "img":
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "TD") {
		  paras=parentNode.getElementsByTagName("span");
		  titleP=paras[0];
		  }
		images=formObj.getElementsByTagName("IMG");
		img=images[0];
		break;
	case "p":
		titleP = formObj;
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "TD") {
		    imgLink = parentNode.firstChild;
		    if (imgLink.nodeName == "A") {
	    		images=imgLink.getElementsByTagName("IMG");
				img=images[0];
				}
			else { return; }
			}
		break;
	case "span":
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "P") {
			titleP = parentNode;
			parentNode=titleP.parentNode;
	 		imgLink = parentNode.firstChild;
			if (parentNode.nodeName == "TD") {
		    	imgLink = parentNode.firstChild;
		    	if (imgLink.nodeName == "A") {
	    			images=imgLink.getElementsByTagName("IMG");
					img=images[0];
					}
				else { return; }
				}
			else { return; }
			}
		break;
	default: 
		return;
		break;
	}
	srcPath=img.src;
	index=srcPath.lastIndexOf("/");
	imgName=srcPath.slice(index+1);
	if (imgName=='plus.gif')
	{
		fOpen=true;
		displayStr="";
		titleStyle = "openAZgroup";
		// value of displayStr changed from 'none' to prevent 'phantom rows' problem in Firefox
		img.src='/Style Library/Edexcel/images/blueMinus.gif';
	}
	else
	{
		fOpen=false;
		displayStr="none";
		titleStyle="";
		img.src='/Style Library/Edexcel/images/bluePlus.gif';
	}
	oldName=img.name;
	img.name=img.alt;
	img.alt=oldName;
	titleP.className = titleStyle;
	spanNode=img;

	while(spanNode !=null)
	{
		spanNode=spanNode.parentNode;
		if (spanNode !=null &&
			spanNode.id !=null &&
			spanNode.id.length > 5 &&
			spanNode.id.substr(0, 5)=="group")
			break;
	}
	parentNode=spanNode;
	while(parentNode !=null)
	{
		parentNode=parentNode.parentNode;
		if (parentNode !=null &&
			parentNode.nodeName=="TABLE")
			break;
	}
	lastNode=null;
	if (parentNode !=null)
	{
		lastNode=parentNode.lastChild;
		if (lastNode !=null && lastNode.nodeName=="TBODY")
			lastNode=lastNode.lastChild;
		if (lastNode !=null && lastNode.nodeName=="TR" && lastNode.lastChild !=null)
			lastNode=lastNode.lastChild;
	}
for(var i=0; i < numElts; i++) {
		var childObj=docElts[i];
		if (childObj==spanNode)
			break;
	}
	ID=spanNode.id.slice(5);
	for(var j=i+1; j<numElts; j++)
	{
		var childObj=docElts[j];
		if (childObj.id.length > 5 &&
			childObj.id.substr(0, 5)=="group")
		{
			curID=childObj.id.slice(5);
			if (curID <=ID)
				return;
		}
		parentNode=childObj;
		while(parentNode !=null)
		{
			parentNode=parentNode.parentNode;
			if (parentNode==spanNode)
				break;
		}
		if (parentNode==spanNode)
			continue;
		if (childObj !=img &&
			childObj.nodeName=="IMG" &&
			childObj.src &&
			childObj.src.slice(childObj.src.length - 25)=='/Style Library/Edexcel/images/bluePlus.gif')
		{
			childObj.src='/Style Library/Edexcel/images/blueMinus.gif';
			oldName=childObj.name;
			childObj.name=childObj.alt;
			childObj.alt=oldName;
		}
		if (childObj.nodeName==spanNode.nodeName &&
			childObj.id !="footer")
		{
			childObj.style.display=displayStr;
		}
		if ((childObj.nodeName=="TABLE" && lastNode==null) || childObj==lastNode)
			break;
	}
}


//This method is the same as the one above except it uses different plus and minus images
function ExpGroupByNewImgSet3(formObj,el)
{
// this is the part that prevents it working in Firefox!
//	if (browseris.nav) {
//		return;
//		}
	
	if ((browseris.w3c) && (!browseris.ie)) {
		docElts = document.getElementsByTagName("body")[0].getElementsByTagName("*")
	}
	else { docElts=document.all; }
	var numElts=docElts.length;
	
	switch(el)
	{
	 case "img":
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "TD") {
		  paras=parentNode.getElementsByTagName("a");
		  titleP=paras[0];
		  }
		images=formObj.getElementsByTagName("IMG");
		img=images[0];
		break;
	case "p":
		titleP = formObj;
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "TD") {
		    imgLink = parentNode.firstChild;
		    if (imgLink.nodeName == "A") {
	    		images=imgLink.getElementsByTagName("IMG");
				img=images[0];
				}
			else { return; }
			}
		break;
	case "span":
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "TD") {
			titleP = parentNode;
			parentNode=titleP.parentNode;
	 		imgLink = parentNode.firstChild;
			if (parentNode.nodeName == "TD") {
		    	imgLink = parentNode.firstChild;
		    	if (imgLink.nodeName == "A") {
	    			images=imgLink.getElementsByTagName("IMG");
					img=images[0];
					}
				else { return; }
				}
			else { return; }
			}
		break;
		default:
        return;
		break;
	}
	srcPath=img.src;
	index=srcPath.lastIndexOf("/");
	imgName=srcPath.slice(index+1);
	if (imgName=='bluePlus.gif')
	{
		fOpen=true;
		displayStr="";
		titleStyle = "openAZgroup";
		// value of displayStr changed from 'none' to prevent 'phantom rows' problem in Firefox
		img.src='/Style%20Library/Edexcel/images/blueMinus.gif';
	}
	else
	{
		fOpen=false;
		displayStr="none";
		titleStyle="";
		img.src='/Style%20Library/Edexcel/images/bluePlus.gif'; 
		
	}
	oldName=img.name;
	img.name=img.alt;
	img.alt=oldName;
	titleP.className = titleStyle;
	spanNode=img;

	while(spanNode !=null)
	{
		spanNode=spanNode.parentNode;
		if (spanNode !=null &&
			spanNode.id !=null &&
			spanNode.id.length > 5 &&
			spanNode.id.substr(0, 5)=="group")
			break;
	}
	parentNode=spanNode;
	while(parentNode !=null)
	{
		parentNode=parentNode.parentNode;
		if (parentNode !=null &&
			parentNode.nodeName=="TABLE")
			break;
	}
	lastNode=null;
	if (parentNode !=null)
	{
		lastNode=parentNode.lastChild;
		if (lastNode !=null && lastNode.nodeName=="TBODY")
			lastNode=lastNode.lastChild;
		if (lastNode !=null && lastNode.nodeName=="TR" && lastNode.lastChild !=null)
			lastNode=lastNode.lastChild;
	}
for(var i=0; i < numElts; i++) {
		var childObj=docElts[i];
		if (childObj==spanNode)
			break;
	}
	ID=spanNode.id.slice(5);
	for(var j=i+1; j<numElts; j++)
	{
		var childObj=docElts[j];
		if (childObj.id.length > 5 &&
			childObj.id.substr(0, 5)=="group")
		{
			curID=childObj.id.slice(5);
			if (curID <=ID)
				return;
		}
		parentNode=childObj;
		while(parentNode !=null)
		{
			parentNode=parentNode.parentNode;
			if (parentNode==spanNode)
				break;
		}
		if (parentNode==spanNode)
			continue;
		if (childObj !=img &&
			childObj.nodeName=="IMG" &&
			childObj.src &&
			childObj.src.slice(childObj.src.length - 25)=='/Style%20Library/Edexcel/images/bluePlus.gif')
		{
			childObj.src='/Style%20Library/Edexcel/images/blueMinus.gif';
			oldName=childObj.name;
			childObj.name=childObj.alt;
			childObj.alt=oldName;
		}
		if (childObj.nodeName==spanNode.nodeName &&
			childObj.id !="footer")
		{
			childObj.style.display=displayStr;
		}
		if ((childObj.nodeName=="TABLE" && lastNode==null) || childObj==lastNode)
			break;
	}
}

//This method is the same as the one above except it uses different plus and minus images
function ExpGroupByNewImgSet4(formObj,el)
{
// this is the part that prevents it working in Firefox!
//	if (browseris.nav) {
//		return;
//		}
	
	if ((browseris.w3c) && (!browseris.ie)) {
		docElts = document.getElementsByTagName("body")[0].getElementsByTagName("*")
	}
	else { docElts=document.all; }
	var numElts=docElts.length;
	
	switch(el)
	{
	 case "img":
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "TD") {
		  paras=parentNode.getElementsByTagName("a");
		  titleP=paras[0];
		  }
		images=formObj.getElementsByTagName("IMG");
		img=images[0];
		break;
	case "p":
		titleP = formObj;
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "TD") {
		    imgLink = parentNode.firstChild;
		    if (imgLink.nodeName == "A") {
	    		images=imgLink.getElementsByTagName("IMG");
				img=images[0];
				}
			else { return; }
			}
		break;
	case "span":
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "TD") {
			titleP = parentNode;
			parentNode=titleP.parentNode;
	 		imgLink = parentNode.firstChild;
			if (parentNode.nodeName == "TD") {
		    	imgLink = parentNode.firstChild;
		    	if (imgLink.nodeName == "A") {
	    			images=imgLink.getElementsByTagName("IMG");
					img=images[0];
					}
				else { return; }
				}
			else { return; }
			}
		break;
		default:
        return;
		break;
	}
	srcPath=img.src;
	index=srcPath.lastIndexOf("/");
	imgName=srcPath.slice(index+1);
	if (imgName=='bluePlus.gif')
	{
		fOpen=true;
		displayStr="";
		titleStyle = "openAZgroup";
		// value of displayStr changed from 'none' to prevent 'phantom rows' problem in Firefox
		img.src='/Style%20Library/Edexcel/images/blueMinus.gif';
	}
	else
	{
		fOpen=false;
		displayStr="none";
		titleStyle="";
		img.src='/Style%20Library/Edexcel/images/bluePlus.gif'; 
		
	}
	oldName=img.name;
	img.name=img.alt;
	img.alt=oldName;
	titleP.className = titleStyle;
	spanNode=img;

	while(spanNode !=null)
	{
		spanNode=spanNode.parentNode;
		if (spanNode !=null &&
			spanNode.id !=null &&
			spanNode.id.length > 5 &&
			spanNode.id.substr(0, 5)=="group")
			break;
	}
	parentNode=spanNode;
	while(parentNode !=null)
	{
		parentNode=parentNode.parentNode;
		if (parentNode !=null &&
			parentNode.nodeName=="TABLE")
			break;
	}
	lastNode=null;
	if (parentNode !=null)
	{
		lastNode=parentNode.lastChild;
		if (lastNode !=null && lastNode.nodeName=="TBODY")
			lastNode=lastNode.lastChild;
		if (lastNode !=null && lastNode.nodeName=="TR" && lastNode.lastChild !=null)
			lastNode=lastNode.lastChild;
	}
for(var i=0; i < numElts; i++) {
		var childObj=docElts[i];
		if (childObj==spanNode)
			break;
	}
	ID=spanNode.id.slice(5);
	for(var j=i+1; j<numElts; j++)
	{
		var childObj=docElts[j];
		if (childObj.id.length > 5 &&
			childObj.id.substr(0, 5)=="group")
		{
			curID=childObj.id.slice(5);
			if (curID <=ID)
				return;
		}
		parentNode=childObj;
		while(parentNode !=null)
		{
			parentNode=parentNode.parentNode;
			if (parentNode==spanNode)
				break;
		}
		if (parentNode==spanNode)
			continue;
		if (childObj !=img &&
			childObj.nodeName=="IMG" &&
			childObj.src &&
			childObj.src.slice(childObj.src.length - 25)=='/Style%20Library/Edexcel/images/bluePlus.gif')
		{
			childObj.src='/Style%20Library/Edexcel/images/blueMinus.gif';
			oldName=childObj.name;
			childObj.name=childObj.alt;
			childObj.alt=oldName;
		}
		if (childObj.nodeName==spanNode.nodeName &&
			childObj.id !="footer")
		{
			childObj.style.display=displayStr;
		}
		if ((childObj.nodeName=="TABLE" && lastNode==null) || childObj==lastNode)
			break;
	}
}

//This method is the same as the one above except it uses different plus and minus images
function ExpGroupByNewImgSet5(formObj,el)
{
// this is the part that prevents it working in Firefox!
//	if (browseris.nav) {
//		return;
//		}
	
	if ((browseris.w3c) && (!browseris.ie)) {
		docElts = document.getElementsByTagName("body")[0].getElementsByTagName("*")
	}
	else { docElts=document.all; }
	var numElts=docElts.length;
	
	switch(el)
	{
	 case "img":
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "TD") {
		  paras=parentNode.getElementsByTagName("a");
		  titleP=paras[0];
		  }
		images=formObj.getElementsByTagName("IMG");
		img=images[0];
		break;
	case "p":
		titleP = formObj;
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "TD") {
		    imgLink = parentNode.firstChild;
		    if (imgLink.nodeName == "A") {
	    		images=imgLink.getElementsByTagName("IMG");
				img=images[0];
				}
			else { return; }
			}
		break;
	case "span":
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "TD") {
			titleP = parentNode;
			parentNode=titleP.parentNode;
	 		imgLink = parentNode.firstChild;
			if (parentNode.nodeName == "TD") {
		    	imgLink = parentNode.firstChild;
		    	if (imgLink.nodeName == "A") {
	    			images=imgLink.getElementsByTagName("IMG");
					img=images[0];
					}
				else { return; }
				}
			else { return; }
			}
		break;
		default:
        return;
		break;
	}
	srcPath=img.src;
	index=srcPath.lastIndexOf("/");
	imgName=srcPath.slice(index+1);
	if (imgName=='arrrtw.gif')
	{
		fOpen=true;
		displayStr="";
		titleStyle = "openAZgroup";
		// value of displayStr changed from 'none' to prevent 'phantom rows' problem in Firefox
		img.src='/Style Library/Edexcel/Images/International/arrdnw.gif';
	}
	else
	{
		fOpen=false;
		displayStr="none";
		titleStyle="";
		img.src='/Style Library/Edexcel/Images/International/arrrtw.gif'; 
		
	}
	oldName=img.name;
	img.name=img.alt;
	img.alt=oldName;
	titleP.className = titleStyle;
	spanNode=img;

	while(spanNode !=null)
	{
		spanNode=spanNode.parentNode;
		if (spanNode !=null &&
			spanNode.id !=null &&
			spanNode.id.length > 5 &&
			spanNode.id.substr(0, 5)=="group")
			break;
	}
	parentNode=spanNode;
	while(parentNode !=null)
	{
		parentNode=parentNode.parentNode;
		if (parentNode !=null &&
			parentNode.nodeName=="TABLE")
			break;
	}
	lastNode=null;
	if (parentNode !=null)
	{
		lastNode=parentNode.lastChild;
		if (lastNode !=null && lastNode.nodeName=="TBODY")
			lastNode=lastNode.lastChild;
		if (lastNode !=null && lastNode.nodeName=="TR" && lastNode.lastChild !=null)
			lastNode=lastNode.lastChild;
	}
for(var i=0; i < numElts; i++) {
		var childObj=docElts[i];
		if (childObj==spanNode)
			break;
	}
	ID=spanNode.id.slice(5);
	for(var j=i+1; j<numElts; j++)
	{
		var childObj=docElts[j];
		if (childObj.id.length > 5 &&
			childObj.id.substr(0, 5)=="group")
		{
			curID=childObj.id.slice(5);
			if (curID <=ID)
				return;
		}
		parentNode=childObj;
		while(parentNode !=null)
		{
			parentNode=parentNode.parentNode;
			if (parentNode==spanNode)
				break;
		}
		if (parentNode==spanNode)
			continue;
		if (childObj !=img &&
			childObj.nodeName=="IMG" &&
			childObj.src &&
			childObj.src.slice(childObj.src.length - 25)=='/Style Library/Edexcel/Images/International/arrrtw.gif')
		{
			childObj.src='/Style Library/Edexcel/Images/International/arrdnw.gif';
			oldName=childObj.name;
			childObj.name=childObj.alt;
			childObj.alt=oldName;
		}
		if (childObj.nodeName==spanNode.nodeName &&
			childObj.id !="footer")
		{
			childObj.style.display=displayStr;
		}
		if ((childObj.nodeName=="TABLE" && lastNode==null) || childObj==lastNode)
			break;
	}
}

//This method is the same as the one above except it uses different plus and minus images
function ExpGroupByNewImgSet6(formObj,el)
{
// this is the part that prevents it working in Firefox!
//	if (browseris.nav) {
//		return;
//		}
	
	if ((browseris.w3c) && (!browseris.ie)) {
		docElts = document.getElementsByTagName("body")[0].getElementsByTagName("*")
	}
	else { docElts=document.all; }
	var numElts=docElts.length;
	
	switch(el)
	{
	 case "img":
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "TD") {
		  paras=parentNode.getElementsByTagName("a");
		  titleP=paras[0];
		  }
		images=formObj.getElementsByTagName("IMG");
		img=images[0];
		break;
	case "p":
		titleP = formObj;
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "TD") {
		    imgLink = parentNode.firstChild;
		    if (imgLink.nodeName == "A") {
	    		images=imgLink.getElementsByTagName("IMG");
				img=images[0];
				}
			else { return; }
			}
		break;
	case "span":
		parentNode=formObj.parentNode;
		if (parentNode.nodeName == "TD") {
			titleP = parentNode;
			parentNode=titleP.parentNode;
	 		imgLink = parentNode.firstChild;
			if (parentNode.nodeName == "TD") {
		    	imgLink = parentNode.firstChild;
		    	if (imgLink.nodeName == "A") {
	    			images=imgLink.getElementsByTagName("IMG");
					img=images[0];
					}
				else { return; }
				}
			else { return; }
			}
		break;
		default:
        return;
		break;
	}
	srcPath=img.src;
	index=srcPath.lastIndexOf("/");
	imgName=srcPath.slice(index+1);
	if (imgName=='arrrtb.gif')
	{
		fOpen=true;
		displayStr="";
		titleStyle = "openAZgroup";
		// value of displayStr changed from 'none' to prevent 'phantom rows' problem in Firefox
		img.src='/Style Library/Edexcel/Images/International/arrdnb.gif';
	}
	else
	{
		fOpen=false;
		displayStr="none";
		titleStyle="";
		img.src='/Style Library/Edexcel/Images/International/arrrtb.gif'; 
		
	}
	oldName=img.name;
	img.name=img.alt;
	img.alt=oldName;
	titleP.className = titleStyle;
	spanNode=img;

	while(spanNode !=null)
	{
		spanNode=spanNode.parentNode;
		if (spanNode !=null &&
			spanNode.id !=null &&
			spanNode.id.length > 5 &&
			spanNode.id.substr(0, 5)=="group")
			break;
	}
	parentNode=spanNode;
	while(parentNode !=null)
	{
		parentNode=parentNode.parentNode;
		if (parentNode !=null &&
			parentNode.nodeName=="TABLE")
			break;
	}
	lastNode=null;
	if (parentNode !=null)
	{
		lastNode=parentNode.lastChild;
		if (lastNode !=null && lastNode.nodeName=="TBODY")
			lastNode=lastNode.lastChild;
		if (lastNode !=null && lastNode.nodeName=="TR" && lastNode.lastChild !=null)
			lastNode=lastNode.lastChild;
	}
for(var i=0; i < numElts; i++) {
		var childObj=docElts[i];
		if (childObj==spanNode)
			break;
	}
	ID=spanNode.id.slice(5);
	for(var j=i+1; j<numElts; j++)
	{
		var childObj=docElts[j];
		if (childObj.id.length > 5 &&
			childObj.id.substr(0, 5)=="group")
		{
			curID=childObj.id.slice(5);
			if (curID <=ID)
				return;
		}
		parentNode=childObj;
		while(parentNode !=null)
		{
			parentNode=parentNode.parentNode;
			if (parentNode==spanNode)
				break;
		}
		if (parentNode==spanNode)
			continue;
		if (childObj !=img &&
			childObj.nodeName=="IMG" &&
			childObj.src &&
			childObj.src.slice(childObj.src.length - 25)=='/Style Library/Edexcel/Images/International/arrrtb.gif')
		{
			childObj.src='/Style Library/Edexcel/Images/International/arrdnb.gif';
			oldName=childObj.name;
			childObj.name=childObj.alt;
			childObj.alt=oldName;
		}
		if (childObj.nodeName==spanNode.nodeName &&
			childObj.id !="footer")
		{
			childObj.style.display=displayStr;
		}
		if ((childObj.nodeName=="TABLE" && lastNode==null) || childObj==lastNode)
			break;
	}
}


// Google Analytics event tracking
//Creative SharePoint - Feb 2010
	function GAEventTracking(category, action, optional_label, optional_value)
		{
		//alert(category +',' + action+ ','+ optional_label+ ','+ optional_value);
		pageTracker._trackEvent(category, action,optional_label);
		}



function TweakPageTitle()
{
 var leftNav = $('.edx-LeftNav');
 if(leftNav.length < 1)
 {
 	$('.edx-leftColumn').css('display', 'none');
 	$('.edx-PageTitle').parent().css('width', '938px');
 	$('.edx-PageTitle').parent().css('margin-bottom', '3px');
 }

 if($('#edx-LayoutWrapper .edx-PageTitle').html() != null)
 {
 	var TT = $('.edx-PageTitle').text().length;
 	if( $('.edx-PageTitle').html().length < 8)
 	{
 		$('.edx-PageTitle').parent().css('display', 'none');
 	}
 }


} 

function searchDocs()/*Search string builder function*/
	{
		var url = '/PearsonResearchInstitute/Pages/Updates.aspx'
		var vTheme = document.getElementById("cboSearch");
		var vFreetext = document.getElementById("txtSearch");
		var selected_Index = document.getElementById("cboSearch").selectedIndex;
					
		if (selected_Index != 0 && vFreetext.value == "") {
		url += '?theme=';
		url += vTheme.options[selected_Index].text;
		window.location = url;
		}
		
		else if (vFreetext.value != "" && selected_Index == 0) {
		url += '?k=';
		url += vFreetext.value;
		window.location = url;
		}

		else if (vFreetext.value != "" && selected_Index != 0) {
		url += '?k=';
		url += vFreetext.value;
		window.location = url;
		}
		
		else {
		window.location = url;
		}
	
	}
	
	function getPagePath()
	{
		fullURL = parent.document.URL? parent.document.URL : window.location;
		var qstrsplit  = fullURL.indexOf('?');
		qstrsplit   = (qstrsplit>0)? qstrsplit : fullURL.length; 
		return fullURL.substring(0, qstrsplit); 
		
	}

function WBLNoticeArchiveMoreClick()
{
	  for (var i = 0; i<=9; i++)
	  {
		 var current = $('.WBLNoticeArchiveHidden')[0];	 
		 $(current).removeClass('WBLNoticeArchiveHidden');
	  }
}

/*PEARSON RESOURCES - MAY 2011 - DAVID HENDRY*/
function RenderPRPage(PageNumber)
{
 	$(".pearsonResources").hide();
 	$(".pearsonResources" + PageNumber + "0").show();
 	SetSelectedPage(PageNumber);
	UpdatePearsonResourcesPagingDetails(PageNumber)
 	$(location).attr('href','#PearsonResourcesTop');
}

function PearsonResourcesPaginationNextPage()
{
	 var nextPage = parseInt($(".SelectedPage")[0].innerHTML) + 1;
	 RenderPRPage(nextPage);
}

function PearsonResourcesPaginationPrevPage()
{
	 var prevPage = parseInt($(".SelectedPage")[0].innerHTML) - 1;
	 RenderPRPage(prevPage);
}

function PearsonResourcesPaginationNextPageClientPagination()
{
	 var nextPage = parseInt($(".SelectedPage")[0].innerHTML) + 1;
	 ClientPagination(nextPage);
}

function PearsonResourcesPaginationPrevPageClientPagination()
{
	 var prevPage = parseInt($(".SelectedPage")[0].innerHTML) - 1;
	 ClientPagination(prevPage);
}


function UpdatePearsonResourcesPagingDetails(PageNumber)
{
 	if (IsLastPage(PageNumber))
 		  $(".Pagination-NextPage").css('display','none');
 	else
 		  $(".Pagination-NextPage").css('display','inline');
 	if (IsFirstPage(PageNumber))
 		  $(".Pagination-PrevPage").css('display','none');
 	else
 		  $(".Pagination-PrevPage").css('display','inline');
	
 	var shownItems = $(".pearsonResources" + PageNumber + "0").length;
 	if (PageNumber == 1)
 	{
 		$(".PearsonResourcesInitialElement").each(function(){
 			$(this).text('1');
 		});
 	$(".PearsonResourcesLastElement").each(function(){
 		$(this).text(shownItems);
 		});
 	}
 	else
 	{
 		var initialElement = ((PageNumber - 1) * 10) + 1;
 		var lastElement = initialElement + shownItems - 1;
 		$(".PearsonResourcesInitialElement").each(function(){
 			$(this).text(initialElement);
 		});
 		$(".PearsonResourcesLastElement").each(function(){
 			$(this).text(lastElement);
 		});
 	}
}

function UpdatePearsonResourcesPagingDetailsClientPagination(PageNumber,initialElement,lastElement,allElements)
{
	if ( lastElement < allElements)
 		  $(".Pagination-NextPage").css('display','inline');
 	else
  		  $(".Pagination-NextPage").css('display','none');
 	if (initialElement > 10)
 		  $(".Pagination-PrevPage").css('display','inline');
 	else
 		  $(".Pagination-PrevPage").css('display','none');
	 	
 	if (PageNumber == 1)
 	{
 		$(".PearsonResourcesInitialElement").each(function(){
 			$(this).text('1');
 		});
 		$(".PearsonResourcesLastElement").each(function(){
 			$(this).text(lastElement);
 		});
 		$(".PearsonResourcesAllElements").each(function(){
 			$(this).text(allElements);
 		}); 
 	}
 	else
 	{ 		
 		$(".PearsonResourcesInitialElement").each(function(){
 			$(this).text(initialElement);
 		});
 		$(".PearsonResourcesLastElement").each(function(){
 			$(this).text(lastElement);
 		});
 		$(".PearsonResourcesAllElements").each(function(){
 			$(this).text(allElements);
 		}); 		
 	}

}

function IsLastPage(PageNumber)
{
 	var nextPageNumber = PageNumber + 1;
 	var nextPage = '.pearsonResources' + nextPageNumber + '0';
 	if ($(nextPage).length != 0)
 		return false;
 	else
 		return true;
}

function IsFirstPage(PageNumber)
{
 	var prevPageNumber = PageNumber - 1;
 	var nextPage = '.pearsonResources' + prevPageNumber + '0';
 	if ($(prevPageNumber).length != 0)
 		return false;
 	else
 		return true;
}

function SetSelectedPage(PageNumber)
{
 	$(".SelectedPage").css('font-weight','normal');
 	$(".SelectedPage").removeClass('SelectedPage');
 	$(".pearsonResourcePage" + PageNumber).addClass("SelectedPage")
 	$(".SelectedPage").css('font-weight','bold');
 	$(".edx-SmallNoticesHeader1").focus();
}
function ClientPagination(PageNumber)
{
	var qualFilter = $('.QualificationFilterSelect').val();
	
	if (qualFilter == '')
	{
		HideAllElements();		
		ShowItems(PageNumber);				
		ShowPages();
		SetSelectedPage(PageNumber);	
		var initialElement = ((PageNumber - 1) * 10) + 1;		
		var allElements = $('.pearsonResources').length;
 		var lastElement = initialElement + 9;
 		if (lastElement > allElements)
 		 	lastElement = allElements;
		UpdatePearsonResourcesPagingDetailsClientPagination(PageNumber,initialElement,lastElement,allElements); 
		$(location).attr('href','#PearsonResourcesTop');
	}	
	else
	{ 
		var initialItem = parseInt(((PageNumber-1)*10));
		var lastItem = parseInt(initialItem + 9);
		var shownItems = 0;
		var allItems = 0;
		var i=0;
			$('input[type=hidden].QFAndQS').each(function() {				
				if ($(this).val()!= qualFilter )
					$(this).parents('.pearsonResources').addClass('pearsonResourcesHidden');
				else
				{		
					allItems++;			
					if (i>= initialItem && i<=lastItem)
					{					
						$(this).parents('.pearsonResources').removeClass('pearsonResourcesHidden');											
						shownItems++;
					}
					else
					{
						$(this).parents('.pearsonResources').addClass('pearsonResourcesHidden');
					}
				i++;	
				}
			});						
		SetSelectedPage(PageNumber);
		UpdatePearsonResourcesPagingDetailsClientPagination(PageNumber,initialItem + 1,initialItem + shownItems,allItems); 
		$(location).attr('href','#PearsonResourcesTop');
	}
}

function ShowPages()
{
	for (var i = 1; i<=10; i++)
	{
		var currentPage = '.pearsonResourcePage' + i;
		$(currentPage).show();
	}	
}

function ShowItems(PageNumber)
{
	var initialItem = parseInt(((PageNumber - 1)*10)+1);
	var finalItem = parseInt(initialItem +9);
	for(var i=initialItem ;i<=finalItem;i++)
	{		
		var currentItem = '.item' +  i;	
		$(currentItem).removeClass('pearsonResourcesHidden');
	}	
}

function HideAllElements()
{
	$('.pearsonResources').each(function() {
		if (!$(this).hasClass('pearsonResourcesHidden'))
			$(this).addClass('pearsonResourcesHidden');				
	});
}

function SetPaginationAfterClientFiltering(items)
{
	ShowPages();
	var maxNumberPages = Math.ceil(items/10)
	for (var i = maxNumberPages + 1; i<=20; i++)
	{
		var currentPage = '.pearsonResourcePage' + i;
		$(currentPage).hide();
	}	
	SetSelectedPage(1);
}

function QualificationSubjectFiltering()
{

	var items = 0;	
	var qualFilter = $('.QualificationFilterSelect').val();
	if (qualFilter == '')
	{		
		HideAllElements();			
		ShowItems(1);			
		ShowPages();
		SetSelectedPage(1);
		
		var allElements = $('.pearsonResources').length;
 		var lastElement = 10;
 		if (lastElement > allElements)
 		 	lastElement = allElements;
		UpdatePearsonResourcesPagingDetailsClientPagination(1,1,lastElement,allElements); 

				
	}		
	else
	{
		var initialItem = 1;
		var lastItem = parseInt(initialItem + 9);
		var shownItems = 0;
		var allItems = 0;

		$('input[type=hidden].QFAndQS').each(function() {				
			if ($(this).val()!= qualFilter)
				$(this).parents('.pearsonResources').addClass('pearsonResourcesHidden');
			else
			{	
				allItems++;					
				if (items<10)
				{						
					$(this).parents('.pearsonResources').removeClass('pearsonResourcesHidden');	
					shownItems++;										
				}
				items++;
			}
		});	
		SetPaginationAfterClientFiltering(items);
		UpdatePearsonResourcesPagingDetailsClientPagination(1,initialItem,shownItems,allItems); 
	}
}

/*END OF PEARSON RESOURCES*/




/***************************************************
* BTEC Apprenticeships
***************************************************/
function apprenticeSetUpTooltips() {
	var tt = $('a[href$="#tooltip"]')
		, ttSize = tt.length;
	
	if(ttSize > 0){
		tt.addClass('csp-tooltip');

		for (var i=0; i<ttSize; i++){
			var a = tt[i]
				, t = document.createElement('span')
				, tip = document.createElement('span');
		
			// Create tooltip
			t.id = 'dd_'+ i;
			t.className = 'csp-definition';
			t.innerHTML = a.getAttribute('title');
			tip.className = 'csp-tooltip-tip';
			t.appendChild(tip);
			a.parentElement.appendChild(t);

			// link attributes
			a.setAttribute('id','tt_'+ i);
			a.removeAttribute('title');
		}
	
		// Clicking events
		tt.bind('click',function(e){
			e.preventDefault();
			e.stopPropagation();
		});
	
		tt.bind('mouseover mouseout',function(e){
			e.stopPropagation();
			var i = this.id
				, extra = 0
				, ddPos;
			i = i.substring(i.indexOf('_')+1, i.length);
			ddPos = $('#tt_'+ i).offset().left + $('#tt_'+ i).width()/1.5 + $('#dd_'+ i).width();
			
			$('.csp-definition').not('#dd_'+ i).fadeOut();
					
			if(ddPos + 10 > document.body.clientWidth)
			{
				extra = ddPos + 25 - document.body.clientWidth - document.body.scrollLeft;
				var left = (extra > $('#dd_'+ i).width()) ? $('#dd_'+ i).width()-5 : extra;
				$('#dd_'+ i).find('.csp-tooltip-tip').css({'left':left});
			}
			else {
				extra = 5;
				$('#dd_'+ i).find('.csp-tooltip-tip').css({'left':extra});
			}
			
			$('#dd_'+ i).css({ 'top': $('#tt_'+ i).offset().top - $('#dd_'+ i).height()-15, 'left':$('#tt_'+ i).offset().left + $('#tt_'+ i).width()/1.5 - extra }).not('.csp-tooltip-tip').stop(true, true).slideToggle(50);
		});

	
		$('.csp-definition').bind('click', function(e){
			e.preventDefault();
		});
	}
}

function apprenticeSetNavCurrentPage() {
	var url = (document.URL).toLowerCase()
		, links = document.getElementById('csp-apprentice-nav').getElementsByTagName('a')
		, href = '';

	for (var i=0; i<links.length; i++) {
		c = links[i];
		href = (c.getAttribute('href')).toLowerCase();
		if(url.indexOf(href)>=0) { 
			links[i].setAttribute('className', "csp-nav-selected") || links[i].setAttribute('class', "csp-nav-selected");
			break; 
		}
	}
}

function apprenticeHeaderModal() {
	$('#edx-ContentMain').find('.csp-apprenticeship-banner').each(function(){
		$(this).click(function(){
			$('#csp-find-out-more').html('<h3>Find out how we can help your business by filling in the form below:</h3><iframe src="/Forms/Pages/apprentice-hiring-csp.aspx" height="560" width="640" frameborder="0" scrolling="no" id="apprenticeHiring"></iframe>').dialog({
				modal: true
				, resizable: false
				, draggable: false
				, height: 560
				, width: 640
				, dialogClass: 'csp-modal-borderless'
				, closeOnEscape: true
			});	
		
		});
	});
}

/* END BTEC Apprenticeships
***************************************************/

