//funkcje do podmiany zdjec
function fon(n){document.images[n].src='grafika/'+n+'1.gif';}
function foff(n){document.images[n].src='grafika/'+n+'.gif';}

//funkcja do wyswietlania popupu
var okno_pop='';
function popup(wi,he,uerel,alignx,aligny,scrol)
{
	// Bartosz Szczecinski
	// 20.04.2006
	// Opera 8.x nie obsluguje !okno_pop.closed
	if(okno_pop && okno_pop.closed==false) {
		okno_pop.close()
	}
	if(wi=='100%'){wi=screen.availWidth-30}
	if(he=='100%'){he=screen.availHeight-0}
	if(alignx=='left'){xx=0}
	else if(alignx=='right'){xx=(screen.availWidth-wi)-10}
	else{xx=(screen.availWidth-wi)/2}
	if(aligny=='top'){yy=0}
	else if(aligny=='bottom'){yy=(screen.availHeight-he)}
	else{yy=(screen.availHeight-he)/2}
	okno_pop=window.open(uerel, '_blank', 'scrollbars='+scrol+',height='+he+',width='+wi+',top='+yy+',left='+xx);
}

function popupFrame(wi, he, url, alignX, alignY, scroll) {
	popup(wi, he, 'popup.php?popupFile='+url.replace(/\?/, '&'), alignX, alignY, scroll);
}

function blurall() {
	var links = document.getElementsByTagName('a');
	for (var i=0;i<links.length;i++){
		links[i].onfocus = blurme;
	}
}

function blurme()
{
	this.blur();
}


function printversion(id,path)
{
	var okno='';
	(okno && !okno.closed)?okno.close():'';
	he=400;
	wi=730;
	xx=(screen.availHeight-he)/2-10;
	yy=(screen.availWidth-wi)/2;
	okno=window.open('print_version.php?id='+id, '_blank', 'menubar=yes,scrollbars=yes,height='+he+',width='+wi+',top='+xx+',left='+yy);
}


/*ladowanie do casch-u zdjec
foto=new Array('pl','en');
menuA=new Array();menuB=new Array();
for(n=0;n<foto.length;n++){
menuA[n]=new Image();
menuA[n].src='grafika/'+foto[n]+'.gif';
menuB[n]=new Image();
menuB[n].src='grafika/'+foto[n]+'1.gif';
}
*/

function openInNewWindow(e) {
	var event;
	if (!e) event = window.event;
	else event = e;
	if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
		return true;
	}
	else {
	    var newWindow = window.open(this.getAttribute('href'), '_blank');
		if (newWindow) {
			if (newWindow.focus) {
				newWindow.focus();
			}
			return false;
		}
		return true;
	}
}

function getNewWindowLinks() {
	if (document.getElementById && document.createElement && document.appendChild) {
		var strNewWindowAlert = "";
		var links = document.getElementsByTagName('a');
		var objWarningText;
		var link;
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			if (/\bnon\-html\b/.test(link.className)) {
				objWarningText = document.createElement("em");
				objWarningText.appendChild(document.createTextNode(strNewWindowAlert));
				link.appendChild(objWarningText);
				link.onclick = openInNewWindow;
			}
		}
		objWarningText = null;
	}
}


window.addEvent('domready', function(){
	Slimbox.scanPage();
	
	if( $('uploadfoto') && $('dodajtitle') )
	{
		var szk = new Fx.Slide('uploadfoto', {duration: 200});
		szk.hide();
		
		$('dodajtitle').addEvent('click', function(e) {
			$('uploadfoto').style.display = 'block';
			szk.toggle();
		});
		
	}
	
	if( $('uploadzdjecie') )
	{
		$('uploadzdjecie').addEvent('click', function(e) {
			this.set('value','zapisuje...'); 
			$('galeriadodajformup').send();

		});
	}
	
	if( $$('.editfototextarea') )
	{
		$$('.editfototextarea').addEvent('click', function(e) {
			var numerid = this.id;
			zaptbn = numerid.substr(6,numerid.length);
			
			if( $(this.id).getProperty('class') == 'editfototextarea first' )
			{
				$(this.id).value = '';
			}
			$( this.id ).style.border = '1px solid #095BA5';
			/*border: ;*/
			
			$('zapisz-'+zaptbn).style.display = 'block';
		});
		
		$$('.editfototextarea').addEvents({
			'mouseenter': function(){
				$( this.id ).style.border = '1px solid #095BA5';
			},
			'mouseleave': function(){
				var numerid = this.id;
				zaptbn = numerid.substr(6,numerid.length);
				
				if( $('zapisz-'+zaptbn).getStyle('display') == 'none' ) $( this.id ).style.border = '1px solid #fff';
			}
		});
	}
	
	if( $('setustawstatus') )
	{
		var zapis = 0;
		
		$('setustawstatus').addEvents({
			'mouseenter': function(){
				$( this.id ).style.border = '1px solid #fff';
			},
			'mouseleave': function(){
				
				$( this.id ).style.border = '1px solid #095BA5';
			}
		});
		
		prepare = function () {
			if( $('setustawstatus').getProperty('lang') == 'en' )
			{
				$('zapiszstsbtn').value = 'Save';
			}
			else
			{
				$('zapiszstsbtn').value = 'Zapisz';
			}
			
			$('setustawstatus').setStyle('background-color', '#fff');
			$('setustawstatus').setStyle('color', '#095BA5');
			$('setustawstatus').focus();
		}
		
		zapiszstatus = function () {
			$('pokazladujacyajax').setStyle('visibility', 'visible');
			
			var myRequest = new Request({url: 'profil.php?akcja=zapiszstatus', method: 'post', onSuccess: function(responseText, responseXML) {
				$('pokazladujacyajax').setStyle('visibility', 'hidden');
			}});
			myRequest.send('opis='+$('setustawstatus').value);
			
			if( $('setustawstatus').getProperty('lang') == 'en' )
			{
				$('zapiszstsbtn').value = 'Set status';
			}
			else
			{
				$('zapiszstsbtn').value = 'Zmień status';
			}
			
			$('setustawstatus').setStyle('background-color', '#095BA5');
			$('setustawstatus').setStyle('color', '#fff');
		}
		
		
		
		$('setustawstatus').addEvent('click', function(e) {
			if( zapis == 0 )
			{
				prepare();
				zapis = 1;
			}
		});
		
		$('zapiszstsbtn').addEvent('click', function(e) {
			e = new Event(e);
			e.stop();
			
			if( zapis == 0 )
			{
				prepare();
				zapis = 1;
			}
			else
			{
				zapiszstatus();
				zapis = 0;
			}
		});
	}
	
	if( $('addmetofrends') )
	{
		var inv = new Fx.Slide('zaproszenietekst', {duration: 500});
		inv.hide();
		
		$('addmetofrends').addEvent('click', function(e) {
			$('zaproszenietekst').style.display = 'block';
			inv.toggle();
		});
	}
	
	if( $('advancedsearch') )
	{
		var inv = new Fx.Slide('advancedsearch', {duration: 500});
		if( $('advancedsearch').getStyle('display') == 'none' ) inv.hide();
		
		$('showzaawansowanasearch').addEvent('click', function(e) {
			$('advancedsearch').style.display = 'block';
			inv.toggle();
		});
	}
	
	if( $('tablicaprogramadd') )
	{
		
		$('tablicaprogramadd').addEvent('click', function(e) {
			id = $('wybierzprogram').options.selectedIndex;
			idx = $('wybierzedycje').options.selectedIndex;
			
			if( id != 0 ) 
			{
				if( idx == 0 )
				{
					nazwa = $('wybierzprogram').options[id].text;
					wartosc = $('wybierzprogram').options[id].value;
				}
				else
				{
					nazwa = $('wybierzprogram').options[id].text + ', ' + $('wybierzedycje').options[idx].text;
					wartosc = $('wybierzprogram').options[id].value + '-' + $('wybierzedycje').options[idx].value;
				}
			}
			
			var listItem = new Element('li');
			$('wybraneprogramy').grab(listItem);
			listItem.innerHTML = nazwa + '<input type="hidden" name="programywybrane[]" value="'+wartosc+'" />';
			$('firstonechoosedelete').erase('html');
		});
	}
	
	
	if( $('dodajodpowiedztab') )
	{
		var inv = new Fx.Slide('poleodpowiedztab', {duration: 500});
		if( $('poleodpowiedztab').getStyle('display') == 'none' ) inv.hide();
		
		$('dodajodpowiedztab').addEvent('click', function(e) {
			$('poleodpowiedztab').style.display = 'block';
			inv.toggle();
		});
	}
	
});
