function userinfo(uid,session) {
	var msg = window.open("/forum/popups/userpopup.html?moduleUserinfo-uid="+uid+session,"msg","height=520,width=500,left=80,top=80");
}

function printpage(tid,seite,sortorder) {
    var printpage = window.open("/forum/popups/printpage.html?bwthreadid="+tid+"&modulePostingList-page="+seite+"&bwsortorder="+sortorder,"printpage","height=600,width=644,left=80,top=80,scrollbars=yes");
}

function printmessage(mid) {
    var printmessage = window.open("/forum/popups/printposting.html?bwpostingid="+mid,"printmessage","height=300,width=628,left=80,top=80,scrollbars=yes");
}

function useronline(session) {
    var msg = window.open("/forum/popups/usersonline.html"+session,"msg","height=520,width=500,left=80,top=80,scrollbars=yes,resizable=no");
}

function dosubmit( type, action ) {
    if( type == "save" ) {
        document.forms["posting"].elements["bwaction"].value = action;
        document.posting.submit();
    } else if( type == "preview" ) {
        document.forms["posting"].elements["bwaction"].value = "postingpreview";
        document.posting.submit();
    }
}

function Go(x) {
    if(x == 0) {
        return false;
    } else if(x == -1) {
        location.href = "index.html";
    } else {
        document.location.href = "forum.html?bwboardid="+x+"&bwpage=1";
    }
}

function editsubmit( type ) {
    if( type == "save" ) {
        document.forms["edit"].elements["bwaction"].value = "changeposting";
        document.edit.submit();
    } else if( type == "preview" ) {
        document.forms["edit"].elements["bwaction"].value = "editposting";
        document.edit.submit();
    }
}

function triggerHidden( posting ) {
    newstyle = posting.nextSibling.style.display == "none" ? "block" : "none";
    posting.nextSibling.style.display = newstyle;
}

function insertText(aTag, eTag) {
    var input = document.getElementById("bodytext");
    input.focus();

    if( !eTag ) {
        eTag='';
    }

    if( document.selection ) {
        /* IE */
        var range = document.selection.createRange();
        var insText = range.text;
        range.text = aTag + insText + eTag;

        range = document.selection.createRange();
        if( insText.length == 0 ) {
            range.move('character', -eTag.length);
        } else {
            range.moveStart('character', aTag.length + insText.length + eTag.length);
        }
    } else if(typeof input.selectionStart != 'undefined') {
        /* Firefox */
        var start = input.selectionStart;
        var end = input.selectionEnd;
        var insText = input.value.substring(start, end);
        input.value = input.value.substr(0, start) + aTag + insText + eTag + input.value.substr(end);

        var pos = start + aTag.length + eTag.length;
        if (insText.length > 0) {
            pos += insText.length;
        }
        input.selectionStart = pos;
        input.selectionEnd = pos;
    } else {
        var pos = input.value.length;
        var insText = prompt("Bitte geben Sie den zu formatierenden Text ein:");
        input.value = input.value.substr(0, pos) + aTag + insText + eTag + input.value.substr(pos);
    }
}

function inserturl() {
    url = prompt('(1/2) URL','http://');
    if (url == '' || url == null) {
        return false;
    }
    linktext = prompt('(2/2) Linktext','');
    if( linktext == null ) {
        return false;
    }
    if (linktext == '') {
        linktext = url;
    }
    var reg = new RegExp("([a-zA-Z]+://)");
    if( !reg.test(url) ) {
        url = "http://" + url;
    }
    insertText( '[@link ' + url + ']' + linktext + '[/link]' );
}

function insertimage() {
    url = prompt('URL des Bildes','http://');
    if (url == '' || url == null) {
        return false;
    }
    insertText( '[@img ' + url + ']' );
}

function encloseInTag( tag ) {
    insertText( '['+tag+']', '[/'+tag+']' );
}

function disablePosting( postingid, threadid, sessid ) {
    if( confirm("Beitrag wirklich entfernen?") ) {
        document.location.href = "/forum/topic.asp?bwaction=disableposting&bwpostingid="+postingid+"&bwthreadid="+threadid+"&"+sessid;
    }
}

function disableThread( threadid, sessid ) {
    if( confirm("Thema wirklich entfernen?") ) {
        document.location.href = "/forum/topic.asp?bwaction=lockthread&bwthreadid="+threadid+"&"+sessid;
    }
}

function colorize() {
    var elColor = document.getElementById("textcolor");
    if( elColor.selectedIndex > 0 ) {
        encloseInTag( elColor.options[elColor.selectedIndex].value );
    }
    elColor.selectedIndex = 0;
}

function confirmAction( msg, targeturl ) {
    if( confirm( msg ) ) {
        document.location.href = targeturl;
    }
}

function confirmFormAction( msg, form ) {
    if( confirm( msg ) ) {
        form.submit();
    }
}

function changeFormAction( formid, newaction ) {
    el = document.getElementById(formid).elements;
    for( i=0 ; i<el.length ; i++ ) {
        if( el.item(i).name == "cva[action]" ) {
            el.item(i).value = newaction;
            return true;
        }
    }
    return false;
}

function setNotification( thread_id, object_type, object_id, state, url, title ) {
    if( thread_id > 0 ) {
        calldata = { module: "forum", action: "threadnotification", thread_id: thread_id, state: state, url: url, title: title };
    } else {
        calldata = { module: "forum", action: "threadnotification", object_type: object_type, object_id: object_id, state: state, url: url, title: title };
    }
    $.ajax({
        url: '/ajax.php',
        type: 'GET',
        data: calldata,
        dataType: 'json',
        timeout: 1000,
        error: function(){
            $('#notifyresult').html( '<span style="color:red">Serverfehlerx!</span>' );
        },
        success: function(json){
            if( json.success ) {
                $('#notifyresult').html( '<span style="color:green">'+json.success+'</span>' );
            } else {
                $('#notifyresult').html( '<span style="color:red">'+json.error+'</span>' );
            }
        }
    });
}

function setObjectNotification( object_type, object_id, state, url, title ) {
    setNotification( 0, object_type, object_id, state, url, title );
}

function setThreadNotification( thread_id, state, url, title ) {
    setNotification( thread_id, 0, 0, state, url, title );
}

function togglePrivateMsgText( id, mark_as_read ) {
    if( $('#msgtext_'+id).is(':hidden') ) {
        $('#msgtext_'+id).fadeIn('slow');
        if( mark_as_read && ($('#msgstatus_'+id).html() == 'neu') ) {
            $.get( '/ajax.php',
                    {module: 'messaging', action: 'markpmread', msg_id: id},
                    function(data) { $('#msgstatus_'+id).html(data) } );
        }
    } else {
        $('#msgtext_'+id).fadeOut('slow');
    }
}

function toggleMsgText( id ) {
    if( $('#msgtext_'+id).is(':hidden') ) {
        $('#msgtext_'+id).fadeIn('slow');
    } else {
        $('#msgtext_'+id).fadeOut('slow');
    }
}

var blink_counter = 6;
var blink_old_color;

function blinkMsg() {
    $('#sysmessagetext').fadeOut().fadeIn().fadeOut().fadeIn();
}

function CVRating( rating_value ) {
    this.rating = Math.floor(rating_value);
    this.messages = [ "wuerg!", "mies", "durchschnitt", "nicht schlecht", "super!" ];

    function clearStar( index ) {
        $("#star"+index).removeClass("rating_star_full").addClass("rating_star_empty");
    }
    function fillStar( index ) {
        $("#star"+index).removeClass("rating_star_empty").addClass("rating_star_full");
    }
    function hoverStar( index ) {
        for( var i=1 ; i<=5 ; i++ ) {
            (i <= index) ? fillStar(i) : clearStar(i);
        }
        $('#ratingmsg').text( this.messages[index-1] );
    }
    function resetRating() {
        for( var i=1 ; i<=5 ; i++ ) {
            (i <= this.rating) ? fillStar(i) : clearStar(i);
        }
        if( this.rating > 0 ) {
            $('#ratingmsg').text( this.messages[this.rating-1] );
        } else {
            $('#ratingmsg').text("");
        }
    }
    function rate( index ) {
        $('#rating_value').val(index);
        $('#form_rate').submit();
    }

    this.hoverStar = hoverStar;
    this.resetRating = resetRating;
    this.rate = rate;
    this.resetRating();
}

function changeCountry( id ) {
    sel = document.getElementById( "select_" + id );
    newname = "/img/flags/" + sel.options[sel.selectedIndex].text + ".gif";
    linkimg = document.getElementById( "img_" + id );
    linkimg.src = newname;
}

function toggleContact() {
    $('.contact_data').toggle();
    if( $('.contact_data:first').is(":hidden") ) {
        $('#contact_button').html('Kontaktdaten zeigen');
    } else {
        $('#contact_button').html('Kontaktdaten verstecken');
    }
}

