
function SpecifikaForm(sForm){
	this.sForm = sForm;
	
	this.getSpecVals = function() {
		var checkedVals = this.checkedValues();
		var specType = $("input#spec_typ", this.sForm).val();
	  sfrm = this;

	  $.ajax({
			type: "POST",
			url: "specInfo.php",
			data: {stype: specType, spec: checkedVals},
			// dataType: 'html',
			dataType: 'json',
			beforeSend: function(){
			  sfrm.loading(true);
			},
			error: function(data){
			  sfrm.loading(false);
			},
			success: function(json, textStatus){
			  sfrm.loading(false);
				sfrm.showCount(json.cnt);
				sfrm.enableRelevantChecks(json.vals);
			}
 		});
	}

	this.showCount = function(val) {
		$('#specCount b').html(val);
	}

	this.checkedValues = function() {
	  var checked = [];
	  $("table.specifika tbody input.chck:checked", this.sForm).each(function(){
	      checked.push(this.id.replace('vl','')); //push all checked ids in a list
	  });
		return checked.join(',');
	}

	this.enableRelevantChecks = function(specs) {
	  $("table.specifika tbody input.chck", this.sForm).each(function(obj){
				existuje = eval('specs.' + $(this).attr('name'));
				if ($(this).attr('checked') || existuje == 1) {
          $(this).removeAttr("disabled").parent('td').parent('tr').removeClass("disabled");
				} else {
          $(this).attr("disabled", true).parent('td').parent('tr').addClass("disabled");
				};
	  });
	}

	this.loading = function(show) {
	  if (show) {
      $('#specLoading').show();
		} else {
      $('#specLoading').hide();
		}
	}
}


