﻿// Add form validation for the site search
options.containerQuery = '#content-wrap .search-form';
options.triggerQuery = '#content-wrap .search-form .go';
options.successHandler = function(result) 
{
	var frm = $("#content-wrap .search-form");
	window.location.href = frm.attr("action") + "?q=" + $('#help-site-search', frm).val();
};
new $.validation.Group(options);

//faq modules

$(document).ready(function() {
	$('#content dl.faq').each(function(idx) {
		$('dt a', this).click(function(evt) {
			evt.preventDefault();

			var elm = $(this);
			var nextElm = elm.parent().next();
			if (!nextElm.hasClass('show')) {
				nextElm.addClass('show').show('fast');

				var sectionName = elm.parent().parent().find('h4 span:first').text();
				var qNum = elm.parent().parent().find('dt a').index(this) + 1;

				X.Omniture.triggerPageLoad({ prop16: "FAQ " + sectionName + " QUESTION " + qNum, prop28: "FAQS" });
			}
			else {
				nextElm.removeClass('show').hide('fast');
			}

			elm.parent().find('> a').each(function(idx) {
				if (!$(this).parent().next().hasClass('show')) {
					$(this).removeClass('selected');
				}
				else {
					$(this).addClass('selected');
				}
			});
		});

		//setup faq expand/collapse buttons
		$('.expand', this).click(function(evt) {
			evt.preventDefault();

			var sectionName = $(this).parent().parent().find('span:first').text();
			X.Omniture.triggerPageLoad({ prop16: "FAQ " + sectionName + " EXPAND ALL", prop28: "FAQS"});			
			
			var section = $(this).parent().parent().parent();
			section = ($(section).attr('class') === 'faq') ? $(section).children() : $(section).parent().children();
			$(section).each(function(idx) {
				var elm = $(this);
				if (elm.hasClass('a')) {
					elm.addClass('show');
				}
				else if ($(this).hasClass('q')) {
					elm.children().addClass('selected');
				}
			});
		});

		$('.collapse', this).click(function(evt) {
			evt.preventDefault();

			var sectionName = $(this).parent().parent().find('span:first').text();
			X.Omniture.triggerPageLoad({ prop16: "FAQ " + sectionName + " COLLAPSE ALL", prop28: "FAQS" });
			
			var section = $(this).parent().parent().parent();
			section = ($(section).attr('class') === 'faq') ? $(section).children() : $(section).parent().children();
			$(section).each(function(idx) {
				var elm = $(this);
				if (elm.hasClass('a')) {
					elm.removeClass('show');
				}
				else if (elm.hasClass('q')) {
					elm.children().removeClass('selected');
				}
			});
		});
	});
});


