﻿        function AdjustColumnsHeight()
        {
            // get a reference to the three DIVS that make up the columns
            var centerCol = window.document.getElementById('mainCol');
            var leftCol = window.document.getElementById('menuCol');
            var rightCol = window.document.getElementById('basketCol');
            
            // calculate the max height
            var hCenterCol = centerCol.offsetHeight;
            var hLeftCol = leftCol.offsetHeight;
            var hRightCol = rightCol.offsetHeight;
            var maxHeight = Math.max(hCenterCol, Math.max(hLeftCol, hRightCol));
            // set the height of all 3 DIVS to the max height
//            centerCol.style.height = maxHeight + 'px';
//            leftCol.style.height = maxHeight + 'px';
//            rightCol.style.height = maxHeight + 'px';            
            // Show the footer
            window.document.getElementById('footer').style.visibility = 'inherit';
            window.document.getElementById('footer').style.top = (maxHeight + 148).toString() + 'px';
        }
        window.onload = function() { AdjustColumnsHeight(); }
        window.onresize = function() { AdjustColumnsHeight(); }


function changeQuantity(ID, amount) 
{ 
    if(document.getElementById != null) 
    { 
        var txtQuantity = document.getElementById(ID); 
        if(!isNaN(txtQuantity.value)) 
        { 
            var intQuantity = parseInt(txtQuantity.value); 
            var intNewQuantity = intQuantity + amount;
            if(intNewQuantity < 1)
            {
                intNewQuantity = 1;
            }
            if(intNewQuantity > 999)
            {
                intNewQuantity = 999;
            }
            txtQuantity.value = intNewQuantity.toString();
        } else {
            txtQuantity.value = "1";
        }
    }
}

function popup(ID)
{
    if(document.getElementById != null)
    {
        var elements = document.documentElement.getElementsByTagName("div");
        var element;
        for(i = 0; i < elements.length; i++)
        {
            element = elements[i];
            if(element.className == "popup")
            {
                if(element.id == ID)
                {
                    element.style.display = "block";
                    centreOnScreen3(element);
                } else {
                    element.style.display = "none";
                }
            }
        }
    }
}

function centreOnScreen(element)
{
   var ypos = 0;
   var xpos = 0;
   if (window.pageYOffset) {
     ypos = window.pageYOffset;
     xpos = window.pageXOffset;
   }
   else {
     ypos = document.documentElement.scrollTop;
     xpos = document.documentElement.scrollLeft;
   }
   
   var frameWidth;
   var frameHeight;
   if (self.innerWidth)
   {
        frameWidth = self.innerWidth;
        frameHeight = self.innerHeight;
   }
   else if (document.documentElement && document.documentElement.clientWidth)
   {
        frameWidth = document.documentElement.clientWidth;
        frameHeight = document.documentElement.clientHeight;
   }
   else if (document.body)
   {
        frameWidth = document.body.clientWidth;
        frameHeight = document.body.clientHeight;
   }
      
//   element.style.display = "block";
   var top = ypos + (frameHeight/2) - (element.offsetHeight/2);
   var left = xpos + (frameWidth/2) - (element.offsetWidth/2);
   element.style.top = top + "px";
   element.style.left = left + "px";
}

function centreOnScreen2 (divid)
{

    var IpopTop = parseInt((document.body.clientHeight - document.getElementById(divid).offsetHeight) / 2);
    var IpopLeft = parseInt((document.body.clientWidth - document.getElementById(divid).offsetWidth) / 2);

    var pageY;
    
    if (document.body.scrollTop)
    {
        pageY = document.body.scrollTop;
    } else {
        pageY = pageYOffset;
    }

    alert("pageY = " + pageY.toString());

    document.getElementById(divid).style.left=IpopLeft.toString() + "px;";
    document.getElementById(divid).style.top=(IpopTop + pageY).toString() + "px;";

}

function centreOnScreen3(element)
{
    var windowWidth = 800;
    var windowHeight = 600;
    var yOffset = 0;
    var popupWidth = 600;
    var popupHeight = 500;

    windowWidth = f_clientWidth();
    windowHeight = f_clientHeight();

    if (element.offsetWidth)
    {
        popupWidth = element.offsetWidth;
        popupHeight = element.offsetHeight;
    }

    yOffset = f_scrollTop();

    var popupX = parseInt((windowWidth - popupWidth) / 2);
    var popupY = parseInt((windowHeight - popupHeight) / 2) + yOffset;
    
    //subtract relative position of #mainCol 
    popupX -= 176;
    popupY -= 133;
    
    element.style.left = popupX + 'px';
    element.style.top = popupY + 'px';
//    alert('Popup width ' + popupWidth.toString() + ' height ' + popupHeight.toString() + '\nWindow width ' + windowWidth.toString() + ' height ' + windowHeight.toString() + '\nyOffset ' + yOffset.toString() + '\nPopup x ' + popupX.toString() + ' y ' + popupY.toString());
}











function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

