/// <reference path="jquery/jquery-1.5.1.min.js" />
/// <reference path="json2.min.js" />
/// <reference path="jquery/jquery.validate.min.js" />
/// <reference path="jquery/jquery.ba-serializeobject.js" />

$(document).ready(function () {
    //init faqs
    $("a.faqQ").click(function () {
        $(this).next().slideToggle();
        return false;
    });

    InitSupportPage();
});

function InitSupportPage() {
    if ($("div.page-support").length == 0) {
        return;
    }

    $("#supportRequestLink").colorbox({ inline: true, href: "#supportRequest" });

    $("#supportRequest form").submit(function () {
        //field validation?
        //ajax call to submit

        if (!$(this).valid()) {
            return false;
        }

        var dataArray = $(this).serializeArray();
        var dataJson = JSON.stringify(dataArray);
        var dataForm = $(this).serialize();
        var dataObject = $(this).serializeObject();
        dataJson = JSON.stringify(dataObject);

        $.ajax(
            {
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: $(this).attr("action"),
                data: dataJson,
                dataType: "json",
                success: function (msg) {
                    if (window.console && window.console.log) {
                        window.console.log(msg);
                    }
                    if (msg) {
                        //$("#supportRequest").html(msg);
                        //$.colorbox.close();
                        $.colorbox({ html: msg });
                    }
                    else {
                        //show error msg with form
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    if (window.console && window.console.log) {
                        window.console.log(errorThrown);
                    }
                    $.colorbox({ html: "<p>There was an error submitting your request. Please call the support phone number.</p>" });
                }
            });

        return false;
    });

    //resource library
    $("#resources div.product a").click(function () {
        $("#resources div.productResources").hide();
        $($(this).attr("href")).show();
        return false;
    });

}
/*
function initTabs()
{
var sets = document.getElementsByTagName("ul");
for (var i = 0; i < sets.length; i++)
{
if (sets[i].className.indexOf("tabset") != -1)
{
var tabs = [];
var links = sets[i].getElementsByTagName("a");
for (var j = 0; j < links.length; j++)
{
if (links[j].className.indexOf("tab") != -1)
{
tabs.push(links[j]);
links[j].tabs = tabs;
var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));

if (c) if (links[j].parentNode.className.indexOf("active") != -1) c.style.display = "block";
else c.style.display = "none";

links[j].onclick = function ()
{
var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
if (c)
{
for (var i = 0; i < this.tabs.length; i++)
{
var tab = document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1));
if (tab)
{
tab.style.display = "none";
}
this.tabs[i].parentNode.className = this.tabs[i].parentNode.className.replace("active", "");
}
this.parentNode.className += " active";
c.style.display = "block";
return false;
}
}
}
}
}
}
}
if (window.addEventListener)
window.addEventListener("load", initTabs, false);
else if (window.attachEvent && !window.opera)
window.attachEvent("onload", initTabs);
*/
