$(function(){
	var checkBoxes = $(":checkbox");
	var products = $(".compare-tbl-column");
	
	$.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;
	  });
	};


	function resetOptions() {
		$(":checkbox").each(function() {
			this.checked = false;
		});
		$(".compare-tbl-column").fadeOut();
		$(".button").toggle();
	}
	
	function compareProds() {
		var shown = 0;
		
		for ( var i = 0; i < checkBoxes.length-1; i++) {
			if ( checkBoxes[i].checked && checkBoxes[i] != "undefined" ) 
				shown++;
		}
		
		if ( shown <= 3) {			
			for ( i = 0; i < checkBoxes.length; i++){
				if ( checkBoxes[i].checked == true ){
					$(products[i]).fadeIn();
				} else {
					$(products[i]).fadeOut();
				}
			};
			$(".button").toggle();
		}  else {
			alert("Please only select a total of three types of credit-cards");
			$(checkBoxes).each(function() {
				this.checked = false;
			});
		}
	};
})
