$.fn.clearForm = function() {
  return this.each(function() {
 var type = this.type, tag = this.tagName.toLowerCase();
 if (tag == 'form')
   return $(':input',this).clearForm();
 if (type == 'text' || type == 'password' || tag == 'textarea')
   this.value = '';
 else if (type == 'checkbox' || type == 'radio')
   this.checked = false;
 else if (tag == 'select')
   this.selectedIndex = -1;
  });
};

$(document).ready(function(){
	$("#clear").click(function(e){
		e.preventDefault()
		$(this).parents("form").clearForm()
	})
})

$(document).ready(function() {
	$("[class^='count[']").each(function() {
		var elClass = $(this).attr('class');
		var minChars = 0;
		var maxChars = 0;
		var countControl = elClass.substring((elClass.indexOf('['))+1, elClass.lastIndexOf(']')).split(',');
		
		if(countControl.length > 1) {
			minChars = countControl[0];
			maxChars = countControl[1];
		} else {
			maxChars = countControl[0];
		}	
		
		//$(this).after('<div class="wordCount"><strong>0</strong> Words</div>');
		//if(minChars > 0) {
		//	$(this).siblings('.wordCount').addClass('error');
		//}	
		
		$(this).bind('keyup click blur focus change paste keydown keypress', function() {
			var numWords = $(this).val().length;
			if($(this).val() === '') {
				numWords = 0;
			}
				
			$(this).siblings('.wordCount').children('strong').text(200-numWords);
			
			if(numWords < minChars || (numWords > maxChars && maxChars != 0)) {
				console.log($(this).val().substr(0, 200))
				$(this).val($(this).val().substr(0, 200))
				$(this).siblings('.wordCount').children('strong').text(0);
			}
		});
	});
});


$(document).ready(function(){
	$("#pratica_1, #help_pratica, label[for=pratica_1]").click(function(e){
		$("#info_pratica").slideToggle("slow");
	})
	$("#help_entrepeneur").click(function(e){
		$("#info_entrepeneur").slideToggle("slow");
	})
	/*
	$("label[for=tipo_1]").click(function(e){
		$("#info_entrepeneur_one").slideToggle("slow");
	})
	$("label[for=tipo_2]").click(function(e){
		$("#info_entrepeneur_two").slideToggle("slow");
	})
	$("label[for=tipo_3]").click(function(e){
		$("#info_entrepeneur_three").slideToggle("slow");
	})
	*/
	$("#help_points").click(function(e){
		$("#info_points").slideToggle("slow");
	})
})