﻿/// <reference path="jquery-1.3.2-vsdoc.js"/> 
/*********************
Secret JS V1
*********************/
var productContainer;
$(document).ready(function() {
    try {
        productTabs(); // Load Product Tabs
         $('.reveal-list').find('dt').addClass('closed');

        $('.reveal-list').find('dd').addClass('closed');

        $('.reveal-list').find('dt:first').removeClass('closed');

        $('.reveal-list').find('dd:first').removeClass('closed');

        $('.reveal-list dt').click( function() {

        $('.reveal-list').find('dt').addClass('closed');

        $('.reveal-list').find('dd').addClass('closed');

//$(this).removeClass('closed');

//$(this).next('dd').toggleClass('closed').siblings("dd").toggleClass('closed');

        $(this).toggleClass('closed').next('dd').toggleClass('closed');
        });
    }


    catch (e) {
        alert("productTabs() error: " + e);
    }
});

//Accenture EXPOTV Video - Added new tab case watchreviews
function productTabs() {
    try {
        $(".tab_content").hide(); //Hide all content        
        switch (InitialTabSelected) {
            case "ratings":
                $("#tabInfo ul a#tab_ratings").parent().addClass("active").show(); //Activate ratings tab
                $(".tab_content#ratings").show(); //Show ratings tab content
                break;
            case "watchreviews":
                $("#tabInfo ul a#tab_watchreviews").parent().addClass("active").show(); //Activate ratings tab
                $(".tab_content#watchreviews").show(); //Show watchreviews tab content//Accenture
                break;
            case "FAQs":
                $("#tabInfo ul a#tab_faq").parent().addClass("active").show(); //Activate ratings tab
                $(".tab_content#FAQs").show(); //Show ratings tab content
                break;
            case "extras":
                $("#tabInfo ul a#tab_extras").parent().addClass("active").show(); //Activate ratings tab
                $(".tab_content#extras").show(); //Show ratings tab content
                break;
            case "specials":
                $("#tabInfo ul a#tab_specials").parent().addClass("active").show(); //Activate ratings tab
                $(".tab_content#specials").show(); //Show ratings tab content
                break;
            case "talking":
                $("#tabInfo ul a#tab_talking").parent().addClass("active").show(); //Activate ratings tab
                $(".tab_content#talking").show(); //Show ratings tab content
                break;

        }

        //On Click Event
        $("#tabInfo ul a").click(function() {


            $("#tabInfo ul li").removeClass("active"); //Remove any "active" class
            $(this).parent().addClass("active"); //Add "active" class to selected tab
            $(".tab_content").hide(); //Hide all tab content

            var activeTab = $(this).attr("href");
             //Find the href attribute value to identify the active tab + content
            activeTab = activeTab.split('=');
            activeTab = '#' + activeTab[1];           

            $(activeTab).fadeIn(); //Fade in the active ID content
            if (activeTab != "#ratings") {                
                getTabContent(activeTab, SubCatId, SubCatUniquePageName, SubCatName);
            }

            return false;
        });

    }
    catch (e) {
        alert("productTabs() error: " + e);
    }
}

    function FAQs(reveallist) {
    if (!reveallist.length) {
        return;
    }

    $(reveallist).children('dt:gt(0),dd:gt(0)', 'dl').addClass('closed');
    $(reveallist).children('dt').click(function() {
        $(reveallist + ' dt').addClass('closed');
        $(reveallist + ' dd').addClass('closed');
        $(this).toggleClass('closed').next('dd').toggleClass('closed');
    });
    }

//Accenture EXPOTV Video - Added watchreviews case
function getTabContent(tabContentId, productSubCategoryID, productSubCategoryUniquePageName, productSubCategoryName) {
    switch (tabContentId) {
        case "#extras":
            //CallPageMethod("GetExtrasTabContentByProductSubCategoryID", successExtrasTab, fail, "productSubCategoryID", productSubCategoryID);
            CallPageMethod("GetExtrasTabContentHTMLByProductSubCategoryID", successExtrasTabHtml, fail, "productSubCategoryID", productSubCategoryID, "forCodebehind", false);
            break;
        case "#ratings":
            CallPageMethod("GetRatingsTabContentHTMLByProductSubCategoryUniqueName", successRatingsTabHtml, fail, "productSubCategoryUniqueName", productSubCategoryUniquePageName, "pageNumber", 1, "forCodebehind", false);
            break;
        case "#watchreviews":
            CallPageMethod("GetVideoReviewsTabContentHTMLByProductSubCategoryUniqueName", successWatchReviewsTabHtml, fail, "productSubCategoryUniqueName", productSubCategoryUniquePageName, "pageNumber", 1, "forCodebehind", false);
            break;
        case "#specials":
            //CallPageMethod("GetSpecialOffersTabContentByProductSubCategoryID", successSpecialsTab, fail, "productSubCategoryID", productSubCategoryID);
            CallPageMethod("GetSpecialOffersTabContentHTMLByProductSubCategoryID", successSpecialsTabHtml, fail, "productSubCategoryID", productSubCategoryID, "forCodebehind", false);
            break;
        case "#FAQs":
            //CallPageMethod("GetFAQsTabContentByProductSubCategoryID", successFAQsTab, fail, "productSubCategoryID", productSubCategoryID);
             CallPageMethod("GetFAQsTabContentHTMLByProductSubCategoryID", successFAQsTabHtml, fail, "productSubCategoryID", productSubCategoryID, "forCodebehind", false);
         
           // GetFAQ();
            break;
        case "#talking":
            CallPageMethod("GetBlogsTabContentHTMLByProductSubCategoryName", successBlogsTabHtml, fail, "productSubCategoryName", productSubCategoryName, "forCodebehind", false);
            break;
        default:
            break;
    }
}

function ReportInappropriateReview(reviewId) {    
    CallPageMethod("ReportInappropriateReview", successReportInappropriateReview, fail, "reviewId", reviewId);
    
}

function successReportInappropriateReview(response) {
}

function ReportInappropriateVideoReview(reviewId) {
    CallPageMethod("ReportInappropriateVideoReview", successReportInappropriateVideoReview, fail, "reviewId", reviewId);
}

function successReportInappropriateVideoReview(response) {  
}


function CallPageMethod(methodName, onSuccess, onFail) {
    var args = '';
    var l = arguments.length;
    if (l > 3) {
        for (var i = 3; i < l - 1; i += 2) {
            if (args.length != 0) args += ',';
            args += '"' + arguments[i] + '":"' + arguments[i + 1] + '"';
        }
    }
    var loc = "/WebUtils/AjaxPageMethods.aspx";
    $.ajax({
        type: "POST",
        url: loc + "/" + methodName,
        data: "{" + args + "}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: onSuccess,
        fail: onFail
    });
}

function successRatingsTabHtml(response) {
    var reviews = eval('(' + response.d + ')');
    $("#productReviewsTabArea").html(reviews.htmlText);
}

//Accenture EXPOTV Video - 
function successWatchReviewsTabHtml(response) {
    var reviews = eval('(' + response.d + ')');
    $("#productVideoReviewsTabArea").html(reviews.htmlText);
}

function successTotalWatchReviews(response) {
    var reviews = eval('(' + response.d + ')');
    $("#productVideoReviewsTabArea").html(reviews.htmlText);
}


function successExtrasTabHtml(response) {
    var extras = eval('(' + response.d + ')');
    $("#extras").html(extras.htmlText);
}

function successFAQsTabHtml(response) {

    var faqs = eval('(' + response.d + ')');
    $("#FAQs dl").html(faqs.htmlText);

    try {
        FAQs("dl.reveal-list"); // Load FAQ Reveal List
    }
    catch (e) {
        //swallow
        alert("FAQs('dl.reveal-list') error: " + e);
    }
}

function successSpecialsTabHtml(response) {

    var specials = eval('(' + response.d + ')');
    $("#specials").html(specials.htmlText);
}

function successBlogsTabHtml(response) {

    var blogs = eval('(' + response.d + ')');
    $("#talking").html(blogs.htmlText);
}



function fail(response) {
    alert("an error occurred.");
}

function GetRatingsPage(pageNumber, productSubCategoryUniqueName) {
    CallPageMethod("GetRatingsTabContentHTMLByProductSubCategoryUniqueName", successRatingsTabHtml, fail, "productSubCategoryUniqueName", productSubCategoryUniqueName, "pageNumber", pageNumber, "forCodebehind", false);
}

//Accenture EXPOTV Video -
function GetWatchReviewsPage(pageNumber, productSubCategoryUniqueName) {

    CallPageMethod("GetVideoReviewsTabContentHTMLByProductSubCategoryUniqueName", successWatchReviewsTabHtml, fail, "productSubCategoryUniqueName", productSubCategoryUniqueName, "pageNumber", pageNumber, "forCodebehind", false);
    
}

$(document).ready(function() {


    if ($("#tabInfo ul li.active")) {//Remove any "active" class
       // $(this).parent().addClass("active"); //Add "active" class to selected tab
        $(".tab_content").hide(); //Hide all tab content

        var activeTab = $("#tabInfo ul li.active a").attr("href"); //Find the href attribute value to identify the active tab + content
        activeTab = activeTab.split('=');
      
        activeTab = '#' + activeTab[1];
       
        $(activeTab).fadeIn(); //Fade in the active ID content
        if (activeTab != "#ratings") {
          
            getTabContent(activeTab, SubCatId, SubCatUniquePageName, SubCatName);
        }

        return false;
    }
});
        
