//////////////////////////////
// Chmurki, zamiast title
//////////////////////////////

function DrawCloud(MouseEvent,CloudTitle,Operation,UseTimeout){
      if(Operation==1){
          PosX = MouseEvent.clientX + document.documentElement.scrollLeft - 18;
          PosY = MouseEvent.clientY + document.documentElement.scrollTop + 35;
          PosXC = PosX + 25;
          PosYC = PosY - 17;
          document.getElementById("cloud_arrow").style.left = PosXC+'px';
          document.getElementById("cloud_arrow").style.top = PosYC+'px';
          document.getElementById("cloud_text").innerHTML = CloudTitle;
          document.getElementById("cloud").style.left = PosX+'px';
          document.getElementById("cloud").style.top = PosY+'px';
          if(UseTimeout==1){
              BeginCloud = setTimeout("DisplayCloud(1)",1000);
          } else {
              DisplayCloud(1);
          }
      } else if(Operation==0){
          if(typeof(BeginCloud)!="undefined"){
              clearTimeout(BeginCloud);
          }
          DisplayCloud(0);
      }
  }
  function DisplayCloud(Display){
      if(Display==1){
          document.getElementById("cloud_arrow").style.visibility = "visible";
          document.getElementById("cloud").style.visibility = "visible";
      } else if(Display==0){
          document.getElementById("cloud_arrow").style.visibility = "hidden";
          document.getElementById("cloud").style.visibility = "hidden";
      }
  }
//////////////////////////////
// Okienko odtwarzania melodii
//////////////////////////////
function PlayMellody(PlayFile,SubNav){
    var JoinSubNav = "";
    if(SubNav==1){
        JoinSubNav = "&nav=1";
    }
    if(PlayFile=="off"){
        MW = window.open("popups/play_mellody.php?mellody=off","MellodyWindow","top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=200,height=130");
        MW.close();
    } else if(PlayFile=="random"){
        MW = window.open("popups/play_mellody.php?mellody=random","MellodyWindow","top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=200,height=130");
        MW.focus();
    } else {
        MW = window.open("popups/play_mellody.php?mellody="+PlayFile+JoinSubNav,"MellodyWindow","top=0,left=0,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=200,height=130");
        MW.focus();
    }
}
//////////////////////////////
// Okienko wyszukiwania użytkownika
//////////////////////////////
function SearchUser(where,mode,FormName){
    window.open("popups/search_user.php?where="+where+"&insert="+mode+"&form_name="+FormName,"window","left=0,top=0,width=500px,height=300px,scrollbars=1,status=0,resizable=0");
}
//////////////////////////////
// wstawianie w textarea
//////////////////////////////
function insert(what,where,FormName){
    document.forms[FormName].elements[where].value+=what+" ";
    document.forms[FormName].elements[where].focus();
/*
	var txtarea = document.forms[FormName].elements[where];
	what = ' ' + what + ' ';
	if (txtarea.createTextRange && txtarea.caretPos) {
		var caretPos = txtarea.caretPos;
		caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? caretPos.text + text + ' ' : caretPos.text + text;
		txtarea.focus();
	} else {
		txtarea.value  += what;
		txtarea.focus();
	}
*/
}
//////////////////////////////
// Sprawdzanie poprawności loginu i hasła podczas logowania
//////////////////////////////
function CheckMenuLoginForm(){
    test_menu_form_user_login=/^[0-9a-zA-Z._-]+$/;
    if((document.menu_login_form.form_user_login.value.length<3)||(document.menu_login_form.form_user_login.value.length>16)||(test_menu_form_user_login.test(document.menu_login_form.form_user_login.value)==false)){
        window.alert("Wpisz poprawny login: 3 do 16 znaków.");
        return false;
    }
    if((document.menu_login_form.form_user_password.value.length<3)||(document.menu_login_form.form_user_password.value.length>16)){
        window.alert("Wpisz poprawne hasło: 3 do 16 znaków.");
        return false;
    }
}
//////////////////////////////
// Obsługa znaczników BBCode:
//////////////////////////////
function insert_bbcode(textarea_name,FormName,OpenMark,CloseMark,FieldId){
    if(FieldId==""){
        var TxtArea = document.forms[FormName].elements[textarea_name];
    } else {
        var TxtArea = document.getElementById(FieldId);
    }

    var SelectedText = "";
	var IE = false;
	var NN = false;

    if(navigator.appName=="Microsoft Internet Explorer"){
        var IE = true;
    } else if(
        (navigator.appName=="Netscape")||
        (navigator.appName=="Opera")
    ){
        var NN = true;
    }
    if(IE){
        SelectedText = document.selection.createRange().text;
    } else if(NN){
        SelectedText = TxtArea.value.substring(TxtArea.selectionStart,TxtArea.selectionEnd);
    }
    if(!SelectedText){
        TxtArea.value += OpenMark+CloseMark+" ";
    } else {
        if(IE){
            document.selection.createRange().text = OpenMark+document.selection.createRange().text+CloseMark;
        } else if(NN){
            TxtArea.value = TxtArea.value.substring(0,TxtArea.selectionStart)+OpenMark+SelectedText+CloseMark+TxtArea.value.substring(TxtArea.selectionEnd,TxtArea.textLength);
        }
    }
    TxtArea.focus();
}
function insert_parameter_bbcode(bbcode_type,textarea_name,FormName,FieldId){
    if(FieldId==""){
        var TxtArea = document.forms[FormName].elements[textarea_name];
    } else {
        var TxtArea = document.getElementById(FieldId);
    }

    var SelectedText = "";
	var IE = false;
	var NN = false;

    if(navigator.appName=="Microsoft Internet Explorer"){
        var IE = true;
    } else if(
        (navigator.appName=="Netscape")||
        (navigator.appName=="Opera")
    ){
        var NN = true;
    }
    if(IE){
        SelectedText = document.selection.createRange().text;
    } else if(NN){
        SelectedText = TxtArea.value.substring(TxtArea.selectionStart,TxtArea.selectionEnd);
    }

    if(!SelectedText){
        PutText = "Opis...";
    } else {
        PutText = SelectedText;
    }
    if(bbcode_type=="[link]"){
        if(bbcode_url = window.prompt("Wpisz adres URL:","http://")){
            if(bbcode_description = window.prompt("Wpisz opis linka:",PutText)){
                if(bbcode_url.substring(0,7)=="http://"){
                    if(!SelectedText){
                        TxtArea.value += "[link="+bbcode_url.substring(7)+"]"+bbcode_description+"[/link]";
                    } else {
                        if(IE){
                            document.selection.createRange().text = "[link="+bbcode_url.substring(7)+"]"+bbcode_description+"[/link]";
                        } else if(NN){
                            TxtArea.value = TxtArea.value.substring(0,TxtArea.selectionStart)+"[link="+bbcode_url.substring(7)+"]"+bbcode_description+"[/link]"+TxtArea.value.substring(TxtArea.selectionEnd,TxtArea.textLength);
                        }
                    }
                } else {
                    if(!SelectedText){
                        TxtArea.value += "[link="+bbcode_url+"]"+bbcode_description+"[/link]";
                    } else {
                        if(IE){
                            document.selection.createRange().text = "[link="+bbcode_url+"]"+bbcode_description+"[/link]";
                        } else if(NN){
                            TxtArea.value = TxtArea.value.substring(0,TxtArea.selectionStart)+"[link="+bbcode_url+"]"+bbcode_description+"[/link]"+TxtArea.value.substring(TxtArea.selectionEnd,TxtArea.textLength);
                        }
                    }
                }
            }
        }
    }
    if(bbcode_type=="[llink]"){
        if(bbcode_subpage = window.prompt("Wpisz podstronę serwisu:","podstrona.php")){
            if(bbcode_description = window.prompt("Wpisz opis linka:",PutText)){
                if(!SelectedText){
                    TxtArea.value += "[llink="+bbcode_subpage+"]"+bbcode_description+"[/llink]";
                } else {
                    if(IE){
                        document.selection.createRange().text = "[llink="+bbcode_subpage+"]"+bbcode_description+"[/llink]";
                    } else if(NN){
                        TxtArea.value = TxtArea.value.substring(0,TxtArea.selectionStart)+"[llink="+bbcode_subpage+"]"+bbcode_description+"[/llink]"+TxtArea.value.substring(TxtArea.selectionEnd,TxtArea.textLength);
                    }
                }
            }
        }
    }
    if(bbcode_type=="[quote]"){
        if(quote_user_login = window.prompt("Wpisz nick użytkownika:","nick")){
            if(!SelectedText){
                TxtArea.value += "[quote="+quote_user_login+"][/quote]";
            } else {
                if(IE){
                    document.selection.createRange().text = "[quote="+quote_user_login+"]"+SelectedText+"[/quote]";
                } else if(NN){
                    TxtArea.value = TxtArea.value.substring(0,TxtArea.selectionStart)+"[quote="+quote_user_login+"]"+SelectedText+"[/quote]"+TxtArea.value.substring(TxtArea.selectionEnd,TxtArea.textLength);
                }
            }
        }
    }
    if(bbcode_type=="[color]"){
        if(bbcode_color = window.prompt("Wpisz angielską nazwę koloru:","black")){
            if(!SelectedText){
                TxtArea.value += "[color="+bbcode_color+"][/color]";
            } else {
                if(IE){
                    document.selection.createRange().text = "[color="+bbcode_color+"]"+SelectedText+"[/color]";
                } else if(NN){
                    TxtArea.value = TxtArea.value.substring(0,TxtArea.selectionStart)+"[color="+bbcode_color+"]"+SelectedText+"[/color]"+TxtArea.value.substring(TxtArea.selectionEnd,TxtArea.textLength);
                }
            }
        }
    }
    if(bbcode_type=="[size]"){
        if(bbcode_size = window.prompt("Wpisz rozmiar textu (od 1 do 99):","10")){
            if((bbcode_size<1)||(bbcode_size>99)){
                window.alert("Minimalna wielkość textu to 1, maksymalna wielkość textu to 99.");
                return false;
            }
            if(!SelectedText){
                TxtArea.value += "[size="+bbcode_size+"][/size]";
            } else {
                if(IE){
                    document.selection.createRange().text = "[size="+bbcode_size+"]"+SelectedText+"[/size]";
                } else if(NN){
                    TxtArea.value = TxtArea.value.substring(0,TxtArea.selectionStart)+"[size="+bbcode_size+"]"+SelectedText+"[/size]"+TxtArea.value.substring(TxtArea.selectionEnd,TxtArea.textLength);
                }
            }
        }
    }
    if(bbcode_type=="[img]"){
        if(bbcode_img = window.prompt("Wpisz adres URL obrazka:","http://")){
            TxtArea.value += "[img="+bbcode_img.substring(7)+"]";
        }
    }
    TxtArea.focus();
}
//////////////////////////////
// Pobieranie pliku
//////////////////////////////
function GetFile(id,type,directory){
    window.open("popups/get_file.php?sid="+id+"&ftype="+type+"&directory="+directory,"GetFileWindow","resizable=0,left=0,top=0,width=600,height=250,scrollbars=1");
}
//////////////////////////////
// Zaznaczanie wszystkich elemntów z listy
//////////////////////////////
function CheckAll(status,FormName){
    for (i=0;i<document.forms[FormName].length;i++){
        document.forms[FormName].elements[i].checked = status;
    }
}
//////////////////////////////
// Okienko potwierdzenia
//////////////////////////////
function ConfirmWindow(question,url){
    if(window.confirm(question)){
        window.location.href = url;
    }
}
//////////////////////////////
// Potwierdzenie multioperacji w zarządzaniu dla opiekunów działów
//////////////////////////////
function ConfirmMultipleOperation(OperationType,FormName){
    document.forms[FormName].operation.value = OperationType;
    countElements = document.forms[FormName].length;
    checkedElements = 0;
    for(i=1;i<countElements;i++){
        if(document.forms[FormName].elements[i].checked == true){
            checkedElements++;
        }
    }
    if(checkedElements==0){
        window.alert("Zaznacz przynajmniej jeden element z listy.");
    } else {
        if(OperationType=="PublishYes"){
            confirmationQuestion = "Czy napewno chcesz opublikować zaznaczone ("+checkedElements+") elementy?";
        }
        if(OperationType=="PublishNo"){
            confirmationQuestion = "Czy na pewno nie chcesz publikować zaznaczonych ("+checkedElements+") elementów?";
        }
        if(OperationType=="Activation"){
            confirmationQuestion = "Czy napewno chcesz aktywować zaznaczone ("+checkedElements+") elementy?";
        }
        if(OperationType=="Deactivation"){
            confirmationQuestion = "Czy napewno chcesz deaktywować zaznaczone ("+checkedElements+") elementy?";
        }
        if(OperationType=="MultipleDelete"){
            confirmationQuestion = "Czy napewno chcesz usunąć zaznaczone ("+checkedElements+") elementy?";
        }
        if(window.confirm(confirmationQuestion)){
            document.forms[FormName].submit();
        }
    }
}
function SetOperation(OperationType,FormName){
    document.forms[FormName].operation.value = OperationType;
}
function SetHFValue(HFName,HFValue,FormName){
    document.forms[FormName].elements[HFName].value = HFValue;
}
//////////////////////////////
// Drukowanie inforrmacji
//////////////////////////////
function Print(question,type,print_id){
    if(window.confirm(question)){
        window.open("popups/print.php?print="+type+"&sid="+print_id,"printWindow","resizable=0,left=0,top=0,width=600,height=450,scrollbars=1");
    }
}
//////////////////////////////
// Ukrywanie / wyświetlanie opcji zarządzania działami serwisów
//////////////////////////////
function ProtectorDeskOptions(GetValue,GetIDsCounter){
    for(a=1;a<=(GetIDsCounter+1);a++){
        document.getElementById('eid_'+a).style.display=GetValue;
    }
}
//////////////////////////////
// Ukrywanie / wyświetlanie opcji zarządzania działami serwisów
//////////////////////////////
function SubmitForm(FormName,NoResultsError){
    if(NoResultsError==1){
        window.alert("Brak wartości dla jednego z wymaganych pól, wysyłanie formularza zatrzymano.");
    } else {
        document.forms[FormName].submit();
    }
}
//////////////////////////////
// Rysowanie menu serwisu
//////////////////////////////
// 0 - element wyswietlany
// 1 - opis elementu wyswietlanego
// 2 - url elementu wyswietlanego
// 3 - znaczek nowosci
// 4 - wyswietlanie elementu 1=tak, 0=nie
// 5 - wyswietlanie obrazka przed elementem, czyli ta mala strzalka
// 6 - wyrownanie elementu, left=do lewej, center=do srodka, right=dop prawej
function DrawMenu(GetMenuArray){
    for(a=0;a<GetMenuArray.length;a++){
        GetMenuArraySplit = GetMenuArray[a].split("[%|%]");
        if(GetMenuArraySplit[4]==1){
            document.write('<tr>');
                document.write('<td class="menu_table_text" style="text-align:'+GetMenuArraySplit[6]+'">');
                    if(GetMenuArraySplit[5]==1){
                        document.write('<img src="'+ServiceCssGfx+'/right.gif">&nbsp;');
                    }
                    if(GetMenuArraySplit[6]=="center"){
                        document.write('<a class="menu_table_text" href="'+GetMenuArraySplit[2]+'" title="'+GetMenuArraySplit[1]+'" target="_blank">'+GetMenuArraySplit[0]+'</a>');
                    } else {
                        document.write('<a class="menu_table_text" href="'+GetMenuArraySplit[2]+'" title="'+GetMenuArraySplit[1]+'">'+GetMenuArraySplit[0]+'</a>');
                    }
                    document.write(GetMenuArraySplit[3]);
                document.write('</td>');
            document.write('</tr>');
        }
    }
	document.write('<tr class="menu_table_close">');
		document.write('<td></td>');
	document.write('</tr>');
}
// Ładowanie strony...
function PageLoading(GetVisibility){
    document.getElementById("page_loading").style.visibility = GetVisibility;
    document.getElementById("page_loading").style.left = Math.ceil(document.body.clientWidth/2)-100;
    document.getElementById("page_loading").style.top = document.body.clientHeight-500;
}
//////////////////////////////
// Sprawdzanie formularza logowania...
//////////////////////////////
function CheckLoginForm(FormName){
    //test_user_login=/^[0-9a-zA-Z._-]{3,16}+$/;
    if(test_user_login.test(document.forms[FormName].user_login.value)==false){
        window.alert("Wpisz poprawny login: 3 do 16 znaków.");
        return false;
    }
    //test_user_password=/^.{3,32}+$/;
    if(test_user_password.test(document.forms[FormName].user_password.value)==false){
        window.alert("Wpisz poprawne hasło: 3 do 32 znaków.");
        return false;
    }
}