﻿var loading = false;
var Voted = false;
var waitElement;
var scrollX, scrollY = -1;

function Loading() {
    document.getElementById("Loader").style.visibility = 'visible';
    
}
function Unloading() {

    var Loader = document.getElementById("Loader");
    if (Loader.style.visibility == 'visible')
        Loader.style.visibility = 'hidden';
}
function Initalize() {


    if (window.addEventListener) {
        window.addEventListener('scroll', MoveWaitElement, false);
        window.addEventListener('resize', MoveWaitElement, false);
    }
    else if (window.attachEvent) {
        window.attachEvent('onscroll', MoveWaitElement);
        window.attachEvent('onresize', MoveWaitElement);
    }
    MoveWaitElement();

    if (document.getElementById('a2'))

        document.getElementById('a2').disabled = true;

}
function MoveWaitElement() {
    var scrollYT, scrollXT;
    waitElement = document.getElementById("Loader");
    if (typeof (window.pageYOffset) == "number") {
        scrollYT = window.pageYOffset;
        scrollXT = window.pageXOffset;
    }
    else if (document.body && document.documentElement && document.documentElement.scrollTop) {
        scrollYT = document.documentElement.scrollTop;
        scrollXT = document.body.scrollLeft;
    }
    else if (document.body && typeof (document.body.scrollTop) == "number") {
        scrollYT = document.body.scrollTop;
        scrollXT = document.body.scrollLeft;
    }
    if (scrollX != scrollXT || scrollY != scrollYT) {
        scrollX = scrollXT;
        scrollY = scrollYT;
        var width = document.body.clientWidth;
        waitElement.style.top = scrollYT + "px";
        waitElement.style.right = -scrollXT + "px";
    }
}
function ReplaceImage(img) {

    a1 = document.getElementById('fotoObject');
    a1.src = "./dane/middle/" + img;


}
function ShowBigNew(url) {

    url = url.slice(url.lastIndexOf('/') + 1);

    Win = window.open('Picture.aspx?src=' + url, 'displayWindow', 'width=50,height=50,titlebar=no,toolbar=no,resizable=yes,scrollbars=no,status=no,menubar=no,location=no,directories=no,copyhistory=no');

}

function Register() {
    var req = mint.Request();
    req.AddParam("typ", "register");
    req.OnSuccess =
    function() {
        Unloading();
        $("middle-main").innerHTML = this.responseText;
    }
    Loading();
    req.SendForm("RegisterForm", "Dispatcher.aspx");

}
function Edit() {
    var req = mint.Request();
    req.AddParam("typ", "edycja");
    req.OnSuccess =
    function() {
        Unloading();
        $("middle-main").innerHTML = this.responseText;
    }
    Loading();
    req.SendForm("EditForm", "Dispatcher.aspx");
}


function BasketRemove(ident) {
    var req = mint.Request();
    req.AddParam("typ", "basketremove");
    req.AddParam("id", ident);


    req.OnSuccess =
    function() {
        Unloading();
        var temp = this.responseText.split("<usp />");
        $("middle-main").innerHTML = temp[1];
        $("basketbox").innerHTML = temp[0];

    }
    req.Send("Dispatcher.aspx");


}
function Platnosc(id) {
    var req = mint.Request();
    req.AddParam("typ", "platnosc");
    req.AddParam("id", id);

    req.Send("Dispatcher.aspx", "Platnosci");

}

function Comment(ProductID) {
    SetOpinionCookie(ProductID);
    var req = mint.Request();
    req.AddParam("typ", "comment");
    req.OnSuccess =
    function() {
        Unloading();

        $("komentarze").innerHTML = this.responseText;
    }
    Loading();
    req.SendForm("CommentForm", "Dispatcher.aspx");

}
function BasketLogged() {

    var req = mint.Request();
    req.AddParam("typ", "loggedfinish");
    req.OnSuccess =
    function() {
        Unloading();
        var temp = this.responseText.split("<usp />");

        if (temp[1] == undefined)
            $("middle-main").innerHTML = temp[0];
        else {
            $("middle-main").innerHTML = temp[1];
            $("basketbox").innerHTML = temp[0];
        }
    }
    Loading();
    req.SendForm("BasketDaneLogged", "Dispatcher.aspx");

}

function Dostawa(id) {
    var req = mint.Request();
    req.AddParam("typ", "dostawa");
    req.AddParam("did", id);

    req.Send("Dispatcher.aspx", "Platnosci");

}


function BasketDane() {
    var req = mint.Request();
    req.AddParam("typ", "basketdane");
    req.OnSuccess =
    function() {
        Unloading();
        var temp = this.responseText.split("<usp />");

        if (temp[1] == undefined)
            $("middle-main").innerHTML = temp[0];
        else {
            $("middle-main").innerHTML = temp[1];
            $("basketbox").innerHTML = temp[0];
        }
    }
    Loading();
    req.SendForm("BasketDane", "Dispatcher.aspx");

}
function Recall() {

    var req = mint.Request();
    req.AddParam("typ", "recall");
    req.OnSuccess =
    function() {
        Unloading();
        var temp = this.responseText.split("<usp />");
        $("middle-main").innerHTML = temp[1];
        $("basketbox").innerHTML = temp[0];

    }
    Loading();
    req.SendForm("ProductForm", "Dispatcher.aspx");

}
function GetPage(pos) {
    var req = mint.Request();
    req.AddParam("typ", "getpage");
    req.AddParam("num", pos);
    req.Send("Dispatcher.aspx", "middle-main");
}
function GetDetail() {

    var req = mint.Request();
    req.AddParam("typ", "zamowienia");
    req.AddParam("ident", $('StoreOrderList').value);
    req.Send("Dispatcher.aspx", "middle-main");
}
function SwapFirma() {
    firma = $('FirmaBox');
    nip = $('NipBox');

    if (firma.style.display == '') {
        firma.style.display = 'none';
        nip.style.display = 'none';

    }
    else {
        firma.style.display = '';
        nip.style.display = '';
    }

}
function SwapDostawa() {

    ad1 = $('AD1');
    ad2 = $('AD2');
    ad3 = $('AD3');
    if (ad1.style.display == '') {
        ad1.style.display = 'none';
        ad2.style.display = 'none';
        ad3.style.display = 'none';


    }
    else {
        ad1.style.display = '';
        ad2.style.display = '';
        ad3.style.display = '';

    }

}
function SwapDostawaLogged() {

    ad1 = $('ADL1');
    ad2 = $('ADL2');
    ad3 = $('ADL3');
    if (ad1.style.display == '') {
        ad1.style.display = 'none';
        ad2.style.display = 'none';
        ad3.style.display = 'none';


    }
    else {
        ad1.style.display = '';
        ad2.style.display = '';
        ad3.style.display = '';

    }

}




function SetDemocracyCookie(Ank_ID) {

    var today = new Date();
    var expire = new Date();

    expire.setTime(today.getTime() + 3600000 * 24 * 30);

    document.cookie = "Ankieta" + escape(Ank_ID) + "=true"
                     + ";expires=" + expire.toGMTString();
}
function SetOpinionCookie(ProductID) {

    var today = new Date();
    var expire = new Date();

    expire.setTime(today.getTime() + 3600000 * 24 * 30);
    document.cookie = "ProductComment=" + escape(ProductID)
                     + ";expires=" + expire.toGMTString();
}
function SendDemocracy(id, pos) {
    SetDemocracyCookie(id);
    var req = mint.Request();
    req.AddParam("typ", "democracy");
    req.AddParam("pos", pos);
    req.AddParam("ident", id);
    req.OnSuccess =
    function() {
        Unloading();
        $("questionbox").innerHTML = this.responseText;


    }
    Loading();
    req.Send("Dispatcher.aspx");

}


