function Comments(){}

Comments.prototype.updateView = function(response,data){
    if(response != -1){
        var now = new Date();
        //formats the date to look like a MySQL date. Could be better but doesn't matter
        var formattedDate = now.getFullYear()+'-'+
                            (now.getMonth()<10?'0'+now.getMonth():now.getMonth())+'-'+
                            (now.getDate()<10?'0'+now.getDate():now.getDate())+' '+
                            (now.getHours()<10?'0'+now.getHours():now.getHours())+':'+
                            (now.getMinutes()<10?'0'+now.getMinutes():now.getMinutes())+':'+
                            (now.getSeconds()<10?'0'+now.getSeconds():now.getSeconds());
        //formats the comment to preserve newlines but eliminate HTML (it just displays the characters
        var safeComment = strip_tags(data.comment.replace(/\n/g,'[newline]'),"<a>").replace(/\[newline\]/g,'<br />');
        //var safeComment = ($('<span>').text(data.comment.replace(/\n/g,'[newline]'))).html().replace(/\[newline\]/g,'<br />');
        var html = '<p style="border-bottom:1px solid #000;"><span style="float:right;">'+formattedDate+'</span><span class="bold">'+data.authorname+"</span> "+(data.authorwebsite!=""?'- <a href="'+data.authorwebsite+'">'+data.authorwebsite+'</a> ':'')+'<br />'+safeComment+'</p>';
        
        $("#wait").hide();
        $("#comments").append(html);
    }else{
        $("#wait").hide();
        alert("There was a problem inserting your comment. Refresh your page and try again. If you continue to have issues then contact Allan Bogh, ajbogh@allanbogh.com."); //TODO fix this
    }
};

Comments.prototype.createComment = function(form){
   var requiredFields = new Array(form.authorname,form.email,form.comment);
   if(!checkRequiredTextFields(requiredFields)){
        return;
   }

    //define the data
	var oData = {
		requesting: "Comment",
        articleid:form.articleid.value,
		authorid:form.authorid.value,
        authorname:form.authorname.value,
        authoremail:form.email.value,
        authorwebsite:form.website.value,
        comment: form.comment.value
	};
   $("#wait").show();
   $.post("/ajax/comment.php",oData,function(responseText){(new Comments).updateView(responseText,oData);},"text");
};




