﻿var loading = false;
var Voted = false;
var waitElement;
var scrollX, scrollY = -1;

function Loading() {
    document.getElementById("gsLoader").style.visibility = 'visible';
}
function Unloading() {

    var Loader = document.getElementById("gsLoader");
    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();

}
function MoveWaitElement() {
    var scrollYT, scrollXT;
    waitElement = document.getElementById("gsLoader");
    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) {

 
    $('fotoObject').src = "./dane/middle/" + img;
    $('fotoObjectLink').href = "./dane/full/" + img;

}


function Register() {
    var req = mint.Request();
    req.AddParam("typ", "register");
    req.OnSuccess =
    function() {
        Unloading();
        $("gsWorkArea").innerHTML = this.responseText;
    }
    Loading();
    req.SendForm("RegisterForm", "Dispatcher.aspx");

}
function Edit() {
    var req = mint.Request();
    req.AddParam("typ", "edycja");
    req.OnSuccess =
    function() {
        Unloading();
        $("gsWorkArea").innerHTML = this.responseText;
    }
    Loading();
    req.SendForm("EditForm", "Dispatcher.aspx");
}

function removepos(ident) {
    var req = mint.Request();
    req.AddParam("typ", "basketremove");
    req.AddParam("posid", ident);


    req.OnSuccess =
    function() {
        Unloading();
        var temp = this.responseText.split("<usp />");
        $("gsWorkArea").innerHTML = temp[1];
        $("gsBasketBox").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)
            $("gsWorkArea").innerHTML = temp[0];
        else {
            $("gsWorkArea").innerHTML = temp[1];
            $("gsBasketBox").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)
            $("gsWorkArea").innerHTML = temp[0];
        else {
            $("gsWorkArea").innerHTML = temp[1];
            $("gsBasketBox").innerHTML = temp[0];
        }
    }
    Loading();
    req.SendForm("BasketDane", "Dispatcher.aspx");

}
function recalcpos(posid,newamount) {

    
    Loading();
    var req = mint.Request();
    req.AddParam("typ", "recall");
    req.AddParam("posid", posid);
    req.AddParam("amount", newamount);
    
    req.OnSuccess =
    function() {
        Unloading();
        var temp = this.responseText.split("<usp />");
        $("gsWorkArea").innerHTML = temp[1];
        $("gsBasketBox").innerHTML = temp[0];

    }
    req.Send("Dispatcher.aspx");

}


function GetPage(pos) {
    var req = mint.Request();
    req.AddParam("typ", "getpage");
    req.AddParam("num", pos);
    req.Send("Dispatcher.aspx", "gsWorkArea");
}
function GetDetail() {

    var req = mint.Request();
    req.AddParam("typ", "zamowienia");
    req.AddParam("ident", $('StoreOrderList').value);
    req.Send("Dispatcher.aspx", "gsWorkArea");
}
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();
        $("gsQuestionbox").innerHTML = this.responseText;


    }
    Loading();
    req.Send("Dispatcher.aspx");

}

