﻿$(document).ready(function () {
    if (window.location.hash) {
        ScrollTo(window.location.hash);
    }
    $('a[rel*=facebox],a[class*=facebox]').facebox({ loading_image: '/Images/Icons/ajaxload-miniprofile3.gif', close_image: 'closelabel.gif' });
    $('.like').click(function () {
        var sStr = "{'a':'" + $(this).attr('rel') + "'}"
        var objId = $(this).attr('rel');
        $.ajax({
            type: "POST",
            url: "/WebServices/ProcessAjaxRequest.asmx/UpdateLike",
            data: sStr,
            contentType: "application/json; charset=utf-8",
            timeout: 5000,
            cache: false,
            success: function (response) {
                var str = response.d;
                var substr = str.split('||');
                var likeNarrative = '';

                if (substr[1] == '1') {
                    likeNarrative = substr[1] + ' person likes this';
                } else {
                    likeNarrative = substr[1] + ' people like this';
                }

                $('#l_' + objId).html('<span class="tools">You like this</span>').css({ opacity: 0 }).fadeTo("normal", 1);
                $('#lc_' + objId).html('<span class="like-count">' + likeNarrative + '</span>').css({ opacity: 0 }).fadeTo("normal", 1);
            },
            error: function (objAJAXRequest, strError) {
                jQuery.facebox('<header>Oops! Something went wrong here...</header><div style="width:500px;"><p>We\'re sorry, but there has been a problem saving your profile settings. Our developers have been made aware of this problem and should have it sorted soon.</p><p>Please try again later.</p><p><strong>Error:</strong> ' + strError + '</p></div><footer><input type="button" value="Close" onclick="jQuery.facebox.close();" /></footer>');
            }
        });
    });
    $('#QuickStatus').tipsy({ gravity: 's' }).click(function () {
        if (jQuery.trim($('#QuickStatus').val()) == 'What\'s on your mind?') {
            $('#QuickStatus').val('');
        }
    }).blur(function () {
        if (jQuery.trim($('#QuickStatus').val()) == '') {
            $('#QuickStatus').val('What\'s on your mind?');
        }
    });
    $('.followus, .breadcrumbs, #EventCalPrevMonth, #EventCalNextMonth, .LoginHelp').tipsy({ gravity: 's' });
    $('#EventCalPrevMonth, #EventCalNextMonth, #GoToToday').click(function () {
        var sStr = "{'a':'" + this.id + "','b':'" + $('#rNav_DisplayDate').val() + "'}"
        $.ajax({
            type: "POST",
            url: "/WebServices/ProcessAjaxRequest.asmx/EventCalendarNavigation",
            data: sStr,
            contentType: "application/json; charset=utf-8",
            timeout: 5000,
            cache: false,
            success: function (response) {
                var str = response.d;
                var substr = str.split('|');
                var datestr = substr[1].split('/');
                var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
                var displayMonth = monthNames[datestr[1] - 1];
                $('#CalBody').empty().append(substr[0]).css({ opacity: 0 }).fadeTo("normal", 1);
                $('#rNav_DisplayDate').val(substr[1]);
                // setCookie('GPAEventCal', substr[1]);
                //$('#rNav_MonthName').html(displayMonth + ' ' + datestr[2]).css({ opacity: 0 }).fadeTo("normal", 1);
                $('#rNav_MonthName').html(displayMonth + ' ' + datestr[2]);
                initBinding();
            },
            error: function (objAJAXRequest, strError) {
                jQuery.facebox('<header>Oops! Something went wrong here...</header><div style="width:500px;"><p>We\'re sorry, but there has been a problem saving your profile settings. Our developers have been made aware of this problem and should have it sorted soon.</p><p>Please try again later.</p><p><strong>Error:</strong> ' + strError + '</p></div><footer><input type="button" value="Close" onclick="jQuery.facebox.close();" /></footer>');
            }
        });
    });
    $('#PollVoteSubmit').click(function () {
        alert($('#rNav_PollId').val() + ' / ' + $('input[name=' + $('#rNav_PollId').val() + ']:checked').val());
    });
    $('#PollViewResults').click(function () {
        $('#PollDivContent').html('test');
        $('#PollVoteSubmit, #PollViewResults').hide();
    });
    initBinding();
});

function initBinding() {
    $('.hasEvent').each(function () {

        // options
        var distance = 3;
        var time = 150;
        var hideDelay = 100;

        var hideDelayTimer = null;

        // tracker
        var beingShown = false;
        var shown = false;

        var trigger = $(this);
        var popup = $('.theEvent *', this).css('opacity', 0);

        $(trigger.get(0), popup.get(0)).mouseover(function () { // set the mouseover and mouseout on both element
            if (hideDelayTimer) clearTimeout(hideDelayTimer); // stops the hide event if we move from the trigger to the popup element

            if (beingShown || shown) { // don't trigger the animation again if we're being shown, or already visible
                return;
            } else {
                beingShown = true;
                popup.css({ // reset position of popup box
                    bottom: 20,
                    left: -76,
                    display: 'block' // brings the popup back in to view
                })
        .animate({ // (we're using chaining on the popup) now animate it's opacity and position
            bottom: '+=' + distance + 'px',
            opacity: 1
        }, time, 'swing', function () { // once the animation is complete, set the tracker variables
            beingShown = false;
            shown = true;
        });
            }
        }).mouseout(function () {
            if (hideDelayTimer) clearTimeout(hideDelayTimer); // reset the timer if we get fired again - avoids double animations

            hideDelayTimer = setTimeout(function () { // store the timer so that it can be cleared in the mouseover if required
                hideDelayTimer = null;
                popup.animate({
                    bottom: '-=' + distance + 'px',
                    opacity: 0
                }, time, 'swing', function () { // once the animate is complete, set the tracker variables
                    shown = false; // hide the popup entirely after the effect (opacity alone doesn't do the job)
                    popup.css('display', 'none');
                });
            }, hideDelay);
        });
    });
}

// THIRD PARTY FUNCTIONS

/*
* Facebox (for jQuery)
* version: 1.3
* @requires jQuery v1.2 or later
* @homepage https://github.com/defunkt/facebox
*
* Licensed under the MIT:
*   http://www.opensource.org/licenses/mit-license.php
*
* Copyright Forever Chris Wanstrath, Kyle Neath
*
* Usage:
*
*  jQuery(document).ready(function() {
*    jQuery('a[rel*=facebox]').facebox()
*  })
*
*  <a href="#terms" rel="facebox">Terms</a>
*    Loads the #terms div in the box
*
*  <a href="terms.html" rel="facebox">Terms</a>
*    Loads the terms.html page in the box
*
*  <a href="terms.png" rel="facebox">Terms</a>
*    Loads the terms.png image in the box
*
*
*  You can also use it programmatically:
*
*    jQuery.facebox('some html')
*    jQuery.facebox('some html', 'my-groovy-style')
*
*  The above will open a facebox with "some html" as the content.
*
*    jQuery.facebox(function($) {
*      $.get('blah.html', function(data) { $.facebox(data) })
*    })
*
*  The above will show a loading screen before the passed function is called,
*  allowing for a better ajaxy experience.
*
*  The facebox function can also display an ajax page, an image, or the contents of a div:
*
*    jQuery.facebox({ ajax: 'remote.html' })
*    jQuery.facebox({ ajax: 'remote.html' }, 'my-groovy-style')
*    jQuery.facebox({ image: 'stairs.jpg' })
*    jQuery.facebox({ image: 'stairs.jpg' }, 'my-groovy-style')
*    jQuery.facebox({ div: '#box' })
*    jQuery.facebox({ div: '#box' }, 'my-groovy-style')
*
*  Want to close the facebox?  Trigger the 'close.facebox' document event:
*
*    jQuery(document).trigger('close.facebox')
*
*  Facebox also has a bunch of other hooks:
*
*    loading.facebox
*    beforeReveal.facebox
*    reveal.facebox (aliased as 'afterReveal.facebox')
*    init.facebox
*    afterClose.facebox
*
*  Simply bind a function to any of these hooks:
*
*   $(document).bind('reveal.facebox', function() { ...stuff to do after the facebox and contents are revealed... })
*
*/
(function ($) {
    $.facebox = function (data, klass) {
        $.facebox.loading()

        if (data.ajax) fillFaceboxFromAjax(data.ajax, klass)
        else if (data.image) fillFaceboxFromImage(data.image, klass)
        else if (data.div) fillFaceboxFromHref(data.div, klass)
        else if ($.isFunction(data)) data.call($)
        else $.facebox.reveal(data, klass)
    }

    /*
    * Public, $.facebox methods
    */

    $.extend($.facebox, {
        settings: {
            //opacity: 0.2,
            opacity: 0.6,
            overlay: true,
            loadingImage: '/Images/Icons/ajaxload-miniprofile3.gif',
            closeImage: '/Images/Facebox/closelabel.png',
            imageTypes: ['png', 'jpg', 'jpeg', 'gif'],
            faceboxHtml: '\
                        <div id="facebox" style="display:none;"> \
                            <div class="popup"> \
                            <div class="content"> \
                            </div> \
                            </div> \
                        </div>'
        },

        loading: function () {
            init()
            if ($('#facebox .loading').length == 1) return true
            showOverlay()

            $('#facebox .content').empty()
            $('#facebox .body').children().hide().end().append('<div class="loading"><img src="' + $.facebox.settings.loadingImage + '"/></div>')

            $('#facebox').css({
                top: getPageScroll()[1] + (getPageHeight() / 5),
                left: $(window).width() / 2 - 205
            }).show()

            $(document).bind('keydown.facebox', function (e) {
                if (e.keyCode == 27) $.facebox.close()
                return true
            })
            $(document).trigger('loading.facebox')
        },

        reveal: function (data, klass) {
            $("body").css({ 'overflow': 'hidden' });
            $(document).trigger('beforeReveal.facebox')
            if (klass) $('#facebox .content').addClass(klass)
            $('#facebox .content').append(data)
            $('#facebox .loading').remove()
            $('#facebox .body').children().fadeIn('normal')
            $('#facebox').css('left', $(window).width() / 2 - ($('#facebox .popup').width() / 2))
            $(document).trigger('reveal.facebox').trigger('afterReveal.facebox')
        },

        close: function () {
            $(document).trigger('close.facebox')
            return false
        }
    })

    /*
    * Public, $.fn methods
    */

    $.fn.facebox = function (settings) {
        if ($(this).length == 0) return

        init(settings)

        function clickHandler() {
            $.facebox.loading(true)

            // support for rel="facebox.inline_popup" syntax, to add a class
            // also supports deprecated "facebox[.inline_popup]" syntax
            var klass = this.rel.match(/facebox\[?\.(\w+)\]?/)
            if (klass) klass = klass[1]

            fillFaceboxFromHref(this.href, klass)
            return false
        }

        return this.bind('click.facebox', clickHandler)
    }

    /*
    * Private methods
    */

    // called one time to setup facebox on this page
    function init(settings) {
        if ($.facebox.settings.inited) return true
        else $.facebox.settings.inited = true

        $(document).trigger('init.facebox')
        makeCompatible()

        var imageTypes = $.facebox.settings.imageTypes.join('|')
        $.facebox.settings.imageTypesRegexp = new RegExp('\.(' + imageTypes + ')$', 'i')

        if (settings) $.extend($.facebox.settings, settings)
        $('body').append($.facebox.settings.faceboxHtml)

        var preload = [new Image(), new Image()]
        preload[0].src = $.facebox.settings.closeImage
        preload[1].src = $.facebox.settings.loadingImage

        $('#facebox').find('.b:first, .bl').each(function () {
            preload.push(new Image())
            preload.slice(-1).src = $(this).css('background-image').replace(/url\((.+)\)/, '$1')
        })

        $('#facebox .close').click($.facebox.close)
        $('#facebox .close_image').attr('src', $.facebox.settings.closeImage)
    }

    // getPageScroll() by quirksmode.com
    function getPageScroll() {
        var xScroll, yScroll;
        if (self.pageYOffset) {
            yScroll = self.pageYOffset;
            xScroll = self.pageXOffset;
        } else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
            yScroll = document.documentElement.scrollTop;
            xScroll = document.documentElement.scrollLeft;
        } else if (document.body) {// all other Explorers
            yScroll = document.body.scrollTop;
            xScroll = document.body.scrollLeft;
        }
        return new Array(xScroll, yScroll)
    }

    // Adapted from getPageSize() by quirksmode.com
    function getPageHeight() {
        var windowHeight
        if (self.innerHeight) {	// all except Explorer
            windowHeight = self.innerHeight;
        } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
            windowHeight = document.documentElement.clientHeight;
        } else if (document.body) { // other Explorers
            windowHeight = document.body.clientHeight;
        }
        return windowHeight
    }

    // Backwards compatibility
    function makeCompatible() {
        var $s = $.facebox.settings

        $s.loadingImage = $s.loading_image || $s.loadingImage
        $s.closeImage = $s.close_image || $s.closeImage
        $s.imageTypes = $s.image_types || $s.imageTypes
        $s.faceboxHtml = $s.facebox_html || $s.faceboxHtml
    }

    // Figures out what you want to display and displays it
    // formats are:
    //     div: #id
    //   image: blah.extension
    //    ajax: anything else
    function fillFaceboxFromHref(href, klass) {
        // div
        if (href.match(/#/)) {
            var url = window.location.href.split('#')[0]
            var target = href.replace(url, '')
            if (target == '#') return
            $.facebox.reveal($(target).html(), klass)

            // image
        } else if (href.match($.facebox.settings.imageTypesRegexp)) {
            fillFaceboxFromImage(href, klass)
            // ajax
        } else {
            fillFaceboxFromAjax(href, klass)
        }
    }

    function fillFaceboxFromImage(href, klass) {
        var image = new Image()
        image.onload = function () {
            $.facebox.reveal('<div class="image"><img src="' + image.src + '" /></div>', klass)
        }
        image.src = href
    }

    function fillFaceboxFromAjax(href, klass) {
        $.get(href, function (data) { $.facebox.reveal(data, klass) })
    }

    function skipOverlay() {
        return $.facebox.settings.overlay == false || $.facebox.settings.opacity === null
    }

    function showOverlay() {
        if (skipOverlay()) return

        if ($('#facebox_overlay').length == 0)
            $("body").append('<div id="facebox_overlay" class="facebox_hide"></div>')

        $('#facebox_overlay').hide().addClass("facebox_overlayBG")
      .css('opacity', $.facebox.settings.opacity)
      .click(function () { })
      .fadeIn(200)
        return false
    }

    function hideOverlay() {
        if (skipOverlay()) return

        $('#facebox_overlay').fadeOut(200, function () {
            $("#facebox_overlay").removeClass("facebox_overlayBG")
            $("#facebox_overlay").addClass("facebox_hide")
            $("#facebox_overlay").remove()
        })

        return false
    }

    /*
    * Bindings
    */

    $(document).bind('close.facebox', function () {
        $("body").css({ "overflow": "visible" });
        $(document).unbind('keydown.facebox')
        $('#facebox').fadeOut(function () {
            $('#facebox .content').removeClass().addClass('content')
            $('#facebox .loading').remove()
            $(document).trigger('afterClose.facebox')
        })
        hideOverlay()
    })

})(jQuery);

(function ($) {
    $.fn.tipsy = function (options) {

        options = $.extend({}, $.fn.tipsy.defaults, options);

        return this.each(function () {

            var opts = $.fn.tipsy.elementOptions(this, options);

            $(this).hover(function () {

                $.data(this, 'cancel.tipsy', true);

                var tip = $.data(this, 'active.tipsy');
                if (!tip) {
                    tip = $('<div class="tipsy"><div class="tipsy-inner"/></div>');
                    tip.css({ position: 'absolute', zIndex: 100000 });
                    $.data(this, 'active.tipsy', tip);
                }

                if ($(this).attr('title') || typeof ($(this).attr('original-title')) != 'string') {
                    $(this).attr('original-title', $(this).attr('title') || '').removeAttr('title');
                }

                var title;
                if (typeof opts.title == 'string') {
                    title = $(this).attr(opts.title == 'title' ? 'original-title' : opts.title);
                } else if (typeof opts.title == 'function') {
                    title = opts.title.call(this);
                }

                tip.find('.tipsy-inner')[opts.html ? 'html' : 'text'](title || opts.fallback);

                var pos = $.extend({}, $(this).offset(), { width: this.offsetWidth, height: this.offsetHeight });
                tip.get(0).className = 'tipsy'; // reset classname in case of dynamic gravity
                tip.remove().css({ top: 0, left: 0, visibility: 'hidden', display: 'block' }).appendTo(document.body);
                var actualWidth = tip[0].offsetWidth, actualHeight = tip[0].offsetHeight;
                var gravity = (typeof opts.gravity == 'function') ? opts.gravity.call(this) : opts.gravity;

                switch (gravity.charAt(0)) {
                    case 'n':
                        tip.css({ top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2 }).addClass('tipsy-north');
                        break;
                    case 's':
                        tip.css({ top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 }).addClass('tipsy-south');
                        break;
                    case 'e':
                        tip.css({ top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth }).addClass('tipsy-east');
                        break;
                    case 'w':
                        tip.css({ top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width }).addClass('tipsy-west');
                        break;
                }

                if (opts.fade) {
                    tip.css({ opacity: 0, display: 'block', visibility: 'visible' }).animate({ opacity: 0.8 });
                } else {
                    tip.css({ visibility: 'visible' });
                }

            }, function () {
                $.data(this, 'cancel.tipsy', false);
                var self = this;
                setTimeout(function () {
                    if ($.data(this, 'cancel.tipsy')) return;
                    var tip = $.data(self, 'active.tipsy');
                    if (opts.fade) {
                        tip.stop().fadeOut(function () { $(this).remove(); });
                    } else {
                        tip.remove();
                    }
                }, 100);

            });

        });

    };

    // Overwrite this method to provide options on a per-element basis.
    // For example, you could store the gravity in a 'tipsy-gravity' attribute:
    // return $.extend({}, options, {gravity: $(ele).attr('tipsy-gravity') || 'n' });
    // (remember - do not modify 'options' in place!)
    $.fn.tipsy.elementOptions = function (ele, options) {
        return $.metadata ? $.extend({}, options, $(ele).metadata()) : options;
    };

    $.fn.tipsy.defaults = {
        fade: false,
        fallback: '',
        gravity: 'n',
        html: false,
        title: 'title'
    };

    $.fn.tipsy.autoNS = function () {
        return $(this).offset().top > ($(document).scrollTop() + $(window).height() / 2) ? 's' : 'n';
    };

    $.fn.tipsy.autoWE = function () {
        return $(this).offset().left > ($(document).scrollLeft() + $(window).width() / 2) ? 'e' : 'w';
    };

})(jQuery);

(function ($) {

    $.fn.autoResize = function (options) {

        // Just some abstracted details,
        // to make plugin users happy:
        var settings = $.extend({
            onResize: function () { },
            animate: true,
            animateDuration: 150,
            animateCallback: function () { },
            extraSpace: 20,
            limit: 1000
        }, options);

        // Only textarea's auto-resize:
        this.filter('textarea').each(function () {

            // Get rid of scrollbars and disable WebKit resizing:
            var textarea = $(this).css({ resize: 'none', 'overflow-y': 'hidden' }),

            // Cache original height, for use later:
                origHeight = textarea.height(),

            // Need clone of textarea, hidden off screen:
                clone = (function () {

                    // Properties which may effect space taken up by chracters:
                    var props = ['height', 'width', 'lineHeight', 'textDecoration', 'letterSpacing'],
                        propOb = {};

                    // Create object of styles to apply:
                    $.each(props, function (i, prop) {
                        propOb[prop] = textarea.css(prop);
                    });

                    // Clone the actual textarea removing unique properties
                    // and insert before original textarea:
                    return textarea.clone().removeAttr('id').removeAttr('name').css({
                        position: 'absolute',
                        top: 0,
                        left: -9999
                    }).css(propOb).attr('tabIndex', '-1').insertBefore(textarea);

                })(),
                lastScrollTop = null,
                updateSize = function () {

                    // Prepare the clone:
                    clone.height(0).val($(this).val()).scrollTop(10000);

                    // Find the height of text:
                    var scrollTop = Math.max(clone.scrollTop(), origHeight) + settings.extraSpace,
                        toChange = $(this).add(clone);

                    // Don't do anything if scrollTip hasen't changed:
                    if (lastScrollTop === scrollTop) { return; }
                    lastScrollTop = scrollTop;

                    // Check for limit:
                    if (scrollTop >= settings.limit) {
                        $(this).css('overflow-y', '');
                        return;
                    }
                    // Fire off callback:
                    settings.onResize.call(this);

                    // Either animate or directly apply height:
                    settings.animate && textarea.css('display') === 'block' ?
                        toChange.stop().animate({ height: scrollTop }, settings.animateDuration, settings.animateCallback)
                        : toChange.height(scrollTop);
                };

            // Bind namespaced handlers to appropriate events:
            textarea
                .unbind('.dynSiz')
                .bind('keyup.dynSiz', updateSize)
                .bind('keydown.dynSiz', updateSize)
                .bind('change.dynSiz', updateSize);

        });

        // Chain:
        return this;

    };



})(jQuery);

// CUSTOM FUNCTIONS

function ScrollTo(id) {
    $('html,body').animate({ scrollTop: $(id).offset().top }, 'slow');
}

function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

function isValidUrl(webAddress) {
    var pattern = new RegExp(/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi);
    return pattern.test(webAddress);
}

function confirmSignOut() {
    jQuery.facebox('<header>Confirmation needed...</header><div><p>Please confirm you wish to sign out from Gib8Ball.com?</p></div><footer><input type="button" value="Cancel" class="cancel" onclick="jQuery.facebox.close();" /> <input type="button" value="Sign Out" onclick="window.location.href=\'/Members/SignOut.aspx\';" /></footer>');
    return false;
}

function updateStatus(newStatus) {
    if (jQuery.trim(newStatus) != 'What\'s on your mind?') {
        var sStr = "{'a':'ValueNotSet','b':'ValueNotSet','c':'" + newStatus.replace(/'/g, "\\'") + "'}"
        $.ajax({
            type: "POST",
            url: "/WebServices/ProcessAjaxRequest.asmx/UpdateProfileDetails",
            data: sStr,
            contentType: "application/json; charset=utf-8",
            timeout: 5000,
            cache: false,
            success: function (response) {
                if (response.d == "False") {
                    jQuery.facebox('<header>Oops! Something went wrong here...</header><div style="width:500px;"><p>We\'re sorry, but there has been a problem saving your profile settings. Our developers have been made aware of this problem and should have it sorted soon.</p><p>Please try again later.</p></div><footer><input type="button" value="Close" onclick="jQuery.facebox.close();" /></footer>');
                } else {
                    jQuery.facebox('<header>Status update complete!</header><div><p>Your Gib8Ball.com status has successfully been updated.</p><p>Please note that some settings require a browser refresh before the changes become visible.</p></div><footer><input type="button" value="Close" onclick="jQuery.facebox.close();" /></footer>');
                    $('#QuickStatus').val('What\'s on your mind?');
                    if ($('#Status').length > 0) {
                        $('#Status').html(newStatus);
                        $('#StatusUpdated').html('Updated: less than a minute ago');
                    }
                }
            },
            error: function (objAJAXRequest, strError) {
                jQuery.facebox('<header>Oops! Something went wrong here...</header><div style="width:500px;"><p>We\'re sorry, but there has been a problem saving your profile settings. Our developers have been made aware of this problem and should have it sorted soon.</p><p>Please try again later.</p></div><footer><input type="button" value="Close" onclick="jQuery.facebox.close();" /></footer>');
            }
        });
    } else {
        jQuery.facebox('<header>Oops! Something went wrong here...</header><div><p>Please enter a status before clicking update.</p></div><footer><input type="button" value="Close" onclick="jQuery.facebox.close();" /></footer>');
    }
}

function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}

function getCookie(c_name) {
    var i, x, y, ARRcookies = document.cookie.split(";");
    for (i = 0; i < ARRcookies.length; i++) {
        x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
        y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
        x = x.replace(/^\s+|\s+$/g, "");
        if (x == c_name) {
            return unescape(y);
        }
    }
}

function checkCookie() {
    var username = getCookie("username");
    if (username != null && username != "") {
        alert("Welcome again " + username);
    }
    else {
        username = prompt("Please enter your name:", "");
        if (username != null && username != "") {
            setCookie("username", username, 365);
        }
    }
}
