﻿
$(document).ready(function() {
setTimeout("setBackground()", 0);
});

function applyLoginFieldsEffect()
{
setUserDefaultEmailFromCookie();
    
    $('#pass-text').focus(function() {
        $('#pass-text').hide();
        $('#Password').show();
        $('#Password').focus();
    });
    $('#Password').blur(function() {
        if ($('#Password').val() == '') {
            $('#pass-text').show();
            $('#Password').hide();
        }
    });

    $('#userName-text').focus(function() {
        $('#userName-text').hide();
        $('#userName').show();
        $('#userName').focus();
    });
    $('#userName').blur(function() {
        if ($('#userName').val() == '') {
            $('#userName-text').show();
            $('#userName').hide();
        }
    });
}

function setUserDefaultEmailFromCookie() {
    
    var userEmail = Get_Cookie("userEmail");
    if (userEmail) {
        $('#userName').val(userEmail);
            $('#userName-text').hide();
            $('#userName').show();
    }
}

function streachBackgroundsUsingGradient() {
     }

   function streachBackgrounds() {
       if (Theme.toLowerCase() == "sport") return;      
    }
function setBackground() {
return
    var BackGroundGradientIMG = $("#BackGroundGradientImage");
    if (BackGroundGradientIMG.css("display") === "none") return;
    BackGroundGradientIMG.css("display", "none");
    var InnerContainer = $("#InnerContainer");
    var obj = $(".centerBlock");
    
    try{
    h = obj.height();
    }catch(e){return}
    if (h == 0) { setBackground(".centerBlock"); return; }
    var margin = ((InnerContainer.css("margin-top") !== undefined && !isNaN(InnerContainer.css("margin-top").replace("px", ""))) ? Number(InnerContainer.css("margin-top").replace("px", "")) : 0)
                - ((BackGroundGradientIMG.css("margin-top") !== undefined && !isNaN(BackGroundGradientIMG.css("margin-top").replace("px", ""))) ? Number(BackGroundGradientIMG.css("margin-top").replace("px", "")) : 0)

    var h = obj.height()
            + ((InnerContainer.css("margin-top") !== undefined && !isNaN(InnerContainer.css("margin-top").replace("px", ""))) ? Number(InnerContainer.css("margin-top").replace("px", "")) : 0)
            + ((obj.position() == null) ? 0 : obj.position().top)
            + ((InnerContainer.position() == null) ? 0 : InnerContainer.position().top);
    if (h < 500)  hCB = h = 500;

    InnerContainer.height(h - margin + 20);
    BackGroundGradientIMG.height(h);

   /* if (jQuery.browser.mozilla) {
       
        BackGroundGradientIMG.width($(".footerTD").find("table:first").width());
    }*/
    BackGroundGradientIMG.css("display", "block");
    
}
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
/*\\\\\\\\\\\Logout User\\\\\\\\\\\\*/
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
function LogoutUser() {
    try {
        UserServices_LogoutUser(m_session, onLogoutUserSuccess);
    }
    catch (ex) { }

}
function onLogoutUserSuccess(result) {

    location.href = "http://" + location.host;
}



/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
/*\\\\\\\\\\\Get Fresh User\\\\\\\\\*/
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
function GetUserBalance() {
    if (m_session != '')
        UserServices_GetUserBalance(m_session, onSuccessGetUser);
}

function onSuccessGetUser(result) {
    if (result == null) return;
     setUserDisplayedBalance(parseFloat(result.Balance));
      CheckUserBalance();
}

function setUserDisplayedBalance(balance) {
     $("#UserBalanceDisplay").text(addCommas(balance.toFixed(2)));
    
}

function getUserDisplayedBalance() {
    return  parseFloat($("#UserBalanceDisplay").text().replace(',', ''));
   // return parseFloat(document.getElementById('UserBalanceDisplay').innerText.replace(',', ''));
}

/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
/*\\\\\Extracted from masterpage\\\\*/
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/

function SendSessionURL() {
    var callerURL = $(this)[0].href;
    var callerPath = $(this)[0].pathname;
    //HACK to fix session in content pages
    var searchDomain = location.host.toUpperCase();
    var searchURL = callerURL.toUpperCase();
    if (isLoggedIn() && (callerURL.indexOf("#") == -1) && (callerURL.search("javascript:") == -1) && (searchURL.search(searchDomain) != -1)) {

       if ($.query !== undefined) {
           $(this)[0].href = "/" + callerPath;
       }
        
    }
}


/*///blinking user balance odelia\\\*/
function CheckUserBalance() {
    BalanceElement = document.getElementById("UserBalanceDisplay");
    if (BalanceElement == null)
        return;

    var displayedBalance = getUserDisplayedBalance();

    if (OldBalance == 0) {
        OldBalance = displayedBalance;

    } else if (OldBalance < displayedBalance) {
        OldBalance = displayedBalance;
        BlinkBalanceText();
        setTimeout("StopBlinkingBalanceText()", BLINKING_TIME_OUT);
    } else {
        OldBalance = displayedBalance;
    }
}

function BlinkBalanceText() {
    BlinkControl('UserBalanceDisplay');
    TimeoutBlinkProcess = setTimeout("BlinkBalanceText()", BLINKING_TEXT_INTERVAL);
}
function StopBlinkingBalanceText() {
    clearTimeout(TimeoutBlinkProcess);
    document.getElementById('UserBalanceDisplay').style.visibility = "visible";
}


function ApplyHoverability() {
    $(".Hoverable").mouseenter(HandleHoverable_MouseEnter);
    $(".Hoverable").mouseleave(HandleHoverable_MouseLeave);
}

function HandleHoverable_MouseEnter(eventArgs) {
    if (this.tagName.toUpperCase() == "IMG") {
        if (this.src.indexOf('_Hover') == -1)
            this.src = InsertAtIndex(this.src, "_Hover", this.src.lastIndexOf('.') + 1);
    }
    else {
        if (this.style.backgroundImage.indexOf('_Hover') == -1)
            this.style.backgroundImage = InsertAtIndex(this.style.backgroundImage, "_Hover", this.style.backgroundImage.lastIndexOf('.') + 1);
    }
}

function HandleHoverable_MouseLeave(eventArgs) {
    if (this.tagName.toUpperCase() == "IMG") {
        this.src = this.src.replace('_Hover.', '.');
    }
    else {
        this.style.backgroundImage = this.style.backgroundImage.replace('_Hover.', '.');
    }
}
function MainBannerSwitch(id, isWeekend) {
    var _imgName = (isWeekend) ? "main_img_WE" : "main_img";
    var myOptions = { noImages: 2, path: Skin + "/Media/Images/Accounts/" + id + "/SlideshowImages/", imgType: "gif", imgName: _imgName, timerInterval: 7000}
    $("div.MainBlockBackgroundTD").easySlides(myOptions);
}
function ImgOnMainBannerSwitch() {
    var myOptions = { noImages: 2, path: Skin + "/Media/Images/SlideshowImages/", imgType: "gif", imgName: "img", timerInterval: 5000 }
    $("div.MainBannerText").easySlides(myOptions);
 }

function RemoveCookieBoxStyle() {
    if (Skin.toLowerCase().indexOf("ezbinaryskin") > -1)  //task 1643 
        Delete_Cookie("tbv1", "/", window.location.hostname);
}
