// JavaScript Document

//-----------------------------------sprawdzanie czy email sie nie powtarza--------------------------------
function profil_sprawdz_email(){
/*
sprawdzono
*/
	//pokazanie loading
	$("uwaga_email").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var email1 = $("email1").value;
	var url = 'xmlphp/profil_sprawdz_email.php';
	var pars = 'email=' + email1;
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: SR_profil_sprawdz_email							  
		}
	);
}

function SR_profil_sprawdz_email(originalRequest){
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	
	//pobranie ilosc
	var ilosc = xmlResponse.getElementsByTagName("email").item(0).firstChild.data;
	//wypisanie komunikatu
	
	if (ilosc>0){
		$("uwaga_email").innerHTML = "Wprowadzony adres email istnieje ju&#x17C; w bazie.";
	}
	else {
		$("uwaga_email").innerHTML = "";
	}
	
}

//-----------------------------------wybieranie pracodawcy z listy--------------------------------
function profil_pracodawca_wybierz(){
	var firma = $("firma").value;
	if (firma.length > 2){
		if ($("uwaga_firma")){
			$("uwaga_firma").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
		}
		var url = 'xmlphp/profil_pracodawca_wybierz.php';
		var pars = 'firma=' + firma;
		var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: pars,
				onComplete: SR_profil_pracodawca_wybierz							  
			}
		);
	}
	else {
		$("scroll").style.visibility = 'hidden';
	}
	
}

function SR_profil_pracodawca_wybierz(originalRequest){
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	
	var html = "<table cellpadding='0' cellspacing='0'>";
	//firmy i miasta
	var firmy_array = xmlRoot.getElementsByTagName("firma");
	var miasta_array = xmlRoot.getElementsByTagName("miasto");
	var firma_czysta_array = xmlRoot.getElementsByTagName("firma_czysta");
	for (var i=0; i<firmy_array.length; i++){
		html += "<tr>";
		html += "<td><a href='javascript:profil_pracodawca_scroll(\"" + firma_czysta_array.item(i).firstChild.data + "\", \"" + miasta_array.item(i).firstChild.data + "\")'>" + firmy_array.item(i).firstChild.data + " - " + miasta_array.item(i).firstChild.data + "</a></td>";
		html += "</tr>";
	}
	
	html += "</table>";
	$("scroll").innerHTML = html;
	//pojawienie sie tylko gdy mamy jakies wyniki
	if (firmy_array.length > 0){
		$("scroll").style.visibility = 'visible';
	}
	else {
		$("scroll").style.visibility = 'hidden';
	}
	if ($("uwaga_firma")){
		$("uwaga_firma").innerHTML = "";
	}
	
}

function profil_pracodawca_scroll(firma, miasto){
	if ($("scroll")){
		$("scroll").style.visibility = 'hidden';
	}
	$("firma").value = firma;
	$("miasto").value = miasto;
}

//-----------------------------------dodaj doswiadczenie zawodowe--------------------------------
function profil_dodaj_doswiadczenie(){

/*
sprawdzono
*/
	var miesiac_rozpoczecia = parseInt($("miesiac_rozpoczecia").value);
	var rok_rozpoczecia = parseInt($("rok_rozpoczecia").value);
	var miesiac_zakonczenia = parseInt($("miesiac_zakonczenia").value);
	var rok_zakonczenia = parseInt($("rok_zakonczenia").value);
	var firma = $("firma").value;
	var miasto = $("miasto").value;
	var stanowisko = $("stanowisko").value;
	var czynnosci = $("czynnosci").value.replace(/<br>/i, "__newline__").replace(/<br\/>/i, "__newline__"); // "__newline__" zostanie pozniej zamienione na "\n"
	
	var ok = true;
	var komunikat;
	//sprawdzenie poprawnosci danych
	if (rok_zakonczenia < rok_rozpoczecia){
		ok = false;
		komunikat = "Wprowadz poprawna date rozpoczecia i zakonczenia.";
	}
	if ((rok_zakonczenia == rok_rozpoczecia) & (miesiac_zakonczenia < miesiac_rozpoczecia)){
		ok = false;
		komunikat = "Wprowadz poprawna date rozpoczecia i zakonczenia.";
	}
	if ((firma == "") || (miasto == "")){
		ok = false;
		komunikat = "Uzupelnij nazwe oraz miasto siedziby firmy.";
	}
	if ((rok_zakonczenia == "") & (miesiac_zakonczenia == "") & (firma != "") & (miasto != "")){
		ok = true;
	}
	
	if (ok){
		$("uwaga_firma").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
		
		var url = 'xmlphp/profil_dodaj_doswiadczenie.php';
		var pars = 'miesiac_rozpoczecia=' + miesiac_rozpoczecia + "&rok_rozpoczecia=" + rok_rozpoczecia + "&miesiac_zakonczenia=" + miesiac_zakonczenia + "&rok_zakonczenia=" + rok_zakonczenia + "&firma=" + firma + "&miasto=" + miasto + "&stanowisko=" + stanowisko + "&czynnosci=" + czynnosci;
		var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: pars,
				onComplete: SR_profil_dodaj_doswiadczenie							  
			}
		);
		
	}
	
	else {
		alert(komunikat);	
	}
}



function profil_dodaj_doswiadczenie2(){

/*
sprawdzono
*/
	var miesiac_rozpoczecia = parseInt($("miesiac_rozpoczecia").value);
	var rok_rozpoczecia = parseInt($("rok_rozpoczecia").value);
	var miesiac_zakonczenia = parseInt($("miesiac_zakonczenia").value);
	var rok_zakonczenia = parseInt($("rok_zakonczenia").value);
	var firma = $("firma").value;
	var miasto = $("miasto").value;
	var stanowisko = $("stanowisko").value;
	var czynnosci = $("czynnosci").value.replace(/<br>/i, "__newline__").replace(/<br\/>/i, "__newline__"); // "__newline__" zostanie pozniej zamienione na "\n"
	
	var ok = true;
	var komunikat;
	//sprawdzenie poprawnosci danych
	if (rok_zakonczenia < rok_rozpoczecia){
		ok = false;
		komunikat = "Wprowadz poprawna date rozpoczecia i zakonczenia.";
	}
	if ((rok_zakonczenia == rok_rozpoczecia) & (miesiac_zakonczenia < miesiac_rozpoczecia)){
		ok = false;
		komunikat = "Wprowadz poprawna date rozpoczecia i zakonczenia.";
	}
	if ((firma == "") || (miasto == "")){
		ok = false;
		komunikat = "Uzupelnij nazwe oraz miasto siedziby firmy.";
	}
	if ((rok_zakonczenia == "") & (miesiac_zakonczenia == "") & (firma != "") & (miasto != "")){
		ok = true;
	}
	
	if (ok){
		$("uwaga_firma").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
		
		var url = 'dodaj_doswiadczenie.php';
		var pars = 'miesiac_rozpoczecia=' + miesiac_rozpoczecia + "&rok_rozpoczecia=" + rok_rozpoczecia + "&miesiac_zakonczenia=" + miesiac_zakonczenia + "&rok_zakonczenia=" + rok_zakonczenia + "&firma=" + firma + "&miasto=" + miasto + "&stanowisko=" + stanowisko + "&czynnosci=" + czynnosci;
		var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: pars,
				onComplete: SR_profil_dodaj_doswiadczenie2							  
			}
		);
		
	}
	
	else {
		alert(komunikat);	
	}
}



function SR_profil_dodaj_doswiadczenie2(originalRequest){
//alert('tets');
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	//$("uwaga").innerHTML = 'test';
	var id_doswiadczenia_array = xmlRoot.getElementsByTagName("id_doswiadczenia");
	var id_pracodawcy_array = xmlRoot.getElementsByTagName("id_pracodawcy");
	var data_rozpoczecia_array = xmlRoot.getElementsByTagName("data_rozpoczecia");
	var data_zakonczenia_array = xmlRoot.getElementsByTagName("data_zakonczenia");
	var stanowisko_array = xmlRoot.getElementsByTagName("stanowisko");
	var wykonywane_czynnosci_array = xmlRoot.getElementsByTagName("wykonywane_czynnosci");
	var nazwa_firmy_array = xmlRoot.getElementsByTagName("nazwa_firmy");
	var miasto_array = xmlRoot.getElementsByTagName("miasto");
	
	var html = "<table cellpadding='0' cellspacing='0' width='100%'>";
	
	for (var i=0; i<id_doswiadczenia_array.length; i++){
		html += "<tr>";
		html += "<td class='profil_rejestracja_text'>";
		html += data_rozpoczecia_array.item(i).firstChild.data + " - " + data_zakonczenia_array.item(i).firstChild.data;
		html += "</td>";
		html += "<td class='profil_rejestracja_input'><div class='ogranicznik_szerokosci'>";
		html += nazwa_firmy_array.item(i).firstChild.data + "<br/>";
		html += miasto_array.item(i).firstChild.data + "<br/>";
		if (stanowisko_array.item(i).firstChild.data != "0"){
			html += stanowisko_array.item(i).firstChild.data + "<br/>";	
		}
		if (wykonywane_czynnosci_array.item(i).firstChild.data != "0"){
			html += wykonywane_czynnosci_array.item(i).firstChild.data + "<br/>";	
		}
		html += "</div></td>";
		html += "<td class='profil_rejestracja_uwaga'>";
		html += "</td>";
		html += "</tr>";
		
		html += "<tr>";
		html += "<td class='profil_rejestracja_text'>";

        //przesuwanie
    	if (i > 0) {
    		html += "<a href='javascript:profil_przesun_doswiadczenie(" + id_doswiadczenia_array.item(i).firstChild.data + ", \"g\")'><img src='images/arrow_up.png' alt='Przesuń w górę' title='Przesuń w górę' border='0' /></a>";
    	}
    	if (i < id_doswiadczenia_array.length - 1) {
    		html += "<a href='javascript:profil_przesun_doswiadczenie(" + id_doswiadczenia_array.item(i).firstChild.data + ", \"d\")'><img src='images/arrow_down.png' alt='Przesuń w dół' title='Przesuń w dół' border='0' /></a>";
    	}

		html += "<a href='javascript:profil_usun_doswiadczenie(" + id_doswiadczenia_array.item(i).firstChild.data + ")'><img src='images/btn_usun.jpg' alt='usun' border='0' /></a>";
		html += "<a href='javascript:profil_edytuj_doswiadczenie(" + id_doswiadczenia_array.item(i).firstChild.data + ")'><img src='images/btn_edytuj.jpg' alt='edytuj' border='0' /></a>";
		html += "</td>";
		html += "<td class='profil_rejestracja_input'>";
		html += "</td>";
		html += "<td class='profil_rejestracja_uwaga'>";
		html += "</td>";
		html += "</tr>";
	}
	
	html += "</table>";
	
	$("profil_doswiadczenie").innerHTML = html;
	$("uwaga_firma").innerHTML = "";
	$("firma").value = "";
	$("miasto").value = "";
	$("stanowisko").value = "";
	$("czynnosci").value = "";
}

//-----------------------------------przesun doswiadczenie--------------------------------
function profil_przesun_doswiadczenie(id_doswiadczenia, kierunek){
/*
sprawdzono
*/
    if (kierunek != 'g') {
        kierunek = 'd';
    }

	$("uwaga_firma").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var url = 'xmlphp/profil_przesun_doswiadczenie.php';
	var pars = 'id_doswiadczenia=' + parseInt(id_doswiadczenia) + "&kierunek=" + kierunek;
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: SR_profil_dodaj_doswiadczenie							  
		}
	);
}

//-----------------------------------usun doswiadczenie--------------------------------
function profil_usun_doswiadczenie(id_doswiadczenia){
/*
sprawdzono
*/
	$("uwaga_firma").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var url = 'xmlphp/profil_usun_doswiadczenie.php';
	var pars = 'id_doswiadczenia=' + id_doswiadczenia;
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: SR_profil_usun_doswiadczenie							  
		}
	);
}

function SR_profil_usun_doswiadczenie(originalRequest){
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	
	var html = "<table cellpadding='0' cellspacing='0' width='100%'>";
	
	var id_doswiadczenia_array = xmlRoot.getElementsByTagName("id_doswiadczenia");
	var id_pracodawcy_array = xmlRoot.getElementsByTagName("id_pracodawcy");
	var data_rozpoczecia_array = xmlRoot.getElementsByTagName("data_rozpoczecia");
	var data_zakonczenia_array = xmlRoot.getElementsByTagName("data_zakonczenia");
	var stanowisko_array = xmlRoot.getElementsByTagName("stanowisko");
	var wykonywane_czynnosci_array = xmlRoot.getElementsByTagName("wykonywane_czynnosci");
	var nazwa_firmy_array = xmlRoot.getElementsByTagName("nazwa_firmy");
	var miasto_array = xmlRoot.getElementsByTagName("miasto");
	
	for (var i=0; i<id_doswiadczenia_array.length; i++){
		html += "<tr>";
		html += "<td class='profil_rejestracja_text'>";
		html += data_rozpoczecia_array.item(i).firstChild.data + " - " + data_zakonczenia_array.item(i).firstChild.data;
		html += "</td>";
		html += "<td class='profil_rejestracja_input'><div class='ogranicznik_szerokosci'>";
		html += nazwa_firmy_array.item(i).firstChild.data + "<br/>";
		html += miasto_array.item(i).firstChild.data + "<br/>";
		if (stanowisko_array.item(i).firstChild.data != "0"){
			html += stanowisko_array.item(i).firstChild.data + "<br/>";	
		}
		if (wykonywane_czynnosci_array.item(i).firstChild.data != "0"){
			html += wykonywane_czynnosci_array.item(i).firstChild.data + "<br/>";	
		}
		html += "</div></td>";
		html += "<td class='profil_rejestracja_uwaga'>";
		html += "</td>";
		html += "</tr>";
		
		html += "<tr>";
		html += "<td class='profil_rejestracja_text'>";

        //przesuwanie
    	if (i > 0) {
    		html += "<a href='javascript:profil_przesun_doswiadczenie(" + id_doswiadczenia_array.item(i).firstChild.data + ", \"g\")'><img src='images/arrow_up.png' alt='Przesuń w górę' title='Przesuń w górę' border='0' /></a>";
    	}
    	if (i < id_doswiadczenia_array.length - 1) {
    		html += "<a href='javascript:profil_przesun_doswiadczenie(" + id_doswiadczenia_array.item(i).firstChild.data + ", \"d\")'><img src='images/arrow_down.png' alt='Przesuń w dół' title='Przesuń w dół' border='0' /></a>";
    	}

		html += "<a href='javascript:profil_usun_doswiadczenie(" + id_doswiadczenia_array.item(i).firstChild.data + ")'><img src='images/btn_usun.jpg' alt='usun' border='0' /></a>";
		html += "<a href='javascript:profil_edytuj_doswiadczenie(" + id_doswiadczenia_array.item(i).firstChild.data + ")'><img src='images/btn_edytuj.jpg' alt='edytuj' border='0' /></a>";
		html += "</td>";
		html += "<td class='profil_rejestracja_input'>";
		html += "</td>";
		html += "<td class='profil_rejestracja_uwaga'>";
		html += "</td>";
		html += "</tr>";
	}
	
	html += "</table>";
	
	$("profil_doswiadczenie").innerHTML = html;
	$("uwaga_firma").innerHTML = "";
}

//-----------------------------------edytuj doswiadczenie--------------------------------
function profil_edytuj_doswiadczenie(id_doswiadczenia){
/*
sprawdzono
*/
	$$(".wiersz_formatki_dodawania_doswiadczenia").each(function(s) {Element.hide(s)});
	$("uwaga_firma").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var url = 'xmlphp/profil_edytuj_doswiadczenie.php';
	var pars = 'id_doswiadczenia=' + id_doswiadczenia;
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: SR_profil_edytuj_doswiadczenie							  
		}
	);
}

function SR_profil_edytuj_doswiadczenie(originalRequest){
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	
	var html = "<table cellpadding='0' cellspacing='0' width='100%'>";
	
	var id_doswiadczenia_do_edycji = xmlRoot.getElementsByTagName("id_doswiadczenia_do_edycji").item(0).firstChild.data;
	var obecny_rok = parseInt(xmlRoot.getElementsByTagName("obecny_rok").item(0).firstChild.data);
	var id_doswiadczenia_array = xmlRoot.getElementsByTagName("id_doswiadczenia");
	var id_pracodawcy_array = xmlRoot.getElementsByTagName("id_pracodawcy");
	var miesiac_rozpoczecia_array = xmlRoot.getElementsByTagName("miesiac_rozpoczecia");
	var rok_rozpoczecia_array = xmlRoot.getElementsByTagName("rok_rozpoczecia");
	var miesiac_zakonczenia_array = xmlRoot.getElementsByTagName("miesiac_zakonczenia");
	var rok_zakonczenia_array = xmlRoot.getElementsByTagName("rok_zakonczenia");
	var stanowisko_array = xmlRoot.getElementsByTagName("stanowisko");
	var wykonywane_czynnosci_array = xmlRoot.getElementsByTagName("wykonywane_czynnosci");
	var nazwa_firmy_array = xmlRoot.getElementsByTagName("nazwa_firmy");
	var miasto_array = xmlRoot.getElementsByTagName("miasto");
	
	for (var i=0; i<id_doswiadczenia_array.length; i++){
		if (id_doswiadczenia_array.item(i).firstChild.data == id_doswiadczenia_do_edycji) {
		
		    var miesiac_rozpoczecia_options = "";
		    for (var k = 12; k >= 1; k--) {
		        if (k == miesiac_rozpoczecia_array.item(i).firstChild.data) {
		            var selected = "selected='selected'";
		        } else {
		            var selected = "";
		        }
		        miesiac_rozpoczecia_options += "<option value='"+k+"' "+selected+">"+k+"</option>";
		    }
		
		    var rok_rozpoczecia_options = "";
		    for (var k = obecny_rok; k >= 1950; k--) {
		        if (k == rok_rozpoczecia_array.item(i).firstChild.data) {
		            var selected = "selected='selected'";
		        } else {
		            var selected = "";
		        }
		        rok_rozpoczecia_options += "<option value='"+k+"' "+selected+">"+k+"</option>";
		    }
		
		    var miesiac_zakonczenia_options = "<option>teraz</option>";
		    if (miesiac_zakonczenia_array.item(i).firstChild.data == 0) {
		        miesiac_zakonczenia_options = "<option selected='selected'>teraz</option>";
		    }
		    for (var k = 12; k >= 1; k--) {
		        if (k == miesiac_zakonczenia_array.item(i).firstChild.data) {
		            var selected = "selected='selected'";
		        } else {
		            var selected = "";
		        }
		        miesiac_zakonczenia_options += "<option value='"+k+"' "+selected+">"+k+"</option>";
		    }
		
		    var rok_zakonczenia_options = "<option>teraz</option>";
		    if (rok_zakonczenia_array.item(i).firstChild.data == 0) {
		        rok_zakonczenia_options = "<option selected='selected'>teraz</option>";
		    }
		    for (var k = obecny_rok; k >= 1950; k--) {
		        if (k == rok_zakonczenia_array.item(i).firstChild.data) {
		            var selected = "selected='selected'";
		        } else {
		            var selected = "";
		        }
		        rok_zakonczenia_options += "<option value='"+k+"' "+selected+">"+k+"</option>";
		    }
		
		    html += "\
                <tr>\
                	<td class='profil_rejestracja_text'>\
                    	<select name='miesiac_rozpoczecia' id='edycja_miesiac_rozpoczecia' class='input_select'>\
                        	" + miesiac_rozpoczecia_options + "\
                        </select>\
                    	.\
                        <select name='rok_rozpoczecia' id='edycja_rok_rozpoczecia' class='input_select'>\
                        	" + rok_rozpoczecia_options + "\
                        </select>\
                        -\
                        <select name='miesiac_zakonczenia' id='edycja_miesiac_zakonczenia' class='input_select'>\
                        	" + miesiac_zakonczenia_options + "\
                        </select>\
                        .\
                        <select name='rok_zakonczenia' id='edycja_rok_zakonczenia' class='input_select'>\
                        	" + rok_zakonczenia_options + "\
                        </select>\
                        <br /><span class='small_text'>mies. i rok rozp.<span class='red_small_text'>*</span> - mies. i rok zak.</span>\
                    </td>\
                    <td class='profil_rejestracja_input'>\
                        <input type='text' name='firma' id='edycja_firma' onFocus='javascript:\
                                var options = {\
                                script: function (input) { return (\'xmlphp/autocom_wyb_prac.php?input=\'+input); },\
                                callback: function (obj) { $(\'edycja_miasto\').value=obj.info; }\
                                };\
                                var xml=new AutoComplete(\'edycja_firma\',options);return true;'\
                                value='" + nazwa_firmy_array.item(i).firstChild.data + "' />\
                        <br/>\
                        <span class='small_text'>Nazwa firmy.</span><span class='red_small_text'>*</span><br />\
                        </span><span id='edycja_xml_info'></span>\
\
                        <input type='text' name='miasto' id='edycja_miasto' value='" + miasto_array.item(i).firstChild.data + "'/><br /><span class='small_text'>Miasto siedziby firmy.</span><span class='red_small_text'>*</span><br />\
					    <input type='text' name='stanowisko' id='edycja_stanowisko' value='" + stanowisko_array.item(i).firstChild.data + "'/><br /><span class='small_text'>Stanowisko.</span><br />\
                        <textarea name='czynnosci' id='edycja_czynnosci' rows='6' cols='' class='input_textarea'>" + wykonywane_czynnosci_array.item(i).firstChild.data + "</textarea><br /><span class='small_text'>Opis wykonywanych czynności.</span>\
                    </td>\
                    <td class='profil_rejestracja_uwaga' valign='top' id='edycja_uwaga_firma'></td>\
                </tr>\
                <tr>\
                	<td></td>\
                    <td class='profil_rejestracja_text'>\
                    	<a href='javascript:profil_pokaz_doswiadczenie()'><img src='images/btn_anuluj.jpg' border='0' alt='anuluj edycje' /></a>\
                    	<a href='javascript:profil_zapisz_doswiadczenie(" + id_doswiadczenia_do_edycji + ")'><img src='images/btn_zapisz.jpg' border='0' alt='zapisz doswiadczenie' /></a>\
                   	</td>\
                    <td></td>\
                </tr>\
		    ";
		} else {
	    }
	}
	
	html += "</table>";

	$("profil_doswiadczenie").innerHTML = html;
	$("uwaga_firma").innerHTML = "";
}

//-----------------------------------zapisz doswiadczenie--------------------------------
function profil_zapisz_doswiadczenie(id_doswiadczenia){
	$$(".wiersz_formatki_dodawania_doswiadczenia").each(function(s) {Element.show(s)});

	var miesiac_rozpoczecia = parseInt($("edycja_miesiac_rozpoczecia").value);
	var rok_rozpoczecia = parseInt($("edycja_rok_rozpoczecia").value);
	var miesiac_zakonczenia = parseInt($("edycja_miesiac_zakonczenia").value);
	var rok_zakonczenia = parseInt($("edycja_rok_zakonczenia").value);
	var firma = $("edycja_firma").value;
	var miasto = $("edycja_miasto").value;
	var stanowisko = $("edycja_stanowisko").value;
	var czynnosci = $("edycja_czynnosci").value.replace(/<br>/i, "__newline__").replace(/<br\/>/i, "__newline__"); // "__newline__" zostanie pozniej zamienione na "\n"
	
	var ok = true;
	var komunikat;
	//sprawdzenie poprawnosci danych
	if (rok_zakonczenia < rok_rozpoczecia){
		ok = false;
		komunikat = "Wprowadz poprawna date rozpoczecia i zakonczenia.";
	}
	if ((rok_zakonczenia == rok_rozpoczecia) & (miesiac_zakonczenia < miesiac_rozpoczecia)){
		ok = false;
		komunikat = "Wprowadz poprawna date rozpoczecia i zakonczenia.";
	}
	if ((firma == "") || (miasto == "")){
		ok = false;
		komunikat = "Uzupelnij nazwe oraz miasto siedziby firmy.";
	}
	if ((rok_zakonczenia == "") & (miesiac_zakonczenia == "") & (firma != "") & (miasto != "")){
		ok = true;
	}
	
	if (ok){
		$("uwaga_firma").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
		
		var url = 'xmlphp/profil_zapisz_doswiadczenie.php';
		var pars = 'id_doswiadczenia=' + id_doswiadczenia + '&miesiac_rozpoczecia=' + miesiac_rozpoczecia + "&rok_rozpoczecia=" + rok_rozpoczecia + "&miesiac_zakonczenia=" + miesiac_zakonczenia + "&rok_zakonczenia=" + rok_zakonczenia + "&firma=" + firma + "&miasto=" + miasto + "&stanowisko=" + stanowisko + "&czynnosci=" + czynnosci;
		var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: pars,
				onComplete: SR_profil_dodaj_doswiadczenie							  
			}
		);
	}
	else {
		alert(komunikat);	
	}
}

//-----------------------------------pokaz normalnie doswiadczenie--------------------------------
function profil_pokaz_doswiadczenie(){
/*
sprawdzono
*/
	$$(".wiersz_formatki_dodawania_doswiadczenia").each(function(s) {Element.show(s)});
	$("uwaga_firma").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var url = 'xmlphp/profil_pokaz_doswiadczenie.php';
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			onComplete: SR_profil_dodaj_doswiadczenie							  
		}
	);
}

//-----------------------------------dodaj edukacje--------------------------------
function profil_dodaj_edukacje(){
	var rok_rozpoczecia = $("rok_rozpoczecia_edu").value;
	var rok_zakonczenia = $("rok_zakonczenia_edu").value;
	var uczelnia = $("uczelnia").value;
	var kierunek = $("kierunek").value;
	var poziom = $("poziom").value;
	
	if (((rok_zakonczenia >= rok_rozpoczecia) || (rok_zakonczenia == "")) & (uczelnia != "")){
		$("uwaga_edukacja").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
		
		var url = 'xmlphp/profil_dodaj_edukacje.php';
		var pars = 'rok_rozpoczecia=' + rok_rozpoczecia + "&rok_zakonczenia=" + rok_zakonczenia + "&uczelnia=" + uczelnia + "&kierunek=" + kierunek + "&poziom=" + poziom;
		var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: pars,
				onComplete: SR_profil_dodaj_edukacje							  
			}
		);
	}
	else {
		alert("Niepoprawne daty rozpoczecia i zakonczenia edukacji lub niewypelnione pole nazwy uczelni.");	
	}
}

function SR_profil_dodaj_edukacje(originalRequest){
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	
	var html = "<table cellpadding='0' cellspacing='0' width='100%'>";
	
	var id_edukacji_array = xmlRoot.getElementsByTagName("id_edukacji");
	var rok_rozpoczecia_array = xmlRoot.getElementsByTagName("rok_rozpoczecia");
	var rok_zakonczenia_array = xmlRoot.getElementsByTagName("rok_zakonczenia");
	var nazwa_uczelni_array = xmlRoot.getElementsByTagName("nazwa_uczelni");
	var kierunek_array = xmlRoot.getElementsByTagName("kierunek");
	var poziom_array = xmlRoot.getElementsByTagName("poziom");
	var rok_zakonczenia;
	
	for (var i=0; i<id_edukacji_array.length; i++){
		html += "<tr>";
		html += "<td class='profil_rejestracja_text'>";
		if (rok_zakonczenia_array.item(i).firstChild.data == "0"){
			rok_zakonczenia = "trwa";	
		}
		else {
			rok_zakonczenia = rok_zakonczenia_array.item(i).firstChild.data;
		}
		html += rok_rozpoczecia_array.item(i).firstChild.data + " - " + rok_zakonczenia;
		html += "</td>";
		html += "<td class='profil_rejestracja_input'><div class='ogranicznik_szerokosci'>";
		html += nazwa_uczelni_array.item(i).firstChild.data + "<br/>";
		if (kierunek_array.item(i).firstChild.data != "brak"){
			html += kierunek_array.item(i).firstChild.data + "<br/>";	
		}
		if (poziom_array.item(i).firstChild.data != "brak"){
			html += poziom_array.item(i).firstChild.data + "<br/>";	
		}
		html += "</div></td>";
		html += "<td class='profil_rejestracja_uwaga'>";
		html += "</td>";
		html += "</tr>";
		
		html += "<tr>";
		html += "<td class='profil_rejestracja_text'>";

        //przesuwanie
    	if (i > 0) {
    		html += "<a href='javascript:profil_przesun_edukacje(" + id_edukacji_array.item(i).firstChild.data + ", \"g\")'><img src='images/arrow_up.png' alt='Przesuń w górę' title='Przesuń w górę' border='0' /></a>";
    	}
    	if (i < id_edukacji_array.length - 1) {
    		html += "<a href='javascript:profil_przesun_edukacje(" + id_edukacji_array.item(i).firstChild.data + ", \"d\")'><img src='images/arrow_down.png' alt='Przesuń w dół' title='Przesuń w dół' border='0' /></a>";
    	}

		html += "<a href='javascript:profil_usun_edukacje(" + id_edukacji_array.item(i).firstChild.data + ")'><img src='images/btn_usun.jpg' alt='usun' border='0' /></a>";
		html += "<a href='javascript:profil_edytuj_edukacje(" + id_edukacji_array.item(i).firstChild.data + ")'><img src='images/btn_edytuj.jpg' alt='edytuj' border='0' /></a>";
		html += "</td>";
		html += "<td class='profil_rejestracja_input'>";
		html += "</td>";
		html += "<td class='profil_rejestracja_uwaga'>";
		html += "</td>";
		html += "</tr>";
	}
	
	html += "</table>";
	
	$("profil_edukacja").innerHTML = html;
	$("uwaga_edukacja").innerHTML = "";
	$("uczelnia").value = "";
	$("kierunek").value = "";
	$("poziom").value = "";
}

//-----------------------------------przesun edukacje--------------------------------
function profil_przesun_edukacje(id_edukacji, kierunek){
/*
sprawdzono
*/
    if (kierunek != 'g') {
        kierunek = 'd';
    }

	$("uwaga_edukacja").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var url = 'xmlphp/profil_przesun_edukacje.php';
	var pars = 'id_edukacji=' + parseInt(id_edukacji) + "&kierunek=" + kierunek;
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: SR_profil_dodaj_edukacje							  
		}
	);
}

//-----------------------------------usun edukacje--------------------------------
function profil_usun_edukacje(id_edukacji){
	$("uwaga_edukacja").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var url = 'xmlphp/profil_usun_edukacje.php';
	var pars = 'id_edukacji=' + id_edukacji;
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: SR_profil_usun_edukacje							  
		}
	);
}

function SR_profil_usun_edukacje(originalRequest){
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	
	var html = "<table cellpadding='0' cellspacing='0' width='100%'>";
	
	var id_edukacji_array = xmlRoot.getElementsByTagName("id_edukacji");
	var rok_rozpoczecia_array = xmlRoot.getElementsByTagName("rok_rozpoczecia");
	var rok_zakonczenia_array = xmlRoot.getElementsByTagName("rok_zakonczenia");
	var nazwa_uczelni_array = xmlRoot.getElementsByTagName("nazwa_uczelni");
	var kierunek_array = xmlRoot.getElementsByTagName("kierunek");
	var poziom_array = xmlRoot.getElementsByTagName("poziom");
	var rok_zakonczenia;
	
	for (var i=0; i<id_edukacji_array.length; i++){
		html += "<tr>";
		html += "<td class='profil_rejestracja_text'>";
		if (rok_zakonczenia_array.item(i).firstChild.data == "0"){
			rok_zakonczenia = "trwa";	
		}
		else {
			rok_zakonczenia = rok_zakonczenia_array.item(i).firstChild.data;
		}
		html += rok_rozpoczecia_array.item(i).firstChild.data + " - " + rok_zakonczenia;
		html += "</td>";
		html += "<td class='profil_rejestracja_input'><div class='ogranicznik_szerokosci'>";
		html += nazwa_uczelni_array.item(i).firstChild.data + "<br/>";
		if (kierunek_array.item(i).firstChild.data != "brak"){
			html += kierunek_array.item(i).firstChild.data + "<br/>";	
		}
		if (poziom_array.item(i).firstChild.data != "brak"){
			html += poziom_array.item(i).firstChild.data + "<br/>";	
		}
		html += "</div></td>";
		html += "<td class='profil_rejestracja_uwaga'>";
		html += "</td>";
		html += "</tr>";
		
		html += "<tr>";
		html += "<td class='profil_rejestracja_text'>";

        //przesuwanie
    	if (i > 0) {
    		html += "<a href='javascript:profil_przesun_edukacje(" + id_edukacji_array.item(i).firstChild.data + ", \"g\")'><img src='images/arrow_up.png' alt='Przesuń w górę' title='Przesuń w górę' border='0' /></a>";
    	}
    	if (i < id_edukacji_array.length - 1) {
    		html += "<a href='javascript:profil_przesun_edukacje(" + id_edukacji_array.item(i).firstChild.data + ", \"d\")'><img src='images/arrow_down.png' alt='Przesuń w dół' title='Przesuń w dół' border='0' /></a>";
    	}

		html += "<a href='javascript:profil_usun_edukacje(" + id_edukacji_array.item(i).firstChild.data + ")'><img src='images/btn_usun.jpg' alt='usun' border='0' /></a>";
		html += "<a href='javascript:profil_edytuj_edukacje(" + id_edukacji_array.item(i).firstChild.data + ")'><img src='images/btn_edytuj.jpg' alt='edytuj' border='0' /></a>";
		html += "</td>";
		html += "<td class='profil_rejestracja_input'>";
		html += "</td>";
		html += "<td class='profil_rejestracja_uwaga'>";
		html += "</td>";
		html += "</tr>";
	}
	
	html += "</table>";
	
	$("profil_edukacja").innerHTML = html;
	$("uwaga_edukacja").innerHTML = "";
	$("uczelnia").value = "";
	$("kierunek").value = "";
	$("poziom").value = "";
}
//-----------------------------------edytuj edukacje--------------------------------
function profil_edytuj_edukacje(id_edukacji){
/*
sprawdzono
*/
	$$(".wiersz_formatki_dodawania_edukacji").each(function(s) {Element.hide(s)});
	$("uwaga_edukacja").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var url = 'xmlphp/profil_edytuj_edukacje.php';
	var pars = 'id_edukacji=' + id_edukacji;
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: SR_profil_edytuj_edukacje							  
		}
	);
}

function SR_profil_edytuj_edukacje(originalRequest){
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	
	var html = "<table cellpadding='0' cellspacing='0' width='100%'>";
	
	var id_edukacji_do_edycji = xmlRoot.getElementsByTagName("id_edukacji_do_edycji").item(0).firstChild.data;
	var obecny_rok = parseInt(xmlRoot.getElementsByTagName("obecny_rok").item(0).firstChild.data);
	var id_edukacji_array = xmlRoot.getElementsByTagName("id_edukacji");
	var rok_rozpoczecia_array = xmlRoot.getElementsByTagName("rok_rozpoczecia");
	var rok_zakonczenia_array = xmlRoot.getElementsByTagName("rok_zakonczenia");
	var nazwa_uczelni_array = xmlRoot.getElementsByTagName("nazwa_uczelni");
	var kierunek_array = xmlRoot.getElementsByTagName("kierunek");
	var poziom_array = xmlRoot.getElementsByTagName("poziom");
	var rok_zakonczenia;
	
	for (var i=0; i<id_edukacji_array.length; i++){
		if (id_edukacji_array.item(i).firstChild.data == id_edukacji_do_edycji) {
		
		    var rok_rozpoczecia_options = "";
		    for (var k = obecny_rok; k >= 1950; k--) {
		        if (k == rok_rozpoczecia_array.item(i).firstChild.data) {
		            var selected = "selected='selected'";
		        } else {
		            var selected = "";
		        }
		        rok_rozpoczecia_options += "<option value='"+k+"' "+selected+">"+k+"</option>";
		    }
		
		
		    var rok_zakonczenia_options = "<option> </option>";
		    for (var k = obecny_rok + 7; k >= 1950; k--) {
		        if (k == rok_zakonczenia_array.item(i).firstChild.data) {
		            var selected = "selected='selected'";
		        } else {
		            var selected = "";
		        }
		        rok_zakonczenia_options += "<option value='"+k+"' "+selected+">"+k+"</option>";
		    }

		    html += "\
                <tr>\
                	<td class='profil_rejestracja_text' valign='top'>\
                    	<select name='rok_rozpoczecia' id='edycja_rok_rozpoczecia_edu' class='input_select'>\
                        	" + rok_rozpoczecia_options + "\
                        </select>\
                        -\
                        <select name='rok_zakonczenia' id='edycja_rok_zakonczenia_edu' class='input_select'>\
                        	" + rok_zakonczenia_options + "\
                        </select>\
                        <br /><span class='small_text'>rok rozp.<span class='red_small_text'>*</span> - rok zak.</span>\
                    </td>\
                    <td class='profil_rejestracja_input'>\
                        <input type='text' name='uczelnia' id='edycja_uczelnia' value='" + nazwa_uczelni_array.item(i).firstChild.data + "'/><br />\
                    	<span class='small_text'>Nazwa uczelni/szkoły.</span><span class='red_small_text'>*</span><br />\
                        <input type='text' name='kierunek' id='edycja_kierunek' value='" + kierunek_array.item(i).firstChild.data + "'/><br />\
                        <span class='small_text'>Kierunek.</span><br />\
					    <input type='text' name='poziom' id='edycja_poziom' value='" + poziom_array.item(i).firstChild.data + "'/><br />\
                        <span class='small_text'>Poziom studiów.</span><br />\
                    </td>\
                    <td class='profil_rejestracja_uwaga' id='edycja_uwaga_edukacja' valign='top'></td>\
                </tr>\
                <tr>\
                	<td></td>\
                    <td class='profil_rejestracja_text'>\
                    	<a href='javascript:profil_pokaz_edukacje()'><img src='images/btn_anuluj.jpg' border='0' alt='anuluj edycje' /></a>\
                    	<a href='javascript:profil_zapisz_edukacje(" + id_edukacji_do_edycji + ")'><img src='images/btn_zapisz.jpg' border='0' alt='zapisz edukacje' /></a>\
                   	</td>\
                    <td class='profil_rejestracja_uwaga'></td>\
                </tr>\
		    ";
		} else {
	    }
	}
	
	html += "</table>";
	
	$("profil_edukacja").innerHTML = html;
	$("uwaga_edukacja").innerHTML = "";
}

//-----------------------------------zapisz edukacje--------------------------------
function profil_zapisz_edukacje(id_edukacji){
	$$(".wiersz_formatki_dodawania_edukacji").each(function(s) {Element.show(s)});

	var rok_rozpoczecia = $("edycja_rok_rozpoczecia_edu").value;
	var rok_zakonczenia = $("edycja_rok_zakonczenia_edu").value;
	var uczelnia = $("edycja_uczelnia").value;
	var kierunek = $("edycja_kierunek").value;
	var poziom = $("edycja_poziom").value;
	
	if (((rok_zakonczenia >= rok_rozpoczecia) || (rok_zakonczenia == "")) & (uczelnia != "")){
		$("uwaga_edukacja").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
		
		var url = 'xmlphp/profil_zapisz_edukacje.php';
		var pars = 'id_edukacji=' + id_edukacji + '&rok_rozpoczecia=' + rok_rozpoczecia + "&rok_zakonczenia=" + rok_zakonczenia + "&uczelnia=" + uczelnia + "&kierunek=" + kierunek + "&poziom=" + poziom;
		var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: pars,
				onComplete: SR_profil_dodaj_edukacje							  
			}
		);
	}
	else {
		alert("Niepoprawne daty rozpoczecia i zakonczenia edukacji lub niewypelnione pole nazwy uczelni.");	
	}
}

//-----------------------------------pokaz normalnie edukacje--------------------------------
function profil_pokaz_edukacje(){
/*
sprawdzono
*/
	$$(".wiersz_formatki_dodawania_edukacji").each(function(s) {Element.show(s)});
	$("uwaga_edukacja").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var url = 'xmlphp/profil_pokaz_edukacje.php';
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			onComplete: SR_profil_dodaj_edukacje							  
		}
	);
}

//-----------------------------------dodaj certyfikat--------------------------------
function profil_dodaj_certyfikat(){
	var certyfikat = $("certyfikat").value;
	
	if (certyfikat != ""){
		$("uwaga_certyfikat").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
		
		var url = 'xmlphp/profil_dodaj_certyfikat.php';
		var pars = 'certyfikat=' + certyfikat;
		var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: pars,
				onComplete: SR_profil_dodaj_certyfikat							  
			}
		);
	}
	else {
		alert("Podaj nazwe certyfikatu.");	
	}
}

function SR_profil_dodaj_certyfikat(originalRequest){
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	
	var html = "<table cellpadding='0' cellspacing='0' width='100%'>";
	
	var id_certyfikatu_array = xmlRoot.getElementsByTagName("id_certyfikatu");
	var nazwa_array = xmlRoot.getElementsByTagName("nazwa");
	
	for (var i=0; i<id_certyfikatu_array.length; i++){
		html += "<tr>";
		html += "<td>";
		html += "</td>";
		html += "<td class='profil_rejestracja_input'><div class='ogranicznik_szerokosci'>";
		html += nazwa_array.item(i).firstChild.data;
		html += "</div></td>";
		html += "<td class='profil_rejestracja_uwaga'>";
		html += "</td>";
		html += "</tr>";
		html += "<tr>";
		html += "<td class='profil_rejestracja_text'>";
		html += "</td>";
		html += "<td class='profil_rejestracja_input'>";

        //przesuwanie
    	if (i > 0) {
    		html += "<a href='javascript:profil_przesun_certyfikat(" + id_certyfikatu_array.item(i).firstChild.data + ", \"g\")'><img src='images/arrow_up.png' alt='Przesuń w górę' title='Przesuń w górę' border='0' /></a>";
    	}
    	if (i < id_certyfikatu_array.length - 1) {
    		html += "<a href='javascript:profil_przesun_certyfikat(" + id_certyfikatu_array.item(i).firstChild.data + ", \"d\")'><img src='images/arrow_down.png' alt='Przesuń w dół' title='Przesuń w dół' border='0' /></a>";
    	}

		html += "<a href='javascript:profil_usun_certyfikat(" + id_certyfikatu_array.item(i).firstChild.data + ")'><img src='images/btn_usun.jpg' alt='usun' border='0' /></a>";
		html += "<a href='javascript:profil_edytuj_certyfikat(" + id_certyfikatu_array.item(i).firstChild.data + ")'><img src='images/btn_edytuj.jpg' alt='edytuj' border='0' /></a>";
		html += "</td>";
		html += "<td class='profil_rejestracja_uwaga'>";
		html += "</td>";
		html += "</tr>";
	}
	
	html += "</table>";
	
	$("profil_certyfikaty").innerHTML = html;
	$("uwaga_certyfikat").innerHTML = "";
	$("certyfikat").value = "";
}

//-----------------------------------przesun certyfikat--------------------------------
function profil_przesun_certyfikat(id_certyfikatu, kierunek){
/*
sprawdzono
*/
    if (kierunek != 'g') {
        kierunek = 'd';
    }

	$("uwaga_certyfikat").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var url = 'xmlphp/profil_przesun_certyfikat.php';
	var pars = 'id_certyfikatu=' + parseInt(id_certyfikatu) + "&kierunek=" + kierunek;
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: SR_profil_dodaj_certyfikat							  
		}
	);
}

//-----------------------------------usun certyfikat--------------------------------
function profil_usun_certyfikat(id_certyfikatu){
	$("uwaga_certyfikat").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
		
	var url = 'xmlphp/profil_usun_certyfikat.php';
	var pars = 'id_certyfikatu=' + id_certyfikatu;
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: SR_profil_usun_certyfikat							  
		}
	);
}

function SR_profil_usun_certyfikat(originalRequest){
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	
	var html = "<table cellpadding='0' cellspacing='0' width='100%'>";
	
	var id_certyfikatu_array = xmlRoot.getElementsByTagName("id_certyfikatu");
	var nazwa_array = xmlRoot.getElementsByTagName("nazwa");
	
	for (var i=0; i<id_certyfikatu_array.length; i++){
		html += "<tr>";
		html += "<td>";
		html += "</td>";
		html += "<td class='profil_rejestracja_input'><div class='ogranicznik_szerokosci'>";
		html += nazwa_array.item(i).firstChild.data;
		html += "</div></td>";
		html += "<td class='profil_rejestracja_uwaga'>";
		html += "</td>";
		html += "</tr>";
		html += "<tr>";
		html += "<td class='profil_rejestracja_text'>";
		html += "</td>";
		html += "<td class='profil_rejestracja_input'>";

        //przesuwanie
    	if (i > 0) {
    		html += "<a href='javascript:profil_przesun_certyfikat(" + id_certyfikatu_array.item(i).firstChild.data + ", \"g\")'><img src='images/arrow_up.png' alt='Przesuń w górę' title='Przesuń w górę' border='0' /></a>";
    	}
    	if (i < id_certyfikatu_array.length - 1) {
    		html += "<a href='javascript:profil_przesun_certyfikat(" + id_certyfikatu_array.item(i).firstChild.data + ", \"d\")'><img src='images/arrow_down.png' alt='Przesuń w dół' title='Przesuń w dół' border='0' /></a>";
    	}

		html += "<a href='javascript:profil_usun_certyfikat(" + id_certyfikatu_array.item(i).firstChild.data + ")'><img src='images/btn_usun.jpg' alt='usun' border='0' /></a>";
		html += "<a href='javascript:profil_edytuj_certyfikat(" + id_certyfikatu_array.item(i).firstChild.data + ")'><img src='images/btn_edytuj.jpg' alt='edytuj' border='0' /></a>";
		html += "</td>";
		html += "<td class='profil_rejestracja_uwaga'>";
		html += "</td>";
		html += "</tr>";
	}
	
	html += "</table>";
	
	$("profil_certyfikaty").innerHTML = html;
	$("uwaga_certyfikat").innerHTML = "";
}
//-----------------------------------edytuj certyfikat--------------------------------
function profil_edytuj_certyfikat(id_certyfikatu){
	$$(".wiersz_formatki_dodawania_certyfikatu").each(function(s) {Element.hide(s)});
	$("uwaga_certyfikat").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var url = 'xmlphp/profil_edytuj_certyfikat.php';
	var pars = 'id_certyfikatu=' + id_certyfikatu;
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: SR_profil_edytuj_certyfikat							  
		}
	);
}

function SR_profil_edytuj_certyfikat(originalRequest){
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	
	var html = "<table cellpadding='0' cellspacing='0' width='100%'>";
	
	var id_certyfikatu_do_edycji = xmlRoot.getElementsByTagName("id_certyfikatu_do_edycji").item(0).firstChild.data;
	var id_certyfikatu_array = xmlRoot.getElementsByTagName("id_certyfikatu");
	var nazwa_array = xmlRoot.getElementsByTagName("nazwa");
	
	for (var i=0; i<id_certyfikatu_array.length; i++){
		if (id_certyfikatu_array.item(i).firstChild.data == id_certyfikatu_do_edycji) {
		    html += "\
                <tr>\
                	<td class='profil_rejestracja_text'>Nazwa <span class='red_text'>*</span></td>\
                    <td class='profil_rejestracja_input'>\
                        <textarea name='certyfikat' id='edycja_certyfikat' rows='6' cols='' class='input_textarea'>" + nazwa_array.item(i).firstChild.data + "</textarea><br />\
                    </td>\
                    <td class='profil_rejestracja_uwaga' id='edycja_uwaga_certyfikat' valign='top'></td>\
                </tr>\
                <tr>\
                	<td></td>\
                    <td class='profil_rejestracja_text'>\
                    	<a href='javascript:profil_pokaz_certyfikaty()'><img src='images/btn_anuluj.jpg' border='0' alt='anuluj edycje' /></a>\
                    	<a href='javascript:profil_zapisz_certyfikat(" + id_certyfikatu_do_edycji + ")'><img src='images/btn_zapisz.jpg' border='0' alt='zapisz certyfikat' /></a>\
                   	</td>\
                    <td class='profil_rejestracja_uwaga'></td>\
                </tr>\
		    ";
		} else {
	    }
	}
	
	html += "</table>";
	
	$("profil_certyfikaty").innerHTML = html;
	$("uwaga_certyfikat").innerHTML = "";
	$("certyfikat").value = "";
}

//-----------------------------------zapisz certyfikat--------------------------------
function profil_zapisz_certyfikat(id_certyfikatu){
	$$(".wiersz_formatki_dodawania_certyfikatu").each(function(s) {Element.show(s)});

	var certyfikat = $("edycja_certyfikat").value;
	
	if (certyfikat != ""){
		$("uwaga_certyfikat").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
		
		var url = 'xmlphp/profil_zapisz_certyfikat.php';
		var pars = 'id_certyfikatu=' + id_certyfikatu + '&certyfikat=' + certyfikat;
		var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: pars,
				onComplete: SR_profil_dodaj_certyfikat							  
			}
		);
	}
	else {
		alert("Podaj nazwe certyfikatu.");	
	}
}

//-----------------------------------pokaz normalnie certyfikaty--------------------------------
function profil_pokaz_certyfikaty(){
/*
sprawdzono
*/
	$$(".wiersz_formatki_dodawania_certyfikatu").each(function(s) {Element.show(s)});
	$("uwaga_certyfikat").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var url = 'xmlphp/profil_pokaz_certyfikaty.php';
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			onComplete: SR_profil_dodaj_certyfikat
		}
	);
}


//-----------------------------------dodawanie wyswietlania--------------------------------
/*
sprawdzono
*/
var czas_najechania;	//przechowuje czas unixowy najechania
var czas_zjechania;		//przechowuje czas unixowy zjechania
var id_uzytkownika1;	//przechowuje id_uzytkownika na ktorego najechalismy
var id_uzytkownika2;	//przechowuje id_uzytkownika z ktorego zesmy zjechali
function profil_dodaj_wyswietlenia(id_uzytkownika){
	data_najechania = new Date();
	czas_najechania = data_najechania.getTime();
	id_uzytkownika1 = id_uzytkownika;
}

function profil_dodaj_wyswietlenia2(id_uzytkownika){
	data_zjechania = new Date();
	czas_zjechania = data_zjechania.getTime();
	id_uzytkownika2 = id_uzytkownika;
	if ((id_uzytkownika1 == id_uzytkownika2) & ( (czas_zjechania-czas_najechania)>1000 )){
		var url = 'xmlphp/profil_dodaj_wyswietlania.php';
		var pars = 'id_uzytkownika=' + id_uzytkownika;
		var myAjax = new Ajax.Request(
			url,
			{
				method: 'get',
				parameters: pars,
				onComplete: SR_profil_dodaj_wyswietlania							  
			}
		);
	}
}

function SR_profil_dodaj_wyswietlania(originalRequest){
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	
	//pobranie danych z xml
	//uzytkownik
	var liczba_wyswietlen = xmlResponse.getElementsByTagName("liczba_wyswietlen").item(0).firstChild.data;
	var id_uzytkownika = xmlResponse.getElementsByTagName("id_uzytkownika").item(0).firstChild.data;
	//pracodawca
	var liczba_odwiedzin = xmlResponse.getElementsByTagName("liczba_odwiedzin").item(0).firstChild.data;
	var id_pracodawcy = xmlResponse.getElementsByTagName("id_pracodawcy").item(0).firstChild.data;
	
	//wskrzykniecie danych do kodu html
	//uzytkownik
	if ($("profil_mini_wys_" + id_uzytkownika)){
		$("profil_mini_wys_" + id_uzytkownika).innerHTML = liczba_wyswietlen + " wy&#x15B;wietle&#x144;";
	}
	//pracodawca
	if (id_pracodawcy != 0){
		if ($("pracodawca_wyswietlil_" + id_pracodawcy)){
			$("pracodawca_wyswietlil_" + id_pracodawcy).innerHTML = "Wy&#x15B;wietli&#x142; " + liczba_odwiedzin + " profili";	
		}
	}
}

//-----------------------------------zablokowanie profilu--------------------------------
function profil_zablokuj(id_uzytkownika){
	//pokazanie loading
	$("profil_blokowanie").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var url = 'xmlphp/profil_zablokuj.php';
	var pars = 'id_uzytkownika=' + id_uzytkownika;
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: SR_profil_zablokuj
		}
	);
}

function SR_profil_zablokuj(originalRequest){
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	
	var id_uzytkownika = xmlResponse.getElementsByTagName("id_uzytkownika").item(0).firstChild.data;
	$("profil_blokowanie").innerHTML = "<a href='javascript:profil_odblokuj(" + id_uzytkownika + ")'>Odblokuj profil</a>";	
}

//-----------------------------------odblokowanie profilu--------------------------------
function profil_odblokuj(id_uzytkownika){
	//pokazanie loading
	$("profil_blokowanie").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var url = 'xmlphp/profil_odblokuj.php';
	var pars = 'id_uzytkownika=' + id_uzytkownika;
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: SR_profil_odblokuj
		}
	);
}

function SR_profil_odblokuj(originalRequest){
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	
	var id_uzytkownika = xmlResponse.getElementsByTagName("id_uzytkownika").item(0).firstChild.data;
	$("profil_blokowanie").innerHTML = "<a href='javascript:profil_zablokuj(" + id_uzytkownika + ")'>Zablokuj profil</a>";
}

//-----------------------------------profil zglos--------------------------------
function profil_zglos(id_uzytkownika){
	//pokazanie loading
	$("profil_zglos").innerHTML = "<img src='images/loading.gif' alt='' height='16' />";
	
	var url = 'xmlphp/profil_zglos.php';
	var pars = 'id_uzytkownika=' + id_uzytkownika;
	var myAjax = new Ajax.Request(
		url,
		{
			method: 'get',
			parameters: pars,
			onComplete: SR_profil_zglos
		}
	);
}

function SR_profil_zglos(originalRequest){
	var xmlResponse = originalRequest.responseXML;
	xmlRoot = xmlResponse.documentElement;
	
	$("profil_zglos").innerHTML = "Profil zostal zg&#x142;oszony";	
}

