﻿var tv = {ajax: {
	    doCallbackHtml: function(id, param, callback){
		    $.ajaxSetup({
			    contentType: "application/x-www-form-urlencoded"
		    });
		    var postData = "__CALLBACKID=" + escape(id) +
		    "&__CALLBACKPARAM=" + escape(param) + "&__VIEWSTATE=&" + postData;
		    $.post(document.URL, postData, function(data, status){
			    if (data.charAt(0) == "s") {
				    status = "success";
				    data = data.substring(1);
			    } else if (data.charAt(0) == "e") {
				    status = "error";
				    data = data.substring(1);
			    } else {
				    var separatorIndex = data.indexOf("|");
				    if (separatorIndex != -1) {
					    var valLength = parseInt(data.substring(0, separatorIndex));
					    if (!isNaN(valLength)) {
						    data = data.substring(separatorIndex + valLength + 1);
					    }
				    }
			    }
			    callback(data, status);
		    }, "html");
	    },
	    doCallbackJson: function(url, method, params, callback){
		    $.ajaxSetup({
			    contentType: "application/json"
		    });
		    $.post(url + method, $.toJSON(params), function(data, status){
			    var res = eval(data);
			    callback(res[method + "Result"], status);
		    }, "json");
	    }
	    ,
	    doCallback: function(url, method, params){
		    $.ajaxSetup({
			    contentType: "application/json"
		    });
		    $.post(url + method, $.toJSON(params),null , "json");
	    }
    }
};
