var deleteEvent = false;

$(function(){
    if(benutzer){
        loadAnzeigenTable($('#benutzer_bewerber_id').val());
    }
});

/*
    Load Anzeigen-List Table
 */
function loadAnzeigenTable(id){
    $.ajax({
        type: "POST",
        url:  contextPath + "/bewerber/ajax/benachrichtigungsprofile-list?bewerberId=" + id,
        success: function(html){
            $("#container-benachrichtigungsprofile-list-table").html(html);
        },
        error: function(){
        }
    });
}

/*
    get Anzeige-Detail
 */
function getAnzeigeDetail(benachrichtigungsprofilId, systemStatus){

    /***
    if(!deleteEvent ){
        window.location.href = contextPath + "/bewerber/benachrichtigungsprofil!show?benachrichtigungsprofilId=" + id;
    } else {
        deleteEvent = false;
    }
    ***/

    bewerberId = $('#benutzer_bewerber_id').val();
    if(!deleteEvent ){
		if(systemStatus == 'development'){
			targetUrl =  contextPath + "/bewerber/benachrichtigungsprofil!show?benachrichtigungsprofilId=" + benachrichtigungsprofilId + "&bewerberId=" + bewerberId;
		} else {
			targetUrl = $.webapp_bridge_URL("http://app.dlg.org:8081" + contextPath + "/bewerber/benachrichtigungsprofil!show?benachrichtigungsprofilId=" + benachrichtigungsprofilId + "&bewerberId=" + bewerberId);
		}
        window.location.href = targetUrl;
    } else {
        deleteEvent = false;
    }

}


/*
   Delete benachrichtigungsprofil
*/
function deleteIt(benachrichtigungsprofilId, systemStatus){

    deleteEvent = true;
    bewerberId = $('#benutzer_bewerber_id').val();
    var answer = confirm(confirmMessage);
    if (answer){
		if(systemStatus == 'development'){
			targetUrl =  contextPath + "/bewerber/benutzer!deleteBenachrichtigungsprofil?benachrichtigungsprofilId=" + benachrichtigungsprofilId + "&bewerberId=" + bewerberId;
		} else {
			targetUrl = $.webapp_bridge_URL("http://app.dlg.org:8081" + contextPath + "/bewerber/benutzer!deleteBenachrichtigungsprofil?benachrichtigungsprofilId=" + benachrichtigungsprofilId + "&bewerberId=" + bewerberId);
		}
        window.location.href = targetUrl;
    }

}

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