﻿/*
Edexcel Core JS developed by Creative SharePoint
Created: 15/07/2009
Developer: David Hendry
*/

// Initiate the Left Navigation Expandable Menus
$(document).ready(function() {
    //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();
	});
    });
});


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;
	}
}


// 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);
		}



