﻿/*
Created At : 11:37 07.05.2008
Copyright (c) Adasoft
http://www.adasoft.com.tr
*/
function  DateTime2(obj)
{
 this.DomObject = document.getElementById(obj.id);
this.Format = obj.Format; 
this.UId = obj.UId;
this.TimeOut = obj.TimeOut;
this.Aylar = ['','Ocak','Şubat','Mart','Nisan','Mayıs','Haziran','Temmuz','Ağustos','Eylül','Ekim','Kasım','Aralık'];
this.Gunler = ['Pazar','Pazartesi','Salı','Çarşamba','Perşembe','Cuma','Cumartesi'];
this.GunlerK = ['Pz.','Pts.','Sa.','Çar.','Per.','Cu','Cts.'];
window[this.UId]=this;
}

DateTime2.prototype.Init = function ()
{
if(this.DomObject)
      this.DomObject.innerHTML=this.UId+' hazırlanıyor..';
    else
      throw Exception('Dom Nesnesi belirsiz..')  ;      
this.Tick();
}
DateTime2.prototype.Tick = function ()
{
window.setTimeout('window[\''+this.UId+'\'].Refresh();'+'',this.TimeOut);
}

DateTime2.prototype.Refresh = function ()
{
//
    var dt = new Date();  
    var yil = dt.getFullYear();
    var ay = (dt.getMonth()+1);
    var gun = dt.getDate();
    var gunIndex = dt.getDay();
    var saat = dt.getHours();
    var dakika = dt.getMinutes();
    var saniye = dt.getSeconds();
    
    var str = new String(this.Format);
    str = str.replace('|gg|',this.getInt(gun ));
    str = str.replace('|GG|',this.Gunler[gunIndex]);
    str = str.replace('|G|',this.GunlerK[gunIndex ]);
    str = str.replace('|a|',this.getInt(ay));
    str = str.replace('|A|',this.Aylar[ay]);
    str = str.replace('|yyyy|',yil);
    str = str.replace('|yy|',(yil+'').substring (2,4));
    str = str.replace('|SAAT|',this.getInt(saat)+':'+this.getInt(dakika )+':'+this.getInt(saniye));    
    saat = saat % 12;
    str = str.replace('|saat|',this.getInt(saat)+':'+this.getInt(dakika )+':'+this.getInt(saniye));    
     this.DomObject.innerHTML=str;
    //
    this.Tick();
}

DateTime2.prototype.getInt= function (str)
{
  var i = parseInt(str);
 if (i>9)  
   return str;
else
  return '0'+str;    
}

