﻿

var NeotekPopup = {
    // Used as Private Varibles
    _title: null,
    _url: null,
    _src: null,
    _includeClose: true,
    _className: null,
    _closeOnLoseFocus: false,
    _width: '200',
    _height: '400',
    _allowDrag: true,
    _customPosition: null,
    _doFade: false,
    _doAnimate: null,
    _fadeBoxIn: false,
    _autoResize: true,
    _backgroundColor: 'Transparent',
    _showTriangle: null,
    _message: '',
    SetDefault: function() {
        var o = NeotekPopup;
        o._title = null;
        o._url = null;
        o._src = '';
        o._includeClose = true;
        o._className = 'neotekPopupBase';
        o._closeOnLoseFocus = '';
        o._width = '600';
        o._height = '420';
        o._allowDrag = true;
        o._customPosition = null;
        o._doFade = true;
        o._doAnimate = null;
        o._fadeBoxIn = false;
        o._autoResize = false;
        o._backgroundColor = null; //'#FFFBD0';
        o._showTriangle = null;
        o._message = '';
        return o;
    },
    Show: function(settings) {
        var o = NeotekPopup.SetDefault(); // Set Back to Default Values
        if (settings.Title) o._title = settings.Title;
        if (settings.URL) o._url = settings.URL;
        if (settings.src) o._src = settings.src;
        if (settings.IncludeClose != null) o._includeClose = settings.IncludeClose;
        if (settings.ClassName) o._className = settings.ClassName;
        if (settings.CloseOnLoseFocus != null) o._closeOnLoseFocus = settings.CloseOnLoseFocus;
        if (settings.Width) o._width = settings.Width;
        if (settings.Height) o._height = settings.Height;
        if (settings.AllowDrag != null) o._allowDrag = settings.AllowDrag;
        if (settings.DoFade != null) o._doFade = settings.DoFade;
        if (settings.Animate) o._doAnimate = settings.Animate;
        if (settings.FadeBoxIn != null) o._fadeBoxIn = settings.FadeBoxIn;
        if (settings.AutoResize != null) o._autoResize = settings.AutoResize;
        if (settings.BackgroundColor) o._backgroundColor = settings.BackgroundColor;
        if (settings.ShowTriangle != null) o._showTriangle = settings.ShowTriangle;
        if (settings.Message != '' && settings.Message != null) o._message = settings.Message;
        if (settings.Position) {
            var e = !!settings.Position ? settings.Position : window.event;
            var ooo = null;
            try { ooo = top.document.getElementById('InfoFrame'); } catch (ex) { }
            var offsetTop = 0
            var offsetLeft = 0;
            if (ooo) {
                offsetTop = ooo.offsetTop;  //GetScreenHeight() - ooo.offsetHeight;
                offsetLeft = ooo.offsetLeft;  //top.document.body.clientWidth - ooo.offsetWidth;
            }
            o._customPosition = [e.clientX + offsetLeft, e.clientY + offsetTop];
        }
        o.Popup();
        if (o._message != '')
            setTimeout('NeotekPopup.GetUrlCallback(NeotekPopup._message);', 100);
        else if (o._src != '')
            NeotekPopup.GetImage(o._src);
        else
            o.GetUrl(o._url); // Must do after above otherwise cache can return too quickly giving errors
    },
    Close: function() {
        var o = $top('Neotek_Popup');
        if (o) o.style.display = 'none';

        Fade.FadeOut('fadePopup', 60);
        if (o) document.body.removeChild(o);
    },
    GetUrl: function(url) {
        url = url.replace('~/', 'http://' + window.location.host + '/');
        try {
            top.neotekText(url, NeotekPopup.GetUrlCallback, null); // Call Ajax - Set return function id insert
        } catch (ex) { neotekText(url, NeotekPopup.GetUrlCallback, null); }
    },
    GetImage: function(src) {

        var bgColour = NeotekPopup._backgroundColor;
        var o = $top('Neotek_Popup_Content');
        if (!!!o) return; //NeotekPopupContent does not exist in DOM (might return too quick)
        if (bgColour)
            o.style.backgroundColor = bgColour;
        o.innerHTML = '<img src=\"' + src + '\"/>';
        var i = new Image();
        i.onload = NeotekPopup.SetPosition;
        i.src = src;
    },
    GetUrlCallback: function(retVal) {
        var bgColour = NeotekPopup._backgroundColor;
        var o = $top('Neotek_Popup_Content');
        if (!!!o) return; //NeotekPopupContent does not exist in DOM (might return too quick)
        if (bgColour)
            o.style.backgroundColor = bgColour;
        o.innerHTML = retVal;
        NeotekPopup.SetPosition();
    },
    SetPosition: function() {
        var bgColour = NeotekPopup._backgroundColor;
        if (NeotekPopup._doAnimate)
            Animate.Start('Neotek_Popup', [50, 50], [NeotekPopup._width, o.offsetHeight], 1000, NeotekPopup._doAnimate);
        o = $top('Neotek_Popup');
        o.style.display = 'block';
        //setTimeout("$('Neotek_Popup').style.display = 'block';",5); // Makes things go weird but stops the flicker for animations
        if (NeotekPopup._fadeBoxIn) Fade.FadeIn(o.id, 100, 1000);

        if (NeotekPopup._autoResize) {
            o.style.width = null;
            o.style.height = null;
        } else {
            o.style.width = NeotekPopup._width + 'px';
            o.style.height = NeotekPopup._height + 'px';
        }

        var scrollY = 0;
        try { scrollY = parseInt(GetScrollPosition()); } catch (ex) { } // ---Not required as will always be zero as we only scroll the iframe, but remains for completeness

        var xPos = 'left';
        var left = 0;
        var topPos = 0;
        o.style.margin = '0px';
        var screenW = GetScreenWidth();
        var screenH = GetScreenHeight();
        var offset = 5;
        if (NeotekPopup._customPosition) {
            topPos = NeotekPopup._customPosition[1] + scrollY - offset;
            left = NeotekPopup._customPosition[0] - offset;
        } else {
            topPos = (screenH / 2) - (NeotekPopup._height / 2) + scrollY;
            left = (screenW / 2) - (NeotekPopup._width / 2);
        }

        if (NeotekPopup._customPosition) {
            var rightedge = left + parseInt(o.offsetWidth); // parseInt(NeotekPopup._width);
            if (rightedge > screenW) {
                xPos = 'right';
                left = left - o.offsetWidth + (offset * 2);    //add offset * 2 to ensure cursor is over popup
            }
            var isTop = true;
            bottomedge = topPos + o.offsetHeight;
            if (bottomedge > screenH) { // This still needs a little work when at bottom with scrollbars
                topPos = topPos - o.offsetHeight + (offset * 2); //add offset * 2 to ensure cursor is over popup
                isTop = false;
            }

            if (NeotekPopup._showTriangle == null) {
                NeotekPopup._showTriangle = new Array();
                NeotekPopup._showTriangle[1] = isTop ? 'top' : 'bottom';
                NeotekPopup._showTriangle[0] = xPos;
            }
        }

        if (left < 0) {
            left = 10;
        }
        o.style.left = left + 'px';
        if (topPos < 0) {
            xPos = 'none';
            topPos = 10;
        }
        o.style.top = topPos + 'px';

        var title = $top('neotekPopupTitle');
        if (title && bgColour) title.style.backgroundColor = bgColour;
        if (bgColour)
            $top('popContentArea').style.backgroundColor = bgColour;
        if (Set.isTop) {
            top.RoundedTop("div#Neotek_Popup", "Transparent", bgColour);
            top.RoundedBottom("div#roundedDivBottom", "Transparent", bgColour);
        } else {
            RoundedTop("div#Neotek_Popup", "Transparent", bgColour);
            RoundedBottom("div#roundedDivBottom", "Transparent", bgColour);
        }

        if (NeotekPopup._showTriangle && xPos != 'none') {
            NeotekPopup._showTriangle = new Array();
            NeotekPopup._showTriangle[1] = isTop ? 'top' : 'bottom';
            NeotekPopup._showTriangle[0] = xPos;
            var isTop = (NeotekPopup._showTriangle[1].toLowerCase() == 'top');
            NeotekPopup.DisplayTriangle(o, NeotekPopup._showTriangle[0], isTop, bgColour);
        }

        /* Run any scripts returned */
        var o = $top('Neotek_Popup_Content');
        var scripts = o.getElementsByTagName('script');
        for (var i = 0; i < scripts.length; ++i) {
            try {
                eval(scripts[i].innerHTML);
            } catch (e) { }
        }
    },
    Popup: function() {
        var o = Set.doc.createElement('div');
        o.className = NeotekPopup._className;
        o.id = 'Neotek_Popup';
        o.style.width = NeotekPopup._width + 'px';

        var innerText = '';

        if (NeotekPopup._title != '' && NeotekPopup._title != null) {
            innerText += '<div id="neotekPopupTitle" class="neotekPopupTitle" ';
            if (NeotekPopup._allowDrag) innerText += ' title="Click, hold and move to drag" ';
            innerText += '>';
            innerText += '<div id="roundedDivTop"></div>';
            innerText += NeotekPopup._title + '</div>';
        }
            if (NeotekPopup._includeClose)
                innerText += '<div class="neotekPopupClose" onclick="NeotekPopup.Close()"></div>';

        innerText += '<div id="popContentArea" class="Neotek_Popup_Content Neotek_Popup_BackgroundColour"><div id="Neotek_Popup_Content"></div></div>';
        innerText += '<div id="roundedDivBottom"></div>';
        o.innerHTML = innerText;
        var doClose = null;
        if (NeotekPopup._closeOnLoseFocus) {
            doClose = NeotekPopup.Close;
            o.onmouseout = NeotekPopup.OnLooseFocus; // Onblur doesn't work on FF
        }

        if (NeotekPopup._doFade) {
            Fade.Create('fadePopup', 'divModalFade', 1500, doClose);
            //            if (NeotekPopup._height > screenH)
            //                $('fadePopup').style.height = parseInt(NeotekPopup._height) + parseInt(scrollY) + parseInt(screenH) + 'px';
        }
        try { Set.doc.body.appendChild(o); } catch (ex) { }

        if (NeotekPopup._allowDrag) {
            var drg = $top('neotekPopupTitle');
            if (!!!drg) drg = o;
            Drag.Init(drg, o);
            o.onDragStart = function() {
                var oo = $top('triangleDiv');
                if (!!!oo) return;
                if (oo.style.display != 'none')
                    oo.style.display = 'none';
            }
        }
    },
    DisplayTriangle: function(obj, XPos, isTop, bgColour) {

        var triangleTxt = '<div style="position:relative;display:block;height:20px;"><div id="triangleDiv" class="triangle"></div><div id="triangleOverlayDiv" class="triangleoverlay"></div></div>';

        if (!isTop) {
            obj.innerHTML = obj.innerHTML + triangleTxt;
        } else {
            obj.innerHTML = triangleTxt + obj.innerHTML;
        }

        var os = $top('Neotek_Popup').style;
        var t = $top('triangleDiv');
        var to = $top('triangleOverlayDiv');
        if (!!!t) return;
        t.style.borderColor = 'Transparent';
        t.style.borderWidth = '20px';
        t.style.borderStyle = 'Solid';
        t.style.position = 'absolute';
        to.style.borderColor = 'Transparent';
        to.style.borderStyle = 'Solid';
        to.style.borderWidth = '17px';
        to.style.position = 'absolute';
        if (isTop) {
            t.style.top = '-23px';
            t.style.borderBottomColor = bgColour;
            to.style.top = '-17px';
            to.style.borderBottomColor = 'white';
            os.top = parseInt(os.top.replace('px', '')) - 5 + 'px';
        } else {
            t.style.top = '-10px';
            t.style.borderTopColor = bgColour;
            to.style.top = '-11px';
            to.style.borderTopColor = 'white';
            os.top = parseInt(os.top.replace('px', '')) - 25 + 'px';
        }
        var width = obj.offsetWidth;
        var Left = 0;
        switch (XPos.toLowerCase()) {
            case "left":
                Left = 30;
                os.left = parseInt(os.left.replace('px', '')) - 45 + 'px';
                break;
            case "center":
                Left = (width / 2) - 10; break;
            case "right":
                Left = width - 60;
                os.left = parseInt(os.left.replace('px', '')) + 40 + 'px';
                break;
        }
        t.style.left = Left + 'px';
        to.style.left = Left + 3 + 'px';
    },
    OnLooseFocus: function(e) {
        e = !!e ? e : window.event;
        var o = e.target || e.srcElement;
        fixOnMouseOut(this, e, 'NeotekPopup.Close()');
    }
};

function GetWhichDocument() {
    var obj = null;
    try {
        if (top.document.getElementById('InfoFrame') != null) { // IE 8 Fix (top.document exists but is not usable for framesets)
            obj = top.document;
        } else {
            obj = document;
        }
    } catch (ex) { obj = document; }

    return obj;
}
function DetermineIfTop() {
    if (top != null) {
        try {
            if (top.document.getElementById('InfoFrame') != null) {
                return true;
            } else {
                return false;
            }
        }
        catch (ex) { return false; }
    } else {
        return false;
    }
}
var Set = {
    doc: GetWhichDocument(),
    isTop: DetermineIfTop()
};
function $top(id) { return Set.doc.getElementById(id); }

// Cross Browser Generic Fade
var Fade = {
    Create: function(id, className, zIndex, closeOnClick) {
        if (!!!zIndex) zIndex = 15000;
        var fadeDiv = $(id) != null ? $(id) : Set.doc.createElement('div');
        fadeDiv.id = id; // 'fadeUpload';
        fadeDiv.className = className; //'divFade';
        fadeDiv.style.zIndex = zIndex;
        fadeDiv.onclick = closeOnClick;
        Set.doc.body.appendChild(fadeDiv);

        Fade.FadeIn(fadeDiv.id, 60, 500);
    },
    FadeIn: function(id, opacity, ms) {
        var o = $top(id);
        o.style.opacity = 0;
        o.style.display = 'block';

        Fade.ToggleFade(id, ms, opacity);
    },
    FadeOut: function(id, opacity) {
        var o = $top(id);
        if (!!!o) return;
        Fade.ToggleFade(id, 500, opacity);
    },
    ToggleFade: function(el, milli, opac) {
        var currOpacity = $top(el).style.opacity;
        if (currOpacity != 0) { // if not faded
            Fade.DoFade(el, milli, opac, 0);
        } else { // else the images is already faded
            Fade.DoFade(el, milli, 0, opac);
        }
    },
    DoFade: function(el, milli, start, end) {
        var fadeTime = Math.round(milli / 100);
        var i = 0;  // Fade Timer
        if (start < end) { // Fade in
            for (j = start; j <= end; j++) {
                var expr = "Fade.ChangeOpacity('" + el + "'," + j + ")";
                var timeout = i * fadeTime;
                // setTimeout will call 'expr' after 'timeout' milliseconds
                setTimeout(expr, timeout);
                i++;
            }
        }
        // Fade out
        else if (start > end) {
            for (j = start; j >= end; j--) {
                var expr = "Fade.ChangeOpacity('" + el + "'," + j + ", true)";
                var timeout = i * fadeTime;
                setTimeout(expr, timeout);
                i++;
            }
        }
    },
    ChangeOpacity: function(el, opacity, val) {
        var image = $top(el);
        if (image == null) return;
        image.style.MozOpacity = (opacity / 100); // For Mozilla
        image.style.filter = "alpha(opacity=" + opacity + ")"; // For IE
        image.style.opacity = (opacity / 100); // For others
        if (image.style.opacity == 0 && val) {
            if (!!image) Set.doc.body.removeChild(image);
        }
    }
};

var Drag = {
    obj: null,
    Init: function(o, rootElem) {
        if (!!!o) return;
        o.onmousedown = Drag.Start;
        o.root = rootElem;
        o.onDragStart = null;
    },
    Start: function(e) {
        var o = Drag.obj = this;
        e = Drag.FixE(e);
        var y = parseInt(o.root.style.top);
        var x = parseInt(o.root.style.left);
        o.lastMouseX = e.clientX;
        o.lastMouseY = e.clientY;
        if (o.onDragStart != null) o.onDragStart(e);
        Set.doc.onmousemove = Drag.Drag;
        Set.doc.onmouseup = Drag.End;
    },
    Drag: function(e) {
        //var isFF = !!e;
        e = Drag.FixE(e);
        var o = Drag.obj;
        if (!!!o) return;
        var ey = e.clientY;
        var ex = e.clientX;
        var y = parseInt(o.root.style.top);
        var x = parseInt(o.root.style.left);
        if (!!!y) y = ey + o.offsetHeight + (o.root.offsetTop / 2);
        //if (!!!y) y = parseInt(o.root.offsetTop) + (parseInt(o.root.clientHeight) /2); // Create Jurkyness if not positioned in centre
        if (!!!x) x = parseInt(o.root.offsetLeft) + (parseInt(o.root.clientWidth) / 2);
        var nx, ny;
        nx = x + (ex - o.lastMouseX);
        ny = y + (ey - o.lastMouseY);
        if (ny < 150 && !!!o.root.style.top) ny += 150;

        o.root.style.left = nx + 'px';
        o.root.style.top = ny + 'px';
        o.lastMouseX = ex;
        o.lastMouseY = ey;
    },
    End: function(e) {
        Set.doc.onmousemove = null;
        Set.doc.onmouseup = null;
        Drag.obj.root.lastMouseX = null;
        Drag.obj.root.lastMouseY = null;
        Drag.obj = null;
    },
    FixE: function(e) {
        if (Set.isTop) {
            if (typeof e == 'undefined') e = top.window.event;
        } else {
            if (typeof e == 'undefined') e = window.event;
        }
        if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
        if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
        return e;
    }
};

var Animate = {
    _strSize: [0, 0],
    _endSize: [1, 1],
    _tempVal: null, // Used for persisting temporary value eg: position
    Start: function(id, strSize, endSize, ms, type) {
        Animate._tempVal = null;
        var o = $(id);
        if (!!!o) return;
        o.style.width = strSize[0] + 'px';
        o.style.height = strSize[1] + 'px';
        Animate._strSize = strSize;
        Animate._endSize = endSize;

        var expr;
        switch (type.toLowerCase()) {
            case "topleft": expr = "Animate.ExpandFromTopLeft"; break;
            case "left": expr = "Animate.ExpandFromLeft"; break;
            case "topright": expr = "Animate.ExpandFromTopRight"; break;
            case "right": expr = "Animate.ExpandFromRight"; break;
            case "top": expr = "Animate.ExpandFromTop"; break;
            case "bottom": expr = "Animate.ExpandFromBottom"; break;
            default: expr = "Animate.ExpandFromTopLeft"; break;
        }
        Animate.Resize(o.id, ms, expr);
    },
    Resize: function(id, milli, type) {
        var start = Animate._strSize[0];
        var end = Animate._endSize[0];
        var fadeTime = Math.round(milli / 1000);
        var screenH = GetScreenHeight();
        for (i = start; i <= end; ++i) {
            var x = i;
            var y = parseInt(Animate._strSize[1]) + i;
            var expr = type + "('" + id + "'," + x + ", " + y + ", " + screenH + ")";
            var timeout = i * fadeTime;
            setTimeout(expr, timeout);
        }
    },
    ExpandFromTopLeft: function(id, x, y) {
        var o = $(id); if (!!!o) return;
        if (x <= Animate._endSize[0]) o.style.width = x + 'px';
        if (y <= Animate._endSize[1]) o.style.height = y + 'px';
    },
    ExpandFromLeft: function(id, x, y) {
        var o = $(id); if (!!!o) return;
        if (x <= Animate._endSize[0]) o.style.width = x + 'px';
        o.style.height = Animate._endSize[1] + 'px';
    },
    ExpandFromTopRight: function(id, x, y) {
        var o = $(id); if (!!!o) return;
        var left = Animate._tempVal;
        var endSizeX = parseInt(Animate._endSize[0]);
        if (Animate._tempVal == null) {
            left = parseInt(o.style.left.replace('px', ''));
            if (isNaN(left)) left = endSizeX - parseInt(o.offsetLeft) + 50;
            Animate._tempVal = left;
        }
        left = left + endSizeX - parseInt(x);
        o.style.left = left + 'px';
        if (x <= endSizeX) o.style.width = x + 'px';
        if (y <= Animate._endSize[1]) o.style.height = y + 'px';
    },
    ExpandFromRight: function(id, x, y) {
        var o = $(id); if (!!!o) return;
        var left = Animate._tempVal;
        var endSizeX = parseInt(Animate._endSize[0]);
        if (Animate._tempVal == null) {
            left = parseInt(o.style.left.replace('px', ''));
            if (isNaN(left)) left = endSizeX - parseInt(o.offsetLeft) + 50;
            Animate._tempVal = left;
        }
        left = left + endSizeX - parseInt(x);
        o.style.left = left + 'px';
        if (x <= endSizeX) o.style.width = x + 'px';
        o.style.height = Animate._endSize[1] + 'px';
    },
    ExpandFromTop: function(id, x, y) {
        var o = $(id); if (!!!o) return;
        if (y <= Animate._endSize[1]) o.style.height = y + 'px';
        o.style.width = Animate._endSize[0] + 'px';
    },
    ExpandFromBottom: function(id, x, y, screenH) {
        var o = $(id); if (!!!o) return;
        var top = Animate._tempVal;
        var endSizeY = parseInt(Animate._endSize[1]);
        if (Animate._tempVal == null) {
            top = parseInt(o.style.top.replace('px', ''));
            if (isNaN(top)) top = endSizeY - (parseInt(o.offsetTop) + parseInt(o.offsetHeight));
            Animate._tempVal = top;
        }
        var chk = top;
        var endSizeY = parseInt(Animate._endSize[1]);
        if (screenH - endSizeY < 100 && screenH - endSizeY > 0) { chk -= (screenH - endSizeY) + 80; } // Not Perfect but close
        top = top + endSizeY - parseInt(y);
        if (top > chk) o.style.top = top + 'px';
        if (y <= Animate._endSize[1]) o.style.height = y + 'px';
        o.style.width = Animate._endSize[0] + 'px';
        o.style.marginTop = '0px'; // Can hide
    }
};


function GetScreenHeight() {
    iw = 0; var doc = null;
    try { doc = top.document; } catch (ex) { doc = document; }
    ih = (doc.documentElement.clientHeight ? doc.documentElement.clientHeight : doc.body.clientHeight);
    return ih;
}
function GetScreenWidth() {
    iw = 0; var doc = null;
    try { doc = top.document; } catch (ex) { doc = document; }
    iw = (doc.documentElement.clientWidth ? doc.documentElement.clientWidth : doc.body.clientWidth);
    return iw;
}
function GetScrollPosition() {
    if (typeof top.window.pageYOffset != "undefined") {
        var scroll = top.window.pageYOffset;
    } else if (typeof top.document.documentElement.scrollTop != "undefined") {
        var scroll = top.document.documentElement.scrollTop;
    } else {
        var scroll = top.document.body.scrollTop;
    }
    return scroll;
}

function is_child_of(parent, child) {
    if (child != null) {
        while (child.parentNode) {
            if ((child = child.parentNode) == parent)
                return true;
        }
    }
    return false;
}
// Fixes the onmouseout annoyance for childelements of an element
function fixOnMouseOut(element, event, JavaScript_code) {
    var current_mouse_target = null;
    if (event.toElement)
        current_mouse_target = event.toElement;
    else if (event.relatedTarget)
        current_mouse_target = event.relatedTarget;
    if (!is_child_of(element, current_mouse_target) && element != current_mouse_target)
        eval(JavaScript_code);
}


/* ----- HTML Corners.js --------- */
function NCheck() {
    if (!document.getElementById || !document.createElement)
        return (false);
    var b = navigator.userAgent.toLowerCase();
    if (b.indexOf("msie 5") > 0 && b.indexOf("opera") == -1)
        return (false);
    return (true);
}

function Rounded(selector, bk, color, size) {
    var i;
    var v = getElementsBySelector(selector);
    var l = v.length;
    for (i = 0; i < l; i++) {
        AddTop(v[i], bk, color, size);
        AddBottom(v[i], bk, color, size);
    }
}

function RoundedTop(selector, bk, color, size) {
    var i;
    var v = getElementsBySelector(selector);
    for (i = 0; i < v.length; i++)
        AddTop(v[i], bk, color, size);
}

function RoundedBottom(selector, bk, color, size) {
    var i;
    var v = getElementsBySelector(selector);
    for (i = 0; i < v.length; i++)
        AddBottom(v[i], bk, color, size);
}

function AddTop(el, bk, color, size) {
    var i;
    var d = document.createElement("b");
    var cn = "r";
    var lim = 4;
    if (size && size == "small") { cn = "rs"; lim = 2; }
    d.className = "rtop";
    d.style.backgroundColor = bk;
    for (i = 1; i <= lim; i++) {
        var x = document.createElement("b");
        x.className = cn + i;
        if (color)
            x.style.backgroundColor = color;
        else
            x.className += ' Neotek_Popup_BackgroundColour';
        d.appendChild(x);
    }
    el.insertBefore(d, el.firstChild);
}

function AddBottom(el, bk, color, size) {
    var i;
    var d = document.createElement("b");
    var cn = "r";
    var lim = 4;
    if (size && size == "small") { cn = "rs"; lim = 2; }
    d.className = "rbottom";
    d.style.backgroundColor = bk;
    for (i = lim; i > 0; i--) {
        var x = document.createElement("b");
        x.className = cn + i;
        if (color)
            x.style.backgroundColor = color;
        else
            x.className += ' Neotek_Popup_BackgroundColour';
        d.appendChild(x);
    }
    el.appendChild(d, el.firstChild);
}

function getElementsBySelector(selector) {
    var i;
    var s = [];
    var selid = "";
    var selclass = "";
    var tag = selector;
    var objlist = [];
    if (selector.indexOf(" ") > 0) {  //descendant selector like "tag#id tag"
        s = selector.split(" ");
        var fs = s[0].split("#");
        if (fs.length == 1) return (objlist);
        return (document.getElementById(fs[1]).getElementsByTagName(s[1]));
    }
    if (selector.indexOf("#") > 0) { //id selector like "tag#id"
        s = selector.split("#");
        tag = s[0];
        selid = s[1];
    }
    if (selid != "") {
        objlist.push(document.getElementById(selid));
        return (objlist);
    }
    if (selector.indexOf(".") > 0) {  //class selector like "tag.class"
        s = selector.split(".");
        tag = s[0];
        selclass = s[1];
    }
    var v = document.getElementsByTagName(tag);  // tag selector like "tag"
    if (selclass == "")
        return (v);
    for (i = 0; i < v.length; i++) {
        if (v[i].className == selclass) {
            objlist.push(v[i]);
        }
    }
    return (objlist);
}

/* Added for Popup address form: 
Reason: wouldn't hold this in memory if run under ajax.
*/
function SubmitNewAddressForm(f) {
    var o = $('__VIEWSTATE'); // Disable Viewstate validation
    if (o) {
        o.parentNode.removeChild(o);
    }
    o = $('CityID');
    for (var i = 0; i < o.options.length; ++i) { // Changes to value rather than ID (Should be based on ID anyway but currently isn't (serverside))
        o.options[i].value = o.options[i].innerHTML;
    }
    var str = getFormValues(f);
    neotekscript('/Basket/NewDeliveryAddress.aspx', str);
}

function AddressSaved(Id) {
    var Address = '';
    Address = document.getElementById('Street1').value;
    Address += ", ";
    Address = document.getElementById('Street2').value;
    Address += ", ";
    Address = document.getElementById('Town').value;
    Address += ", ";
    Address = document.getElementById('CityID').value;
    if (opener == null) {
        top.InfoFrame.setAddress(Address, Id);
        top.InfoFrame.window.location.reload();
        NeotekPopup.Close();
    } else {
        opener.setAddress(Address, Id);
        window.close();
    }
}
