function deleteTask(id)
{
	var sure=confirm("Are you sure you want to delete this task?");
	if(sure==true)
	{
		if(xmlHttpDel.readyState==4 || xmlHttpDel.readyState==0)
	    {
			xmlHttpDel.open("GET", "show.php?del=true&id="+id, true);
			xmlHttpDel.send(null);
			
			var day=document.getElementById("hiddenDay").value;
			var mon=document.getElementById("hiddenMon").value;
					document.getElementById("deleteTask").innerHTML="";
	                document.getElementById("changeTask").innerHTML="";

			process(day, mon);

		}
	}
}
function changeTask(id)
{
	if(xmlHttpCh.readyState==4 || xmlHttpCh.readyState==0)
	{
			xmlHttpCh.open("GET", "show.php?change=true&id="+id, true);
			xmlHttpCh.onreadystatechange=serverResponseChangeTask;
			xmlHttpCh.send(null);
		
	}
}

function serverResponseChangeTask()
{
	if(xmlHttpCh.readyState==4)
	{
		if(xmlHttpCh.status==200)
		{

		xmlResponse=xmlHttpCh.responseXML;
		xmlDocumentElement=xmlResponse.documentElement;			
		show=xmlDocumentElement.getElementsByTagName("show");		
		taskTitle=xmlDocumentElement.getElementsByTagName("taskTitle");
		taskId=xmlDocumentElement.getElementsByTagName("id");		

		var showData="";	
		var taskTitleData="";		
		var id="";			

		for(var i=0; i<show.length; i++)
		{
   			id=taskId.item(i).firstChild.data;
			showData=show.item(i).firstChild.data;
			title=taskTitle.item(i).firstChild.data;

            var str="<form name=\"ch_form\" method=\"post\"><input type=\"text\" id=\"task\" value=\""+title+"\"><br />";
                str+="<textarea id=\"taskText\" cols=\"45\" rows=\"5\">"+showData+"</textarea><br /><input type=\"button\"";
				str+="value=\"Add Task\" onclick=\"chTask("+id+");\"><input type=\"button\" value=\"Cancel\"";
				str+="onclick=document.getElementById(\"addTaskForm\").innerHTML=\"\";></form>";
			
			document.getElementById("addTaskForm").innerHTML=str;	
			document.getElementById("addTask").innerHTML="<a href=\"javascript:changeTask("+id+")\">Change Task</a>";

	    }
		}
	}	
}
function chTask(id)
{
	var task=document.getElementById("task").value;
	var taskText=document.getElementById("taskText").value;
	
	if((!task) || (!taskText)) 
	 document.getElementById("formAlert").innerHTML="Necessary fields are empty!";
	else
	{
		document.getElementById("formAlert").innerHTML="";
		document.getElementById("addTaskForm").innerHTML="";
		
		if(xmlHttp.readyState==4 || xmlHttp.readyState==0)
	    {
			var day=document.getElementById("hiddenDay").value;
			var mon=document.getElementById("hiddenMon").value;

			xmlHttpAdd.open("GET", "show.php?ch=true&task="+task+"&taskText="+taskText+"&id="+id, true);
			xmlHttpAdd.send(null);
			process(day, mon);
		}
		else
		setTimeout('chTask()', 1000);
	}
}
