function reportAbuse(questionAnswerId , reportAbuseTypeParam){

    var userId = USER_ID;
    if (userId == 0){
        showLoginPopup();
    }
    else{
        //jQuery.facebox($j('#reportAbusePopUp').val());
        jQuery.facebox('<DIV id="report-abuse-container" style="color:black;">' +
                '<div class = "title">Report</div>' +
                '<div class = "report-body">' +
                    '<p>You are about to report a violation of our Terms of Use. <span style = "font-weight: bold;">All reports are strictly confidential.</span></p>' +
                    '<p>We will NOT remove posts just because you disagree with the statement being made.</p>' +
                    '<div id="report-abuse-error" name = "report-abuse-error" class="clear-both error-container" style="display: none;">' +
                        '<span>{MSG}</span>' +
                    '</div>' +
                    '<div class = "formRow">' +
                        '<label>Reason:<br/>(required)</label>' +
                        '<select id="reason" name="reason" class="">' +
                            '<option value="0">Choose One</option>' +
                            '<option value="SPAM_OR_ADVERTISEMENT">Spam or Advertisement</option>' +
                            '<option value="ATTACKS_OR_OFFENDS">Attacks or Offends</option>' +
                        '</select>' +
                    '</div>' +
                    '<div class = "formRow" style = "height: 70px;">' +
                        '<label>Additional Comments:<br/>(required)</label>' +
                        '<textarea maxlength="256" rows="3" name="additional-comments" id="additional-comments"></textarea>' +
                    '</div>' +
                '</div>' +
                '<div class = "report-abuse-footer">' +
                    '<button type = "button" onclick = "javascript:submitReportAbuse();">Submit</button>' +
                    '<button type = "button" onclick = "javascript:closeReportAbuse();">Cancel</button>' +
                '</div>' +
            '</DIV>' +
            '<DIV class="clear-both"></DIV>');
        $j('#facebox .body').css({'width':'470px' });
        $j('#facebox .body').css({'padding':'0px' });
        $j('#facebox .footer').hide();
        $j('#facebox #report-abuse-error').hide();
        $j('#facebox').css({'left':($j(window).width() - $j('#facebox').width()) / 2})
        //$j('#report-abuse').html('');
        currentQuestionAnswerId = questionAnswerId;
        reportAbuseType = reportAbuseTypeParam;
    }
}

function closeReportAbuse(){
    //$j('#report-abuse').html( $j('.fb_content').html() );
    jQuery(document).trigger('close.facebox');
}

function submitReportAbuse(){
    var validForm = validateReporAbuseForm();

    if (validForm){
        //alert('submit');
        var url = "/answers/ajax/ajax-action/submit-report-abuse";
        var reasonValue = $j('#facebox #reason').val();
        var additionalCommentsValue = $j('#facebox #additional-comments').val();

        var params = {questionAnswerId: currentQuestionAnswerId, reason: reasonValue, additionalComments: additionalCommentsValue, userId: USER_ID, type: reportAbuseType };
        goAjax(url, params, afterSubmitReportAbuse);
        jQuery.facebox.loading();
        $j('#facebox').css({'left':($j(window).width() - $j('#facebox').width()) / 2})
    }
}

function afterSubmitReportAbuse(jsonedResponse){
    var response = eval( '(' + jsonedResponse + ')' );
    var responseShowed = document.getElementById( 'success-template' ).innerHTML;
    responseShowed = responseShowed.replace(/{STATUS-MSG}/g, 'Thanks. Your report has been submitted.');

    jQuery.facebox(responseShowed);
    $j('#facebox .body').css({'padding':'10px', 'width':'370px' });
    $j('#facebox .footer').css({'float':'none', 'width':'auto' });
    $j('#facebox').css({'left':($j(window).width() - $j('#facebox').width()) / 2})
}

function validateReporAbuseForm(){
    var validForm = true;
    var reason = $j('#reason');
    var reasonValue = $j('#facebox #reason').val();
    //var reasonValue = document.getElementById('reason').value;

    var errorMessages = new Array();

    if (reasonValue == '0'){
        errorMessages[errorMessages.length] = 'Please select a reason';
    }

    var additionalCommentsValue = $j('#facebox #additional-comments').val();

    if (additionalCommentsValue == ''){
        errorMessages[errorMessages.length] = 'The additional comments is required';
    }

    if ( errorMessages.length > 0 ){
        validForm = false;
        goError(errorMessages);
    }

    return validForm;
}

function goError(errorMessages)
{
    var errorMessage = '';

    for(i=0; i < errorMessages.length; i++) {
        errorMessage = errorMessage + '<span>' + errorMessages[i] + '</span>';
    }

    $j('#facebox #report-abuse-error').html(errorMessage);
    $j('#facebox #report-abuse-error').fadeIn();
    window.setTimeout("$j('#facebox #report-abuse-error').fadeOut();", 3000);
}
