$(function() {
   $('input:text, input:password').addClass("MetinKutusu");
   $('.TarihKutusu').datepicker();
   $('.RakamKutusu').numeric();
	
   $('input:button, input:submit').button();
	
	$('.UyeFormlar input:file').css('width','133px');
	$('a.lightBox').lightBox();
   
   $('#BtnBilgiGuncelle').click(function(){
      parent.location = 'UyeBilgiGuncelle';
   });

   $('#BtnUyeCikis').click(function(){
      if (confirm('Oturumu sonlandırmak istediğinizden emin misiniz?')) {
         parent.location = 'Cikis';
      } else {
         return;
      }
   });

   $('#UyeGirisFormu input:text').keyup(function(){
      $('#UyeGirisFormu p.Mesaj').html('');
   });   

   $('legend a').click(function(){
      if ($('#FiltrelemeAlaniDiv').css('display')=='block'){
         $('#FiltrelemeAlaniDiv').css('display', 'none');
         $('legend a').html('Göster &laquo;');
      }
      else{
         $('#FiltrelemeAlaniDiv').css('display', 'block');
         $('legend a').html('Gizle &laquo;');
      }
   });

   $("#TumunuSec").click(function() { 
      var SecimDurumu = this.checked; 
      if (SecimDurumu==false){
         $('#ButonSecilenleriSil').css('display','none');
      }
      else{
         $('#ButonSecilenleriSil').css('display','inline');
      }
	
      $(".CheckList").each(function()  { 
         this.checked = SecimDurumu;
      }); 
   });

   $("#SonucListesi").sortable({
      placeholder: 'ui-state-highlight'
   });
	
   $("#SonucListesi").disableSelection();
	
	
   $('#UYELIK_KOSUL_KONTROL').click(function() { 
      var SecimDurumu = this.checked;
      if (SecimDurumu==false){
         $('#BtnUyeKaydetDogrula1').attr('disabled', 'disabled');
      }
      else{
         $('#BtnUyeKaydetDogrula1').removeAttr('disabled');
      }
   });
	
   $('#UYELIK_KOSUL_LINK').click(function() {
      $( "#UyelikKosullariDiv" ).dialog({
         modal: true,
         buttons: {
            Tamam: function() {
               $( this ).dialog( "close" );
            }
         }
      });
   });


});

function OturumVar(){
   $("#OturumSuresi").html(SifirDoldur(DAKIKA,2) + ":" + SifirDoldur(SANIYE,2));
   setInterval(OturumSuresiniGoster, 1000);
}

function OturumSuresiniGoster(){
   if(SANIYE > 0) {
      SANIYE = SANIYE - 1;
   }
   else{
      SANIYE = 59;
      if(DAKIKA > 0) {
         DAKIKA = DAKIKA - 1;
      }
      else{
         parent.location = 'Cikis';
      }
   }
   $("#OturumSuresi").html(SifirDoldur(DAKIKA,2) + ":" + SifirDoldur(SANIYE,2));
}

function SifirDoldur(Sayi, Uzunluk) {
   var Sonuc = Sayi.toString();
   var Ifade = Uzunluk - Sonuc.length;
   while(Ifade > 0) {
      Sonuc = '0' + Sonuc;
      Ifade--;
   }
   return Sonuc;
}

function SiralamayiKaydet(tablo,anahtar){
   var Nolar='';
   $('.CheckList').each(function(){ 
      Nolar += this.value+",";
   });
   $.ajax({
      type:'post',
      url:'SiralamayiKaydet',
      data:'Tablo='+tablo+'&Anahtar='+anahtar+'&No='+Nolar,
      success:function(ListelemeAlani){
         parent.location=KelimelerinBasHarfleriniBuyukHarfYap(anahtar)+"Listele";
      }
   })
	
}

function SecilenleriSil(tablo,anahtar){
   if (confirm('Seçilenleri silmek istediğinizden emin misiniz?')) {
      var Nolar='';
      $('.CheckList:checked').each(function(){ 
         Nolar += this.value+",";
      });
      $.ajax({
         type:'post',
         url:'SecilenleriSil',
         data:'Tablo='+tablo+'&Anahtar='+anahtar+'&No='+Nolar,
         success:function(ajaxSonuc){
				parent.location=KelimelerinBasHarfleriniBuyukHarfYap(anahtar)+"Listele";
         }
      })
   } else {
      return;
   }
}

function SEOYap(Ifade){
   Ifade = Ifade.replace(/\s+/g, '-');
   Ifade = Ifade.replace("Ç", "c");
   Ifade = Ifade.replace("Ğ", "g");
   Ifade = Ifade.replace("I", "i");
   Ifade = Ifade.replace("İ", "i");
   Ifade = Ifade.replace("Ö", "o");
   Ifade = Ifade.replace("Ş", "s");
   Ifade = Ifade.replace("Ü", "u");
   Ifade = Ifade.replace("ç", "c");
   Ifade = Ifade.replace("ğ", "g");
   Ifade = Ifade.replace("ı", "i");
   Ifade = Ifade.replace("i", "i");
   Ifade = Ifade.replace("ö", "o");
   Ifade = Ifade.replace("ş", "s");
   Ifade = Ifade.replace("ü", "u");
   Ifade = Ifade.toLowerCase()
   return Ifade;
}

function TumunuBuyukHarfYap(Ifade) {
   Ifade = Ifade.replace("Ç", "Ç");
   Ifade = Ifade.replace("Ğ", "Ğ");
   Ifade = Ifade.replace("I", "I");
   Ifade = Ifade.replace("İ", "İ");
   Ifade = Ifade.replace("Ö", "Ö");
   Ifade = Ifade.replace("Ş", "Ş");
   Ifade = Ifade.replace("Ü", "Ü");
   Ifade = Ifade.replace("ç", "Ç");
   Ifade = Ifade.replace("ğ", "Ğ");
   Ifade = Ifade.replace("ı", "I");
   Ifade = Ifade.replace("i", "İ");
   Ifade = Ifade.replace("ö", "Ö");
   Ifade = Ifade.replace("ş", "Ş");
   Ifade = Ifade.replace("ü", "Ü");
   Ifade = Ifade.toUpperCase();
   return Ifade;
}

function KelimelerinBasHarfleriniBuyukHarfYap(Ifade) {
   return (Ifade + '').replace(/^([a-z])|\s+([a-z])/g, function ($1) {
      return TumunuBuyukHarfYap($1);
   });
}


function removeByElement(arrayName,arrayElement){
	for(var i=0; i<arrayName.length;i++){
		if(arrayName[i]==arrayElement){
			arrayName.splice(i,1);
		}
	}
}
