$(document).ready(function(){
/* ------------------------------------------------------------------------------------------------------------- */
$("#tabs").tabs({ 
	cache: true
});
//$('#labelSearch').focus();
/* ------------------------------------------------------------------------------------------------------------- */	
//$("tbody tr:first-child, tr th:first-child, tr td:first-child, ul li:first-child, ol li:first-child").addClass("first");
//$("tbody tr:last, tr th:last, tr td:last, tr th:last-child, tr td:last-child, ul li:last, ol li:last").addClass("last");
$("ul li:first-child, ol li:first-child").addClass("first");
$("ul li:last, ol li:last").addClass("last");
/* ------------------------------------------------------------------------------------------------------------- */
// --- datepicker pl ------------------------------------
$.datepicker.regional['pl'] = {
	closeText: 'Zamknij',
	prevText: '&laquo; Poprzedni',
	nextText: 'Następny &raquo;',
	currentText: 'Dziś',
	monthNames: ['Styczeń','Luty','Marzec','Kwiecień','Maj','Czerwiec','Lipiec','Sierpień','Wrzesień','Październik','Listopad','Grudzień'],
	monthNamesShort: ['Sty','Lu','Mar','Kw','Maj','Cze','Lip','Sie','Wrz','Pa','Lis','Gru'],
	dayNames: ['Niedziela','Poniedzialek','Wtorek','Środa','Czwartek','Piątek','Sobota'],
	dayNamesShort: ['Nie','Pn','Wt','Śr','Czw','Pt','So'],
	dayNamesMin: ['N','Pn','Wt','Śr','Cz','Pt','So'],
	dateFormat: 'yy-mm-dd', firstDay: 1,
	isRTL: false};
$.datepicker.setDefaults($.datepicker.regional['pl']);
// --- end datepicker pl ------------------------------------   

$(".datepicker").datepicker({
	showOn: 'button', 
	buttonImage: '/img/ico.calculator.gif', 
	buttonImageOnly: true,
	duration: 'fast' ,
	showAnim: 'fadeIn',
	showButtonPanel: true,
	showOn: 'both'
});		
/* ------------------------------------------------------------------------------------------------------------- */
	
$("#admin div.admin").hover(function(){
	$(this).addClass('adminHover');
  }, function(){
	$(this).removeClass('adminHover');
  }
);
/* ------------------------------------------------------------------------------------------------------------- */	
$("#header div.user dl dd").hover(function(){
	$(this).find("div.menu").show(100);
  }, function(){
	$(this).find("div.menu").hide(100);
  }
);
/* ------------------------------------------------------------------------------------------------------------- */
$('#admin input.btn').click(function() {
	var $action = $(this).attr("title");		
	if ($action != '' &&  $action != ' ') { 
		$(this).parents("form").attr("action", $action).submit();
	}
});
/* ------------------------------------------------------------------------------------------------------------- */	
$('input.delete, a.delete').click(function(){
  var answer = 'Czy na pewno usunać?';
  var title = $(this).attr('title');
	if (title != '' &&  title != ' ') { 
		if (confirm(title)) {
			return answerTitle;
		} else {
			return false;
		}
	} else {
		if (confirm(answer)){
			return answer;
		} else {
			return false;
		}			
	}
}); 
/* ------------------------------------------------------------------------------------------------------------- */	
	$("a[rel='gallery'], a[rel='thumbs'], a[rel='map']").colorbox({slideshow:true});
/* ------------------------------------------------------------------------------------------------------------- */	
		$('.btnChoose').click(function() {
			$(this).after('<div id="dialog"></div>');	
			var id_list_category = $('#id_category').val();
			var multiple = $('#id_category').attr('title');
			var onlyLeaf = $('#id_category').attr('alt');
			var isMain = $('#is_main').attr('name');
			var isMainVal = $('#is_main').val();																				
			if(isMain=='is_main'){														
				var url = this.href+'id_list_category='+id_list_category+'&multiple='+multiple+'&onlyLeaf='+onlyLeaf+'&isMain=1&isMainVal='+isMainVal;
			} else {
				var url = this.href+'id_list_category='+id_list_category+'&multiple='+multiple+'&onlyLeaf='+onlyLeaf;
			}
			var title = this.title;			  		
			$("#dialog").load(url, [], function(){
				$("#dialog").dialog("open");
			});
			$("#dialog").dialog({
				closeText: 'Zamknij',
				title: title,
				modal: true,
				bgiframe: true,
				autoOpen: true,
				height: 500,				
				minHeight: 300,
				maxHeight: 800,
				width: 980,
				minWidth: 980,
				draggable: true,
				resizeable: true,	
				zIndex: 200000,			
				buttons: { 
					"Zamknij": function() { 
						$(this).dialog("close");
						$('#dialog').remove();						 
					}
				}
			});
			return false;
		});	
/* ------------------------------------------------------------------------------------------------------------- */	
		$('.btnMap').click(function() {			
			$(this).after('<div id="dialog"></div>');	
			var url = this.href;
			var title = this.title;												  		
			$("#dialog").load(url, [], function(){
				$("#dialog").dialog("open");
			});
			$("#dialog").dialog({
				closeText: 'Zamknij',
				title: title,
				modal: true,
				bgiframe: true,
				autoOpen: true,
				height: 500,				
				minHeight: 300,
				maxHeight: 800,
				width: 980,
				minWidth: 980,
				draggable: true,
				resizeable: true,	
				zIndex: 200000,			
				buttons: { 
					"Zamknij": function() { 
						$(this).dialog("close");
						$('#dialog').remove();						 
					}
				}
			});
			return false;
		});	
/* ------------------------------------------------------------------------------------------------------------- */	
		$('.btnSearchProducer').click(function() {
			$(this).after('<div id="dialogSearchProducer"></div>');	
			var id_list_producer = $('#id_producer').val();
			var multiple = $('#id_producer').attr('title');			
			var url = this.href+'id_list_producer='+id_list_producer+'&multiple='+multiple;
			var title = this.title;			  		
			$("#dialogSearchProducer").load(url, [], function(){
				$("#dialogSearchProducer").dialog("open");
			});
			$("#dialogSearchProducer").dialog({
				closeText: 'Zamknij',
				title: title,
				modal: true,
				bgiframe: true,
				autoOpen: true,
				height: 500,				
				minHeight: 300,
				maxHeight: 800,
				width: 980,
				minWidth: 980,
				draggable: true,
				resizeable: true,	
				zIndex: 200000,	
				closeOnEscape: false,
				buttons: { 
					"Zamknij": function() { 
						$(this).dialog("close");
						$('#dialogSearchProducer').remove();						 
					}
				}
			});
			return false;
		});
/* ------------------------------------------------------------------------------------------------------------- */
	$('.GalListItemBuyBt a, .ProductDetailBuy a, .ShortListItemPromoBuyBt a, .ShortListItemBuyBt a, .SimProductsItem .Bt a, #NotificationBox .BtEdit a').click(function() {		
		var $action = $(this).attr("rev");		
		if ($action != '' &&  $action != ' ') { 
			$(this).parents("form").attr("action", $action).submit();
		}
	});
/* ------------------------------------------------------------------------------------------------------------- */
	$('.FilterBox .Ico img').click(function() {		
		var $listType = $(this).attr("rev");		
		if ($listType != '' &&  $listType != ' ') { 
			$('#list_type').val($listType);
			$(this).parents("form").submit();
		}
	});
/* ------------------------------------------------------------------------------------------------------------- */
$('.numberonly').keyup(function(e){
	if(e.which==13) return false;
	$(this).val(parseInt($(this).val()));
	if ($(this).val()=='NaN')
	    $(this).val(1);
	if ($(this).val()<1)
		$(this).val(1);
	$(this).val(c);
});
$('input.changeInputNumber').wrap('<div class="changeInputNumber"></div>').after('<div class="changeInputNumberPlus">+</div><div class="changeInputNumberMinus">-</div>');		
$('div.changeInputNumber .changeInputNumberPlus').click(function(){
	var $tmp = $(this).parent('.changeInputNumber').find('input').attr('value');
	$tmp = parseInt($tmp)+1;
	$(this).parent('.changeInputNumber').find('input').attr('value',$tmp);
	$(this).parents("form").submit();
});	
$('div.changeInputNumber .changeInputNumberMinus').click(function(){
	var $tmp = $(this).parent('.changeInputNumber').find('input').attr('value');
	if ($tmp>1) {
		$tmp = parseInt($tmp)-1;
		$(this).parent('.changeInputNumber').find('input').attr('value',$tmp);		
		$(this).parents("form").submit();
	}
});

$('input.changeInputNumber').click(function(){
	var $tmpValue = $(this).attr('value');
	$(this).blur(function(){									   
		var $tmpValueBlur = $(this).attr('value');
		if($tmpValue!=$tmpValueBlur){
			$(this).parents("form").submit();
		}
	});
});
/* ------------------------------------------------------------------------------------------------------------- */	
$('.btnSelectAll').click(function(){
	$(this).parent('form').find('input:checkbox').attr('checked', 'checked');
});		
$('.btnUncheckAll').click(function(){
	$(this).parent('form').find('input:checkbox').attr('checked', '');
});	
/* ------------------------------------------------------------------------------------------------------------- */
$('#widgetFacebook').mouseover(function(){
	$('#widgetFacebook').removeClass('widget_hide');
	$('#widgetFacebook').addClass('widget_show');						
});
$('#widgetFacebook').mouseout(function(){
	$('#widgetFacebook').removeClass('widget_show');
	$('#widgetFacebook').addClass('widget_hide');						
});
/* ------------------------------------------------------------------------------------------------------------- */
$('#widgetInterComp').mouseover(function(){
	$('#widgetInterComp').removeClass('widgetInterComp_hide');
	$('#widgetInterComp').addClass('widgetInterComp_show');						
});
$('#widgetInterComp').mouseout(function(){
	$('#widgetInterComp').removeClass('widgetInterComp_show');
	$('#widgetInterComp').addClass('widgetInterComp_hide');						
});
/* ------------------------------------------------------------------------------------------------------------- */
});


function printProduct(url){

    url   = "/print"+url;
	specs = "toolbar=no,directories=no,menubar=no,scrollbars=yes,width=700,height=700";
    open(url, "", specs);

}

function sendToPrinter(){
    
	$("#PrintButton").toggle();
	window.print();

}
