﻿var loading = false;
var Voted =false;
var waitElement;
var scrollX, scrollY = -1;

function GetAjaxError(message, oContext){
  //  alert('Wystąpił błąd: '+ message);
    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 GetCallbackResultToLoginOut(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];
      setTimeout(MainPage,550);       
   
}


function GetCallbackResultToBasket(result,context){
        Unloading();
       
         document.getElementById('BasketMain').innerHTML = result;
       
      
 
}
function GetCallbackResultToBasket2(result,context){
         Unloading();
        
        if (result != 'nada'){
               
             //  Blink();
               document.getElementById('BasketMain').innerHTML = result;
       }
}
function GetCallbackResultToVoter(result,context)
{   Unloading();
    document.getElementById('voter').innerHTML = result;
    Voted = true;

}
function GetCallbackResultToBasket3(result,context){
         Unloading();
        
        if (result != 'nada'){
             //  if (result.length <150)
              //  Blink();
               document.getElementById('BasketMain').innerHTML = result;
       }
}

function GetCallbackResultToMiddle(result,context){
        Unloading();
       
        if(result != '')
        document.getElementById('middle-main').innerHTML = result;
       
         
}
function GetCallbackResultToRandom(result,context){
        Unloading();
        document.getElementById('RandomContainer').innerHTML = result;
        window.setTimeout(GetRandom, 30*1000); 
}

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 GetPage(number){     
     AjaxCall('MainContent$MainProducts','PageSelect&' + AjaxParamInt('page',number) ,GetCallbackResultToMiddle,'');   
}

function ChangeSort(number){     
     AjaxCall('MainContent$MainProducts','SortMethod&' + AjaxParamInt('sort',number) ,GetCallbackResultToMiddle,'');   
}

function Ocen(number,id)
{
    if(!Voted)
    AjaxCall('MainContent$DetailProduct$Voter','Vote&'+AjaxParamInt('value',number)+'&'+AjaxParamInt('id',id) ,GetCallbackResultToVoter,'');   

}

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(){
    
    AjaxCall('MainContent$SearchResult','Search&'+AjaxParam('query','SearchTB'),GetCallbackResultToMiddle,'');
    
}
function Newsletter(Direction){
    
    AjaxCall('Newsletter',Direction+'&'+AjaxParam('email','NewsBox'),GetCallbackResultToNews,'');
   

}
function MainPage(){
    ctCollapseTree('TreeDiv');
    AjaxCall('MainContent$MainProducts','MainPage&',GetCallbackResultToMiddle,'');
}
function ShowNew(){
    ctCollapseTree('TreeDiv');
    AjaxCall('MainContent$MainProducts','ShowNew&',GetCallbackResultToMiddle,'');
}
function ShowPromoted(){
    ctCollapseTree('TreeDiv');
    AjaxCall('MainContent$MainProducts','ShowPromoted&',GetCallbackResultToMiddle,'');
}

function GetContent(number){
    AjaxCall('MainContent$Content','Content&'+AjaxParamInt('id',number),GetCallbackResultToMiddle,'');
}

function GetRandom(){

     AjaxCall('Random','O',GetCallbackResultToRandom,'');
}
function GetCategory(number)
{
    AjaxCall('MainContent$MainProducts','SelectCategory&'+escape('id='+number),GetCallbackResultToMiddle,'');
}
function GetProductCat(number)
{
    AjaxCall('MainContent$MainProducts','BackCategory&'+escape('id='+number),GetCallbackResultToMiddle,'');
}

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';
}


// JScript File

function Initalize()
{
       window.setTimeout(GetRandom, 30*1000); 
       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();
 
        var cat = document.getElementById('HiddenCat');
        if(cat)
               { 
           
               ctExposeItem (0, cat.innerHTML);
            
        }

        
       
}
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 ShowBig(url) {
     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 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 AskPrice(id)
{
Win=window.open('/Ask.aspx?id='+id,'displayWindow','width=450,height=190,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');
    
    if (firma.style.display == '')
    {
        firma.style.display = 'none';
        nip.style.display = 'none';
    
    }else
    {
        firma.style.display = '';
        nip.style.display = '';
    }

}


