/*
 * This file holds general javascript for KCFit.Net
 */
 
function initPlaceholder(){
	$("input.text[placeholder!='']").each(function(){
		if ($(this).val() == "")
			$(this).val($(this).attr("placeholder")).addClass("placeholder");
			
		$(this).bind("focus",function(){
			if ($(this).val() == $(this).attr("placeholder")){
				$(this).val("").removeClass("placeholder");
			}
		});
		$(this).bind("blur",function(){
			if ($(this).val() == ""){
				$(this).val($(this).attr("placeholder")).addClass("placeholder");
			}
		});
	});
};

function initFilter(tableId){
	$("#filter-list a").bind("click",function(){
		$(this).toggleClass("open").blur();
		$("#filters").slideToggle();
		return false;	
	});
	
	//Set total number of providers
	$("#total").text($("#" + tableId + " tbody tr").length);
	//Set total shown
	$("#totalShown").text($("#" + tableId + " tbody tr").not(".hide").length);
};

function checkEmptySet(tableId){
	//Set visibility of message stating if no events were found
	if($("#" + tableId + " tbody tr").not(".hide").length == 0)
		$("#" + tableId + " tfoot").removeClass("hide");
	else
		$("#" + tableId + " tfoot").addClass("hide");
};

function filterTable(controlid, item, column, isSpan){
	if ($("#" + controlid).val() != ""){
		if (isSpan){
			$("#" + item + "-list tbody tr td:nth-child(" + column + ") span").not(":contains(" + $("#" + controlid).val() + ")").each(function(){
				$(this).parent().parent().addClass("hide");
			});
		} else{
			$("#" + item + "-list tbody tr td:nth-child(" + column + ")").not(":contains(" + $("#" + controlid).val() + ")").each(function(){
				$(this).parent().addClass("hide");
			});
		}
	}
};

function initStepTabs(){
	$("#amount").click(function(){
		$(this).addClass('selected').next().removeClass('selected').next();
		$("#add-amount").slideDown();
		$("#add-duration").slideUp();
		this.blur();
		return false;	
	});
	$("#duration").click(function(){
		$(this).addClass('selected').prev().removeClass('selected');
		$("#add-duration").slideDown();
		$("#add-amount").slideUp();
		this.blur();
		return false;	
	});
}

$(document).ready(function(){
	initPlaceholder();
});
