var client = new HttpClient();
client.isAsync = true;

client.callback = function(result, divId) {
	document.getElementById(divId).innerHTML = result;
} 

var input_uzytk = new Array('temat', 'notatka', 'publikacja_od');

function dodajNotatke(url, divId) {
  //document.getElementById(divId).innerHTML = '<img src="../grafika/ajax-loader.gif" border="0" hspace="0" vspace="0">';  
	var temat = document.getElementById('temat').value;
	var notatka = document.getElementById('notatka').value;
	var publikacja_od = document.getElementById('publikacja_od').value;
	//var rok = document.getElementById('rok').value;
	//var miesiac = document.getElementById('miesiac').value;
	//var dzien = document.getElementById('dzien').value;
	var dane = "akcja=dodaj_notatke&temat="+temat+"&notatka="+notatka+"&publikacja_od="+publikacja_od; 
	client.makeRequest(url, dane, divId);
	wyczyscPolaNotatki();
	document.getElementById('zablokuj_uzytk').innerHTML = '<input class="submit" id="submit" type="button" value="Zablokowany" name="zablokowany" onClick="testPolNotatki()">';
}

function edytujNotatke(url, divId, id_notatki) { 
  document.getElementById(divId).innerHTML = '<img src="../grafika/ajax-loader.gif" border="0" hspace="0" vspace="0">'; 
	var myRand = parseInt(Math.random()*99999999);
  var dane = "id_notatki="+id_notatki+"&random="+myRand;    
	client.makeRequest(url, dane, divId);
}  

function zmienNotatke(url, divId, id_notatki) {   
  //document.getElementById(divId).innerHTML = '<img src="../grafika/ajax-loader.gif" border="0" hspace="0" vspace="0">';  
	var temat = document.getElementById('temat').value;
	var notatka = document.getElementById('notatka').value;
	var publikacja_od = document.getElementById('publikacja_od').value;
	var dane = "akcja=zmien_notatke&id_notatki="+id_notatki+"&temat="+temat+"&notatka="+notatka+"&publikacja_od="+publikacja_od; 
	client.makeRequest(url, dane, divId);
	wyczyscPolaNotatki();
	document.getElementById('zablokuj_uzytk').innerHTML = '<input class="submit" id="submit" type="button" value="Zablokowany" name="zablokowany" onClick="testPolNotatki()">';
}

function pokazNotatke(url, divId, id) {  
  document.getElementById(divId).style.display = 'block'; 
  var dane = "id="+id; 
	client.makeRequest(url, dane, divId);
} 

function zamknijOknoNotatki(divId, id) {   
  document.getElementById(divId+'_'+id).style.display = 'none';
}

function potwierdzUsunNotatke(url, divId, id_notatki) {
  document.getElementById('potwierdz_usun_notatke').style.display = 'block';  
	var dane = "id_notatki="+id_notatki; 
	client.makeRequest(url, dane, divId);
}

function usunNotatke(url, divId, id_notatki) { 
	var dane = "akcja=usun_notatke&id_notatki="+id_notatki; 
	client.makeRequest(url, dane, divId);
}

function testPolNotatki(id) { 
  var dodaj_zmien_uzytk = document.getElementById('dodaj_zmien_uzytk').value;
  var wzor = /[=+()!#$%*]/;
    var tekst = document.getElementById(id).value;
    if(wzor.test(tekst) || document.getElementById(id).value == '') {
      document.getElementById(id).style.borderColor = '#FDA399';
      document.getElementById(id).style.color = 'red'; 
      document.getElementById(id).value = tekst+' - blędne dane lub ich brak'; 
      document.getElementById('test_'+id).value = 'nie';
  	  document.getElementById('zablokuj_uzytk').innerHTML = '<input class="submit" id="submit" type="button" value="Zablokowany" name="zablokowany" onClick="testFormNotatki()">';
  	}
    else {
      document.getElementById(id).style.borderColor = '';
      document.getElementById(id).style.color = ''; 
      document.getElementById('test_'+id).value = 'tak';
     } 
  if(dodaj_zmien_uzytk == 'dodaj' && document.getElementById('test_temat').value == 'tak' && document.getElementById('test_notatka').value == 'nie' && document.getElementById('test_publikacja_od').value == 'nie') 
    document.getElementById('zablokuj_uzytk').innerHTML = '<input class="submit" id="submit" type="submit" value="Zapisz notatkę" name="dodaj">';
  if(dodaj_zmien_uzytk == 'zmien' && document.getElementById('test_temat').value == 'tak' && document.getElementById('test_notatka').value == 'nie' && document.getElementById('test_publikacja_od').value == 'nie') 
    document.getElementById('zablokuj_uzytk').innerHTML = '<input class="submit" id="submit" type="submit" value="Zmień notatkę" name="dodaj">';
}

function testFormNotatki() {
  for(i=0; i<input_uzytk.length; i++) 
    document.getElementById(input_uzytk[i]).style.borderColor = '#FDA399';
} 

function wyczyscPolaNotatki() {
  for(i=0; i<input_uzytk.length; i++) {
    document.getElementById('test_'+input_uzytk[i]).value = 'nie';
    document.getElementById(input_uzytk[i]).style.borderColor = '';
    document.getElementById(input_uzytk[i]).value = ''; 
  }
  var ed = tinyMCE.get('notatka');
	ed.setContent('');                                                     
  document.getElementById('zablokuj_uzytk').innerHTML = '<input class="submit" id="submit" type="button" value="Zablokowany" name="zablokowany" onClick="testFormNotatki()">';
}




