// A fix for IE button bug:
// IE sends all the buttons in the form instead of the one that
// was clicked. It also sends the button's text instead of value.
// So in each form we add a hidden input named 'actionjs'.
// Each button calls this function on click, and the server
// checks the 'actionjs' value. If it isn't there it means that
// there's no javascript, so it looks at the 'action' value instead.
function buttonClick(value) {
  document.getElementById('actionjs').value = value;
}

// Show the user a confirmation message, and then call buttonClick.
// Example: onclick="return confirmClick('Are you sure?', 'delete')"
function confirmClick(msg, value) {
  if (confirm(msg)) {
    buttonClick(value);
    return true;
  }
  return false;
}

$(document).ready(function() {
  // Change class of focused input fields; focus on the first one
  $(":input[type!=radio][type!=checkbox][type!=image][type!=hidden][type!=submit][type!=button][id!=search]")
    .bind("focus", function() {
        $(this).addClass("focused_field");
    })
    .bind("blur", function() {
        $(this).removeClass("focused_field");
    })
	.eq(0).each(function() {
		this.focus();
	});
  // Zebra-stripe tables
  $("table.zebra tr:even").addClass("even");
  // Animate messages div
  $("#messages").hide();
  $("#messages").slideDown("slow");
  
  ezquant_faq.init();
  ezquant_search.init();
});

ezquant_faq = {
	init : function() {
		$('.answer').hide('fast');
		$('.question').click(function() {ezquant_faq.toggle(this) });
	},
	
	toggle : function(elt) {
		if ($(elt).is('.active'))
			$(elt).next().next().fadeOut('fast');
		else 
			$(elt).next().next().fadeIn('fast');
		$(elt).toggleClass('active');
	}
}


ezquant_search = {
	init : function() {
		$('.search_title').toggleClass('active');
		$('.search_icon').toggleClass('expand');
		$('.search_title').click(function() {ezquant_search.toggle(this) });
	},
	
	toggle : function(elt) {
		if ($(elt).is('.active')) {
			$(elt).next().slideUp("fast");
			$(elt).find('.search_icon').removeClass('expand');
			$(elt).find('.search_icon').addClass('collapse');
		}
		else {
			$(elt).next().slideDown("fast");
			$(elt).find('.search_icon').removeClass('collapse');
			$(elt).find('.search_icon').addClass('expand');
		}
		$(elt).toggleClass('active');
	}
}

