// new calls used on index.html
var RssCalls = {

	loadUserData: function(instance_id, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/loaduserdata.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id), onComplete: completed_callback});
	},

	addPackages: function(instance_id, packages, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/addpackage.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id + "&packages=" + packages), onComplete: completed_callback});
	},

	removeTab: function(instance_id, tab_id, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/removetab.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id + "&tab_id=" + tab_id), onComplete: completed_callback});
	},

	updateTab: function(instance_id, tab_id, tab_name, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/updatetab.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id + "&tab_id=" + tab_id + "&tab_name=" + encodeURIComponent(tab_name)), onComplete: completed_callback});
	},

	listFeeds: function(instance_id, tab_id, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/listfeeds.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id + "&tab_id=" + tab_id), onComplete: completed_callback});
	},

	loadFeed: function(instance_id, tab_id, feed_id, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/updatefeed.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id + "&tab_id=" + tab_id + "&feed_id=" + feed_id), onComplete: completed_callback});
	},

	editFeed: function(instance_id, tab_id, feed_id, title, headlines, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/editfeed.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id + "&tab_id=" + tab_id + "&feed_id=" + feed_id + "&t=" + encodeURIComponent(title) + "&h=" + headlines), onComplete: completed_callback});
	},

	removeFeed: function(instance_id, tab_id, feed_id, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/removefeed.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id + "&tab_id=" + tab_id + "&feed_id=" + feed_id), onComplete: completed_callback});
	},

	editPosition: function(instance_id, tab_id, seq, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/editposition.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id + "&tab_id=" + tab_id + "&seq=" + encodeURIComponent(seq)), onComplete: completed_callback});
	},

	showSiteSearchPreview: function(q, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/previewfeed.aspx", {method: "get", parameters: uncache("q=" + encodeURIComponent(q)), onComplete: completed_callback});
	},

	addSiteSearch: function(instance_id, tab_id, q, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/addtoreader.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id + "&tab_id=" + tab_id + "&q=" + encodeURIComponent(q)), onComplete: completed_callback});
	},

	showExternalPreview: function(url, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/previewfeed.aspx", {method: "get", parameters: uncache("url=" + encodeURIComponent(url)), onComplete: completed_callback});
	},

	addExternalUrl: function(instance_id, tab_id, url, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/addtoreader.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id + "&tab_id=" + tab_id + "&url=" + encodeURIComponent(url)), onComplete: completed_callback});
	},

	addFeeds: function(instance_id, tab_id, feed_ids, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/addfeeds.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id + "&tab_id=" + tab_id + "&feed_ids=" + encodeURIComponent(feed_ids)), onComplete: completed_callback});
	},

	getStep1: function(instance_id, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/step1data.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id), onComplete: completed_callback});
	},

	getStep2: function(step1_id, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/step2data.aspx", {method: "get", parameters: uncache("id=" + step1_id), onComplete: completed_callback});
	},

	getStep3: function(step2_id, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/step3data.aspx", {method: "get", parameters: uncache("id=" + step2_id), onComplete: completed_callback});
	},

	revertDefaultTab: function(instance_id, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/revert.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id), onComplete: completed_callback});
	}
};

// subset of old calls used on web.html
var StepProxy = {

	GetStep1: function(instance_id, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/step1data.aspx", {method: "get", parameters: uncache("instance_id=" + instance_id), onComplete: completed_callback});
	},

	GetStep2: function(step1_id, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/step2data.aspx", {method: "get", parameters: uncache("id=" + step1_id), onComplete: completed_callback});
	},

	GetStep3: function(step2_id, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/step3data.aspx", {method: "get", parameters: uncache("id=" + step2_id), onComplete: completed_callback});
	}
};

var FeedProxy = {
	
	CreateFeed: function(step2_id, keyword, completed_callback) {
		var req = new Ajax.Request(SERVER_NAME + "/scripts/reader/createfeed.aspx", {method: "get", parameters: uncache("sid=" + step2_id + "&q=" + encodeURIComponent(keyword)), onComplete: completed_callback});
	}
};

// add timestamp to querystring
function uncache(querystring) {
	return querystring + "&timestamp=" + new Date().getTime();
}