function open_blank(file)
{
	window.open(file, '_blank');
}

function open_window(file, width, height)
{
	var win = window.open(file, '_blank', 'width='+width+', height='+height+', resizable=no, scrollbars=yes, toolbar=no, location=no, directories=no, status=yes, menubar=no');
	win.focus();
}

function open_window2(arg, width, height, id)
{
    var win = window.open(arg+".php?id="+id, "_blank", "width="+width+", height="+height+", resizable=yes, scrollbars=yes, toolbar=no, location=no, directories=no, status=yes, menubar=no");
	win.focus();
}

function handle_choose(field)
{
    open_window("/popup/choose.php?field=" + field, 750, 500);
}

function handle_pchoose(field)
{
    window.open("pchoose.php?field=" + field, "_blank", "width=625, height=500, resizable=no, scrollbars=yes, toolbar=no, location=no, directories=no, status=yes, menubar=no");
}

function handle_uchoose(field)
{
    window.open("uchoose.php", "_blank", "width=570, height=500, resizable=no, scrollbars=yes, toolbar=no, location=no, directories=no, status=yes, menubar=no");
}

function handle_gchoose(field)
{
    window.open("gchoose.php", "_blank", "width=570, height=500, resizable=no, scrollbars=yes, toolbar=no, location=no, directories=no, status=yes, menubar=no");
}

function handle_schoose(field)
{
    open_window("/popup/schoose.php?field=" + field, 750, 500);
}

function handle_cchoose(field)
{
    window.open("cchoose.php", "_blank", "width=750, height=500, resizable=no, scrollbars=yes, toolbar=no, location=no, directories=no, status=yes, menubar=no");
}

function handle_tchoose()
{
    window.open("tchoose.php", "_blank", "width=750, height=500, resizable=no, scrollbars=yes, toolbar=no, location=no, directories=no, status=yes, menubar=no");
}

function handle_cgchoose()
{
    window.open("cgchoose.php", "_blank", "width=750, height=500, resizable=no, scrollbars=yes, toolbar=no, location=no, directories=no, status=yes, menubar=no");
}

function handle_ugmchoose(field)
{
    open_window("/popup/ugmchoose.php?field=" + field, 750, 500);
}

function handle_ugchoose(field)
{
    open_window("/popup/ugchoose.php?field=" + field, 750, 500);
}

function handle_richedit(field)
{
    window.open("../rich.php?field=" + field, "_blank", "width=800, height=500, resizable=no, scrollbars=no, toolbar=no, location=no, directories=no, status=no, menubar=no");
}

function handle_export_page(field)
{
    document.forms.main.action = 'export-page.php?field=' + field;
    window.setTimeout("document.forms.main.submit()", 100);
}

function handle_start_course(id)
{
    parent.location.href='/?id=445&cid='+id;
}

function onClickCheckboxes(checkbox) {
	var temp = checkbox.name.replace('[]', '');
	
	if(document.forms.main.elements[temp + '_' + checkbox.value]) {
		eval('document.forms.main.' + temp + '_' + checkbox.value + '.disabled = ' + (! checkbox.checked));
	}
}

function onClickRadioButtons(radioButton, extended) {
	var temp = radioButton.name.replace('[]', '');

        if(extended>0)
	    eval('document.forms.main.' + temp + '_' + extended + '.disabled = ' + (extended != radioButton.value));
}

function printpage(string_query) {
    wind=window.open("/?" + string_query + "&print=1", "_blank", "width=590, height=500, resizable=no, scrollbars=yes, toolbar=no, location=no, directories=no, status=yes, menubar=no");
    wind.focus();
    wind.onLoad=setTimeout("wind.print()",1500);
}

function iopen(src)
{
    document.getElementById("content_iframe").src="/admin/"+src+".php";
    document.getElementById("content_iframe").style.display="";
}

function getMultipleSelectValues(id)
{
    var el = document.getElementById(id);
    var selected='';

    if(el!=null)
    {
        for(i=0; i<el.options.length; i++)
        {
            if(el.options[i].selected)
            {
                selected += (selected.length > 0 ? "|" : "") + el.options[i].value;
            }
        }
    }
    return selected;
}

function getSelectValue(id)
{
	return document.getElementById(id).options[document.getElementById(id).selectedIndex].value;
}

function getIdValue(id)
{
	return document.getElementById(id).value;
}

function OpenFile( fileUrl )
{
	window.top.opener.SetUrl( fileUrl ) ;
	window.top.close() ;
	window.top.opener.focus() ;
}

function CKEditorOpenFile(funcNum,fileUrl,errorStr){
    window.top.opener.CKEDITOR.tools.callFunction( funcNum, fileUrl,errorStr);
    window.top.close() ;
    window.top.opener.focus() ;
}

function getArchive()
{
	document.forms.main.form_archive.value = document.forms.main.archive.value;
	return document.forms.main.archive.value;
}

function checkAll(field)
{
	for(i=0; i<document.forms.main.elements.length; i++)
	{
		if(document.forms.main.elements[i].name.substr(0, 7) == field)
			document.forms.main.elements[i].checked = document.forms.main.check_all.checked;
	}
}

function show_menu(id)
{
	var el=document.getElementById("level_1_"+id);
	if(el.style.display=="")
		el.style.display="none";
	else
		el.style.display="";
}

function onKeyDown(e)
{
    var keynum;
    if(window.event) // IE
    {
        keynum = e.keyCode;
    }
    else if(e.which) // Netscape/Firefox/Opera
    {
        keynum = e.which;
    }
	if(keynum==13) handle_action('search', document.forms.search.search.value);
}

var stt = 1800

function timeToLogout(){
   if(stt>0){
   stt = stt - 1;
   min  = Math.floor(stt/60);
   sec =  stt%60;
    if(sec<=0 && min<=0){
       sec = 0;
       min = 0;
      $('sestimer').update("Sesja zakończona.");
      Modalbox.show('<div class="warning"><p style="text-align:justify;padding:10px;font-size:11px">Upłyną czas sesji, co wiąże się z możliwością wylogowania z serwisu. Jeżeli to był koniec Twojej pracy, wybierz "Wyloguj", jeżeli chcesz zachować dane z formularza, wybierz "Pozostaw formularz".</p> <input type="button" class="button" value="Pozostaw formularz" onclick="Modalbox.hide()" /> lub <input type="button" class="button" value="Wyloguj" onclick="location.href=\'/?id=4&logout=1\'" /></div>',{title: this.title, width: 300});
    }
    if(sec<10) sec ='0'+sec
    $('sestimer').update(" Koniec sesji za "+min+":"+sec+" ");
    
    if(stt>=120){
      //  $('sestimer').setStyle({color:'#E8FFAF'});
    }
    if(stt<120){
        $('sestimer').setStyle({color:'#FFB900'});
    }
    if(stt<60){
        $('sestimer').setStyle({color:'#FF5A00'});
        $('sestimer').setStyle({border:'1px solid #FF5A00'});
    }
   }
}