$(document).ready(function(){
	
	var list_hovered_monday=0;
	$("#monday > li").live("mouseover", function(){
		list_hovered_monday=1;
	});
	$("#monday > li").live("mouseout", function(){
		list_hovered_monday=0;
	});
	$("#monday").live("click", function(){
		if(list_hovered_monday==0)
			$("#monday_add_subject").focus();
	});
	
	var suggestions_hovered_monday=0;
	$("#monday_suggestions").live("mouseover", function(){
		suggestions_hovered_monday=1;
	});
	$("#monday_suggestions").live("mouseout", function(){
		suggestions_hovered_monday=0;
	});
	
	$("#monday_add_subject").live("keyup", function(e){
		if(e.which==13){
			e.preventDefault();
			suggestions_hovered_monday=0;//reset the hover to enter cleanly in the blur()
			$("#monday_add_subject").trigger("addSubject");//trigger the same blur event as below; when user clicks on suggestion, it automatically adds to list, clearing the input and sending the subject name to database
		}
		else{
			$("#monday_add_subject").attr("size", ($("#monday_add_subject").val().length+2));//resize input
			$("#monday_suggestions").empty().show();
			if($("#monday_add_subject").val().length>=2){
				$("#monday_suggestions").html("<ul><li>Loading...</li></ul>");
				$.ajax({
					type: "POST",
					url: "widget_schedule/ajax/subjectSuggestions.php",
					data: "q="+$("#monday_add_subject").val(),
					success: function(data){
						$("#monday_suggestions").html(data);
					}
				});
			}
			else{
				$("#monday_suggestions").html("<ul><li>Start typing...</li></ul>").show();	
			}
		}
	});
	
	$("#monday_add_subject").live("focus", function(){
		if($("ul#monday").children().length>=11){//check if the limit of subjects has been reached
			if(!$("ul#monday li#err").length){//check if another error message was not sent
				$("#monday_add_subject").attr("disabled", "disabled");
				$("ul#monday li#as").after("<li id='err' class='error'>The limit of subjects has been reached!</li>");
			}
		}
		else
			if($("#monday_add_subject").val()!=''){//if text is entered in input, then show the suggestions on input focus
				$("#monday_suggestions").show();
			}
			else{
				$("#monday_suggestions").html("<ul><li>Start typing...</li></ul>").show();	
			}
	});
	$("#monday_add_subject").live("blur", function(){
		if(list_hovered_monday==0&&suggestions_hovered_monday==0)//hide suggestions only if user clicks outside input and not in the list or suggestion list
			$("#monday_suggestions").hide();
	});
	
	$("#monday_add_subject").live("addSubject", function(){
		if($("ul#monday").children().length<11){//continue only if subject limit was not reached
			$("#monday_add_subject").attr("size", "2");//resize input
			$("#monday_suggestions").hide();
			if(jQuery.trim($("#monday_add_subject").val())!=""&&$("#monday_add_subject").val().length>=3){//only if some value exists in input
				$.ajax({//send the subject and insert it into db if it doesn't exist
					async: false,//important! if set to true, val("") executes before ajax request completes and <span> with sb name remains empty
					type: "POST",
					url: "widget_schedule/ajax/addSubject.php",
					data: "subject="+$("#monday_add_subject").val(),
					success: function(data){
						if(data==0){
							$("ul#monday li#as").after("<li id='err' class='error'>An error occured when trying to send your request.</li>");
							$("ul#monday li#err").delay(3000).fadeOut().remove($("ul#monday li#err"));
						}
						else{
							var subject_id=data;
							$("ul#monday li#as").before("<li id='monday_"+subject_id+"'><img src='images/move.png' alt='Move' class='move' /><span>"+$("#monday_add_subject").val()+"</span><img src='images/delete_small.png' alt='Delete' class='delete' /></li>");//add new list element with new subject before input text	
							if($("ul#monday").children().length>=2&&$("ul#monday li#ns").length)//remove schedule not set item if subjects have been added
								$("ul#monday li#ns").remove();
							if($("ul#monday").children().length>=2&&$("ul#monday li#fd").length)//remove free day item if subjects have been added
								$("ul#monday li#fd").remove();
								
							updateSchedule("monday");
						}
						$("#monday_add_subject").val("").focus();
					},
					error: function(xhr,text){
						$("ul#monday li#as").after("<li id='err' class='error'>Error: "+text+"</li>");
						$("ul#monday li#err").delay(3000).fadeOut().remove($("ul#monday li#err"));
					}
				});
				$("#monday_add_subject").val("");//empty input from any user inputted text
			}
		}
	});
	
	$("div#monday_suggestions ul li span[id^='subject_']").live("click", function(){
		var divID=$(this).parent().parent().parent().attr("id");//span->li->ul->div id
		var day=divID.split("_");
		$("#"+day[0]+"_add_subject").val($(this).text());
		$("#monday_suggestions").hide();
		suggestions_hovered_monday=0;//reset the hover to enter cleanly in the blur()
		$("#monday_add_subject").trigger("addSubject");//trigger the same blur event as above; when user clicks on suggestion, it automatically adds to list, clearing the input and sending the subject name to database
	});
	
	$("ul#monday li img.delete").live("click", function(){
		$(this).parent().remove();
		if($("#monday").children().length==1)//add free day item if all subjects have been deleted
			$("#monday").prepend("<li id='fd'>Free Day</li>");
		if($("ul#monday").children().length==11){//check if the limit element has been removed; if so, remove the error message
			$("#monday_add_subject").removeAttr("disabled");
			$("ul#monday li#err").remove();
		}
		updateSchedule("monday");
	});
	
	var list_hovered_tuesday=0;
	$("#tuesday > li").live("mouseover", function(){
		list_hovered_tuesday=1;
	});
	$("#tuesday > li").live("mouseout", function(){
		list_hovered_tuesday=0;
	});
	$("#tuesday").live("click", function(){
		if(list_hovered_tuesday==0)
			$("#tuesday_add_subject").focus();
	});
	
	var suggestions_hovered_tuesday=0;
	$("#tuesday_suggestions").live("mouseover", function(){
		suggestions_hovered_tuesday=1;
	});
	$("#tuesday_suggestions").live("mouseout", function(){
		suggestions_hovered_tuesday=0;
	});
	
	$("#tuesday_add_subject").live("keyup", function(e){
		if(e.which==13){
			e.preventDefault();
			suggestions_hovered_tuesday=0;//reset the hover to enter cleanly in the blur()
			$("#tuesday_add_subject").trigger("addSubject");//trigger the same blur event as below; when user clicks on suggestion, it automatically adds to list, clearing the input and sending the subject name to database
		}
		else{
			$("#tuesday_add_subject").attr("size", ($("#tuesday_add_subject").val().length+2));//resize input
			$("#tuesday_suggestions").empty().show();
			if($("#tuesday_add_subject").val().length>=2){
				$("#tuesday_suggestions").html("<ul><li>Loading...</li></ul>");
				$.ajax({
					type: "POST",
					url: "widget_schedule/ajax/subjectSuggestions.php",
					data: "q="+$("#tuesday_add_subject").val(),
					success: function(data){
						$("#tuesday_suggestions").html(data);
					}
				});
			}
			else{
				$("#tuesday_suggestions").html("<ul><li>Start typing...</li></ul>").show();	
			}
		}
	});
	
	$("#tuesday_add_subject").live("focus", function(){
		if($("ul#tuesday").children().length>=11){//check if the limit of subjects has been reached
			if(!$("ul#tuesday li#err").length){//check if another error message was not sent
				$("#tuesday_add_subject").attr("disabled", "disabled");
				$("ul#tuesday li#as").after("<li id='err' class='error'>The limit of subjects has been reached!</li>");
			}
		}
		else
			if($("#tuesday_add_subject").val()!=''){//if text is entered in input, then show the suggestions on input focus
				$("#tuesday_suggestions").show();
			}
			else{
				$("#tuesday_suggestions").html("<ul><li>Start typing...</li></ul>").show();	
			}
	});
	$("#tuesday_add_subject").live("blur", function(){
		if(list_hovered_tuesday==0&&suggestions_hovered_tuesday==0)//hide suggestions only if user clicks outside input and not in the list or suggestion list
			$("#tuesday_suggestions").hide();
	});
	
	$("#tuesday_add_subject").live("addSubject", function(){
		if($("ul#tuesday").children().length<11){//continue only if subject limit was not reached
			$("#tuesday_add_subject").attr("size", "2");//resize input
			$("#tuesday_suggestions").hide();
			if(jQuery.trim($("#tuesday_add_subject").val())!=""&&$("#tuesday_add_subject").val().length>=3){//only if some value exists in input
				$.ajax({//send the subject and insert it into db if it doesn't exist
					async: false,//important! if set to true, val("") executes before ajax request completes and <span> with sb name remains empty
					type: "POST",
					url: "widget_schedule/ajax/addSubject.php",
					data: "subject="+$("#tuesday_add_subject").val(),
					success: function(data){
						if(data==0){
							$("ul#tuesday li#as").after("<li id='err' class='error'>An error occured when trying to send your request.</li>");
							$("ul#tuesday li#err").delay(3000).fadeOut();
						}
						else{
							var subject_id=data;
							$("ul#tuesday li#as").before("<li id='tuesday_"+subject_id+"'><img src='images/move.png' alt='Move' class='move' /><span>"+$("#tuesday_add_subject").val()+"</span><img src='images/delete_small.png' alt='Delete' class='delete' /></li>");//add new list element with new subject before input text	
							if($("ul#tuesday").children().length>=2&&$("ul#tuesday li#ns").length)//remove schedule not set item if subjects have been added
								$("ul#tuesday li#ns").remove();
							if($("ul#tuesday").children().length>=2&&$("ul#tuesday li#fd").length)//remove free day item if subjects have been added
								$("ul#tuesday li#fd").remove();
								
							updateSchedule("tuesday");
						}
					},
					error: function(xhr,text){
						$("ul#tuesday li#as").after("<li id='err' class='error'>Error: "+text+"</li>");
						$("ul#tuesday li#err").delay(3000).fadeOut();
					}
				});
				$("#tuesday_add_subject").val("");//empty input from any user inputted text
			}
		}
	});
	
	$("div#tuesday_suggestions ul li span[id^='subject_']").live("click", function(){
		var divID=$(this).parent().parent().parent().attr("id");//span->li->ul->div id
		var day=divID.split("_");
		$("#"+day[0]+"_add_subject").val($(this).text());
		$("#tuesday_suggestions").hide();
		suggestions_hovered_tuesday=0;//reset the hover to enter cleanly in the blur()
		$("#tuesday_add_subject").trigger("addSubject");//trigger the same blur event as above; when user clicks on suggestion, it automatically adds to list, clearing the input and sending the subject name to database
	});
	
	$("ul#tuesday li img.delete").live("click", function(){
		$(this).parent().remove();
		if($("#tuesday").children().length==1)//add free day item if all subjects have been deleted
			$("#tuesday").prepend("<li id='fd'>Free Day</li>");
		if($("ul#tuesday").children().length==11){//check if the limit element has been removed; if so, remove the error message
			$("#tuesday_add_subject").removeAttr("disabled");
			$("ul#tuesday li#err").remove();
		}
		updateSchedule("tuesday");
	});
	
	var list_hovered_wednesday=0;
	$("#wednesday > li").live("mouseover", function(){
		list_hovered_wednesday=1;
	});
	$("#wednesday > li").live("mouseout", function(){
		list_hovered_wednesday=0;
	});
	$("#wednesday").live("click", function(){
		if(list_hovered_wednesday==0)
			$("#wednesday_add_subject").focus();
	});
	
	var suggestions_hovered_wednesday=0;
	$("#wednesday_suggestions").live("mouseover", function(){
		suggestions_hovered_wednesday=1;
	});
	$("#wednesday_suggestions").live("mouseout", function(){
		suggestions_hovered_wednesday=0;
	});
	
	$("#wednesday_add_subject").live("keyup", function(e){
		if(e.which==13){
			e.preventDefault();
			suggestions_hovered_wednesday=0;//reset the hover to enter cleanly in the blur()
			$("#wednesday_add_subject").trigger("addSubject");//trigger the same blur event as below; when user clicks on suggestion, it automatically adds to list, clearing the input and sending the subject name to database
		}
		else{
			$("#wednesday_add_subject").attr("size", ($("#wednesday_add_subject").val().length+2));//resize input
			$("#wednesday_suggestions").empty().show();
			if($("#wednesday_add_subject").val().length>=2){
				$("#wednesday_suggestions").html("<ul><li>Loading...</li></ul>");
				$.ajax({
					type: "POST",
					url: "widget_schedule/ajax/subjectSuggestions.php",
					data: "q="+$("#wednesday_add_subject").val(),
					success: function(data){
						$("#wednesday_suggestions").html(data);
					}
				});
			}
			else{
				$("#wednesday_suggestions").html("<ul><li>Start typing...</li></ul>").show();	
			}
		}
	});
	
	$("#wednesday_add_subject").live("focus", function(){
		if($("ul#wednesday").children().length>=11){//check if the limit of subjects has been reached
			if(!$("ul#wednesday li#err").length){//check if another error message was not sent
				$("#wednesday_add_subject").attr("disabled", "disabled");
				$("ul#wednesday li#as").after("<li id='err' class='error'>The limit of subjects has been reached!</li>");
			}
		}
		else
			if($("#wednesday_add_subject").val()!=''){//if text is entered in input, then show the suggestions on input focus
				$("#wednesday_suggestions").show();
			}
			else{
				$("#wednesday_suggestions").html("<ul><li>Start typing...</li></ul>").show();	
			}
	});
	$("#wednesday_add_subject").live("blur", function(){
		if(list_hovered_wednesday==0&&suggestions_hovered_wednesday==0)//hide suggestions only if user clicks outside input and not in the list or suggestion list
			$("#wednesday_suggestions").hide();
	});
	
	$("#wednesday_add_subject").live("addSubject", function(){
		if($("ul#wednesday").children().length<11){//continue only if subject limit was not reached
			$("#wednesday_add_subject").attr("size", "2");//resize input
			$("#wednesday_suggestions").hide();
			if(jQuery.trim($("#wednesday_add_subject").val())!=""&&$("#wednesday_add_subject").val().length>=3){//only if some value exists in input
				$.ajax({//send the subject and insert it into db if it doesn't exist
					async: false,//important! if set to true, val("") executes before ajax request completes and <span> with sb name remains empty
					type: "POST",
					url: "widget_schedule/ajax/addSubject.php",
					data: "subject="+$("#wednesday_add_subject").val(),
					success: function(data){
						if(data==0){
							$("ul#wednesday li#as").after("<li id='err' class='error'>An error occured when trying to send your request.</li>");
							$("ul#wednesday li#err").delay(3000).fadeOut();
						}
						else{
							var subject_id=data;
							$("ul#wednesday li#as").before("<li id='wednesday_"+subject_id+"'><img src='images/move.png' alt='Move' class='move' /><span>"+$("#wednesday_add_subject").val()+"</span><img src='images/delete_small.png' alt='Delete' class='delete' /></li>");//add new list element with new subject before input text	
							if($("ul#wednesday").children().length>=2&&$("ul#wednesday li#ns").length)//remove schedule not set item if subjects have been added
								$("ul#wednesday li#ns").remove();
							if($("ul#wednesday").children().length>=2&&$("ul#wednesday li#fd").length)//remove free day item if subjects have been added
								$("ul#wednesday li#fd").remove();
								
							updateSchedule("wednesday");
						}
					},
					error: function(xhr,text){
						$("ul#wednesday li#as").after("<li id='err' class='error'>Error: "+text+"</li>");
						$("ul#wednesday li#err").delay(3000).fadeOut().remove($("ul#wednesday li#err"));
					}
				});
				$("#wednesday_add_subject").val("");//empty input from any user inputted text
			}
		}
	});
	
	$("div#wednesday_suggestions ul li span[id^='subject_']").live("click", function(){
		var divID=$(this).parent().parent().parent().attr("id");//span->li->ul->div id
		var day=divID.split("_");
		$("#"+day[0]+"_add_subject").val($(this).text());
		$("#wednesday_suggestions").hide();
		suggestions_hovered_wednesday=0;//reset the hover to enter cleanly in the blur()
		$("#wednesday_add_subject").trigger("addSubject");//trigger the same blur event as above; when user clicks on suggestion, it automatically adds to list, clearing the input and sending the subject name to database
	});
	

	$("ul#wednesday li img.delete").live("click", function(){
		$(this).parent().remove();
		if($("#wednesday").children().length==1)//add free day item if all subjects have been deleted
			$("#wednesday").prepend("<li id='fd'>Free Day</li>");
		if($("ul#wednesday").children().length==11){//check if the limit element has been removed; if so, remove the error message
			$("#wednesday_add_subject").removeAttr("disabled");
			$("ul#wednesday li#err").remove();
		}
		updateSchedule("wednesday");
	});
	
	var list_hovered_thursday=0;
	$("#thursday > li").live("mouseover", function(){
		list_hovered_thursday=1;
	});
	$("#thursday > li").live("mouseout", function(){
		list_hovered_thursday=0;
	});
	$("#thursday").live("click", function(){
		if(list_hovered_thursday==0)
			$("#thursday_add_subject").focus();
	});
	
	var suggestions_hovered_thursday=0;
	$("#thursday_suggestions").live("mouseover", function(){
		suggestions_hovered_thursday=1;
	});
	$("#thursday_suggestions").live("mouseout", function(){
		suggestions_hovered_thursday=0;
	});
	
	$("#thursday_add_subject").live("keyup", function(e){
		if(e.which==13){
			e.preventDefault();
			suggestions_hovered_thursday=0;//reset the hover to enter cleanly in the blur()
			$("#thursday_add_subject").trigger("addSubject");//trigger the same blur event as below; when user clicks on suggestion, it automatically adds to list, clearing the input and sending the subject name to database
		}
		else{
			$("#thursday_add_subject").attr("size", ($("#thursday_add_subject").val().length+2));//resize input
			$("#thursday_suggestions").empty().show();
			if($("#thursday_add_subject").val().length>=2){
				$("#thursday_suggestions").html("<ul><li>Loading...</li></ul>");
				$.ajax({
					type: "POST",
					url: "widget_schedule/ajax/subjectSuggestions.php",
					data: "q="+$("#thursday_add_subject").val(),
					success: function(data){
						$("#thursday_suggestions").html(data);
					}
				});
			}
			else{
				$("#thursday_suggestions").html("<ul><li>Start typing...</li></ul>").show();	
			}
		}
	});
	
	$("#thursday_add_subject").live("focus", function(){
		if($("ul#thursday").children().length>=11){//check if the limit of subjects has been reached
			if(!$("ul#thursday li#err").length){//check if another error message was not sent
				$("#thursday_add_subject").attr("disabled", "disabled");
				$("ul#thursday li#as").after("<li id='err' class='error'>The limit of subjects has been reached!</li>");
			}
		}
		else
			if($("#thursday_add_subject").val()!=''){//if text is entered in input, then show the suggestions on input focus
				$("#thursday_suggestions").show();
			}
			else{
				$("#thursday_suggestions").html("<ul><li>Start typing...</li></ul>").show();	
			}
	});
	$("#thursday_add_subject").live("blur", function(){
		if(list_hovered_thursday==0&&suggestions_hovered_thursday==0)//hide suggestions only if user clicks outside input and not in the list or suggestion list
			$("#thursday_suggestions").hide();
	});
	
	$("#thursday_add_subject").live("addSubject", function(){
		if($("ul#thursday").children().length<11){//continue only if subject limit was not reached
			$("#thursday_add_subject").attr("size", "2");//resize input
			$("#thursday_suggestions").hide();
			if(jQuery.trim($("#thursday_add_subject").val())!=""&&$("#thursday_add_subject").val().length>=3){//only if some value exists in input
				$.ajax({//send the subject and insert it into db if it doesn't exist
					async: false,//important! if set to true, val("") executes before ajax request completes and <span> with sb name remains empty
					type: "POST",
					url: "widget_schedule/ajax/addSubject.php",
					data: "subject="+$("#thursday_add_subject").val(),
					success: function(data){
						if(data==0){
							$("ul#thursday li#as").after("<li id='err' class='error'>An error occured when trying to send your request.</li>");
							$("ul#thursday li#err").delay(3000).fadeOut();
						}
						else{
							var subject_id=data;
							$("ul#thursday li#as").before("<li id='thursday_"+subject_id+"'><img src='images/move.png' alt='Move' class='move' /><span>"+$("#thursday_add_subject").val()+"</span><img src='images/delete_small.png' alt='Delete' class='delete' /></li>");//add new list element with new subject before input text	
							if($("ul#thursday").children().length>=2&&$("ul#thursday li#ns").length)//remove schedule not set item if subjects have been added
								$("ul#thursday li#ns").remove();
							if($("ul#thursday").children().length>=2&&$("ul#thursday li#fd").length)//remove free day item if subjects have been added
								$("ul#thursday li#fd").remove();
								
							updateSchedule("thursday");
						}
					},
					error: function(xhr,text){
						$("ul#thursday li#as").after("<li id='err' class='error'>Error: "+text+"</li>");
						$("ul#thursday li#err").delay(3000).fadeOut().remove($("ul#thursday li#err"));
					}
				});
				$("#thursday_add_subject").val("");//empty input from any user inputted text
			}
		}
	});
	
	$("div#thursday_suggestions ul li span[id^='subject_']").live("click", function(){
		var divID=$(this).parent().parent().parent().attr("id");//span->li->ul->div id
		var day=divID.split("_");
		$("#"+day[0]+"_add_subject").val($(this).text());
		$("#thursday_suggestions").hide();
		suggestions_hovered_thursday=0;//reset the hover to enter cleanly in the blur()
		$("#thursday_add_subject").trigger("addSubject");//trigger the same blur event as above; when user clicks on suggestion, it automatically adds to list, clearing the input and sending the subject name to database
	});
	

	$("ul#thursday li img.delete").live("click", function(){
		$(this).parent().remove();
		if($("#thursday").children().length==1)//add free day item if all subjects have been deleted
			$("#thursday").prepend("<li id='fd'>Free Day</li>");
		if($("ul#thursday").children().length==11){//check if the limit element has been removed; if so, remove the error message
			$("#thursday_add_subject").removeAttr("disabled");
			$("ul#thursday li#err").remove();
		}
		updateSchedule("thursday");
	});
	
	var list_hovered_friday=0;
	$("#friday > li").live("mouseover", function(){
		list_hovered_friday=1;
	});
	$("#friday > li").live("mouseout", function(){
		list_hovered_friday=0;
	});
	$("#friday").live("click", function(){
		if(list_hovered_friday==0)
			$("#friday_add_subject").focus();
	});
	
	var suggestions_hovered_friday=0;
	$("#friday_suggestions").live("mouseover", function(){
		suggestions_hovered_friday=1;
	});
	$("#friday_suggestions").live("mouseout", function(){
		suggestions_hovered_friday=0;
	});
	
	$("#friday_add_subject").live("keyup", function(e){
		if(e.which==13){
			e.preventDefault();
			suggestions_hovered_friday=0;//reset the hover to enter cleanly in the blur()
			$("#friday_add_subject").trigger("addSubject");//trigger the same blur event as below; when user clicks on suggestion, it automatically adds to list, clearing the input and sending the subject name to database
		}
		else{
			$("#friday_add_subject").attr("size", ($("#friday_add_subject").val().length+2));//resize input
			$("#friday_suggestions").empty().show();
			if($("#friday_add_subject").val().length>=2){
				$("#friday_suggestions").html("<ul><li>Loading...</li></ul>");
				$.ajax({
					type: "POST",
					url: "widget_schedule/ajax/subjectSuggestions.php",
					data: "q="+$("#friday_add_subject").val(),
					success: function(data){
						$("#friday_suggestions").html(data);
					}
				});
			}
			else{
				$("#friday_suggestions").html("<ul><li>Start typing...</li></ul>").show();	
			}
		}
	});
	
	$("#friday_add_subject").live("focus", function(){
		if($("ul#friday").children().length>=11){//check if the limit of subjects has been reached
			if(!$("ul#friday li#err").length){//check if another error message was not sent
				$("#friday_add_subject").attr("disabled", "disabled");
				$("ul#friday li#as").after("<li id='err' class='error'>The limit of subjects has been reached!</li>");
			}
		}
		else
			if($("#friday_add_subject").val()!=''){//if text is entered in input, then show the suggestions on input focus
				$("#friday_suggestions").show();
			}
			else{
				$("#friday_suggestions").html("<ul><li>Start typing...</li></ul>").show();	
			}
	});
	$("#friday_add_subject").live("blur", function(){
		if(list_hovered_friday==0&&suggestions_hovered_friday==0)//hide suggestions only if user clicks outside input and not in the list or suggestion list
			$("#friday_suggestions").hide();
	});

	$("#friday_add_subject").live("addSubject", function(){
		if($("ul#friday").children().length<11){//continue only if subject limit was not reached
			$("#friday_add_subject").attr("size", "2");//resize input
			$("#friday_suggestions").hide();
			if(jQuery.trim($("#friday_add_subject").val())!=""&&$("#friday_add_subject").val().length>=3){//only if some value exists in input
				$.ajax({//send the subject and insert it into db if it doesn't exist
					async: false,//important! if set to true, val("") executes before ajax request completes and <span> with sb name remains empty
					type: "POST",
					url: "widget_schedule/ajax/addSubject.php",
					data: "subject="+$("#friday_add_subject").val(),
					success: function(data){
						if(data==0){
							$("ul#friday li#as").after("<li id='err' class='error'>An error occured when trying to send your request.</li>");
							$("ul#friday li#err").delay(3000).fadeOut();
						}
						else{
							var subject_id=data;
							$("ul#friday li#as").before("<li id='friday_"+subject_id+"'><img src='images/move.png' alt='Move' class='move' /><span>"+$("#friday_add_subject").val()+"</span><img src='images/delete_small.png' alt='Delete' class='delete' /></li>");//add new list element with new subject before input text	
							if($("ul#friday").children().length>=2&&$("ul#friday li#ns").length)//remove schedule not set item if subjects have been added
								$("ul#friday li#ns").remove();
							if($("ul#friday").children().length>=2&&$("ul#friday li#fd").length)//remove free day item if subjects have been added
								$("ul#friday li#fd").remove();
								
							updateSchedule("friday");
						}
					},
					error: function(xhr,text){
						$("ul#friday li#as").after("<li id='err' class='error'>Error: "+text+"</li>");
						$("ul#friday li#err").delay(3000).fadeOut().remove($("ul#friday li#err"));
					}
				});
				$("#friday_add_subject").val("");//empty input from any user inputted text
			}
		}
	});
	
	$("div#friday_suggestions ul li span[id^='subject_']").live("click", function(){
		var divID=$(this).parent().parent().parent().attr("id");//span->li->ul->div id
		var day=divID.split("_");
		$("#"+day[0]+"_add_subject").val($(this).text());
		$("#friday_suggestions").hide();
		suggestions_hovered_friday=0;//reset the hover to enter cleanly in the blur()
		$("#friday_add_subject").trigger("addSubject");//trigger the same blur event as above; when user clicks on suggestion, it automatically adds to list, clearing the input and sending the subject name to database
	});
	

	$("ul#friday li img.delete").live("click", function(){
		$(this).parent().remove();
		if($("#friday").children().length==1)//add free day item if all subjects have been deleted
			$("#friday").prepend("<li id='fd'>Free Day</li>");
		if($("ul#friday").children().length==11){//check if the limit element has been removed; if so, remove the error message
			$("#friday_add_subject").removeAttr("disabled");
			$("ul#friday li#err").remove();
		}
		updateSchedule("friday");
	});
	
	var list_hovered_saturday=0;
	$("#saturday > li").live("mouseover", function(){
		list_hovered_saturday=1;
	});
	$("#saturday > li").live("mouseout", function(){
		list_hovered_saturday=0;
	});
	$("#saturday").live("click", function(){
		if(list_hovered_saturday==0)
			$("#saturday_add_subject").focus();
	});
	
	var suggestions_hovered_saturday=0;
	$("#saturday_suggestions").live("mouseover", function(){
		suggestions_hovered_saturday=1;
	});
	$("#saturday_suggestions").live("mouseout", function(){
		suggestions_hovered_saturday=0;
	});
	
	$("#saturday_add_subject").live("keyup", function(e){
		if(e.which==13){
			e.preventDefault();
			suggestions_hovered_saturday=0;//reset the hover to enter cleanly in the blur()
			$("#saturday_add_subject").trigger("addSubject");//trigger the same blur event as below; when user clicks on suggestion, it automatically adds to list, clearing the input and sending the subject name to database
		}
		else{
			$("#saturday_add_subject").attr("size", ($("#saturday_add_subject").val().length+2));//resize input
			$("#saturday_suggestions").empty().show();
			if($("#saturday_add_subject").val().length>=2){
				$("#saturday_suggestions").html("<ul><li>Loading...</li></ul>");
				$.ajax({
					type: "POST",
					url: "widget_schedule/ajax/subjectSuggestions.php",
					data: "q="+$("#saturday_add_subject").val(),
					success: function(data){
						$("#saturday_suggestions").html(data);
					}
				});
			}
			else{
				$("#saturday_suggestions").html("<ul><li>Start typing...</li></ul>").show();	
			}
		}
	});
	
	$("#saturday_add_subject").live("focus", function(){
		if($("ul#saturday").children().length>=11){//check if the limit of subjects has been reached
			if(!$("ul#saturday li#err").length){//check if another error message was not sent
				$("#saturday_add_subject").attr("disabled", "disabled");
				$("ul#saturday li#as").after("<li id='err' class='error'>The limit of subjects has been reached!</li>");
			}
		}
		else
			if($("#saturday_add_subject").val()!=''){//if text is entered in input, then show the suggestions on input focus
				$("#saturday_suggestions").show();
			}
			else{
				$("#saturday_suggestions").html("<ul><li>Start typing...</li></ul>").show();	
			}
	});
	$("#saturday_add_subject").live("blur", function(){
		if(list_hovered_saturday==0&&suggestions_hovered_saturday==0)//hide suggestions only if user clicks outside input and not in the list or suggestion list
			$("#saturday_suggestions").hide();
	});
	
	$("#saturday_add_subject").live("addSubject", function(){
		if($("ul#saturday").children().length<11){//continue only if subject limit was not reached
			$("#saturday_add_subject").attr("size", "2");//resize input
			$("#saturday_suggestions").hide();
			if(jQuery.trim($("#saturday_add_subject").val())!=""&&$("#saturday_add_subject").val().length>=3){//only if some value exists in input
				$.ajax({//send the subject and insert it into db if it doesn't exist
					async: false,//important! if set to true, val("") executes before ajax request completes and <span> with sb name remains empty
					type: "POST",
					url: "widget_schedule/ajax/addSubject.php",
					data: "subject="+$("#saturday_add_subject").val(),
					success: function(data){
						if(data==0){
							$("ul#saturday li#as").after("<li id='err' class='error'>An error occured when trying to send your request.</li>");
							$("ul#saturday li#err").delay(3000).fadeOut();
						}
						else{
							var subject_id=data;
							$("ul#saturday li#as").before("<li id='saturday_"+subject_id+"'><img src='images/move.png' alt='Move' class='move' /><span>"+$("#saturday_add_subject").val()+"</span><img src='images/delete_small.png' alt='Delete' class='delete' /></li>");//add new list element with new subject before input text	
							if($("ul#saturday").children().length>=2&&$("ul#saturday li#ns").length)//remove schedule not set item if subjects have been added
								$("ul#saturday li#ns").remove();
							if($("ul#saturday").children().length>=2&&$("ul#saturday li#fd").length)//remove free day item if subjects have been added
								$("ul#saturday li#fd").remove();
								
							updateSchedule("saturday");
						}
					},
					error: function(xhr,text){
						$("ul#saturday li#as").after("<li id='err' class='error'>Error: "+text+"</li>");
						$("ul#saturday li#err").delay(3000).fadeOut().remove($("ul#saturday li#err"));
					}
				});
				$("#saturday_add_subject").val("");//empty input from any user inputted text
			}
		}
	});
	
	$("div#saturday_suggestions ul li span[id^='subject_']").live("click", function(){
		var divID=$(this).parent().parent().parent().attr("id");//span->li->ul->div id
		var day=divID.split("_");
		$("#"+day[0]+"_add_subject").val($(this).text());
		$("#saturday_suggestions").hide();
		suggestions_hovered_saturday=0;//reset the hover to enter cleanly in the blur()
		$("#saturday_add_subject").trigger("addSubject");//trigger the same blur event as above; when user clicks on suggestion, it automatically adds to list, clearing the input and sending the subject name to database
	});
	

	$("ul#saturday li img.delete").live("click", function(){
		$(this).parent().remove();
		if($("#saturday").children().length==1)//add free day item if all subjects have been deleted
			$("#saturday").prepend("<li id='fd'>Free Day</li>");
		if($("ul#saturday").children().length==11){//check if the limit element has been removed; if so, remove the error message
			$("#saturday_add_subject").removeAttr("disabled");
			$("ul#saturday li#err").remove();
		}
		updateSchedule("saturday");
	});
	
	var list_hovered_sunday=0;
	$("#sunday > li").live("mouseover", function(){
		list_hovered_sunday=1;
	});
	$("#sunday > li").live("mouseout", function(){
		list_hovered_sunday=0;
	});
	$("#sunday").live("click", function(){
		if(list_hovered_sunday==0)
			$("#sunday_add_subject").focus();
	});
	
	var suggestions_hovered_sunday=0;
	$("#sunday_suggestions").live("mouseover", function(){
		suggestions_hovered_sunday=1;
	});
	$("#sunday_suggestions").live("mouseout", function(){
		suggestions_hovered_sunday=0;
	});
	
	$("#sunday_add_subject").live("keyup", function(e){
		if(e.which==13){
			e.preventDefault();
			suggestions_hovered_sunday=0;//reset the hover to enter cleanly in the blur()
			$("#sunday_add_subject").trigger("addSubject");//trigger the same blur event as below; when user clicks on suggestion, it automatically adds to list, clearing the input and sending the subject name to database
		}
		else{
			$("#sunday_add_subject").attr("size", ($("#sunday_add_subject").val().length+2));//resize input
			$("#sunday_suggestions").empty().show();
			if($("#sunday_add_subject").val().length>=2){
				$("#sunday_suggestions").html("<ul><li>Loading...</li></ul>");
				$.ajax({
					type: "POST",
					url: "widget_schedule/ajax/subjectSuggestions.php",
					data: "q="+$("#sunday_add_subject").val(),
					success: function(data){
						$("#sunday_suggestions").html(data);
					}
				});
			}
			else{
				$("#sunday_suggestions").html("<ul><li>Start typing...</li></ul>").show();	
			}
		}
	});
	
	$("#sunday_add_subject").live("focus", function(){
		if($("ul#sunday").children().length>=11){//check if the limit of subjects has been reached
			if(!$("ul#sunday li#err").length){//check if another error message was not sent
				$("#sunday_add_subject").attr("disabled", "disabled");
				$("ul#sunday li#as").after("<li id='err' class='error'>The limit of subjects has been reached!</li>");
			}
		}
		else
			if($("#sunday_add_subject").val()!=''){//if text is entered in input, then show the suggestions on input focus
				$("#sunday_suggestions").show();
			}
			else{
				$("#sunday_suggestions").html("<ul><li>Start typing...</li></ul>").show();	
			}
	});
	$("#sunday_add_subject").live("blur", function(){
		if(list_hovered_sunday==0&&suggestions_hovered_sunday==0)//hide suggestions only if user clicks outside input and not in the list or suggestion list
			$("#sunday_suggestions").hide();
	});

	$("#sunday_add_subject").live("addSubject", function(){
		if($("ul#sunday").children().length<11){//continue only if subject limit was not reached
			$("#sunday_add_subject").attr("size", "2");//resize input
			$("#sunday_suggestions").hide();
			if(jQuery.trim($("#sunday_add_subject").val())!=""&&$("#sunday_add_subject").val().length>=3){//only if some value exists in input
				$.ajax({//send the subject and insert it into db if it doesn't exist
					async: false,//important! if set to true, val("") executes before ajax request completes and <span> with sb name remains empty
					type: "POST",
					url: "widget_schedule/ajax/addSubject.php",
					data: "subject="+$("#sunday_add_subject").val(),
					success: function(data){
						if(data==0){
							$("ul#sunday li#as").after("<li id='err' class='error'>An error occured when trying to send your request.</li>");
							$("ul#sunday li#err").delay(3000).fadeOut();
						}
						else{
							var subject_id=data;
							$("ul#sunday li#as").before("<li id='sunday_"+subject_id+"'><img src='images/move.png' alt='Move' class='move' /><span>"+$("#sunday_add_subject").val()+"</span><img src='images/delete_small.png' alt='Delete' class='delete' /></li>");//add new list element with new subject before input text	
							if($("ul#sunday").children().length>=2&&$("ul#sunday li#ns").length)//remove schedule not set item if subjects have been added
								$("ul#sunday li#ns").remove();
							if($("ul#sunday").children().length>=2&&$("ul#sunday li#fd").length)//remove free day item if subjects have been added
								$("ul#sunday li#fd").remove();
								
							updateSchedule("sunday");
						}
					},
					error: function(xhr,text){
						$("ul#sunday li#as").after("<li id='err' class='error'>Error: "+text+"</li>");
						$("ul#sunday li#err").delay(3000).fadeOut().remove($("ul#sunday li#err"));
					}
				});
				$("#sunday_add_subject").val("");//empty input from any user inputted text
			}
		}
	});
	
	$("div#sunday_suggestions ul li span[id^='subject_']").live("click", function(){
		var divID=$(this).parent().parent().parent().attr("id");//span->li->ul->div id
		var day=divID.split("_");
		$("#"+day[0]+"_add_subject").val($(this).text());
		$("#sunday_suggestions").hide();
		suggestions_hovered_sunday=0;//reset the hover to enter cleanly in the blur()
		$("#sunday_add_subject").trigger("addSubject");//trigger the same blur event as above; when user clicks on suggestion, it automatically adds to list, clearing the input and sending the subject name to database
	});
	

	$("ul#sunday li img.delete").live("click", function(){
		$(this).parent().remove();
		if($("#sunday").children().length==1)//add free day item if all subjects have been deleted
			$("#sunday").prepend("<li id='fd'>Free Day</li>");
		if($("ul#sunday").children().length==11){//check if the limit element has been removed; if so, remove the error message
			$("#sunday_add_subject").removeAttr("disabled");
			$("ul#sunday li#err").remove();
		}
		updateSchedule("sunday");
	});
	
});

function loadSortableSchedule(day){
	if(day=='all'){
		$("#monday").sortable({
			handle: '.move',
			update: function(){
				updateSchedule("monday");
			}
		}); 
		$("#tuesday").sortable({
			handle: '.move',
			update: function(){
				updateSchedule("tuesday");
			}
		}); 
		$("#wednesday").sortable({
			handle: '.move',
			update: function(){
				updateSchedule("wednesday");
			}
		}); 
		$("#thursday").sortable({
			handle: '.move',
			update: function(){
				updateSchedule("thursday");
			}
		}); 
		$("#friday").sortable({
			handle: '.move',
			update: function(){
				updateSchedule("friday");
			}
		}); 
		$("#saturday").sortable({
			handle: '.move',
			update: function(){
				updateSchedule("saturday");
			}
		}); 
		$("#sunday").sortable({
			handle: '.move',
			update: function(){
				updateSchedule("sunday");
			}
		}); 
	}
	else{
		$("#"+day).sortable({
			handle: '.move',
			update: function(){
				updateSchedule(day);
			}
		}); 
	}
}

function updateSchedule(day){ 
	if($("#"+day+" #fd").length)//if free day element exists, than update the database corresponding field to -1
		var order=day+"[]=-1";
	else//else serialize the subjects and send their id's to be updated in corresponding field
		var order=$("#"+day).sortable('serialize');

	$.get("widget_schedule/ajax/updateSchedule.php?uwid="+$("#uwid").val()+"&day="+day+"&"+order, function(data){
		if(data!=1){
			$("ul#"+day+" li#as").after("<li id='err' class='error'></li>");
			$("ul#"+day+" li#err").html(data).delay(10000).fadeOut().remove($("ul#"+day+" li#err")); 
		}
	});
}

function editSchedule(uwid){
	$("#dimBackground").show();
	$("#settings").show();
	
	$.ajax({
		type: "GET",
		url: "widget_schedule/ajax/editSchedule.php",
		data: "uwid="+uwid,
		beforeSend: function(){
			$("#settings").html("<div class='load'></div>");
		},
		success: function(data){
			$("#settings").html(data);
			loadSortableSchedule("all");	
		},
		error: function(xhr,error){
			$("#settings").html("<div class='error'>Error: "+error+"</div>");
		}
	});
}







function GetXmlHttpObject(){
	if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
	  return new XMLHttpRequest();
	}
	if (window.ActiveXObject){// code for IE6, IE5
	  return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

function scheduleTimeout(uwid,auto_refresh_interval){
	window['xmlhttpSchedule_'+uwid].abort();
	document.getElementById("schedule_"+uwid).innerHTML="<div class='error'>Connection has timed out <input type='button' class='ImagesRefresh' onclick='getSchedule("+uwid+", "+auto_refresh_interval+")' /> <input type='button' class='ImagesSettings' onclick='showSettings("+uwid+")' /></div>";
}

function getSchedule(uwid,auto_refresh_interval,weekday){
	
	if(typeof(window['auto_refresh_schedule_'+uwid])!="undefined"){
		clearTimeout(window['auto_refresh_schedule_'+uwid]);
	}
	
	window['xmlhttpSchedule_'+uwid]=GetXmlHttpObject();
	
	if (window['xmlhttpSchedule_'+uwid]==null){
		alert ("Browser does not support HTTP Request");
	  	return;
	}
	
	var url="widget_schedule/ajax/getSchedule.php";
	url=url+"?uwid="+uwid;
	if(weekday!=undefined)
		url=url+"&weekday="+weekday;
	url=url+"&sid="+Math.random();
	window['xmlhttpSchedule_'+uwid].onreadystatechange=function(){
		if (window['xmlhttpSchedule_'+uwid].readyState!=4){
			document.getElementById("schedule_"+uwid).innerHTML="<div class='load'></div>";
		}
		if (window['xmlhttpSchedule_'+uwid].readyState==4){
			clearTimeout(window['schedule_'+uwid+'_timeout']);
			document.getElementById("schedule_"+uwid).innerHTML=window['xmlhttpSchedule_'+uwid].responseText;
			if(auto_refresh_interval!=0)
				window['auto_refresh_schedule_'+uwid]=setTimeout('getSchedule(' + uwid + ', ' + auto_refresh_interval + ')', (auto_refresh_interval*1000));//auto-refresh function	
		}
	}
	window['xmlhttpSchedule_'+uwid].open("GET",url,true);
	window['xmlhttpSchedule_'+uwid].send(null);
	
	window['schedule_'+uwid+'_timeout']=setTimeout("scheduleTimeout("+uwid+", "+auto_refresh_interval+")", 5000);
}

function enableDisableAutoRefreshSchedule(id,value){
	if(value==1)
		document.getElementById(id).removeAttribute("disabled");
	else
		if(value==0)
			document.getElementById(id).setAttribute("disabled", "disabled");
}

function hideElement(id){
	document.getElementById(id).style.display="none";	
}

function showElement(id){
	document.getElementById(id).style.display="inline";	
}

function highlightDay(uwid,weekday){
	all_days=document.getElementById("daysBackground_"+uwid);	//parse all days
	for(i=0;i<all_days.childNodes.length-3;i++){// -3 for the <span> and two settings <button>s
		if(all_days.childNodes[i].name==weekday+"_button_"+uwid)
			document.getElementById(weekday+"_button_"+uwid).setAttribute("class", "select");	//if new changed day, change highlight background on selected day
		else
			document.getElementById(all_days.childNodes[i].name).removeAttribute("class");	//if not new changed day, remove attribute class (so as not to be selected - the old day and the new one)
	}	
}

function showSettings(uwid){
	document.getElementById("dimBackground").style.display="block";
	document.getElementById("settings").style.display="block";
	//document.getElementById("settings").innerHTML="settings";
	
	window['xmlhttpSchedule_'+uwid]=GetXmlHttpObject();
	
	if (window['xmlhttpSchedule_'+uwid]==null){
		alert ("Browser does not support HTTP Request");
	  	return;
	}
	
	var url="widget_schedule/ajax/showSettings.php";
	url=url+"?uwid="+uwid+"&sid="+Math.random();
	window['xmlhttpSchedule_'+uwid].onreadystatechange=function(){
		if (window['xmlhttpSchedule_'+uwid].readyState!=4){
			document.getElementById("settings").innerHTML="<div class='load'></div>";
		}
		if (window['xmlhttpSchedule_'+uwid].readyState==4){
			document.getElementById("settings").innerHTML=window['xmlhttpSchedule_'+uwid].responseText;
		}
	};
	window['xmlhttpSchedule_'+uwid].open("GET",url,true);
	window['xmlhttpSchedule_'+uwid].send(null);
}

/*function editSchedule(uwid){
	document.getElementById("dimBackground").style.display="block";
	document.getElementById("settings").style.display="block";
	//document.getElementById("settings").innerHTML="settings";
	
	window['xmlhttpSchedule_'+uwid]=GetXmlHttpObject();
	
	if (window['xmlhttpSchedule_'+uwid]==null){
		alert ("Browser does not support HTTP Request");
	  	return;
	}
	
	var url="widget_schedule/ajax/editSchedule.php";
	url=url+"?uwid="+uwid+"&sid="+Math.random();
	window['xmlhttpSchedule_'+uwid].onreadystatechange=function(){
		if (window['xmlhttpSchedule_'+uwid].readyState!=4){
			document.getElementById("settings").innerHTML="<div class='load'></div>";
		}
		if (window['xmlhttpSchedule_'+uwid].readyState==4){
			document.getElementById("settings").innerHTML=window['xmlhttpSchedule_'+uwid].responseText;
		}
	};
	window['xmlhttpSchedule_'+uwid].open("GET",url,true);
	window['xmlhttpSchedule_'+uwid].send(null);
}
*/
function hideSettings(){
	document.getElementById("settings").style.display="none";
	document.getElementById("dimBackground").style.display="none";
}

function updateField(uwid,field_name,value){
	
	window['xmlhttpSchedule_'+uwid]=GetXmlHttpObject();
	
	if (window['xmlhttpSchedule_'+uwid]==null){
		alert ("Browser does not support HTTP Request");
	  	return;
	}
	
	value=encodeURIComponent(value);
	
	var url="widget_schedule/ajax/updateField.php";
	url=url+"?uwid="+uwid+"&field_name="+field_name+"&value="+value;
	url=url+"&sid="+Math.random();
	window['xmlhttpSchedule_'+uwid].onreadystatechange=function(){
		if (window['xmlhttpSchedule_'+uwid].readyState!=4){
			document.getElementById("update_field_status").innerHTML="<div class='load'></div>";
		}
		if (window['xmlhttpSchedule_'+uwid].readyState==4){
			document.getElementById("update_field_status").innerHTML="";//remove loading icon
			if(field_name=="change_hour"||field_name=="change_minute")//if one of those, change the field name to the general one
				field_name="change_time";
				
			if(window['xmlhttpSchedule_'+uwid].responseText==1){//if data was valid and settings have been saved...
				//showSettings(uwid);//...refresh the settings page...
				//document.getElementById("update_field_status").innerHTML="<img src='../images/success.png' alt='Settings have been successfully saved' title='Settings have been successfully saved' />";//..and display an 'OK' icon...
				//$("#update_field_status").delay(1000).fadeOut(1000);///...for 1 second
				document.getElementById("validate_"+field_name).setAttribute("class", "success");
				document.getElementById("validate_"+field_name).style.display="inline";
				document.getElementById("validate_"+field_name).innerHTML='<span class="pointer">&nbsp;</span>'+'OK';
				$("#validate_"+field_name).delay(1000).fadeOut(1000);
				
				if(field_name=="auto_refresh"&&value==1){//if auto refresh has been enabled, change the onclick event of the exit button
					auto_refresh_interval=document.getElementById("auto_refresh_interval").value;
					document.getElementById("exit_"+uwid).setAttribute("onclick", "hideSettings(); getSchedule("+uwid+", "+auto_refresh_interval+");");
				}
				if(field_name=="auto_refresh"&&value==0){//if auto refresh has been disabled, change the onclick event of the exit button
					document.getElementById("exit_"+uwid).setAttribute("onclick", "hideSettings(); getSchedule("+uwid+", 0);");
				}
				if(field_name=="auto_refresh_interval"){//if auto refresh interval has changed...
					if(document.getElementById("auto_refresh_1").checked)//.and auto refresh is enabled, change the onclick event of the exit button
						document.getElementById("exit_"+uwid).setAttribute("onclick", "hideSettings(); getSchedule("+uwid+", "+value+");");
				}
			}
			else if(window['xmlhttpSchedule_'+uwid].responseText==0){//...else, if data was valid but settings could not be saved...
				//showSettings(uwid);//...refresh the settings page...
				//document.getElementById("update_field_status").innerHTML="<img src='../images/error.png' alt='Settings could not be saved' title='Settings could not be saved' />";//..and display an 'ERROR' icon...
				//$("#update_field_status").delay(1000).fadeOut(1000);///...for 1 second
				document.getElementById("validate_"+field_name).setAttribute("class", "error");
				document.getElementById("validate_"+field_name).style.display="inline";
				document.getElementById("validate_"+field_name).innerHTML='<span class="pointer">&nbsp;</span>'+'Error';
				$("#validate_"+field_name).delay(3000).fadeOut(1000);
			}
			else{//...else, data was not valid...
				document.getElementById("validate_"+field_name).setAttribute("class", "error");
				document.getElementById("validate_"+field_name).style.display="inline";
				document.getElementById("validate_"+field_name).innerHTML='<span class="pointer">&nbsp;</span>'+window['xmlhttpSchedule_'+uwid].responseText;
				$("#validate_"+field_name).delay(3000).fadeOut(1000);
			}
		}
	};
	window['xmlhttpSchedule_'+uwid].open("GET",url,true);
	window['xmlhttpSchedule_'+uwid].send(null);
}

function elementInfoSchedule(uwid,element){
	
	document.getElementById("validate_"+element).removeAttribute("class"); //remove previous errors (if any) and show the normal tooltip
	
	window['xmlhttpSchedule_'+uwid+'_elementInfo']=GetXmlHttpObject();
	
	if (window['xmlhttpSchedule_'+uwid+'_elementInfo']==null){
		alert ("Browser does not support HTTP Request");
	  	return;
	}
	
	var url="widget_schedule/ajax/elementInfoSchedule.php";
	url=url+"?"+element+"&sid="+Math.random();
	
	window['xmlhttpSchedule_'+uwid+'_elementInfo'].open("GET",url,false);
	window['xmlhttpSchedule_'+uwid+'_elementInfo'].send(null);
	
	document.getElementById("validate_"+element).style.display="inline";
	document.getElementById("validate_"+element).innerHTML='<span class="pointer">&nbsp;</span>'+window['xmlhttpSchedule_'+uwid+'_elementInfo'].responseText;
	$("#validate_"+element).delay(3000).fadeOut(1000);
}
