
var new_proj_table = null;
var edit_proj_links_last_index = 0;

//otwieranie linkow w nowym oknie
window.addEvent('domready', function()
{
	$$('a.newwindow').setProperty('target', '_blank');

	// nowy projekt: dodawanie linkow
	var t = $('new_proj_new_link');
	if(t!=null) 
	{
	new_proj_table = $('new_proj_links');
	if(new_proj_table!=null) 
	 {
	  try{new_proj_table = new HtmlTable($('new_proj_links'));}
	  catch(e)
	  { 
	  //nie udalo sie z HtmlTable, pewnie firefox 2.0 jest w okolicy
	  }
	 }
	t.addEvent('click' ,function(){DodajNowyLink(new_proj_table); } );
	}
	
	// modyfikowanie projektu: dodawanie linkow
	var g = $('edit_proj_new_link');	
	if(g!=null) 
	{
	edit_proj_table = $('edit_proj_links');
	edit_proj_links_last_index =  edit_proj_table.rows.length;
	
	if(edit_proj_table!=null) 
	 {
	  try{edit_proj_table = new HtmlTable($('edit_proj_links'));}
	  catch(e) {}
	 }
	g.addEvent('click' ,function(){Edit_DodajNowyLink(edit_proj_table); } );
	}
	
	// dodaj/zmien projekt: wiecej miejsca na opis
	var more_text = $('new_proj_more_text');
	if(more_text!=null)
	{
	more_text.addEvent('click' , function(){ WiecejMiejscaWTextarea('opis');} );
	}
	

});




var i=2;
//dodawanie linkow/okladek przy projektach
function DodajNowyLink(tablica)
{
 try{
//dodajemy nowa pozycje do tabeli z okladkami/linkami
tablica.push([ i +'.', 
 '<input type="text" name="linki[]" size="40"/>',
 '<input type="file" name="covers[]" id="cover1_filename"/>',
 '<span style="cursor:pointer; color:white; font-weight:bold;" onclick="javascript: $(\'' + i + '\').dispose();">usuń</span>'],{'id':i} );
 }
 catch(e)
 {
  //skoro push nie wyszlo to pewnie firefox 2.0 jest w okolicy 
  //( nawet ie7 to poprawnie obsluguje)
  //no coz, trzeba jechac na standardowych metodach JS
  var row = tablica.insertRow(-1);
    row.id = i;
  var cell = row.insertCell(-1);
  cell.innerHTML = i + '.';
  cell = row.insertCell(-1);
  cell.innerHTML = '<input type="text" name="linki[]" size="40"/>';
  cell = row.insertCell(-1);
  cell.innerHTML =  '<input type="file" name="covers[]" id="cover1_filename"/>';
  cell = row.insertCell(-1);
  cell.innerHTML = '<span style="cursor:pointer; color:white; font-weight:bold;" onclick="javascript: $(\'' + i + '\').dispose();">usuń</span>';
 }
 
 i++;
}



//dodawanie linkow/okladek przy modyfikacji projektu 
// nie mozna uzyc gotowej DodajNowyLink() bo jest inny uklad tabeli
function Edit_DodajNowyLink(tablica)
{
 try{
//dodajemy nowa pozycje do tabeli z okladkami/linkami
tablica.push([ edit_proj_links_last_index +'.', 
 '',
 '<input type="text" name="linki[]" size="35"/>',
 '<input type="file" name="covers[]" id="cover1_filename"/>',
 '<span style="cursor:pointer; color:white; font-weight:bold;" onclick="javascript: $(\'' + edit_proj_links_last_index + '\').dispose();">usuń</span>'],{'id':edit_proj_links_last_index} );
 }
 catch(e)
 {
  //skoro push nie wyszlo to pewnie firefox 2.0 jest w okolicy 
  //( nawet ie7 to poprawnie obsluguje)
  //no coz, trzeba jechac na standardowych metodach JS
  var row = tablica.insertRow(-1);
    row.id = edit_proj_links_last_index;
  var cell = row.insertCell(-1);
  cell.innerHTML = edit_proj_links_last_index + '.';
  cell = row.insertCell(-1);
  cell.innerHTML = '-';
  cell = row.insertCell(-1);
  cell.innerHTML = '<input type="text" name="linki[]" size="35"/>';
  cell = row.insertCell(-1);
  cell.innerHTML =  '<input type="file" name="covers[]" id="cover1_filename"/>';
  cell = row.insertCell(-1);
  cell.innerHTML = '<span style="cursor:pointer; color:white; font-weight:bold;" onclick="javascript: $(\'' + edit_proj_links_last_index + '\').dispose();">usuń</span>';
 }
 
 edit_proj_links_last_index++;
}

function WiecejMiejscaWTextarea(nazwa)
{
 var textarea = $(nazwa);
 var rows = null;
 if(textarea!= null)
  {
   rows = textarea.getProperty('rows');
   var newrows = parseInt(rows) + 10;
   textarea.setProperty('rows',newrows);
  }
}
