﻿function scroll()
{
      if ( document.documentElement && document.documentElement.scrollTop )
      {
            document.documentElement.scrollTop = 0;
      }
      else if ( document.body )
      {
            document.body.scrollTop = 0;
      }
}

function showCartDetail(makevisible)
{
    if (makevisible)
    {
        scroll();
        _showCartDetail();
   
       var cd = $("#CartDetail");
       if (cd != null) {
            if (hide) clearTimeout(hide);
            hide = setTimeout(function() { _hideCartDetail();}, 4000);
       }
    }
}

function _showCartDetail()
{
    var cd = $("#CartDetail");
    
    if (cd === undefined || cd == null || cd.length == 0) {
        cd = $("<div />");
        cd.attr("id", "CartDetail");
        cd.addClass("CartInfoDetail2");
        cd.css({position: 'absolute', display: 'none'});        
        cd.appendTo($("body"));
    }
    var ch = $(".Carthdr");
    var pos = ch.offset();
    var toppos = pos.top + ch.height() + 10;
    var leftpos = pos.left - 44;
    
    cd.css({width: '195px', background: '#ffffff'});        
    cd.css({top: (toppos + 'px'), left: (leftpos + 'px')});
    cd.html($("#CartDetailTemplate").html());
    cd.fadeIn("fast");

    $('.Carthdr').addClass("Carthdrborder");
}


function _hideCartDetail() {
   $('.Carthdr').removeClass("Carthdrborder");
    $('#CartDetail').fadeOut("slow");    
}

function _getSecUrl(url)
{
    var curl = 'https://' + window.location.hostname + url;
    return curl;
}

function updateCartInformation(makevisible)
{ 
   var ci = jQuery("#cartInfo");
    
    if (ci != null) 
    {
        jQuery.get('/Benefits/Cart/UpdateCartStatus.rails',
                 { ts: (new Date()) },
                   function(data) {
                       var trgt = $('#templateDiv');
                       
                       if (trgt.length > 0) {
                           $('#templateDiv').createTable(data);
                           showCartDetail(makevisible);
                       }
                   },
                "json");
    }
}

function setSDRCartPos() {
    var sdrtarget = jQuery("#reposition");

    if (sdrtarget.length > 0) {
        var ch = $('.CartInfoDiv');
        var shift = 0;
        sdrtargetCnt = $('#topnavmain>ul>li');

        if (sdrtargetCnt.length > 2) {
            var itemno = sdrtargetCnt.length - 2;
            sdrLastPos = $('#topnavmain>ul>li:eq(' + itemno + ')');
            shift = sdrLastPos.position().top - ch.position().top;
        }
        
        if (navigator.platform.match(/win/ig) != null) {
            if (navigator.appName.match(/microsoft/ig) != null && navigator.appVersion.match(/MSIE 7./ig) != null) 
            {
                shift = shift - 1;
            } else {
                shift = shift - 2;
            }
        }    

        if (shift != 0)
            ch.css({ top: (shift + 'px') });
    }
};


