﻿var pageHeight;
var pageWidth;
var mykid;

function showCurtain()
{
	pageHeight = (document.height !== undefined) ? document.height : document.body.offsetHeight;
	pageWidth = (document.width !== undefined) ? document.width : document.body.offsetWidth;

	if (document.body.clientHeight > pageHeight)
	{
		pageHeight = document.body.clientHeight;
	}
	pageHeight = document.getElementById('container').offsetHeight;
	if (window.innerHeight)
	{
		pageHeight = (window.innerHeight > pageHeight ? window.innerHeight : pageHeight);
	}

	var curtain_div = document.getElementById('divCurtain');
	curtain_div.style.height = (Math.ceil(pageHeight)) + "px";
	curtain_div.style.width = Math.ceil(pageWidth) + "px";
	curtain_div.style.display = "block";
}

function showPopup(name)
{
	var scrollOffset = document.all ? ((document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body).scrollTop : pageYOffset;

	mykid = document.getElementById(name);
	mykid.style.position = "absolute";
	mykid.style.top = (200 + scrollOffset) + "px";
	mykid.style.left = (Math.ceil(pageWidth)/2 - parseInt(mykid.style.width)/2) + "px";
	mykid.style.zIndex = "1000";
	mykid.style.display = "block";
}

function hideCurtain()
{
	document.getElementById('divCurtain').style.display = "none";
	if (mykid)
	{
		mykid.style.display = "none";
	}
}

function showUploadDiv(childDivName)
{
	showCurtain();
	showPopup(childDivName);
}
function showUploadDiv(childDivName, newimagename, productname)
{
    var largeImage = document.getElementById('imgLargeProduct');
    largeImage.src = "/images/wines/" + newimagename.toString() + ".png";
    
    var newimage = new Image();
    newimage.src = "/images/wines/" + newimagename.toString() + ".png";
/*    newimage.onload=function() {
        if(newimage.width <= 500){
            largeImage.height = newimage.height; 
            largeImage.width = newimage.width;
        }
        else{
            largeImage.width = 500;
            largeImage.height = parseInt(newimage.height * (500 / newimage.width));
        };
    }*/

    largeImage.src = newimage.src;
    largeImage.alt = productname + " Label";
    var divProd = document.getElementById('divProductName');
    divProd.innerHTML = productname;
	showCurtain();
	showPopup(childDivName);
}
