function closePopup(popup)
{
	$(popup).hide();
}
function closePopup2()
{
	$('popup').hide();
}

function loadPopup()
{
	 var sWidth = screen.width;
	 var sHeight = screen.height;

	if ($('popup').style.display == 'none')
	{
		 if (navigator.appName.indexOf("Microsoft")!=-1)
		 {
			  sWidth = document.body.offsetWidth;
			  sHeight = document.body.offsetHeight;
		 }
		 else
		 {
			 sWidth = window.innerWidth;
		     sHeight = window.innerHeight;
		 }
		
		 $('popup').style.display = 'block';
		 $('popup').style.left = (sWidth/2-400)+'px';
		 $('popup').style.top = (sHeight/2-200)+'px';
	
		 var pp = new SWFObject("gfx/pop.swf", "popupSwf", "775", "360", "7");
		 pp.addParam("quality", "hight");
		 pp.addParam("wmode", "transparent");
		 pp.write("popup");
	 }
	
}

function foto(name, w, h)
{
 window.open("show_img.php?"+name, "foto","tollbar=no,menubar=no,location=no,personalbar=no,scrollbars=no,status=no,resizable=no,width="+w+",height="+h+", top="+((screen.height/2)-(h/2))+",left="+((screen.width/2)-(w/2)));
} // foto()

function pokaz_pola_uploadu()
{
  var ile_zdjec = parseInt(document.forms[0].pictures_count.value);
  var pola = document.getElementById('pola');
  var zwrot = '';

  for( i = 0; i < ile_zdjec; i++ )
    zwrot = zwrot + '<label>Zdjęcie nr. '+parseInt(i+1)+'</label>&nbsp;<input type="file" size="50" style="width: 330px; margin: 3px 0px 3px 0px" name="pictures[]" class="textField" value="" /><br />';

  pola.innerHTML = zwrot;
} // pokaz_pola_uploadu()

function pokaz_pola_uploadu_2()
{
  var ile_zdjec = parseInt(document.forms[0].pictures_count.value);
  var pola = document.getElementById('pola');
  var zwrot = '';

  for( i = 0; i < ile_zdjec; i++ ) {
    zwrot = zwrot + 'Opis nr. '+ parseInt(i+1) + '<input type="text" name="descs[]" style="width: 100px" class="textField" value="" /> ';
    zwrot = zwrot + 'Zdjęcie nr. '+parseInt(i+1)+'&nbsp;<input type="file" size="10" style="margin: 3px 0px 3px 0px" name="pictures[]" class="textField" value="" /><br />';
  }
  pola.innerHTML = zwrot;
} // pokaz_pola_uploadu()




function addFav()
{
if( document.all && navigator.userAgent.indexOf('Opera')==-1 )
 window.external.AddFavorite(location.href, document.title);
else if( window.sidebar )
 window.sidebar.addPanel(document.title, location.href, "");
else
 alert('Naci¶nij Ctrl+D aby dodać stronę do ulubionych');
} // dodaj_do_ulubionych()


function popup(url,tytul){
with(open('','','width=500,height=500').document){open();write('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl"><head><title>');
write(''+tytul+'</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" /></head><body style="margin:0;padding:0" onclick="self.close()"><img src="'+url+'" style="display:block" onload="resizeTo(this.width,this.height+60)"></body></html>');close()}
}

function popup2(nazwa, w, h)
{
 var pos_y = (screen.height/2)-(h/2);
 var pos_x = (screen.width/2)-(w/2);
 if( pos_y < 0 ) pos_y = 0;
 if( pos_x < 0 ) pos_x = 0;
 window.open("include/popup2.php?" + nazwa, "","tollbar=no,menubar=no,location=no,personalbar=no,scrollbars=yes,status=no,resizable=no,width="+ w +",height="+ h +", top="+ pos_y +",left="+ pos_x);
} 
 
function showOrHideElement(id)
{
	var element;
	elemet = document.getElementById(id);
	elemet.style.display = (elemet.style.display == 'none')? 'block':'none';
}

function changeElement(id1,id2)
{
	var element1;
	var element2;
	element1 = document.getElementById(id1);
	element2 = document.getElementById(id2);
	
	if(element1.style.display=='none')
	{
		element1.style.display='inline';
		element2.style.display='none';
	}
	else
	{
		element2.style.display='inline';
		element1.style.display='none';
	}
}

function showViz(id1,ids)
{
	document.getElementById(id1).style.display='block';
	
	for(var i in ids)
	{
		
		document.getElementById(ids[i]).style.display='none';
	}
}

function changePicture(pictures,pictureID)
{
	var element1;
	var element2;
	element1 = document.getElementById("Picture_"+pictureID);
	element2 = document.getElementById("PictureZoom_"+pictureID);
	
	/*
	for(var pic in pictures)
	{
		alert(pictures[pic]);
		if(pictures[pic] != pictureID)
		{
			//document.getElementById("Picture_"+pictures[pic]).style.display='none';
			//document.getElementById("PictureZoom_"+pictures[pic]).style.display='none';
		}
		
	}
	*/
	//Prototype Working HERE!!!!!!!!!!!!!!!!!!!!!!! JAŁZZZZZZZZZZAAAAAAAAAAAAAAAAAAAAAAAAAA
	pictures.each(function(pic)
	{
		if(pic != pictureID)
		{
			document.getElementById("Picture_"+pic).style.display='none';
			document.getElementById("PictureZoom_"+pic).style.display='none';
		}
		
	});
	
	element1.style.display='block';
	element2.style.display='block';
	return true;
}


function showFields(quntityField,id,txt,tableName,fileType)
{
  
  if(parseInt(quntityField)>20)
		alert('Za duża liczba. Max to 20.');
  else
  {
	  if(typeof(fileType) == 'unidentified')
		fileType= 'text'; 
	  var quantity = parseInt(quntityField);
	  var outputElement = document.getElementById(id);
	  var output = '';

	  for( i = 0; i < quantity; i++ )
	    output += '<label>'+txt+' <span style="color:#ff9900">nr. '+parseInt(i+1)+'</span></label>&nbsp;<input type="'+fileType+'" size="50" style="width: 300px; margin: 3px 0px 3px 0px" name="'+tableName+'[]" class="textField" value="" /><br />';


		outputElement.innerHTML = output;
 }
  return false;
}

function showFields2(quntityField,id,txt,tableName,fileType,max)
{
  
  if(parseInt(quntityField)>max)
		alert('Za duża liczba. Max to '+max+'.');
  else
  {
	  if(typeof(fileType) == 'unidentified')
		fileType= 'text'; 
	  var quantity = parseInt(quntityField);
	  var outputElement = document.getElementById(id);
	  var output = '';

	  for( i = 0; i < quantity; i++ )
	    output += '<label>'+txt+' <span style="color:#ff9900">nr. '+parseInt(i+1)+'</span></label>&nbsp;<input type="'+fileType+'" size="50" style="width: 300px; margin: 3px 0px 3px 0px" name="'+tableName+'[]" class="textField" value="" /><br />';


		outputElement.innerHTML = output;
 }
  return false;
}


function addField(quntityField,id,txt,tableName)
{
 var quantity = document.getElementById(quntityField);
  if(quantity.value > 0)
	quantity.value ++ ;
  else
	quantity.value=1;

  var outputElement = document.getElementById(id);
  var output = '';

 
    output += '<label>'+txt+' <span style="color:#ff9900">nr. '+parseInt(quantity.value)+'</span></label>&nbsp;<input type="text" size="50" style="width: 330px; margin: 3px 0px 3px 0px" name="'+tableName+'[]" class="textField" value="" /><br />';


	outputElement.innerHTML += output;
  
  return false;
}


function HandleRequest(action,url,outPutDiv,statusID)
{
	new Ajax.Request(action + encodeURIComponent(url), {
	method: 'get',
	onSuccess: function(transport)
	{
		var response = transport.responseText
		var notice = $(outPutDiv);
		var status = $(statusID);
		notice.hide();
		status.hide();
		notice.update(response);
		Effect.BlindDown(outPutDiv,{duration : 1});
	} ,
	onLoading: function()
	{
		var status = $(statusID);
		status.show();
		
	} ,
	onFailure: function()
	{
		alert('Wystąpił błąd podczas wysyłania zapytania. Proszę spróbować później.');
	}
});
}


function showPopup(link, w, h)
{
 window.open(link, "","tollbar=no,menubar=no,location=no,personalbar=no,scrollbars=yes,status=no,resizable=no,width="+w+",height="+h+", top="+((screen.height/2)-(h/2))+",left="+((screen.width/2)-(w/2)));
} 


function changeQuantity(id,mode)
{
  var value = $(id).value;
  switch(mode)
  {
	case 'plus':
	  if(value> 0 && value<1000)
		 value++;
	  else
		value=1;
		
		break;
		
	case 'minus':
	  if(value> 1 && value<1000)
		 value--;
	  else
		value=1;
		
		break;
  }
	
	$(id).value = value;
	return;
	
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function CheckAll()
{
var col = document.getElementsByTagName("input");
for (var i=0;i<col.length;i++)
col[i].checked= true;
return true;
}
function UnCheckAll()
{
var col = document.getElementsByTagName("input");
for (var i=0;i<col.length;i++)
col[i].checked= false;
return true;
}

function CheckBanners(id,num)
{	
	 if(id.checked && num < 3)
		bannersNum++;
	else if(id.checked == false && num >=1)
			bannersNum--;
	
	if(num==3)
		id.checked = false;
		
	if(num==0)
		id.checked = true;
		
	
	return bannersNum;
}


function PopPrintPrev(page,title, w, h)
{
 window.open(page, title,"tollbar=no,menubar=no,location=no,personalbar=no,scrollbars=no,status=no,resizable=no,width="+w+",height="+h+", top="+((screen.height/2)-(h/2))+",left="+((screen.width/2)-(w/2)));
}
