// JavaScript Document
var Y = document.documentElement.clientHeight;
var X = document.documentElement.clientWidth;

var aylar = new Array ('Ocak', '&#350;ubat', 'Mart', 'Nisan', 'May&#305;s', 'Haziran', 'Temmuz', 'A&#287;ustos', 'Eyl&uuml;l', 'Ekim', 'Kas&#305;m', 'Aral&#305;k');
var gunler = new Array ('Pazartesi', 'Sali', 'Çarşamba', 'Perşembe', 'Cuma', 'Cumartesi', 'Pazar');

function FixDate (DateTime, Format) 
{
	/*
		Mysql'in DateTime formatindaki (YYYY-AA-GG SA:DK:SN) Tarihi, 
		Türkiyede kullanilan tarih formatina çevirmek için bir fonksiyon.
	*/
	DateTime = DateTime.split(' ');
	Temp = DateTime[0].split('-');
	Year = Temp [0]; Month = Temp [1]; Day = Temp [2];
	Temp = DateTime[1].split(':');
	Hour = Temp [0]; Minute = Temp [1]; Second = Temp [2];
	
	if (Format == undefined) {Format = 1;}
	
	if (Format == 1) { 
		return Day + " " + aylar[Month*1] + " " + Year + " " + Hour + ":" + Minute;
	} else if (Format == 2) { 
		return Day + " " + aylar[Month*1] + " " + Year;
	}
}
function Simdi(Format)
{
	/*
		Şuanki tarihi;
		Format 1, Mysql'in DateTime formatindaki (YYYY-AA-GG SA:DK:SN) şekle,
		Format 2 ve 3, Türkiyede kullanilan tarih formatina
		çevirmek için bir fonksiyon
	*/
	if (Format == undefined) {Format = 2;}
	var today = new Date();
	DateTime  = today.getFullYear() + '-' + today.getMonth() + '-' + today.getDate() + ' ' + today.getHours() + ':' + today.getMinutes() + ':' + today.getSeconds();
	if (Format == 1)
		return DateTime;
	else if (Format == 2)
		return FixDate(DateTime,Format = 1);
	else if (Format == 3)
		return FixDate(DateTime,Format = 2);
	else if (Format == 4)
		return today.getDate() + ' ' + aylar[today.getMonth()] + ' ' + today.getFullYear() + '<br />' + gunler[today.getDay()] + '<br />' + today.getHours() + ':' + today.getMinutes() + ':' + today.getSeconds();

}

function ZamanFarki(Basla,Bitir,Tur)
{
	/*
		Başlangiç ve Bitiş Tarihleri arasindaki 
		zaman farkini bulan bir fonksiyon.
		
		Eger Tur;
			"sn" ise Saniye olarak
			"dk" ise Dakika olarak
			"gn" ise Gün olarak
			"yl" ise Yil olarak
			"tum" ise, zaman farkini " XX yil, XX gün, XX saat, XX dakika, XX saniye " olarak
		deger üretir.
		
		başlangiç ve bitiş degerleri unix zaman damgasi olarak verilecegi gibi,
		mysql DateTime Zaman formati olarakta verilebilir.
	*/
	if (Basla.indexOf("-")>-1 || Basla.indexOf(":")>-1)
	{
		DateTime = Basla.split(' ');
		Temp = DateTime[0].split('-');
		Year = Temp [0]; Month = Temp [1]; Day = Temp [2];
		Temp = DateTime[1].split(':');
		Hour = Temp [0]; Minute = Temp [1]; Second = Temp [2];
		
		var gecmis_unix = Date.UTC(Year,Month,Day,Hour,Minute,Second/1000);
	}
	else
	{
		var gecmis_unix = Basla; 
	}
	if (Bitir.indexOf("-")>-1 || Bitir.indexOf(":")>-1)
	{
		DateTime = Bitir.split(' ');
		Temp = DateTime[0].split('-');
		Year = Temp [0]; Month = Temp [1]; Day = Temp [2];
		Temp = DateTime[1].split(':');
		Hour = Temp [0]; Minute = Temp [1]; Second = Temp [2];
	
		var simdiki_unix = Date.UTC(Year,Month-1,Day,Hour-3,Minute,Second)/1000;
	}
	else
	{
		var simdiki_unix = Bitir; 
	}

	var today = new Date();
	Year = today.getFullYear();
	Month = today.getMonth();
	Day = today.getDate();
	now = Date.UTC(Year,Month,Day, today.getHours()-3,today.getMinutes(),today.getSeconds())/1000;

	// alert(simdiki_unix+ ' \n\r' + gecmis_unix + ' \n\r' + now);

	var fark_unix = simdiki_unix - gecmis_unix; // Farki Bul
	Gecen_Sure = '';
	if (Tur == "sn") Gecen_Sure = floor(fark_unix); // SN Dönüştür...
	else if (Tur == "dk") Gecen_Sure = floor(fark_unix / 60); // DK Dönüştür...
	else if (Tur == "sa") Gecen_Sure = floor(fark_unix / (60 * 60)); // SAAT Dönüştür...
	else if (Tur == "gn") Gecen_Sure = floor(fark_unix / (60 * 60 * 24)); // GÜN Dönüştür...
	else if (Tur == "yl") Gecen_Sure = floor(fark_unix / (60 * 60 * 24 * 365)); // YIL Dönüştür...
	else if (Tur == "tum") { // Tüm dönüşümleri yaparak yaz.
		YIL = (fark_unix / (60 * 60 * 24 * 365)).floor(); // Yila Dönüştür...
		if (YIL > 0) {
			fark_unix -= YIL * (60 * 60 * 24 * 365);
			Gecen_Sure += YIL + ' yil, ';
		}
		
		GUN  = (fark_unix / (60 * 60 * 24)).floor(); // Güne Dönüştür...
		if (GUN > 0) {
			fark_unix -= GUN * (60 * 60 * 24);
			Gecen_Sure += GUN + ' gün, ';
		}
	
		SAAT = (fark_unix / (60 * 60)).floor(); // Saate Dönüştür...
		if (SAAT > 0) {
			fark_unix -= SAAT * (60 * 60);
			Gecen_Sure += SAAT + ' saat, ';
		}
		
		DAK  = (fark_unix / 60).floor(); // Dakikaya Dönüştür...
		if (DAK > 0) {
			fark_unix -= DAK * (60);
			Gecen_Sure += DAK + ' dakika, ';
		}

		SAN  = (fark_unix).floor(); // Saniyeye Dönüştür...
		if (SAN >= 0) {
			Gecen_Sure += SAN + ' saniye';
		} else {
			Gecen_Sure += ' 0 saniye';
		}
		
		if (YIL+GUN+SAAT+DAK+SAN <= 0) window.location.reload();
	}
	return Gecen_Sure;
}
function ac(element){ // ------	------	------	------	------	ELEMENTI AÇMA
	$(element).style.display = 'block';
}
function kapa(element){ // ------	------	------	------	------	ELEMENTI KAPAMA
	$(element).style.display = 'none';
}
function ackapa(element){ // ------	------	------	------	------	ELEMENTI AÇMA
	if ($(element).style.display == 'none' ) $(element).style.display = 'block';
	else if ($(element).style.display == 'block' ) $(element).style.display = 'none';
}
function Highlight(element,basla,bitir){ // ----	------	------	------	Highligh EFEKTI
	if (!(basla)) basla = "#FFFFCC";
	if (!(bitir)) bitir = "none";

	element.style.cursor='pointer'; 
	element.style.background = basla;
	element.onmouseout = function(){element.style.background = bitir;};
}
function PopSayfaAc(url,name,w,h) 
{ 
//	alert(url+" "+name+" "+w+" "+h);
   newwindow=window.open(url,name,'height='+h+',width='+w+',toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0'); 
   if (window.focus) {newwindow.focus()} 
} 
function addLoadEvent(func)
{
  var oldonload = window.onload;
  if (typeof window.onload != 'function')
  {
    window.onload = func;
  }
  else
  {
	window.onload = function()
	{
      if (oldonload)
	  {
        oldonload();
      }
      func();
    }
  }
}
