﻿$('document').ready(function() {
	wizardEvents();

	$(".wizard-question").hide();
	$("#wizard_question_1").show();
	$(".error").hide();
});

function wizardEvents() {
	// Radio List
	$('.radio-list li input:checked').parents('li').addClass('radioSelected');
	$('.radio-list li').live('mouseover', function() {
		$(this).addClass('radioActive');
	}).live('mouseout', function() {
		$(this).removeClass('radioActive');
	}).live('click', function() {
		$('.radio-list li').removeClass('radioSelected');
		$(this).addClass('radioSelected');
		$(this).find('input').attr('checked', true);
		$.uniform.update();
	});

	// Checkbox List
	$('.checkbox-list li').live('mouseover', function() {
		$(this).addClass('checkboxActive');
	}).live('mouseout', function() {
		$(this).removeClass('checkboxActive');
	});
//	$('.checkbox-list li input').live('click', function() {
//		$(this).toggleClass('checkboxSelected');
//		if ($(this).prop('checked') == false)
//			$(this).prop('checked', true);
//		else
//			$(this).prop('checked', false);
//		$.uniform.update();
//    });
	$('.checkbox-list li .answer-text').live('click', function () {
	    $(this).siblings('div').find('input').toggleClass('checkboxSelected');
	    if ($(this).siblings('div').find('input').attr('checked') == 'checked')
	        $(this).siblings('div').find('input').removeAttr('checked');
	    else
	        $(this).siblings('div').find('input').attr('checked', 'checked');
	    $.uniform.update();
	});

	// If "Start Over" is clicked, confirm action from user.
	$('.cancel-link').click(function(e) {
	    pageTracker._trackEvent('Bat Coach', 'Start Over'); // GA Event Tracker
	
		if (confirm('Are you sure you want to start over?')) {
			window.location = $(this).attr('href');
		}
		e.preventDefault();
	});
}

function showQuestion(q) {
    $('.wizard-question:visible').hide();
	$('#wizard_question_' + q).show();
}

function changeQuestion(currentQuestion, nextQuestion) {
    $(currentQuestion).hide();
	$(nextQuestion).show();
}

function getNextQuestion(controlName) {
	var temp = $('[name=' + controlName + ']:checked').attr('next');
	if (temp == undefined) {
		alert(temp);
		temp = $('[name=' + controlName + '_option]:selected').attr('next');
		alert(temp);
	}

	return (temp);
}

function Validate(controlName, currentQuestion, gaText) {
	$(currentQuestion + " > .error").hide();

	var temp = $('[name="' + controlName + '"]:checked').attr('next');
	var tempText = '';
	$('[name=' + controlName + ']:checked').each(
	    function() {
	        if (tempText != '') {
	            tempText = tempText + ',';
	        }
	        tempText = tempText + $(this).parent().parent().siblings('.answer-text').html();
	    }
	    );
	
	if (temp == undefined) {
	    temp = $('[name=' + controlName + '_option]:selected').attr('next');
	    tempText = $('[name=' + controlName + '_option]:selected').html();
	}

	if (temp == undefined) {
		$(currentQuestion + " > .error").show();
		return false;
    }
    
    try {
        eval('load_wizard_question_' + temp + '()');
    }
    catch (er) {
    }

	$(currentQuestion).hide();
	$('#wizard_question_' + temp).show();

	if (gaText) {
	    pageTracker._trackEvent('Bat Coach', gaText + tempText); // GA Event Tracker
	}

	return false;
}
