var http=null;
if (window.XMLHttpRequest)
{// code for all new browsers
        http=new XMLHttpRequest();
}
else if (window.ActiveXObject)
{// code for IE5 and IE6
        http=new ActiveXObject("Microsoft.XMLHTTP");
}
function openDiv(id)
{
    var obj1 = document.getElementById(''+ id + '');
    if (obj1.style.display == "none")
    {
        obj1.style.display = "inline";
    }
}
function closeDiv(id)
{
    var obj2 = document.getElementById(''+ id + '');
    if (obj2.style.display == "inline")
    {
        obj2.style.display = "none";
    }
}
function validateReportForm(obj)
{
    if (trim(obj.captcha_input.value) == '')
    {
        alert('Please Enter Captcha !!');
        return false;
    }
    return false;
}
function loadReportCaptcha(id,form_obj)
{       
    var img_captcha = '/scripts/comments/captcha.php?rand=' + Math.floor(Math.random()*99999999);
    document.getElementById("" + id + "").src = img_captcha;
    form_obj.captcha_input.value = '';
}

function handleReport(form_obj)
{
    var url = "/scripts/mail/handle_report.php";
    var params = 'action=process&';
    if (form_obj.name)
    {
        params += 'form=' + form_obj.name + '&';
        params += 'url=' + document.location.href + '&';
        params += 'captcha=' + form_obj.captcha_input.value;
        params += 'url_id=' + form_obj.url_id.value;
    }
    http.open("POST", url, true);

    //Send the proper header information along with the request
    http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http.setRequestHeader("Content-length", params.length);
    http.setRequestHeader("Connection", "close");

    http.onreadystatechange = function() 
    {//Call a function when the state changes.
            if(http.readyState == 4 && http.status == 200) 
            {
                var response = http.responseText;
                alert(response);
                if (response=='report_abuse')
                {
                    alert("Your report has been sent.");
                    closeDiv('abuse_div');
                }
                else if (response == 'report_bad_link')
                {
                    alert("Your report has been sent.");
                    closeDiv('bad_link_div');
                }
                else if (response == 'report_abuse_captcha_error')
                {
                    alert("Enter the number in the box.");
                    loadReportCaptcha('report_abuse_captcha', 'report_abuse');
                }
                else if (response == 'report_bad_link_captcha_error')
                {
                    alert("Enter the number in the box.");
                    loadReportCaptcha('report_bad_link_captcha', 'report_bad_link');
                }
                else
                {
                    alert("Error in the system!!\nPlease try again later !!");
                    closeDiv('bad_link_div');
                    closeDiv('abuse_div');
                }
            }
    }
    http.send(params);
}
