var pytanie  = 'Czy na pewno wykonać polecenie';
var poczta_trwa_synchronizacja = false;

//*********************************************************
//*********************************************************************
function checkKeyPressed(evt, func, params) //sprawdza czy nacisnieto enter i wywoluje funkcje z parametrami
{
  evt = (evt) ? evt : (window.event) ? event : null;
  if (evt)
  {
    var charCode = (evt.charCode) ? evt.charCode :
                   ((evt.keyCode) ? evt.keyCode :
                   ((evt.which) ? evt.which : 0));
    if (charCode == 13) func(params);
  }    
}

function makeLink(x, pole, link)
{

var y=document.getElementById(pole).value;
document.getElementById(x).href=link+""+y;



}

function wyswietlStrone(id, id_kl) {
	var y=document.getElementById(id).value;
	var y2 =document.getElementById(id_kl).value;
	
	if(y!="pusty" & y2!="none") window.location = "?dzial=crm&modul=oferty&fun=pokaz_szablon&plik="+y+"&klient="+y2;
	else alert("Nie wybrałeś klienta lub szablonu");
}

function openSzablonWindow(id_szabl, link, width, height) {
	var y=document.getElementById(id_szabl).value;
	if(y!="pusty") window.open(link+'&szablon='+y, 'cechy', 'scrollbars=yes,width='+width+',height='+height);
	else alert("Nie wybrałeś szablonu");
}

function wypelnijPole(pole, ktore, przycisk) {
	
	var y=document.getElementById(pole).value;
	
	if(y=='Rok' || y=='Autonumer') {
		document.getElementById(ktore).value=y;
		document.getElementById(ktore).disabled=true;
		document.getElementById(przycisk).disabled=false;
	
	}else {
		document.getElementById(ktore).disabled=false;
		document.getElementById(przycisk).disabled=true;
		document.getElementById(ktore).value="";
	}
}


function dodajWartoscDoPola(pole, skad, przycisk, selekcik) {
		var y=document.getElementById(skad).value;
		
		if(y=='Rok' || y=='Autonumer') {
			if(y=='Rok') y='(rok)';
			else if(y=='Autonumer') y='(autonumer)';
			document.getElementById(pole).value+=y;
		}else if(document.getElementById(selekcik).value=='Stała') {
			document.getElementById(pole).value+="["+y+"]";
			document.getElementById(skad).value="";
		
			document.getElementById(przycisk).disabled=true;
		}else {			
			document.getElementById(skad).value="";
	
			document.getElementById(przycisk).disabled=true;
		}
		
		
}

function sprawdzCzyPusty(pole, przycisk) {
		var y=document.getElementById(pole).value;
		if(y=='') document.getElementById(przycisk).disabled=true;
		else document.getElementById(przycisk).disabled=false;
}
function addFileForm(tableId) {
	var root=document.getElementById(tableId).getElementsByTagName('tr')[0].parentNode;
	var oR = cE('tr');
	var oC = cE('td');
	var oI = cE('input');
	var oS=cE('span')
	cA(oC,'align','center');
	cA(oI,'type','file');
	cA(oI,'name','plik[]');
	oS.style.cursor='pointer';
	oS.onclick=function() {
		this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode)
	}
	oS.appendChild(document.createTextNode(' Usuń'));
	oC.appendChild(oI);oC.appendChild(oS);oR.appendChild(oC);root.appendChild(oR);
}

function cE(el){
	this.obj =document.createElement(el);
	return this.obj;
}

function cA(obj,att,val){
	obj.setAttribute(att,val);
	return;
}

function wylacz_pole(id) {
	var tmp = document.getElementById(id);
	//alert(tmp.disabled);
	if (tmp) {
		var tmp2 = tmp.disabled;
		if (tmp2 == true) {
			//alert('aaa');
			tmp.disabled = false;
		} else {
			tmp.disabled = true;
		}
	}
}

function zaladuj_obrazek(id) {

	var img = document.getElementById(id);
	if (img) {
		var img2 = new Image();
		img2.src = img.src;			
	}
}

function disp_confirm()	
  {
  var abcd = window.confirm("Press a button");
  if (abcd == true)
    {
    window.alert("You pressed OK!")
    }
  else
    {
    window.alert("You pressed Cancel!")
    }
  }


function rozwin_galaz(id, napis) {
	var temp;
	temp = document.getElementById(id);
	if (temp) {
		if (temp.style.display == "none") temp.style.display = "block";
		else temp.style.display = "none";
	}
	if (napis.value == "-") napis.value = "+";
	else napis.value = "-";

}
	
function opcje_plikow (id_s, id_d) {

	var select = document.getElementById(id_s);
	var div = document.getElementById(id_d);

	if (select && div) {
		if (select.options[select.selectedIndex].value == 'plik') {
			div.style.display = 'block';
		} else {
			div.style.display = "none";
		}
	}
}
	
	

function zaznacz(name, bool) {
	var i;
	var elty;
	elty = document.getElementsByName(name);
	
	if (elty) {
		for(i=0;i<elty.length;i++) elty[i].checked = bool;
	}
}


function potwierdzenie(adres, polecenie)
{
  var potwierdzony = confirm(pytanie + ':\n' + polecenie);
  if (potwierdzony) adres.href += '&potwierdzony=1';

  return potwierdzony;
}

function spr_typ_pliku(id1, id2, name) {
			
	var file_input = document.getElementById(id1);
	var div = document.getElementById(id2);
	
	if (file_input && div) {

		var tab = 'unknown';
		if (typeof name == 'string') {
			tab = name.split('.');
		} else {
			tab = file_input.value.split('.');
		}
		var ext = tab[tab.length - 1];
			ext = ext.toLowerCase();
		var mini_input = div.getElementsByTagName('input');
		
		if (ext == 'jpg' || ext == 'jpeg' || ext == 'gif' || ext == 'png') {
			div.style.display = 'block';
			for (var i=0;i<mini_input.length;i++)
  			{ 
			  mini_input[i].disabled = false;
  		  	}
		} else {
			div.style.display = 'none';
			for (var i=0;i<mini_input.length;i++)
  			{ 
			  mini_input[i].disabled = true;
  		  	}
		}
	} 

}

function potwierdzenie_usuniecia(adres, nazwa)
{
  var potwierdzony = confirm('Czy na pewno chesz usunąć element : '+nazwa+'?');
  if (potwierdzony) adres.href += '&potwierdzony=1';

  return potwierdzony;
}

function potwierdzenie_usuniecia_proj(adres, nazwa)
{
  var potwierdzony = confirm('Czy na pewno chesz usunąć projekt : '+nazwa+'? Spowoduje to usunięcie wszystkich dodanych do niego materiałów.');
  if (potwierdzony) adres.href += '&potwierdzony=1';

  return potwierdzony;
}

function potwierdzenie_usuniecia_kat(adres, nazwa)
{
  var potwierdzony = confirm('Czy na pewno chesz usunąć kategorię : '+nazwa+'? Spowoduje to usunięcie wszystkich kategorii podrzędnych oraz artykułów przypisanych jedynie do nich.');
  if (potwierdzony) adres.href += '&potwierdzony=1';

  return potwierdzony;
}

function potwierdzenie_usuniecia_art(adres, nazwa)
{
  var potwierdzony = confirm('Czy na pewno chesz usunąć artykuł : '+nazwa+'? Spowoduje to usunięcie wszystkich plików przypisanych do niego.');
  if (potwierdzony) adres.href += '&potwierdzony=1';

  return potwierdzony;
}

var kolejny_typ_danych = 1;
function dodaj_pole_typ_danych(tbody, liczba)
{
	if (liczba > kolejny_typ_danych)
		kolejny_typ_danych = liczba;
		
	tab = document.getElementById('dane');

	tr = tab.insertRow(tab.rows.length);
	td = tr.insertCell(tr.cells.length);
	
  	td.style.textAlign = 'right';
	td.innerHTML = 'Nazwa atrybutu';
	
	td = tr.insertCell(tr.cells.length);
	td.innerHTML = '<input type="text" name="dane[nazwa][]" value="" id="dane'+kolejny_typ_danych+'"><input type="button" value="Usuń przy zapisywaniu" onClick="document.getElementById(\'dane'+kolejny_typ_danych+'\').value = \'\'">';
	
	tr = tab.insertRow(tab.rows.length);
	td = tr.insertCell(tr.cells.length);
	
	td.style.textAlign = 'right';
	td.innerHTML = 'Typ atrybutu';
	
	var wzor = document.getElementById('wzor');
	td = tr.insertCell(tr.cells.length);
	//td.innerHTML = '<select name="dane[typ][]"><option value="int">Liczba</option><option value="text">Tekst</option><option value="krotki_tekst">Krótki tekst</option><option value="data">Data</option><option value="tak_nie">Tak lub nie</option></select>';
	var temp = wzor.cloneNode(true);
	temp.name = "dane[typ][]";
	temp.id = 'select_'+kolejny_typ_danych;
	
	
	tr = tab.insertRow(tab.rows.length);
	tr.style.display = 'none';
	tr.id = 'opcje_plikow_'+kolejny_typ_danych;
	
	temp.onchange = function (){
		var x=this.id.split('_');
		opcje_plikow(this.id, 'opcje_plikow_'+x[x.length - 1]);
	}
	td.appendChild(temp);
	
	td = tr.insertCell(tr.cells.length);
	td.style.textAlign = 'right';
	td.innerHTML = 'Opcje plików';
	
	td = tr.insertCell(tr.cells.length);
	var wzor2 = document.getElementById('wzor_typy_mime');

	var temp2 = wzor2.getElementsByTagName('input');
	var temp3 = '';
	var label = '';
	
	for (i = 0; i < temp2.length; i++) {
		temp3 = temp2[i].cloneNode(true);

		temp3.name = 'dane[typy_mime]['+kolejny_typ_danych+'][]';
		temp3.id = 'typ_mime_'+kolejny_typ_danych+i;
		label = document.createElement('label');
		label.setAttribute('for', 'typ_mime_'+kolejny_typ_danych+i);
		label.appendChild(document.createTextNode(temp3.value));
		td.appendChild(temp3);
		td.appendChild(label);
		td.appendChild(document.createElement('br'));
			
	}
	
	var temp4 = document.createElement('div');
	temp4.appendChild(document.createTextNode('Wymiar miniatur'));
	var temp5 = document.createElement('input');
	temp5.type = 'text';
	temp5.name = 'dane[miniatury][]';
	temp4.appendChild(temp5);
	temp4.appendChild(document.createElement('br'));
	var temp6 = document.createElement('small');
	temp6.appendChild(document.createTextNode('Proszę podać wymiary miniatur oddzielone przecinkiem, brak wpisu oznacza brak miniatur.'));
	temp4.appendChild(temp6);
		
	td.appendChild(temp4);
	
	tr = tab.insertRow(tab.rows.length);
	td = tr.insertCell(tr.cells.length);
	
	td.style.textAlign = 'right';
	td.innerHTML = 'Opis atrybutu';
	
	td = tr.insertCell(tr.cells.length);
	td.innerHTML = '<textarea name="dane[opis][]" cols="40" rows="5"></textarea>';
	
	tr = tab.insertRow(tab.rows.length);
	td = tr.insertCell(tr.cells.length);
	
	td.style.textAlign = 'right';
	td.innerHTML = 'Regex - filtr zawartosci';
	
	td = tr.insertCell(tr.cells.length);
	td.innerHTML = '<input type="text" name="dane[regex][]" value="">';
	
	tr = tab.insertRow(tab.rows.length);
	td = tr.insertCell(tr.cells.length);
	
	td.style.textAlign = 'right';
	td.innerHTML = 'Opis formatu';
	
	td = tr.insertCell(tr.cells.length);
	td.innerHTML = '<textarea name="dane[opisf][]" cols="40" rows="5"></textarea>';
	
	
	
	
	tr = tab.insertRow(tab.rows.length);
	td = tr.insertCell(tr.cells.length);
	
	td.style.textAlign = 'right';
	td.innerHTML = 'Obowiązkowy';
	
	td = tr.insertCell(tr.cells.length);
	td.innerHTML = '<input type="checkbox" name="dane[obowiazkowy]['+kolejny_typ_danych+']" value="true">';
	
	
	tr = tab.insertRow(tab.rows.length);
	td = tr.insertCell(tr.cells.length);
	td.colSpan = 3;
	td.height = 4; 
	td.innerHTML = '<img src="/technik/img/piksel.gif" width="1" height="4">';
	tr = tab.insertRow(tab.rows.length);
	td = tr.insertCell(tr.cells.length);
	td.colSpan = 3;
	td.bgcolor = '#969696';
	td.style.background = 'url(/technik/img/intea/linia-szara-poziom.gif) repeat-x';
	td.height = 1;
	tr = tab.insertRow(tab.rows.length);
	td = tr.insertCell(tr.cells.length);
	td.colSpan = 3;
	td.height = 4; 
	td.innerHTML = '<img src="/technik/img/piksel.gif" width="1" height="4">';
	
	tr = tab.insertRow(tab.rows.length);
	td = tr.insertCell(tr.cells.length);
	
	td.style.textAlign = 'right';
	td.innerHTML = 'Sortowanie';
	
	td = tr.insertCell(tr.cells.length);
	td.innerHTML = '<input type="input" name="dane[sortowanie]['+kolejny_typ_danych+']" value="1">';
	
	
	tr = tab.insertRow(tab.rows.length);
	td = tr.insertCell(tr.cells.length);
	td.colSpan = 3;
	td.height = 4; 
	td.innerHTML = '<img src="/technik/img/piksel.gif" width="1" height="4">';
	tr = tab.insertRow(tab.rows.length);
	td = tr.insertCell(tr.cells.length);
	td.colSpan = 3;
	td.bgcolor = '#969696';
	td.style.background = 'url(/technik/img/intea/linia-szara-poziom.gif) repeat-x';
	td.height = 1;
	tr = tab.insertRow(tab.rows.length);
	td = tr.insertCell(tr.cells.length);
	td.colSpan = 3;
	td.height = 4; 
	td.innerHTML = '<img src="/technik/img/piksel.gif" width="1" height="4">';
	
	kolejny_typ_danych++;


}



function showDiv(id)
	{ 
  		if (document.getElementById(id).style.display == "block")
  		 document.getElementById(id).style.display = "none" 
  		else
  		 document.getElementById(id).style.display = "block"
   } 
	
function hideDiv(id)
	{ 
  		try
		{
  			document.getElementById(id).style.display = "none";
		}
		catch (err) {}
   } 


//przechwytywanie klawiszy
//do modułu Poczta
if (!document.all) document.captureEvents(Event.ONKEYDOWN);
  document.onkeydown = onKeyDownPoczta;

var id_wiadomosci = 0;

function onKeyDownPoczta(e)
{
	var keynum;
	var keychar;

	if(window.event) // IE
	{
		keynum = window.event.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}

	keychar = String.fromCharCode(keynum);
	
	//alert('Test: ' + keychar + '\n' + keynum + '\n');
		
	if (keynum == 46 && id_wiadomosci != 'undefinded' && id_wiadomosci != 0)
	{
		if(potwierdzenie(this, 'Usuń wiadomość'))
		{
			window.open('?dzial=crm&modul=poczta&fun=usun_wiadomosc&old_fun=panel&wiadomosc='+id_wiadomosci+'', 'Usun', 'resizable=yes,width=600,height=200,scrollbars=yes');
		}
	}
	
	if (keynum == 114 && document.getElementById('przelog_form'))
	{
		pokaz_element('przelog_form');
		if(document.getElementById('przelog_form').style.display == "block")
		{
			logowanie.uzytkownik.focus();
		}
		window.event.keyCode = 505;
		return false;
	}
	
	if (keynum == 27 && document.getElementById('przelog_form'))
	{
		if(document.getElementById('przelog_form').style.display == "block")
		{
			hideDiv('przelog_form');
		}
	}
		
}
	
	
/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
		currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3
    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }
    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function
function dodaj_zalacznik()
{
	var pole = document.getElementById('zalaczniki');
	var string = '<input type="file" name="zalacznik[]"></br>';
	pole.innerHTML += string;

}

var pierwszy_zablokowany = 1;
var mail_zablokowany = 1;

function odblokuj_zalacznik()
{
	if (pierwszy_zablokowany >10)
		return;
	var file = document.getElementById(pierwszy_zablokowany);
	file.style.display = 'block';
	pierwszy_zablokowany++;	
}

function odblokuj_pole_mail()
{
	if (mail_zablokowany >10)
		return;
	var file = document.getElementById('ekstra_do_'+mail_zablokowany);
	file.style.display = 'block';
	mail_zablokowany++;	
}

function sprawdz_mail(Obj){
		  		
	var reg = new RegExp('[a-zA-Z_0-9.]{3,}@[a-zA-Z_0-9.]{3,}','i');
	var wynik = reg.test(Obj.value);

	if (wynik)
	{
  		Obj.style.backgroundColor = 'blue';
  		var zapisz = document.getElementById('Zapisz').disabled = false;
	}
	else
	{
		Obj.style.backgroundColor = 'red';
		var zapisz = document.getElementById('Zapisz').disabled = true;
	}
}

var kolejny_mail = 1;
function dodaj_pole_mail(myDiv, liczba)
{
	if (liczba > kolejny_mail)
		kolejny_mail = liczba;
		
	if (myDiv)
	{
		myDiv.innerHTML += '</br><input type="text" name="email[]" value="" size="40"> - domyślny: <input type="checkbox" name="domyslny['+kolejny_mail+']">';
		kolejny_mail++;
	}
	else
	{
		alert('Nie znaleziono elemntu ! Błąd!!')
	}
}

function dodaj_pole_konto(myDiv)
{
	if (myDiv)
	{
		myDiv.innerHTML += '</br>Kod swift: <input type="text" name="kod_swift[]" value="" size="8"> Konto: <input type="text" name="konto_ban[]" value="" size="26">';
	}
	else
	{
		alert('Nie znaleziono elemntu '+myDiv+'! Błąd!!')
	}
}

var kolejny_mail_osoba = 1;

function dodaj_pole_mail_osoba(myDiv, liczba)
{
	if (liczba > kolejny_mail_osoba)
		kolejny_mail_osoba = liczba;
	if (myDiv)
	{
		myDiv.innerHTML += '</br><input type="text" name="osoba_kontaktowa[email][]" value="" size="40"> - domyślny: <input type="checkbox" name="osoba_kontaktowa[domyslny]['+kolejny_mail_osoba+']">';
		kolejny_mail_osoba++;
	}
	else
	{
		alert('Nie znaleziono elemntu ! Błąd!!')
	}
}


function obsluz_blok(myCheckBox, myDiv, name_prefix)
{
	var zazn = myCheckBox.checked;
	var inDiv;

	if (!zazn)
	{
		myDiv.style.display = 'none';
	}else {
		myDiv.style.display = 'block';
	}
	
	var i = 1;
	inDiv = document.getElementById(name_prefix+'_'+i);
	while (inDiv)
	{
		inDiv.checked = zazn;
		i++;
		inDiv = document.getElementById(name_prefix+'_'+i);
	}

}


//obsługa podświetlania do modułu poczta
var marked_row_poczta = 'undefinded';
var prevDefaultColor = '#FFFFFF';

function setPointerPoczta(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor, theMarkText)
{
	try
	{
	
    var theCells = null;
	 var theCellsPrev = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }
	 
	 if(marked_row_poczta != 'undefinded')
	 {
	 	 if (typeof(document.getElementsByTagName) != 'undefined') {
	        theCellsPrev = marked_row_poczta.getElementsByTagName('td');
	    }
	    else if (typeof(marked_row_poczta.cells) != 'undefined') {
	        theCellsPrev = marked_row_poczta.cells;
	    }
	    else {
	        return false;
	    }
	 }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
	 var standardText = '#000000';
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor != null && currentColor != '' && currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase())
	 {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
				
				var c = null;
        		if (domDetect)
				{
            	for (c = 0; c < rowCellsCnt; c++)
					{
               	theCells[c].setAttribute('bgcolor', newColor, 0);
            	}
        		}
        		else
				{
            	for (c = 0; c < rowCellsCnt; c++)
					{
                	theCells[c].style.backgroundColor = newColor;
            	}
        		}
        }
        else if (theAction == 'click' && theMarkColor != '') {
				if(marked_row_poczta != 'undefinded')
				{
					var p = null;
	        		if (domDetect)
					{
	            	for (p = 0; p < rowCellsCnt; p++)
						{
	               	theCellsPrev[p].setAttribute('bgcolor', prevDefaultColor, 0);
							theCellsPrev[p].style.color = standardText;
	            	}
	        		}
	        		else
					{
	            	for (p = 0; p < rowCellsCnt; p++)
						{
	                	theCellsPrev[p].style.backgroundColor = prevDefaultColor;
							theCellsPrev[p].style.color = standardText;
	            	}
	        		}
				}
					
            newColor = theMarkColor;
            marked_row_poczta = theRow;
				
				var c = null;
        		if (domDetect)
				{
            	for (c = 0; c < rowCellsCnt; c++)
					{
               	theCells[c].setAttribute('bgcolor', newColor, 0);
						theCells[c].style.color = theMarkText;
						theCells[c].style.fontWeight = 'normal';
            	}
        		}
        		else
				{
            	for (c = 0; c < rowCellsCnt; c++)
					{
                	theCells[c].style.backgroundColor = newColor;
						theCells[c].style.color = theMarkText;
						theCells[c].style.fontWeight = 'normal';
            	}
        		}
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase())
	 {
        if (theAction == 'out') {
            newColor = theDefaultColor;
				
				var c = null;
        		if (domDetect)
				{
            	for (c = 0; c < rowCellsCnt; c++)
					{
               	theCells[c].setAttribute('bgcolor', newColor, 0);
            	}
        		}
        		else
				{
            	for (c = 0; c < rowCellsCnt; c++)
					{
                	theCells[c].style.backgroundColor = newColor;
            	}
        		}
        }
        else if (theAction == 'click' && theMarkColor != '') {
        		if(marked_row_poczta != 'undefinded')
				{
					var p = null;
	        		if (domDetect)
					{
	            	for (p = 0; p < rowCellsCnt; p++)
						{
	               	theCellsPrev[p].setAttribute('bgcolor', prevDefaultColor, 0);
							theCellsPrev[p].style.color = standardText;
	            	}
	        		}
	        		else
					{
	            	for (p = 0; p < rowCellsCnt; p++)
						{
	                	theCellsPrev[p].style.backgroundColor = prevDefaultColor;
							theCellsPrev[p].style.color = standardText;
	            	}
	        		}
				}
				
				newColor = theMarkColor;
            marked_row_poczta = theRow;
            
				var c = null;
        		if (domDetect)
				{
            	for (c = 0; c < rowCellsCnt; c++)
					{
               	theCells[c].setAttribute('bgcolor', newColor, 0);
						theCells[c].style.color = theMarkText;
						theCells[c].style.fontWeight = 'normal';
            	}
        		}
        		else
				{
            	for (c = 0; c < rowCellsCnt; c++)
					{
                	theCells[c].style.backgroundColor = newColor;
						theCells[c].style.color = theMarkText;
						theCells[c].style.fontWeight = 'normal';
            	}
        		}
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
		  
    } // end 4
	
	}
	catch(err) { return false; }
	
    return true;
    
} // end of the 'setPointer()' function

function trim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function sprawdz_zawartosc_odblokuj(el_zawartosc,el_unlock)
{
	if (trim (document.getElementById(el_zawartosc).value) == '')
		document.getElementById(el_unlock).disabled=true;
	else
	{
		document.getElementById(el_unlock).disabled=false;
	}
	return false;
}

function scrollIfVisibleFocus(id,name,el_focus)
{
	if (document.getElementById(id).style.display == "block")
	{
		location.href=name;
		document.getElementById(el_focus).focus();
	} 
}

function disableEnterKey(e)
{
     var key;

     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox

     if(key == 13)
          return false;
     else
          return true;
}


var alerted	 = false;
var confirmed= false;



function sprawdzFormularz(element,pytanie)
{
	if(!alerted && element.value != '' )
	{
		if (confirmed=confirm(pytanie))//'Czy dodac adres do wskazanego klienta?'
		{
			alerted = true;
			//window.location=adres;
		}
		else
		{
			element.value = '';
			alerted=false;
		}
	}
	return confirmed;
}


function clearForm(myForm)
{
	for (var i=0;i<myForm.length;i++)
  {
  	myForm.elements[i].value='';
  }
}

function disableForm(myForm)
{
	for (var i=0;i<myForm.length;i++)
  {
  	myForm.elements[i].disabled=true;
  }
}

function numbersonly(myfield, e, dec)
{
	var key;
	var keychar;

	if (window.event)
	   key = window.event.keyCode;
	else if (e)
	   key = e.which;
	else
	   return true;
	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || 
	    (key==9) || (key==13) || (key==27) )
	   return true;

	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;

	// decimal point jump
	else if (dec && (keychar == "."))
	   {
	   myfield.form.elements[dec].focus();
	   return false;
	   }
	else
	   return false;
}

function enable_disable(id)
{ 
	if (document.getElementById(id).disabled == true)
		document.getElementById(id).disabled=false; 
	else
		document.getElementById(id).disabled=true;
}

function switch_image(id,src1,src2)
{
	var el=document.getElementById(id);
	//document.write(el.src);
	if (el.src.indexOf(src1)!=-1)
		el.src=el.src.replace(src1,src2);
	else 	if (el.src.indexOf(src2)!=-1)
		el.src=el.src.replace(src2,src1);
}

function anchoredAjaxPopup(anchorId,adres,tresc)
{
	var xmlHttp;
	try
	{
		//	 Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				alert("Twoja przeglądarka nie wspiera AJAXa!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState<4)
		{
			return overlib('<center><img src="technik/img/indicator.gif" class="fold" > Proszę czekać...</center>', WIDTH, 300, ANCHOR,anchorId, ANCHORALIGN, 'LL', 'UL',STICKY,FGCOLOR, '#C0DFF8',  BORDER, 1, TEXTSIZE, '10px', TEXTFONT , 'Verdana', MOUSEOFF,SHADOW,SHADOWOPACITY,75 );
		}
		if(xmlHttp.readyState==4)
		{
			return overlib(xmlHttp.responseText, WIDTH, 300, ANCHOR,anchorId, ANCHORALIGN, 'LL', 'UL',STICKY,FGCOLOR, '#C0DFF8',  BORDER, 1, TEXTSIZE, '10px', TEXTFONT , 'Verdana', MOUSEOFF,SHADOW,SHADOWOPACITY,75 );
		}
	}
	xmlHttp.open("GET",adres,true);
	xmlHttp.send(null);
}

function foldSave(debugID,adres,tresc)
{
	var xmlHttp;
	try
	{
		//	 Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//alert("Twoja przeglądarka nie wspiera AJAXa!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState==4)
		{
		}
	}
	xmlHttp.open("GET",adres,true);
	xmlHttp.send(null);
}
function ajaxFillElement(id,adres,tresc)
{
	if (tresc == '') tresc = 'Proszę czekać...';
	
	var xmlHttp;
	try
	{
		//	 Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//alert("Twoja przeglądarka nie wspiera AJAXa!");
				return false;
			}
		}
	}
	xmlHttp.onreadystatechange=function()
	{
		if(xmlHttp.readyState<4)
		{
			document.getElementById(id).innerHTML='<center><img src="technik/img/indicator.gif" class="fold" > '+tresc+'</center>';
		}
		
		if(xmlHttp.readyState==4)
		{
			document.getElementById(id).innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",adres,true);
	xmlHttp.send(null);
}

function typ_konta()
{
	var typ1=document.getElementById('typ1').selectedIndex;
	var typ2=document.getElementById('typ2').selectedIndex;
	switch(typ1)
	{
		case 0:
			document.getElementById('typ2').disabled=false;
			document.getElementById('typ2').options[1].disabled=false;
			if(typ2==1)
			{
				document.getElementById('rozrachunki').disabled=false;
			}
			else
			{
				document.getElementById('rozrachunki').disabled=true;
				document.getElementById('typ2').options[1].disabled=false;
			}
			break;
		case 1:
			document.getElementById('typ2').disabled=true;
			document.getElementById('rozrachunki').selectedIndex=2;
			document.getElementById('rozrachunki').disabled=true;
			break;
		case 2:
			document.getElementById('rozrachunki').selectedIndex=2;
			document.getElementById('typ2').options[1].disabled=true;
			document.getElementById('typ2').disabled=false;
			document.getElementById('rozrachunki').disabled=true;
			break;
	}
	
}

function wstaw_id_konta(id_konta, pole, zamknij)
{
	try
	{
		var czy_kart = document.getElementById('czy_kartoteka').value;
		if (czy_kart == 'tak')
		{
			var kart_id = document.getElementById('kartoteka_id').value;
			id_konta += '-'+kart_id;
		}
	}
	catch(err) {}
	
	window.opener.document.getElementById(pole).value = id_konta;
			
	if(zamknij == 'tak') window.close();
}

function pokaz_element(id)
{
    if (document.getElementById(id).style.display=="block")document.getElementById(id).style.display="none"
    else document.getElementById(id).style.display="block"
}

function rem_white_spaces(stringToRem)
{
	return stringToRem.replace(/\s/g,"");
}

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function ltrim(stringToTrim) {
	return stringToTrim.replace(/^\s+/,"");
}

function rtrim(stringToTrim) {
	return stringToTrim.replace(/\s+$/,"");
}

//pobiera wartość pola o podanym id i zwraca wartość typu float
function get_float(id, tofixed_n)
{
	var wartosc = document.getElementById(id).value;
	wartosc = rem_white_spaces(wartosc);
	if (typeof(tofixed_n) == 'undefined')
	{
		return parseFloat(wartosc);
	}
	return parseFloat((parseFloat(wartosc)).toFixed(tofixed_n));
}

function kwota_dodaj_spacje(kwota_str)
{
	var dlug = kwota_str.length;
	var i;
	for (i=dlug-7; i>=0; i -= 3)
	{
		kwota_str = kwota_str.substr(0, i+1)+' '+kwota_str.substr(i+1);
	}
	
	return kwota_str;
}

function formatuj_kwote(id)
{
	
	var kwota = document.getElementById(id).value;
	var wynik = '';
	
	if (trim(kwota) == '') 
	{
		document.getElementById(id).value='';
		return;
	}
	
	kwota = kwota.replace(',', '.');
	kwota = parseFloat(kwota);
	
	if (isNaN(kwota)) kwota = 0;
	
	wynik += parseInt(kwota);
	wynik += '.';
	
	var poPrzecinku = parseInt( (parseInt(Math.round(kwota*100))-parseInt(kwota)*100) );
	if (poPrzecinku >= 100) poPrzecinku = 99;
	
	if (poPrzecinku < 10) wynik += '0'+poPrzecinku; else wynik += poPrzecinku;
	
	document.getElementById(id).value = wynik;
}

var kolejny_mail = 1;
function dodaj_pole_mail(myDiv, liczba)
{
	if (liczba > kolejny_mail)
		kolejny_mail = liczba;
		
	if (myDiv)
	{
		myDiv.innerHTML += '</br><input type="text" name="email[]" value="" size="40"> - domyślny: <input type="checkbox" name="domyslny['+kolejny_mail+']">';
		kolejny_mail++;
	}
	else
	{
		alert('Nie znaleziono elemntu ! Błąd!!')
	}
}

var kolejne_przypomnienie = 1;
function dodaj_pole_przypomnienie(myDiv, liczba)
{
	if (liczba > kolejne_przypomnienie)
		kolejne_przypomnienie = liczba;
		
	if (myDiv)
	{
		myDiv.innerHTML += '<input type="radio" name="dni_czy_daty['+kolejne_przypomnienie+']" id="radjs'+kolejne_przypomnienie+'a" value="dni" checked> <label for="radjs'+kolejne_przypomnienie+'a">Ile dni wcześniej:</label> <input type="text" name="dni[]" value="" size="3" maxlength="3"> <input type="radio" name="dni_czy_daty['+kolejne_przypomnienie+']" id="radjs'+kolejne_przypomnienie+'b" value="daty"> <label for="radjs'+kolejne_przypomnienie+'b">Data:</label> <input type="text" name="daty[]" value="" size="6" onfocus="Calendar(\'divdatajs'+kolejne_przypomnienie+'\',this)"><div id="divdatajs'+kolejne_przypomnienie+'" class="clndr"></div><br/>';
		kolejne_przypomnienie++;
	}
	else
	{
		alert('Nie znaleziono elemntu ! Błąd!!')
	}
}

function poczta_okienko_synchro_start(adres, czas_ponownej_synchro)
{
	var obrazek = document.getElementById('img_reload').src = '../technik/img/indicator32.gif';
	document.getElementById('div_synchro').style.display = 'block';
	poczta_synchronizacja_ajax(adres, czas_ponownej_synchro);
}

function poczta_synchronizacja_ajax(adres, czas_ponownej_synchro)
{
	if (poczta_trwa_synchronizacja == true) return;
	poczta_trwa_synchronizacja = true;
	
	var xmlHttpPoczta;
	try
	{
		//	 Firefox, Opera 8.0+, Safari
		xmlHttpPoczta=new XMLHttpRequest();
	}
	catch (e)
	{
		// Internet Explorer
		try
		{
			xmlHttpPoczta=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				xmlHttpPoczta=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				//alert("Twoja przeglądarka nie wspiera AJAXa!");
				return false;
			}
		}
	}
	
	var lastSynchro = document.getElementById('input_now').value;
	
	xmlHttpPoczta.onreadystatechange=function()
	{
		if(xmlHttpPoczta.readyState<4)
		{
			document.getElementById('div_synchro').innerHTML='<b>Trwa sprawdzanie poczty...</b>';
		}
		
		if(xmlHttpPoczta.readyState==4)
		{
			var xmlResponse = xmlHttpPoczta.responseXML;
			var xmlRoot = xmlResponse.documentElement;
			var html = '';
			
			//alert('lastSynchro='+lastSynchro+'; now='+xmlAtr.item(0).firstChild.data);
			
			var xmlAtr = xmlRoot.getElementsByTagName('messages_number');
			if (parseInt(xmlAtr.item(0).firstChild.data) > 0)
			{
				var xmlMessages = xmlRoot.getElementsByTagName('messages').item(0).getElementsByTagName('message');
				var tabela = document.getElementById('tabela_wiadomosci');
				for (var i=0; i<xmlMessages.length; i++)
				{
					var xmlMessageAtr = xmlMessages.item(i).getElementsByTagName('id_wiadomosci');
					var id_wiadomosci = xmlMessageAtr.item(0).firstChild.data;
					var wstawione_id_wiad = id_wiadomosci;
					var zdarzenia = ' onClick="zmienLink(\''+id_wiadomosci+'\'); document.getElementById(\'tresc_wiadomosci\').src=\'?dzial=crm&modul=poczta&fun=wiadomosc_szczegoly&wiadomosc='+id_wiadomosci+'\';" ';
					
					var wiersz = tabela.insertRow(2);
					
					var komorka = wiersz.insertCell(0);
					komorka.colSpan = 9;
					komorka.innerHTML = '<div style="overflow: hidden; margin-top:4px; padding: 0px; height: 4px; background-color: #ffffff; border-top: 1px solid #888888;"></div>';
					wiersz = tabela.insertRow(2);
					komorka = wiersz.insertCell(0);
					komorka = wiersz.insertCell(1);
					komorka = wiersz.insertCell(2);
					komorka = wiersz.insertCell(3);
					komorka = wiersz.insertCell(4);
					
					komorka = wiersz.insertCell(5);
					komorka.innerHTML = '<div align="center"><input type="checkbox" name="do_usuniecia[]" value="'+id_wiadomosci+'"></div>';
					
					komorka = wiersz.insertCell(6);
					var xmlMessageAtr = xmlMessages.item(i).getElementsByTagName('from');
					var tekst_from = '';
					try
					{
						tekst_from = xmlMessageAtr.item(0).firstChild.data;
					}
					catch(err) {}
					
					komorka.innerHTML = '<a href="javascript:void(0);" '+zdarzenia+' style="cursor: default; text-decoration: none; font-size: 10px; font-weight: bold; color:#000000;"><div style="width:100%;">'+tekst_from+'</div></a>';
					
					komorka = wiersz.insertCell(7);
					var xmlMessageAtr = xmlMessages.item(i).getElementsByTagName('subject');
					var tekst_subject = '';
					try
					{
						tekst_subject = xmlMessageAtr.item(0).firstChild.data;
					}
					catch(err) {}
					
					komorka.innerHTML = '<a href="javascript:void(0);" '+zdarzenia+' style="cursor: default; text-decoration: none; font-size: 10px; font-weight: bold; color:#000000;"><div style="width:100%;">'+tekst_subject+'</div></a>';
					
					komorka = wiersz.insertCell(8);
					var xmlMessageAtr = xmlMessages.item(i).getElementsByTagName('data_dostarczenia');
					var tekst_data = '';
					try
					{
						tekst_data = xmlMessageAtr.item(0).firstChild.data;
					}
					catch(err) {}
					
					komorka.innerHTML = komorka.innerHTML = '<a href="javascript:void(0);" '+zdarzenia+' style="cursor: default; text-decoration: none; font-size: 10px; font-weight: bold; color:#000000;"><div style="width:100%; text-align:center;">'+tekst_data+'</div></a>';
				}
			}
			
			var xmlAtr = xmlRoot.getElementsByTagName('new_messages_number');
			if (xmlAtr.item(0).firstChild.data == 0)
			{
				html += '<b>Brak nowych wiadomości</b>';
			}
			else
			{
				var sufix = ' nowych wiadomości!';
				var iloscNowych = xmlAtr.item(0).firstChild.data;
				if (iloscNowych <= 4) sufix = ' nowe wiadomości!';
				if (iloscNowych == 1) sufix = ' nową wiadomość!';
				html += '<img border="0" src="../technik/img/intea/crm/korespondencja.gif" width="16" height="16" style="margin: 0px;" vspace="0" hspace="0" alt=""> <b>Masz '+iloscNowych+'. '+sufix+'</b>';
			}
			
			var xmlAtr = xmlRoot.getElementsByTagName('last_message_time');
			try
			{
				document.getElementById('input_now').value = xmlAtr.item(0).firstChild.data;
			}
			catch(err) {}
			
			document.getElementById('div_synchro').innerHTML=html;
			
			//document.getElementById('div_synchro').innerHTML=xmlHttpPoczta.responseText;
			
			var obrazek = document.getElementById('img_reload').src = '../technik/img/intea/crm/reload.gif';
			
			setTimeout('document.getElementById(\'div_synchro\').style.display=\'none\';', 5000);
			if (czas_ponownej_synchro>10000) 
			{
				setTimeout('poczta_okienko_synchro_start(\''+adres+'\', '+(parseInt(czas_ponownej_synchro)+5000)+')', czas_ponownej_synchro);
			}
			
			poczta_trwa_synchronizacja = false;
		}
	}
	
	xmlHttpPoczta.open("GET",adres+'&last_synchro='+lastSynchro,true);
	xmlHttpPoczta.send(null);
}

//obsluga menu pod prawym przyciskiem w CRM POCZTA
//wykrywanie typu przegladarki
var przie = false;
var przop = false;
if (document.all){ if (navigator.userAgent.search('Opera')>=0){ przie = false; przop = true;} else {przie = true; przop = false;}}
var prznn = (document.layers)?true:false;
var przn6 = (navigator.vendor == ("Netscape6") || navigator.product == ("Gecko"));

//funkcja przejmujaca darzenia wcisniecia klawisza myszki
function przyciski_myszki()
{
  if (prznn) document.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP | Event.MOUSECLICK);
	
  if(!przie)
  {
  	document.onmousedown = poczta_menu_prawy_przycisk_down;
  	document.onmouseup = poczta_menu_prawy_przycisk_up;
  }
	
  document.onclick = poczta_klikniecie;	
}

//funkcja obslugujaca mousedown
function poczta_menu_prawy_przycisk_down(e)
{
  var rightclick = false;
  
  try
  {
  if (prznn || przn6)
  {
  	  przycisk = e.which;
	  rightclick = (przycisk == 3);
  } else
  if (przie || przop)
  {
     przycisk = event.button;
	  rightclick = (przycisk == 2);
  }
  } catch (err) {}
  
  //alert('Rightclick: ' + rightclick); //true or false
	
  if(rightclick)
  {
	  if (prznn || przn6)
	    {
	    	x = e.pageX;
	    	y = e.pageY;
	    	ekran_x = e.screenX;
	    	ekran_y = e.screenY;
	    } else
	  if (przie)
	    {
	    	x = event.clientX + document.body.scrollLeft;
	    	y = event.clientY + document.body.scrollTop;
	    	ekran_x = event.screenX;
	    	ekran_y = event.screenY;
	    } else
	  if (przop)
	    {
	    	x = event.clientX;
	    	y = event.clientY;
	    	ekran_x = event.screenX;
	    	ekran_y = event.screenY;
	    }
		 
	  //alert('X: ' + x + ' Y: ' + x);
	  
		try
		{
			  /*
				if(prznn)
			    {
			    Left = document.layers['lista_wiadomosci'].left;
			    Top = document.layers['lista_wiadomosci'].top;
			    } else
			  if(przie || przop)
			    {
			    Left = document.all['lista_wiadomosci'].offsetLeft;
			    Top = document.all['lista_wiadomosci'].offsetTop;
			    } else
			  if(przn6)
			    {
			    Left = document.getElementById('lista_wiadomosci').offsetLeft;
			    Top = document.getElementById('lista_wiadomosci').offsetTop;
			    }
				*/
				document.getElementById('menu_pp').style.display = "block";
				
				//alert(Left+' '+Top);
				
			  if(prznn)
			    {
			    	document.layers['menu_pp'].left = x;
			    	document.layers['menu_pp'].top = y;
			    } else
			  if(przie || przop)
			    {
			    	document.all['menu_pp'].style.left = x;
			    	document.all['menu_pp'].style.top = y;	
			    } else
			  if(przn6)
			    {
			    	document.getElementById('menu_pp').style.left = x;
			    	document.getElementById('menu_pp').style.top = y;
			    }
		}
		catch(err) {}
  }		
	
	return false;
//koniec funkcji...
}

//funkcja obslugujaca mouseup
function poczta_menu_prawy_przycisk_up(e)
{
  	document.oncontextmenu = context;
	return false;	
}

//funkcja obslugujaca mousclick
function poczta_klikniecie(e)
{
	if(document.getElementById('menu_pp'))
	{
		if(document.getElementById('menu_pp').style.display == "block")
			document.getElementById('menu_pp').style.display = "none";
	}
}

function context()
{
//This function takes care of Net 6 and IE.
	return false;
}


function Calendar(E,T, pola)
{
 if (pola) ukryj(pola, 0);

 if(!document.getElementById||!document.body.appendChild)return
 var i,j,tBody,Row,od,Do,d,dt
 function cEl(t,p,h,w){
  p.appendChild(t=document.createElement(t))
  if(h)t.innerHTML=h;if(w)t.style.width='27px'
  return t}
 function cB(x){with(cld_BlaTek){
  B=0;x==0?R--:x==1?R++:x==2?(!M?(M=11,R--):M--):(M==11?(M=0,R++):M++)}
 }
 with(cld_BlaTek){
  od=Date.UTC(R,M,1);Do=Date.UTC(R,M+1,1)}
 E=document.getElementById(E)
 while(E.childNodes.length)E.removeChild(E.firstChild)
 tBody=cEl('tbody',cEl('table',E))
 tBody.onmouseup=function(){T.focus()}
 tBody.onmousemove=function(){
  if(window.getSelection)window.getSelection().removeAllRanges()}
 Row=cEl('tr',tBody)
 cEl('td',Row,'«',1).onmousedown=function(){cB(0)}
 cEl('th',Row,cld_BlaTek.R)
 cEl('td',Row,'»',1).onmousedown=function(){cB(1)}
 Row=cEl('tr',tBody)
 cEl('td',Row,'«',1).onmousedown=function(){cB(2)}
 cEl('th',Row,cld_BlaTek.month[cld_BlaTek.M])
 cEl('td',Row,'»',1).onmousedown=function(){cB(3)}

 tBody=cEl('tbody',cEl('table',E))
 Row=cEl('tr',tBody)
 for(i=0;i<7;i++)
  with(cEl('th',Row,cld_BlaTek.day[i]))
   if(i==6)style.backgroundColor='#f88'

 for(i=od;i<Do;i+=86400000){
  with(new Date(i)){d=getUTCDate();dt=getUTCDay()}
  if(dt==1||i==od)Row=cEl('tr',tBody)
  if(dt!=1&&d==1)for(j=1;j<(dt?dt:7);j++)cEl('th',Row)
  dt=cEl('td',Row,d);dt.onmousedown=function(x){
   x=+this.innerHTML
   with(cld_BlaTek)
    {
    dzien = (x<10?'0'+x:x);
    miesiac = ((x=M+1)<10?'0'+x:x);
    
    T.value=R+'-'+miesiac+'-'+dzien
    }
  }
  with(cld_BlaTek)
  if(d==D.getDate()&&M==D.getMonth()&&R==D.getFullYear())
   dt.style.backgroundColor='#62A0FF'
 }
 T.onblur=function()
 {
  if(cld_BlaTek.B)E.style.display='none'
  //ukryj(pola, 1);	jak sie gdzies wyjebie do odkomentowac
 }
 cld_BlaTek.B=1;E.style.display='block'
}

function ukryj(pola, tryb)
  {
    for( var i = 0; i < pola.length ; i++)
	 {
	   if (document.getElementById(pola[i]))
		{
	     if (tryb == 0)
			document.getElementById(pola[i]).style.visibility="hidden"
		  else
		   document.getElementById(pola[i]).style.visibility="visible"
		}
	 }
  }	


//global object (You can translate month&day names)
cld_BlaTek={
 day:['pn','wt','śr','cz','pt','so','n'],
 month:['styczeń','luty','marzec','kwiecień','maj','czerwiec',
 'lipiec','sierpień','wrzesień','październik','listopad','grudzień'],
 D:new Date(),M:new Date().getMonth(),R:new Date().getFullYear()
}

//dodaje pole typu FILE do bloku
function dodaj_pole_file(nazwa, kontener)
{
	var nowe_pole = document.createElement('input');
	nowe_pole.setAttribute('type', 'file');
	nowe_pole.setAttribute('name', nazwa);
	
	var br = document.createElement('br');
	
	var dodac_do = document.getElementById(kontener);
	
	dodac_do.appendChild(nowe_pole);
	dodac_do.appendChild(br);
}

function otworz_plik_zalacznik(id_pola_file, id) {
	var sciezka = document.getElementById(id_pola_file).value;
	if(sciezka=='') alert("Pole jest puste!");
	else {
	//alert("C:\Documents and Settings\tomek\Pulpit\ofer_normsalna.rtf");
	open.window("C:\Documents and Settings\tomek\Pulpit\ofer_normsalna.rtf");
	
	}
}

function dodaj_pole_file_zalaczniki(nazwa, kontener, nazwa_opisu)
{
	var rows = document.getElementById(kontener).getElementsByTagName('tr');
	var rowsCount =rows.length;
	var nowe_pole = document.createElement('input');
	nowe_pole.setAttribute('type', 'file');
	nowe_pole.setAttribute('name', nazwa);
	nowe_pole.setAttribute('id', "up"+rowsCount);
	
	
	var nowe_pole_opis = document.createElement('input');
	nowe_pole_opis.setAttribute('type', 'text');
	nowe_pole_opis.setAttribute('name', nazwa_opisu);
	
	var br = document.createElement('br');
	var p = document.createElement('p');
		
	var dodac_do = document.getElementById(kontener);
	
	var hr = document.createElement('hr');
	
	var label = document.createElement("span");
  	label.innerHTML = "Opis: ";
	
	var imgLupa = document.createElement("img");
	imgLupa.setAttribute('id', rowsCount);
	imgLupa.setAttribute('src', "technik/img/intea/crm/search.gif");
	imgLupa.setAttribute('width', 16);
	imgLupa.setAttribute('height', 16);
	imgLupa.setAttribute('style', "cursor:pointer");
	imgLupa.setAttribute('alt', "Podgląd załącznika");
	imgLupa.setAttribute('onclick', "otworz_plik_zalacznik('up"+rowsCount+"',"+rowsCount+")");
	imgLupa.setAttribute('onmouseover', "Tip(\'Podgląd załącznika\', SHADOW, true, SHADOWWIDTH, 2, FADEIN, 200, FADEOUT, 200, WIDTH, 140, BGCOLOR, \'#F5F5DC\')");
	//var imgLupa = document.createElement("span");
	//imgLupa.innerHTML = "&nbsp;&nbsp;<img id="+rows+" src='technik/img/intea/crm/search.gif' width='16' height='16' style='cursor:pointer' alt='Obejrzyj plik'>";
	
	var strzalka = document.createElement("span");
	strzalka.innerHTML = "<img src='technik/img/intea/crm/strzalka.gif' width='7' height='7' >&nbsp;";
	
	var tr = document.createElement("tr");
	var td = document.createElement("td");
	
	
	
	td.appendChild(strzalka);
	td.appendChild(nowe_pole);
	td.appendChild(imgLupa);
	td.appendChild(br);
	td.appendChild(label);
	td.appendChild(nowe_pole_opis);
	td.appendChild(hr);
	td.appendChild(p);
	tr.appendChild(td);
	dodac_do.appendChild(tr);
}

//dodaje dwukropek do godziny i zero na poczatku jesli pierwsza cyfra >=3
function dodaj_dwukropek(Obj)
{
   var reg1 = /^[0-9]{2}$/;
   if (Obj.value.length == 1) {
	if (Obj.value >= 3)
		Obj.value = '0' + Obj.value;
	}
   if (Obj.value.length == 2 && reg1.exec(Obj.value))
	Obj.value = Obj.value + ':';
}
function sprawdz_godzine(Obj)
{
   var co = Obj;
   var reg1 = /^[0-1]?[0-9]:[0-5][0-9]$/;
   var reg2 = /^2[0-3]:[0-5][0-9]$/;
   if ( (!reg1.exec(co.value)) && (!reg2.exec(co.value)) ) {co.style.backgroundColor = "red";}
	   else {co.style.backgroundColor = "white";}
   if (co.value=="") co.style.backgroundColor = "white";
}
