function submitComment()
{
    var xmlhttp = getRequestObject();           // getting XMLHttpRequest object
    var url = '/includes/save_comments.php';                       // action url of post
    var params = "";                            // parameters to be transmitted
    var i;

    for( i = 0; i < document.forms['comment_form'].elements.length; i++ )
    {
        if( document.forms['comment_form'].elements[i].value )
        {
            params += document.forms['comment_form'].elements[i].name
                   + "=" + document.forms['comment_form'].elements[i].value;
            params += "&";
        }
    }

    params += "passedViaAjax" + "=" + "yes";

    // parameters to be transmitted are encoded
    params = encodeURI(params);

    // Test if the browser supports AJAX
    if (xmlhttp==null)
    {
        alert ("Your browser does not support AJAX!");
        return;
    }

    // If result is successful we show a message
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 || xmlhttp.readyState=="complete")
        {
            if (xmlhttp.status == 200)
            {
                var myJsonObj = jsonParse(xmlhttp.responseText);

                if( myJsonObj.response == 'saved' )
                {
                    $(".list_comments").prepend(myJsonObj.new_comment);
                    //alert(myJsonObj.new_comment);
                    $("#total_comments").text(myJsonObj.total_comments);

                    $(".comments_input").val("");
                    $(".comments_text").val("");
                    $("#comments_error").html('');
                }
                else
                {
                    var r = Math.random();

                    $("#comments_error").html('');
                    $("#comments_error").html(myJsonObj.errors);
                    $("#captcha_img").attr('src','/includes/captcha.php?id=' + r );
                }
	    }
            else
            {
                alert( xmlhttp.responseText );
	    }
        }
    }

    // Catching the exceptions and errors
    try
    {
        xmlhttp.open("POST", url, true);
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        xmlhttp.send(params);
    }
    catch(e)
    {
        // Do something with exceptions
    }
}

function getRequestObject()
{
    // Get XMLHttpRequest Object for AJAX manipulations

    if (window.XMLHttpRequest)
    {
        // If browser is NOT IE
        return(new XMLHttpRequest());
    }
    else if (window.ActiveXObject)
    {
        // If browser is IE
        return(new ActiveXObject("Microsoft.XMLHTTP"));
    }
    else
    {
        return(null);
    }
}

function showPaper( n )
{
    $(n).css("z-index","1000");
    $(n).css("position","absolute");
    $(n).attr("width","450");
    $(n).attr("height","648");
}

function hidePaper( n )
{
    $(n).css("z-index","0");
    $(n).css("position","auto");
    $(n).attr("width","140");
    $(n).attr("height","200");
}

function tab_show_form()
{
    $('#tab_show_form.item').removeClass('selected');
    $('#tab_hide_form.item').addClass('selected');
    $(".form_holder").css("display","none");
}

function tab_hide_form()
{
    $('#tab_show_form.item').addClass('selected');
    $('#tab_hide_form.item').removeClass('selected');
    $(".form_holder").css("display","block");
}

