﻿function setSizes(){

    // pageProperties
    menuWidth = 200;

    contentWidth = 760;
    contentPadding = 10;
    windowHeight = document.documentElement.clientHeight;
    windowWidth = document.documentElement.clientWidth;
    itemInSearchHeight = 45;
    
    
    //Defining the height of the header
    if (windowHeight > 650) //------ Larger then 1024*768
    {
        headerHeight =  100;
        logoContainerHeight = 0;
        logoTop = 20;
    }
    else if (windowHeight < 550) //- Less then 1024*768
    {
        headerHeight = 1;
        logoContainerHeight = 80;
        logoTop = 10;
    }
    else //------------------------- Is 1024*768
    {
        headerHeight =  20;
        logoContainerHeight = 80;
        logoTop = 20;
    }
    
    //Set header/logo/menu height
    document.getElementById("pageHeader").style.height = headerHeight + "px";
    document.getElementById("logoContainer").style.height = logoContainerHeight + "px";  
    document.getElementById("pageMenu").style.height = (windowHeight - headerHeight) + "px";
    document.getElementById("logo").style.top = logoTop + "px";
   
    //Overlay Size & Position
    document.getElementById("popupOverlay").style.height = (windowHeight - headerHeight) + "px";
    document.getElementById("popupOverlay").style.width  = (windowWidth - menuWidth) + "px";
    document.getElementById("popupOverlay").style.top    = headerHeight + "px";
    document.getElementById("popupOverlay").style.left   = menuWidth + "px";
   
    //Sets the amount of visible items in a search
    

    var visibleItems = Math.floor((windowHeight-headerHeight-184)/itemInSearchHeight);
    document.getElementById("ctl00_visibleItems").value = visibleItems;

    //path
    var path = location.pathname;
    
    //Basket
    if (path.lastIndexOf("cart.aspx") != -1)
    { 
        var frameHeight = windowHeight - headerHeight - 260;
        document.getElementById("cartFrame").style.height = frameHeight + "px";
    }
    
    //Pickup
    if (path.lastIndexOf("cartPickup.aspx") != -1)
    { 
        var frameHeight = windowHeight - headerHeight - 90;
        document.getElementById("cartFrame").style.height = frameHeight + "px";
    }
    
    //Detailed order page
    if (path.lastIndexOf("showOrder.aspx") != -1)
    { 
        var frameHeight = windowHeight - headerHeight - 50;
        document.getElementById("orderFrame").style.height = frameHeight + "px";
    }
}


//Position
function positionPopup(element,popupWidth)
{
    setSizes();
    
    var popupHeight = element.offsetHeight;
    var popupX = ((windowWidth-menuWidth)/2) - (popupWidth/2) + menuWidth + contentPadding;
    var popupY = ((windowHeight-headerHeight)/2) - (popupHeight/2) + headerHeight;
    
    element.style.width = popupWidth+"px";
    element.style.top = popupY+"px";
    element.style.left = popupX+"px";
}


//Cart priceswitch
function switchPrices()
{
    if (document.getElementById("masterCartNetPrice").style.display == "none")
    {
        document.getElementById("masterCartGrossPrice").style.display = "none";
        document.getElementById("masterCartNetPrice").style.display = "inline";
    }
    else
    {
        document.getElementById("masterCartGrossPrice").style.display = "inline";
        document.getElementById("masterCartNetPrice").style.display = "none";
    }
}


//Mouseposition
var isIE = document.all ? true : false;
if (!isIE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMousePosition;

function getMousePosition(e) {
  if (!isIE)
  {
    _x = e.pageX +14;
    _y = e.pageY -4;
  }
  else
  {
    _x = event.clientX +14;
    _y = event.clientY -4;
    
  }
  //return true;
}


//Fjerner popup
function clearPopup()
{
    document.getElementById("popupOverlay").style.display = "none";
    document.getElementById("popupGeneral").style.display = "none";

    var pathname = location.pathname;
    
    if (pathname.lastIndexOf("cart.aspx") != -1)
    { 
        document.location.href="cart.aspx?id=30";
    }

}

//Fjerner itemInfo
function clearPopupItemInfo()
{
    document.getElementById("popupItemInfo").style.display = "none";
}

function addOnEnter(e,id)
{
    var key = e.charCode ? e.charCode : e.keyCode;
    if (key == 13)
        document.getElementById("ctl00_Content_"+id+"").focus();
    if (key != 8) //Backspace
        if (key<48||key>57) //Numre
            return false;
}

//Sætter fokus på et element hvis det eksisterer
function setFocus(item)
{
    if (document.getElementById(item) != null)
    {
        document.getElementById(item).focus(); //Sætter txtCount til værdien på varen
        
        //txtCount feltet kan requestes efter postback
        document.getElementById("ctl00_Content_txtCount").value = document.getElementById(item).value;
    }
}
