$(function(){
	$("#setCheckboxesAll").click(function() { setCheckboxesAll(this); return this; });
});

////////////////////////////
// 
function template_delete_items(text) {
	if($('#check_item')<0){
		alert('empty');
		return false;
	}
	
	if (confirm(text + ' ?')) {
		$('#act').val('delete');
		document.adminForm.submit();
	}
	else
		return false;
}

function setCheckboxesAll(Obj) {
	if(Obj.checked){
		$("input:checkbox[@name^=check_item]").attr("checked", "checked");
	} else {
		$("input:checkbox[@name^=check_item]").removeAttr("checked");
	}
	return 1;
}

function check_null(value)
{
	if(parseInt(value) != 'NaN' && value != '' && value != 'undefined' && value != null)
		return 1;
	else
		return 0;
}
///////////////////////// OLD
/*
function count_form() {
	count = document.getElementsByName('opisanie');
	COUNT_FORM = count.length;
	COUNT_NAME_FORM = count.length;
	if(count.length <= 1){
		$("#drop_block").attr("disabled", "disabled");
	}
}

function set_click(obj) {
	$(obj).find(' :button').each(function(){
			if($(this).attr('id') == "add_block")
				$(this).click(function(){
					add_block(this);
				});
			
			else if($(this).attr('id') == "drop_block")
				$(this).click(function(){
					drop_block(this);
				});
		});
}

function add_block(obj) {
	$("#drop_block").attr("disabled", "");
	var new_obj = $("#opisanie").clone(true);
	COUNT_FORM++;
	COUNT_NAME_FORM++;
	$(new_obj).find(' :input:not(:button):not(:hidden)').each(function(){
		//if($(this).attr('type') != 'button'){}
		$(this).val('');
		$(this).attr('name', $(this).attr('name') + COUNT_NAME_FORM);
	});//.resetForm .clearForm .clearFields
	$(new_obj).find(' :hidden').val(COUNT_NAME_FORM);
	
	var parent_obj = $(obj).parents('#opisanie');
	var parent_obj = $(obj).parents().parents('#opisanie');
	$(new_obj).insertAfter(parent_obj);
	return 1;
}

function drop_block(obj) {
	var parent_obj = $(obj).parents("table");
	if(parent_obj){
		$("#remove_obj").remove();
		$('<div id="remove_obj" style="padding-right:11px;text-align:right"><font onclick="recovery_block()" style="color:red;text-decoration:underline; cursor:pointer;">Recovery?</a></font>').insertAfter(parent_obj);
	}
	REMOVE_OBJ = $(parent_obj).remove();
	COUNT_FORM--;
	if(COUNT_FORM == 1)
		$("#drop_block").attr("disabled", "disabled");
	return 1;
}

function recovery_block() {
	if(REMOVE_OBJ){
		var parent_obj = $("#remove_obj");
		
		set_click(REMOVE_OBJ);
		/$(REMOVE_OBJ).find(' :button').each(function(){
			if($(this).attr('id') == "add_block")
				$(this).click(function(){
					add_block(this);
				});
			
			else if($(this).attr('id') == "drop_block")
				$(this).click(function(){
					drop_block(this);
				});
		});/
		
		$(REMOVE_OBJ).insertAfter(parent_obj);
		$("#remove_obj").remove();
		COUNT_FORM++;
		if(COUNT_FORM > 1)
			$("#drop_block :disabled").attr("disabled", "");
	} else {
		$("#remove_obj").html('Error');
	}
}*/
