function displayWindow(url, width, height) {
    var Win = window.open (url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=yes, menubar=no' );
}

function okienko(url,width,height,sb,top,left){ 
	window.open(url,'okienko','align=center,location=0,toolbar=0,status=0,location=0,directories=0,resizable=0,scrollbars='+sb+',width='+width+',height='+height+',top='+top+',left='+left+',menubar=no')
}

function okienko1(url,width,height,sb,top,left){ 
	window.open(url,'okienko1','align=center,location=0,toolbar=0,status=0,location=0,directories=0,resizable=0,scrollbars=yes,width='+width+',height='+height+',top='+top+',left='+left+',menubar=no') 
}

function zmienOpakowanie() {
	if (document.platnosci.opakowanie.checked == true) {
		document.platnosci.dedykacja.disabled = false;
	}
	else {
		document.platnosci.dedykacja.disabled = true;
	}
}

function lista(w, x, l){
	if (document.getElementById("lista1").value > 0) {

		obj = document.getElementById("submit");
		obj.style.display = "block";

		obj2 = document.getElementById("submitDisabled");
		obj2.style.display = "none";

	}
	else {

		obj = document.getElementById("submit");
		obj.style.display = "none";

		obj2 = document.getElementById("submitDisabled");
		obj2.style.display = "block";

	}

	var lista = document.getElementById(x);

	for (var i = 0, dl = lista.options.length; i < dl; i++) {
		lista.options[0] = null;
	}

	var el = eval(l); el = el[w.options[w.options.selectedIndex].value];

	for (i = 0; i < el.length; i++) {
		lista.options[i] = new Option(el[i][1], el[i][0]);
	}
}

function koszyk(w, x, l){
	if (document.getElementById("koszykRozmiary").value > 0) {
		obj = document.getElementById("koszykSubmit");
		obj.style.display = "";

		obj2 = document.getElementById("koszykSubmitDisabled");
		obj2.style.display = "none";

	}
	else {
		obj = document.getElementById("koszykSubmit");
		obj.style.display = "none";

		obj2 = document.getElementById("koszykSubmitDisabled");
		obj2.style.display = "";

	}

	var lista = document.getElementById(x);

	for(var i = 0, dl = lista.options.length; i < dl; i++) {
		lista.options[i]=null;
	}

	var el = eval(l); 
	el = el[w.options[w.options.selectedIndex].value];

	for(i = 0; i < el.length; i++) {
		if (!el[i])
		{
			
		}
		else
			lista.options[i] = new Option(el[i][1],el[i][0]);
	}

	$("select").friendlyDropDown();

}

function pasujaceKoszyk(w,x,l) {
	var lista=document.getElementById(x);

	for(var i=0, dl=lista.options.length;i<dl;i++){
		lista.options[0]=null;
	}

	var el=eval(l); el=el[w.options[w.options.selectedIndex].value];

	for(i=0;i<el.length;i++){
		lista.options[i] = new Option(el[i][1],el[i][0]);
	}

	if(arguments[3]){
		var lista=document.getElementById('lista3');

		for(var i=0, dl=lista.options.length;i<dl;i++){
			lista.options[0]=null;
			lista.options[0]=new Option("-",0);
		}
	}
	$("select").friendlyDropDown();
}



function zaznacz(id) {
    document.getElementById(id).focus();
    document.getElementById(id).select();
}


// dodatkowe zdjecia
function changeimage(towhat, url) {
	if (document.images){
		document.images.targetimage.src=towhat.src
		gotolink = url
	}
}

var myimages = new Array()
var gotolink = "#"

function preloadimages() {
	for (i = 0; i < preloadimages.arguments.length; i++) {
		myimages[i] = new Image()
		myimages[i].src = preloadimages.arguments[i]
	}
}




$(document).ready(function(){
	
	
	$("#kloc").click(function () {
	    $('#kloc').stop().animate({
	        top: "-225"
	    }, 500);
	});

	var klik = 0;

	//podmiana duzej fotki
	$(".more_foto").click(function () {
	    klik = 1;
	    $('#more').stop().animate({
	        top: "0"
	    }, 500, function () {
	        klik = 0;
	    });

	    var male = $(this).attr('src');
	    var duze = male.slice(0, (male.length - 6)) + "_d." + male.slice((male.length - 3), male.length);

	    $('#foto_duze').attr('src', duze);
	});

	$("#more").mouseenter(function () {
	    $('#more').stop().animate({
	        top: "-225"
	    }, 500, function () {
	        klik = 0;
	    });
	});

	$("#more_img").click(function () {
	    $('#more').stop().animate({
	        top: "-225"
	    }, 500, function () {
	        klik = 0;
	    });
	});


	$("#more").mouseleave(function () {
	    if (klik == 0) {
	        $('#more').stop().animate({
	            top: "0"
	        }, 500);
	    }
	});

	var ile_fot = $('.more_foto').length;
	var ktora = 2;
	if (ile_fot < 3) {
	    $("#prawo_more").css("display", "none");
	}

	//sprawdza czy moze isc w prawo
	$("#prawo_more").click(function () {
	    if (ktora < ile_fot) {
	        $('#pole_ruch').animate({
	            left: "-=152"
	        }, 500);
	        ktora++;

	        //ukrywanie przyciskow
	        $("#lewo_more").css("display", "block");
	        if (ktora == ile_fot) {
	            $("#prawo_more").css("display", "none");
	        }
	    }
	});

	$("#lewo_more").click(function () {
	    if (ktora > 2) {
	        $('#pole_ruch').animate({
	            left: "+=152"
	        }, 500);
	        ktora--;

	        $("#prawo_more").css("display", "block");
	        if (ktora == 2) {
	            $("#lewo_more").css("display", "none");
	        }
	    }
	});
	
	
	/*
	 * DYMKI
	 */
    $('.producent a').leviTip({
    	sourceType: 'attribute',
    	source: 'rel',
    	addClass: 'prosty-tool-3',
    	hideSourceElement: true
    });

    $('.zaznaczony, #koszykSubmitDisabled, .usunfiltr').leviTip({
    	sourceType: 'attribute',
    	source: 'rel',
    	addClass: 'prosty-tool-2',
    	hideSourceElement: true
    });

    $('.gwarancje, .info').leviTip({
    	sourceType: 'attribute',
    	source: 'rel',
    	addClass: 'prosty-tool',
    	hideSourceElement: true
    });

    $('.rozmiary_dostepnosci').leviTip({
    	sourceType: 'element',
    	source: '#dostepnoscInfo',
    	addClass: 'prosty-tool',
    	hideSourceElement: true
    });

    $('.rozmiary_tabela').leviTip({
    	sourceType: 'element',
    	source: '#rozmiaryInfo',
    	addClass: 'prosty-tool-5',
    	hideSourceElement: true
    });
    

		
	$("select").friendlyDropDown();

	
    
	if (js_platnosci) {

		$("#submit").attr("disabled", true).attr("src", "/_szablony_/rosme/img/podsumowanie_dis.png");;

		sprawdz_czy_wybrano = function () {

		    $("div.sposob_dostawy input").each(function() {
		    	if ($(this).attr("checked")) {
		            $("div.platnosci").not("#platnosc" + $(this).attr("id")).hide;
		            $("#platnosc" + $(this).attr("id")).show();
		        }
		    });
		    
		    $("div.platnosci input").each(function() {
		    	if ($(this).is(":checked")) {
		    		$("#sans_registration_button").attr('disabled', '');
		    	}
		    });

		}

		dostawa_zmiana = function (kto) {

		    //bloku submit
		    $("#submit").attr("disabled", true).attr("src", "/_szablony_/rosme/img/podsumowanie_dis.png");;

		    //chowa wszystkie metody platnosci (divy) a pokazuje tylko dla zaznaczonego
		    $("div.platnosci").css({
		        "display": "none"
		    });
		    $("#sp_platnosc" + kto).css({
		        "display": "block"
		    });
		    //odznacza wszystkie radiony platnosci
		    $("div.platnosci input").attr("checked", false);
	        //jezeli za pobraniem to chowa "wybierz sposob platnosci" i zaznacza platnosc przy odbiorze oraz atktywuje submita
	        if(kto=="1"||kto=="3"||kto=="8"||kto=="9"||kto=="14"||kto=="15"){
	           $("#sposob_platnosci").hide();  
	           $("#sp_platnosc"+kto+" input:first").attr("checked",true);
	           //$("#submit").attr("disabled",false).attr("src","/_szablony_/public/img/dalej_krok2.png");
	           sprawdz_czy_wybrano();
	        } else {
	           $("#sposob_platnosci").css({"display":"block"}); 
	        }

		};

		platnosc_zmiana = function (kto) {
		    //odznacza wszystkie radiony a zaznacza tylko klikniety
		    $("div.platnosci input").attr("checked", false);
		    $("#" + kto).attr("checked", true);

		    //odblokowuje submit
		    $("#submit").attr("disabled", false).attr("src", "/_szablony_/rosme/img/podsumowanie.png");
			sprawdz_czy_wybrano();

		};

		sprawdz_czy_wybrano();

		$('#adresy_lista input').click(function () {
			$('#adresy_lista li').removeClass('activ');
			$(this).parents('#adresy_lista li').addClass('activ');
		    $('#adresy_wartosc > div').hide();
		    $('#adres' + $(this).attr('value')).show();
		});	
		
		//jQuery UI init
		$(".datepicker").datepicker({ minDate : new Date()});
		//$("input:submit, button").button();
	}
});
