﻿/// <reference path="../JqueryJs/jquery-1.2.6-vsdoc.js"/>
// global variables
var signUpWnd = null;
var resetPassWnd = null;
function closeRadWindows() {
    if (signUpWnd != null)
        signUpWnd.close();
    if (resetPassWnd != null)
        resetPassWnd.close();
}
$(function() {
    $('.floatingFeedback').aqFloater({ attach: 'se' });
    $('.floatingFeedback').click(function() {
        $.dimScreen(500, 0.7, function() {
            jQuery.facebox({ div: '#showfeedback' });
            setupFeedback();
        });

    });

    $('.centerDiv').css({ "display": "block" });
    //show the correct login controls
    if ($('.nickname').val() != "" && $('.greendollar').val() != "") {
        $('#headerCatchPhrase').css("display", "none");
        $('.Login').css("display", "none");
        $('.LoginError').css("display", "none");
        $('.LoginSuccessful').css("display", "block");

        //$('.LoginSuccessfulMessage').html("Welcome, " + $('.nickname').val() + "!<br/><div style='float: left; margin-top: 5px; padding-top: 2px;'>You have </div><div class='greenDollarAmount greenDollarAmountinDB'><font class='WineFontColor'>" + $('.greendollar').val() + "</div></font><div style='float: left; margin-top: 5px; padding-top: 2px;'> trading points.</div>")
        //$('.LoginSuccessfulMessage').html("Welcome, " + $('.nickname').val() + "!<br/><div style='float: left; margin-top: 5px; padding-top:         2px;'>You have </div><div id='greenDollarAmount' style='margin-left:3px;width:12px; float:Left' class='greenDollarAmount floatLeft'></div><div style='float: left;margin-top:7px;margin-right:2px'><font class='WineFontColor'>" + $('.greendollar').val() + "</font></div><div style='float: left; margin-top: 5px; padding-top: 2px;'> trading points.</div>")
        $('.LoginSuccessfulMessage').html("Welcome, " + $('.nickname').val() + "!<br/><div style='float: left; margin-top: 5px; padding-top: 2px;'></div><div id='greenDollarAmount' style='margin-left:3px;width:12px; float:Left' class='greenDollarAmount floatLeft'></div><div style='float: left;margin-top:7px;margin-right:2px' class='GDALabel'><font class='WineFontColor'>" + $('.greendollar').val() + "</font></div><div style='float: left; margin-top: 5px; padding-top: 2px;'> trading points </div><div style='float:left;margin-top: 5px; padding-top: 2px;'></div><div id='walletAmount' style='margin-left:3px;float:Left' class='walletAmount floatLeft'></div><div style='float: left;margin-top:7px;margin-right:2px;margin-left:3px;' class='walletALabel'><font class='WineFontColor'>" + $('.walletA').val() + "</font></div><div style='float: left; margin-top: 5px; padding-top: 2px;'> wallet balance</div>")

        $('.LoginSuccessfulMessage').css("display", "block");
        //        $('.btnHome').css({ "left": "480px", "top": "42px", "width": "40px", "display": "block" });
        //        $('.btnHomeText').text("Home");
        //firefox 2 does not support inline-block
        if (BrowserDetect.browser == "Firefox") {
            if (BrowserDetect.version < 3) {
                $('.TheDBMenu').css({ "display": "inline" });
            }
            else {
                $('.TheDBMenu').css({ "display": "inline-block" });
            }
        }
        else {
            $('.TheDBMenu').css({ "display": "inline-block" });
        }

        $('.GeneralMenu').css({ "display": "none" });
    }
    else {
        //        $('.btnHome').css({ "left": "510px", "top": "50px", "width": "200px", "display": "none" });
        //        $('.btnHomeText').text("Back to SwapItGreen home");
       // $('#pendingTasksContainer').css("display", "none");
    }

    if ($('.inthenewshidden').val() != "0") {
        $('.inthenews').css("display", "inline");
    }
    else {
        $('.inthenews').css("display", "none");
    }

    //set up the curvy corners plugin
    //    $('.innerContainer').corner({
    //        tl: { radius: 15 },
    //        tr: false,
    //        bl: false,
    //        br: { radius: 15 },
    //        antiAlias: true,
    //        autoPad: true,
    //        validTags: ["div"]
    //    });
    $('#Login .SignUpLink').click(function() {
        var url = $('#Login .SignUpLink').attr("info");
        //jQuery.showAkModal(url, 'Sign Up', 320, 350);
        //signUpWnd = radopen(url, 'rwSignUp');
        location.href = url;
        return false;
    });
    $('#Login .forgotPasswordLink').click(function() {
        var url = $('#Login .forgotPasswordLink').attr("info");
        //jQuery.showAkModal(url, 'Forgot Password', 320, 235);
        //resetPassWnd = radopen(url, 'rwPass');
        location.href = url;
        return false;
    });
    if ($('.buyPointsHidden').val() == "1") {
        $('.BuyPointsMenu').css("display", "inline");
        $('.BuyPointsMenu').click(function() {

            jQuery.showAkModal("../MessageForms/BuyTradingPoints.aspx?page=" + $('.pageurl').val(), "Buy Trading Points", 600, 270);

            return false;
        });
    }
    else {
        $('.BuyPointsMenu').css("display", "none");
    }
});

//SWAPITGREEN.MASTER *******************************************
function pageLoad() {
    // If function contentPageLoad exists, execute it.
    if (typeof contentPageLoad == 'function')
        contentPageLoad();
}
// 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 whatCanIGet() {
    PurpleParrot.SwapSite.WebUI.Services.Search.whatCanIGet($('.greendollar').val(), onHandleKeySucc1, onHandleKeyFailure);
    return false;
}
function onHandleKeySucc1(result) {
    window.location = result;
}
function onHandleKeyFailure(error) {
    alert(error.get_message());
}


if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();