function saveNewsDate(newsId, langId, date)
{
   var url = "actions/saveNewsDate.php";
   new Ajax.Request(url, {
	method:	'get',
	  parameters: 'newsId='+newsId  +'&langId='+langId +'&date='+date,
	  onSuccess: function(t) {
	     $('date_'+newsId).innerHTML = t.responseText;
	     
	     $('date_'+newsId).setAttribute("date", date);
	  }
      
   } ); 
}
function saveEventDate(eventId, dateType, date)
{
   var url = "actions/saveEventDate.php";
   new Ajax.Request(url, {
	method:	'get',
	  parameters: 'eventId='+eventId  +'&dateType='+dateType +'&date='+date,
	  onSuccess: function(t) {
	     $('date_'+eventId+'_'+dateType).innerHTML = date;
	     
	     $('date_'+eventId+'_'+dateType).setAttribute("date", date);
	     
	     $('input_'+eventId+'_'+dateType).value = date;
	  }
      
   } ); 
}


var doingEvents = false;
// This function gets called when the end-user clicks on some date.
function news_selectDate(cal, date)
{
   doingEvents = false;
   saveNewsDate( cal.sel.getAttribute("newsId"), langId, date);
}


function event_selectDate(cal, date) 
{
   doingEvents = true;
   //saveEventDate( cal.sel.getAttribute("eventId"), cal.sel.getAttribute("dateType"), date);
   var eventId = cal.sel.getAttribute("eventId");
   var dateType = cal.sel.getAttribute("dateType");
   $('date_' +eventId+'_'+dateType).innerHTML = date;
   $('date_' +eventId+'_'+dateType).setAttribute("date", date);
   $('input_'+eventId+'_'+dateType).value = date;
   
   eventEditableChanged(cal.sel);
   
}


function closeHandler(cal) {
   cal.hide();
   //  cal.destroy();
   // 
   _dynarch_popupCalendar = null;
}


function showCalendar(el, onclick) {
   if (_dynarch_popupCalendar != null)
     {
	// we already have some calendar created
	_dynarch_popupCalendar.hide();                 // so we hide it first.
     } else {
	// first-time call, create the calendar.
	var cal = new Calendar(1, null, onclick, closeHandler);
	// uncomment the following line to hide the week numbers
	// cal.weekNumbers = false;
	cal.showsTime = true;
	cal.time24 = true;
	
	
	cal.showsOtherMonths = true;
	
	_dynarch_popupCalendar  = cal;                  // remember it in the global var
	cal.setRange(1900, 2070);        // min/max year allowed.
	cal.create();
     }	
   
   _dynarch_popupCalendar.setDateFormat( "%Y-%m-%d" );    // set the specified date format
   _dynarch_popupCalendar.parseDate( el.getAttribute("date") );      // try to parse the text in field
   _dynarch_popupCalendar.sel = el;
   // inform it what input field we use
   // 	     
   // the reference element that we pass to showAtElement is the button that
   // triggers the calendar.  In this example we align the calendar bottom-right
   // to the button.
   _dynarch_popupCalendar.showAtElement(el, "Br");// show the calendar
   
   return false;
}



