﻿var loading = false;
var Voted =false;
var waitElement;
var scrollX, scrollY = -1;

function GetAjaxError(message, oContext){
     Unloading();
}
function AjaxCall(address,message,resultFunction,context){     
       Loading();
       WebForm_DoCallback(address,message,resultFunction,context,GetAjaxError,false);  
}
function GetCallbackResultToMenu(result,context){
        Unloading();
        var temp = result.split("<unique>");
        
        document.getElementById('right-login').innerHTML = temp[0];
        if (temp.length == 2 )
               document.getElementById('BasketMain').innerHTML = temp[1];
               
}
function Toggle()
{

    document.getElementById('show-login').style.display = 'none';
    document.getElementById('right-login').style.display = 'block';

}
function GetCallbackResultToBasket(result,context){
        Unloading();
        document.getElementById('BasketMain').style.display ="block";
        document.getElementById('BasketMain').innerHTML = result;
}
function GetCallbackResultToBasket2(result,context){
         Unloading();
        
        if (result != 'nada'){
               
              document.getElementById('BasketMain').style.display ="block";
               document.getElementById('BasketMain').innerHTML = result;
       }
}
function GetCallbackResultToDelivery(result,context)
{   
        Unloading();
        document.getElementById('deliverer').innerHTML = result;
    

}
function GetCallbackResultToBasket3(result,context){
         
       Unloading();
       if (result != 'nada'){
               if(result == "")
                        document.getElementById('BasketMain').style.display ="none";
                        else{
                        document.getElementById('BasketMain').style.display ="block";
               document.getElementById('BasketMain').innerHTML = result;
               }
       }
}
function GetCallbackResultToMiddle(result,context){
        Unloading();
       
        if(result != '')
        document.getElementById('middle-main').innerHTML = result;
       
         
}
function GetCallbackResultToNews(result,context){
        Unloading();
       
        document.getElementById('NewsletterContainer').innerHTML = result;
       
}
function AjaxParam(name,objId){
        return escape(name + '=' + document.getElementById(objId).value);

}
function AjaxParamInt(name,integer){
    return escape(name + '=' + integer);

}

function AjaxParamSt(name,integer){
    return escape(name + '=' + integer);

}
function AjaxParamCB(name,objId){
        return escape(name + '=' + (document.getElementById(objId).checked ? '1':'0'));

}
function LoginSend()    { 
      AjaxCall('Logowanie','Login&' + AjaxParam('login','Login') + '&' + AjaxParam('password','Password'),GetCallbackResultToMenu,'');
 }
function BasketAdd(number){
     scroll(0,0);
    AjaxCall('Basket','AddProduct&' + AjaxParamInt('product',number) ,GetCallbackResultToBasket,'');
}
function BasketRem(number){
    AjaxCall('Basket','RemoveProduct&' + AjaxParamInt('product',number) ,GetCallbackResultToBasket3,'');
}

function SendOrder(){
    AjaxCall('Basket','Order&',GetCallbackResultToBasket,'');
}
function SendSearch(){
    window.location = "./Szukaj.aspx?query="+encodeURI(document.getElementById('SearchTB').value);  
}
function SendSearchAdv(){

    window.location = "./Szukaj.aspx?query="+encodeURI(document.getElementById('MainContent_ctl00_Fraza').value)
                        +"&cat="+document.getElementById('MainContent_ctl00_KategoriaDDL').value
                        +"&prod="+document.getElementById('MainContent_ctl00_ProducentDDL').value ;
    
}
function Newsletter(Direction){
    
    AjaxCall('Newsletter',Direction+'&'+AjaxParam('email','NewsBox'),GetCallbackResultToNews,'');
   

}
function ChangeDelivery(value)
{
    if (document.getElementById(value))
    {
        AjaxCall('Basket$Delivery','SelectPayment&' + AjaxParam('platnosc',value),GetCallbackResultToDelivery,'');
    
    }

}
function RecallCart()
{

    var max = document.getElementById('Counter').value;
    var command='';
    var h=1;
    for (h=1;h<=max;h++)
    {    
       command+='AjaxParamInt(\''+h+'\',\''+document.getElementById('basket'+h).value+'\')+ \'&\'+';
    }
    command+='\'\'';
    AjaxCall('Basket','Recall&' + eval(command) ,GetCallbackResultToBasket3,'');     

}

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();

    
    
        
        
       
}
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 Submitter(e){

if (!e) var e = window.event
	if (e.keyCode) code = e.keyCode;
	else if (e.which) code = e.which;

if (code ==13)
    return true;
else return false;

}
function ReplaceImage(img)
{
   a1 = document.getElementById('FotoGallery');
   a1.src = "./dane/middle/"+img;  
}
function ShowInfo(id,type) {
     Win=window.open('/Opis.aspx?id='+id+'&type='+type,'displayWindow','width=210,height=175,titlebar=no,toolbar=no,resizable=yes,scrollbars=auto,status=no,menubar=no,location=no,directories=no,copyhistory=no' );
}
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 CallInfo(DropID,type)
{
    ShowInfo(document.getElementById(DropID).value,type);
}

function rb()
{
    
    firma = document.getElementById('FirmaBox');
    nip = document.getElementById('NipBox');
    sel =  document.getElementById('Basket_Faktura');
    
    if (sel.value == 2)
    {
    
        
       firma.style.display = 'none';
        nip.style.display = 'none';
    
    }
    else
    {
        firma.style.display = '';
        nip.style.display = '';
    }

}
function rb2()
{
    firma = document.getElementById('FirmaBox');
    nip = document.getElementById('NipBox');
    if (firma.style.display == '')
    {
        
        firma.style.display = 'none';
        nip.style.display = 'none';
    }
    else
    {
        firma.style.display = '';
        nip.style.display = '';
    }

}
function rb3()
{

    a1 = document.getElementById('T1');
    a2 = document.getElementById('T2');
    a3 = document.getElementById('T3');
      a4 = document.getElementById('T4');
    if (a1.style.display == '')
    {
        a1.style.display = 'none';
        a2.style.display = 'none';
        a3.style.display = 'none';
        a4.style.display = 'none';
       
    }
    else
    {
        a1.style.display = '';
        a2.style.display = '';
        a3.style.display = '';
        a4.style.display = '';
    }

}

function CheckRe()
{

        if(!document.getElementById('Rcheck').checked)
        alert('cos');

}