﻿//here you place the ids of every element you want.
var ids = new Array('prod_description', 'ingredients', 'directions', 'restrictions');

function switchid(id) {
    hideallids();
    showdiv(id);
}

function hideallids() {
    //loop through the array and hide each element by id
    for (var i = 0; i < ids.length; i++) {
        hidediv(ids[i]);
    }
}
function hidediv(id) {
    //safe function to hide an element with a specified id
    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'none';
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = 'none';
        }
        else { // IE 4
            document.all.id.style.display = 'none';
        }
    }
}

function showdiv(id) {
    //safe function to show an element with a specified id

    if (document.getElementById) { // DOM3 = IE5, NS6
        document.getElementById(id).style.display = 'block';
    }
    else {
        if (document.layers) { // Netscape 4
            document.id.display = 'block';
        }
        else { // IE 4
            document.all.id.style.display = 'block';
        }
    }
}

function switch2(span) {
    var option2 = ['prod_one', 'prod_two', 'prod_three', 'prod_four'];
    for (var i = 0; i < option2.length; i++) {
        if (document.getElementById(option2[i])) {
            obj = document.getElementById(option2[i]);
            obj.style.background = (option2[i] == span) ? "url(/resources/assets/product/tabs2.jpg) right bottom repeat-x" : "url(/resources/assets/product/tabs1.jpg) right bottom repeat-x";
        }
    }
}

function switch4(span) {
    var option4 = ['a-panel_1_start'];
    for (var i = 0; i < option4.length; i++) {
        if (document.getElementById(option4[i])) {
            obj = document.getElementById(option4[i]);
            obj.id = (option4[i] == span) ? "a-panel_1" : "";
        }
    }
}

$(document).ready(function () {
    $('.lowerTabs a').click(function () {
        switch_tabs($(this));
    });

    $('.ask').click(function () {
        $('.tab-content').hide();
        $('.lowerTabs a').removeClass("selected");
        $('#tabs2').show();
        $('#tab_two a').addClass("selected");
    });

    $('.reviews').click(function () {
        $('.tab-content').hide();
        $('.lowerTabs a').removeClass("selected");
        $('#tabs1').show();
        $('#tab_one a').addClass("selected");
    });

    switch_tabs($('.defaulttab'));
});

function switch_tabs(obj) {
    $('.tab-content').hide();
    $('.lowerTabs a').removeClass("selected");
    var id = obj.attr("rel");

    $('#' + id).show();
    obj.addClass("selected");
}

var BVQAisLoaded = false;
function BVcheckQALoadState() {
    if (!BVQAisLoaded) {
        var page = document.getElementById('BVQAFrame').src;
        document.getElementById('BVQAFrame').src = 'http://answers.spalook.com/bvstaging/logging?page=' + escape(page);
        document.getElementById('BVQAContainer').innerHTML = "<!-- QA retrieval timed out -->";
    }
}

function bvLoadQA() {
    var bvQAFrameSrc = '<asp:Literal ID="BVProductUrl" runat="server"/>';
    var bvQuestionIDName = 'featurequestion';

    var bvoice_user = $bv('#BVQACustomerID').text();

    var bvQuestionIDRegex = new RegExp('[?&]' + bvQuestionIDName + '=([^&#]+)');
    var bvQuestionIDMatch = bvQuestionIDRegex.exec(window.location.search);
    var bvQuestionID = bvQuestionIDMatch ? decodeURIComponent(bvQuestionIDMatch[1]) : null;

    bvQAFrameSrc = /^[0-9]+$/.test(bvQuestionID) ? bvQAFrameSrc.replace('/questionshome.htm', '/questions.htm') + '&expandQuestionID=' + bvQuestionID : bvQAFrameSrc;

    var bvPageMatch = /[?&]bvpage=([^&#]+)/.exec(window.location.search);
    var bvPage = bvPageMatch ? decodeURIComponent(bvPageMatch[1]) : null;
    var bvRegex = new RegExp('^' + window.location.protocol + '\/\/([A-Za-z0-9-.]+[.])?' + document.domain + '\/');

    $bv('#BVQAFrame').attr('src', (bvPage && bvRegex.test(bvPage)) ? bvPage.replace(/__USERID__/, bvoice_user) : bvQAFrameSrc);

    //Timeout for QA load.  Consider content unavailable if not loaded within 15 seconds   
    setTimeout("BVcheckQALoadState()", 15000);
}
