﻿function setDate(str,id) {

 if (str == "   ") {
  return;
 }

 mnth1 = document.forms[0].month.value;
 ccmnth = mnth1;
 ccmnth++;
 year = document.forms[0].year.value;
 dateStr = ccmnth+"/"+str+"/"+year;

 dateStr = trim(dateStr);
 
 //Ftiaximo pali to original background se ola ta td
 for(i=3; i<=44; i++)
 {
	var elem = "calButton" + i;
	document.getElementById(elem).style.background = "#d82524";
	if(document.getElementById(elem).value == "   ")
	{
		document.getElementById(elem).style.cursor = "default";
	}
 }
 
 document.getElementById(id).style.background = "#a12625";
 document.getElementById("garbage").focus();
 
 	//-BEGIN REQUEST---------------------------
 	//alert(year);
	//alert(mnth1);
	//alert(str);
	var qyear = year;
	var qmonth = parseInt(mnth1)+1;
	var qday = str;
	
 	var query = "";
	var url = 'Default.aspx?t=events.aspx&day='+qday+"&month="+qmonth+"&year="+qyear;
	//alert(url);
	div = document.getElementById("apaki");
	//div.style.display = 'none';
	//if(query == '')
	//	return;

		var resp = "";	
		var req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");

		req.open('GET', url, false);
		req.send(null);
						

		resp = req.responseText;
		//alert(resp);
	div.style.visibility = "visible";
	div.innerHTML = resp;
	//----------------------------------------


}//setDate()

<!-- This function removes spaces from the selected date.--->

function trim(str) {

 res="";

 for(var i=0; i< str.length; i++) {
   if (str.charAt(i) != " ") {
     res +=str.charAt(i);
  }
 }
   
 return res;

}//trim()
 
<!-- This method retrieves the Month name given the Month number of the year. --->

function getMonthName(ccmnth) {

 if (ccmnth == 0) {
  name = "Ιανουάριος";
 }else if(ccmnth==1) {
  name = "Φεβρουάριος";
 }else if(ccmnth==2) {
  name = "Μάρτιος";
 }else if(ccmnth==3) {
  name = "Απρίλιος";
 }else if(ccmnth==4) {
  name = "Μάιος";
 } else if(ccmnth==5) {
  name = "Ιούνιος";
 } else if(ccmnth==6) {
  name = "Ιούλιος";
 } else if(ccmnth==7) {
  name = "Αύγουστος";
 } else if(ccmnth==8) {
  name = "Σεπτέμβριος";
 } else if(ccmnth==9) {
  name = "Οκτώβριος";
 } else if(ccmnth==10) {
  name = "Νοέμβριος";
 } else if(ccmnth==11) {
  name = "Δεκέμβριος";
 }

 return name;

}//getMonthName()

<!-- Get the number of days in the month based on the year. --->

function getNoOfDaysInMnth(ccmnth,yr) {
 
 rem = yr % 4;

 if(rem ==0) {
   leap = 1;
 } else {
  leap = 0;
 }

 noDays=0;

 if ( (ccmnth == 1) || (ccmnth == 3) || (ccmnth == 5) ||
      (ccmnth == 7) || (ccmnth == 8) || (ccmnth == 10) ||
      (ccmnth == 12)) {
  noDays=31;
 } else if (ccmnth == 2) {
           noDays=28+leap;
        } else {
           noDays=30;
 }

 //alert(noDays);
 return noDays;
 
      
}//getNoOfDaysInMnth()
  
<!-- The function to reset the date values in the buttons of the slots. --->

function fillDates(dayOfWeek1,noOfDaysInmnth) {

 for(var i=1; i<43; i++) {
   str = "s"+i;
   document.forms[0].elements[str].value="   ";
 }


 startSlotIndx = dayOfWeek1;
 slotIndx = startSlotIndx;

 for(var i=1; i<(noOfDaysInmnth+1); i++) {
  slotName = "s"+slotIndx;

  val="";
  if (i<10) {
    val = " "+i+" ";
  } else {
    val = i;
  }

  document.forms[0].elements[slotName].value = val;
  slotIndx++;
 }
 
 //Ftiaximo pali to original background se ola ta td
 for(i=3; i<=44; i++)
 {
	var elem = "calButton" + i;
	if(document.getElementById(elem).value == "   ")
	{
		document.getElementById(elem).style.cursor = "default";
	}
	else
	{
		document.getElementById(elem).style.cursor = "hand";
	}
	document.getElementById(elem).style.background = "#d82524";
 }
  
}//fillDates()
 

<!-- The function that is called at the time of loading the paage. --->
<!-- This function displays Today's date and also displays the --->
<!-- the calendar of the current month. --->
 

function thisMonth() {
	
  dt = new Date();
  ccmnth  = dt.getMonth(); /* 0-11*/
  dayOfMnth = dt.getDate(); /* 1-31*/
  dayOfWeek = dt.getDay(); /*0-6*/
  yr = dt.getFullYear(); /*4-digit year*/

  //alert("month:"+(ccmnth+1)+":dayofMnth:"+dayOfMnth+":dayofweek:"+dayOfWeek+":year:"+yr);

  mnthName = getMonthName(ccmnth)+ " ";
  document.forms[0].month.value = ccmnth;
  document.forms[0].year.value = yr;
  document.forms[0].currMonth.value = ccmnth;
  document.forms[0].currYear.value = yr;
  
  //<input type="text" size="15" name="monthYear" value="" ID="Text1">
  //document.forms[0].monthYear.value = mnthName+yr;
  document.getElementById("titleLbl").innerHTML = mnthName+yr;

  startStr = (ccmnth+1)+"/1/"+yr;
  dt1 = new Date(startStr);
  dayOfWeek1 = dt1.getDay(); /*0-6*/

  noOfDaysInMnth = getNoOfDaysInMnth(ccmnth+1,yr);
  fillDates(dayOfWeek1+1,noOfDaysInMnth);
  
  
  //osa td den periexoun imera, na min patiountai
  //proepilogi tis simerinis meras
 for(i=3; i<=44; i++)
 {
	var elem = "calButton" + i;
	if(document.getElementById(elem).value == "   ")
	{
		document.getElementById(elem).style.cursor = "default";
	}
	if(trim(document.getElementById(elem).value) == dayOfMnth)
	{
		document.getElementById(elem).style.background = "#a12625";
	}
 }

 
 
 //document.getElementById(id).style.background = "#a12625";
 	//-BEGIN REQUEST---------------------------
 	//alert(year);
	//alert(mnth1);
	//alert(str);
	var qyear = yr;
	var qmonth = parseInt(ccmnth) + 1;
	var qday = dayOfMnth;
	
 	var query = "";
	var url = 'Default.aspx?t=events.aspx&day='+qday+"&month="+qmonth+"&year="+qyear;
	
	div = document.getElementById("apaki");
	//div.style.display = 'none';
	//if(query == '')
	//	return;

		var resp = "";	
		var req = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("MSXML2.XMLHTTP.3.0");

		req.open('GET', url, false);
		req.send(null);
						

		resp = req.responseText;

	div.style.visibility = "visible";
	div.innerHTML = resp;
	//----------------------------------------
 

}//thisMonth()

<!--- The function that will be used to display the calendar of the next month. --->

function nextMonth() {
 
 div = document.getElementById("apaki");
 div.style.visibility = "hidden";
 
 var currMnth = document.forms[0].month.value;
 currYr = document.forms[0].year.value;

 if (currMnth == "11") {
    nextMnth = 0;
    nextYr = currYr;
    nextYr++;
 } else {
   nextMnth=currMnth;
   nextMnth++;
   nextYr = currYr;
 }

 mnthName = getMonthName(nextMnth);
 document.forms[0].month.value=nextMnth;
 document.forms[0].year.value=nextYr;
 //document.forms[0].monthYear.value= mnthName+" "+nextYr;
  document.getElementById("titleLbl").innerHTML = mnthName+" "+nextYr;
 
 str = (nextMnth+1)+"/1/"+nextYr;
 dt = new Date(str);
 dayOfWeek = dt.getDay();

 noOfDays = getNoOfDaysInMnth(nextMnth+1,nextYr);

 fillDates(dayOfWeek+1,noOfDays);
 
 document.getElementById("garbage").focus(); 

}//nextMonth()

<!--- The method to display the calendar of the previous month.--->

function prevMonth() {
 
 div = document.getElementById("apaki");
 div.style.visibility = "hidden";
 
 var currMnth = document.forms[0].month.value;
 currYr = document.forms[0].year.value;

 if (currMnth == "0") {
    prevMnth = 11;
    prevYr = currYr;
    prevYr--;
 } else {
   prevMnth=currMnth;
   prevMnth--;
   prevYr = currYr;
 }

 str = (prevMnth+1)+"/1/"+prevYr;
 dt = new Date(str);
 dayOfWeek = dt.getDay();

 <!-- Remove the comment if do not want the user to go to any previous month than this current month.-->

 runningMonth = document.forms[0].currMonth.value;
 rMonth=runningMonth;
 rMonth++;
 runningYear = document.forms[0].currYear.value;
 rYear=runningYear;

 str = (rMonth)+"/1/"+rYear;
 dt1 = new Date(str);
 
// if (dt.valueOf() < dt1.valueOf()) {
//   alert('Cannot Go Before Current Month');
//   return;
// }
 
 <!--- End of comment--->

 mnthName = getMonthName(prevMnth);
 document.forms[0].month.value=prevMnth;
 document.forms[0].year.value=prevYr;
 //document.forms[0].monthYear.value= mnthName+" "+prevYr;
  document.getElementById("titleLbl").innerHTML = mnthName+" "+prevYr;

 noOfDays = getNoOfDaysInMnth(prevMnth+1,prevYr);
 fillDates(dayOfWeek+1,noOfDays);
 
 document.getElementById("garbage").focus();
 
}//prevMonth()