function calcs()
{
	var self = this;

	this.GetYearI = function(strdate)
	{
		return parseInt(strdate.substring(0,4),10);
	}
	this.GetMonthI = function(strdate)
	{
	 	return parseInt(strdate.substring(5,7),10);
	}
	this.GetDayI = function(strdate)
	{
		return parseInt(strdate.substring(8,10),10);
	}
	this.GetHourI = function(strdate)
	{
   	var hour = strdate.substring(11,13);
	   if(hour != '') return parseInt(hour,10);
	   else return 0;
	}
	this.GetMinutesI = function(strdate)
	{
	   var minutes = strdate.substring(14,16);
	   if(minutes != '') return parseInt(minutes,10);
	   else return 0;
	}
	this.GetSecondsI = function(strdate)
	{
   	var seconds = strdate.substring(17);
	   if(seconds != '') return parseInt(seconds,10);
	   else return 0;
	}
	this.GetDayString = function(strdate)
	{
		return strdate.substring(8,10);
	}
	this.MakeDateDigit = function(num)
	{
   	var num1 = parseInt(num,10);
	   if(num1 < 10 && num1 >= 0) return '0'+String(num1);
	   return String(num1);
	}
	this.CalcDauerMilsecs = function(milsecs)
	{
   	var dauer = parseInt((milsecs / 1000 / 60),10);
	   if(dauer > 0)
	   {
      	if(dauer >= 60)
	      {
         	var std = parseInt((dauer / 60),10);
	         var min = parseInt((dauer - (std * 60)),10);
	         dauer = self.MakeDateDigit(std)+':'+self.MakeDateDigit(min);
	      }
	      else dauer = '00:'+self.MakeDateDigit(dauer);
	   }
	   else dauer = '00:00';

	   return dauer;
	}
	this.CalcDauer = function(start_date, end_date)
	{
   	var dauer = end_date.getTime() - start_date.getTime();
	   return self.CalcDauerMilsecs(dauer);
	}
	this.MoveTo = function(div_node, top, left)
	{
   	div_node.style.position = 'absolute';
	   div_node.style.top = top+'px';
	   div_node.style.left = left+'px';
	}
	this.FormatBR = function(text)
	{
		return text.replace(/\n/g,"<br />");
	}
	this.GetDateFromStr = function(date)
	{
		return new Date(this.GetYearI(date),this.GetMonthI(date)-1,this.GetDayI(date),this.GetHourI(date),this.GetMinutesI(date),this.GetSecondsI(date));
	}
	this.GetStrFromDate = function(date)
	{
		return date.getFullYear()+'-'+this.MakeDateDigit(String(date.getMonth()+1))+'-'+this.MakeDateDigit(date.getDate())+' '+this.MakeDateDigit(date.getHours())+':'+this.MakeDateDigit(date.getMinutes())+':00';
	}
	this.GetTimeFromDate = function(date)
	{
		return this.MakeDateDigit(date.getHours())+':'+this.MakeDateDigit(date.getMinutes());
	}
	this.GetOnlyStrDate = function(strdate)
	{
		return strdate.substring(0,10);
	}
	this.GetMonthName = function(month_id)
	{
   	switch(month_id)
	   {
      	default:
	      case 1: return "Januar";    case 2: return "Februar";
	      case 3: return "März";      case 4: return "April";
	      case 5: return "Mai";       case 6: return "Juni";
	      case 7: return "Juli";      case 8: return "August";
	      case 9: return "September"; case 10:return "Oktober";
	      case 11:return "November";  case 12:return "Dezember";
	   }
	}
	this.GetDayName = function(day_id)
	{
   	switch(day_id)
	   {
      	default:
	      case 0: return "kein gültiger Tag";
	      case 1: return "Montag";    case 2: return "Dienstag";
	      case 3: return "Mittwoch";  case 4: return "Donnerstag";
	      case 5: return "Freitag";   case 6: return "Samstag";
	      case 7: return "Sonntag";
	   }
	}
	this.GetDayDesc = function(date)
	{
		return this.MakeDateDigit(date.getDate())+'.'+this.MakeDateDigit(date.getMonth()+1)+'.'+date.getFullYear();
	}
	this.DatesSameDay = function(date1, date2)
	{
   	if(date1.getFullYear() == date2.getFullYear() && date1.getMonth() == date2.getMonth() && date1.getDate() == date2.getDate())
	   	return true;

	   return false;
	}
	this.TimeGreater = function(date1, date2)
	{
   	var hrs1 = date1.getHours();
	   var min1 = date1.getMinutes();

	   var hrs2 = date2.getHours();
	   var min2 = date2.getMinutes();

	   if(hrs1 > hrs2)
	   	return true;
	   else if(hrs1 < hrs2)
	   	return false;
	   else
	   {
      	if(min1 > min2)
	      	return true;
	   }
	   return false;
	}
	this.DateGreater = function(date1, date2)
	{  //if date1 greater date2 == true
   	   var year1 = date1.getFullYear();
	   var year2 = date2.getFullYear();

	   var month1 = date1.getMonth();
	   var month2 = date2.getMonth();

	   var day1 = date1.getDate();
	   var day2 = date2.getDate();

	   if(year1 > year2)
	   	return true;
	   else if(year1 < year2)
	   	return false;
	   else
	   {
      	if(month1 > month2)
	      	return true;
	      else if(month1 < month2)
	      	return false;
	      else
	      {
         	if(day1 > day2)
	         	return true;
	      }
	   }
	   return false;
	}
	this.LastDayOfMonth = function(date)
	{
   	   var year = date.getFullYear();
	   var month = date.getMonth()+1;
	   var last = 31;
	   if(month == 4 || month == 6 || month == 9 || month == 11)
	   	--last;
	   if(month == 2)
	   {
      	last = last - 3;
	      if(year % 4 == 0) 	last++;
	      if(year % 100 == 0) 	last--;
	      if(year % 400 == 0) 	last++;
	   }
	   return last;
	}
	this.CopyDate = function(date)
	{
   	var tmpDate = new Date(date.getFullYear(),date.getMonth(),date.getDate(),date.getHours(),date.getMinutes(),date.getSeconds());
	   return tmpDate;
	}
}
var calc = new calcs();

function oTime(mins)
{
   var minutes = mins;

   this.GetTimeStr = function()
   {
      var dauer = minutes * 1000 * 60;
      if(dauer >= 0)
         return calc.CalcDauerMilsecs(dauer);
      else
         return calc.CalcDauerMilsecs(-dauer);
   }
	this.AddMins = function(mins)
	{
		minutes += mins;
	}
   this.IsPos = function()
   {
		if(minutes >= 0)
      	return true;
      return false;
   }
   this.GetMinutes = function()
   {
   	return minutes;
   }
}

function calc_time(selnode)
{
	var self = this;

	var system_date = new Date();
	var time_node = selnode;
	var time_method = 0;

	var reload_counter = 1;
	var time_reload = 0;
	var reloadCallback = 0;

	this.GetSystemDate = function()
	{
		return calc.CopyDate(system_date);
	}
	this.StartTime = function(systemDate)
	{
   	   self.StopTime();
	   system_date = calc.CopyDate(systemDate);
	   time_method = window.setInterval(self.CalcTime, 1000);
	}
	this.StopTime = function()
	{
   	   if(time_method)
	   	window.clearInterval(time_method);
	   time_method = 0;
	}
	this.CalcTime = function()
	{
   	   var abs_time = system_date.getTime();
	   abs_time += 1000;
	   system_date.setTime(abs_time);
	   var sec = system_date.getSeconds();

	   if(sec == 1)
	   {
      	  var jahr = system_date.getFullYear();
	      var monat = system_date.getMonth()+1;
	      var tag = system_date.getDate();
	      var std = system_date.getHours();
	      var min = system_date.getMinutes();
	      var day_id = system_date.getDay();
	      if(day_id == 0) day_id = 7;
	      var str_date = calc.GetDayName(day_id)+', der '+calc.MakeDateDigit(tag)+'.'+calc.GetMonthName(monat)+'.'+String(jahr);
	      var str_time = calc.MakeDateDigit(std)+':'+calc.MakeDateDigit(min)/*+':'+calc.MakeDateDigit(sec)*/;
	      Element.update(time_node,str_date+' '+str_time);

	      if(time_reload)
	      {
	         if(time_reload <= reload_counter)
	         {
	            reload_counter = 1;
	            reloadCallback();
	         }
	         else reload_counter++;
	      }
	   }
	}
	this.SetReload = function(reload, funcCallback)
	{
       if(typeof funcCallback != 'function') return;
       reload_counter = 1;
	   time_reload = reload;
	   reloadCallback = funcCallback;
	}
}
