$(document).ready(function()
{
    $('#reportTitle').text($('#directoryMainLink').text());
    $('#reportUrl').text($('#directoryMainLink').attr('href'));
    
    $('a.report').fancybox();
});

function ReportLink()
{
    var id = $('#directoryId').val();
    var title = $('#reportTitle').text();
    var url = $('#reportUrl').text();
    var type = $('input[type=radio]:checked').val();
    var name = $('#reportName').val();
    var email = $('#reportEmail').val();
    var message = $('#reportMessage').val();
    
    if(!type)
    {
        alert('Please select a reason for your report - use the "anything else" box to give more information if you wish.');
        $('input[type=radio]')[0].focus();
        return;
    }
    
    if(!name)
    {
        alert('Please give us your name incase we need to contact you about this report.');
        $('#reportName').focus();
        return;
    }
    
    if(!email)
    {
        alert('Please give us your email address incase we need to contact you about this report.');
        $('#reportEmail').focus();
        return;
    }

    $.ajax({
       url: _baseUrl + 'handlers/ReportLink.ashx',
       type: 'POST',
       cache: false,
       async: false,
       data: ({ 
                id: id,
                title: title,
                url: url,
                type: type,
                name: name,
                email: email,
                message: message
        }),
       success: function(html) 
       { 
            if(html == "ok")
            {
                alert('Thank you for your report. We will contact you once we have reviewed this link.');
                $.fancybox.close();
            }
            else            
            {
                alert('There was a problem sending your report. Please wait a moment and try again. If the problem persists, please contact us directly at: admin@handmade-crafts.co.uk.');
            }
       }
    });
}

