﻿//function pageLoad(sender) {
//    if ($get("gm_porfno_on") != null)
//        $get("gm_porfno_on").onkeyup = bfem_porfno_al;
//}

function bfem_porfno_al(evt) {
    evt = (evt) ? evt : ((window.event) ? event : null);
    if (evt && ((evt.keyCode >= 48 && evt.keyCode <= 57) || (evt.keyCode >= 96 && evt.keyCode <= 105) || evt.keyCode == 8)) {
        var porfno_on = $get("gm_porfno_on").value;
        if (porfno_on != "" || porfno_on != null) {
            goster('gm_porfno_yukleniyor');
            bfem_ws_porfnogetir.porfno_bul(porfno_on, 3, bfem_porfno_sonuc_al);            
        }
    } else if (evt && evt.keyCode == 13) {
        document.location = "gayrimenkul-" + $get("gm_porfno_on").value + ".aspx";
        //alert("gayrimenkul-" + $get("gm_porfno_on").value + ".aspx");
        evt.keyCode = 0;
    }
}

function bfem_porfno_sonuc_al(sonuc_veri) {
    gizle('gm_porfno_yukleniyor');
    if (sonuc_veri != "") {
        $get("gm_porfno_sonuclar").innerHTML = sonuc_veri;
    }
    else if ($get("gm_porfno_on").value == "" && sonuc_veri == "") {
        $get("gm_porfno_sonuclar").innerHTML = "";
    }
    else {
        $get("gm_porfno_sonuclar").innerHTML = "Aradığınız portföy numarasına sahip portföy bulunamadı!";
    }
}

function kocak_tems_harita_al(il, temsdiv) {
    if (il != "" || il != null) {
        goster('kocak_tems_widget_harita_yukleniyor');
        gizle('kocak_tems_widget_harita_sonuc');
        kocak_temsilcilikler_il_al.tems_al(il, kocak_tems_harita_sonuc_al);

        if ($get("kocak_tems_widget_harita_sonuc").innerHTML == "")
            kocak_smooth_scroll('harita_tems'); //  location.href = "#";
    }
}

function kocak_tems_harita_sonuc_al(sonuc_veri) {
    if (sonuc_veri != "") {
        $get("kocak_tems_widget_harita_sonuc").innerHTML = sonuc_veri;
    }
    else if ($get("gm_porfno_on").value == "" && sonuc_veri == "")
        $get("kocak_tems_widget_harita_sonuc").innerHTML = "";
    else
        $get("kocak_tems_widget_harita_sonuc").innerHTML = "Seçtiğiniz şehirde temsilciliğimiz bulunmamaktadır!";

    gizle('kocak_tems_widget_harita_yukleniyor');
    goster('kocak_tems_widget_harita_sonuc');

}

function kocak_tems_harita_al_hepsi() {
    if ($get("kocak_tems_hepsi_widget_harita_sonuc").innerHTML == "") {
        kocak_temsilcilikler_il_al.tems_al("hepsi", kocak_tems_hepsi_harita_sonuc_al);
        goster('kocak_tems_hepsi_widget_yukleniyor');
    }
}

function kocak_tems_hepsi_harita_sonuc_al(sonuc_veri) {
    gizle('kocak_tems_hepsi_widget_yukleniyor');
    if (sonuc_veri != "")
        $get("kocak_tems_hepsi_widget_harita_sonuc").innerHTML = sonuc_veri;
    else if ($get("gm_porfno_on").value == "" && sonuc_veri == "")
        $get("kocak_tems_hepsi_widget_harita_sonuc").innerHTML = "";
    else
        $get("kocak_tems_hepsi_widget_harita_sonuc").innerHTML = "Temsilcilikler Alınamadı!";

}

function bfem_arama_detayli_ackapat(detayli_hidden, detayli_div, detayli_btn) {
    if ($get(detayli_hidden).value == "1") {
        gizle(detayli_div);
        $get(detayli_hidden).value = "0";
        $get(detayli_btn).value = "Detaylı Arama";
    }
    else {
        goster(detayli_div);
        $get(detayli_hidden).value = "1";
        $get(detayli_btn).value = "Basit Arama";
    }
}

function kocak_scroll_get_y(d) {
    gy = d.offsetTop;
    if (d.offsetParent)
        while (d = d.offsetParent)
        gy += d.offsetTop;
    return gy;
}

function kocak_scroll_scroll_top() {
    bodyy = document.body;
    d = document.documentElement;
    if (bodyy && bodyy.scrollTop) return bodyy.scrollTop;
    if (d && d.scrollTop) return d.scrollTop;
    if (window.pageYOffset) return window.pageYOffset;
    return 0;
}

function kocak_scroll(d) {
    i = window.innerHeight || document.documentElement.clientHeight;
    h = document.body.scrollHeight;
    a = kocak_scroll_scroll_top();

    if (d > a)
        if (h - d > i)
        a += Math.ceil((d - a) / this.scroll_speed);
    else
        a += Math.ceil((d - a - (h - d)) / this.scroll_speed);
    else
        a = a + (d - a) / this.scroll_speed;

    window.scrollTo(0, a);

    if (a == d || this.offsetTop == a) clearInterval(this.scroll_interval);
    this.offsetTop = a;

}

function kocak_smooth_scroll(div) {
    clearInterval(this.scroll_interval);
    this.scroll_interval = setInterval('kocak_scroll(' + kocak_scroll_get_y(document.getElementById(div)) + ')', 10);
}
this.scroll_speed = 20;

/*
Scroller = {
// control the speed of the scroller.
// dont change it here directly, please use Scroller.speed=50;
speed:10,

// returns the Y position of the div
gy: function (d) {
gy = d.offsetTop
if (d.offsetParent) while (d = d.offsetParent) gy += d.offsetTop
return gy
},

// returns the current scroll position
scrollTop: function (){
body=document.body
d=document.documentElement
if (body && body.scrollTop) return body.scrollTop
if (d && d.scrollTop) return d.scrollTop
if (window.pageYOffset) return window.pageYOffset
return 0
},

// attach an event for an element
// (element, type, function)
add: function(event, body, d) {
if (event.addEventListener) return event.addEventListener(body, d,false)
if (event.attachEvent) return event.attachEvent('on'+body, d)
},

// kill an event of an element
end: function(e){
if (window.event) {
window.event.cancelBubble = true
window.event.returnValue = false
return;
}
if (e.preventDefault && e.stopPropagation) {
e.preventDefault()
e.stopPropagation()
}
},
	
// move the scroll bar to the particular div.
scroll: function(d){
i = window.innerHeight || document.documentElement.clientHeight;
h = document.body.scrollHeight;
a = Scroller.scrollTop();
		
if(d>a)
if(h-d>i)
a+=Math.ceil((d-a)/Scroller.speed);
else
a+=Math.ceil((d-a-(h-d))/Scroller.speed);
else
a = a+(d-a)/Scroller.speed;
			
window.scrollTo(0,a);
if(a==d || Scroller.offsetTop==a)clearInterval(Scroller.interval);
Scroller.offsetTop=a
},
	
smoothscroll_div : function(div){
clearInterval(Scroller.interval);
Scroller.interval=setInterval('Scroller.scroll('+Scroller.gy(document.getElementById(div))+')',10);

},
// initializer that adds the renderer to the onload function of the window
init: function(){
Scroller.add(window,'load', Scroller.render);
},

// this method extracts all the anchors and validates then as # and attaches the events.
render: function(){
a = document.getElementsByTagName('a');
Scroller.end(this);
window.onscroll
for (i=0;i<a.length;i++) {
l = a[i];
if(l.href && l.href.indexOf('#') != -1 && ((l.pathname==location.pathname) || ('/'+l.pathname==location.pathname)) ){
Scroller.add(l,'click',Scroller.end)
l.onclick = function(){
Scroller.end(this);
l=this.hash.substr(1);
a = document.getElementsByTagName('a');
for (i=0;i<a.length;i++) {
if(a[i].name == l){
clearInterval(Scroller.interval);
Scroller.interval=setInterval('Scroller.scroll('+Scroller.gy(a[i])+')',10);
}
}
}
}
}
}
}
*/