
var KELLYOCG = (function($) {

    // Self
    var _this = {};
    var method;


    // Public methods
    _this.init_body = function() {
        $('body').addClass('js-enabled');
        $('body').append('<div id="ajaxBusy"><div id="ajaxBusyLoadingGif"></div></div>');
        $('#ajaxBusy').css({ display: "none",
            position: "fixed",
            zIndex: "1000",
            top: '0px',
            left: '0px',
            height: '100%',
            width: '100%',
            background: '#BAB1B1',
            opacity: '0.6'
        });
        $('#ajaxBusyLoadingGif').css({
            position: 'fixed',
            height: '250px',
            width: '250px',
            background: 'url(/images/loading_transparent.gif) no-repeat',
            top: '50%',
            left: '50%',
            margin: '-6px 0 0 -104px'
        });

    };

    _this.init_solution_tabs = function() {
        $('#solutions-rollover .default').show();
        $('#content .areas ul li a').mouseover(function() {
            $('#content .areas ul li').removeClass('current');
            $(this).parent('li').addClass('hover');
            p = '#content .' + $(this).attr('class');
            $('#solutions-rollover > div.solution').hide();
            $(p).show();
        }).mouseout(function() {
            $(this).parent('li').removeClass('hover');
            $(this).parent('li').addClass('current');
        }
		);
    }

    _this.position_sub_menus = function() {

        $('#header #nav > div > ul > li').mouseenter(
				function(e) {
				    pos = $(this).offset();
				    height = $(this).height();
				    lvl2 = '#' + $(this).attr('id') + '-submenu';
				    if ($(this).position().left > ($('#nav').width() / 2)) {
				        pos.left = pos.left - $(lvl2).width() + $(this).width();
				    }
				    $(this).addClass('hover');
				    $(lvl2).show();
				    $(lvl2).css({ 'left': (pos.left - 12) + 'px', 'top': pos.top + height + 'px' });
				}
			);
        $('#header #nav > div > ul > li').mouseleave(function(e) {
            //$(e.relatedTarget).css('border', '2px solid red');
            if (!$(e.relatedTarget).is('div.level-2')) {
                $('#header #nav > div > ul > li.hover').removeClass('hover');
                $(lvl2).hide();
            } else {
                e.preventDefault();

            }
            $('div.level-2').live('mouseleave', function(e) {
                $(lvl2).hide();
                $('#header #nav > div > ul > li.hover').removeClass('hover');
            });
        });
        /* 		$('div.level-2').live('mouseleave',
        function(){
        $(this).hide();
        }); */
    }


    _this.position_member_menus = function() {
        //Login Form
        $('#header a.login').live('mouseenter', function() {
            $('#login-form').show();
            pos = $(this).offset();
            $('#login-form').css({ 'left': pos.left - 178 + 'px', 'top': pos.top - 15 + 'px' });
        });
        $('#login-form').click(function(e) {
            e.stopPropagation(); //Stops form from being hidden when the user clicks inside the the form
        });
        $('#login-form .tab span.reg').live('mouseenter', function() {
            $('#login-form').hide();
            $('#register-form').show();
        });
        $(document).click(function(e) {
            if (!$(e.relatedTarget).parent('#login-form')[0] && e.target.id != 'login') {
                $('#login-form').hide();
            }
        });
        $('.restrictor a#login').live('click', function() {
            $('#login-form').show();
            pos = $('#header a.login').offset();
            $('#login-form').css({ 'left': pos.left - 178 + 'px', 'top': pos.top - 15 + 'px' });
        });
        $('div#validate-account a#login').live('click', function() {
            $('#login-form').show();
            pos = $('#header a.login').offset();
            $('#login-form').css({ 'left': pos.left - 178 + 'px', 'top': pos.top - 15 + 'px' });
        });

        //Register form
        $('#header a.register').live('mouseenter', function() {
            $('#register-form').show();
            pos = $(this).offset();
            $('#register-form').css({ 'left': pos.left - 268 + 'px', 'top': pos.top - 14 + 'px' });
        });
        $('#register-form').click(function(e) {
            e.stopPropagation();
        });
        $('#register-form .tab span.log').live('mouseenter', function() {
            $('#register-form').hide();
            $('#login-form').show();
        });
        $('.restrictor a#register').live('click', function() {
            $('#register-form').show();
            pos = $('#header #MemberNotLoggedIn a.register').offset();
            $('#register-form').css({ 'left': pos.left - 268 + 'px', 'top': pos.top - 14 + 'px' });

        });

        $(document).click(function(e) {
            if (!$(e.relatedTarget).parent('#register-form')[0] && e.target.id != 'register') {
                $('#register-form').hide();
            }
            else {
                return false
            }
        });
        $('#forgot-password').click(function(e) {
            var email = document.getElementById('email');
            if (email == null || email.value == '') {
                alert('Please enter your email address');
            }
            else {
                $('#ajaxBusy').show();
                url = "/KellyOCGAjaxBase/KellysOCGAjaxBase.aspx?action=resetuserpassword&email=" + email.value;
                //handle responses in statechanged
                xmlHttp = GetXmlHttpObject(memberResetPasswordStateChanged);
                xmlHttp.open("GET", url, true);
                xmlHttp.send(null);
            }
        });
    }

    _this.member_login = function() {
        url = "/KellyOCGAjaxBase/KellysOCGAjaxBase.aspx?action=getloggedinuser";
        xmlHttp = GetXmlHttpObject(memberGetLoggedInUserStateChanged);
        xmlHttp.open("GET", url, true);
        xmlHttp.send(null);
        $('div#login-form').keypress(function(event) {
            if (event.keyCode == '13') {
                event.preventDefault();
                $('#member-login-button').trigger('click');
            }
        });
        $('#member-login-button').click(function(e) {
            var email = document.getElementById('email');
            var password = document.getElementById('password');
            var remember = document.getElementById('remember');
            if (email == undefined || email.value == 'undefined' || email.value == '') {
                alert('Please enter your email address');
            }
            else if (password == undefined || password.value == 'undefined' || password.value == '') {
                alert('Please enter your password');
            }
            else {
                $('#ajaxBusy').show();
                url = "/KellyOCGAjaxBase/KellysOCGAjaxBase.aspx?action=memberlogin&email=" + email.value + "&password=" + password.value + "&server=localhost&domain=&remember=" + remember.checked;
                //handle responses in statechanged
                xmlHttp = GetXmlHttpObject(memberLoginStateChanged);
                xmlHttp.open("GET", url, true);
                xmlHttp.send(null);
            }
        });
        $('a.logout').click(function() {
            $('#ajaxBusy').show();
            url = "/KellyOCGAjaxBase/KellysOCGAjaxBase.aspx?action=memberlogout";
            //handle responses in statechanged
            xmlHttp = GetXmlHttpObject(memberLogoutStateChanged);
            xmlHttp.open("GET", url, true);
            xmlHttp.send(null);
        });
        $('#CreateAccount').click(function() {
            var firstname = document.getElementById('first-name');
            var lastname = document.getElementById('last-name');
            var company = document.getElementById('company');
            var country = document.getElementById('country');
            var regemail = document.getElementById('reg-email');
            var regconfirmemail = document.getElementById('reg-confirm-email');
            var regpassword = document.getElementById('reg-password');
            var regconfirmpass = document.getElementById('reg-confirm-pass');
            var agreetoterms = document.getElementById('privacy');
            $('#ajaxBusy').show();
            url = "/KellyOCGAjaxBase/KellysOCGAjaxBase.aspx?action=membercreateaccount&firstname=" + firstname.value + "&lastname=" + lastname.value + "&company=" + company.value + "&country=" + country.value + "&email=" + regemail.value + "&confirmemail=" + regconfirmemail.value + "&password=" + regpassword.value + "&confirmpassword=" + regconfirmpass.value + "&agreetoterms=" + agreetoterms.checked;
            xmlHttp = GetXmlHttpObject(memberCreateAccountStateChanged);
            xmlHttp.open("GET", url, true);
            xmlHttp.send(null);
        });


        $('a.#email-update').click(function() {
            $('#update-member-details').trigger('click');
        });

        $('#update-member-details').click(function() {
            var firstname = document.getElementById('mm-first-name');
            var lastname = document.getElementById('mm-last-name');
            var telephone = document.getElementById('mm-telephone');
            var company = document.getElementById('mm-company-name');
            var country = document.getElementById('mm-country');
            var email = document.getElementById('mm-email');
            var password = document.getElementById('mm-password');
            var confirmpass = document.getElementById('mm-confirm-password');
            var jobtitle = document.getElementById('mm-job-title');
            //var timezone = document.getElementById('mm-timezone');
            var timezone = "";

            var billingcountry = "";
            var billingaddress1 = "";
            var billingaddress2 = "";
            var billingcity = "";
            var billingstate = "";
            var billingzip = "";

            if (document.getElementById('mm-biling-country') != null) {
                billingcountry = document.getElementById('mm-biling-country').value;
                billingaddress1 = document.getElementById('mm-biling-address').value;
                billingaddress2 = document.getElementById('mm-biling-address-two').value;
                billingcity = document.getElementById('mm-biling-city').value;
                billingstate = document.getElementById('mm-biling-state').value;
                billingzip = document.getElementById('mm-biling-postcode').value;
            }

            var subscriptions = "";
            var interests = "";

            var InterestBPO = "false";
            var InterestCTO = "false";
            var InterestCWO = "false";
            var InterestES = "false";
            var InterestHR = "false";
            var InterestRPO = "false";
            var MonthlyNews = "false";

            $("#subscription-fieldset #subscription-fieldset-wrapper input[type=checkbox]:checked").each(function() {
                subscriptions = subscriptions + ',' + $(this).val();
                if ($(this).val() == '4294967297') {
                    MonthlyNews = "true";
                }
            });
            $("#subscription-fieldset #interests-wrapper input[type=checkbox]:checked").each(function() {
                interests = interests + ',' + $(this).val();
                if ($(this).val() == "Recruitment Process Outsourcing") {
                    InterestRPO = "true";
                }
                if ($(this).val() == "Career Transition and Organisational Effectiveness") {
                    InterestCTO = "true";
                }
                if ($(this).val() == "Contingent Workforce Outsourcing") {
                    InterestCWO = "true";
                }
                if ($(this).val() == "Business Process Outsourcing") {
                    InterestBPO = "true";
                }
                if ($(this).val() == "Human Resource Consulting") {
                    InterestHR = "true";
                }
                if ($(this).val() == "Executive Search") {
                    InterestES = "true";
                }
            });

            $('#ajaxBusy').show();
            url = "/KellyOCGAjaxBase/KellysOCGAjaxBase.aspx?action=memberupdateaccount&firstname=" + firstname.value + "&lastname=" + lastname.value + "&email=" + email.value + "&password=" + password.value + "&confirmpassword=" + confirmpass.value + "&country=" + country.value + "&company=" + company.value + "&jobtitle=" + jobtitle.value + "&timezone=" + timezone/*.value*/ + "&phone=" + telephone.value + "&subscriptions=" + subscriptions + "&interests=" + interests + "&billingcountry=" + billingcountry + "&address1=" + billingaddress1 + "&address2=" + billingaddress2 + "&city=" + billingcity + "&state=" + billingstate + "&zip=" + billingzip + "&InterestBPO=" + InterestBPO + "&InterestCTO=" + InterestCTO + "&InterestCWO=" + InterestCWO + "&InterestES=" + InterestES + "&InterestHR=" + InterestHR + "&InterestRPO=" + InterestRPO + "&MonthlyNews=" + MonthlyNews;
            xmlHttp = GetXmlHttpObject(memberUpdateMemberStateChanged);
            xmlHttp.open("GET", url, true);
            xmlHttp.send(null);
        });
        $('#close-account').click(function() {
            var reason = document.getElementById('close-account-reason');
            $('#ajaxBusy').show();
            url = "/KellyOCGAjaxBase/KellysOCGAjaxBase.aspx?action=memberaccountclose&reason=" + reason.value;
            xmlHttp = GetXmlHttpObject(memberAccountClosedStateChanged);
            xmlHttp.open("GET", url, true);
            xmlHttp.send(null);
        });
    }

    _this.init_knowledge_results = function() {
        $('div#search-knowledge div.search input').keypress(function(event) {
            if (event.keyCode == '13') {
                event.preventDefault();
                $('div#search-knowledge div.input-button input.search').trigger('click');
            }
        });

        if ($('#search-areas div.module').size() == 1) {
            $('#search-areas div.module').addClass('selected');
        }

        if ($('#search-knowledge div.filters label').size() <= 2) {
            if ($('#search-knowledge div.filters label').size() > 1) {
                $('#search-knowledge div.filters label:first').hide(0);
            }
            $('#search-knowledge div.filters .dropdown').removeClass('dropdown');
        }

        $('#search-areas .module h3').click(function() {
            if ($(this).parent('.module').hasClass('selected')) {
                $(this).parent('.selected').removeClass('selected');
                $('.highlight-selected').removeClass('highlight-selected');
            }
            else {
                $('.selected').removeClass('selected');
                $('.highlight-selected').removeClass('highlight-selected');
                $(this).parent('.module').addClass('selected');
                if ($(this).parent('.module').hasClass('highlight')) {
                    $(this).parent('.module').addClass('highlight-selected');
                }
            }
        });
        $('#search-knowledge .input-button .button').click(function() {
            $('#search-areas').hide();
            $('.search-results').show();
        })

        $('div.results div.head a.title.descending').live('click', function() {
            $(this).parent().next('ul').find('li').sortElements(function(a, b) {
                return $(a).find('div.title h4').text() > $(b).find('div.title h4').text() ? 1 : -1;
            });
            $(this).removeClass('descending');
            $(this).addClass('ascending');
            $(this).addClass('current');
            $('div.results div.head a.type').removeClass('current');
        });

        $('div.results div.head a.title.ascending').live('click', function() {
            $(this).parent().next('ul').find('li').sortElements(function(a, b) {
                return $(a).find('div.title h4').text() < $(b).find('div.title h4').text() ? 1 : -1;
            });
            $(this).removeClass('ascending');
            $(this).addClass('descending');
            $(this).addClass('current');
            $('div.results div.head a.type').removeClass('current');
        });

        $('div.results div.head a.type.descending').live('click', function() {
            $(this).parent().next('ul').find('li').sortElements(function(a, b) {
                return $(a).find('div.type').text() > $(b).find('div.type').text() ? 1 : -1;
            });
            $(this).removeClass('descending');
            $(this).addClass('ascending');
            $(this).addClass('current');
            $('div.results div.head a.title').removeClass('current');
        });

        $('div.results div.head a.type.ascending').live('click', function() {
            $(this).parent().next('ul').find('li').sortElements(function(a, b) {
                return $(a).find('div.type').text() < $(b).find('div.type').text() ? 1 : -1;
            });
            $(this).removeClass('ascending');
            $(this).addClass('descending');
            $(this).addClass('current');
            $('div.results div.head a.title').removeClass('current');
        });


    }

    function GetXmlHttpObject(handler) {
        var objXmlHttp = null
        if (navigator.userAgent.indexOf("MSIE") >= 0) {
            var strName = "Msxml2.XMLHTTP"
            if (navigator.appVersion.indexOf("MSIE 5.5") >= 0) {
                strName = "Microsoft.XMLHTTP"
            }
            try {
                objXmlHttp = new ActiveXObject(strName)
                if (handler != null) {
                    objXmlHttp.onreadystatechange = handler
                }
                return objXmlHttp
            }
            catch (e) {
                alert("Error. Scripting for ActiveX might be disabled")
                return
            }
        }
        if (navigator.userAgent.indexOf("Mozilla") >= 0) {
            objXmlHttp = new XMLHttpRequest()
            objXmlHttp.onload = handler
            objXmlHttp.onerror = handler
            return objXmlHttp
        }
    }

    _this.init_stars = function() {
        if ($('#stars').length) {
            $('#stars').stars();
            $("#stars").data("stars").$cancel.remove();
        }

        if ($('[id*="starsreadonly"]').length) {
            $('[id*="starsreadonly"]').stars();
            $('[id*="starsreadonly"]').data("stars").$cancel.remove();
        }
        $('#stars a').click(function() {
            //rhdlr('stars', (this).innerHTML, 'click');
            var iekcontent = document.getElementById('ekcontentid').value;
            var position = (this).innerHTML * 2;
            var atext = new Array(position, iekcontent, false);
            AddEditRating(atext, '', 'stars');
        })
        $('.comments a.flag').click(function() {
            var iekcontent = document.getElementById('ekcontentid').value;
            var iflaggingitemid = document.getElementById('flaggingitemid').value;
            $('#ajaxBusy').show();
            //23 = calendar type
            url = "/KellyOCGAjaxBase/KellysOCGAjaxBase.aspx?action=addeditcontentflag&contentid=" + iekcontent + "&flag=" + iflaggingitemid + "&flagid=0&contenttype=23&comment=Review comment " + (this).id + " has been flagged as inappropriate";
            xmlHttp = GetXmlHttpObject(flagContentStateChanged);
            xmlHttp.open("GET", url, true);
            xmlHttp.send(null);
        });
    }

    _this.init_lightbox = function() {
        if ($('.gallery a').length) {
            Shadowbox.init();
        }
    }

    _this.init_gallerySlider = function() {
        /* 	$('.gallery li[class^="page"]').hide();
        $('.gallery li.page1').show(); */
        $('#photo-entries .overlay').remove();
        cur_page = 1;
        pages = $('.gallery.new .pages-wrapper ul').length;
        width = pages * 700 + 'px';
        $('.gallery.new .pages-wrapper').css('width', width);
        $('.gallery.new a.next').click(function(e) {
            if (cur_page < pages) {
                $('.gallery.new ul[class^="page"]').animate(
					{ "left": "-=700px" }, "slow"
				);
                cur_page++;
            }
            e.preventDefault();
        });
        $('.gallery.new a.prev').click(function(e) {
            if (cur_page > 1) {
                $('.gallery.new ul[class^="page"]').animate(
					{ "left": "+=700px" }, "slow"
				);
                cur_page--
            }
            e.preventDefault();
        });
    }

    _this.init_gallerySliderOld = function() {
        /* 	$('.gallery li[class^="page"]').hide();
        $('.gallery li.page1').show(); */
        cur_page_old = 1;
        pages_old = $('.gallery.old .pages-wrapper ul').length;
        width_old = pages_old * 700 + 'px';
        $('.gallery.old .pages-wrapper').css('width', width_old);
        $('.gallery.old a.next').click(function(e) {
            if (cur_page_old < pages_old) {
                $('.gallery.old ul[class^="page"]').animate(
					{ "left": "-=700px" }, "slow"
				);
                cur_page_old++;
            }
            e.preventDefault();
        });
        $('.gallery.old a.prev').click(function(e) {
            if (cur_page_old > 1) {
                $('.gallery.old ul[class^="page"]').animate(
					{ "left": "+=700px" }, "slow"
				);
                cur_page_old--
            }
            e.preventDefault();
        });
    }


    _this.init_popupLightbox = function(name) {
        //var top = $(window).scrollTop() + 100;
        //var left = $(window).width() / 2; // -275;

        if ((($(window).height() - $('#lightbox.' + name).height()) / 2 + ($(window).scrollTop() - 100)) < $(window).scrollTop()) {
            $('#lightbox.' + name).css("top", ($(window).height() - $('#lightbox.' + name).height()) / 2 + ($(window).scrollTop() + 20) + "px");
        }
        else {
            $('#lightbox.' + name).css("top", ($(window).height() - $('#lightbox.' + name).height()) / 2 + ($(window).scrollTop() - 100) + "px");
        }
        $('#lightbox.' + name).css("left", ($(window).width() - $('#lightbox.' + name).width()) / 2 + $(window).scrollLeft() + "px");

        //$('#lightbox').css(
        //	{
        //	    'top': top,
        //	    'left': left
        //	}
        //);
        lb = '#lightbox.' + name;
        $(lb).show();
        $('#lightbox-overlay').show();
    }

    _this.init_hideLightbox = function() {
        $('#lightbox').hide();
        $('#lightbox-overlay').hide();
        //JT: Added command to explicitely hide registration lightbox
        $('#lightbox.registration-lightbox').hide();
        $('#resetPasswordLightbox.registration-lightbox').hide();
        $('#lightbox.closeAccount').hide();
    }

    _this.init_lightboxControllers = function() {
        $('a.show_lightbox').click(function(e) {
            name = $(this).attr('href');
            name = name.substring(1);
            _this.init_popupLightbox(name);
            e.preventDefault();
        });
        //JT: added registration-lightbox as close account lightbox should only be close when close is successful
        $('#lightbox .cancel, #lightbox-overlay, #lightbox.registration-lightbox .close').click(function(e) {
            _this.init_hideLightbox();
            e.preventDefault();
        });

        $('#resetPasswordLightbox.registration-lightbox .close').click(function(e) {
            $('#resetPasswordLightbox.registration-lightbox').hide();
            e.preventDefault();
        });

        $('#email-submit .close').click(function(e) {
            $("span.StaffProfileLiteral").html("");
            $('#email-submit').hide();
            $('#email-overlay').hide();
            $('span.PostbackMessage').html("");
            if ($('#recaptcha_widget_div').css('display') != undefined && $('#recaptcha_widget_div').css('display') != 'none') {
                Recaptcha.reload();
            }
            e.preventDefault();
        });

    }



    _this.preload = function() {
        if ($('.homepage').length) {
            $.preloadCssImages();
        }
    }

    _this.inputs = function() {
        $('input[type="text"]').one('focus', function() {
            //Continue to add OR's with: ||
            if (!$(this).attr('id') == 'search' || $(this).hasClass('search')) {
                if ($(this).val().indexOf('Search') != -1) {
                    $(this).val('');
                }
            }
        });
    }

    _this.init_photoSubmit = function() {

        var captcha = document.getElementById('captcha');
        if (captcha != null) {
            Recaptcha.create("6Ld0AAwAAAAAACsli_U0kAZLRZ6ugyRPwtU6Q-QY", 'captcha', {
                theme: "clean",
                callback: Recaptcha.focus_response_field
            });
        }
        $('.fileinput input[type="file"]').change(function() {
            loc = $(this).attr('value');
            $(this).siblings('.filename-holder').attr('value', loc);
            //e.preventDefault();
        });
        x = 3
        $('#add-image').click(function(e) {
            $('#upload' + x).show();
            x++;
            if (x == 6) {
                $(this).hide();
            }
            e.preventDefault();
        });
        $('input.browse').click(function(e) {
            $('input.file').click();
            e.preventDefault();
        });


        $('#submit-photo-to-flickr').click(function(e) {
            var Agree = document.getElementById('agree');

            if (Agree.checked == false) {
                alert("Please accept the terms and conditions to upload photos to Flickr");
            }
            else {
                $('#ajaxBusy').show();
                url = "/KellyOCGAjaxBase/KellysOCGAjaxBase.aspx?action=validaterecaptcha&challenge=" + Recaptcha.get_challenge() + "&response=" + Recaptcha.get_response();
                xmlHttp = GetXmlHttpObject(photoUploadValidateRecaptchaStateChanged);
                xmlHttp.open("GET", url, true);
                xmlHttp.send(null);
            }
        });
    }

    _this.PNGfix = function() {
        if ($.browser.msie && $.browser.version.substr(0, 1) < 7) {
            DD_belatedPNG.fix('#page-wrapper, input.search, input.go, #legal, .button, .input-button, .level-2, .member-form, .more, .email, #left-nav ul li, #content #page-article .comments ul li, #img-nav li, #lightbox .wrapper, #lightbox, #lightbox-overlay');
        }
    }

    _this.init_imageSlider_nav = function() {
        var len = $('#comp-images').children().size();
        var html = '<ul id="slide-nav">';
        for (i = 0; i <= len - 1; i++) {
            html = html + '<li class="slide_' + i + '">X</li>';
        }
        html = html + '</ul>';
        $(html).appendTo('#photo-comp');
    }

    _this.init_imageSlider = function() {
        if ($('ul#comp-images').length) {
            _this.init_imageSlider_nav();

            var liheight = '' + $('ul#comp-images li:first').height($('ul#comp-images li:first > img').height()) - 1 + 'px' + '';

            $('ul#comp-images').innerfade({
                speed: 0,
                timeout: 5000,
                type: 'sequence',
                containerheight: '270px',
                //JT: Change to yes to turn on auto rotator
                slide_timer_on: 'no',
                slide_ui_parent: 'comp-images',
                //pause_button_id: 'pause_button'
                slide_nav_id: 'slide-nav'
            });
            $.setOptionsButtonEvent();

            /* $("#pause_button").click(function() {
            $.pause();
            }); */

            $("#next_button").click(function() {
                $.next();
                $('ul#comp-images li').each(function() {
                    if (this.style.display != "none") {
                        $('ul#comp-images').height($(this).children('img').height());
                        padding = (400 - $(this).children('img').width()) / 2;
                        $(this).children('img').css('padding-left', padding + 'px');
                        $(this).children('img').css('padding-right', padding + 'px');
                    }
                });
            });

            $("#prev_button").click(function() {
                $.prev();
                $('ul#comp-images li').each(function() {
                    if (this.style.display != "none") {
                        $('ul#comp-images').height($(this).children('img').height());
                        padding = (400 - $(this).children('img').width()) / 2;
                        $(this).children('img').css('padding-left', padding + 'px');
                        $(this).children('img').css('padding-right', padding + 'px');
                    }
                });
            });

            /* $("#first_button").click(function() {
            $.first();
            });
				
				$("#last_button").click(function() {
            $.last();
            }); */
        }
    };


    _this.init_webcastRegistrationModule = function() {
        var eventType = document.getElementById('EventTypeWidgetController');
        if (eventType != null) {
            if (eventType.innerHTML != 'undefined') {
                if (eventType.innerHTML == 'Webcast') {
                    $('#webcast-registration').show();
                }
                else {
                    $('#webcast-registration').hide();
                }
            }
        }
    }

    _this.init_eventCollateralModule = function() {
        var eventCollateral = document.getElementById('event-collateral-content');
        if (eventCollateral != null) {
            if (eventCollateral.innerHTML != 'undefined') {
                if (eventCollateral.innerHTML != '') {
                    $('#event-collateral').show();
                }
                else {
                    $('#event-collateral').hide();
                }
            }
        }
    }

    function createCookie(name, value, days) {
        if (days) {
            var date = new Date();
            date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else var expires = "";
        document.cookie = name + "=" + value + expires + "; path=/";
    }

    function readCookie(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    }

    function eraseCookie(name) {
        createCookie(name, "", -1);
    }


    _this.init_blogCalendar = function() {

        $('#blog-feed').hide();

        var link = readCookie('link');
        if (link != null) {
            $("[id$=_LinkIdTextBox]").val(link);
            eraseCookie('link')
            $("[id$=_HiddenUpdatePanelButton]").trigger("click");
        }

        //Hide controld used to trigger update
        $("[id$=_HiddenUpdatePanelButton]").hide();
        $("[id$=_LinkIdTextBox]").hide();

        if (!$('dl.calender-definition-list').length) {
            //return;
        }
        $('dl.calender-definition-list').each(function() {
            $(this).find('dd:last').addClass('last');
        });
        //Add current class to selected link. Note: code on server side to overwrite viewstate
        $('#blog-search-sidebar a').click(function() {

            $('dl.calender-definition-list').each(function() {
                $(this).find('dd a').removeClass('current');
                $(this).find('dt a').removeClass('current');
            });
            $('.topics a').each(function() {
                $(this).removeClass('current');
            });

            $("[id$=_LinkIdTextBox]").val($(this).attr('id'));
            $("[id$=_HiddenUpdatePanelButton]").trigger("click");

            var blogTitle = $(this).attr('id');
            blogTitle = blogTitle.replace('-', ' ');

            $('h2').find('span').remove();
            $('h2').append('<span id="blogheading">' + blogTitle + '</span>');

            $(this).addClass('current');

            createCookie('link', $(this).attr('id'), 1);


        });

        $('#blog-feed').show();

    }

    _this.init_leadershipSearch = function() {

        //filter controls
        var checkBoxes = $('.region-filter');
        var solutionsdropdown = $('.LeadershipSolutionsDropdown');

        $('#last-name-list a').click(function() {

            $('#last-name-filter').val((this).innerHTML);
            $('#default-leaders ul li.leader-list-item').each(function() {
                listitem = $(this);
                if ($(this).find('input.last-name').val().substring(0, 1) == $('#last-name-filter').val()) {
                    $(checkBoxes).each(function() {
                        if ($(listitem).find('p.location').attr("innerHTML") == $(this).attr('id') && $(this).attr('checked') == false) {
                            $(listitem).hide();
                            $(listitem).removeClass('visible');
                        }
                        else if ($(listitem).find('p.location').attr("innerHTML") == $(this).attr('id') && $(this).attr('checked') == true) {
                            if ($(solutionsdropdown).val() != '' && $(listitem).attr("innerHTML").indexOf($(solutionsdropdown).val()) > 0) {
                                if ($('#' + $(this).find('p.location').attr('innerHTML') + ' .region-filter').attr('checked') == false) {
                                    $(listitem).hide();
                                    $(listitem).removeClass('visible');
                                }
                                else {
                                    $(listitem).show();
                                    $(listitem).addClass('visible');
                                }
                            }
                            else {
                                solutions = (listitem.find('div.hiddensolutions').attr('innerHTML'));
                                if (solutions == null || solutions == '' || solutions == undefined) {
                                    $(this).hide();
                                    $(this).removeClass('visible')
                                }
                                else {
                                    $(listitem).show();
                                    $(listitem).addClass('visible');
                                }
                            }
                        }
                    });
                }
                else {
                    $(listitem).hide();
                }
            });
            $('li.visible').last().addClass('last');
        });

        //show / hide list items when region changes
        $(checkBoxes).click(function() {
            var checkboxid = $(this).attr('id')
            var checkboxchecked = $(this).attr('checked')

            $('li.leader-list-item').each(function() {
                if ($(this).find('p.location').attr("innerHTML") == checkboxid) {
                    if (checkboxchecked == false) {
                        $(this).hide();
                        $(this).removeClass('visible')
                    }
                    else {
                        var hiddensolutions = $(this);
                        hiddensolutions = hiddensolutions.find("div.hiddensolutions").attr('innerHTML');
                        //before showing list item check solution dropdown
                        if (hiddensolutions != undefined) {
                            if ((solutionsdropdown).val() == '' || hiddensolutions.match((solutionsdropdown).val())) {
                                $(this).show();
                                $(this).addClass('visible');
                            }
                        }
                    }
                }
            });
            $('li.visible').last().addClass('last');
        });

        //show / hide list items when solution changes
        $(solutionsdropdown).change(function() {

            if ($(this).val() != '') {
                solutionval = $(this).val();
                $('li.leader-list-item').each(function() {
                    var solutions = $(this);
                    solutions = (solutions.find('div.hiddensolutions').attr('innerHTML'));
                    if (solutions == null || solutions == '' || solutions == undefined) {
                        $(this).hide();
                        $(this).removeClass('visible')
                    }
                    else if (solutions.length > 0) {
                        if (solutions.indexOf(solutionval) > -1) {
                            if ($('#' + $(this).find('p.location').attr('innerHTML') + '.region-filter').attr('checked') == false) {
                                $(this).hide();
                                $(this).removeClass('visible')
                            }
                            else {
                                $(this).show();
                                $(this).addClass('visible');
                            }
                        }
                        else {
                            $(this).hide();
                            $(this).removeClass('visible')
                        }
                    }

                });

            }
            else {
                //even though the solution is set to all check the region selection before showing the list item
                $(checkBoxes).each(function() {
                    var checkboxid = $(this).attr('id');
                    var checkboxchecked = $(this).attr('checked');
                    $('li.leader-list-item').each(function() {

                        var listitem = $(this);
                        var location = $(this).find('p.location').attr("innerHTML");
                        if (location == checkboxid && checkboxchecked == false) {
                            $(listitem).hide();
                            $(listitem).removeClass('visible')
                        }
                        else if (location == checkboxid && checkboxchecked == true) {
                            $(listitem).show();
                            $(listitem).addClass('visible');
                        }
                    });
                });
            }
            $('li.visible').last().addClass('last');
        });

        //Add last class to leadership page
        $('div#leaders').last().find('li:last').addClass('last');

    }

    _this.init_siteSearch = function() {
        $('div.header-search input#site-search-text').keypress(function(event) {
            if (event.keyCode == '13') {
                event.preventDefault();
                $('#site-search-go').trigger('click');
            }
        });
        $('#site-search-go').click(function() {
            //createCookie('link', $(this).attr('id'), 1);
            var url = "/Search/";
            var searchtext = $('#site-search-text').val();
            createCookie('searchtextcookie', searchtext, 1);
            $(window.location).attr('href', url);

        });

        var searchtextcookie = readCookie('searchtextcookie');

        if (searchtextcookie != null) {
            $('div.search .search').attr('value', searchtextcookie);
            eraseCookie('searchtextcookie')
            $('.search').trigger("click");
        }

    }

    _this.init_PushLiveEventRegToMarketo = function() {
        $('a#regforevent').click(function() {
            url = "/KellyOCGAjaxBase/KellysOCGAjaxBase.aspx?action=pushliveeventregtomarketo&campaign=" + $(this).attr('alt');
            xmlHttp = GetXmlHttpObject();
            xmlHttp.open("GET", url, true);
            xmlHttp.send(null);
        });
    }

    _this.jumpToBookmark = function() {

        //        // replace # with #_ in all links containing #
        //        $('a[href*=#]').each(function() {
        //            $(this).attr('href', $(this).attr('href'));
        //        });

        //        if (window.location.hash != '') {
        //            // scrollTo if #_ found
        //            hashname = window.location.hash;
        //            // find element to scroll to (<a name=""> or anything with particular id)
        //            elem = $('a[name="' + hashname + '"],#' + hashname);
        //            
        //            if (elem) {
        //                $(document).scrollTo(elem, 800);
        //            }
        //        }
    }

    _this.init_scrollToError = function() {

    }

    _this.init_sendEmail = function() {
        if ($('span.PostbackMessage').html() != "") {
            $('#recaptcha_widget_div').css('display', $('.FormControls').css('display'));
            if ($('#recaptcha_widget_div').css('display') != 'block') {
                $('span.PostbackMessage').removeClass('error-literal');
            }
            pos = $('a.email').attr('href', $('input.StaffProfileID').val()).offset();
            $('#email-submit').css("position", "absolute");
            if ((($(window).height() - $('#email-submit').height()) / 2 + ($(window).scrollTop() - 100)) < $(window).scrollTop()) {
                $('#email-submit').css("top", ($(window).height() - $('#email-submit').height()) / 2 + ($(window).scrollTop() + 20) + "px");
            }
            else {
                $('#email-submit').css("top", ($(window).height() - $('#email-submit').height()) / 2 + ($(window).scrollTop() - 100) + "px");
            }
            $('#email-submit').css("left", ($(window).width() - $('#email-submit').width()) / 2 + $(window).scrollLeft() + "px");
            $('input.StaffProfileID').val()
            $("#email-submit").show();
        }

        if ($("input.StaffProfileID").val() == '') {
            $("div#ToAddressPanel").show();
        }
        else {
            $("div#ToAddressPanel").hide();
            ValidatorEnable($('[id*=ToEmailRegularExpressionValidator]')[0], false);
            ValidatorEnable($('[id*=ToEmailRequiredFieldValidator]')[0], false);
        }

        $('a.email').live('click', function() {
            $('#recaptcha_widget_div').css('display', $('.FormControls').css('display'));
            if ($('#recaptcha_widget_div').css('display') != undefined && $('#recaptcha_widget_div').css('display') != 'none') {
                Recaptcha.reload();
            }

            $("input.StaffProfileID").val($(this).attr('alt'));
            if ($(this).attr('alt') == '' || $(this).attr('alt') == null) {
                $("div#ToAddressPanel").show();
                //Set dummy address to supress validator error message on enable
                $('[id*=toemail]').val('test@test.com');
                ValidatorEnable($('[id*=ToEmailRegularExpressionValidator]')[0], true);
                ValidatorEnable($('[id*=ToEmailRequiredFieldValidator]')[0], true);
                //Clear dummy address
                $('[id*=toemail]').val('');
                $('[id*=subject]').val(document.title);
                $('[id*=body]').val('Take a look at this page I found titled ' + document.title + '. You can see this page at ' + $(location).attr('href') + '.');
            }
            else {
                $("div#ToAddressPanel").hide();
                ValidatorEnable($('[id*=ToEmailRegularExpressionValidator]')[0], false);
                ValidatorEnable($('[id*=ToEmailRequiredFieldValidator]')[0], false);
            }
            $('#email-submit').show();
            $('#email-overlay').css({ 'height': $(document).height() + 'px' });
            $('#email-overlay').show();
            $('.FormControls').show();

            pos = $(this).offset();

            $('#email-submit').css("position", "absolute");
            if ((($(window).height() - $('#email-submit').height()) / 2 + ($(window).scrollTop() - 100)) < $(window).scrollTop()) {
                $('#email-submit').css("top", ($(window).height() - $('#email-submit').height()) / 2 + ($(window).scrollTop() + 20) + "px");
            }
            else {
                $('#email-submit').css("top", ($(window).height() - $('#email-submit').height()) / 2 + ($(window).scrollTop() - 100) + "px");
            }
            $('#email-submit').css("left", ($(window).width() - $('#email-submit').width()) / 2 + $(window).scrollLeft() + "px");

            url = "/KellyOCGAjaxBase/KellysOCGAjaxBase.aspx?action=getleader&id=" + $(this).attr('alt');
            xmlHttp = GetXmlHttpObject(getLeaderChanged);
            xmlHttp.open("GET", url, true);
            xmlHttp.send(null);
        });

    }

    _this.init_addLastClass = function() {
        $('ul li.staffProfile-list-item:last-child').addClass('last');
        $('div.pagination li.next').prev('li').addClass('last');
        $('div#leadership div.right-shadow ul li:last-child').addClass('last');
    }

    _this.init_twitterHover = function() {
        $('a.twitter').click(function() {
            var tweettext = $(this).attr('rel');
            twttr.anywhere(function(T) {
                $('#tbox').empty();
                T("#tbox").tweetBox({
                    label: "Tweet this:",
                    width: 400,
                    height: 100,
                    defaultContent: "" + tweettext + "",
                    onTweet: function(plain, html) {
                        $('#tbox').hide();
                    }
                });
                $("#tbox").addClass('tbox-style');

            });
        });

        $('#tweeting-button').click(function() {
            $('#tbox').empty();
            $("#tbox").removeClass('tbox-style');
        });

        $(document).click(function(e) {
            if ($(e.target).attr('class') != 'twitter') {
                $('#tbox').empty();
                $("#tbox").removeClass('tbox-style');
            }
        });
    }

    function EndRequestHandler(sender, args) {
        if (args.get_error() == undefined) {
            _this.init_stars();
            _this.init_blogCalendar();
            _this.init_leadershipSearch();
            _this.init_siteSearch();
            _this.init_knowledge_results();
            _this.init_scrollToError();
            _this.init_addLastClass();
            _this.init_sendEmail();
            _this.init_lightboxControllers();
            _this.inputs();
        }
    }

    _this.addWebkitClass = function() {
        if ($.browser.webkit) {
            $('body').addClass('webkit');
        }
    }

    // document.ready - initialise various things
    $(document).ready(function() {
        _this.init_body();
        _this.init_addLastClass();
        _this.init_twitterHover();
        _this.init_solution_tabs();
        _this.position_sub_menus();
        _this.position_member_menus();
        _this.init_knowledge_results();
        _this.init_imageSlider();
        _this.init_stars();
        _this.init_lightbox();
        _this.init_gallerySlider();
        _this.init_gallerySliderOld();
        _this.init_lightboxControllers();
        _this.init_photoSubmit();
        _this.init_webcastRegistrationModule();
        _this.init_eventCollateralModule();
        _this.member_login();
        _this.init_blogCalendar();
        _this.init_leadershipSearch();
        _this.init_siteSearch();
        _this.init_PushLiveEventRegToMarketo();
        _this.init_scrollToError();
        _this.init_sendEmail();
        _this.jumpToBookmark();
        _this.preload();
        _this.inputs();
        _this.PNGfix();
        _this.addWebkitClass();
        if (typeof (Sys) !== 'undefined') {
            Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
            _this.addWebkitClass();
        }
    });
    return _this;

    function flagContentStateChanged() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            if (xmlHttp.status == 200) {
                $('#ajaxBusy').hide();
                // ...processing statements go here...
                response = xmlHttp.responseXML.documentElement;
                method = response.getElementsByTagName('method')[0].firstChild.data;
                result = response.getElementsByTagName('result')[0].firstChild.data;
                key = response.getElementsByTagName('key')[0].firstChild.data;

            } else {
                $('#ajaxBusy').hide();
                alert("There was a problem retrieving the XML data:\n" + xmlHttp.statusText);
            }
        }
    }

    function memberLoginStateChanged() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            if (xmlHttp.status == 200) {
                $('#ajaxBusy').hide();
                // ...processing statements go here...
                response = xmlHttp.responseXML.documentElement;
                method = response.getElementsByTagName('method')[0].firstChild.data;
                result = response.getElementsByTagName('result')[0].firstChild.data;
                success = response.getElementsByTagName('success')[0].firstChild.data;
                if (success != 'True') {
                    $('#login-form').show();
                    var ResultLiteral = document.getElementById('ResultLiteral');
                    ResultLiteral.innerHTML = result;
                }
                else {
                    $('#login-form').hide();
                    $('#MemberNotLoggedIn').hide();
                    $('#MemberLoggedIn').show();
                    $('#memberNameLabel').text(result);
                    location.reload();
                }
                //window.location = response.getResponseHeader('Location')

            } else {
                $('#ajaxBusy').hide();
                alert("There was a problem retrieving the XML data:\n" + xmlHttp.statusText);
            }
        }
    }

    function memberLogoutStateChanged() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            if (xmlHttp.status == 200) {
                $('#ajaxBusy').hide();
                // ...processing statements go here...
                response = xmlHttp.responseXML.documentElement;
                method = response.getElementsByTagName('method')[0].firstChild.data;
                result = response.getElementsByTagName('result')[0].firstChild.data;
                success = response.getElementsByTagName('success')[0].firstChild.data;
                if (success != 'True') {
                    $('#MemberNotLoggedIn').hide();
                    $('#MemberLoggedIn').show();
                }
                else {
                    $('#MemberNotLoggedIn').show();
                    $('#MemberLoggedIn').hide();
                    location.reload();
                }
                //window.location = response.getResponseHeader('Location')

            } else {
                $('#ajaxBusy').hide();
                alert("There was a problem retrieving the XML data:\n" + xmlHttp.statusText);
            }
        }
    }

    function memberGetLoggedInUserStateChanged() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            if (xmlHttp.status == 200) {
                $('#ajaxBusy').hide();
                // ...processing statements go here...
                response = xmlHttp.responseXML.documentElement;
                method = response.getElementsByTagName('method')[0].firstChild.data;
                result = response.getElementsByTagName('result')[0].firstChild.data;
                success = response.getElementsByTagName('success')[0].firstChild.data;
                if (success == 'True') {
                    if (result == 'null') {
                        $('#MemberNotLoggedIn').show();
                        $('#MemberLoggedIn').hide();
                    }
                    else {
                        $('#login-form').hide();
                        $('#MemberNotLoggedIn').hide();
                        $('#MemberLoggedIn').show();
                        $('#memberNameLabel').text(result);
                    }
                }
                else {
                    $('#MemberNotLoggedIn').show();
                    $('#MemberLoggedIn').hide();
                }

            } else {
                alert("There was a problem retrieving the XML data:\n" + xmlHttp.statusText);
            }
        }
    }

    function memberUpdateMemberStateChanged() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            if (xmlHttp.status == 200) {
                $('#ajaxBusy').hide();
                // ...processing statements go here...
                response = xmlHttp.responseXML.documentElement;
                method = response.getElementsByTagName('method')[0].firstChild.data;
                result = response.getElementsByTagName('result')[0].firstChild.data;
                success = response.getElementsByTagName('success')[0].firstChild.data;
                if (success == 'True') {
                    var MemberUpdateSuccessLiteral = document.getElementById('MemberUpdateSuccessLiteral');
                    $('#MemberUpdateSuccessLiteral').show();
                    var MemberUpdateErrorLiteral = document.getElementById('MemberUpdateErrorLiteral');
                    $('#MemberUpdateErrorLiteral').hide();
                    MemberUpdateSuccessLiteral.innerHTML = result;
                }
                else {
                    var MemberUpdateSuccessLiteral = document.getElementById('MemberUpdateSuccessLiteral');
                    $('#MemberUpdateSuccessLiteral').hide();
                    var MemberUpdateErrorLiteral = document.getElementById('MemberUpdateErrorLiteral');
                    $('#MemberUpdateErrorLiteral').show();
                    MemberUpdateErrorLiteral.innerHTML = result;
                }
                $('html, body').animate({ scrollTop: $("#my-membership").offset().top }, 0);


            } else {
                $('#ajaxBusy').hide();
                alert("There was a problem retrieving the XML data:\n" + xmlHttp.statusText);
            }
        }
    }

    function memberCreateAccountStateChanged() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            if (xmlHttp.status == 200) {
                $('#ajaxBusy').hide();
                // ...processing statements go here...
                response = xmlHttp.responseXML.documentElement;
                method = response.getElementsByTagName('method')[0].firstChild.data;
                result = response.getElementsByTagName('result')[0].firstChild.data;
                success = response.getElementsByTagName('success')[0].firstChild.data;
                firstname = response.getElementsByTagName('firstname')[0].firstChild.data;
                if (success == 'True') {
                    $('#register-form').hide();
                    if ((($(window).height() - $('.registration-lightbox').height()) / 2 + ($(window).scrollTop() - 100)) < $(window).scrollTop()) {
                        $('.registration-lightbox').css("top", ($(window).height() - $('.registration-lightbox').height()) / 2 + ($(window).scrollTop() + 20) + "px");
                    }
                    else {
                        $('.registration-lightbox').css("top", ($(window).height() - $('.registration-lightbox').height()) / 2 + ($(window).scrollTop() - 100) + "px");
                    }
                    $('.registration-lightbox').css("left", ($(window).width() - $('.registration-lightbox').width()) / 2 + $(window).scrollLeft() + "px");
                    $('#lightbox.registration-lightbox').show();

                    //_this.init_popupLightbox('registration-lightbox');
                    //$('html').animate({ scrollTop: 0 }, 'slow');
                    document.getElementById('registration-first-name').innerHTML = firstname;

                }
                else {
                    var RegistrationLiteral = document.getElementById('RegistrationLiteral');
                    RegistrationLiteral.innerHTML = result;
                    if ($('#register-form .error-literal').attr('innerHTML') != null) {
                        $('html, body').animate({ scrollTop: $("#register-form").offset().top }, 0);
                    }
                }

            } else {
                $('#ajaxBusy').hide();
                alert("There was a problem retrieving the XML data:\n" + xmlHttp.statusText);
            }
        }
    }

    function memberAccountClosedStateChanged() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            if (xmlHttp.status == 200) {
                $('#ajaxBusy').hide();
                // ...processing statements go here...
                response = xmlHttp.responseXML.documentElement;
                method = response.getElementsByTagName('method')[0].firstChild.data;
                result = response.getElementsByTagName('result')[0].firstChild.data;
                success = response.getElementsByTagName('success')[0].firstChild.data;
                if (success == 'True') {
                    _this.init_hideLightbox();
                    location.reload();
                }
                else {
                    var CloseAccountLiteral = document.getElementById('CloseAccountLiteral');
                    CloseAccountLiteral.innerHTML = result;
                }

            } else {
                $('#ajaxBusy').hide();
                alert("There was a problem retrieving the XML data:\n" + xmlHttp.statusText);
            }
        }
    }

    function photoUploadStateChanged() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            if (xmlHttp.status == 200) {
                // ...processing statements go here...
                response = xmlHttp.responseXML.documentElement;
                method = response.getElementsByTagName('method')[0].firstChild.data;
                result = response.getElementsByTagName('result')[0].firstChild.data;
                success = response.getElementsByTagName('success')[0].firstChild.data;
                if (success == 'True') {
                    if ($('#recaptcha_widget_div').css('display') != undefined && $('#recaptcha_widget_div').css('display') != 'none') {
                        Recaptcha.reload();
                    }
                    $('#ajaxBusy').hide();
                    document.getElementById('title1').value = "";
                    document.getElementById('filename1').value = "";
                    document.getElementById('title2').value = "";
                    document.getElementById('filename2').value = "";
                    document.getElementById('title3').value = "";
                    document.getElementById('filename3').value = "";
                    document.getElementById('title4').value = "";
                    document.getElementById('filename4').value = "";
                    document.getElementById('title5').value = "";
                    document.getElementById('filename5').value = "";
                    alert(result);
                    _this.init_hideLightbox();
                }
                else {
                    if ($('#recaptcha_widget_div').css('display') != undefined && $('#recaptcha_widget_div').css('display') != 'none') {
                        Recaptcha.reload();
                    }
                    $('#ajaxBusy').hide();
                    alert(result);
                    _this.init_hideLightbox();
                }

            } else {
                $('#ajaxBusy').hide();
                alert("There was a problem retrieving the XML data:\n" + xmlHttp.statusText);
            }
        }
    }

    function photoUploadValidateRecaptchaStateChanged() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            if (xmlHttp.status == 200) {
                $('#ajaxBusy').hide();
                // ...processing statements go here...
                response = xmlHttp.responseXML.documentElement;
                method = response.getElementsByTagName('method')[0].firstChild.data;
                result = response.getElementsByTagName('result')[0].firstChild.data;
                success = response.getElementsByTagName('success')[0].firstChild.data;
                if (success == 'True') {
                    var flickremail = document.getElementById('FlickrEmailAdress');
                    var name = document.getElementById('photoupload_name');
                    var email = document.getElementById('photoupload_email');
                    var PhotoOneTitle = document.getElementById('title1');
                    var PhotoOneLocation = document.getElementById('image1');
                    var PhotoTwoTitle = document.getElementById('title2');
                    var PhotoTwoLocation = document.getElementById('image2');
                    var PhotoThreeTitle = document.getElementById('title3');
                    var PhotoThreeLocation = document.getElementById('image3');
                    var PhotoFourTitle = document.getElementById('title4');
                    var PhotoFourLocation = document.getElementById('image4');
                    var PhotoFiveTitle = document.getElementById('title5');
                    var PhotoFiveLocation = document.getElementById('image5');
                    $('#ajaxBusy').show();
                    url = "/KellyOCGAjaxBase/KellysOCGAjaxBase.aspx?action=uploadphoto&flickremail=" + flickremail.value + "&name=" + name.value + "&email=" + email.value + "&title1=" + PhotoOneTitle.value + "&location1=" + PhotoOneLocation.value + "&title2=" + PhotoTwoTitle.value + "&location2=" + PhotoTwoLocation.value + "&title3=" + PhotoThreeTitle.value + "&location3=" + PhotoThreeLocation.value + "&title4=" + PhotoFourTitle.value + "&location4=" + PhotoFourLocation.value + "&title5=" + PhotoFiveTitle.value + "&location5=" + PhotoFiveLocation.value;
                    xmlHttp = GetXmlHttpObject(photoUploadStateChanged);
                    xmlHttp.open("GET", url, true);
                    xmlHttp.send(null);
                }
                else {
                    alert('Confirmation: Invalid CAPTCHA, please try again.');
                    if ($('#recaptcha_widget_div').css('display') != undefined && $('#recaptcha_widget_div').css('display') != 'none') {
                        Recaptcha.reload();
                    }
                    _this.init_hideLightbox();
                }
            } else {
                $('#ajaxBusy').hide();
                alert("There was a problem retrieving the XML data:\n" + xmlHttp.statusText);
            }
        }
    }

    function memberResetPasswordStateChanged() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            if (xmlHttp.status == 200) {
                $('#ajaxBusy').hide();
                // ...processing statements go here...
                response = xmlHttp.responseXML.documentElement;
                method = response.getElementsByTagName('method')[0].firstChild.data;
                result = response.getElementsByTagName('result')[0].firstChild.data;
                success = response.getElementsByTagName('success')[0].firstChild.data;
                var MemberPasswordResetLiteral = document.getElementById('MemberPasswordResetLiteral');
                MemberPasswordResetLiteral.innerHTML = result;
                if ((($(window).height() - $('#resetPasswordLightbox').height()) / 2 + ($(window).scrollTop() - 100)) < $(window).scrollTop()) {
                    $('#resetPasswordLightbox').css("top", ($(window).height() - $('#resetPasswordLightbox').height()) / 2 + ($(window).scrollTop() + 20) + "px");
                }
                else {
                    $('#resetPasswordLightbox').css("top", ($(window).height() - $('#resetPasswordLightbox').height()) / 2 + ($(window).scrollTop() - 100) + "px");
                }
                $('#resetPasswordLightbox').css("left", ($(window).width() - $('#resetPasswordLightbox').width()) / 2 + $(window).scrollLeft() + "px");
                $('#resetPasswordLightbox').show();
            } else {
                $('#ajaxBusy').hide();
                alert("There was a problem retrieving the XML data:\n" + xmlHttp.statusText);
            }
        }
    }

    function getBlogEntriesStateChanged() {
        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            if (xmlHttp.status == 200) {
                $('#ajaxBusy').hide();
                // ...processing statements go here...
                //response = xmlHttp.responseXML.documentElement;
                //method = response.getElementsByTagName('method')[0].firstChild.data;
                //result = response.getElementsByTagName('result')[0].firstChild.data;
                //key = response.getElementsByTagName('key')[0].firstChild.data;

            } else {
                $('#ajaxBusy').hide();
                alert("There was a problem retrieving the XML data:\n" + xmlHttp.statusText);
            }
        }
    }


    function getText(obj) {
        for (var i = 0; i < obj.childNodes.length; i++) {
            if (obj.childNodes[i].nodeType == 3) { // text node
                result += obj.childNodes[i].nodeValue + ","; // collect text
            }
            else if (obj.childNodes[i].nodeType == 1) { // element node
                getText(obj.childNodes[i]); // recursive search
            }
        }
    }

    function getLeaderChanged() {

        if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
            if (xmlHttp.status == 200) {

                $('#ajaxBusy').hide();
                // ...processing statements go here...
                response = xmlHttp.responseXML.documentElement;
                //alert(xmlHttp.responseText);
                result = response.getElementsByTagName("result")[0];
                method = response.getElementsByTagName('method')[0].firstChild.data;
                success = response.getElementsByTagName('success')[0].firstChild.data;


                var searchresult = '';
                if (typeof XMLSerializer != "undefined")
                    searchresult = (new XMLSerializer()).serializeToString(result);
                else if (result.xml)
                    searchresult = result.xml;

                $("span.StaffProfileLiteral").html(searchresult);

            }
        }
    }

} (jQuery));

function printPartOfPage(elementId) {
    var printContent = document.getElementById(elementId);
    var printWindow = window.open('', '', 'left=0,top=0,scrollbars=1,width=500,height=500');

    var Html = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
    Html = Html + '<html id="html" lang="en"><head runat="server"><meta content="text/html;charset=UTF-8" http-equiv="content-type">';
    Html = Html + '<title>Kellys OCG</title><link type="text/css" rel="stylesheet" href="/css/grid.css">';
    Html = Html + '<link type="text/css" rel="stylesheet" href="/css/screen.css"><link rel="stylesheet" type="text/css" href="/css/print.css" />';
    Html = Html + '</head><body>';
    Html = Html + '<form id="form1" runat="server"><div id="page-wrapper" class="container_18">';
    Html = Html + '<div id="content">' + printContent.innerHTML + '</div></div></form></body></html>';

    printWindow.document.write(Html);

    printWindow.document.close();
    printWindow.focus();

    printWindow.print();
    printWindow.close();
}
