function setAlarm_lay2011(C, D) {
	$("#alkom" + C).hide();
	if (D != "") {
    	$.getJSON("/sfx/ajaxaction.php?act=6&compid=" + C + "&price=" + D,function(json){
    		$("#alkom" + C).html('<strong>Alarm został ustawiony</strong>').show().animate({borderWidth: 0},1700,"linear",function(){
            	if(json.status == 1){
            		if($("#row"+C).length > 0){
            			$("#row"+C+" div.soffer").append("<div id=\"alm"+C+"\" class=\"userCurrentAlarm\">Twój alarm wynosi: <b id=\"alm"+C+"price\">"+json.price+" PLN</b></div>");
            			switch(json.valid){
            			case 1: $("#row"+C).addClass("green"); break;
            			case 0: $("#row"+C).removeClass("green"); break;
            			}
            		} else if($("#product_summary").length > 0){
            			$("#product_new_rank p").append("<span id=\"alm"+C+"\"><br/>Twój alarm wynosi: <em id=\"alm"+C+"price\">"+json.price+"</em></span>");
            		}
            		$(this).html('<a class="act31_lay2011" onclick="deleteAlarm_lay2011('+C+', \'\');" href="javascript://">Usuń alarm cenowy</a><a class="act32_lay2011" onclick="changeAlarm_lay2011('+C+', \'\','+json.price+');" href="javascript://">Zmień alarm cenowy</a>');
            		$("#favkom"+C).html("<a id=\"remove_from_set_148124\" class=\"act41_lay2011\" onclick=\"delFav_lay2011("+C+")\" href=\"javascript://\">Usuń z ulubionych</a>");
            		$("#alm"+C+"price").text(json.price+" PLN");
            		$("#alm"+C).show();
            	} else { $(this).html('<a class="act3_lay2011" onclick="setAlarm_lay2011('+C+',\'\')" href="javascript://">Ustaw alarm cenowy</a>'); }
        	});
           $("#kom"+C).height('18px');
    	});
    } else {
    	$("#alkom" + C).html("<input class=\"addPriceAlarmFix\" type=\"text\" size=\"12\" value=\"Wpisz cenę\" onfocus=\"if(this.value=='Wpisz cenę') this.value=''\"  id=\"tx" + C + '" name="opisbledu"/><input type="button" style="margin-left:4px" class="send_min" onclick="setAlarm_lay2011(' + C + ", document.getElementById('" + ("tx" + C) + '\').value);"/>');
    }
	$("#alkom" + C).show();
}
function deleteAlarm_lay2011(B) {
    if(stype == 1 || stype == 2){
    	var check = confirm("Czy na pewno usunać alarm dla produktu ?");
    	if(!check) return false;
    }
	$.getJSON("/sfx/ajaxaction.php?act=7&compid=" + B,function(json){
        if(json.status == 1) {
        $("#alkom" + B).html('<strong>Alarm został usunięty</strong>');
        } else { $("#alkom" + B).html('<strong>Przepraszamy - wystąpił błąd</strong>'); }
        if(stype == 2) {
        	$("#row" + B).remove();
        	if($(".p_row").length == 0) { location.reload(); }
        }
        else {
	        $("#alkom" + B).animate({opacity: 1},1700,"linear",function(){
	        	$(this).html('<a class="act3_lay2011" onclick="setAlarm_lay2011('+B+',\'\')" href="javascript://">Ustaw alarm cenowy</a>');
	    		$("#alm"+B).remove();
	    		if($("#row"+B).length > 0) { $("#row"+B).removeClass("green"); }
	        });
        }
    });
    
	if (window.location.href.match('/site/doc/19'))
	{
		window.location.reload(true);
	}
}

function changeAlarm_lay2011(C, D, P) {
	$("#alkom" + C).hide();
	if (D != "") {
        $.getJSON("/sfx/ajaxaction.php?act=8&compid=" + C + "&price=" + D,function(json){
        	if(json.status == 1) $("#alkom" + C).html('<strong>Alarm został zmieniony</strong>');
        	else $("#alkom" + C).html('<strong>Alarm nie został zmieniony</strong>');
        	$("#alkom" + C).animate({borderWidth: 0},1700,"linear",function(){
        		if($("#row"+C).length > 0){
        			switch(json.valid){
        			case 1: $("#row"+C).addClass("green"); break;
        			case 0: $("#row"+C).removeClass("green"); break;
        			}
        		} 
        		$("#alm"+C+"price").text(json.price+" PLN");
        		$(this).html('<a class="act31_lay2011" onclick="deleteAlarm_lay2011('+C+', \'\');" href="javascript://">Usuń alarm cenowy</a><a class="act32_lay2011" onclick="changeAlarm_lay2011('+C+', \'\','+json.price+');" href="javascript://">Zmień alarm cenowy</a>');
        	});
        	$("#kom"+C).height('18px');
            });
    } else {
        $("#alkom" + C).html("<input class=\"addPriceAlarmFix\" type=\"text\" value=\"" + P + "\" id=\"tx" + C + '" name="opisbledu"/><input type="button" class="send_min" onclick="changeAlarm_lay2011(' + C + ", document.getElementById('" + ("tx" + C) + '\').value);">');
    }
	$("#alkom" + C).show();
}

function addFav_lay2011(B, reloadAfter) {
	$.get("/sfx/ajaxaction.php?act=9&compid=" + B, function(){
		$("#favkom" + B).html('<a id="remove_from_set_'+B+'" class="act41_lay2011" onclick="delFav_lay2011('+B+')" href="javascript://">Usuń z ulubionych</a>');
		$("div#bfav" + B).replaceWith('<div id="bfav'+B+'" class="boxButtonUnfav" onclick="delFav_lay2011('+B+')" title="Usuń z ulubionych"></div>');    		
		if(reloadAfter == true){
			window.location.reload();
		}
	});
}
function delFav_lay2011(B) {
	if(stype == 1 || stype == 2){
    	var check = confirm("Czy na pewno usunać produkt z ulubionych ?");
    	if(!check) { return false; }
    }
	$.get("/sfx/ajaxaction.php?act=10&compid=" + B, function(){
		$("#favkom" + B).html('<a id="add_to_set_'+B+';" class="act4_lay2011" onclick="addFav_lay2011('+B+')" href="javascript://">Dodaj do ulubionych</a>');
        $("div#bfav" + B).replaceWith('<div id="bfav'+B+'" class="boxButtonFav" onclick="addFav_lay2011('+B+')" title="Dodaj do ulubionych"></div>');
        $("#alkom"+B).html("<a class=\"act3_lay2011\" href=\"javascript://\" onclick=\"setAlarm_lay2011("+B+",'')\">Ustaw alarm cenowy</a>");
        if($("#alm"+B).length > 0) { $("#alm"+B).remove(); }
        if($("#row"+B).length > 0) { $("#row"+B).removeClass("green"); }
        if(stype == 1 || stype == 2){
        	$("#row" + B).remove();
        	if($(".p_row").length == 0) location.reload();
        }
        
    	if ((window.location.href.match('/site/doc/19')) || (window.location.href.match('/site/doc/18')))
    	{
    		window.location.reload(true);
    	}
	});
}

function desc_new_toggle_lay2011(){
	switch($('.product_params_expand').text()){
	case 'rozwiń':
		$('#product_new_description table tr:gt(2):not(:last)').show();
		$('.product_params_expand').text('zwiń').css({'background-position':'0 -315px'}); break;
	case 'zwiń': 
		$('#product_new_description table tr:gt(2):not(:last)').hide();
		$('.product_params_expand').text('rozwiń').css({'background-position':'0 -298px'}); break;
	}
}

function componentOffersSort_lay2011(){
	
	var city = parseInt($("#cityID option:selected").attr('city'));
	if(city != 0) { $("h2[name=main]").html("Lista sklepów: <span>"+$("#cityID option:selected").val()+"</span>");
	} else $("h2[name=main]").html("Lista sklepów: ");
	if($("table#offerList tbody tr:not(.spacer)").length == 1) { return false; }

	var comp = parseInt($("table#offerList").attr('comp'));
	var delType = $("#cityID option:selected").attr('t');
	var sort = $("table#offerList").attr('sort');
	var ord = $("table#offerList").attr('ord');
	var book = $("#select_city").attr('book');
	
	$("table#offerList tbody").hide();
	$("table#offerList tr.spacer").remove();
	$.getJSON("/inc/component_ajax2.php?comp="+comp+"&sort="+sort+"&sord="+ord+"&book="+book+"&city="+city+"&del="+delType,function(data){
		$("tr#rowAd").remove();
		if(city == 0){
			$("tbody#lpsb").remove();
			$("tbody#lps").remove();
		}
		$.each(data,function(pos,id){
			if(city != 0 && ((delType == 'c' && id['c'] == 0) || (delType == 'r' && id['r'] == 0))){
				city = 0;
				$("table#offerList tbody#lpsb").remove();
				var selectOpt = $("#cityID option:selected").text().toUpperCase();
				$("table#offerList tbody:first").before('<tbody id="lpsb"><tr><td style="background: #FECD63; border-top: 1px solid #F3AA0D; border-bottom: 1px solid #F3AA0D;" colspan="5"><h2>'+selectOpt+'</h2></td></tr></tbody>');
				$("table#offerList tbody#lps").remove();
				$("table#offerList tbody:last").after('<tbody id="lps"><tr><td style="background: #E3EDF8; border-top: 1px solid #C1D8E4; border-bottom: 1px solid #C1D8E4;" colspan="5"><h2>LISTA POZOSTAŁYCH SKLEPÓW</h2></td></tr></tbody>');
			}
			$("table#offerList tbody#ofgroup_"+id['tbid']).appendTo("table#offerList");
		});
		updateLinks();
		$("table#offerList tbody").show();
	});
	
}

function errorParam_lay2011(F, G, E, H) {
	if(E !== ""){
		$.get("/sfx/ajaxaction.php?act=1&oferta=" + F + "&ip=" + G + "&tekst=" + E + "&typ=2&category_id=" + H, 
				function() { document.getElementById("err_cmp"+F).innerHTML = "&nbsp;Dziękujemy za zgłoszenie błędu"; });
	}
	else{
		var obj = document.getElementById("err_cmp"+F);
		obj.innerHTML =
			"<textarea onclick='if(this.value==\"gdzie jest błąd?\" || this.value==\"Pole nie może być puste\"){this.value=\"\"}' cols='45' rows='2' id=\"tx_cmp" + F + "\" name=\"opisbledu\" style=\"FONT-WEIGHT: normal; font-size: 10px; width:120px;\">gdzie jest błąd?</textarea><br><span class=\"hand\" style=\"padding-left: 50px;\" onclick=\"var tx=document.getElementById('tx_cmp"+F+"').value; if(tx && tx != 'gdzie jest błąd?' && tx != 'Pole nie może być puste') { tx = 'W OPISIE PRODUKTU: '+tx ;errorParam(" + F + ",'" + G + "',tx,'"+ H +"') } else { $(this).prev().prev().val('Pole nie może być puste'); } \" title=\"Wyślij\">Wyślij</span>";
		$.get("/inc/ajax_usage_counter.php?seg=106");
	}
}


$(document).ready(function() {
	$("ul.menu_lay2011 li.active").prev().children().css('border-right', 'none');
});
