function show(what, where, highres) {
    var d = document.getElementById(where);
    var alt = '';
    var html ;
    var popImage = '' ;
    var zoomImage = '' ;
    if (typeof what == "object" && what.tagName.toLowerCase() == 'img') {
        alt = what.alt;
        what = what.src;
        if ('' != highres) {
                popImage = ' onClick="popImage(\'' + highres + '\',\'\')" style="cursor:pointer ;" title="Click Zoom" ' ;
                zoomImage = '<img src="/img/zoom.png" class="zoomImg" alt="Zoom" ' + popImage + ' />' ; 
            }
        html = zoomImage + '<img src="' + what + '" alt="' + alt + '"' + popImage + ' />';
    } else {
        html = what;
    }
    d.innerHTML = html;
    return true;
}

function showArticle(title, description, material, price) {
    show(title, 'productTitle', '');
    show(description, "productDescription", '');
    show(material, 'materialSpec', '');
    show(price, 'productPrice', '');
}

function popImage(imageURL, imageTitle)
// Creates a popup containing one image and then resizing the window to fit the image
{
    // check if img URL reference is actually an image object 
    if (typeof imageURL == "object" && imageURL.tagName.toLowerCase() == 'img') {
        imageURL = imageURL.src;
    }
    var PositionX = 100;
    var PositionY = 100;
    var defaultWidth = 800;
    var defaultHeight = 600;
    var AutoClose = true;
    var isNN , isIE ;
    if (parseInt(navigator.appVersion.charAt(0)) >= 4) {
        isNN = (navigator.appName == "Netscape") ? 1 : 0;
        isIE = (navigator.appName.indexOf("Microsoft") != -1) ? 1 : 0;
    }
    var optNN = 'resizable=1,scrollbars=yes,width=' + defaultWidth + ',height=' + defaultHeight + ',left=' + PositionX + ',top=' + PositionY;
    var optIE = 'resizable=1,scrollbars=yes,width=800,height=600,left=' + PositionX + ',top=' + PositionY;

    imageTitle = null == imageTitle ? "" : imageTitle;
    var imgWin ;
    if (isNN) {
        imgWin = window.open('about:blank', '', optNN);
    }
    if (isIE) {
        imgWin = window.open('about:blank', '', optIE);
    }
    with (imgWin.document) {
        writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
        writeln('<sc' + 'ript>');
        writeln("var isNN,isIE;\n" +
                "if (parseInt(navigator.appVersion.charAt(0))>=4){\n" +
                "isNN=(navigator.appName==\"Netscape\")?1:0;\n" +
                "isIE=(navigator.appName.indexOf(\"Microsoft\")!=-1)?1:0;}\n" +
                "function reSizeToImage(){\n" +
                "if (isIE){\n" +
                "window.resizeTo(100,100);\n" +
                "aWidth = document.images[0].width > 790 ? 800 : document.images[0].width+20 ;    \n" +
                "aHight = document.images[0].height > 590 ? 600 : document.images[0].height+20 ;    \n" +
                "width=100-(document.body.clientWidth-aWidth);\n" +
                "height=100-(document.body.clientHeight-aHight);\n" +
                "window.resizeTo(width,height);}\n" +
                "if (isNN){\n" +
                "window.innerWidth=document.images[\"George\"].width > 690 ? 700 : document.images[\"George\"].width +20 ;\n" +
                "window.innerHeight=document.images[\"George\"].height > 490 ? 500 : document.images[\"George\"].height+20 ;}}\n" +
                "function doTitle(){document.title=\"\";}");
        writeln('</sc' + 'ript>');
        if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
        else writeln('</head><body bgcolor="#FFFFFF" scroll="yes" onload="reSizeToImage();doTitle();self.focus();" onblur="self.close()">');
        writeln('<img name="George" src="' + imageURL + '" style="display:block"></body></html>');
        close();
    }
}



function popPhotoBrowser(returnID) {
    var photoBrowser = window.open('listphotourls.jsp?openerId=' + returnID, '', 'width=500,height=600,resizable=yes,scrollbars=yes') ;
}

function showChart(productName,showName) {
    var chartBrowser = window.open('/measurementchart.jsp?productName=' + productName + '&showName='+showName, '', 'toolbar=0,location=0,status=0,width=500,height=200,resizable=yes') ;
    chartBrowser.moveTo(200,200);
}


function setPhotoUrl(what, where) {
    var d = document.getElementById(where);
    d.value = what;
    d = document.getElementById("icon_" + where);
    d.src = "/img/productimages/" + what;
    return true;
}


function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if (opacStart > opacEnd) {
        for (i = opacStart; i >= opacEnd; i--) {
            setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
            timer++;
        }
    } else if (opacStart < opacEnd) {
        for (i = opacStart; i <= opacEnd; i++)
        {
            setTimeout("changeOpac(" + i + ",'" + id + "')", (timer * speed));
            timer++;
        }
    }
}

function setDisplayDiv(whichLayer, what)
{
    var style2 ;
    if (document.getElementById)
    {
        // Standard
        style2 = document.getElementById(whichLayer).style;
    }
    else if (document.all)
    {
        // MSIE compatibility
        style2 = document.all[whichLayer].style;
    }
    else if (document.layers)
    {
        // NN4 compatibility
        style2 = document.layers[whichLayer].style;
    }
    style2.display = what;
}


//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
var isVisible = false ;

if (0 < document.URL.indexOf("cartDisplay")) {
    isVisible = true;
}

function toggleDiv(whichLayer, forceHide)
{
    if (!isVisible) {
        isVisible = true;
        setDisplayDiv(whichLayer, 'block');
        changeOpac(0, whichLayer);
        opacity(whichLayer, 0, 99, 1500);
    } else if (forceHide) {
        opacity(whichLayer, 99, 0, 400);
        setTimeout("setDisplayDiv('" + whichLayer + "','none')", 500);
        setTimeout("isVisible=false", 500);
    }
}

function addMeasure(artId,measureTemplateId,measureValue){
    if (null==measureTemplateId || measureTemplateId=='' || null==artId || artId=='' || null==measureValue || measureValue=='' ) {
        alert('Missing template article or value') ;
        return ;
    }
    document.location.href= "addmeasure.jsp?artId="+artId+"&measureTemplateId="+measureTemplateId+"&measureValue="+ measureValue ;
}

var spanVisible = false ;

function toggleSpan(whichSpan)
{
    if (!spanVisible) {
        spanVisible = true;
        setDisplayDiv(whichSpan, 'block');
        changeOpac(0, whichSpan);
        opacity(whichSpan, 0, 99, 1500);
    } else {
        opacity(whichSpan, 99, 0, 400);
        setTimeout("setDisplayDiv('" + whichSpan + "','none')", 500);
        setTimeout("spanVisible=false", 500);
    }
}

function roundNumber(num, dec) {
	return Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
}