function sel_check() {
	var selClin = getCookies("selClin");
	if (selClin == null || selClin == '') {
		alert('Вы не выбрали ни одной клиники.');
		return false;
	}
	else {
		return true;
	}
}
function switch_item(id) {
	var checkbox = document.getElementById(id);
	if (!checkbox) return false;
	if (checkbox.checked) {
		check_item(id);
	}
	else {
		uncheck_item(id);
	}
}
function check_item(id) {
	var checkbox = document.getElementById(id);
	if (!checkbox) return false;
	var numTop = document.getElementById('numTop');
	var numBottom = document.getElementById('numBottom');
	select_item(id);
	if(numTop) numTop.innerHTML++;
	if(numBottom) numBottom.innerHTML++;
}
function uncheck_item(id) {
	var checkbox = document.getElementById(id);
	var numTop = document.getElementById('numTop');
	var numBottom = document.getElementById('numBottom');
	if (!checkbox) return false;
	unselect_item(id);
	if(numTop) numTop.innerHTML--;
	if(numBottom) numBottom.innerHTML--;
}
function select_item(id){
	setCookies("selClin", id, 12, true);
}
function clear_selected() {
    for (i = 0; i < document.forms["listCl"].elements.length; i++) {
        var item = document.forms["listCl"].elements[i];
        if (item.name == "clinic") {
            item.checked = false;
        }
    }
	setCookies("selClin", "", 12);
	var numTop = document.getElementById('numTop');
	var numBottom = document.getElementById('numBottom');
	if(numTop) numTop.innerHTML='0';
	if(numBottom) numBottom.innerHTML='0';
}
function unselect_item(id){
	selClin = getCookies("selClin");
	if (selClin == null) {
		return;
	}
	selClinArr = selClin.split(" ");
	newSelClin = '';
	for (var i=0; i<selClinArr.length; i++) {
		if(newSelClin!='') newSelClin += ' ';
		if(selClinArr[i]!=id) newSelClin += selClinArr[i];
	}
	setCookies("selClin", newSelClin, 12);
}

function setOldCountSelected() {
//	return;
//	alert('sdf');
	selClin = getCookies("selClin");
	if (selClin == null || !selClin) {
		return;
	}
	selClinArr = selClin.split(" ");
	var numTop = document.getElementById('numTop');
	var numBottom = document.getElementById('numBottom');
	if(numTop) numTop.innerHTML = selClinArr.length;
	if(numBottom) numBottom.innerHTML = selClinArr.length;
	for (var i=0; i<selClinArr.length; i++) {
//		alert(selClinArr[i]);
		if(document.getElementById(selClinArr[i])) document.getElementById(selClinArr[i]).checked=true;
	}
}



function switch_all(fmname, itemname, checkbox){
    if (!checkbox) return false;
    if (checkbox.checked) {
        check_all(fmname, itemname);
    } else {
        uncheck_all(fmname, itemname);
    }
}

function check_all(fmname, itemname) {
    var numTop = document.getElementById('numTop');
    var numBottom = document.getElementById('numBottom');
    var total = num1.innerHTML;

    for (i = 0; i < document.forms[fmname].elements.length; i++) {
        var item = document.forms[fmname].elements[i];
        if (item.name == itemname && item.checked == false) {
            total++;
        }
        if (item.name == itemname || item.name == 'all') {
            item.checked = true;
        }
    }
    if(numTop) numTop.innerHTML = total;
	if(numBottom) numBottom.innerHTML = total;

    for (i = 0; i < document.forms[fmname].elements.length; i++) {
        var item = document.forms[fmname].elements[i];
        if (item.name == itemname) {
            select_item(item.id);
        }
    }
}

function uncheck_all(fmname, itemname) {
    var numTop = document.getElementById('numTop');
    var numBottom = document.getElementById('numBottom');
    var total = num1.innerHTML;

    for (i = 0; i < document.forms[fmname].elements.length; i++) {
        var item = document.forms[fmname].elements[i];
        if (item.name == itemname && item.checked == true) {
            total--;
        }
        if (item.name == itemname || item.name == 'all') {
            item.checked = false;
        }
    }
    if(numTop) numTop.innerHTML = total;
    if(numBottom) numBottom.innerHTML = total;

    for (i = 0; i < document.forms[fmname].elements.length; i++) {
        var item = document.forms[fmname].elements[i];
        if (item.name == itemname) {
            unselect_item(item.id);
        }
    }
}


function showHiddenInfo(id) {
	var lastObj = document.getElementById(nowShow);
	if(lastObj) lastObj.style.display = 'none';

	if(document.getElementById(nowShow+'_Vis')) document.getElementById(nowShow+'_Vis').style.display = 'block';
	if(document.getElementById(nowShow+'_Invis')) document.getElementById(nowShow+'_Invis').style.display = 'none';

	var nowObj = document.getElementById(id);
	if(nowObj) nowObj.style.display = 'block';

	if(document.getElementById(id+'_Vis')) document.getElementById(id+'_Vis').style.display = 'none';
	if(document.getElementById(id+'_Vis')) document.getElementById(id+'_Invis').style.display = 'block';

	nowShow = id;
}
