function openSimulator(url)
{
  window.open('blank.html','newwin','');
}


function updateClock ( )
{
  var currentTime = new Date();

  var currentHours = currentTime.getHours();
  var currentMinutes = currentTime.getMinutes();
  var currentSeconds = currentTime.getSeconds();

  // Pad the minutes and seconds with leading zeros, if required
  currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
  currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;

  // Convert an hours component of "0" to "12"
  currentHours = ( currentHours == 0 ) ? 12 : currentHours;

  // Compose the string for display
  var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " ";

  // Update the time display
  document.getElementById("clock").firstChild.nodeValue = currentTimeString;
}


//------------------------------------------------------------------------------

      function show(id) 
      {
        var e = document.getElementById(id);
        if(e.style.display == 'none')
          e.style.display = 'block';
        else
          e.style.display = 'none';
      };   

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
function dostdetget(id)
{
  $('dostplat_wait').innerHTML='wczytywanie...';
  var jsonRequest = new Request.JSON({url: "/bask_ajaxplat/"+id, onSuccess: function(dane){
    
    if(dane.wysylka==1)
    {
        $('wysylkaadr').setStyle('display','block');
        
        if($('ppar').getProperty('checked')==true)
        {
          $('ppar').setProperty('checked',false);
          $('ppar').setProperty('disabled',true); 
          $('pfakt').setProperty('checked',true); 
          $('faktura').setStyle('display','block');
        }
        
        
    }
    else
    {
       $('wysylkaadr').setStyle('display','none');       
       $('ppar').setProperty('disabled',false);
       
    }; 
    $('dostplat_wait').innerHTML='';
    
  }}).send();


};

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
      
      function wysylkach() 
      {
        var wys = document.getElementById('wysylka');
        var e = document.getElementById('wysylkaadr');
        var x = document.getElementById('ppar');
        var y = document.getElementById('pfakt');
        var form_plat = document.getElementById('formy_platnosci');
        var koszt_wys = document.getElementById('koszt_wys');
        
        //adres dostawy
        if(wys.value=='-1' || wys.value=='1')
          e.style.display = 'none';
        else
          e.style.display = 'block';
       
        //czyszczenie kosztow
        if(koszt_wys!=null)
          koszt_wys.innerHTML='';
        if(form_plat!=null && wys.value=='0')
          form_plat.innerHTML='';

        //faktura / paragon
        if(wys.value!='1' && wys.value!='-1')
        {
          if(x.checked==true)
            y.checked=true;
          x.disabled=true;
          document.getElementById('faktura').style.display = 'block';
        }
        else
        {
          x.disabled=false;
          x.checked=true;
          document.getElementById('faktura').style.display = 'none';
        };
        //oznaczanie jako wymaagne        
        /*
        if(wys.value=='-1')
          wys.class="validate['required']";
        else
          wys.class="";
        */
      };         
  
//------------------------------------------------------------------------------
//ustawia wartosc ukrytego checkboxa
//------------------------------------------------------------------------------
function faktch_set(x) 
{
  var z = document.getElementById('uzup_dane_fakt');
  z.value=x;
}

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

function faktch() 
{
  var x = document.getElementById('os');
  var y = document.getElementById('fir');
  var z = document.getElementById('uzup_dane_fakt');
          
  var nazwaflabel = document.getElementById('nazwaflabel');
  var niplabel = document.getElementById('niplabel');
 document.getElementById('nazwa_firmy').value='';
  document.getElementById('nip').value='';
            
//podmiana labelek
  if(x.checked!=true)
  {
    nazwaflabel.innerHTML='Nazwa firmy:';
    niplabel.innerHTML='Nip:';
  }
  else
  {
    nazwaflabel.innerHTML='Imię:';
    niplabel.innerHTML='Nazwisko:';
  }
//uzupelnianie danymi
  if(z.value=='1')
  {
    var ajx = new Request({
    		method: 'get',
    		url:'/ajx_baskdanefakt/',
    		onComplete: function(html) 
        {
          arr = String.split(html,'::');

          $('platnik_ulica').set('value',arr[4]);
          $('platnik_numer_domu').set('value',arr[5]);
          $('platnik_numer_lokalu').set('value',arr[6]);
          $('platnik_kod_pocztowy').set('value',arr[7]);
    		  $('platnik_miejscowosc').set('value',arr[8]);
     		},
    		onFailure: function() {
    			//alert('test');
    		}
    	}).send();


    //na osobe
    if(x.checked==true)
    {
      setTimeout('$(\'nazwa_firmy\').set(\'value\',arr[0]);$(\'nip\').set(\'value\',arr[1]);',150);
    }
    //na firme
    else if(y.checked==true)
    {
      setTimeout('$(\'nazwa_firmy\').set(\'value\',arr[2]);$(\'nip\').set(\'value\',arr[3]);',150);
    }
  }
  else
  {
      $('nazwa_firmy').set('value','');
      $('nip').set('value','');
      $('platnik_ulica').set('value','');
      $('platnik_numer_domu').set('value','');
      $('platnik_numer_lokalu').set('value','');
      $('platnik_kod_pocztowy').set('value','');
    	$('platnik_miejscowosc').set('value','');  
  }
};

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

function ajx_wysylka(x)
{
  //$('imie').load('/ajx_baskdostawa');
  
    var ajx = new Request({
    		method: 'get',
    		url:'/ajx_baskdostawa/'+x.value,
    		onComplete: function(html) {
    		  
          var arr = String.split(html,'::');
    		  $('imie').set('value',arr[0]);
          $('nazwisko').set('value',arr[1]);
          $('ulica').set('value',arr[2]);
          $('numer_domu').set('value',arr[3]);
          $('numer_lokalu').set('value',arr[4]);
          $('kod').set('value',arr[5]);
    		  $('miejscowosc').set('value',arr[6]);
    		},
    		onFailure: function() {
    			//alert('test');
    		}
    	}).send();	
  
	
};

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

function ajx_formy_platnosci(x)
{ 
    var ajx = new Request({
    		method: 'get',
    		url:'/ajx_baskplatnosci/'+x,
    		onComplete: function(html) {
    		  
    		  $('formy_platnosci').innerHTML=html;
    		},
    		onFailure: function() {
    			//alert('test');
    		}
    	}).send();	
};

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

function ajx_koszt_wys(x)
{  
    //jesli wybrane
    if(x!='-1')
    {
    var ajx = new Request({
    		method: 'get',
    		url:'/ajx_baskkosztwys/'+x,
    		onComplete: function(html) {
    		  var arr = String.split(html,'::#::');
    		  $('koszt_wys').innerHTML=arr[1];
    		  
    		  //sprawdza czy wybrano raty - tylko faktura
          if(arr[0]=='1')
    		  {
            document.getElementById('pfakt').checked=true;
            document.getElementById('ppar').disabled=true;
            document.getElementById('faktura').style.display = 'block';

          }
          // jesli nie i odbior osobisty - mozliwy paragon
          else if(document.getElementById('wysylka').value=='1')
          {

            document.getElementById('pfakt').checked=false;
            document.getElementById('ppar').disabled=false;
            document.getElementById('faktura').style.display = 'none';
          }
    		},
    		onFailure: function() {
    		}
    	}).send();	
    }
    //czyszczenie kosztow
    else
    {
      $('koszt_wys').innerHTML='';
    }
};

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

function alertconfirm(al,go)
{
  var x = Alertbox.confirm(al, {
  textBoxBtnOk: 'Tak',
  textBoxBtnCancel: 'Nie',
  onComplete: 
          function(returnvalue) { 
            if(returnvalue)
            {
              var tmp = go.toURI();
              tmp.go();
            };
            
          }  
  });
  

};

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

window.addEvent('domready',function(){

updateClock(); 
setInterval('updateClock()', 1000 );

//------------------------------------------------------------------------------
// mooquee
//------------------------------------------------------------------------------

if($('mooquee1')!=null)
obj = new mooquee($('mooquee1'), {pauseOnOver: true,direction:'left',marHeight: 20, marWidth: 685});

//------------------------------------------------------------------------------
// tooltipy
//------------------------------------------------------------------------------

  $$('.tooltip').each(function(element,index) {
        var content = element.get('title').split('::');
        element.store('tip:title', content[0]);
        element.store('tip:text', content[1]);
    });

  var toolTips = new Tips($$('.tooltip'));

 
//------------------------------------------------------------------------------
// lightwindow
//------------------------------------------------------------------------------

  SqueezeBox.assign($$('a[rel=boxed]'));
  
  //var formch = new FormCheck('formularz',{display:{listErrorsAtTop:true}});

//------------------------------------------------------------------------------
//alert box
//------------------------------------------------------------------------------

  var al = $('ind_error_bask_add');  
  if(al!=null)
    Alertbox.info($('ind_error_bask_add').get('html'));
  var al2 = $('ind_error');  
  if(al2!=null)
    Alertbox.alert($('ind_error').get('html'));

//------------------------------------------------------------------------------
// ajax nowosci
//------------------------------------------------------------------------------

  
      var req_news = new Request.HTML({
    		method: 'get',
    		url:'/ajx_indnews',
        initialDelay: 0, 
    		delay: 5000,
    		onSuccess: function(html) { 
          var x = document.getElementById('ind_news');
          if(x!=null)  
          { 
            
              $('ind_news').fade(0);                                   		  
              $('ind_news').empty();
              $('ind_news').adopt(html);
              $('ind_news').fade(1); 
            
          };
    		},
    		onFailure: function() {
    		  var x = document.getElementById('ind_news');
          if(x!=null)  
          {           
    			   $('ind_news').adopt('<img src="/js/moo/assets/spinner.gif" alt="wczytywanie">');
    			};
    		}
    	});	
    	req_news.startTimer();
	

//------------------------------------------------------------------------------
// ajax promocje
//------------------------------------------------------------------------------

  var y = document.getElementById('ind_promo');
  if(y!=null)
  {
      var req_promo = new Request.HTML({
    		method: 'get',
    		url:'/ajx_indpromo',
        initialDelay: 0, 
    		delay: 5000,
    		onSuccess: function(html) {
    			$('ind_promo').empty();
    			$('ind_promo').adopt(html);
    		},
    		onFailure: function() {
    			$('ind_promo').adopt('<img src="/js/moo/assets/spinner.gif" alt="wczytywanie">');
    		}
    	});	
    	req_promo.startTimer();
	};

//------------------------------------------------------------------------------
// MENU
//------------------------------------------------------------------------------

  var menupod = $(document.body).getElements('div.ind_menuslave');
  
  menupod.each(function(item, index){
      item.addEvent('mouseenter', function() {
  	
  	   this.setStyle('opacity',0.6);
  	   
	
	    });
	    
	    item.addEvent('mouseleave', function() {
  	
  	   this.fade(1);
	
	    });
	    
  });
  
  
  var menumas = $(document.body).getElements('div.ind_menumaster');
  
  menumas.each(function(item, index){
      item.addEvent('mouseenter', function() {
  	
  	   this.setStyle('opacity',0.6);
	
	    });
	    
	    item.addEvent('mouseleave', function() {
  	
  	   this.fade(1);
	
	    });
	    
  });
  
//------------------------------------------------------------------------------
//klocki kategorii
//------------------------------------------------------------------------------

var z = document.getElementById('prod_kattable');
if(z!=null)
{
    var prodkat = $('prod_kattable').getElements('td');
    if(prodkat!=null)
      prodkat.each(function(item, index)
      {
          
          var str=item.getStyle('border');
          
          if(str.substring(0,3)!='0px')
          {
              item.addEvent('mouseenter', function() {
          	
          	   this.setStyle('background-color','#ededed');
          	   
        	
        	    });
    	    };
    	    
    	    if(str.substring(0,3)!='0px')
      	    item.addEvent('mouseleave', function() {
        	
        	   //this.fade(1);
        	   
        	   this.set('tween',{duration: 150});
        	   this.tween('background-color',['#ededed','#ffffff']);
      	
      	    });
    	    
      }); 
  
};

//------------------------------------------------------------------------------
//---------------- prod_dodajk
//------------------------------------------------------------------------------

var koszb = $('ind_colright').getElements('a.prod_dodajk');	    
if(koszb!=null)
{ 	    
	    koszb.addEvent('mouseleave', function() {
  	
  	   this.fade(1);
	
	    });
	    
	     koszb.addEvent('mouseenter', function() {
  	
  	   this.fade(0.6);
	
	    });	    
};
	    
  
//------------------------------------------------------------------------------
//klocki produktow
//------------------------------------------------------------------------------

var y = document.getElementById('prod_prodtable');
if(y!=null)
{
    var prodprodboxt = $('prod_prodtable').getElements('td');
    if(prodprodboxt!=null)
    prodprodboxt.each(function(item, index)
    {
      	
      	var str=item.getStyle('border');
          
        if(str.substring(0,3)!='0px')
      	   item.addEvent('mouseenter', function() 
           {
      	
      	       this.setStyle('background-color','#ededed');
    	
    	     });
    	   
         if(str.substring(0,3)!='0px')  
    	     item.addEvent('mouseleave', function() {
      	   
      	   this.set('tween',{duration: 150});
      	   this.tween('background-color',['#ededed','#ffffff']);
    	
    	    });
    	
    });

};

//------------------------------------------------------------------------------
//------------------------------------------------------------------------------

});



