﻿
//<!--
if ((navigator.appVersion.indexOf("Mac") != -1)) {
    document.write("<link rel=stylesheet href=\"http://img.ireward.com.au/content/css/mac.css\" type=\"text/css\" />");
}
// -->


function ApplyWallMessgeBehavior(e) {
    //Hide all reply box.
    $('.addReplyWrapper').hide();

    $(".commentActions .showAllCommentsLink").show();
    

    //Add behaviour to remove post link
    $('A.RemovePost').click(function(e) {
        e.preventDefault();
        $.ajax({
            type: "GET",
            url: $(this).attr('href'),
            cache: false,
            success: function() { $(e.target).parents('.MessageWrapper').fadeOut(200); },
            error: function() { location.reload(); }
        });
    });

    //Apply behavior to delete link.
    $('A.RemoveComment').click(function(e) {
        e.preventDefault();
        $.ajax({
            type: "GET",
            url: $(this).attr('href'),
            cache: false,
            success: function() { $(e.target).parents('.friendStatus').fadeOut(200); },
            error: function() { location.reload(); }
        });
    });
}


function HightLightTab(e) {
    //Unselect previous one.
    $('.tabNav').find('li.selected').removeClass('selected');
    $(this).parent().toggleClass('selected');
}
function HideFriendElement(e) {
    $(this).closest('div').slideUp('fast');
}
function HideForumPost(e) {

    $(this).closest('.post').slideUp('fast');

}
function RefreshPage(e) {
    window.location.reload(true);
}


function UpdateFriendRequestView(e) {

    $(this).closest('div').slideUp('fast');
    var $friendCount = $('#FriendRequestCount').html();
    //Update friendRequest display count if available.
    if ($friendCount.length > 0) {
        $friendCount--;
        if ($friendCount > 0) {
            $('#FriendRequestCount').html($friendCount);
            $('#CountDisplayTitle').html($friendCount);
        }
        else {
            $('#FriendRequestCount').parent().hide();
            $('#CountDisplayTitle').html('No');
        }
    }

}

function HideElement(e) {
    $(this).hide();
}


$(document).ready(function() {
    //focus the cursor on the first visible input field but skips Friend Search
    $("input:visible:enabled:not(#friendSearch):first").focus();


    //Bread Crumb function
    var breadCrumb = $('#breadCrumb').html();

    if (!breadCrumb) {
        $('#navHome').attr('class', 'selected');
    }
    else if (breadCrumb.match("Earn") != null || breadCrumb.match("Online Rewards") != null) {
        $('#navEarnPoints').attr('class', 'selected');
    }
    else if (breadCrumb.match("Spend") != null) {
        $('#navSpendPoints').attr('class', 'selected');
    }
    else if (breadCrumb.match("Competitions") != null) {
        $('#navCompetitions').attr('class', 'selected');
    }
    else if (breadCrumb.match("Your Friends") != null) {
        $('#navYourFriend').attr('class', 'selected');
    }
    else if (breadCrumb.match("Your Account") != null) {
        $('#navAccount').attr('class', 'selected');
    }
    else if (breadCrumb.match("About") != null) {
        $('#navAccount').attr('class', 'selected');
    }
    else if (breadCrumb.match("Help") != null) {
        $('#navHelp').attr('class', 'selected');
    }
    else if (breadCrumb.match("Contact Us") != null) {
        $('#navContact').attr('class', 'selected');
    }
    else
        $('#navHome').attr('class', 'selected');


    //Account Logon
    $('#AccountLogon').click(function(e) {
        e.preventDefault();
        $('#login').css('display', 'Block');
        $('#login').find('#LoginUsername').focus();
    });

    //Mouse hover remember me
    $('#RememberMeLnk').hover(
    function() {
        $('#RememberMeSpan').removeClass('off');
    },
    function() {
        $('#RememberMeSpan').addClass('off');
    });

    //Close logon
    $('#CloseLogon').click(function(e) {
        $('#login').css('display', 'none');
    });

    //find out if there are elements with input-validation-error
    //and mark it's parent li with error class.

    $inputErrors = $('.field-validation-error');

    $inputErrors.each(function() {
        $(this).closest('li').addClass('error');
    });

    //check if error class has been applied.
    $error = $('#login').children().children().children('.error')
    if ($error.length > 0) {
        $('#login').css('display', 'Block');
    }

});


