function addModToForm(obj) {	
	win = new Window({className: "dialog", width:350, height:300, zIndex: 100, resizable: true, title: "Dodaj moderatora", showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff, draggable:true, wiredDrag: true})
	win.getContent().innerHTML= "<div id=\"tbUsersList\"><img src=\"/i/loading.gif\" alt=\"loading...\" title=\"loading...\" class=\"loading\" /></div><span class=\"listInfo\">wybierz moderatora forum spośród Twoich znajomych</span>"
	win.showCenterInput(obj.id);
	// because of error in 'wondows' library. In IE 7 you have to show it twice
	if (!(navigator.appVersion.indexOf("MSIE 7.")==-1)) { win.showCenter() }
}

function addUserToForm(obj) {	
	win = new Window({className: "dialog", width:350, height:300, zIndex: 100, resizable: true, title: "Wybierz użytkownika", showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff, draggable:true, wiredDrag: true})
	win.getContent().innerHTML= "<div id=\"tbUsersList\"><img src=\"/i/loading.gif\" alt=\"loading...\" title=\"loading...\" class=\"loading\" /></div><span class=\"listInfo\">wybierz nowego administratora grupy spośród Twoich znajomych</span>"
	win.showCenterInput(obj.id);
	// because of error in 'wondows' library. In IE 7 you have to show it twice
	if (!(navigator.appVersion.indexOf("MSIE 7.")==-1)) { win.showCenter() }
}

function addInstituteToForm(obj) {	
	win = new Window({className: "dialog", width:350, height:300, zIndex: 100, resizable: true, title: "Dodaj instytucję powiązaną", showEffect:Effect.BlindDown, hideEffect: Effect.SwitchOff, draggable:true, wiredDrag: true})
	win.getContent().innerHTML= "<div id=\"tbInstituteList\"><img src=\"/i/loading.gif\" alt=\"loading...\" title=\"loading...\" class=\"loading\" /></div><span class=\"listInfo\">wybierz instytucję, z którą chcesz powiązać nową grupę</span>"
	win.showCenterInstitute(obj.id);
	// because of error in 'wondows' library. In IE 7 you have to show it twice
	if (!(navigator.appVersion.indexOf("MSIE 7.")==-1)) { win.showCenter() }
}

function selectFriend(obj, userId) {
	
	var grFriendsList = $('grFriendsList');
	var grFriendsListLi = grFriendsList.getElementsByTagName('li');

	for ( g=0; g<grFriendsListLi.length; g++ ) {
		
		grFriendsListLi[g].className = 'grFriendOff';
	}
	
	var friend = $(obj.id); 
	friend.className = 'grFriendOn';
	
	var grInputId = $('choosenModId');
	grInputId.value = userId;
}

function setFriend() {
	
	var modId = $('choosenModId').value;
	var sourceInputId = $('sourceInputId');
	
	var inputId = sourceInputId.value;
	
	var sourceInput = $(inputId);
	sourceInput.value = modId;
	
	var wId = $('windowId');
	Windows.close(wId.value);
}

function addToGroup(gId,gName) {
	dialog = Dialog.alert({url: "/grupy/dodaj/gId/"+gId+"/gName/"+gName+"/", options: {method: 'get'}},  {top: 200, width: 300, className: "alphacube", buttonClass: "myButtonClass", okLabel: "powrót", ok:function(win) {return true;}});
}

function removeFromGroup(gId,gName) {
	dialog = Dialog.alert({url: "/grupy/zrezygnuj/gId/"+gId+"/gName/"+gName+"/", options: {method: 'get'}},  {top: 200, width: 300, className: "alphacube", buttonClass: "myButtonClass", okLabel: "powrót", ok:function(win) {return true;}});
}

function deleteModerator(gId,gName,uId) {
	dialog = Dialog.alert({url: "/admingrupy/usunmoda/gId/"+gId+"/gName/"+gName+"/uId/"+uId+"/", options: {method: 'get'}},  {top: 200, width: 300, className: "alphacube", buttonClass: "myButtonClass", okLabel: "powrót", ok:function(win) {return true;}});
}

function deleteThread(gId,tId) {
	dialog = Dialog.alert({url: "/admingrupy/usunwatek/gId/"+gId+"/tId/"+tId+"/", options: {method: 'get'}},  {top: 200, width: 300, className: "alphacube", buttonClass: "myButtonClass", okLabel: "powrót", ok:function(win) {return true;}});
}

function deletePost(gId,tId,pId) {
	dialog = Dialog.alert({url: "/admingrupy/usunpost/gId/"+gId+"/tId/"+tId+"/pId/"+pId+"/", options: {method: 'get'}},  {top: 200, width: 300, className: "alphacube", buttonClass: "myButtonClass", okLabel: "powrót", ok:function(win) {return true;}});
}

function deleteInstitute(gId,insId) {
	dialog = Dialog.alert({url: "/admingrupy/usuninstytucje/gId/"+gId+"/insId/"+insId+"/", options: {method: 'get'}},  {top: 200, width: 300, className: "alphacube", buttonClass: "myButtonClass", okLabel: "powrót", ok:function(win) {return true;}});
}

function deleteGroupConnection(gId,insId) {
	dialog = Dialog.alert({url: "/admingrupy/usunpowiazanie/gId/"+gId+"/insId/"+insId+"/", options: {method: 'get'}},  {top: 200, width: 300, className: "alphacube", buttonClass: "myButtonClass", okLabel: "powrót", ok:function(win) {return true;}});
}

function sendElementToModeration(eId,eType) {
	dialog = Dialog.alert({url: "/moderacja/zglos/eId/"+eId+"/eType/"+eType+"/", options: {method: 'get'}},  {top: 200, width: 300, className: "alphacube", buttonClass: "myButtonClass", okLabel: "powrót", ok:function(win) {return true;}});
}

function checkForm() {
	
	var message = "Nie wypełniono następujących pól:\n";
	
	var form = $('frAddThread');
	
	var title = $('frThreadTitle');
	var content = $('frThreadContent');
	
	if ( title.value == '' ) {
		message += "  - tytuł posta\n";
	} 
	
	if ( content.value == '' ) {
		message += "  - treść posta\n";
	}
	
	if ( title.value != '' && content.value != '' ) {
		form.submit();
	} else {
		alert(message);
	}
}

function getElementsByClassName(cn){
  var arr = new Array(); 
  var els = document.getElementsByTagName("*");
  var exp= new RegExp("^(.* )?"+cn+"( .*)?$", "g");
  for (var i = 0; i < els.length; i++ ){
    if (exp.test(els[i].className)){
      arr.push(els[i]);
    }
  }
  return arr;
}

function countChars() { 
    with(document.forms[0]) { 

        var tekst = document.getElementById('frThreadContent').value; // cały text z pola textarea 
        var countInput = document.getElementById('frThreadContentCount');
        var dl_tresc = document.getElementById('frThreadContent').value.length; // długoś tekstu z textarea 
        var maxlen = 3000; // maxymalna dozwolona długość 
        var prawdziwa = 0; // licznik znaków 
        var entery = 0; 
        
        for (i=0; i<dl_tresc; i++) { 
            if (tekst.charAt(i) == "\n") { 

                prawdziwa++; 
                entery++;
 
                if (navigator.appName != "Netscape") 
                    i++; 
            } 
            prawdziwa++; 
        } // koniec for i 
        
        countInput.value= maxlen - prawdziwa; // wyświetl komunikat o licznie znaków 
        if (prawdziwa>maxlen) { 
            if (navigator.appName != "Netscape") 
                tekst = tekst.substring(0,maxlen);
            else 
               tekst = tekst.substring(0,maxlen-entery);
    
        countInput.value = 3000 - maxlen; 
        alert("Maksymalna długość to " + maxlen +"!"); 
        } 
    } // koniec with 
} 

function submitThreadForm() {
	
	var tinyContent = tinyMCE.get('frThreadContent').getContent();
	var tForm = document.getElementById('frAddThread')

	var charsCount = tinyContent.length;
	if ( charsCount > 5096 ) {
		alert( 'Twoja wypowiedź ma ponad 4000 znaków więc nie może zostać dodana.' );
	} else {
		tForm.submit();
	}
}

function autochangePromotedEvents(id) {
	
	var next = id+1;
	if (next == 4) next = 1;
	if (packStoped == false) {
		changePromotedEvent('t'+id,'i'+id,'c'+id,'btnE'+id);
		window.setTimeout('autochangePromotedEvents('+next+')',6000);
	}
}

function changePromotedEvent(tId, iId, cId, btnId) {
	
	var element = document.getElementById(tId);
	var element = document.getElementById(iId);
	var element = document.getElementById(cId);
	var button = document.getElementById(btnId);
	
	var navi = document.getElementById('sgNavi');
	var title = document.getElementById('sgRecInfo');
	var content = document.getElementById('sgRecContent');
	var images = document.getElementById('sgRec');
	
	var aTabs = navi.getElementsByTagName('a');
	var tTabs = title.getElementsByTagName('div');
	var cTabs = content.getElementsByTagName('div');
	var iTabs = images.getElementsByTagName('img');
	
	var aMax = aTabs.length;
	var tMax = tTabs.length;
	var cMax = cTabs.length;
	var iMax = iTabs.length;
	
	for(a=0; a<aMax; a++) {
		
		if ( aTabs[a].id == btnId ) {
			aTabs[a].className = 'selected';
		} else {
			aTabs[a].className = 'none';
		}
	}
	
	for(t=0; t<tMax; t++) {
		
		if ( tTabs[t].id == tId ) {
			tTabs[t].className = 'block';
		} else {
			tTabs[t].className = 'hidden';
		}
	}
	
	for(c=0; c<cMax; c++) {
		
		if ( cTabs[c].id == cId ) {
			cTabs[c].className = 'block';
		} else {
			cTabs[c].className = 'hidden';
		}
	}
	
	for(i=0; i<tMax; i++) {
		
		if ( iTabs[i].id == iId ) {
			iTabs[i].className = 'block';
		} else {
			iTabs[i].className = 'hidden';
		}
	}
}
	

function slideBlock(id) {
		
	var element = $(id);
	var blockOpen = readCookie(id);
	
	if ( blockOpen == 'true' || element.style.display == 'block' ) {
		Effect.SlideUp(id);
		eraseCookie(id);
	} else {
		Effect.SlideDown(id);
		createCookie(id,'true',123);
		return false;
	}
}

function openDefaultHelpBlocks() {
	
	var blockOpen = new Array('docsRules', 'docsComposition', 'docsAdditional');
	var cookie = '';
	var element = '';
	
	for (var i=0; i<3; i++) {
		
		cookie = readCookie(blockOpen[i]);
		element = $(blockOpen[i]);
			
		if ( cookie == 'true' ) {
			element.style.display = 'block';
		} else {
			element.style.display = 'none';
		}
	}
	
}

function orderGift(gId) {
	
	var q = document.getElementById('gQuantity'+gId).value;
	dialog = Dialog.alert({url: "/nagrody/zamow/nId/"+gId+"/nQuauntity/"+q+"/", options: {method: 'get'}},  {top: 200, width: 300, className: "alphacube", buttonClass: "myButtonClass", okLabel: "powrót", ok:function(win) {return true;}});
}