﻿//DEFAULT.MASTER *******************************************
function SimpleCategory() {
    this.Id = 0;
    this.Text = '';
    this.Count = 0;
    this.Url = '';
    this.Children = new Array();
}

function pageLoad() {


    $('.contestHighlight').effect("pulsate", { times: 5 }, "slow");
    $('.GiveAwaysDiv').mouseover(function() {
        $('.contestHighlight').effect("highlight", { 'color': '#842439' }, 2000);
        $('.pointerCursor').css({ 'cursor': 'pointer' });
    });


    // If function contentPageLoad exists, execute it.
    if (typeof contentPageLoad == 'function')
        contentPageLoad();

    if (typeof LoadHomeIntro == 'function') {
        LoadHomeIntro();
    }

}
// Show login in akModal
function loginPopup() {
    var url = $('#Login .MarkerLogin').attr("info");
    //jQuery.showAkModal(url, 'Secure Login', 530, 360);
    //var oWnd = radopen(url, 'rwLogin');
    location.href = url;
}
function logoutUser() {
    IUserInfoService.GetRedirectUrl(onGetRedirectUrlSuccess, onGetRedirectUrlFailure);
    return false;
}
function onGetRedirectUrlSuccess(result, context, methodName) {
    //Sys.Debug.traceDump(result, "RedirectUrl");
    Sys.Services.AuthenticationService.logout(result, onLogoutSuccess, onLogoutFailure, null);
    return false;
}
function onGetRedirectUrlFailure(error, context, methodName) {
    alert(error.get_message());
}
function onLogoutSuccess(result, context, methodName) {
    $('#LoginControls .MarkerEmail').val("");
    $('#LoginControls .MarkerPassword').val("");
    $('.Login').css("display", "block");

    $('#LoginControls .LoginError').css("display", "none");
    $('.LoginSuccessful').css("display", "none");
    $('#LoginSuccessful .LoginSuccessfulMessage').html("");
    $('.nickname').val("");
    $('.greendollar').val("");

}
function onLogoutFailure(error) {
    alert(error.get_message());
}
function comboLoad(sender, eventArgs) {
    sender.set_text(sender.get_items().getItem(0).get_value());
}
function nodeClicking(sender, args) {
    var comboBox = $find("ctl00_RadComboBox1");
    var node = args.get_node()
    comboBox.set_text(node.get_text());
    comboBox.trackChanges();
    comboBox.get_items().getItem(0).set_value(node.get_text());
    comboBox.commitChanges();
    comboBox.hideDropDown();
    $('.saveCatid')[0].value = node.get_value();
}
function StopPropagation(e) {
    if (!e) {
        e = window.event;
    }
    e.cancelBubble = true;
}
function OnClientDropDownOpenedHandler(sender, eventArgs) {
    var tree = sender.get_items().getItem(0).findControl("RadTreeView1");
    if (tree != null) {
        var selectedNode = tree.get_selectedNode();
        if (selectedNode) {
            selectedNode.scrollIntoView();
        }
    }
}
function whatCanIGet() {
    PurpleParrot.SwapSite.WebUI.Services.Search.whatCanIGet($('.greendollar').val(), onHandleKeySucc1, onHandleKeyFailure);
    return false;
}
function onHandleKeySucc1(result) {
    window.location = result;
}

var _cancelLoad = false;
var _curMenuId;

function LoadCategoryChildren(menu, args) {

    _cancelLoad = false;

    setTimeout(function() {
        if (_cancelLoad == false) {
            _curMenuId = args.get_item().get_value();
            var attributes = args.get_item().get_attributes();
            var loaded = attributes.getAttribute("loaded");
            if (loaded == null) {
                var catId = args.get_item().get_value();
                PurpleParrot.SwapSite.WebUI.Services.Search.GetCategoryChildren(catId, onGetCategoryChildrenSuccess);
            }
        }

    }, 750);

}

function CancelLoadCategoryChildren(menu, args) {
    _cancelLoad = true;
}

function onGetCategoryChildrenSuccess(result) {
    //var menu = $find("<%= listingCategoryMenu.ClientID %>");
    var menu = $find("ctl00_listingCategoryMenu");
    //menu.trackChanges();
    var parentItem = menu.findItemByValue(result.Id);

    $.each(result.Children, function(i, val) {
        var menuItem = new Telerik.Web.UI.RadMenuItem();
        menuItem.set_text(val.Text);
        menuItem.set_value(val.Id);
        menuItem.set_navigateUrl(val.Url);
        parentItem.get_items().add(menuItem);
    });

    var attributes = parentItem.get_attributes();
    attributes.setAttribute("loaded", "true");

    //menu.commitChanges();
    if (_curMenuId == result.Id) {
        parentItem.open();
    }

}
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();