// $Id: func.js,v 1.36 2008/11/27 07:44:28 stryc Exp $

function setPointer(field, action, defaultColorOdd,defaultColorEven, pointerColor, markColor) {

var tabela1='tabela';
if (!tabela1) return alert ("No table(s) ID specified in parameters");
	var tabela = (document.all ? document.all[tabela1] : document.getElementById(tabela1));
	if (!tabela) return alert ("Can't find table(s) with specified ID (" + tabela1 + ")");
	
	
	
if (field.highlighted==true){
	//alert(field.id);
}
if (field.highlighted == true) {
if (action == 'click') {
//click odklikniecie
field.style.backgroundColor=pointerColor; 
field.highlighted = false;


wybraneId='';
	TosamoId='1';
	doButtonsOff();

}
} else {
if (action == 'over') {
//przejazd
//alert("over");
field.style.backgroundColor=pointerColor; 
}
if (action == 'out') {
//wyjazd

for (var i = 1; i < tabela.rows.length; i++){
    if (i%2){
    	if (tabela.rows[i]==field){
    		field.style.backgroundColor=defaultColorEven;
    	}
    }else{
    	if (tabela.rows[i]==field){
    		field.style.backgroundColor=defaultColorOdd; 
    		 
    	}
    }
}

//field.style.backgroundColor=defaultColorEven; 
} 
if (action == 'click') {
//klikniecie zaznaczenei

for (var i = 1; i < tabela.rows.length; i++){
  if (field!=tabela.rows[i]){  
 	tabela.rows[i].highlighted = false;
    if (i%2){
    	
    	tabela.rows[i].style.backgroundColor=defaultColorEven;
    }else{
 
    	tabela.rows[i].style.backgroundColor=defaultColorOdd;
    	
    }
 }
}

field.style.backgroundColor=markColor; 
field.highlighted = true;


wybraneId=field.id;
TosamoId='';
doButtonsOn();
}
}
}

/*
function noweOkno(file_name, file_type, width_big, height_big)
{
    
    file_type = "%20";
	var picture_left = screen.width;
	var picture_top = screen.height;
	    
	if((picture_left > width_big) && (picture_top > height_big))
	{
		    	
		picture_left = (picture_left/2) - (width_big/2);
		picture_top = (picture_top/2) - (height_big/2);
		    			
	}
	else
	{
	    picture_left = 0;
	    picture_top = 0;
	}
		    			    					
	PictureWindow = window.open('', '', 'toolbar=no, resizable=yes, width=' + width_big + ', height=' + height_big + ', left=' + picture_left + ', top=' + picture_top);
	PictureWindow.document.open();
	PictureWindow.document.write('<HTML><HEAD><TITLE>PowiÄkszenie...</TITLE></HEAD><BODY marginheight="0" marginwidth="0" topmargin="0" leftmargin="0">');
	PictureWindow.document.write('<a href="javascript:window.close()"><img src="' + file_name + '" width=' +
		width_big + ' height=' + height_big + ' vspace="0" hspace="0" border="0" alt="Zamknij okno..."></a>');
	PictureWindow.document.write('</BODY></HEAD>');
	PictureWindow.document.close();
	PictureWindow.focus();
		    			    									    	    	    
}
// nowe okienko
function noweOkno(url, nazwa, szerokosc, wysokosc) {
   alert(szerokosc);
   x = (screen.width) ? (screen.width - szerokosc) / 2 : 0;
   y = (screen.height) ? (screen.height - wysokosc) / 2 : 0;
   window.open(url, nazwa, 'toolbar=0,location=0,directories=0,menubar=0,status=0,scrollbars=1,resizable=1,left=' + x + ',top=' + y + ',width=' + szerokosc + ',height=' + wysokosc);
}
*/		    			    									    	    	    
		    			    									    	    	    

function otworzOkno(url, nazwa, width, height) {
   if (parseInt(navigator.appVersion)>3) {
      if (navigator.appName=='Netscape') {
         winWidth = window.innerWidth;
         winHeight = window.innerHeight;
      }
      if (navigator.appName.indexOf('Microsoft')!=-1) {
         winWidth = document.body.offsetWidth;
         winHeight = document.body.offsetHeight;
      }
   }
   x = (winWidth-width) / 2;
   y = (winHeight-height) / 2;
   var Win = window.open(url,nazwa,'width='+ width+',height='+height+',left='+x+',top='+y+',screenX='+x+',screenY='+y+',resizable=1,scrollbars=yes,menubar=no');
}


function move_item(from, to)
{
  var f;
  var SI; 
  if(from.options.length>0)
  {
    for(i=0;i<from.length;i++)
    {
      if(from.options[i].selected)
      {
        SI=from.selectedIndex;
        f=from.options[SI].index;
        to.options[to.length]=new Option(from.options[SI].text,from.options[SI].value);
        from.options[f]=null;
        i--; 
      }
    }
  }
}

function move_item_down(from)
{
  	var f;
  	var SI; 
  	if(from.options.length>0)
  	{
    	for(i=0;i<from.length;i++)
    	{
      		if(from.options[i].selected)
      		{
        		SI=from.selectedIndex;
        		f=from.options[SI].index;
        		from.options[f]=null;
        		i--; 
      		}
    	}
  	}
}

function move_item_up(id,tytul,to) {
	var jest = false;
	var value;
	var x;
	
	if(to.options.length>0)
  	{    	
    	for(i=0;i<to.length;i++)
    	{
    		value=to.options[i].value;
    		if (id == value) 
    		{
    			jest = true;
    			break;
    		}
    	}
    } 
    
	if(id>8 && jest == false)
		to.options[to.length] = new Option(tytul,id);
}

function przeslij()
{
document.forms['f1'].elements[0].value=2;

if (document.forms['f1'].items_left.length<1){
	alert('Musisz wybra� conajmniej 1 kategorie ...');
	
}else{
	for(var i=0;i<document.forms['f1'].items_left.length;i++){
 		document.forms['f1'].wybrano.value+=document.forms['f1'].items_left[i].value+';';
	}
	
	document.forms['f1'].submit();
}

}

function wybierz_gmine()
{
	for(i=0;i<document.forms['gmina'].select_gmina.options.length;i++)
    {
      if(document.forms['gmina'].select_gmina.options[i].selected)
      {
        document.forms['gmina'].submit();
      }
    }
}

function wybierz_gmine_art()
{
	for(i=0;i<document.forms['gmina'].select_gmina_art.options.length;i++)
    {
      if(document.forms['gmina'].select_gmina_art.options[i].selected)
      {
        document.forms['gmina'].submit();
      }
    }
}

function pokazPola(obj)
 {
	var pole1 = styleobj('pole');
	var pole2 = styleobj('pole2');
	
	if (obj[obj.selectedIndex].value != 2) { 
		pole1.visibility = 'hidden';
		pole2.visibility = 'hidden';
	} else {
		pole1.visibility='visible'; 
		pole2.visibility='visible'; 
	} 
	
}

function styleobj(strid) {

	if (document.all) { if (document.all[strid] != null) return document.all[strid].style; else return null;}
	if (document.ids) return document.ids[strid];
	if (document.layers) return document.layers[strid];
	if (document.getElementById) { if (document.getElementById(strid) != null)
	{return document.getElementById(strid).style; }
	} else return null;
	return null ;
}

function przenies(id,tytul) {
	if (opener && !opener.closed ) {
		opener.dodajKategorie(id,tytul);
	}
	self.close();
}

function przenies_obiekt(id,tytul) {
	if (opener && !opener.closed ) {
		opener.dodajObiekt(id,tytul);
	}
	self.close();
}

function przenies_obiekt_ob(id) {
	if (opener && !opener.closed ) {
		var tab = id.split("_");
		opener.dodajObiekt_ob(tab[0], tab[1]);
	}
	self.close();
}

function przenies_obiektGr(id,tytul) {
	if (opener && !opener.closed ) {
		opener.dodajObiektGr(id,tytul);
	}
	self.close();
}

function dodajKategorie(id,tytul){
	document.forms['artykul'].kaId.options[document.forms['artykul'].kaId.length] = new Option(tytul,id);
}

function dodajObiekt(id,tytul){
	document.forms['obiekt'].soNazwaM.options[document.forms['obiekt'].soNazwaM.length] = new Option(tytul,id);
	przygotujDaneObiektM();
}

function dodajObiekt_ob(id,tytul){
	document.forms['artykul'].obNazwa.options[0] = new Option(tytul,id);
	document.forms['artykul'].obid.value=id;	
}

function dodajObiektGr(id,tytul){
	document.forms['artykul'].soNazwaM.options[document.forms['artykul'].soNazwaM.length] = new Option(tytul,id);
}

function dodajSlowa(){

   if (document.forms['artykul'].slowo.value!=''){
	document.forms['artykul'].slowaKluczowe.options[document.forms['artykul'].slowaKluczowe.length] = new Option(document.forms['artykul'].slowo.value,document.forms['artykul'].slowo.value);
	document.forms['artykul'].slowo.value='';
  } 
}


function usunObiekt(){
	for(var i=document.forms['obiekt'].soNazwaM.length-1;i>-1;i--){
		if (document.forms['obiekt'].soNazwaM.options[i].selected){
 			document.forms['obiekt'].soNazwaM.options[i]=null;
 		}
	}
	przygotujDaneObiektM();
}

function usunSlowko(){
	for(var i=document.forms['obiekt'].slowoM.length-1;i>-1;i--){
		if (document.forms['obiekt'].slowoM.options[i].selected){
 			document.forms['obiekt'].slowoM.options[i]=null;
 		}
	}
}

function usunKategorie(){
	for(var i=document.forms['artykul'].kaId.length-1;i>-1;i--){
		if (document.forms['artykul'].kaId.options[i].selected){
 			document.forms['artykul'].kaId.options[i]=null;
 		}
	}

}

function usunStrukture(){
	for(var i=document.forms['artykul'].soNazwaM.length-1;i>-1;i--){
		if (document.forms['artykul'].soNazwaM.options[i].selected){
 			document.forms['artykul'].soNazwaM.options[i]=null;
 		}
	}
}

function usunObiekt_ob(){
	document.forms['artykul'].obNazwa.options[0]=null;
	document.forms['artykul'].obid.value = null;
}

function usunSlowa(){
	for(var i=document.forms['artykul'].slowaKluczowe.length-1;i>-1;i--){
		if (document.forms['artykul'].slowaKluczowe.options[i].selected){
 			document.forms['artykul'].slowaKluczowe.options[i]=null;
 		}	
	}	
}

//dodaje do tablicy id dodawnego pliku 
function dodajPlik(id){
	plikiId[plikiId.length]=id;
	przygotujDane();
	updateDanych();
}

//dodaje plik loga do struktury obiektow
function dodajPlikL(id){
	plikiIdL=id;
	document.forms['obiekt'].soLogo.value = id;
	document.forms['obiekt'].event.value=3;
	document.forms['obiekt'].submit();
}

//dodaje plik obrazka do struktury obiektow
function dodajPlikO(id,pole){
	plikiIdO=id;
	for (i=0; i<document.forms['obiekt'].length; i++){
		if (document.forms['obiekt'][i].name == pole ) {
			document.forms['obiekt'][i].value = id;
		}
	}	
	document.forms['obiekt'].event.value=4;
	document.forms['obiekt'].submit();
}

//dodaje plik obrazka do struktury obiektow
function dodajPlikT(id){
	plikiIdT=id;
	document.forms['obiekt'].soObrazekTabela.value = id;
	document.forms['obiekt'].event.value=5;
	document.forms['obiekt'].submit();
}

function dodajLink(id){
	linkiId[linkiId.length]=id;
	przygotujDane();
	updateDanych();
}

function dodajLinkZewnetrzny(){
	var linkZewTmp=document.forms['artykul'].linkZew.value;
	document.forms['artykul'].linkZew.value='';
	if (linkZewTmp.length>0){
		linkiZewnetrzneId[linkiZewnetrzneId.length]=linkZewTmp;
		przygotujDane();
		updateDanych();
	}
}


function usunPlik(id){
alert(id);
	document.forms['artykul'].plikiUsuniete.value = id;
	//document.forms['obiekt'].submit();
	//var tmp = new Array();
	//for(i=0; i<plikiId.length; i++){
		//if (plikiId[i] != id) {
			//tmp[tmp.length]=plikiId[i];
			//document.forms['artykul'].elements['arPriorytet_'+plikiId[i]].value=tmp.length;
		//}
	//}
	//plikiId = tmp;
	//przygotujDane();
	//updateDanych();

}

//usuwa plik loga do struktury obiektow
function usunPlikL(id){
	plikiIdL=null;
	document.forms['obiekt'].soLogo.value = "";
	document.forms['obiekt'].event.value=3;
	document.forms['obiekt'].submit();
}

//usuwa plik obrazka do struktury obiektow
function usunPlikO(id, pole){
	plikiIdO=null;
	for (i=0; i<document.forms['obiekt'].length; i++){
		if (document.forms['obiekt'][i].name == pole ) {
			document.forms['obiekt'][i].value = "";
		}
	}	
	document.forms['obiekt'].event.value=4;
	document.forms['obiekt'].submit();
}

//usuwa plik obrazka do struktury obiektow
function usunPlikT(id){
	plikiIdT=null;
	document.forms['obiekt'].soObrazekTabela.value = "";
	document.forms['obiekt'].event.value=5;
	document.forms['obiekt'].submit();
}

function usunLink(id){
	var tmp = new Array();
	for(i=0; i<linkiId.length; i++)
	if (linkiId[i] != id) 
			tmp[tmp.length]=linkiId[i];
	linkiId = tmp;
	przygotujDane();
	updateDanych();

}

function zmianaPriorytetu(z,pole){
	document.forms['artykul'].priorZmiana.value=z; 
	document.forms['artykul'].priorZmianaNa.value=pole.value;
	document.forms['artykul'].priorZmianaPole.value=pole.name;
	przygotujDane();
	updateDanych();
}

function usunLinkZewnetrzny(id){
	if (linkiZewnetrzneId[id] != null) {
		linkiZewnetrzneId[id]=null;
		przygotujDane();
		updateDanych();
	}
}

//przygotowanie danych do wysy�ki ale nie do zapisu
function przygotujDane(){
	
	document.forms['artykul'].pliki.value = plikiId.join(',');
	document.forms['artykul'].linki.value = linkiId.join(',');
	tablica = new Array();
	for(i=0,j=0; i<linkiZewnetrzneId.length ; i++) {
	if (linkiZewnetrzneId[i] != null)
		tablica[j++] = i + "^^" + linkiZewnetrzneId[i];
	}
	document.forms['artykul'].linkiZewnetrzne.value = tablica.join('^|^')
	if (document.forms['artykul'].kaId!=null){
document.forms['artykul'].wybranoKaId.value='';
for(var i=0;i<document.forms['artykul'].kaId.length;i++)
 document.forms['artykul'].wybranoKaId.value+=document.forms['artykul'].kaId[i].value+';';

}
if (document.forms['artykul'].slowaKluczowe!=null){
document.forms['artykul'].wybranoSlowa.value='';
for(var i=0;i<document.forms['artykul'].slowaKluczowe.length;i++)
 document.forms['artykul'].wybranoSlowa.value+=document.forms['artykul'].slowaKluczowe[i].value+';';
}
}

//przygotowanie danych do wysy�ki ale nie do zapisu
function przygotujDaneGrupy(){
	
	if (document.forms['artykul'].kaId!=null){
        document.forms['artykul'].wybranoKaId.value='';
        for(var i=0;i<document.forms['artykul'].kaId.length;i++)
           document.forms['artykul'].wybranoKaId.value+=document.forms['artykul'].kaId[i].value+';';
    } else {
    	    	
    	document.forms['artykul'].wybranoKaId.value='';
    }

	if (document.forms['artykul'].soNazwaM!=null){
        document.forms['artykul'].soNM.value='';
		for(var i=0;i<document.forms['artykul'].soNazwaM.length;i++)
			document.forms['artykul'].soNM.value+=document.forms['artykul'].soNazwaM[i].value+';';
    } else {
    	    	
    	document.forms['artykul'].soNM.value='';
    }
	
	return true;
}

function przygotujDaneObiektM() {
    document.forms['obiekt'].soNM.value='';	
	if (document.forms['obiekt'].soNazwaM.length>0)	
		document.forms['obiekt'].soNM.value=document.forms['obiekt'].soNazwaM[0].value;
	for(var i=1;i<document.forms['obiekt'].soNazwaM.length;i++)
		document.forms['obiekt'].soNM.value+=','+document.forms['obiekt'].soNazwaM[i].value;
}



function updateDanych(){
		//dane tylko upgrejdowane nie zapisywane
		document.forms['artykul'].event.value=5;
		document.forms['artykul'].submit();
}

function dodajId(){
	var id=document.wyszukiwanieId.plId.value;
	if ( id.match(/(\d{1,11})/) && !opener.closed){
		opener.dodajPlik(id);
		self.close();
	}
}

function dodajIdL(){
	var id=document.wyszukiwanieId.plId.value;
	if ( id.match(/(\d{1,11})/) && !opener.closed){
		opener.dodajPlikL(id);
		self.close();
	}
}

function dodajIdO(pole){
	var id=document.wyszukiwanieId.plId.value;
	if ( id.match(/(\d{1,11})/) && !opener.closed){
		opener.dodajPlikO(id, pole);
		self.close();
	}
}

function dodajIdT(){
	var id=document.wyszukiwanieId.plId.value;
	if ( id.match(/(\d{1,11})/) && !opener.closed){
		opener.dodajPlikT(id);
		self.close();
	}
}

function dodajPlikId(id){
	
	if ( !opener.closed){
		opener.dodajPlik(id);
		self.close();
	}
}

function dodajPlikIdL(id){
	
	if ( !opener.closed){
		opener.dodajPlikL(id);
		self.close();
	}
}

function dodajPlikIdO(id, pole){
	
	if ( !opener.closed){
		opener.dodajPlikO(id, pole);
		self.close();
	}
}

function dodajPlikIdT(id){
	
	if ( !opener.closed){
		opener.dodajPlikT(id);
		self.close();
	}
}

function dodajLinkId(id){
	if ( !opener.closed){
		opener.dodajLink(id);
		self.close();
	}
}


function dodajIdLink(){
	var id=document.wyszukiwanieId.lnId.value;
	if ( id.match(/(\d{1,11})/) && !opener.closed){
		opener.dodajLink(id);
		self.close();
	}
}

function przeslijArtykul()
{
   	
	var tmp_string='start';
	var przeslij=0;
	for(i=0; i<plikiId.length; i++){
		var id=plikiId[i];
		var szukaj=","+document.forms['artykul'].elements['arPriorytet_'+id].value+",";
		if ((tmp_string.indexOf(szukaj)>0)){
			przeslij=1;
			alert('Nie poprawne priorytety plik�w. Popraw dane i spr�buj raz jeszcze !!');
		}else{
			tmp_string=tmp_string+","+document.forms['artykul'].elements['arPriorytet_'+id].value+",";
		}
	}
	
	if (przeslij==0){
		document.forms['artykul'].elements[0].value=2;

		if (document.forms['artykul'].kaId!=null){
			document.forms['artykul'].wybranoKaId.value='';
			for(var i=0;i<document.forms['artykul'].kaId.length;i++)
				document.forms['artykul'].wybranoKaId.value+=document.forms['artykul'].kaId[i].value+';';
		}
		if (document.forms['artykul'].slowaKluczowe!=null){
			document.forms['artykul'].wybranoSlowa.value='';
			for(var i=0;i<document.forms['artykul'].slowaKluczowe.length;i++)
 				document.forms['artykul'].wybranoSlowa.value+=document.forms['artykul'].slowaKluczowe[i].value+';';
		}
		przygotujDane();
		return true;
	}else{	
		return false;
	}
}

function podgladKartka(id_zdjecia) 
{
	kadIdZjecia = 'kadIdZjecia='+id_zdjecia;	
	karOdbEmail = 'karOdbEmail='+document.forms['mailForm'].input_email.value;
	karNadEmail = 'karNadEmail='+document.forms['mailForm'].input_emailn.value;
	karNadNazwa = 'karNadNazwa='+document.forms['mailForm'].input_nadawca.value;
	karTresc = 'karTresc='+document.forms['mailForm'].textarea_tresc.value;
	karNaglowek = 'karNaglowek='+document.forms['mailForm'].input_tytul.value;
	
	id = 0;
	if (document.forms['mailForm'].radio_znaczki.value > 0) {
		id = document.forms['mailForm'].radio_znaczki.value;
	} else {
		for (i=0;i<document.forms['mailForm'].radio_znaczki.length;i++){
			if (document.forms['mailForm'].radio_znaczki[i].checked==true)
				id = document.forms['mailForm'].radio_znaczki[i].value;
		}
	}	
	karIdZnaczek = 'karIdZnaczek='+id;
	id = 0;
	if (document.forms['mailForm'].radio_papeteria.value > 0) {
		id = document.forms['mailForm'].radio_papeteria.value;
	} else {
		for (i=0;i<document.forms['mailForm'].radio_papeteria.length;i++){
			if (document.forms['mailForm'].radio_papeteria[i].checked==true)
				id = document.forms['mailForm'].radio_papeteria[i].value;
		}
	}
	karIdPapeteria = 'karIdPapeteria='+id;	
	adres = kadIdZjecia+'&'+karOdbEmail+'&'+karNadEmail+'&'+karNadNazwa+'&'+karTresc+'&'+karIdZnaczek+'&'+karIdPapeteria+'&'+karNaglowek;
	okienko('/kartki/odczyt/kartka.html?'+adres,'Podglad_kartki',600,800);
}


function okienko(adres, tytul, wys, szer)
{
	window.open(adres,"tytul", 'menubar=no, toolbar=no, location=no, scrollbars=yes, resizable=yes, status=no, width='+szer+', height='+wys);
}

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	var sfEls = document.getElementById("navHorizontal").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}	
}
//if (window.attachEvent) window.attachEvent("onload", sfHover);

// nowe okienko
/*
function noweOkno(url, nazwa, szerokosc, wysokosc) {
   x = (screen.width) ? (screen.width - szerokosc) / 2 : 0;
   y = (screen.height) ? (screen.height - wysokosc) / 2 : 0;
   window.open(url, nazwa, 'toolbar=0,location=0,directories=0,menubar=0,status=0,scrollbars=1,resizable=1,left=' + x + ',top=' + y + ',width=' + szerokosc + ',height=' + wysokosc);
}
*/

function noweOkno(file) {
 param = 'toolbar=0,directories=0,menubar=0,scrollbars=0,resizable=0,type=fullWindow,fullscreen,scrollbars=yes';
 window.open(file, 'Lębork', param);
} 