/*
 * author:addo zhang
 */

(function(){
    function $(id){
        return document.getElementById(id);
    }
    function setStyleDisplay(id,status){
        $(id).style.display=status;
    }
    function reply(comment_id,comment_author,textarea_id,reply_to,cancel){
        var str = '<a class="reply" href="#comment-'+comment_id+'">@';
        str += comment_author;
        str += '</a>';
        $(reply_to).innerHTML = ' to '+str.replace("@",'');
        $(cancel).innerHTML = '<input type="button" value="Cancel" onclick="Util.cancel(\''+reply_to+'\',\''+cancel+'\')"/>';
        $(textarea_id).focus();
    }
    function cancel(reply_to,cancel){
        $(reply_to).innerHTML = '';
        $(cancel).innerHTML = '';
    }
    function appendComment(reply_to,comment,reply_comment){
        var replyTo = $(reply_to).innerHTML;
        if(replyTo.length!=0){
            $(reply_comment).value = '@'+replyTo.replace('to ','')+'\n'+$(comment).value;
        }else {
            $(reply_comment).value = $(comment).value;
        }
    }
    function getRequestObject (url,options){
        //init request
        var req = false;
        if(window.XMLHttpRequest){
            var req = new Window.XMLHttpRequest();
        }else if(window.ActiveXObject){
            var req = new Window.ActiveXObject('Microsoft.XMLHTTP');
        }
        if(!req) return false;
    }

    window['Util'] = {};
    window['Util']['$']=$;
    window['Util']['reply']=reply;
    window['Util']['cancel']=cancel;
    window['Util']['appendComment']=appendComment;
    window['Util']['setStyleDisplay']=setStyleDisplay;
})();