var Variables;

function getURLParam() {
	var strQueryString = "";
	var hasQueryString = document.URL.indexOf('?');
	if (hasQueryString != -1) {
		strQueryString = document.URL.substring(hasQueryString+1, document.URL.length);
	}
	Variables = strQueryString.split("#");
}

/*--------ograniczenie ilosci znakow w textarea---------*/

Textarea = function() { 
     jQuery("#zamowienie_form textarea").keyup(function(){
          var maximum = 255; 
          var box=jQuery(this).val();
          if(box.length > maximum){
          alert('Dopuszczalna ilość znaków to '+maximum);
               jQuery(this).val(jQuery(this).val().substring(0,maximum));
          }
     });
}

/*----------------*/

jQuery.noConflict();

jQuery(document).ready(function() {
  
  jQuery('.help').tooltip({showURL: false});
  
	jQuery(function() {
		jQuery('#container-1 > ul').tabs();
	});
	
	Textarea();
	jQuery('.lightbox').lightBox();
	jQuery('.zoom').lightBox();
	
	if (jQuery("#form_faktura").hasClass('ukryj')) {
		jQuery("#form_faktura").hide();
	}
	
	jQuery("#faktura").bind('click', function() {
		if(jQuery(this).hasClass('checked')) {
			jQuery("#form_faktura").hide();
			jQuery(this).removeClass('checked');
			jQuery(".dane_f label").removeClass('checked');
		} else {
			jQuery("#form_faktura").show();
			jQuery(this).addClass('checked');
			jQuery(".dane_f label").addClass('checked');
		}
	});
	
	var dt = '.dt';
	var dd = '.dd';
	jQuery('.dd.hide').hide();

	getURLParam();
	var url1 = document.location.toString().split("#");
	jQuery('.dt#'+url1[1]).addClass('selected').next('.dd').show();

	jQuery("#link_dostawa").bind('click', function() {
		var id=jQuery(this).attr('href').split("#");
		jQuery(".dt#" + id[1]).next(".dd").show();
	});

	jQuery("#link_platnosci").bind('click', function() {
		var id=jQuery(this).attr('href').split("#");
		jQuery(".dt#" + id[1]).next(".dd").show();
	});

	jQuery('.dt').click(function() {
		var url = document.location.toString().split("#");
		var hash = jQuery(this).attr('id');
		document.location = url[0] + "#" + hash;
	});

	var ofs = jQuery("#" + url1[1]).offset();
	if (ofs) {
		//jQuery('html,body').animate({scrollTop: ofs.top}, 1);
	}

	jQuery(".dt").bind('click', function() {
		if (jQuery(this).hasClass('selected')) {
			jQuery(this).removeClass('selected').next('.dd').hide('fast');
		} else {
			jQuery(dt + '.selected').removeClass('selected').next('.dd').hide('fast');
			jQuery(this).next('.dd').show('fast');
			jQuery(this).addClass('selected');
		}
		return false;
	});

	jQuery("#link_bt").css("display","none");
	jQuery("#button").css("display","block");

	/*jQuery('#koszty').hide();

	jQuery('#koszty_link').click(function() {
		jQuery('#koszty').toggle();
		return false; 
	}).toggle(function() {
		jQuery(this).addClass('selected');
	}, function() {
		jQuery(this).removeClass('selected');
	});*/
	
	jQuery('#koszty_link').click(function() {
	  var link = jQuery(this).attr('href');
    window.open(link,'koszty','scrollbars=yes, status=no, toolbar=no, location=no, directories=no, width=700, height=700, left=100, top=100');
    return false;
  });

	jQuery('#koszyk_link').click(function() {
		jQuery('#koszyk_box').toggle();
		return false; 
	}).toggle(function() {
		jQuery(this).addClass('selected');
		jQuery(this).find('span').text('Zwiń koszyk');
	}, function() {
		jQuery(this).removeClass('selected');
		jQuery(this).find('span').text('Rozwiń koszyk');
	});
	
	jQuery("#dzialalnosc").bind('click', function() {
	    if(jQuery(this).hasClass('checked')){
        jQuery(this).removeClass('checked');
      }
      else{
        jQuery(this).addClass('checked');
      }
        
	}); 
	
	jQuery("#nip input").focus(function() {
	  if(!jQuery("#dzialalnosc").hasClass('checked')){
	    alert('Potwierdź prowadzenie działalności gospodarczej!');
    }
  });
  
  
});	


/*------------ podsumowanie zamowienia ------------*/		
		
		function okno_procedura_zagiel() {
			window.open('https://www.zagiel.com.pl/kalkulator/jak_kupic.html', 'nowe_okno', 'width=800,height=600,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
    }

		function validate_Zagiel() {
			var potwierdzenie_zagiel = document.getElementById( 'potwierdzenie_zagiel' );
			if ( ! potwierdzenie_zagiel.checked ){
				alert ("Zanim złożysz zamówienie, zapoznaj się z procedurą udzielenia kredytu ratalnego eRaty Żagiel.");
				return false;
			} else {
				return true;
			}
		}		
