﻿
$(document).ready(function() {

//setTimeout("streachBackgrounds()", 0);
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() {
   // if (document.getElementById('BackGroundGradientImage'))
      //  $("#BackGroundGradientImage").gradient({ colorStart: ['#ffffff', '#e6ebef'], colorEnd: ['#e6ebef', '#ffffff'], spaceSize: [100], horizontal: false, opacity: 90, lineWidth: 5 });
   }

   function streachBackgrounds() {

       if (Theme.toLowerCase() == "sport") return;
      
    /*if (document.getElementById('BackGroundGradientImage') && document.getElementById('InnerContainer') ) {
        document.getElementById('BackGroundGradientImage').style.height = (Number(document.getElementById('InnerContainer').offsetHeight) + 50).toString() + 'px';
       }
     
    if (document.getElementById('baseBackgroundBottomGradientImg'))
       document.getElementById('baseBackgroundBottomGradientImg').style.height = (Number(document.getElementById('MainContentTable').offsetHeight) - 180).toString() + 'px';
*/}
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;

//    var isLocalLink = false;
//    location.host
    //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) {
//           var action = callerPath.slice(callerPath.lastIndexOf("/"));
//           if (action.indexOf("/") > -1)
//               $(this)[0].href = callerPath.substr(0, callerPath.lastIndexOf("/")) + $.query.load(callerURL).set('s', m_session).toString() + action
//           else {
////               if (callerURL.indexOf("/content/") != -1)
////                   callerPath = "/" + callerPath;
//               $(this)[0].href = "/" + callerPath + $.query.load(callerURL).set('s', m_session).toString();
           //           }

           //   $(this)[0].href = "/" + callerPath + $.query.load(callerURL).set('s', m_session).toString();
           $(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.', '.');
    }
}

