function AddDate()
{

    if(document.getElementById('Add').src.indexOf("images/02.gif")!=-1)
        return;

    //set date
    var date=document.getElementById("date");
//    alert(date.value);
    if(date.value=="")
    {
        today = new Date();
        date.value = FormatDate(today);
    }

    var schaction=document.getElementById("scheduleAction");
    schaction.value="Add";
    //get data
    var request = new Request.JSON({
			  url:    "getdata.php",
			 onSuccess:  function(responseText){

                //var tb = $('ChatList');
                //while(tb.rows.length>1)
                    //tb.deleteRow(1);
                //set title
                var scheduleTitle=document.getElementById("ScheduleTitle");
                scheduleTitle.innerHTML="Chat Room Schedule For "+responseText[0]['DateTitle'];

                 //set the sub/add image
                var subImg = document.getElementById('Sub');
                var addImg=document.getElementById('Add');
                if(responseText[0]['PreDay'])
                     subImg.src="images/03.gif";
                 if(!responseText[0]['NextDay'])
                     addImg.src="images/02.gif";

                 //set value of date element
                date.value=responseText[0]['Date'];
				var temp='<tr align="left" style="color: gray; font-size:16px;"><th width="25%">Show Time</th><th width="45%">Subject</th><th width="30%" align="center" >Hosted By</th></tr>';
                //add data
            	for(var i=1;i<responseText.length;i++)
                {
               //    var row = document.createElement("tr");
                   //var row = tb.insertRow(tb.rows.length);
                   //row.className="setchatFont";
				   /*
				   var td0 =document.createElement('td');
				   td0.appendChild(document.createTextNode(responseText[i]['Show Time']));
				   var td1 =document.createElement('td');
				   td1.appendChild(document.createTextNode(responseText[i]['Subject']));
				   var td2 =document.createElement('td');
                   td2.className="alignCenter";
                   td2.appendChild(document.createTextNode(responseText[i]['HostBy']));

				   row.appendChild(td0);
				   row.appendChild(td1);
				   row.appendChild(td2);
				   */
				   temp+='<tr class="setchatFont"><td>'+responseText[i]['Show Time']+'</td><td tips="'+responseText[i]['tip_subject']+'" onmouseover="showTips(this,event)" onmousemove="showTips(this,event)" onmouseout="hideTips()" style="cursor:pointer">'+responseText[i]['Subject']+'</td><td tips="'+responseText[i]['tip_hosted_by']+'" align="center" onmouseover="showTips(this,event)" onmousemove="showTips(this,event)" onmouseout="hideTips()" style="cursor:pointer">'+responseText[i]['HostBy']+'</td></tr>';
			//	   tb.appendChild(row);
                }
            	$('FirstArea').setStyle('display', 'none');
				$('ScheduleArea').innerHTML="<table id='ChatList' width='100%'>"+temp+"</table>";
			 }
		}).send({method: 'post',data: 'date='+date.value+'&scheduleAction='+schaction.value});


}

function SubDate()
{
    if(document.getElementById('Sub').src.indexOf("images/04.gif")!=-1)
        return;
     //set date
    var dateValue;
    var date=document.getElementById("date");
    if(date.value=="")
    {
        today = new Date();
        date.value = FormatDate(today);
    }
    var schaction=document.getElementById("scheduleAction");
    schaction.value="Sub";
  
    //get data
    var request = new Request.JSON({
			  url:    "getdata.php",
			 onSuccess:  function(responseText){
            //    alert(date.value + "Success");
                //var tb = $('ChatList');
               // while(tb.rows.length>1)
                    //tb.deleteRow(1);
                //set title
                var scheduleTitle=document.getElementById("ScheduleTitle");
                scheduleTitle.innerHTML="Chat Room Schedule For "+responseText[0]['DateTitle'];

                 //set the sub/add image
                if(!responseText[0]['PreDay'])
                {
                     var subImg =  document.getElementById('Sub');
                     subImg.src="images/04.gif";

                 }
                 if(responseText[0]['NextDay'])
                 {
                     var addImg=document.getElementById('Add');
                     addImg.src="images/01.gif";
                 }

                 //set value of date element
                date.value=responseText[0]['Date'];
				var temp='<tr align="left" style="color: gray; font-size:16px;"><th width="25%">Show Time</th><th width="45%">Subject</th><th width="30%" align="center" >Hosted By</th></tr>';
                //add data
            	for(var i=1;i<responseText.length;i++)
                {
               //    var row = document.createElement("tr");
                   //var row = tb.insertRow(tb.rows.length);
                   //row.className="setchatFont";
				   /*
				   var td0 =document.createElement('td');
				   td0.appendChild(document.createTextNode(responseText[i]['Show Time']));
				   var td1 =document.createElement('td');
				   td1.appendChild(document.createTextNode(responseText[i]['Subject']));
				   var td2 =document.createElement('td');
                   td2.className="alignCenter";
                   td2.appendChild(document.createTextNode(responseText[i]['HostBy']));

				   row.appendChild(td0);
				   row.appendChild(td1);
				   row.appendChild(td2);
			//	   tb.appendChild(row);
			       */
				   temp+='<tr class="setchatFont"><td>'+responseText[i]['Show Time']+'</td><td tips="'+responseText[i]['tip_subject']+'" onmouseover="showTips(this,event)" onmousemove="showTips(this,event)" onmouseout="hideTips()" style="cursor:pointer">'+responseText[i]['Subject']+'</td><td tips="'+responseText[i]['tip_hosted_by']+'" align="center" onmouseover="showTips(this,event)" onmousemove="showTips(this,event)" onmouseout="hideTips()" style="cursor:pointer">'+responseText[i]['HostBy']+'</td></tr>';
                }
            	$('FirstArea').setStyle('display', 'none');
				$('ScheduleArea').innerHTML="<table id='ChatList' width='100%'>"+temp+"</table>";
			 }
		}).send({method: 'post',data: 'date='+date.value+'&scheduleAction='+schaction.value});

}
function FormatDate(date)
{
    var month=date.getMonth()+1;
    return date.getFullYear()+"-"+month+"-"+date.getDate();
}
