var objFileReportTranslations = JSON.parse('{"FileReportCancelConfirm":"Do you want to cancel the previous problem report for this file?","FileReportConfirm":"Is there a problem with this content or service functionality?","ReasonPlaceholder":"Enter a description of the problem...","PleaseSelectType":"Choose the type of problem:","Type_DoesNotWork":"Does not work","Type_Bug":"Error","Type_Copyrights":"Copyrights","Type_PersonalPrivacy":"Person\u2019s privacy","Type_Hatred":"Hatred","Type_Terrosim":"Terrorism","Type_Malware":"Malware","Type_Spam":"Spam","Type_Adult":"Adult content","Type_Gore":"GORE","Type_Children":"Children","Type_Other":"Other","Button_Report":"Report","Button_Cancel":"Cancel"}');
function showFileReportModal( domLink, strHash, fnCallback )
{
    if ( typeof fnCallback === "undefined" )
    {
        fnCallback = function () {};
    }
    
    if ( $( domLink ).hasClass( 'has_reported' ) )
        return showCancelFileReportModal(domLink, strHash, fnCallback);
    
    var strInputs = '';
    strInputs += '
';
    strInputs += '
';
    strInputs += '';
    strInputs += '
';
    strInputs += '
';
    strInputs += '';
    strInputs += '
';
    
    fConfirm(
        objFileReportTranslations.FileReportConfirm + strInputs,
        null,
        objFileReportTranslations.Button_Report ,
        objFileReportTranslations.Button_Cancel ,
        // Submit
        function( bolSubmitted, jqModalWindow )
        {
            if( bolSubmitted === true )
            {
                var jqReason = $( '.reason', jqModalWindow );
                var jqType = $( '.type', jqModalWindow );
                makeFileReportRequest( strHash, jqReason.val(), jqType.val(), function ( strActionResponse ) {
                    finishFileReport( domLink, strActionResponse );
                    fnCallback( strActionResponse );
                });
            }
        },
        // Validate
        function ( jqModalWindow )
        {
            var jqReason = $( '.reason', jqModalWindow );
            var jqType = $( '.type', jqModalWindow );
            
            var bolOk = true;
    
            if ( $.trim( jqReason.val() ).length < 4 )
            {
                jqReason.css({'border-color': 'red'});
                bolOk = false;
            }
            else
            {
                jqReason.css({'border-color': 'inherit'});
            }
            
            if ( $.trim( jqType.val() ) == '' )
            {
                jqType.css({'border-color': 'red'});
                bolOk = false;
            }
            else
            {
                jqType.css({'border-color': 'inherit'});
            }
            
            return bolOk;
        }
    );
}
function showCancelFileReportModal(domLink, strHash, fnCallback)
{
    if ( typeof fnCallback === "undefined" )
    {
        fnCallback = function () {};
    }
     
    fConfirm(
        objFileReportTranslations.FileReportCancelConfirm,
        null,
        'OK',
        objFileReportTranslations.Button_Cancel ,
        // Submit
        function( bolSubmitted )
        {
            if( bolSubmitted === true )
            {
                makeFileReportRequest( strHash, null, null, function ( strActionResponse ) {
                    finishFileReport( domLink, strActionResponse );
                    fnCallback( strActionResponse );
                });
            }
        }
    );
}
function finishFileReport( domLink, strActionResponse )
{
    
    if ( strActionResponse == 'report' )
    {
        
        $( domLink ).addClass( 'has_reported' ).attr( 'my_title', 'Cancel a problem report' );
        fSuccess('Thank you, the problem report has been submitted and will be processed shortly.');
    }
    else
    {
        
        $( domLink ).removeClass( 'has_reported' ).attr( 'my_title', 'Report a problem' );
        fSuccess('Your message about dangerous file content has been cancelled.');
    }
    
}
function makeFileReportRequest( strHash, strReason, strType, fncCallback )
{
    $.ajax( {
        type: "POST",
        dataType: "json",
        url: "/ajax/report_file.php",
        data: {
            'report': true,
            'h': strHash,
            'reason': !!strReason ? strReason : null,
            'type': !!strType ? strType : null
        },
        success: function ( data )
        {
            if ( data[ 'status' ] == 'ok' )
            {
                fncCallback( data[ 'action' ] );
            }
        }
    } );
}