function clearStatusMsg(id,cssklasse) {
    (function($) {
        if($('#'+id).html() != "") {
            $('#'+id).slideUp("slow");
            $('#'+id).html('');
            $('#'+id).removeClass(cssklasse);
    }
    })(jQuery);
}


function AddStatusMsg(id, text, cssklasse, ausblendentimeout) {
    (function($) {
        if($('#'+id)) {
            $('#'+id).removeClass();
            $('#'+id).addClass(cssklasse);
            $('#'+id).html(text).slideDown("slow");
            clearInterval(timer[id]);
            timer[id] = setTimeout( function() { clearStatusMsg( id , cssklasse ) } , ausblendentimeout );
        }
    })(jQuery);
}


function openPopWin(winURL, winWidth, winHeight, winFeatures, winLeft, winTop){
    var winCount = 0
    var winName = "popWin"


    var d_winLeft = 20
    var d_winTop = 20
    winName = "popWin" + winCount++
    closePopWin()
    if (openPopWin.arguments.length >= 4)
    winFeatures = "," + winFeatures
    else
    winFeatures = ""
    if (openPopWin.arguments.length == 6)
    winFeatures += getLocation(winWidth, winHeight, winLeft, winTop)
    else
    winFeatures += getLocation(winWidth, winHeight, d_winLeft, d_winTop)
    popWin = window.open(winURL, winName, "width=" + winWidth
       + ",height=" + winHeight + winFeatures)
}

function closePopWin(){
    var popWin = null
      if (navigator.appName != "Microsoft Internet Explorer"
          || parseInt(navigator.appVersion) >=4)
        if(popWin != null) if(!popWin.closed) popWin.close()
}

function getLocation(winWidth, winHeight, winLeft, winTop){
    return ""
}

function urlencode(s) {
    s = encodeURIComponent(s);
    return s.replace(/~/g,'%7E').replace(/%20/g,'+');
}

this.preview = function(){
    /* CONFIG */
        
        xOffset = 10;
        yOffset = 30;
        
        // these 2 variable determine popup's distance from the cursor
        // you might want to adjust to get the right result
        
    /* END CONFIG */
   $(".preview").hover(function(e){
        this.t = this.title;
        this.title = "";    
        var c = (this.t != "") ? "<br/>" + this.t : "";
        $("body").append("<p id='preview'><img src='"+ this.rel +"' alt='url preview' />"+ c +"</p>");                                
        $("#preview")
            .css("top",(e.pageY - xOffset) + "px")
            .css("left",(e.pageX + yOffset) + "px")
            .fadeIn("fast");                        
    },
    function(){
        this.title = this.t;    
        $("#preview").remove();
    }); 
    $(".preview").mousemove(function(e){
        $("#preview")
            .css("top",(e.pageY - xOffset) + "px")
            .css("left",(e.pageX + yOffset) + "px");
    });         
};

function auswahl_sponsor(objekt_id,session_id) {
    $(function(){
        $("select#auswahl_sponsor").change(function(){
            if (this.value != '00') {
                fields_value = 'aktion=sponsor_zuordnung_hinzufuegen';
                fields_value += '&sponsor_logos_id=' + this.value;
                fields_value += '&objekt_id=' + objekt_id;
                fields_value += '&PHPSESSID=' + session_id;

                $.ajax({
                    type: "POST",
                    url: "/save.php",
                    data: fields_value,

                    success: function(xmlmessage) {
                        $("meldung",xmlmessage).each(function(id) {
                            meldung = $("meldung",xmlmessage).get(id);
                            ausgabetext = $("ausgabetext",meldung).text();
                            ausgabetyp = $("ausgabetyp",meldung).text();
                            feldinhalt = $("feldinhalt",meldung).text();
                            html = $("html",meldung).text();
                        });
                        if (ausgabetyp == 'success') {
                            $("#sponsoren").html('');
                            $("#sponsoren").html(html);

                            $('#auswahl_sponsor').val('00');
                            //AddStatusMsg('status_template_pfade', ausgabetext, 'status_meldungen_erfolg','10000');
                            //auswahl_template_pfade();
                        }
                    }
                });
                //$("#debug").show();
                //$("#debug").html("ID: " + this.value + "<br/>" + "Title: " + this.options[this.selectedIndex].text);
            }
        })
    })
}
function sponsor_logos_zuweisungen_loeschen(sponsor_zuordnung_objekte_id,objekt_id,session_id) {
    fields_value = 'aktion=sponsor_logos_zuweisungen_loeschen';
    fields_value += '&sponsor_zuordnung_objekte_id=' + sponsor_zuordnung_objekte_id;
    fields_value += '&PHPSESSID=' + session_id;
    fields_value += '&objekt_id=' + objekt_id;

    $.ajax({ 
        type: "POST", 
        url: "/save.php",
        data: fields_value,
        
        success: function(xmlmessage) {
            $("meldung",xmlmessage).each(function(id) {
                meldung = $("meldung",xmlmessage).get(id);
                ausgabetext = $("ausgabetext",meldung).text();
                ausgabetyp = $("ausgabetyp",meldung).text();
                feldinhalt = $("feldinhalt",meldung).text();
                html = $("html",meldung).text();
            });
            if (ausgabetyp == 'success') {
                $("#sponsoren").html('');
                $("#sponsoren").html(html);

                $('#auswahl_sponsor').val('00');
                //AddStatusMsg('status_template_pfade', ausgabetext, 'status_meldungen_erfolg','10000');
                //auswahl_template_pfade();
            }
        }
    });
}


