// common scripts

// Core scripts v.3.5 - 09.07.02

/*
These scripts are designed to be root relative - they require the site to operating as a domain or port number!

*/


// Window open code

// Better window code

function openWin( winURL, winName, winWidth, winHeight, winX, winY, scrollBars, statusBar, resizable ) {
	winName = window.open( winURL, winName, 'width='  + winWidth + ',height='  + winHeight + ',top=' + winX + ',left=' + winY + ',screenX=' + winX + ',screenY=' + winY + ',location=no,scrollbars=' + scrollBars + ',directories=no,status=' + statusBar + ',menubar=no,personalbar=no,resizable=' + resizable );
	winName.scrollTo( 0, 0 );
}

// Better window code lite

function openWinLite( winURL, winName ) {
	winName = window.open( winURL, winName, 'width=750,height=600,top=0,left=0,screenX=100,screenY=100,location=no,scrollbars=yes,directories=no,status=no,menubar=no,personalbar=no,resizable=no' );
	winName.scrollTo( 0, 0 );
}

function popUpSebnetProduct(winURL, winName)
{
	winName = window.open( winURL, winName, 'width=750,height=600,top=0,left=0,screenX=100,screenY=100,location=no,scrollbars=yes,directories=no,status=no,menubar=no,personalbar=no,resizable=yes' );
	winName.scrollTo( 0, 0 );
}

function printerFriendlyWin(winURL) {
	winName = window.open( winURL, 'printerWin', 'width=570,location=yes,scrollbars=yes,directories=yes,status=yes,menubar=yes,personalbar=no,resizable=yes');
}

// Generally, it's safe to amalgamate all Dreamweaver code down here

function createObject( n, d ) {
	// Object creation code
	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 = createObject( n, d.layers[i].document );
		}
	}
	return x;
}

function preloadImages() {
	var d = document;
	if( d.images ){
		if( !d.preloadArr ) {
			d.preloadArr = new Array();
			var i, j = d.preloadArr.length, a = preloadImages.arguments;
			for( i = 0; i < a.length; i++ ) {
				if ( a[i].indexOf( "#" ) != 0 ){
					d.preloadArr[j] = new Image; d.preloadArr[j++].src = a[i];
				}
			}
		}
	}
}

function swapImage() {
	var i, j = 0, x, a = swapImage.arguments;
	document.imageRestoreArr = new Array;
	for( i = 0; i < ( a.length - 2 ); i += 3 )
		if( ( x = createObject( a[i] ) ) != null ) {
			document.imageRestoreArr[j++] = x;
			if( !x.oSrc )
				x.oSrc = x.src;
				x.src = a[i + 2];
				}
}

function swapImageRestore() {
	var i, x, a = document.imageRestoreArr;
	for( i = 0; a && i < a.length && ( x = a[i] ) && x.oSrc; i++ ) {
		x.src = x.oSrc;
	}
}

// image path starts always from root directory
function openWinImg(imgPath)
{
	winURL = '/showImage.aspx?imgUrl=' + imgPath
	winName = window.open( winURL, 'imgWin', 'width=200,height=500,location=no,scrollbars=yes,directories=no,status=no,menubar=no,personalbar=no,resizable=yes');
}

/* onLoad="preloadImages('images/navigation/home_over.gif')" */
/* onMouseOver="swapImage('aboutus','','image_over.file',1)" onfocus="swapImage('aboutus','','image_over.file',1)" onMouseOut="swapImageRestore()" onblur="swapImageRestore()" */
/* Element Show/Hide by ID using CSS */
/* Rather useful little function, generally */
function toggleElementDisplay( elementID, elementAttribute, attributeValue1, attributeValue2 ) {
	if( document.getElementById ) {
		theElementStyle = document.getElementById( elementID ).style;
	} else {
		theElementStyle = document.all[ elementID ].style;
	}

	if( theElementStyle[elementAttribute] == attributeValue2 || !theElementStyle[elementAttribute] ) {
		theElementStyle[elementAttribute] = attributeValue1;
	} else {
		theElementStyle[elementAttribute] = attributeValue2;
	}
}

function popUpTechInfo(techID)
{
	winURL = '/energymap/app_emap_tech_info.asp?techID=' + techID
	winName = window.open( winURL, 'imgWin', 'width=800,height=600,location=no,scrollbars=yes,directories=no,status=no,menubar=no,personalbar=no,resizable=yes');
}

function popUpActionInfo(actionID)
{
	winURL = '/energymap/app_emap_action_desc.asp?actionID=' + actionID
	winName = window.open( winURL, 'imgWin', 'width=800,height=600,location=no,scrollbars=yes,directories=no,status=no,menubar=no,personalbar=no,resizable=yes');
}

function popUpEnergySupplyInfo()
{
	winURL = '/energymap/app_emap_energy_supply_info.asp'
	winName = window.open( winURL, 'imgWin', 'width=800,height=600,location=no,scrollbars=yes,directories=no,status=no,menubar=no,personalbar=no,resizable=yes');
}

function popUpProgressInfo(progressID)
{
	winURL = '/energymap/app_emap_progress_info.asp?progressID=' + progressID
	winName = window.open( winURL, 'imgWin', 'width=800,height=600,location=no,scrollbars=yes,directories=no,status=no,menubar=no,personalbar=no,resizable=yes');
}

function popUpSectorInfo()
{
	winURL = '/energymap/app_emap_sector_info.asp'
	winName = window.open( winURL, 'imgWin', 'width=800,height=600,location=no,scrollbars=yes,directories=no,status=no,menubar=no,personalbar=no,resizable=yes');
}

function changeImage(imgObject, event)
{
	if (event.type == "mouseover")
	{
		imgObject.src = "/images_upload/banners/" + imgObject.id + "_On.jpg";
	}

	else if (event.type == "mouseout")
	{
		imgObject.src = "/images_upload/banners/" + imgObject.id + "_Off.jpg";
	}
}

function showHideDiv(objId, linkId)
{
    var sourceObj = document.getElementById(objId);
    
    if (sourceObj.style.display == "block")
    {
        sourceObj.style.display = "none";
    }
    
    else if (sourceObj.style.display == "none")
    {
        sourceObj.style.display = "block";
    }
    
    if ((linkId != "") && (linkId != null))
    {
        var linkObj = document.getElementById(linkId);
        if (linkObj.innerHTML == "expand [+]")
        {
            linkObj.innerHTML = "shrink [-]";
        }
        
        else if (linkObj.innerHTML == "shrink [-]")
        {
            linkObj.innerHTML = "expand [+]";
        }
    }
    
    if (sourceObj.className == "ItemContent")
    {
        if (IsContainerEmpty("ctl00_ContentPlaceHolderMain_ItemsListContainer", "div") == true)
        {
            var divObject = document.getElementById('ctl00_ContentPlaceHolderMain_ItemsListContainer');
            var defaultMessageObject = "<span id='DefaultNoCats_Message'>There are no categories displayed, please add a category using the menu to the left</span>";
            divObject.innerHtml = defaultMessageObject;
        }
        
        else
        {
            var divObject = document.getElementById('ctl00_ContentPlaceHolderMain_ItemsListContainer');
            var defaultMessageObject = document.getElementById("DefaultNoCats_Message");
            
            if ((divObject != null) && (defaultMessageObject != null))
            {
                divObject.removeChild(defaultMessageObject);
            }
        }
    }
}

function showHideDiv_Img(divId, imgId)
{
    var divObj = document.getElementById(divId);
    var imgObj = document.getElementById(imgId);
    
    if (divObj.style.display == "block")
    {
        divObj.style.display = "none";
        
        if (imgObj != null)
        {
            imgObj.src = "/images/EnergyMap/EnergyWizard/Buttons/Button_ExpandSign_Green.gif";
        }
    }
    
    else if (divObj.style.display == "none")
    {
        divObj.style.display = "block";
        
        if (imgObj != null)
        {
            imgObj.src = "/images/EnergyMap/EnergyWizard/Buttons/Button_ShrinkSign_Green.gif";
        }
    }
}

function TreeView_ExpandAll(parentElementId)
{
    if ((parentElementId != "") && (parentElementId != null))
    {
        var parentObject = document.getElementById(parentElementId);
        var divObjects = parentObject.getElementsByTagName('div');
        
        for (var i=0; i<divObjects.length; i++)
        {
            if ((divObjects[i].className == "TreeView_Sector_Container") || (divObjects[i].className == "TreeView_CategoryList_Container") || (divObjects[i].className == "TreeView_TechnologyList_Container") || (divObjects[i].className == "TreeView_ActionList_Container"))
            {
                if (divObjects[i].className != "TreeView_Sector_Container")
                {
                    divObjects[i].style.display = "block";
                }
                
                var imgObjects = divObjects[i].getElementsByTagName('img');
                
                for (var x=0; x<imgObjects.length; x++)
                {
                    if (imgObjects[x].id.match("TreeView_ExpandOrShrink_Img_") != null)
                    {
                        imgObjects[x].src = "/images/EnergyMap/EnergyWizard/Buttons/Button_ShrinkSign_Green.gif";
                    }
                } 
            }
        }
    }
}

function TreeView_ShrinkAll(parentElementId)
{
    if ((parentElementId != "") && (parentElementId != null))
    {
        var parentObject = document.getElementById(parentElementId);
        var divObjects = parentObject.getElementsByTagName('div');
        
        for (var i=0; i<divObjects.length; i++)
        {
            if ((divObjects[i].className == "TreeView_Sector_Container") || (divObjects[i].className == "TreeView_CategoryList_Container") || (divObjects[i].className == "TreeView_TechnologyList_Container") || (divObjects[i].className == "TreeView_ActionList_Container"))
            {
                if (divObjects[i].className != "TreeView_Sector_Container")
                {
                    divObjects[i].style.display = "none";
                }
                
                var imgObjects = divObjects[i].getElementsByTagName('img');
                
                for (var x=0; x<imgObjects.length; x++)
                {
                    if (imgObjects[x].id.match("TreeView_ExpandOrShrink_Img_") != null)
                    {
                        imgObjects[x].src = "/images/EnergyMap/EnergyWizard/Buttons/Button_ExpandSign_Green.gif";
                    }
                }
            }
        }
    }
}

function IsContainerEmpty(containerId, typeToCheck)
{
    var containerObj = document.getElementById(containerId);
    var containerInnerObjs = document.getElementsByTag(typeToCheck);
    
    var isEmpty = true;
    
    if (containerObj != null)
    {
        if (containerInnerObjs != null)
        {
            for (var i=0; i<containerInnerObjs.length; i++)
            {
                if ((containerInnerObjs[i].style.display == "block") || ((containerInnerObjs[i].style.display == "inline-block")) || ((containerInnerObjs[i].style.display == "inline")))
                {
                    isEmpty = false;
                }
            }
        }
    }
    
    return isEmpty;
}

/* Javascript for Schools Pledge Programme */
function CheckParticipated(event, source)
{
    var schoolsListRow = document.getElementById('ctl00_ctl00_ContentPlaceHolder_Main_ContentPlaceHolder_Main_PledgeForm1_DataCollection_DataRow2');
    
    if (source.id.match("DataCollection_Row1_Input1") != null)
    {
        if (schoolsListRow != null)
        {
            schoolsListRow.style.display = "";
        }
    }
    
    else if (source.id.match("DataCollection_Row1_Input2") != null)
    {
        if (schoolsListRow != null)
        {
            schoolsListRow.style.display = "none";
        }
    }
}

function confirmDelete(ev, text)
{
    var theEvent = ev || window.event;
    var confirmAns = confirm(text || 'Are you sure you want to delete this item?');
    
    if (!confirmAns)
    {
        if (theEvent.cancelBubble != null)
         theEvent.cancelBubble = true;
        if (theEvent.stopPropagation)
         theEvent.stopPropagation();
        if (theEvent.preventDefault)
         theEvent.preventDefault();
        if (window.event)
         theEvent.returnValue = false;
        if (theEvent.cancel != null)
         theEvent.cancel = true;
     }

    return confirmAns;
}



$(document).ready(function() {

	$("$.imgLanding img").hover(

	function() {
	var link = $(this).attr('src');
	var newLink = link.replace('.','_over.');
	$(this).attr('src',newLink);

	},
	function(){
	var link = $(this).attr('src');
	var newLink = link.replace('_over.','.');

	$(this).attr('src',newLink);

	}
);

});

function ShowList01Hidden()
{

    $("li.list01HiddenItem").toggle();
$("li.more").toggle();

}

function ShowList0fHiddenItems_Policy() {
    $(".policy_content li.list01HiddenItem").toggle();
    $(".policy_bottom").html("<a href='Javascript:void(0);' id='less' onclick='HideList0fHiddenItems_Policy();'>Less</a>");
}

function ShowList0fHiddenItems_Tech() {
    $(".tech_content li.list01HiddenItem").toggle();
    $(".tech_bottom").html("<a href='Javascript:void(0);' id='less' onclick='HideList0fHiddenItems_Tech();'>Less</a>");
}

function ShowList0fHiddenItems_Info() {
    $(".info_content li.list01HiddenItem").toggle();
    $(".info_bottom").html("<a href='Javascript:void(0);' id='less' onclick='HideList0fHiddenItems_Info();'>Less</a>");
}

function HideList0fHiddenItems_Policy() {
    $(".policy_content li.list01HiddenItem").toggle();
    $(".policy_bottom").html("<a href='Javascript:void(0);' onclick='ShowList0fHiddenItems_Policy();'>More</a>");
}

function HideList0fHiddenItems_Tech() {
    $(".tech_content li.list01HiddenItem").toggle();
    $(".tech_bottom").html("<a href='Javascript:void(0);' onclick='ShowList0fHiddenItems_Tech();'>More</a>");
}

function HideList0fHiddenItems_Info() {
    $(".info_content li.list01HiddenItem").toggle();
    $(".info_bottom").html("<a href='Javascript:void(0);' onclick='ShowList0fHiddenItems_Info();'>More</a>");
}


/* Popup Dialog */

var overlay = null;
var popup = null;
var popupTitle = null;
var popupContent = null;
var closeButton = null;

$(document).ready(function() {
    InitPopupObjects();
    BindPopupEvents();
    SetWindowDimensions("PopupDialog");
    SetWindowDimensions("LoginWarning_Container");
});

function InitPopupObjects() {
    overlay = $("div.Overlay");
    popup = $("div.PopupDialog");
    popupTitle = $("div.PopupDialog_Top div.PopupTitle");
    popupContent = $("div.PopupDialog_Content div.PopupContent");
    closeButton = $("div#CloseButton");
}

function BindPopupEvents() {
    closeButton.click(function() {
        ResetPopup();
    });
}

function ShowPopup(titleId, contentId) {
    if (overlay != null) {
        overlay.show();
    }

    if (popup != null) {
        if ((titleId != null) && (titleId != "") && (popupTitle != null)) {
            var titleObj = $("input[id=" + titleId + "]");

            if (titleObj != null) {
                popupTitle.html(titleObj.val())
            }
        }

        if ((contentId != null) && (contentId != "") && (popupContent != null)) {
            var contentObj = $("input[id=" + contentId + "]");

            if (titleObj != null) {
                popupContent.html(contentObj.val())
            }
        }

        var scrollTop = $(window).scrollTop();
        popup.attr("style", "position: absolute; top: " + (scrollTop + 20) + "px");

        SetOverlayDimensions();
        popup.show();

        var links = $("div.PopupContent a");
        links.attr("target", "_blank");
    }
}

function ResetPopup() {
    if (overlay != null) {
        overlay.hide();
    }

    if (popup != null) {
        if (popupTitle != null) {
            popupTitle.html("");
        }

        if (popupContent != null) {
            popupContent.html("");
        }

        popup.hide();
    }
}

function SetOverlayDimensions() {
    var overlayObj = $("div.Overlay");
    var formObj = $("form[id='aspnetForm']");
    var bodyObj = $("body");
    var footerObj = $("div[id='pageFooter']");

    if ((overlayObj != null) && (bodyObj != null)) {
        var heightToUse = bodyObj.height();
        var widthToUse = bodyObj.width();

        if (footerObj != null) {
            heightToUse += footerObj.height();
        }
        
        overlayObj.height(heightToUse);
        overlayObj.width(widthToUse);
    }
}

function SetWindowDimensions(windowClass) {
    if ((windowClass != null) && (windowClass != '')) {
        var windowObj = $("div." + windowClass);
        var bodyObj = $("body");
        var footerObj = $("div[id='pageFooter']");
        
        if ((windowObj != null) && (bodyObj != null)){

            var heightToUse = bodyObj.height();
            var widthToUse = bodyObj.width();

            if (footerObj != null) {
                heightToUse += footerObj.height();
            }

            windowObj.height(heightToUse);
            windowObj.width(widthToUse);
        }
    }
}

/* Full Tree View JS */
var expandOrShrinkId = null;
var expandOrShrinkButtons = null;

var showAllId = null;
var showAllButton = null;
var hideAllId = null;
var hideAllButton = null;

var listId = null;
var lists = null;

$(document).ready(function() {
    InitFullTreeViewObjects();
    ConfigureFullTreeViewClickEvents();
});

function InitFullTreeViewObjects() {
    expandOrShrinkId = "ExpandOrShrink_";
    expandOrShrinkButtons = $("a[id^=" + expandOrShrinkId + "]");

    showAllId = "ExpandOrShrink_ShowAll";
    hideAllId = "ExpandOrShrink_HideAll";

    showAllButton = $("a[id='" + showAllId + "']");
    hideAllButton = $("a[id='" + hideAllId + "']");

    listId = "ItemList_";
    lists = $("ul[id^=" + listId + "]");
}

function ConfigureFullTreeViewClickEvents() {
    expandOrShrinkButtons.click(function() {

        var buttonObj = $("a[id='" + this.id + "']");

        if (buttonObj != null) {
            var buttonImgObj = $("a[id='" + this.id + "'] img");

            if (buttonImgObj != null) {
                var listObjId = this.id.replace("ExpandOrShrink_", "");
                var listObj = $("ul[id='" + listObjId + "']");

                if (listObj != null) {
                    if (listObj.is(':visible')) {
                        buttonImgObj.attr("src", "/images/EnergyMap/EnergyWizard/Buttons/Button_ExpandSign_Green.gif");
                    }

                    else if (listObj.is(':hidden')) {
                        buttonImgObj.attr("src", "/images/EnergyMap/EnergyWizard/Buttons/Button_ShrinkSign_Green.gif");
                    }
                }
            }

            ShowHide(GetListIdFromButtonId(this.id));
        }
    });

    showAllButton.click(function() {
        ShowAll();
    });

    hideAllButton.click(function() {
        HideAll();
    });
}

function GetListIdFromButtonId(buttonId) {
    var returnValue = "";
    
    if ((buttonId != null) && (buttonId != "")) {
        var listId = buttonId.replace('ExpandOrShrink_', '');

        if ((listId != null) && (listId != "")) {
            returnValue = listId;
        }
    }

    return returnValue;
}

function ShowHide(id) {
    if ((id != null) && (id != "")) {
        var obj = $("ul[id='" + id + "']");

        if (obj != null) {
            if (obj.is(':visible')) {
                obj.hide();
            }

            else if (obj.is(':hidden')) {
                obj.show();
            }
        }
    }
}

function ShowAll() {
    var buttonImgObj = $("a[id^='ExpandOrShrink_'] img");

    if (buttonImgObj != null) {
        buttonImgObj.attr("src", "/images/EnergyMap/EnergyWizard/Buttons/Button_ShrinkSign_Green.gif");
    }
    
    lists.show();
}

function HideAll() {
    var buttonImgObj = $("a[id^='ExpandOrShrink_'] img");

    if (buttonImgObj != null) {
        buttonImgObj.attr("src", "/images/EnergyMap/EnergyWizard/Buttons/Button_ExpandSign_Green.gif");
    }
    
    lists.hide();
}

/*
####################################################################################################################
BER Splash Page Scripts Begin
####################################################################################################################
*/

var ratingsContainerClass;
var ratingsContainer;

var ratingsTableClass;
var ratingsTable;
var ratingsTableCells;

var columnAIdPart;
var columnBIdPart;

var columnACells;
var columnBCells;

var berOverlayClass;
var berOverlay;

var homeOwnersLinkId;
var homeOwnersLink;

var berSplashCloseButtonId;
var berSplashCloseButton;

var berSplashExitButtonId;
var berSplashExitButton;

var berSplashVisitedCookieName;
var redirectLinkAddress;

var queryVariableName;
var queryVariableValue;

var berSplashLoggerCodeContainer;

$(document).ready(function() {
    BerSplash_InitObjects()
});

$(window).load(function() {
    BerSplash_InitEvents();
    BerSplash_CheckQueryString();
});

function BerSplash_InitObjects() {
    ratingsContainerClass = "BerSplashPageContainer";
    ratingsContainer = $("div." + ratingsContainerClass);

    ratingsTableClass = "BerRatingTable";
    ratingsTable = $("table." + ratingsTableClass);
    ratingsTableCells = $("table." + ratingsTableClass + " td");

    columnAIdPart = "_A";
    columnBIdPart = "_B";

    columnACells = $("table." + ratingsTableClass + " td[id$='" + columnAIdPart + "']");
    columnBCells = $("table." + ratingsTableClass + " td[id$='" + columnBIdPart + "']");

    berOverlayClass = "BerRatingsOverlay";
    berOverlay = $("div." + berOverlayClass);

    homeOwnersLinkId = "BER_HomeOwnersLink";
    homeOwnersLink = $("a[id='" + homeOwnersLinkId + "']");

    berSplashCloseButtonId = "BerSplash_CloseButton";
    berSplashCloseButton = $("div[id='" + berSplashCloseButtonId + "']");

    berSplashExitButtonId = "BerSplash_ExitButton";
    berSplashExitButton = $("div[id='" + berSplashExitButtonId + "']");

    berSplashVisitedCookieName = "BerSplashPageVisited";
    redirectLinkAddress = "/Your_Building/BER/Householders/";

    queryVariableName = "campaign";
    queryVariableValue = $.query.get(queryVariableName);

    berSplashLoggerCodeContainer = $("div[id='BerSplashLoggerCodeContainer']");
}

function BerSplash_InitEvents() {
    if (((ratingsTable != null) && (ratingsTable.length >= 1)) && ((ratingsTableCells != null) && (ratingsTableCells.length >= 1))) {
        ratingsTableCells.click(function(event) {
            BerSplash_ShowHide(this.id, event.type);
        });

        ratingsTableCells.hover(function(event) {
            BerSplash_ShowHide(this.id, event.type);
        },
		function(event) {
		    BerSplash_ShowHide(this.id, event.type);
		});
    }

    if ((homeOwnersLink != null) && (homeOwnersLink.length >= 1)) {
        homeOwnersLink.click(function(event) {
            hasVisited = BerSplash_CheckVisited();

            if (hasVisited == "True") {
                window.location = redirectLinkAddress;
            }

            else {
                BerSplash_ShowSplash();
            }
        });
    }

    if ((berSplashExitButton != null) && (berSplashExitButton.length != 0)) {
        berSplashExitButton.click(function(event) {
            BerSplash_SaveVisited();
            window.location = redirectLinkAddress;
        });
    }

    if ((berSplashCloseButton != null) && (berSplashCloseButton.length != 0)) {
        berSplashCloseButton.click(function(event) {
            //BerSplash_HideSplash();
            BerSplash_SaveVisited();
            window.location = redirectLinkAddress;
        });
    }
}

function BerSplash_ShowHide(objectId, eventType) {
    if ((objectId != null) && (objectId != "")) {
        var object = $("td[id='" + objectId + "']");

        if ((object != null) && (object.length >= 1)) {
            if (eventType == "click") {
                if (object.hasClass("Selected")) {
                    object.removeClass("Selected");
                }

                else if (!object.hasClass("Selected")) {
                    object.addClass("Selected");
                }
            }

            else if ((eventType == "mouseenter") || (eventType == "mouseleave")) {
                if (object.hasClass("Hover")) {
                    object.removeClass("Hover");
                }

                else if (!object.hasClass("Hover")) {
                    object.addClass("Hover");
                }
            }
        }
    }
}

function BerSplash_CheckQueryString() {
    if ((queryVariableValue != null) && (queryVariableValue.length != 0) && (queryVariableValue == "ber")) {
        BerSplash_ShowSplash();
    }
}

function BerSplash_ShowSplash() {
    BerSplash_SetWindowDimensions();

    if ((berOverlay != null) && (berOverlay.length != 0)) {
        berOverlay.show();
    }
    
    if ((ratingsContainer != null) && (ratingsContainer.length != 0)) {
        ratingsContainer.show();

        /* BER Splash Page Visits Logging */
        var queryStringCode = encodeURI("?bsp_tle=SplashPageVisit&bsp_desc=BER_SplashPage_PageVisited");
        var imageCode = "<img src='/CustomApps/BER/BERSplashCallback.aspx" + queryStringCode + "' width='1px' height='1px' />";

        if ((imageCode != null) && (imageCode.length >= 1)) {
            if ((berSplashLoggerCodeContainer != null) && (berSplashLoggerCodeContainer.length >= 1)) {
                berSplashLoggerCodeContainer.html(imageCode);
            }
        }
    }
}

function BerSplash_HideSplash() {
    if ((berOverlay != null) && (berOverlay.length != 0)) {
        berOverlay.hide();
    }

    if ((ratingsContainer != null) && (ratingsContainer.length != 0)) {
        ratingsContainer.hide();
    }
}

function BerSplash_SetWindowDimensions() {
    if ((berOverlay != null) && (berOverlay != "")) {
        var height = $(document).height();
        var width = $(document).width();

        berOverlay.height(height);
        berOverlay.width(width);
    }

    if ((ratingsContainer != null) && (ratingsContainer != "")) {
        var height = $(document).height();
        var width = $(document).width();

        ratingsContainer.height(height);
        ratingsContainer.width(width);
    }
}

function BerSplash_CheckVisited() {
    var returnResult = null;

    var previouslyVisited = $.cookie(berSplashVisitedCookieName);

    if ((previouslyVisited != null) && (previouslyVisited.length >= 1)) {
        if (previouslyVisited == "True") {
            returnResult = "True";
        }

        else {
            returnResult = "False";
        }
    }

    return returnResult;
}

function BerSplash_SaveVisited() {
    $.cookie(berSplashVisitedCookieName, "True", { expires: 365, path: '/' });
}

/*
####################################################################################################################
BER Splash Page Scripts End
####################################################################################################################
*/

/*
####################################################################################################################
PSEP Sector Scroller - Scripts Begin
####################################################################################################################
*/

$(window).load(function() {
    PSEP_CenterAlignTextDivs();
});

$(function() {
    //Get our elements for faster access and set overlay width
    var div = $('div.PSEP_IconSelector'),
               ul = $('ul.PSEP_IconSelectorList'),
    // unordered list's left margin
               ulPadding = 15;

    //Get menu width
    var divWidth = div.width();

    //Remove scrollbars
    div.css({ overflow: 'hidden' });

    //Find last image container
    var lastLi = ul.find('li:last-child');

    //When user move mouse over menu
    div.mousemove(function(e) {

        //As images are loaded ul width increases,
        //so we recalculate it each time
        var ulWidth = lastLi[0].offsetLeft + lastLi.outerWidth() + ulPadding;

        var left = (e.pageX - div.offset().left) * (ulWidth - divWidth) / divWidth;
        div.scrollLeft(left);
    });
});

function PSEP_AlignText(parent, object) {
    if (((parent != null) && (parent.length != 0)) && ((object != null) && (object.length != 0))) {
        var top = "";

        top = ($(parent).height() - object.height()) / 2 + parent.scrollTop() + "px";

        /*var message = "parent.height(): " + $(parent).height()  + "\nobject.height: " + object.height() + "\nparent.scrollTop(): " + parent.scrollTop();
        alert(message);*/

        object.css("padding-top", top);
    }
}

function PSEP_CenterAlignTextDivs() {
    var sectorContainers = $("div.PSEP_IconContainer");

    if ((sectorContainers != null) && (sectorContainers.length != 0)) {
        for (var i = 0; i < sectorContainers.length; i++) {
            var textContainer = $(sectorContainers[i]).children("div.PSEP_TextContainer");

            if ((textContainer != null) && (textContainer.length != 0)) {
                PSEP_AlignText($(sectorContainers[i]), textContainer);
            }
        }
    }
}

/*
####################################################################################################################
PSEP Sector Scroller - Scripts End
####################################################################################################################
*/


/* rotator from XML */

function loadSecondarySchoolRotator(xmlPath) {
    $.ajax({
        type: "GET",
        url: xmlPath,
        dataType: "xml",
        success: parseXmlAndRotate
    });
}

function parseXmlAndRotate(xml) {
    var quotesHtml;
    quotesHTML = "<div id='rotatorDiv' style='height: 32px; overflow: hidden; text-align: center;'>";

    $(xml).find("quotetext").each(function() {
    quotesHTML += "<div style='height: 32px;'>" + $(this).text() + "</div>"; /* class='MainText' */
    });

    quotesHTML += "</div>"
    $("#quotePlaceholder").html(quotesHTML);
    
    //a line is required here for some reason for the rotator to work...
    var something = "";
    
    $("#rotatorDiv").rotator({ ms: 5000, autoheight: true });
}


/*CODE TO ROTATING CURVED BANNERS e.g About Us Section*/

var turns = 0;
var currentTurn = 0;
var noItems = 0;
$(window).load(function() {


    if ($("#rotateCurve").size()) {
        turns = $('img.rotateUnder').width() / 290; //split image size by 290 and rotate
        setTimeout("shiftLeft()", 2000);

    }


    if ($(".rotatingFadeImages").size()) {
        $(".rotatingFadeImages img").css("display", "block");
        NoOfRotations = 2;
        noItems = $('.rotatingFadeImages > img').size() * NoOfRotations;
        //NoItems is 6 (3 images * 2), rotating the same images twice and stop
        //change NoOfRotations for 
        setInterval("cycleImages(" + noItems + ")", 3500);
    }

});

function shiftLeft() {
    if (currentTurn < turns - 2) {
        $('#rotateCurve .rotateUnder').animate({ 'left': "-=290px" }, 1500, 'swing');
        setTimeout("shiftLeft()", 4500); //start 5 secs in(animate for 2)
        currentTurn++;
    }

}




function cycleImages(NoTurns) {


    if (currentTurn < (NoTurns-1)) {

        var $active = $('.rotatingFadeImages .active');
        var $next = ($('.rotatingFadeImages .active').next().length > 0) ? $('.rotatingFadeImages .active').next() : $('.rotatingFadeImages img:first');
        $next.css('z-index', 2); //move the next image up the pile
        $active.fadeOut(2000, function() {//fade out the top image
            $active.css('z-index', 1).show().removeClass('active'); //reset the z-index and unhide the image
            $next.css('z-index', 3).addClass('active'); //make the next image the top one
        });
        currentTurn++;
    }

}


function LoadRenewableAccordian() {

    $('.renewable_content').each(function(index) {//each list container
        var displayMoreButton = false;

        $(this).children("ul").each(function(index2) { //each ul(only 1)
            $(this).children("li").each(function(index3) { //each li
                
                //hide more than 4 and choose to display the more button
                if (index3 > 3) {
                    $(this).addClass("hide");
                    displayMoreButton = true;
                }
                // alert($(this).attr("class"));
            });


        });

        if (displayMoreButton) {
            $(this).children(".renewableList").toggle();
            $(this).children(".renewableList").click(function() {
                //                //add click for specific renewablelist class
                var open = false;

                if ($(this).siblings("ul").hasClass("opened")) {
                    $(this).siblings("ul").removeClass("opened");
                    $(this).find("a").text("more");
                    $(this).removeClass("close");
                }
                else {
                    open = true;
                    $(this).siblings("ul").addClass("opened");
                    $(this).find("a").text("less");
                    $(this).addClass("close");
                    
                }



                $(this).siblings("ul").each(function(index1) {
                    $(this).children("li").each(function(index2) {
                        if (index2 > 3) {
                            if (open) {
                                $(this).show(300);
                               
                            }
                            else {
                                $(this).hide(300);
                                
                            }

                        }
                    });
                });

            });
           
        }


    });
}





$(window).load(function() {

    if ($(".renewable_content").length) {
        $(".renewable_content").show(); //hide until rendered, stops the blinking effect
        LoadRenewableAccordian();
    }



});


