/* trim spaces from string */
function trim(str) {
  return str.replace(/^\s*(\S*(\s+\S+)*)\s*$/, str);
}

/* get index of month */
function findIndex(monthsarray,number) {
for (i=0;i<monthsarray.length;i++)
	if (monthsarray[i] == number) return i;
 return -1;
}


/*send ajax request to server and update calendar dom with response */
/*update language parameter in href's*/ 
function performCalendarRefresh(month,year)
{

var post_url = "http://www.ellthea.gr/UpdateCalendar";

$j.post(post_url, { monthselect:month,yearselect:year },function(html){
   $j("#calendarbody").html(html);
   var language = $j("#siteLanguage").text() ;
   $j("#calendarbody a").each(function() {
   $j(this).attr('href',$j(this).attr('href').replace('##lang',language));
   $j(this).attr('href',$j(this).attr('href').replace('#lang',language));
   })
});   

}

/*
$j(document).ready(function() {

monthArray = new Array(8,9,10,11,0,1,2,3); // allowed months 
yearArray = new Array(2007,2007,2007,2007,2008,2008,2008,2008); // allowed months 
firstMonth = monthArray[0]; // calendar's first month 
lastMonth = monthArray[7]; // calendar's last month 

currentMonth = parseInt(trim($j("select#monthselect").val()));
index = findIndex(monthArray,currentMonth);

// user clicks left arrow in calendar 
$j("#monthPrev").click(function() {

//alert("epomeno");

//if (currentMonth == firstMonth) currentMonth = lastMonth;
if (currentMonth == firstMonth) return false; // do nothing if we are in first month 
 //else currentMonth--; 
 else {
 index--; 
 currentMonth = monthArray[index]; 
 }
$j("#calendarYear").val(yearArray[index]);
performCalendarRefresh(currentMonth,yearArray[index]);  // update calendar 
$j("#calendarMonthLabel").text($j("#month_"+currentMonth).text());//update calendar month shown 


return false;

});

*/

/* user clicks right arrow in calendar */

/*$j("#monthNext").cick(function() {

//if (currentMonth == lastMonth) currentMonth = firstMonth;
if (currentMonth == lastMonth) return false; // do nothing if we are in last month 
	else  {
	index++;
	currentMonth = monthArray[index]; 
	}
$j("#calendarYear").val(yearArray[index]);
performCalendarRefresh(currentMonth,yearArray[index]); // update calendar 
$j("#calendarMonthLabel").text($j("#month_"+currentMonth).text()); // update calendar month shown 


return false;
});*/


/* block calendar block while request is processed and unblock after */
//$j().ajaxStart(function(){$j("#calendarControls").block()});
//$j().ajaxStop(function(){$j("#calendarControls").unblock()});


//});

