window.onload = init

function init()
{
    setRollovers()
}


/*

after the html page loads, setRollovers() scans the HTML page for any img tag 
that has the class "rollOver". When it finds one, it attaches the mouseover events.

*/

function setRollovers()
{
    imgs = document.getElementsByTagName("img")
    for (i = 0; i < imgs.length; i++)
    {
        if (/rollOver/.test(imgs[i].className))
        {
            imgs[i].parentNode.onmouseover = function() {
                roll(this, true);
            }
            imgs[i].parentNode.onmouseout = function() {
                roll(this, false);
            }
            imgs[i].parentNode.onfocus = function() {
                roll(this, true);
            }
            imgs[i].parentNode.onblur = function() {
                roll(this, false);
            }
        }
    }
}


/*

roll() handles the image rollovers.

*/

function roll(node, status)
{
    nodeImg = node.firstChild
    srcImage = nodeImg.getAttribute("src")

    if (status)
    {
        navState = srcImage.substring(srcImage.length - 7, srcImage.length - 4)
        if (navState == "off")
        {
            srcImage = srcImage.substring(0, srcImage.length - 7)
            srcImage = srcImage + "on.gif"
            nodeImg.setAttribute("src", srcImage)
        }
    }
    else
    {
        navState = srcImage.substring(srcImage.length - 7, srcImage.length - 4)
        if ((navState != "sel") && (navState != "off"))
        {
            srcImage = srcImage.substring(0, srcImage.length - 6)
            srcImage = srcImage + "off.gif"
            nodeImg.setAttribute("src", srcImage)
        }
    }
}


/*

swatchClick() handles the actions when a swatch is clicked in the 
Purchase Fabrics and Create a Sample Kit pages.

Note 'swatchRoot' variabe below -- this identifies the folder where
the larger swatches can be found.

*/

function swatchClick(node, name, image, sale, description)
{
    document.getElementById("swatchName").innerHTML = name
    document.getElementById("swatchSale").innerHTML = sale

    if (document.getElementById("getSampleKit"))
    {
        document.getElementById("getSampleKit").style.display = "block"
    }

    if (document.getElementById("swatchDescriptionDefault"))
    {
        document.getElementById("swatchDescriptionDefault").style.display = "none"
    }

    for (var i=0;el=document.getElementById("swatchDescription"+i);i++) {
        el.style.display = "none";
    }
    document.getElementById("swatchDescription" + description).style.display = "block"

    document.getElementById("swatchName").style.display = "block"
    document.getElementById("swatchInfo").style.display = "block"

    if (document.getElementById("addedToCart"))
    {
        document.getElementById("addedToCart").style.display = "none"
    }

    imgs = document.getElementById("swatchTable").getElementsByTagName("img")
    for (i = 0; i < imgs.length; i++)
    {
        src = imgs[i].getAttribute("src")
        if (!/icon/.test(src))
        {
            imgs[i].parentNode.className = ""
        }
    }

    node.className = "selected"

    // swatchRoot = "images/swatches/medium/ swatchRoot + "
    document.getElementById("swatchClicked").setAttribute("src", image)
}


/*

roll() handles the image rollovers.

*/

function setStyleName(styleName)
{
    document.getElementById("thumbName").innerHTML = styleName
}

/*

launches pop-up window for Enlarge Image, More Images, and Swatches

*/

function popUp(file)
{
/* 2008-05-01 DMD@AKT - handle larger images */
//    width = 585
//    height = 515
/* 2008-10-21 DMD@AKT - handle larger images */
//    width = 585
//    height = 685
    width = 785
//    height = 695
    height = 830

    x = (screen.availWidth - width) / 2
    y = ((screen.availHeight - height) / 2 ) - 40
    attribs = "width=" + width + ",height=" + height + ",left=" + x + ",top=" + y + ",scrollbars"
    win = window.open(file, "popWindow", attribs)
}

function popUpL(file)
{
    width = 790
    height = 590

    x = (screen.availWidth - width) / 2
    y = ((screen.availHeight - height) / 2 ) - 40
    attribs = "width=" + width + ",height=" + height + ",left=" + x + ",top=" + y + ",scrollbars"
    win = window.open(file, "popWindow", attribs)
}
/*

image swap routine for consumer landing page

*/

function homeSwap(node, which)
{
    if (which > 0)
    {
        roll(node, true)
    }
    else
    {
        roll(node, false)
    }

    srcImg = document.getElementById("homeImg").getAttribute("src")
    jpg = srcImg.lastIndexOf(".jpg")
    srcImg = srcImg.substring(0, jpg - 7)
    srcImg = srcImg + "option" + which + ".jpg"
    document.getElementById("homeImg").setAttribute("src", srcImg)
}


/*

show distributor detail information on click

*/

function showDistributor(file)
{
    node = document.getElementById("detailInfoFrame")
    node.setAttribute("src", file)
}


/*

move ads on rollover

*/

function movePic()
{
    if (direction == 0)
    {
        return
    }

    oldPos = parseInt(document.getElementById("thumbs").style.left)

    if ((oldPos == 0) && (direction > 0))
    {
        return
    }

    if ((oldPos == -4380) && (direction < 0))
    {
        return
    }

    oldPos = oldPos + direction
    document.getElementById("thumbs").style.left = oldPos + "px"
}

function moveAdsLeft(status)
{
    if (status)
    {
        direction = increment
    }
    else
    {
        direction = 0
    }
}

function moveAdsRight(status)
{
    if (status)
    {
        direction = -increment
    }
    else
    {
        direction = 0
    }
}


/*

launches pop-up window for About Crypton Ads

*/

var currentAd = ""
var bigWidth = 0

function popAd(which, node, where)
{
    imgNode = node.firstChild
    imgWidth = imgNode.getAttribute("width")

    currentAd = which
    width = Math.floor((381 / 171) * imgWidth) + 60

    height = 560
    file = "08_05a_about_ads_detail.htm"

    x = (screen.availWidth - width) / 2
    y = ((screen.availHeight - height) / 2 ) - 40
    attribs = "width=" + width + ",height=" + height + ",left=" + x + ",top=" + y + ",scrollbars=no"
    win = window.open(where, "popWindow", attribs)
}


/*

launches pop-up window for Glosary

*/

function glossary()
{
    width = 620
    height = 560
    //file = "07_00_trade_glossary.htm"
    file = "/crypton/glossary.do"

    x = (screen.availWidth - width) / 2
    y = ((screen.availHeight - height) / 2 ) - 40
    attribs = "width=" + width + ",height=" + height + ",left=" + x + ",top=" + y + ",scrollbars"
    win = window.open(file, "popWindow", attribs)
}


function changeInfo() {
    var flag = document.getElementById("ckeck_flag").getElementsByTagName("input")[0].checked? true : false;
    var el = document.getElementById("tableToChange").getElementsByTagName("input");
    var mt = document.getElementById("mainTable").getElementsByTagName("input");
    for (var i = 0; i < el.length; i++) {
        if (el[i].type == 'text') {
            if (flag) {
                el[i].value = mt[i].value;
            }
            el[i].disabled = flag;
        }
    }
    var el = document.getElementById("tableToChange").getElementsByTagName("select");
    var mt = document.getElementById("mainTable").getElementsByTagName("select");
    el[0].disabled = flag;
    if (flag) {
        el[0].value = mt[0].value;
    }        
}

function petBeds(where)
{
    width = 780
    height = 650
    file = where + "/pet_bed_flash_designer.do"

    x = (screen.availWidth - width) / 2
    y = ((screen.availHeight - height) / 2 ) - 20
    attribs = "width=" + width + ",height=" + height + ",left=" + x + ",top=" + y + ",scrollbars=no"
    win = window.open(file, "popWindow", attribs)
}



