﻿$.ajaxSetup({cache:false});
function scrollYasakla(event) {
    if (event.which == 37 || event.which == 39) {
        event.preventDefault();
        return false;
    }
    return true;
}
var sehirler=new Array("A","ADANA","ADIYAMAN","AFYON","AĞRI","AMASYA","ANKARA","ANTALYA","ARTVİN","AYDIN","BALIKESİR","BİLECİK","BİNGÖL","BİTLİS","BOLU","BURDUR","BURSA","ÇANAKKALE","ÇANKIRI","ÇORUM","DENİZLİ","DİYARBAKIR","EDİRNE","ELAZIĞ","ERZİNCAN","ERZURUM","ESKİŞEHİR","GAZİANTEP","GİRESUN","GÜMÜŞHANE","HAKKARİ","HATAY","ISPARTA","MERSİN","İSTANBUL","İZMİR","KARS","KASTAMONU","KAYSERİ","KIRKLARELİ","KIRŞEHİR","KOCAELİ","KONYA","KÜTAHYA","MALATYA","MANİSA","KAHRAMANMARAŞ","MARDİN","MUĞLA","MUŞ","NEVŞEHİR","NİĞDE","ORDU","RİZE","SAKARYA","SAMSUN","SİİRT","SİNOP","SİVAS","TEKİRDAĞ","TOKAT","TRABZON","TUNCELİ","ŞANLIURFA","UŞAK","VAN","YOZGAT","ZONGULDAK","AKSARAY","BAYBURT","KARAMAN","KIRIKKALE","BATMAN","ŞIRNAK","BARTIN","ARDAHAN","IĞDIR","YALOVA","KARABÜK","KİLİS","OSMANİYE","DÜZCE");
function gunDuzenle(duzelecek,ay,yil) {
    var deger=duzelecek.val();
    duzelecek.html('');
    for (var i=1;i<33-new Date(yil,ay-1,32).getDate();i++) duzelecek.append('<option value="'+i+'">'+i+'</option>');
    duzelecek.val(deger);
}
noBubble=false;
$.fn.resimDuzenle = function (boyutX, boyutY) {
    if (boyutX==undefined) boyutX=100;
    if (boyutY==undefined) boyutY=boyutX;
    $(this).each(function() {
        var gen=$(this).width('').height('').css('margin-left','').css('margin-top','').width();
        var yuk = $(this).height();
        if (gen / boyutX > yuk / boyutY) $(this).height(boyutX * yuk / gen).width(boyutX).css('margin-top', (boyutY - boyutX * yuk / gen) / 2 + 'px').css('margin-left', '0px'); else $(this).width(boyutY * gen / yuk).height(boyutY).css('margin-left', (boyutX - boyutY * gen / yuk) / 2 + 'px').css('margin-top', '0px');
    });
    return $(this);
}
$.fn.resimDuzenleSabit = function (boyutX, boyutY) {
    if (boyutX==undefined) {
        var boyutX=100;
    }
    if (boyutY==undefined) {
        var boyutY=boyutX;
    }
    $(this).each(function() {
        var gen=$(this).width();
        var yuk = $(this).height();
        if (gen / boyutX > yuk / boyutY) $(this).height(boyutX * yuk / gen).width(boyutX); else $(this).width(boyutY * gen / yuk).height(boyutY);
    });
    return $(this);
}
function karartmaliPencereGoster(genislik,yukseklik,url,params) {
	$('.mesaj').css('opacity',0).show().animate({opacity:.5},300,function() {
		pencereGoster(genislik,yukseklik,url,params);
	});
}
function _resimDonusum(resim) {
    if (resim.width() / 800 > resim.height() / 600) {
        var yeniGenislik = 800;
        var yeniYukseklik = resim.height() * 800 / resim.width();
    } else {
        var yeniYukseklik = 600;
        var yeniGenislik = resim.width() * 600 / resim.height();
    }
    return { width: yeniGenislik + 'px', height: yeniYukseklik + 'px', left: $(window).width() / 2 - yeniGenislik / 2 + 'px', top: $(window).height() / 2 - yeniYukseklik/2 + 'px' };
}
$.fn.resmiGoster=function(callback) {
    $(this).each(function() {
        var pozisyon=pos(this);
        var imaj=$('<img style="position:fixed;z-index:3000;" />').css({'left':pozisyon.x+'px','top':pozisyon.y+'px',width:$(this).width()+'px',height:$(this).height()+'px'}).appendTo($('body')).attr('src',$(this).attr('src')).click(function(){
            $(this).remove();
            $('.mesaj').hide();
        });
		$('.mesaj').show().animate({opacity:.7},300);
		imaj.animate(_resimDonusum(imaj),300);
    });
    return $(this);
}
$.fn.resmiGoster2=function(callback) {
    $(this).filter(':first').each(function() {
		var buyuyen=$(this);
        var pozisyon=pos(this);
		var dugme = $('<input type="button" value="Sil" style="position:absolute;cursor:pointer;z-index:5000;display:none;" />').click(function(){
			callback();
			imaj.click();
		}).hover(function() {
			dugme.show();
		},function() {
			dugme.hide();
		});
        var imaj=$('<img style="position:fixed;z-index:3000;" />').css({'left':pozisyon.x+'px','top':pozisyon.y+'px',width:$(this).width()+'px',height:$(this).height()+'px'}).appendTo($('body')).attr('src',$(this).attr('src')).click(function(){
            $(this).remove();
			dugme.remove();
            $('.mesaj').hide();
        }).hover(function() {
			dugme.show();
		},function() {
			dugme.hide();
		});
		
		$('.mesaj').show().animate({opacity:.7},300);
		imaj.animate(_resimDonusum(imaj),300,function() {
			dugme.css({left:parseInt(imaj.css('left'))+imaj.width()-50+'px',top:parseInt(imaj.css('top'))+imaj.height()-30+'px'}).appendTo($('body'));
		});
    });
    return $(this);
}
$.extend($.expr[':'], {
	matchText: function(a,b,m){
	    return (a.textContent||a.innerText||jQuery(a).text()||'').replace(/^\s+|\s+$/,'').toLowerCase() == (m[3]).replace(/^\s+|\s+$/,'').toLowerCase();
	}
});
var suankiEditor='';
function selectYasakla() {
    $('body').css('-moz-user-select','none').bind('selectstart',function() {
        return false;
    });
}
function selectAktive() {
    $('body').css('-moz-user-select','auto').unbind('selectstart');
}
function trKaydirma(event,a,yukari,asagi) {
    var _eleman=$(a);
    var eskiYer=event.clientY;
    var yukariFonk=yukari;
    var asagiFonk=asagi;
    var refNo=_eleman.attr('name');
    var tabloIsmi=_eleman.parents('table').attr('id');
    selectYasakla();
    $(document).mouseup(function() {
        $(document).unbind('mousemove').unbind('mouseup');
        selectAktive();
    }).mousemove(function(event) {
        while (event.clientY-eskiYer>20) {
	        var sonraki=_eleman.next();
	        if (sonraki.next().length>0) {
		        eskiYer+=20;
		        asagiFonk();
		        sonraki.after(_eleman);
	        } else break;
        }
        while (eskiYer-event.clientY>20) {
	        var onceki=_eleman.prev();
	        if (onceki.prev().length>0) {
		        eskiYer-=20;
		        yukariFonk();
		        onceki.before(_eleman);
	        } else break;
	    }
	});
}
function pos(_eleman) {
    var sonuc=new Object();
    sonuc.x=0;
    sonuc.y=0;
    while (_eleman!=null) {
        sonuc.x+=_eleman.offsetLeft;
        sonuc.y+=_eleman.offsetTop;
        _eleman=_eleman.offsetParent;
    }
    return sonuc;
}
function sec(_eleman) {
    _eleman.parents('.table').find('.secili').removeClass('secili').each(function(){
        var textbox=$(this).find(':text');
        if (textbox.length>0) {
            if (textbox.val().length==0) {
				textbox.parent().get()[0].silCallback();
				$(this).remove();
				siraDuzenle();
			} else {
				textbox.parent().get()[0].kaydetCallback(textbox.val());
            	textbox.parent().html(textbox.val());
			}
        }
    });
    _eleman.parent().addClass('secili');
}
function inputYap(_eleman,silCallback,kaydetCallback) {
    _eleman.get()[0].silCallback=silCallback;
	_eleman.get()[0].kaydetCallback=kaydetCallback;
    _eleman.html('<input type="text" style="border:none;width:100%;height=100%;" value="'+_eleman.text().replace(/^\s+|\s+$/g,"")+'" />').find(':text').keydown(function(event) {
        if (event.keyCode==27 || event.keyCode==13) {
            sec($(this).parent());
        }
    }).focus();
}
function randomString(sayi) {
    degerler="1234567890qwertyuıopğüasdfghjklşizxcvbnmöçQWERTYUIOPĞÜASDFGHJKLŞİZXCVBNMÖÇ";
    sonuc="";
    for (var i=0;i<sayi;i++) sonuc+=degerler.substr(Math.floor(Math.random()*degerler.length),1);
    return sonuc;
}
$.fn.ortalaOffset=function() {
    _eleman=$(this).get()[0];
    width=_eleman.offsetWidth;
    if (_eleman.offsetWidth<300) {
        $(_eleman).width(300);
        width=300;
    }
    return $(_eleman).css({'margin-left':width/-2,'margin-top':_eleman.offsetHeight/-2});
}
$.fn.kapat=function(tamamenKapat,callback) {
    if (callback!=undefined) callback();
    $(this).parents('.mesajIc').animate({opacity:0},300,function() {
        if ($(this).attr('id')=='alert') $(this).hide(); else $(this).remove();
    });
    if (tamamenKapat) $('.mesaj').animate({opacity:0},300,function() {
        $(this).hide();
    });
}
function alertGoster(baslik,mesaj,tamamenKapat,callback) {
    $('.mesaj').css('opacity',0).show().animate({opacity:.7},300);
    $('#alert').find(':button:first').hide().end().find('h3').html(baslik).end().find('p:first').html(mesaj).end().find(':button:last').attr('value','Tamam').unbind('click').click(function() {
        $(this).kapat(tamamenKapat,callback);
    }).end().show().ortalaOffset().animate({opacity:1},300);
}
function confirmGoster(baslik,mesaj,tamamenKapat,callback) {
    $('.mesaj').css('opacity',0).show().animate({opacity:.7},300);
    $('#alert').find(':button:first').show().unbind('click').click(function(){
        $(this).kapat(tamamenKapat,callback);
    }).end().find('h3').html(baslik).end().find('p:first').html(mesaj).end().find(':button:last').attr('value','Hayır').unbind('click').click(function() {
        $(this).kapat(tamamenKapat);
    }).end().show().ortalaOffset().animate({opacity:1},300);
}
$.fn.yukle=function(url,params,_callback) {
    var callback=_callback;
    $(this).html('<div style="width:100%;height:100%;background-position:center center;background-repeat:no-repeat;position:absolute;z-index:300;background-image:url(\'img/loading.gif\');"></div>').load(url,params,function() {
        if (callback!=undefined) callback();
    });
    return $(this);
}
function siraDuzenle() {
    $('.sirali').each(function() {
        $(this).find(' tr:not(:first,:last) img').show().filter(':first,:last').hide();
    });
}
function pencereGoster(width,height,url,params,callback,karart) {
    var mesajSayisi=$('.mesajIc').length-1;
	if (karart!=undefined) $('.mesaj').css('opacity',0).show().animate({opacity:.7},300);
    var pencere=$('<div class="mesajIc" style="width:'+width+'px;height:'+height+'px"></div>').prependTo('#horizon').show().ortalaOffset().animate({opacity:1},300);
    pencere.css({'z-index':mesajSayisi+5000,'margin-left':parseInt(pencere.css('margin-left'))+mesajSayisi*15,'margin-top':parseInt(pencere.css('margin-top'))+mesajSayisi*15}).yukle(url,params,function() {
        $('<div style="cursor:move;width:100%;height:30px;position:absolute;top:0;left:0;"></div>').prependTo(pencere.append('<img class="clickEt" src="images/kapat.png" style="position:absolute;right:5px;top:2px;" onclick="$(this).kapat(true);" />')).mousedown(function(event) {
           var suruklenen=new Object();
            suruklenen.objesi=$(this).parent();
            suruklenen.x=event.clientX;
            suruklenen.y=event.clientY;
            selectYasakla();
            $(document).mousemove(function(event) {
                suruklenen.objesi.css({'margin-top':parseInt(suruklenen.objesi.css('margin-top'))+event.clientY-suruklenen.y+'px','margin-left':parseInt(suruklenen.objesi.css('margin-left'))+event.clientX-suruklenen.x+'px'});
                suruklenen.x=event.clientX;
                suruklenen.y=event.clientY;
                return false;
            }).mouseup(function() {
                $(document).unbind('mousemove').unbind('mouseup');
                selectAktive();
                suruklenen=null;
            });
        });
		if (callback!=undefined) callback();
    });
}
function editorluPencereGoster(editor,width,height,url,params) {
    $('<div class="mesajIc" style="width:'+width+'px;height:'+height+'px"></div>').prependTo('#horizon').show().ortalaOffset().animate({opacity:1},300).mousedown(function(event) {
        var suruklenen=new Object();
        suruklenen.objesi=$(this);
        suruklenen.x=event.clientX;
        suruklenen.y=event.clientY;
        selectYasakla();
        $(document).mousemove(function(event) {
            suruklenen.objesi.css({'margin-top':parseInt(suruklenen.objesi.css('margin-top'))+event.clientY-suruklenen.y+'px','margin-left':parseInt(suruklenen.objesi.css('margin-left'))+event.clientX-suruklenen.x+'px'});
            suruklenen.x=event.clientX;
            suruklenen.y=event.clientY;
            return false;
        }).mouseup(function() {
            $(document).unbind('mousemove').unbind('mouseup');
            selectAktive();
            suruklenen=null;
        });
    }).css('z-index',$('.mesajIc').length+50).yukle(url,params,function() {
        editorAc(editor);
    });
}
function uyari(mesaj,yer) {
    $('#'+yer+':not(.loggedOut)').parents('tr').before($('<tr class="uyari clickEt"><td colspan="3" align="center"><table cellpadding="0" cellspacing="0"><tr valign="center"><td align="left">'+mesaj+'</td></tr></table></td></tr>').click(function(){
        $(this).fadeOut(300,function() {
            $(this).remove();
        });
    }).show(300));
}
function editorAc(isim) {
	var editorler=isim.split(',');
	for (var i=0;i<editorler.length;i++) tinyMCE.execCommand('mceAddControl', true, editorler[i]);
}
function editorKapat(isim) {
	var editorler=isim.split(',');
	for (var i=0;i<editorler.length;i++) if (tinyMCE.editors[editorler[i]]!=undefined) tinyMCE.editors[editorler[i]].remove();
}
$.fn.editorluYukle=function(editor,adres,veri,callback) {
    editorKapat(editor);
    this.yukle(adres,veri,function() {
        if (callback!=undefined) callback();
        editorAc(editor);
    });
};
function formBilgisi(yer) {
    var osman=new Object();
    yer.find(':text,:password,:checkbox:checked,textarea,select').each(function() {
        osman[$(this).attr('id')]=$(this).val();
    });
    yer.find(':radio:checked').each(function() {
        osman[$(this).attr('name')]=$(this).val();
    });
    return osman;
}
function tabPageAyarla() {
    $('.tablar li').each(function(i){
        $(this).css('z-index',20-i);
    }).click(function() {
        var komut=$(this).attr('onload');
        $(this).parent().find('.current').removeClass('current').end().end().addClass('current');
        $('.tabSayfasi').filter(':not(:eq('+$(this).index()+'))').fadeOut(0).end().filter(':eq('+$(this).index()+')').fadeIn(300,function() {
            if (komut!=undefined) if (typeof(komut)=='string') eval(komut); else komut();
        });
    }).filter(':first').addClass('ilk').click();
}
$.fn.editorluYukle=function(editor,adres,veri,callback) {
    editorKapat(editor);
    this.yukle(adres,veri,function() {
        if (callback!=undefined) callback();
        editorAc(editor);
    });
};
function sayiKontrol(mesaj,yer,minimum,maximum) {
	var deger=$('#'+yer).val();
	if (deger.length==0) {
		deger=0;
		$('#'+yer).val(0);
		return true;
	} 
	deger=parseInt(deger);
	deger=isNaN(deger) || (minimum!=undefined && deger<minimum) || (maximum!=undefined && deger>maximum);
	if (deger) uyari(mesaj,yer);
	return !deger;
}
function tarihKontrol(isim,mesaj) {
    try {
		var obje=$('#'+isim);
        if (obje.val()=='') throw('dana'); else {
            var tarih=obje.val().replace(/[-:\/ ]/g,'.').split('.');
            if (tarih.length>3) throw("dana");
            var gun=parseInt(tarih[0]);
            var ay=parseInt(tarih[1]);
            var yil=parseInt(tarih[2]);
            if (yil<1000) yil+=2000;
            if (gun!=NaN && ay!=NaN && yil!=NaN) {
            var date=new Date();
                date.setDate(gun);
                date.setMonth(ay-1);
                date.setFullYear(yil);
                if (date.getDate()!=gun || date.getMonth()!=ay-1 || date.getFullYear()!=yil) throw("dat");
                obje.val((gun<10?"0":"")+gun+"."+(ay<10?"0":"")+ay+"."+yil);
            } else throw("hu");
        }
    } catch (e) {
        uyari(mesaj,isim);
        return false;
    }
    return true;
}
function formBilgisiArray(yer) {
	var osman=new Object();
    yer.find(':text,:password,:checkbox:checked,textarea,select').each(function() {
        osman[$(this).attr('id')]=$(this).val();
    });
    yer.find(':radio:checked').each(function() {
        osman[$(this).attr('name')]=$(this).val();
    });
    return osman;
}
function mailKontrol(mesaj,isim) {
	var deger=$('#'+isim).val();
	if (deger.length==0 || !/^[\w\d_-]+(.[\w\d_-]+)*@[\w\d_-]+(.[\w\d_-]+)+$/.test(deger)) {
		uyari(mesaj,isim);
		return false;
	}
	return true;
}
