var lastOpened = null;
var lastOpenedSub = null;

function toggleSubItem(_id , _sub) {
    //setItems{id}
    if (_sub == 0) {
        if (lastOpened != null) {
            if (lastOpened != _id) {
                var _it = document.getElementById(lastOpened);
                _it.style.display = 'none';
                lastOpened = _id;
            }

        }
        else
        {
            lastOpened = _id;
        }
    }
    else if(_sub == 1)
    {
        //lastOpenedSub
        if (lastOpenedSub != null) {
            if (lastOpenedSub != _id) {
                var _it = document.getElementById(lastOpenedSub);
                _it.style.display = 'none';
                lastOpenedSub = _id;
            }

        }
        else
        {
            lastOpenedSub = _id;
        }
    }
    var _item = document.getElementById(_id);
    if(_item.style.display == 'none')
    {
        _item.style.display = 'inline';
    }
    else
    {
        _item.style.display = 'none';
    }
    return false;
}

var lastOpened2 = null;
var lastOpenedSub2 = null;

function toggleSubItem2(_id , _sub) {
    //setItems{id}
    if (_sub == 0) {
        if (lastOpened2 != null) {
            if (lastOpened2 != _id) {
                var _it = document.getElementById(lastOpened2);
                _it.style.display = 'none';
                lastOpened2 = _id;
            }

        }
        else
        {
            lastOpened2 = _id;
        }
    }
    else if(_sub == 1)
    {
        //lastOpenedSub
        if (lastOpenedSub2 != null) {
            if (lastOpenedSub2 != _id) {
                var _it = document.getElementById(lastOpenedSub2);
                _it.style.display = 'none';
                lastOpenedSub2 = _id;
            }

        }
        else
        {
            lastOpenedSub2 = _id;
        }
    }
    var _item = document.getElementById(_id);
    if(_item.style.display == 'none')
    {
        _item.style.display = 'inline';
    }
    else
    {
        _item.style.display = 'none';
    }
    return false;
}
//toggleSubItem2


function togglePreviewContainer() {
    var box = document.getElementById('previewBox');
    if(box.style.display=='block')
    {
        box.style.display = 'none';
    }
    else
    {
        box.style.display = 'block';
    }
    return false;
}

function showcal(obj) {
//    'yyyy/mm/dd hh:ii',this,true
    displayCalendar(obj,'yyyy-mm-dd hh:ii',obj,true);
    return false;
}

function showcalNoHour(obj) {
    displayCalendar(obj,'dd.mm.yyyy',obj,false);
    return false;
}

function changeTimes(obj,typ) {
    //alert(window.location.href);
    //alert(obj.value);
    window.location.href = typ+'/'+obj.value;
}

function clearEditor() {
    var edt = document.getElementById('previewEditor');
    if(edt)
    {
        edt.innerHTML = '';
    }
    return false;
}

function changeFields(checkBoxObj,container) {
    var _cont = document.getElementById(container);


    var _inps = _cont.getElementsByTagName("input");
    var _inpsLength = _inps.length;

    for(i=0; i<_inpsLength; i++)
    {
            _inps[i].readOnly = !checkBoxObj.checked;
            if (checkBoxObj.checked) {
                _inps[i].className = "makeNormal";
            }
            else
            {
                _inps[i].className = "makeGrey";
            }
    }

    var _lbls = _cont.getElementsByTagName("label");
    var _lblsLength = _lbls.length;
    for(i=0; i<_lblsLength; i++)
    {
        if (checkBoxObj.checked) {
           _lbls[i].className = "makeNormalLbl";
        }
        else
        {
            _lbls[i].className = "makeGreyLbl";
        }
    }

    return;
}

