function getCalendarEvents(year,month,day,uid,sid,czyje) {	
	if(!uid) {
		ids = 0;
	} else {
		ids = uid;
	}
	advAJAX.get({
	  url : 'load-events',
	  parameters : {
			"year" : year,
			"month" : month,
			"day" :day,
			"uid" : uid,
			"sid" : sid,
			"czyje" : czyje
	  },
	  onLoading : function(obj) {
			loadLightbox("<br/><br/><center>wczytuje dane o terminach ...</center><br/><br/>");
	  },
	  onSuccess : function(obj) {
			loadLightbox(obj.responseText);
	  }
	})
}



function editGetCalendarEvents(id) {	

	advAJAX.get({
	  url : 'load-editevents',
	  parameters : {
			"id" : id
	  },
	  onLoading : function(obj) {
			closeLightbox();
			loadLightbox("<br/><br/><center>wczytuje dane do edycji ... </center><br/><br/>");
	  },
	  onSuccess : function(obj) {
			loadLightbox(obj.responseText);
	  }
	})
}

function copyGetCalendarEvents(id,uid) {	

	advAJAX.get({
	  url : 'load-copyevents',
	  parameters : {
			"id" : id,
			"uid" : uid
	  },
	  onLoading : function(obj) {
			closeLightbox();
			loadLightbox("<br/><br/><center>wczytuje dane ... </center><br/><br/>");
	  },
	  onSuccess : function(obj) {
			loadLightbox(obj.responseText);
	  }
	})
}


function deleteGetCalendarEvents(id) {	

	advAJAX.get({
	  url : 'load-deleteevents',
	  parameters : {
			"id" : id
	  },
	  onLoading : function(obj) {
			closeLightbox();
			loadLightbox("<br/><br/><center>proszę czekać trwa usuwanie ... </center><br/><br/>");
	  },
	  onSuccess : function(obj) {
			loadLightbox('<br/><br/><center>Termin usnięty pomyślnie!</center><br/><br/>');
			window.location.reload();
	  },
	  onError : function(obj) {
			loadLightbox(obj.responseText);
	  }
	})
}

function loadCalendar(year,month,day,uid) {

	var actYear = 0;
var actMonth = 0;
var actDay = 0;	
				
	advAJAX.get({
		url: "./_load/calendar.php",
		parameters : {
			"year" : year,
			"month" : month,
			"day" : day,
			"uid" : uid
		},
		onLoading : function(obj) {
				document.getElementById("aleft").style.visibility = "hidden";
				document.getElementById("aright").style.visibility = "hidden";
				

				},
		onSuccess : function(obj) {	
				
				actYear = year;
				actMonth = month;
				actDay = day;
				
				
				
				document.getElementById("userCalendar").innerHTML = obj.responseText;
				
				document.getElementById("aleft").style.visibility = "visible";
				document.getElementById("aright").style.visibility = "visible";
		},
		onError : function(obj) { closeLightbox(); alert("Nie można było załadować kalendarza.\nProsimy spróbować za chwilę."); }
	});
}

function loadEvents(year,month,day) {
	alert("Loading event for: " + year + "-" + month + "-" + day);
}
function addEvent(uid) {

	advAJAX.submit( document.getElementById("addevent"), {
		onSuccess : function(obj) {
			if (obj.responseText==3) {
				alert("Musisz podać nazwe terminu!");
			}
			if (obj.responseText==0) {
				alert("Wystąpił błąd podczas próby dodania terminu!");
			}
			if (obj.responseText==2) {
				alert("Wybrana data jest nie poprawna!");
			}
			if (obj.responseText==1) {
			document.location.href = "calendar,0,"+uid;
			loadCalendar(actYear,actMonth,actDay);			
			resetElements.elements["hotel"].value = "";
			}
		},
		onLoading : function(obj) {
			//...
		},
		onError : function(obj) {
			alert("Nie można było dodać wybranego terminu :(\nProsimy spróbować za chwilę ...");
		}
	});	
}

function editEvent(id) {
	advAJAX.submit ( document.getElementById("editevent"), {
		onLoading : function(obj) { 
			closeLightbox(); 
			loadLightbox("<br/><br/> <center> Proszę czekąc, trwa zapisywanie danych ... </center><br/><br/>");  
			},
		 onSuccess : function(obj) { 
			loadLightbox("<br/><br/> <center> Dane zostały zapisane pomyślnie! </center><br/><br/>"); 
			location = location;
		 },
		 onError : function(obj) {
			loadLightbox("Błąd podczas zapisywania danych!"); 
			}
	});
}

function copyEvent(uid) {

	advAJAX.submit( document.getElementById("copyevent"), {
		onSuccess : function(obj) {
			if (obj.responseText==0) {
				loadLightbox("Wystąpił błąd podczas próby dodania terminu!");
			}
			if (obj.responseText==2) {
				loadLightbox("<br/><br/> <center>Dzień który wybrałeś już minął </center> <br/><br/>");
			}
			if (obj.responseText==1) {
			document.location.href = "calendar,0,"+uid;
			loadCalendar(actYear,actMonth,actDay);			
			resetElements.elements["hotel"].value = "";
			}
		},
		onLoading : function(obj) {
			closeLightbox(); loadLightbox("<br/><br/> <center> Proszę czekąc, trwa zapisywanie danych ... </center><br/><br/>");
		},
		onError : function(obj) {
			alert(obj.status);
		}
	});	
}


function loadFriends(uid) {
	advAJAX.get({
		url: "load-friends",
		parameters : {
			"uid" : uid
			
		},
		onLoading : function(obj) {
				//...
		 },
		onSuccess : function(obj) {	
				document.getElementById("friendsList").innerHTML = obj.responseText;
		},
		onError : function(obj) { alert("Nie można było w tej chwili załadować listy znajomych :-(\nProsimy spróbować za chwilę."); }
	});
}

function loadSearch(nick,imie,nazwisko,numer_rejestracyjny,firma,email) {
	advAJAX.get({
		url: "load-search",
		parameters : {
			"nick" : nick,
			"imie" : imie,
			"nazwisko" : nazwisko,
			"firma" : firma,
			"numer_rejestracyjny" : numer_rejestracyjny,
			"email" : email
		},
		onLoading : function(obj) {
				//...
		 },
		onSuccess : function(obj) {	
				document.getElementById("searchList").innerHTML = obj.responseText;
		},
		onError : function(obj) { alert("Nie można było w tej chwili załadować listy znajomych :-(\nProsimy spróbować za chwilę.") }
	});
}

function remUser(ob) {
	if(confirm("Czy napewno chcesz usunąć tą osobę z listy kontaktów?") == true) {
		document.location.href = ob.href;	
	} else {
		return false;
	}
}



