﻿
function pageLoad(sender, args) {
    Sys.Net.WebRequestManager.add_invokingRequest(onInvoke);
}

function pageUnload(sender, args) {
    Sys.Net.WebRequestManager.remove_invokingRequest(onInvoke);
}

function onInvoke(sender, args) {
    args.get_webRequest().get_headers()['is_secure'] = is_secure;
}

function getStyle(el, styleProp) {
    var x = document.getElementById(el);
    if (x.currentStyle)
        var y = x.currentStyle[styleProp];
    else
        if (window.getComputedStyle)
        var y = document.defaultView.getComputedStyle(x, null).getPropertyValue(styleProp);
    return y;
}

function getPos(div) {

    var pos = { x: div.offsetLeft, y: div.offsetTop };

    if (div.offsetParent /*&& getStyle(div.id, "position") != "relative"*/) {
        var tmp = getPos(div.offsetParent);
        pos.x += tmp.x;
        pos.y += tmp.y;
    }
    return pos;
}
function toggleDisabled(el, statu) {

    try {
        el.disabled = statu;
    }
    catch (E) { }
    if (el.childNodes && el.childNodes.length > 0) {
        for (var x = 0; x < el.childNodes.length; x++) {
            toggleDisabled(el.childNodes[x], statu);
        }
    }
}

function progress(Divid, sepetDivid) {
    var self = this;
    this.trans_div = document.createElement('div');
    this.content_ana = document.createElement('div');
    this.sepet_img = document.createElement('img');
    this.trans_sepet_img = document.createElement('img');
    this.divid = Divid;
    this.sepetdivid = sepetDivid;
    this.divpos = null;
    this.sepetdivpos = null;
    this.divwidth = 0;
    this.divheight = 0;
    this.sepetdivwidth = 0;
    this.sepetdivheight = 0;
    this.divtop = 0;
    this.divleft = 0;
    this.sepetdivleft = 0;
    this.sepetdivtop = 0;
    this.divcenterx = 0;
    this.divcentery = 0;
    this.sepetdivcenterx = 0;
    this.sepetdivcentery = 0;
    this.vdist = 0;
    this.hdist = 0;
    this.vmove = 0;
    this.hmove = 0;
    this.move = 0;
    this.movecount = 0;

    self.init = function() {

        this.divid = Divid;
        this.sepetdivid = sepetDivid;
        this.divpos = getPos($get(this.divid));
        this.sepetdivpos = getPos($get(this.sepetdivid));

        this.trans_div.setAttribute("id", "trans_div_" + Math.round(Math.random() * 1000));
        this.content_ana.setAttribute("id", "content_ana_" + Math.round(Math.random() * 1000));
        this.sepet_img.setAttribute("src", "http://static.bimeks.com.tr/img/basket_product_page.gif");
        this.trans_sepet_img.setAttribute("src", "http://static.bimeks.com.tr/img/basket_product_page.gif");
        this.content_ana.appendChild(this.sepet_img);
        this.trans_div.appendChild(this.trans_sepet_img);
        this.content_ana.style.display = "none";

        //this.content_ana.innerHTML = $get(this.divid).innerHTML;
        self.show();
    }
    self.show = function() {

        this.content_ana.style.display = "block";
        this.content_ana.style.position = "absolute";
        this.content_ana.style.zIndex = "10";

        this.trans_div.style.display = "block";
        this.trans_div.style.position = "absolute";
        this.trans_div.style.zIndex = "10";
        this.trans_div.style.cursor = "pointer";

        this.content_ana.style.left = this.divpos.x + "px";
        this.content_ana.style.top = this.divpos.y + "px";

        this.trans_div.style.left = this.divpos.x + "px";
        this.trans_div.style.top = this.divpos.y + "px";

        this.content_ana.style.width = $get(this.divid).offsetWidth + "px";
        this.content_ana.style.height = $get(this.divid).offsetHeight + "px";

        this.trans_div.style.width = $get(this.divid).offsetWidth + "px";
        this.trans_div.style.height = $get(this.divid).offsetHeight + "px";

        document.body.appendChild(this.trans_div);
        document.body.appendChild(this.content_ana);

        this.divwidth = $get(this.divid).offsetWidth;
        this.divheight = $get(this.divid).offsetHeight;
        this.divleft = this.divpos.x;
        this.divtop = this.divpos.y;

        this.sepetdivwidth = $get(this.sepetdivid).offsetWidth;
        this.sepetdivheight = $get(this.sepetdivid).offsetHeight;
        this.sepetdivleft = this.sepetdivpos.x;
        this.sepetdivtop = this.sepetdivpos.y;

        this.sepetdivcenterx = Math.round(parseInt(this.sepetdivleft + this.sepetdivwidth + this.sepetdivleft) / 2)
        this.sepetdivcentery = Math.round(parseInt(this.sepetdivtop + this.sepetdivheight + this.sepetdivtop) / 2)

        this.divcenterx = Math.round(parseInt(this.divleft + this.divwidth + this.divleft) / 2)
        this.divcentery = Math.round(parseInt(this.divtop + this.divheight + this.divtop) / 2)

        this.move = 20;
        this.movecount = 0;
        this.vmove = 0;
        this.hmove = 0;

        self.fly();
    }
    self.fly = function() {

        this.divpos = getPos($get(this.content_ana.id));
        this.divleft = this.divpos.x;
        this.divtop = this.divpos.y;

        this.divcenterx = Math.round(parseInt(this.divleft + this.divwidth + this.divleft) / 2)
        this.divcentery = Math.round(parseInt(this.divtop + this.divheight + this.divtop) / 2)

        this.hdist = Math.abs(this.sepetdivcenterx - this.divcenterx);
        this.vdist = Math.abs(this.sepetdivcentery - this.divcentery);

        if (this.movecount == 0 && this.vmove == 0 && this.hmove == 0) {
            this.movecount = Math.round(this.vdist / this.move);
            this.vmove = Math.round(this.vdist / this.movecount);
            this.hmove = Math.round(this.hdist / this.movecount);
        }

        if (this.sepetdivcenterx <= this.divcenterx)
            this.content_ana.style.left = (parseInt(this.content_ana.style.left) - this.hmove) + "px";
        else
            this.content_ana.style.left = (parseInt(this.content_ana.style.left) + this.hmove) + "px";

        this.content_ana.style.top = (parseInt(this.content_ana.style.top) - this.vmove) + "px";

        if (this.sepetdivcentery < this.divcentery)
            window.setTimeout(function() { self.fly(); }, 10);
        else
            self.hide();
    }
    self.hide = function() {

        this.content_ana.style.display = 'none';
        this.trans_div.style.display = 'none';

        //body childnodes ları taranır.
        //runtime da eklediğimiz animation div childenode remove edilir.

        children = document.body.childNodes;
        for (i = 0; i < children.length; i++) {

            if (children[i].id == this.content_ana.id ||
               children[i].id == this.trans_div.id)
                document.body.removeChild(children[i]);
        }

        //diable edilen sepete ekle  divi  enable  edildi.
        //toggleDisabled($get(Divid), true);
    }
}
