﻿/// <reference path="jquery-1.3-vsdoc.js" />
/// <reference path="jquery.string.js" />
/// <reference path="jquery.nyroModal-1.5.0.min.js" />
/// <reference path="jquery.livequery.js" />
/// <reference path="jquery.cookie.js" />
/// <reference path="jqDnR.js" />

var iCurrentSeqNum = 0;

var AttActions =
    {
        JOIN_REQ: 1,
        WITHDRAW_REQUEST: 2,
        ACCEPT_JOIN_REQUEST: 3,
        DECLINE_JOIN_REQUEST: 4,
        CAN_NO_LONGER_ATTEND: 5
    }

    $(document).ready(
function() {

    $('#ctl00_txtPassword, #ctl00_txtEmailAddress').keypress(function(e) {
        if (e.which == 13) {
            //$('#ctl00_btnSignin').click();
            __doPostBack('ctl00$btnSignin', '');
        }
    });

    $('#jqDialog').jqm({ modal: true, toTop: true }).jqDrag();
    $('#jqLocation').jqm({ modal: true, toTop: true });
    $('#jqLocMinor').jqm({ modal: true, toTop: true });

    $('#ctl00_lnkForgottenPassword').click(function(e) {
        var _email = $.trim($('#ctl00_txtEmailAddress').val());
        if (_email != '' && _email.toLowerCase() != 'email address') {
            if (confirm('Do you want to reset your password? (A new password will be emailed to you)')) {                
                __doPostBack('ctl00$lnkForgottenPassword', '')
            }
        }
        else {
            // invalid email address
            alert('Please enter your email address in the sign-in box');
        }
        return false;
    });

    $('ul#ulExpand').hover(function() {
        $(this).addClass('hoverClass');
    }, function() {
        $(this).removeClass('hoverClass');
    });

    $('#jqDialog').hover(function(e) {
        $(this).css('cursor', 'move');
    }, function(e) {
        $(this).css('cursor', 'default');
    });

    $('ul#ulExpand').click(function() {
        var a = $(this).find('a');
        if (bCheck) {
            $(a).css('background-image', 'url(/images/icon_contract.gif)');
            $.cookie('spOption', 1, { path: '/' });
        }
        else {
            $(a).css('background-image', 'url(/images/icon_expand.gif)');
            $.cookie('spOption', 0, { path: '/' });
        };

        bCheck = !bCheck;
        $('div.expandable_area').slideToggle('normal');
    });

    $('input#ctl00_btnSignin, input#ctl00_btnSignout, put#btnRegister, li#liRememberMe').hover(
          function() {
              $(this).css('cursor', 'pointer');
          }, function() {
              $(this).css('cursor', 'default');
          });

    $('div.navigation > ul > li').hover(function() {
        // do it for bottom _and_ top
        var wrappedSet = $('div.navigation > ul > li[menuIndex='
                                    + $(this).attr('menuIndex') + ']');

        wrappedSet.addClass('navOn');
        wrappedSet.children('a').addClass('navAnchorHover');
    }, function() {

        if ($(this).children('a').attr('isSelected') != "1") {
            // do it for bottom _and_ top
            var wrappedSet = $('div.navigation > ul > li[menuIndex='
                                        + $(this).attr('menuIndex') + ']');

            wrappedSet.removeClass('navOn');
            wrappedSet.children('a').removeClass('navAnchorHover');
        }
    });

    $('div.navigation > ul > li').click(function() {
        var wrappedSet = $('div.navigation > ul > li[menuIndex!='
                                    + $(this).attr('menuIndex') + ']');

        wrappedSet.removeClass('navOn');
        wrappedSet.children('a').removeClass('navAnchorHover');

    });

    $("input.signinfield").focus(function() {
        if (this.value == this.defaultValue) {
            this.select();
        }
    });

    $('#aChangeTop').click(changeEvent);
    $('#aChangeBottom').click(changeEvent);

    function changeEvent(e) {
        var elem = $('ul.country a[guid=' + $('#ctl00_hidCurrentLocGuid').val() + ']').css(
                        { backgroundPosition: '2px 50%', backgroundRepeat: 'no-repeat',
                            backgroundImage: 'url(/images/icon_ok_16.png)'
                        });
        $('#jqLocation').jqmShow();
    }

    $('#jqServDialClose').click(function(e) {
        $('#ctl00_jqServerDialog').css('display', 'none');
    });

    $('#ctl00_txtPassword').focus(function(e) {
        $(this).val('');
    });

    $('#ctl00_aCreateEvent').click(function(e) {
        if ($('#ctl00_hidUser')[0] == undefined) {
            __doPostBack('redirectToRegister', 'create');
        } else {
            __doPostBack('redirectToCreateEvent', '');
        }
    });

    $('#aWhyNotCreate').live('click', function(e) {
        if ($('#ctl00_hidUser')[0] == undefined) {
            __doPostBack('redirectToRegister', 'create');
        } else {
            __doPostBack('redirectToCreateEvent', '');
        }
    });

});

function getRedirectUrl(thePage) {
    var sUrl = document.location.href.slice(0, document.location.href.lastIndexOf('/') + 1);
    sUrl += thePage;
    return escape(sUrl);
}


