/*
    Globals
 */
var serializedForm;

/*
    Load Betaetigungsfelder
 */
function showHideBetaetigungsfelder(brancheId){
    if($("input[name=cb_branche_" + brancheId + "]").attr('checked')){
        $.ajax({
            type: "POST",
            url:  contextPath + "/oeffentlich/ajax/betaetigungsfelder-list?brancheId=" + brancheId,
            success: function(html){
                $(".suchmaske-betaetigungsfelder-" + brancheId).replaceWith(html);
                $(".suchmaske-betaetigungsfelder-" + brancheId).css({"display":"block"});
                getResults();
            },
            error: function(){
            }
        });
    } else {
        $(".suchmaske-betaetigungsfelder-" + brancheId).replaceWith("<ul class=\"suchmaske-betaetigungsfelder-" + brancheId + "\" style=\"display: none;\"></ul>");
        getResults();
    }

}

/*
    Load Ergebnisliste
 */
function getResults(){
    serializedForm = $("#suchmaske").serialize();
    $.ajax({
        type: "POST",
        url:  contextPath + "/oeffentlich/ajax/anzeigen-list!listByBranchen?" + serializedForm,
        success: function(html){
            $(".div-suchmaske-ergebnis-list").html(html);
        },
        error: function(){
            alert("ERROR");
        }
    });
}

/*
    get Anzeige-Detail
 */
function getAnzeigeDetail(anzeigeId, systemStatus){
	if(systemStatus == 'development'){
		targetUrl =  contextPath + "/oeffentlich/anzeige?anzeigeId=" + anzeigeId;
	} else {
		targetUrl = $.webapp_bridge_URL("http://app.dlg.org:8081" + contextPath + "/oeffentlich/anzeige?anzeigeId=" + anzeigeId);
	}
	window.location.href = targetUrl;
}

/*
    jMesa Ajax-Requests
*/
function onInvokeAction(id) {
    setExportToLimit(id, '');
    var parameterString = createParameterStringForLimit(id) + "?" + serializedForm;
    $.get(contextPath + '/oeffentlich/ajax/anzeigen-list!listByBranchen?ajax=true&' + parameterString, function(data) {
        $("#results").html(data);
    });
}

