/*
Prototype Ajax API
*/
var PAjaxApi = Class.create();
PAjaxApi.prototype = 
{
	initialize:function() 
    {
        this.method="post";
	},
	
    onCreate:null,
    onSuccess:null,
    onException:null,
    onFailure:null,
    onLoaded:null,
    onLoading:null,
	
	callMethod:function(APIMethod, params) 
    {
        var thisCall = this;
		if (typeof params != "object")
		{
			params = {};
		}
		var RESTURLROOT = APIMethod;//testingURL;
		var RESTURL = "src=js"
		for (var p in params)
		{
			var str = new String(params[p]);
			var reg = /(\x0e)|(\x0f)|(\x10)|(\x11)|(\x12)|(\x13)|(\x14)/gi;
			var str = str.replace(reg, " ");
			//url±àÂë
			RESTURL += "&" + p + "=" + encodeURIComponent(str);
		}
		params.RESTURL = RESTURL;
		var req = new AjaxRequest();
		if(this.method.toLowerCase()=="post")
		{
		      req.sendPOST(RESTURLROOT, RESTURL, this.onCreate,this.onSuccess,this.onException,this.onFailure,this.onLoaded,this.onLoading);
		}
		else if(this.method.toLowerCase()=="get")
		{
		      req.sendGET(RESTURLROOT, RESTURL, this.onCreate,this.onSuccess,this.onException,this.onFailure,this.onLoaded,this.onLoading);
		}
	}
}

var AjaxRequest = Class.create();
AjaxRequest.prototype = 
{
	initialize:function() 
    {
	},
	__send__:function(url, sendMethod, sendData, onCreate, onSuccess,onException,onFailure,onLoaded,onLoading) 
    {
		sendData = sendData + "&timeStamp=" + new Date().getTime();
		var newAjax = new Ajax.Request 
        (
			url, 
			{
                method: sendMethod, 
                parameters: sendData, 
                onCreate: onCreate, 
                onSuccess: onSuccess, 
                onException : onException,
                onFailure : onFailure,
                onLoaded : onLoaded,
                onLoading : onLoading
            }
		);
	},
	sendPOST:function(url, sendData, onCreate, onSuccess,onException,onFailure,onLoaded,onLoading) 
    {
		this.__send__(url, "post", sendData, onCreate, onSuccess,onException,onFailure,onLoaded,onLoading);
	},
	sendGET:function(url, sendData, onCreate, onSuccess,onException,onFailure,onLoaded,onLoading) 
    {
		this.__send__(url, "get", sendData, onCreate, onSuccess,onException,onFailure,onLoaded,onLoading);
	}
}
