
/**************************************************************************

 Copyright (C) 2005 Bartosz 'Denver' Olchowka
                    http://olchowka.info/

 This file is part of System Stron Klanowych.

 System Stron Klanowych is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 System Stron Klanowych is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA

****************************************************************************/


/******************************
 Pokazywanie/chowanie elementu
*******************************/

function ToggleView (id)
{
     if ( document.getElementById(id).style.display == "block" ) {
          document.getElementById(id).style.display = "none";
     } else {
          document.getElementById(id).style.display = "block";
     }
}


/**********
  BBCode 
***********/

function bbcode (strText, strFieldName, strFormName)
{
	if (!strFormName) strFormName = 'entry_form';
	document.forms[strFormName][strFieldName].value += strText;
}



/************************
  Uprawnienia klanowicza
**************************/


// zmiana stanu checkboxa miedzy wlaczonym a wylaczonym
function ToggleCheckbox (strBox, boolChecked)
{
	var cb = document.forms['fauth'][strBox];
	cb.checked = boolChecked;
}


// wybor uzytkownika dla poszczegolnej sekcji
// informacja przydatna przy ustawianiu etykiety dla przycisku
choices = new Array();
choices['all'] = false;
choices['empty'] = false;
choices['news'] = false;
choices['newscomments'] = false;
choices['calendar'] = false;
choices['players'] = false;
choices['guestbook'] = false;
choices['clanwars'] = false;
choices['clanwarscomments'] = false;
choices['clanwarsforum'] = false;

// zmiana stanu niektorych checkboxow na podstawie wyboru uzytkownika
function SetAuthMode (strMode)
{
	var modes = new Array();

	// mozliwe wyboru uzytkownika
	modes['allfields'] = [
	'newsadd', 'newsedit', 'newsdel', 'comadd', 'comedit', 'comdel', 'caladd', 'caledit', 'caldel', 
	'profphoto', 'profconfig', 'playadd', 'playedit', 'playpass', 'playauth', 'playrank', 'playfiel', 'playdel',
	'playphoto', 'playconfig', 'gbedit', 'gbdel', 'cwadd', 'cwedit', 'cwdel', 'cwscreen', 'cwdemo', 'cwcomadd', 'cwcomedit',
	'cwcomdel', 'topadd', 'topedit', 'topdel', 'postadd', 'postedit', 'postdel'
	];

	modes['news'] = ['newsadd','newsedit','newsdel'];
	modes['newscomments'] = ['comadd','comedit','comdel'];
	modes['calendar'] = ['caladd','caledit','caldel'];
	modes['players'] = ['playadd','playedit','playpass','playauth','playrank','playfiel','playdel','playphoto','playconfig'];
	modes['guestbook'] = ['gbedit','gbdel'];
	modes['clanwars'] = ['cwadd','cwedit','cwdel','cwscreen','cwdemo'];
	modes['clanwarscomments'] = ['cwcomadd','cwcomedit','cwcomdel'];
	modes['forum'] = ['topadd','topedit','topdel','postadd','postedit','postdel'];

	// jesli rodzaj sekcji jest pusty, nie robimy nic
	if (!strMode) return;


	switch (strMode)
	{
		// zaznaczenie wszystkich checkboxow
		case "all":
			var choice = true; // wlaczenie checkboxa
			strMode = "allfields"; // komorka tablicy z checkboxami
			choices['all'] = true; // zaznaczono wszystkie checkboxy
			SetAllChoices (1);     // zaznaczono wszystkie checkboxy
			break;

		case "empty":
			var choice = false; // wylaczenie checkboxa
			strMode = "allfields"; // komorka tablicy z checkboxami
			choices['empty'] = true; // wylaczono wszystkie checkboxy
			SetAllChoices (0);       // wylaczono wszystkie checkboxy 
			break;

		default:
			var choice = (choices[strMode]=!choices[strMode]);
			choices['all']   = false;
			choices['empty'] = false;
	}

	SetButtonLabel (strMode);

	var len = modes[strMode].length;

	while (len--)
	{
		ToggleCheckbox (modes[strMode][len], choice);
	}
}

// funkcja wywolywana przy zmianie stanu wszystkich checkboxow naraz
function SetAllChoices (flag)
{
	for (var el in choices) {
		choices[el] = flag;
	}
}

// zmiana tekstu zapisanego na przycisku aktualizacji checkboxow
function SetButtonLabel (strMode)
{
	if (!strMode) return;

	if (strMode=="empty" || strMode=="all") {
		label = ButtonTurnOn;
	} else if (!choices[strMode]) {
		label = ButtonTurnOn;
	} else {
		label = ButtonTurnOff;
	}

	document.forms['fauth']['changeauth'].value = label;
}