﻿
function CommunityHandler()
{
	this._xmlnamespace = "http://"+location.hostname +"/Service";
	this._url = "/Service/Community.asmx";
	
	this.requestRemovePost = function(postKey, url) 
    {
        this._Url = url;
	    var paramNames = ["postKey"];
	    var paramValues = [postKey];	
	    var soapMessage = xmlHttpRequest.createSoap(this._xmlnamespace, "RemovePost", paramNames, paramValues);
	    this.responseLoad = this.responsePost;
	    xmlHttpRequest.send(this, this._url, this._xmlnamespace + "/RemovePost", soapMessage);
    };
    this.requestRecommandPost = function(postKey) 
    {
        this._Url = "";
	    var paramNames = ["postKey"];
	    var paramValues = [postKey];	
	    var soapMessage = xmlHttpRequest.createSoap(this._xmlnamespace, "RecommandPost", paramNames, paramValues);
	    this.responseLoad = this.responsePost;
	    xmlHttpRequest.send(this, this._url, this._xmlnamespace + "/RecommandPost", soapMessage);
    };
    this.requestRemoveComment = function(commentKey) 
    {		
        this._Url = "";
        this._UrlChange = true;
	    var paramNames = ["commentKey"];
	    var paramValues = [commentKey];	
	    var soapMessage = xmlHttpRequest.createSoap(this._xmlnamespace, "RemoveComment", paramNames, paramValues);
	    this.responseLoad = this.responseComm;
	    xmlHttpRequest.send(this, this._url, this._xmlnamespace + "/RemoveComment", soapMessage);
    };
    this.requestRecommandComment = function(commentKey) 
    {
        this._Url = "";
	    var paramNames = ["commentKey"];
	    var paramValues = [commentKey];	
	    var soapMessage = xmlHttpRequest.createSoap(this._xmlnamespace, "RecommandComment", paramNames, paramValues);
	    this.responseLoad = this.responseComm;
	    xmlHttpRequest.send(this, this._url, this._xmlnamespace + "/RecommandComment", soapMessage);
    };
    this.responsePost = function() 
    {
	    var response = this.responseText;
	    if (response == 'undefined') 
	    {
		    alert("Sign in service, an error has occurred.\nIn a few minutes, please try again.");
		    return;
	    }
	    var res = xmlHttpRequest.createDocument(response);
	    var retMsg = xmlHttpRequest.getNode(res, 'Message');
	    var retStatus = parseInt(xmlHttpRequest.getNode(res, 'Status'));
	    
	    alert(retMsg);
	    
	    if(retStatus == 0)
	    {
	        //location.href = (this._Url == "") ? location.href : this._Url;
	        if (this._Url == "comment")     // 개발자 노트의 댓글의 삭제의 경우 파일 삭제지만, 댓글 영역만 새로고침 한다.
	            AjaxReplySetting();
	        else
	            location.href = (this._Url == "") ? location.href : this._Url;
	    }    
    };
    this.responseComm = function() 
    {
	    var response = this.responseText;
	    if (response == 'undefined') 
	    {
		    alert("Sign in service, an error has occurred.\nIn a few minutes, please try again.");
		    return;
	    }
	    var res = xmlHttpRequest.createDocument(response);
	    var retMsg = xmlHttpRequest.getNode(res, 'Message');
	    var retStatus = parseInt(xmlHttpRequest.getNode(res, 'Status'));
	    
	    alert(retMsg);
	    
	    if(retStatus == 0)
	    {
	        AjaxReplySetting();
	    }    
    };
};

var communityHandler = new CommunityHandler();
