$(document).ready(function(){
    //alert(document.location.href);
    $("#postbutton").click(function(){
       var fields = $("#formcomment :input").serializeArray();
        /* To add loading bar  for comment */
        $("#formcomment #postbutton").attr("value","Posting...");
        /* Ajax */
        $.post("/article/comments/update.php",fields, function(data){
                                        $("#formcomment #postbutton").attr("value","Post your comment");
                                        var errorstr = "";            
                                        if(data.status == "Error"){
                                            errorstr = "<ul>";
                                            for(var d in data.error ){
                                                errorstr += " <li>"+data.error[d]+"</li>"; 
                                            }
                                            errorstr += "</ul>";
                                            $(".commenterror").html(errorstr);
                                        }else if(data.status == 'Success'){
                                           var loc1 = document.location.href;
                                           var loc2 = loc1.replace('/articles/','/articles_comments/');
                                           document.location.href = loc2;

                                        }else{

                                        }
                                       
            
                                    },"json");
                                    
                                                                                                                        
    });
    
    
});

function refresh_secureimg(){
	currentDate = new Date();
	security_img_num = 1;
	security_img_num++;
	document.getElementById('box_code').src='/services/security_key.php?number='+currentDate.getHours()+currentDate.getMinutes()+currentDate.getSeconds()+security_img_num;
	//$("#box_code").html("");
	//$("#box_code").html("<img src=\"/services/security_key.php\" alt=\"International Business Times Secutiry Check\">");
	
}
