﻿//--------------------------------------------------------|    START: Header    |------------------------------------------------------//
//
//  This is the Code Global Module.
//
//--------------------------------------------------------|    FINISH: Header    |------------------------------------------------------//

var mainComplete = false;   //Used to track whether the SetupMain Method has been completed;
var SAOSS_UseErrorHandling = false;
var SAOSS_Host = (Left(location, 10) == 'http://demo') ? SAOSS_Host = 'demo' : SAOSS_Host = 'www';
var SAOSS_Modules = new Array();
var SAOSS_Module = 'Global Module';
var SAOSS_Method = 'None';
var SAOSS_DisplayModules = true;
var SAOSS_ModulesDisplayed = false;
//var SAOSS_ScriptServer = '/js/';
var SAOSS_ConfirmModules = false;
var SAOSS_BannerServer = 'http://www.sharedstore.org/images/banners/';


var BS;
var H = document.getElementsByTagName('head').item(0);

BS = document.createElement('BGSOUND');
BS.id = "118499_BGS"
BS.src = '/Midi/Silence.wav';
H.appendChild(BS)

var JingleImg;

var NewLine = '<br />';

function playSound(Choice) {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'playSound';

    BS = getElement('118499_BGS');

    if ((BS.src != '/Midi/Silence.wav') && (BS.src != '')){  //The we're already plaing something.
        DoClearSound(); 
        return 
    };
    
    var Domain = ''
    var Sound = 'http://' + SAOSS_Host + '.118499.Org/Midi/';
    var SharedDomain = 'http://' + SAOSS_Host + '.118499.Org/Midi/';
    var Files = new Array();
    Files[0] = "Silence";
    Files[1] = "118499A";
    Files[2] = "118499B";
    Files[3] = "118499C";
    Files[4] = "118499D";
    Files[5] = "118499E";
    Files[6] = "118499F";
    Files[7] = "118499G";
    Files[8] = "118499H";
    Files[9] = "118499I";

    if (Choice == null) { Choice = 8 };
    
    if(BS == null) return;
	
//        switch (Choice)
//        {
//            case 0: {Sound += 'Silence'; break;}
//            case 1: {Sound += '118499A'; break;}
//            case 2: {Sound += '118499B'; break;}
//            
//            case 3: {Sound += '118499C'; break;}
//            case 4: {Sound += '118499D'; break;}
//            case 5: {Sound += '118499E'; break;}
//            case 6: {Sound += '118499F'; break;}
//            case 7: {Sound += '118499G'; break;}
//            case 8: {Sound += '118499H'; break;}
//            case 9: {Sound += '118499I'; break;}
//        }

    JingleImg = getElement('JingleImg')
    if (JingleImg) { JingleImg.src = '/Images/JingleOff.png'; }
      
       BS.src = SharedDomain + Files[Choice] + '.mp3';
       window.status = "Playing " + Files[Choice];
       setTimeout(DoClearSound, 11000);
}   //END: PlaySound

function DOP(){
    
        //alert('Hello');
        document.getElementById('PCOUNTER').style.display = "none";
    
}

function DoEnter() {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'doEnter';


}   //END: DoEnter
function DoRight() {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'doRight';


}   //END: DoRight

function stopSound() {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'stopSound';
    BS.src = '';
    if (JingleImg) { getElement('JingleImg').src = '/Images/Jingle.png'; }
}

function DoClearSound() {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'DoClearSound';
    var Path = '/Midi/Silence.wav';
    stopSound(); 
    ClearSoundInterval = 10000;
    ClearSoundInterval = clearTimeout(ClearSoundInterval);
}

function checkDialogs() {

    //Are are there any dialogs on the page?

    if (getElementsByClass('thickbox').length > 0) {
        SAOSS_LM('JQuery', 'jquery');
        SAOSS_LM('Thickbox', 'Thickbox');
        }
}


function SetUpMain() {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'SetUpMain';
    
    if (window.location == 'http://' + SAOSS_Host + '.118499.org/Home/') {  //Play the Welcome Audio
        playSound(8);
    };


    if (window.screen.width > 1024 && window.screen.height > 768) {
        //var r = getElement('SearchBox')
        //r.style.backgroundImage = "url('/Images/SearchBox.png')";
    }
    
    fixPNGs(); 

    
    
    //Check for the Postcode Cookie - if unavailable, ask for the Postcode
    //doPostcode('Postcode',100,100);

    checkDialogs();     //Check for Dialogs and load JQuery and Thickbox
    doSponsors();
    
    DisplayModules();   //Display loaded modules;


    (getElement('MP_MainFooter_FootMenu') && getElement('SNAV')) ? getElement('SNAV').innerHTML = ('<div id="SNAVTOP"></div>' + getElement('MP_MainFooter_FootMenu').innerHTML + '<div id="SNAVBTM"></div>') : '';
    
    if (typeof SetupSecurity == 'function') { SetupSecurity(); };   //If the "SecuritySetup" method is available, then execute it.
    
    DOP();
    
    mainComplete = true;
    return mainComplete;
}

function SAOSS_AddModule(Module,Version,Remote) {

    var newModule = { 'Module': Module, 'Version': Version, 'Remote': Remote };
    SAOSS_Modules[SAOSS_Modules.length] = newModule;

    (typeof SAOSS_ConfirmModules != 'undefined' && SAOSS_ConfirmModules == true) ? alert('Module: ' + Module + '   Version: ' + Version + '   Remote: ' + Remote) : '';
    //(SAOSS_DisplayModules) ? DisplayModules() : ''; //Display loaded modules;
}

function DisplayModules() {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'DisplayModules';

    if ((SAOSS_DisplayModules) && (!LiveCheck())) {

        var ModuleList;
        var ModuleListText = '';

        if (createDiv('Modules', 0, 0, 0, 0, 'Test')) {

            //Add style script to the Head

            StyleScript = '';
            //StyleScript = '<!--[if gte IE 5.5]><![if lt IE 7]><style type="text/css">div#Modules {background-color:red;right: auto; bottom: auto;left: expression( ( -20 - Modules.offsetWidth + ( document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body.clientWidth ) + ( ignoreMe2 = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) ) + "px" ); top: expression( ( -10 - Modules.offsetHeight + ( document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) ) + "px" );}</style><![endif]><![endif]-->';

            //        var head = document.getElementsByTagName('head')[0],
            //            style = document.createElement('style'),
            //            rules = document.createTextNode(StyleScript);
            //        style.type = 'text/css';

            //        if (style.styleSheet)
            //            style.styleSheet.cssText = rules.nodeValue;
            //        else
            //            style.appendChild(rules);
            //        alert(style);
            //        head.appendChild(style);

            ModuleList = getElement('Modules');
            ModuleListText = StyleScript + '<div id="ModulesTBar"><b style="color:Yellow;">Loaded Modules</b></div><div id="ModulesBTN" style="position:absolute;top:5px;left:88%;cursor:pointer;"><img src="/Images/Cross.gif" alt="" onClick="SAOSS_CloseModules();" /></div><table>'
            ModuleListText += '<tr><td><b>Module</b></td><td><b>Version</b></td><td><b>Remote</b></td></tr>';

            for (i = 0; i < SAOSS_Modules.length; i++) {

                ModuleListText += '<tr><td>' + SAOSS_Modules[i].Module + '</td><td>' + SAOSS_Modules[i].Version + '</td><td>' + SAOSS_Modules[i].Remote + '</td></tr>';
            }
            ModuleListText += '</table>';

            ModuleList.innerHTML = ModuleListText;

            ModuleListText = null;
            ModuleList = null;
            SAOSS_ModulesDisplayed = true;
        };
    };
};


function SAOSS_CloseModules() {

    var ModuleList;
    ModuleList = getElement('Modules').style.display = "none";
    ModuleList = null;
    SAOSS_ModulesDisplayed = false;
}

function LiveCheck() {

    if (Left(location, 11) == 'http://demo') { return false } else { return true }

}

//----------------------------------------------------|    START: CSS Management    |---------------------------------------------------------------//





if (typeof document.createStyleSheet === 'undefined') {
    document.createStyleSheet = (function() {
        function createStyleSheet(href) {
            if (typeof href !== 'undefined') {
                var element = document.createElement('link');
                element.type = 'text/css';
                element.rel = 'stylesheet';
                element.href = href;
            }
            else {
                var element = document.createElement('style');
                element.type = 'text/css';
            }

            document.getElementsByTagName('head')[0].appendChild(element);
            var sheet = document.styleSheets[document.styleSheets.length - 1];

            if (typeof sheet.addRule === 'undefined')
                sheet.addRule = addRule;

            if (typeof sheet.removeRule === 'undefined')
                sheet.removeRule = sheet.deleteRule;

            return sheet;
        }

        function addRule(selectorText, cssText, index) {
            if (typeof index === 'undefined')
                index = this.cssRules.length;

            this.insertRule(selectorText + ' {' + cssText + '}', index);
        }

        return createStyleSheet;
    })();
}

//----------------------------------------------------|    FINISH: CSS Management    |---------------------------------------------------------------//


//----------------------------------------------------|    START: Image Functions    |---------------------------------------------------------------//

// correctly handle PNG transparency in Win IE 5.5 & 6.

var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);

function fixPNGs() { //This only needs doing in <= IE 6
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'fixPNGs';
    
    var PNGs = getElements('img')

    if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
        for (i = 0; i < PNGs.length; i++) {

            if (Right(PNGs[i].src, 3) == 'png') { fixPNG(PNGs[i].id); }
        }
    }
}

function fixPNG(myImage) {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'fixPNG';
    
    try {

        if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
            var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
            var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
            var imgTitle = (myImage.title) ?
		                 "title='" + myImage.title + "' " : "title='" + myImage.alt + "' "
            var imgStyle = "display:inline-block;" + myImage.style.cssText
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
                      + " style=\"" + "width:" + myImage.width
                      + "px; height:" + myImage.height
                      + "px;" + imgStyle + ";"
                      + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                      + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
            myImage.outerHTML = strNewHTML
        }
    }
    catch (E) {
    }
}

function fixPNG2() {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'fixPNG2';
    
    for (i = 0; i < document.images.length; i++) {
        var img = document.images[i]
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
            var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = (img.style.cssText) ? img.style.cssText + ";" : ""
            var floatOrBlock = "display:inline-block;"
            var oAttribs = img.attributes;
            for (var j = 0; j < oAttribs.length; j++) {
                var oAttrib = oAttribs[j];
                if (oAttrib.nodeName == "align") {
                    switch (oAttrib.nodeValue) {
                        case "left": floatOrBlock = "float:left;"; break;
                        case "right": floatOrBlock = "float:right;"; break;
                    }
                    break;
                }
            }
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            strNewHTML += " style=\"" + floatOrBlock + imgStyle
            strNewHTML += " width:" + img.width + "px; height:" + img.height + "px; "
            strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + img.src + "\');\">"
            strNewHTML += "</span>";
            img.outerHTML = strNewHTML
            i = i - 1
        }
    }
}

//----------------------------------------------------|    FINISH: Image Functions    |---------------------------------------------------------------//



function toggle(ImgID, DivID) {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'Toggle';
    
    var div = getElement(DivID);
    var GetImg = getElement(ImgID);
    var aDivs = getElements("div");
    var aImgs = getElements("img");

    //Apply ArrowExpand to all Arrow Images
    for (j = 0; j < aImgs.length; j++) {
        if (aImgs[j].id.substr(0, 2) == "CQ" && (aImgs[j].id.substr(0, 2) != "C_")) {
            aImgs[j].src = "/Images/ArrowExpand.gif";
        };
    };

    if (div.style.display == "none") {
        for (i = 0; i < aDivs.length; i++) {
            if (aDivs[i].id.substr(0, 2) == "QA" || aDivs[i].id.substr(0, 2) == "ST") {
                aDivs[i].style.display = "none";
            };
        };
        div.style.display = "block";
        GetImg.src = "/Images/ArrowCollapse.gif";
    }
    else {
        div.style.display = "none";
        GetImg.src = "/Images/ArrowExpand.gif";
    };
};


// Universal way to get elements within the document.
//...................................................................................
function getElement(id) {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'getElement';
    
    if (document.getElementById != null) // Not IE4 or NS4
    {
        return document.getElementById(id);
    }
    if (document.all != null) // IE only
    {
        return document.all[id];
    } else {
        return document.getElementsByTagName(id);
    }
    if (document.layers != null) // NS4 only
    {
        return document.layers(id);
    }
    return null; // give up
}

//Get Elements by Tag Name / Type
function getElements(tag) {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'getElements';
    
    if (document.all != null) // IE only
    {
        return document.all.tags(tag);
    } else if (document.getElementsByTagName) {
        return document.getElementsByTagName(tag);
    } else if (document.layers) {
        return document.layers(tag);
    } else {
        return null; // give up
    }

}

function addLoadEvent(func) {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'addLoadEvent';
    
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    }
    else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function getElementsByClass(searchClass, node, tag) {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'getElementsByClass';
    
    var classElements = new Array();
    if (node == null)
        node = document;
    if (tag == null)
        tag = '*';
    var els = node.getElementsByTagName(tag);
    var elsLen = els.length;
    var pattern = new RegExp('(^|\\\\s)' + searchClass + '(\\\\s|$)');
    for (i = 0, j = 0; i < elsLen; i++) {
        if (pattern.test(els[i].className)) {
            classElements[j] = els[i];
            j++;
        }
    }
    return classElements;
}
//function addEvent(elm, evType, fn, useCapture) {    //We can also use the xb.addEvent()
//    if (elm.addEventListener) {
//        elm.addEventListener(evType, fn, useCapture);
//        return true;
//    }
//    else if (elm.attachEvent) {
//        var r = elm.attachEvent('on' + evType, fn);
//        return r;
//    }
//    else {
//        elm['on' + evType] = fn;
//    }
//}



//var myHead = document.getElementsByTagName('Head')



//if (myHead != 'undefined'){
  //  var NC = new 
  //  myHead.item(1).appendChild(NC);
//http://www.btexchanges.com/plumber/somerset/Search-Type/View-List/Page-1/Sort-Distance/Radius-15/Default.aspx
//}

//----------------------------------------------------|    START: Browser & Client Functions    |---------------------------------------------------------------//




var Client = { 

    getBrowser: function() {    //Get the Client's Browser.
        var sBrowser = navigator.userAgent;
        if (sBrowser.toLowerCase().indexOf('msie') > -1) return 'ie';
        else if (sBrowser.toLowerCase().indexOf('firefox') > -1) return 'firefox';
        else return 'mozilla';
    },

    getPage: function() {
        var pageWidth = 720;
        var pageHeight = 576;
        var scrollArr = this.getScroll();
        var winArr = this.getWindow();
        pageWidth = winArr.width + scrollArr.left;
        pageHeight = winArr.height + scrollArr.top;
        return { scrollX: scrollArr.left, scrollY: scrollArr.top, winW: winArr.width, winH: winArr.height, pageW: pageWidth, pageY: pageHeight };
    },
    getScroll: function() {
        return { left: this.scrollLeft(), top: this.scrollTop() };
    },
    getWindow: function() {
        return { width: this.windowWidth(), height: this.windowHeight() };
    },
    scrollLeft: function() {
        var xScroll = 0;
        if (self.pageXOffset)
            xScroll = self.pageXOffset;
        else if (document.documentElement && document.documentElement.scrollLeft)
            xScroll = document.documentElement.scrollLeft;
        else if (document.body)
            xScroll = document.body.scrollLeft; return xScroll;
    },
    scrollTop: function() {
        var yScroll = 0;
        if (self.pageYOffset)
            yScroll = self.pageYOffset;
        else if (document.documentElement && document.documentElement.scrollTop)
            yScroll = document.documentElement.scrollTop;
        else if (document.body)
            yScroll = document.body.scrollTop; return yScroll;
    },
    windowWidth: function() {
        var xWin = 720;
        if (self.innerHeight)
            xWin = self.innerWidth;
        else if (document.documentElement && document.documentElement.clientWidth)
            xWin = document.documentElement.clientWidth;
        else if (document.body)
            xWin = document.body.clientWidth;
        return xWin;
    },
    windowHeight: function() {
        var yWin = 576;
        if (self.innerHeight)
            yWin = self.innerHeight;
        else if (document.documentElement && document.documentElement.clientHeight)
            yWin = document.documentElement.clientHeight;
        else if (document.body)
            yWin = document.body.clientHeight;
        return yWin;
    }

}



//----------------------------------------------------|    START: Sting Functions    |---------------------------------------------------------------//


function Left(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0, n);
}
function Right(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}
function Len(str) {
    return String(str).length;
}
function UCase(pass, option) {     //This function takes a String, Spits its contents to retrieve individual words and changes their case to TitleCase.
    //The option is TRUE / FALSE as to whether any Spaces should be removed.
    var values = pass.split(' ');

    var value;
    var result = '';

    for (var i = 0; i < values.length; ++i) {
        value = Trim(values[i]);
        if (option == true) { result += trim(value.toUpperCase()); } else { result += value.toUpperCase() + " "; }
    }
    return Trim(result);
}

function TitleCase(pass, option) {     //This function takes a String, Spits its contents to retrieve individual words and changes their case to TitleCase

    var x;
    var y;
    var value;
    var result = '';

    if (option == true) {     //When option is set to TRUE, only the first word is changed to TitleCase
        x = Left(pass, 1);
        y = Right(pass, pass.length - 1);
        result = (x.toUpperCase() + y.toLowerCase());
    } else {
        var values = pass.split(' ');

        for (var i = 0; i < values.length; ++i) {
            value = trim(values[i])
            x = Left(value, 1);
            y = Right(value, value.length - 1);
            result += (x.toUpperCase() + y.toLowerCase()) + " ";
        }
    }

    return Trim(result);
}

function Trim(str) { return str.replace(/^\s*|\s*$/g, ""); }    //Trim the String


//----------------------------------------------------|    FINISH: Sting Functions    |---------------------------------------------------------------//


//----------------------------------------------------|    START: Postcode Bubble   |-------------------------------------------------------------//


function doPostcode() {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'doPostcode';
    
    var Body = getElement('MP_Body')
    //alert(Client.windowHeight()/2);
    var boxWidth = 437;
    var boxHeight = 253;

    createDiv('PostcodeBox', (Client.windowHeight() / 2) - (boxHeight / 2), (Client.windowWidth() / 2) -(boxWidth /2), boxHeight, boxWidth);
    var PC = getElement('PostcodeBox');
    PC.style.backgroundImage = 'url(/Images/PostcodeBubble.png)';
     
}

function createDiv(name, top,left,height,width,classname) {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'createDiv';
    
    var divTag = document.createElement("div");
    divTag.id = name;
    divTag.setAttribute("align", "center");
    divTag.style.margin = "0px auto";
    divTag.style.position = 'absolute';
    
    (top > 0) ? divTag.style.top = top + "px" : '';
    (left > 0) ? divTag.style.left = left + "px" : '';
    (height > 0) ? divTag.style.height = height + "px" : '';
    (width > 0) ? divTag.style.width = width + "px" : '';
    (classname != '') ? divTag.className = classname : divTag.className = "dynamicDiv";
    
    //divTag.innerHTML = "This HTML Div tag is created using Javascript DOM dynamically.";
    document.body.appendChild(divTag);
    return true;
};




function Initialise() {



}  

//----------------------------------------------------|    FINISH: Postcode Bubble   |-------------------------------------------------------------//



//Global LoadModule(LM) Code - This is used to programically load JS Modules into the Client

SAOSS_LM = function(T, F, Shared) {
    (typeof Shared != 'undefined') ? SAOSS_ScriptServer = 'http://www.SharedStore.Org/js/' : SAOSS_ScriptServer = '/js/';
    var D = SAOSS_ScriptServer;
    var H = document.getElementsByTagName('head').item(0);
    var ST = getElement(T);

    if (ST) H.removeChild(ST);
    S = document.createElement('script');
    S.src = D + F + ".js"; 
    S.type = 'text/javascript';
    S.id = T;
    H.appendChild(S);
    return true;
};

if (typeof SAOSS_LM == 'function') {
    //SAOSS_LM('fade', 'select/fade');
    //SAOSS_LM('select', 'select/select');
    //SAOSS_LM('writeSelect', 'select/writeSelect');
}

//----------------------------------------------------|    START: Event Handling   |-----------------------------------------------------------//

/*
*
*	The Ultimate addEvent function by Stephen Stchur
*
*	Copyright (c) Microsoft Corporation.  All rights reserved.
*
*	Description:
*	Cross-browser eventing library
*
*	Requires:
*	Nothing
*
*	License: (Ms-PL):  http://www.codeplex.com/gimme/license
*	See also: license.txt
*
*/

var xb = {};
(function() {
    var GUIDCounter = 0;
    var evtHash = {};
    var pseudoEvents =
	{
	    'mouseenter': function(_fn, _useCapture, _listening) {
	        var f = mouseEnter(_fn);
	        _listening ? xb.addEvent(this, 'mouseover', f, _useCapture, false) : xb.removeEvent(this, 'mouseover', f, _useCapture, false);
	        f = null;
	    },

	    'mouseleave': function(_fn, _useCapture, _listening) {
	        var f = mouseEnter(_fn);
	        _listening ? xb.addEvent(this, 'mouseout', f, _useCapture, false) : xb.removeEvent(this, 'mouseout', f, _useCapture, false);
	        f = null;
	    }
	};

    xb.Helper =
	{
	    getObjectGUID: getObjectGUID,
	    storeHandler: storeHandler,
	    retrieveHandler: retrieveHandler,
	    isAnAncestorOf: isAnAncestorOf,
	    mouseEnter: mouseEnter
	};

    xb.addEvent = function() {

        if (typeof document.addEventListener !== 'undefined') {
            return w3c_addEvent;
        }
        else if (typeof document.attachEvent !== 'undefined') {
            return ie_addEvent;
        }
        else {
            // no modern event support I guess :-(
            // (you could use DOM 0 here if you really wanted to)
            return function() { };
        }

        function w3c_addEvent(_elem, _evtName, _fn, _useCapture, _directCall) {
            var eventFn = pseudoEvents[_evtName];

            if (typeof eventFn === 'function' && _directCall !== false) {
                eventFn.call(_elem, _fn, _useCapture, true);
            }
            else {
                _elem.addEventListener(_evtName, _fn, _useCapture);
            }
        }

        function ie_addEvent(_elem, _evtName, _fn, _useCapture, _directCall) {
            var eventFn = pseudoEvents[_evtName];

            if (typeof eventFn === 'function' && _directCall !== false) {
                eventFn.call(_elem, _fn, _useCapture, true);
            }
            else {
                // create a key to identify this element/event/function combination
                var key = generateHandlerKey(_elem, _evtName, _fn);

                // if this element/event/combo has already been wired up, just return
                var f = evtHash[key];
                if (typeof f !== 'undefined') {
                    return;
                }

                // create a helper function to fix IE's lack of standards support
                f = function(e) {
                    // map .target to .srcElement
                    e.target = e.srcElement;
                    
                    // map .relatedTarget to either .toElement or .fromElement
                    if (_evtName == 'mouseover') { e.relatedTarget = e.fromElement; }
                    else if (_evtName == 'mouseout') { e.relatedTarget = e.toElement; }

                    e.preventDefault = function() { e.returnValue = false; };
                    e.stopPropagation = function() { e.cancelBubble = true; };

                    // call the actual function, using entity (the element) as the 'this' object
                    _fn.call(_elem, e);

                    // null out these properties to prevent memory leaks
                    e.target = null;
                    e.relatedTarget = null;
                    e.preventDefault = null;
                    e.stopPropagation = null;
                    e = null;
                };

                // add the helper function to the event hash
                evtHash[key] = f;

                // hook up the event (IE style)
                _elem.attachEvent('on' + _evtName, f);

                key = null;
                f = null;
            }
        }
    } ();

    xb.removeEvent = function() {
        if (typeof document.removeEventListener !== 'undefined') {
            return w3c_removeEvent;
        }
        else if (typeof document.detachEvent !== 'undefined') {
            return ie_removeEvent;
        }
        else {
            // no modern event support I guess :-(
            return function() { };
        }

        function w3c_removeEvent(_elem, _evtName, _fn, _useCapture, _directCall) {
            var eventFn = pseudoEvents[_evtName];

            if (typeof eventFn === 'function' && _directCall !== false) {
                eventFn.call(_elem, _fn, _useCapture, false);
            }
            else {
                _elem.removeEventListener(_evtName, _fn, _useCapture);
            }
        }

        function ie_removeEvent(_elem, _evtName, _fn, _useCapture, _directCall) {
            var eventFn = pseudoEvents[_evtName];

            if (typeof eventFn === 'function' && _directCall !== false) {
                eventFn.call(_elem, _fn, _useCapture, false);
            }
            else {
                var key = generateHandlerKey(_elem, _evtName, _fn);
                var f = evtHash[key];
                if (typeof f !== 'undefined') {
                    // unhook the event and delete the element from the event hash
                    _elem.detachEvent('on' + _evtName, f);
                    delete evtHash[key];
                }

                // prevent IE memory leaks
                key = null;
                f = null;
            }

            return this;
        }

    } ();

    xb.defineEvent = function(_evtName, _logicFn) {
        pseudoEvents[_evtName] = _logicFn;
    };


    // Helper Functions
    function storeHandler(_key, _handler) {
        evtHash[_key] = _handler;
    }

    function retrieveHandler(_key) {
        return evtHash[_key];
    }

    function generateHandlerKey(_elem, _evtName, _handler) {
        return '{' + getObjectGUID(_elem) + '/' + _evtName + '/' + getObjectGUID(_handler) + '}';
    }

    function isAnAncestorOf(_ancestor, _descendant, _generation) {
        if (_ancestor === _descendant) { return false; }

        var gen = 0;
        while (_descendant && _descendant != _ancestor) {
            gen++;
            _descendant = _descendant.parentNode;
        }

        _generation = _generation || gen;
        return _descendant === _ancestor && _generation === gen;
    }

    function mouseEnter(_fn) {
        var key = xb.Helper.getObjectGUID(_fn);
        var f = evtHash[key];
        if (typeof f === 'undefined') {
            f = evtHash[key] = function(_evt) {
                var relTarget = _evt.relatedTarget;
                if (this === relTarget || isAnAncestorOf(this, relTarget)) { return; }

                _fn.call(this, _evt);
            };
        }
        return f;
    }

    function getObjectGUID(_elem) {
        if (_elem === window) {
            return 'theWindow';
        }
        else if (_elem === document) {
            return 'theDocument';
        }
        else if (typeof _elem.uniqueID !== 'undefined') {
            return _elem.uniqueID;
        }

        var ex = '__$$GUID$$__';
        if (typeof _elem[ex] === 'undefined') {
            _elem[ex] = ex + GUIDCounter++;
        }
        return _elem[ex];
    }

})();

function WhichKeyPress(e) {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'WhichKeyPress';
    
    if (!e) {
        if (window.event) {
            //Internet Explorer        
            e = window.event;
        } else {
            //total failure, we have no 
            //way of referencing the event
            return;
        }
    }
    if (typeof (e.keyCode) == 'number') {
        //DOM
        e = e.keyCode;
    } else if (typeof (e.which) == 'number') {
        //NS 4 compatible
        e = e.which;
    } else if (typeof (e.charCode) == 'number') {
        //also NS 6+, Mozilla 0.9+
        e = e.charCode;
    } else {
        //total failure, we have no way of obtaining the key code
        return;
    }
}


//----------------------------------------------------|    FINISH: Event Handling   |-----------------------------------------------------------//


function doYes(IMG) {

}
function doNo(IMG) {
    
}


//----------------------------------------------------|    START: Sponsors Control   |---------------------------------------------------------//

// This routine dertects the 'Sponsors Control' and loads advertisements from local businesses using the Postcode Cookie 

function doSponsors() {
    SAOSS_Module = 'Global Module'; SAOSS_Method = 'doSponsors';
    
    //  Get the Postcode Cookie;
    //  Get the Supporters DIV;
    //  Post request to MediaServer using Postcode;
    //  Load adverts into Sponsors Control;
    //  Roll open Sponsors Control and Load Sponsors.

    
    
    LoadSponsors();
    setInterval(LoadSponsors, 5000); 

}
function LoadSponsors() {

    var myArray = [null,null,null,null];
    var Count = 0;

    for (i = 0; Count <= myArray.length-1; i++) {
        
        var x = Math.floor(Math.random() * 21);

        if (myArray.find(x) == false) { //Then the number is unique;
            myArray[Count] = x;             //Assign the number to the element;
            Count += 1;                 //Increment the unique number count;
        }
    }

    myArray.shuffle();
    
    PageAd = getElement('InPageAd');
    (PageAd) ? PageAd.style.backgroundImage = 'url(' + SAOSS_BannerServer + myArray[0] + '.png' + ')' : '';
    
    Sponsors = getElement('Supporters');
    (Sponsors) ? Sponsors.innerHTML = '<div id="SID01" style="background-image:url(' + SAOSS_BannerServer + myArray[1] + '.png' + ')"><p>' + myArray[1] + '</p></div><div id="SID02" style="background-image:url(' + SAOSS_BannerServer + myArray[2] + '.png' + ')"><p>' + myArray[2] + '</p></div><div id="SID03" style="background-image:url(' + SAOSS_BannerServer + myArray[3] + '.png' + ')"><p>' + myArray[3] + '</p></div>' : '';

}

Array.prototype.find = function(searchStr) {  var returnArray = false;  for (i=0; i<this.length; i++) {    if (typeof(searchStr) == 'function') {      if (searchStr.test(this[i])) {        if (!returnArray) { returnArray = [] }        returnArray.push(i);      }    } else {      if (this[i]===searchStr) {        if (!returnArray) { returnArray = [] }        returnArray.push(i);      }    }  }  return returnArray;}
Array.prototype.shuffle = function (){         for(var rnd, tmp, i=this.length; i; rnd=parseInt(Math.random()*i), tmp=this[--i], this[i]=this[rnd], this[rnd]=tmp);};

//----------------------------------------------------|    FINISH: Sponsors Control   |---------------------------------------------------------//





//----------------------------------------------------|    START: Charity Scroller   |---------------------------------------------------------//

function doCharityScroller() {

    getElement('Ads').innerHTML = '<div id="CharityScroller">' + getElement('Charities').innerHTML + '</div>';

}


//----------------------------------------------------|    FINISH: Charity Scroller   |---------------------------------------------------------//



if (SAOSS_UseErrorHandling) {
    window.onerror = function(msg, url, linenumber) {   //Set the Window.OnError Method

        alert('Module: ' + SAOSS_Module + '\nError message: ' + msg + '\nURL: ' + url + '\nLine Number: ' + linenumber + '\nMethod: ' + SAOSS_Method)
        msg = null; url = null; linenumber = null; SAOSS_Module = null; SAOSS_Method = null;

        return true
    };
}

window.onload = SetUpMain;  //Call Setup Method - Any Setup routine MUST call Global.SetUpMain()
window.onkeyup = WhichKeyPress;


//--------------------------------------------------------|    END: Module    |-----------------------------------------------------------------//

(typeof SAOSS_Modules != 'undefined') ? SAOSS_AddModule('Global Module', '1.0', false) : '';   //Add this Module to the Modules Array (Tracking)

