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 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 submitCVAValues( formel, items ) {
    for( i=0 ; i<formel.elements.length ; i++ ) {
        for( var vname in items ) {
            if( formel.elements.item(i).name == vname ) {
                formel.elements.item(i).value = items[vname];
            }
        }
    }
    formel.submit();
}

function submitCVAAction( formel, action ) {
    submitCVAValues( formel, {'cva[action]': action} );
}

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

function highlite_rate(which)
{

		for(i=1; i<= 5; i++){
			document.getElementById("rating"+i).src = "/fileadmin/templates/grafik/rating-star-empty.gif";
		}


		for(i=1; i<= which; i++){
			document.getElementById("rating"+i).src = "/fileadmin/templates/grafik/rating-star-full.gif";
		}
}

function setNotification( thread_id, object_type, object_id, state, url, title ) {
    var $j = jQuery.noConflict();
    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 };
    }
    $j.ajax({
        url: '/community/ajax.php',
        type: 'GET',
        data: calldata,
        dataType: 'json',
        timeout: 1000,
        error: function(){
            $j('#notifyresult').html( '<span style="color:red">Serverfehler!</span>' );
        },
        success: function(json){
            if( json.success ) {
                $j('#notifyresult').html( '<span style="color:green">'+json.success+'</span>' );
            } else {
                $j('#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 );
}

