function changeSrc(el,img){
	if(el!=null){
		el.src=img;
	}
}

function changeTlo(el,tlo){
	if(el!=null){
		el.className=tlo;
	}
}

function czy_usun(linkp,komunikat){
	if(confirm(komunikat)){
		location.href=linkp;
	}
}


function zaznacz_checkboxy(formularz,tablica,statusel) {
	var elts=(typeof(formularz.elements[tablica+'[]'])!= 'undefined') ? formularz.elements[tablica+'[]'] : '';
	var elts_cnt = (typeof(elts.length) != 'undefined') ? elts.length : 0;
	if (elts_cnt){
		for (var i = 0; i < elts_cnt; i++){ 
		 	elts[i].checked=statusel;
		}
  } else { 
		elts.checked = statusel;
	}
}


function dodajtag(FormName,FieldName,tag,prompttext) {
	if (tag=='b'){ tag_prompt='bold'; }
	if (tag=='i'){ tag_prompt='italic'; }
	inserttext = prompt(prompttext+'\n<'+tag+'>xxx</'+tag+'>','');
	if ((inserttext != null) && (inserttext != '')) {
		document.forms[FormName].elements[FieldName].value += '<'+tag+'>'+inserttext+'</'+tag+'>';
	}
	document.forms[FormName].elements[FieldName].focus();
}

function emotikony_obrazek(pole,znaczek) {
  emotikony_pole=document.getElementById(pole);
  emotikony_pole.value=emotikony_pole.value+znaczek;
  emotikony_pole.focus();
}


function popup_image(okno,imageURL,imageTitle,w,h,margines){

	if(margines==''){
		$margines=0;
	}

	w=w+(2*margines);
	h=h+(2*margines);
	
	PositionY=(screen.height-h)/2; 
	if (PositionY<0){
		PositionY=0;
	}
	
	PositionX=(screen.width-w)/2; 
	if (PositionY<0){
		PositionY=0;
	}	
	
	
  var imgWin = window.open('',okno,'scrollbars=no,resizable=1,width='+w+',height='+h+',left='+PositionX+',top='+PositionY);
	//popup blockers should not cause errors
  if( !imgWin ) { 
		return true; 
	}

	imgWin.moveTo(PositionX,PositionY);
	imgWin.resizeTo(w,h);	
  imgWin.document.write('<html><head><title>'+imageTitle+'<\/title><\/head><body style="margin:0px; padding:0px; text-align:center"><div style="padding:'+margines+'px">'+'<img src="'+imageURL+'" alt=\"\" style=\"cursor:pointer\" onclick=\"window.close();\" />'+'<\/div><\/body><\/html>');
	
	imgWin.document.close();	
	
  if( imgWin.focus ) { 
		imgWin.focus(); 
	}

}
//czyszczenie defaultowej wartosci pola formularza
function field_clear(field,val,czysc){

	wartosc=document.getElementById(field);

	if(czysc){
		if(wartosc.value==val){
			wartosc.value='';
		}		
	} else {
		if(wartosc.value==''){
			wartosc.value=val;
		}				
	}
}
function popup_open(okno,adres,w,h,margines) {

	if(margines==''||!margines||margines=='undefined'||isNaN(margines)){
		margines=0;
	}

	w=w+margines;
	h=h+margines;

	top_okno=(screen.height-h)/2; 
	if (top_okno<0){
		top_okno=0;
	}
	left_okno=(screen.width-w)/2; 
	
	if (left_okno<0){
		left_okno=0;
	}

	imgWin=window.open(adres,okno,'top='+top_okno+',left='+left_okno+',width='+w+',height='+h+',toolbar=no,menubar=no,location=no,directories=no,alwaysRaised=no,status=no,scrollbars=no,resizable=yes,fullscreen=0');
	
	imgWin.moveTo(left_okno,top_okno);
	imgWin.resizeTo(w,h);	
			
	//popup blockers should not cause errors
  if( !imgWin ) { 
		return true; 
	}		
	
  if( imgWin.focus ) { 
		imgWin.focus(); 
	}

} 

function spr_email(email){
	var forma_email=/^(?:(?:\w\-*)+\.?)*\w+@(?:(?:\w\-*)+\.)+\w{1,4}$/;
	return forma_email.test(email);
}

String.prototype.trim=function(){
	return this.replace(/^\s*|\s*$/g,"");
}

function zmienLogin(obj,czysc){
	
	login=document.getElementById('u_login1');
	haslo=document.getElementById('u_haslo1');
	
	if(czysc){
		if(login.value==''&&obj.name=='u_login'){
			login.value='twój email';
		}
		if(haslo.value==''&&obj.name=='u_haslo'){
			haslo.value='      ';
		}			
	} else {
		if(login.value=='twój email'&&obj.name=='u_login'){
			login.value='';
		}
		if(haslo.value=='      '&&obj.name=='u_haslo'){
			haslo.value='';
		}						
	}
	
}

function wlacz_wylacz(id){

	if(id){
	
		element=document.getElementById(id);
		
		if(element){
			if(element.style.display=='none'){
				element.style.display='';
			} else {
				element.style.display="none";
			}
		}
	}
	
}
//show the error message
function error_komunikat(text){	

	main_text='Wystąpił bład formularza sprawdź poprawnośc wypełnienia danych';

	if(text){
	
		text=main_text+"\n\r"+text;			
		err_validatek=document.getElementById('err_validate');				
		if(err_validatek!=null){			
			text=text.replace('\n\r','<br />');		
  			err_validatek.innerHTML = "<div style=\"color:#ff0000;\">"+text+"</div>";
			$('#err_box').show('slow');
		} else {
			alert(text);
		}
	}

	
}
function showSubcategory()
{
	kat = $('#szuk_kategoria').val();
	link="&szuk_podkategoria="+$('#szuk_podkategoria2').val();
	if(kat!='')
	{
		$.ajax(
		{
		  	type: "POST",			
		  	url: "ajax2.php",
		  	data: "akcja=u_podKategorie&kat="+kat+link,						
		  	cache: false,
		  	success: function(html)
		  	{
		  		$("#podkategorie").html(html);
		  	}
		});		
	}
}
function showSubcategory2()
{
	kat = $('#kategoria').val();
	link="&podkategoria="+$('#podkategoria2').val();
	if(kat!='' && kat!='0')
	{
		$.ajax(
		{
		  	type: "POST",			
		  	url: "ajax2.php",
		  	data: "akcja=doswiadczenie_podKategorie&kategoria="+kat+link,						
		  	cache: false,
		  	success: function(html)
		  	{
		  		$("#podkategorie").html(html);
		  	}
		});		
	}
}

