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 loadFirstSub(elName,tp) {
    //toggleSubItem(elName,tp);
    try {
        var elObj = document.getElementById(elName);
        var childs = elObj.getElementsByTagName('ul');
        var lichilds = childs[0].getElementsByTagName('li');
        var achilds = lichilds[0].getElementsByTagName('a');
        window.location.href = achilds[0].getAttribute('href');


    } catch (e)
    {
         opera.postError(e);
    }
    return false;
}

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 clearBox(boxId) {
   var selBox = document.getElementById(boxId);
   var options=selBox.getElementsByTagName("option");
   var i;
   for (i=options.length-1; i>=0; i--)
   {
      selBox.removeChild(options[i]);
   }
   return false;
}

function createOptEl(boxSelId,vName,vVal) {
   var bxObj = document.getElementById(boxSelId);
   var optEl = document.createElement('option');
   var optElText = document.createTextNode(vName);
   optEl.appendChild(optElText);
   optEl.setAttribute('value',vVal);
   bxObj.appendChild(optEl);
   return false;
}


function loadComboMiasta(comboBoxId,cityId) {
    if(cityId== -1)
    {
        return false;
    }
    try {
        clearBox(comboBoxId);
        var opts = myArCity[cityId].length;
        for(i= 0; i<opts; i++)
        {
            createOptEl(comboBoxId,myArCity[cityId][i][1],myArCity[cityId][i][2]);
        }
    } catch (e) {}
    return false;
}

function getMiastoInfo(info) {
    try {
        if(info!=-1)
        {
            window.location.href = info;
        }
    } catch (e) {

    }

    return false;
}
