﻿var runredraw = false;
function showTab(theID) {

    //get the content
    var theTab = document.getElementById("tab" + theID);
    var tabContent = document.getElementById("tabContent");
    tabContent.innerHTML = theTab.innerHTML;

    //switch the tab selected style
    
    //var theLI = document.getElementById("li" + theID);
    var theLIs = document.getElementById("tabList").getElementsByTagName("LI");
    for (var i = 0, l = theLIs.length; i < l; i++) {
        var li = theLIs[i];  //theUL.childNodes[i];
        li.className = "";
        li.getElementsByTagName("a")[0].className = "";
        if (li.id.indexOf(theID) > 0) {
            li.className = "selected";
            li.getElementsByTagName("a")[0].className = "selected";
            //alert(li.innerHTML);
        }
    }

    if (!runredraw) { runredraw = true; }
    else if (ge==undefined) {}
    else {
        sIFR.replace(ge, {
            selector: 'h2.phototip', css: [
                '.sIFR-root { color:#000000; font-weight: normal; font-size: 24px;}',
                'a { text-decoration: none; }',
                'a:link { color: #3f3f3f; }',
                'a:hover { color: #00aeef; }'
                ], wmode: 'transparent'
        });
    }
}
function showTabCN(theID) {

    //get the content
    var theTab = document.getElementById("tab" + theID);
    var tabContent = document.getElementById("tabContent");
    tabContent.innerHTML = theTab.innerHTML;

    //switch the tab selected style

    //var theLI = document.getElementById("li" + theID);
    var theLIs = document.getElementById("tabList").getElementsByTagName("LI");
    for (var i = 0, l = theLIs.length; i < l; i++) {
        var li = theLIs[i];  //theUL.childNodes[i];
        li.className = "";
        li.getElementsByTagName("a")[0].className = "";
        if (li.id.indexOf(theID) > 0) {
            li.className = "selected";
            li.getElementsByTagName("a")[0].className = "selected";
            //alert(li.innerHTML);
        }
    }
}
function toggle(theID) {
    var theTag = document.getElementById(theID);
    theTag.style.display = (theTag.style.display == 'block') ? "none" : "block";
}
function toggleFAQ(theID) {
    var theTag = document.getElementById(theID);
    $(theTag).stop(true, true).animate({ opacity: "show" }, "slow");
    theTag.style.display = (theTag.style.display == 'block') ? "none" : "block";
}

function showCameraLanding(theItem, theID) {
    var theDiv = document.getElementById(theID);
    var dTop = _getTopPos(theItem) - 363;
    var dLeft = _getLeftPos(theItem);  //+ 45;

    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
        var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
        dLeft += 10;
        if (ieversion == 8) { dTop -= 175; }
      }
    else if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)) { dLeft -= 200; }
    else {dTop -= 162;dLeft += 10; }

    //if (dLeft > 590) dLeft -= 620;
    //else if (dLeft > 295) dLeft -= 160;
    //else if (dLeft < 295) dLeft += 295;
    theDiv.style.top  = dTop + "px";
    theDiv.style.left = dLeft + "px";

    theDiv.style.display = 'block';
    //$(theDiv).stop(true, true).show();     
    //if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { $(theDiv).stop(true, true).show(); }
    //else { $(theDiv).stop(true, true).animate({ opacity: "show", top: dTop }, "fast"); }
     //slideDown("normal")  show();

    //sifr replacements
    if (navigator.appVersion.indexOf("Mac") == -1)
    {    
        sIFR.replace(ge, {
            selector: 'h1', css: [
                '.sIFR-root { color:#000000; font-weight:bold; font-size:22px; }'
                ], wmode: 'transparent'
        });
        sIFR.replace(ge, {
        selector: 'h2', css: [
                '.sIFR-root { color:#000000; font-size:16px; leading:1px; }'
                ], wmode: 'transparent'
        });
    }
}
function hideCameraLanding(theID) {
    var theDiv = document.getElementById(theID);
    theDiv.style.display = 'none';
    //$(theDiv).stop(true, true).fadeOut("fast");
}


/*============================================================================
* Position functions
*============================================================================*/
function _getTopPos(inputObj) {
    var returnValue = inputObj.offsetTop;
    while ((inputObj = inputObj.offsetParent) != null) {
        if (inputObj.tagName != 'HTML') returnValue += inputObj.offsetTop;
    }
    return returnValue;
}

function _getLeftPos(inputObj) {
    var returnValue = inputObj.offsetLeft;
    while ((inputObj = inputObj.offsetParent) != null) {
        if (inputObj.tagName != 'HTML') returnValue += inputObj.offsetLeft;
    }
    return returnValue;
}

//function setSupportContent(theItem, theID) {

//    for (var i = 0, l = theItem.parentNode.childNodes.length; i < l; i++) {
//        var li = theItem.parentNode.childNodes[i];
//        li.className = "";
//    }
//    theItem.className = "selected";

//    var divDLContent = document.getElementById("divDownloads");
//    var theDLContent = document.getElementById("divDownloadsContent" + theID);
//    divDLContent.innerHTML = theDLContent.innerHTML;

//    var divImage = document.getElementById("divModel");
//    var theImage = document.getElementById("divImageContent" + theID);
//    divImage.innerHTML = theImage.innerHTML;
//    
//}
function addToCart(theID)
{
    var pid = document.getElementById('optColor' + theID);
    //alert(pid.value);
    window.location = "/store/cart.aspx?product=" + pid.value;
}

function checkEnter(e){ //e is event object passed from function invocation

    var characterCode; //literal character code will be stored in this variable
    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e;
        characterCode = e.which;  //character code is contained in NN4's which property
    }
    else
    {
        e = event;
        characterCode = e.keyCode;  //character code is contained in IE's keyCode property
    }

    return (characterCode == 13); //if generated character code is equal to ascii 13 (if enter key)
}
