// JavaScript Document
var gViewer;
var gFlashVars = '';
var gSubscriberId = '';
var gSum = '';

var gFriendIndex = 0;
var gFriendIdArray = new Array();
var gFriendList = new Array();
var gFriendIncludedIdList = new Array();
var gFriendExcludedIdList = new Array();
var gFriendHtml = '';
var gFriendBatchSize = 40;
var gFriendMax = 6000;
var gInviteMode = 'invite_start';

function updateDataCallback(response) {
    if (!response.hadError()) {
	    viewMain(gFlashVars);
	}
	else {
		// server error
		document.getElementById('unavailable').style.display = 'block';
		document.getElementById('loading').style.display = 'none';
		document.getElementById('main').style.display = 'none';
	}
}
function saveSubscriber() {
	document.getElementById('saving').style.display = 'block';
	document.getElementById('unavailable').style.display = 'none';
    var url = 'http://petfarm.stunme.com/widgets/pet_farm/opensocial/create_subscriber';
	
    var params = {};
    var postdata = {};
	postdata['name'] = encodeURIComponent(document.createForm.farm_name.value);
	postdata['user_id'] = gViewer.getId();
	if (document.createForm.accept_friends.checked) {
		postdata['accept_friends'] = 'Y';
	}
    params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
    params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
    gadgets.io.makeRequest(url, saveSubscriberCallback, params);
        
    function saveSubscriberCallback(data, url, errored) {
        if (!errored) {
			var isSaved = false;
			var params = data.text.split("|");
			if (params[0] == 'created' && params.length >=  3) {
				var req = opensocial.newDataRequest();
				var subscriberId = params[1];
				var sum = params[2];
				gFlashVars = 'sum=' + sum + '&subscriber_id=' + subscriberId;
				req.add(req.newUpdatePersonAppDataRequest('VIEWER', 'subscriber_id', subscriberId));
				req.add(req.newUpdatePersonAppDataRequest('VIEWER', 'flash_vars', escape(gFlashVars)));
				req.send(updateDataCallback);
				isSaved = true;
			}
			if (!isSaved) {
				// server error
				document.getElementById('unavailable').style.display = 'block';
				document.getElementById('main').style.display = 'none';
			}
        } 
        else {
			// server error
			document.getElementById('unavailable').style.display = 'block';
			document.getElementById('main').style.display = 'none';
        }
    }
}
function viewMainCallback(data, url, errored) {
	if (!errored) {
		document.getElementById('main').innerHTML = data.text;
		document.getElementById('loading').style.display = 'none';
	} 
	else {
		// server error
		document.getElementById('unavailable').style.display = 'block';
		document.getElementById('loading').style.display = 'none';
	}
}

function viewMain(flashVars) {
	var url;
	if (flashVars != undefined) {
		url = 'http://petfarm.stunme.com/widgets/pet_farm/opensocial/play0006?subscriber_id=' + gSubscriberId + '&flash_vars=' + escape(flashVars);
	}
	else {
	    url = 'http://petfarm.stunme.com/widgets/pet_farm/opensocial/intro0004?name=' + escape(gViewer.getDisplayName());
	}
	var params = {};
	params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
	gadgets.io.makeRequest(url, viewMainCallback, params);
}
function authCallback(data, url, errored) {
	if (!errored) {
		var params = data.text.split("|");
		if (params[0] == 'found' && params.length >=  3) {
			var req = opensocial.newDataRequest();
			var subscriberId = params[1];
			var sum = params[2];
			gSubscriberId = subscriberId;
			gSum = sum;
			gFlashVars = 'sum=' + sum + '&subscriber_id=' + subscriberId;
			req.add(req.newUpdatePersonAppDataRequest('VIEWER', 'subscriber_id', subscriberId));
			req.add(req.newUpdatePersonAppDataRequest('VIEWER', 'flash_vars', escape(gFlashVars)));
			req.send(updateDataCallback);
		}
		else {
			viewMain(undefined);
		}
	} 
	else {
		// server error
		document.getElementById('unavailable').style.display = 'block';
		document.getElementById('loading').style.display = 'none';
	}
}
function init() {
    var req = opensocial.newDataRequest();
    req.add(req.newFetchPersonRequest(opensocial.DataRequest.PersonId.VIEWER));
    req.send(viewerResponse);

    function viewerResponse(response) {

		gViewer = response.get(opensocial.DataRequest.PersonId.VIEWER).getData(); 
		if (gViewer == null) {
			document.getElementById('loading').style.display = 'none';
			document.getElementById('not_installed').style.display = 'block'; 
			return;
		}
        var userId = gViewer.getId();
		
		var url = 'http://petfarm.stunme.com/widgets/pet_farm/opensocial/get_subscriber';
		var params = {};
		params[gadgets.io.RequestParameters.AUTHORIZATION] = gadgets.io.AuthorizationType.SIGNED;
		params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;					
		var postdata = {};
		postdata['timestamp'] = new Date().getTime();
		params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
		gadgets.io.makeRequest(url, authCallback, params);

    } 
}

// INVITE PAGE

function switchToMain() {
	document.getElementById('main').style.display = 'block';
	document.getElementById('invite').style.display = 'none';
}

function viewInviteCallback(data, url, errored) {
	if (!errored) {
		document.getElementById('invite').innerHTML = data.text;
		document.getElementById('invite').style.display = 'block';
		document.getElementById('loading').style.display = 'none';
		document.getElementById('friends').innerHTML = gFriendHtml;
	} 
	else {
		// server error
		document.getElementById('unavailable').style.display = 'block';
		document.getElementById('loading').style.display = 'none';
	}
}
function viewInvite() {
	var	url = 'http://petfarm.stunme.com/widgets/pet_farm/opensocial/invite';
	var params = {};
	params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
	gadgets.io.makeRequest(url, viewInviteCallback, params);
}
function getInviteHtml() {
	var friendHtml = '';
	var mode = gInviteMode;
	if (mode == "invite_start") {
		friendHtml += '<span class="whitehead">Please click your friends you\'d like to post a comment to invite:</span><br>';
		friendHtml += 'They\'ll receive 3 random pets as a gift<br><br>';
		friendHtml += '<br /><a href="javascript:void(0)" onclick="selectAllFriends()" class="whiteplain">select all</a> | ';
		friendHtml += '<a href="javascript:void(0)" onclick="deselectAllFriends()" class="whiteplain">deselect all</a> ';
		friendHtml += '<input type="button" value="click here to invite selected friends" style="color:#FFFFFF; background-color: #999999; font-family: Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold" onclick="inviteSelectedFriends(\'invite_start\')">';
	}
	else if (mode == "invite_team") {
		friendHtml += 'invite your friends | <a href="javascript:void(0)" onclick="javascript:switchToInviteByMode(\'pending_list\');" class="whiteplain">pending team requests</a> | <a href="javascript:void(0)" onclick="javascript:switchToInviteByMode(\'friend_list\');" class="whiteplain">your team members</a><br><br>';
		friendHtml += '<span class="whitehead">Who would you like to join your team? Please click your friends you\'d like to send comments to invite:</span><br>';
		friendHtml += '<br /><a href="javascript:void(0)" onclick="selectAllFriends()" class="whiteplain">select all</a> | ';
		friendHtml += '<a href="javascript:void(0)" onclick="deselectAllFriends()" class="whiteplain">deselect all</a> ';
		friendHtml += '<input type="button" value="click here to invite selected friends" style="color:#FFFFFF; background-color: #999999; font-family: Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold" onclick="inviteSelectedFriends(\'invite_team\')">';
	}
	else if (mode == "pending_list") {
		friendHtml += '<a href="javascript:void(0)" onclick="javascript:switchToInviteByMode(\'invite_team\');" class="whiteplain">invite your friends</a> | pending team requests | <a href="javascript:void(0)" onclick="javascript:switchToInviteByMode(\'friend_list\');" class="whiteplain">your team members</a><br><br>';
		friendHtml += '<span class="whitehead">Please check all friend requests you\'d like to accept and uncheck all the ones you\'d like to reject:</span><br>';
		
		friendHtml += '<br /><a href="javascript:void(0)" onclick="selectAllFriends()" class="whiteplain">select all</a> | ';
		friendHtml += '<a href="javascript:void(0)" onclick="deselectAllFriends()" class="whiteplain">deselect all</a> ';
		friendHtml += '<input type="button" value="accept selected requests/reject unselected requests" style="color:#FFFFFF; background-color: #999999; font-family: Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold" onclick="acceptRejectFriends()"> ';
		friendHtml += '<input type="button" value="accept all" style="color:#FFFFFF; background-color: #999999; font-family: Arial, Helvetica, sans-serif; font-size: 16px; font-weight: bold" onclick="acceptAllFriends()">';
	}
	else {
	    // friend_list
		friendHtml += '<a href="javascript:void(0)" onclick="javascript:switchToInviteByMode(\'invite_team\');" class="whiteplain">invite your friends</a> | <a href="javascript:void(0)" onclick="javascript:switchToInviteByMode(\'pending_list\');" class="whiteplain">pending team requests</a> | your team members<br><br>';
		friendHtml += '<span class="whitehead">Here\'s the list of friends in your team. Click to see their profile.</span><br>';
	}

	var colNum = 6;
	friendHtml += '<br /><div style="height: 500px; overflow: auto;">';
	friendHtml += '<form name="friendForm"><table border="0" cellspacing="0" cellpadding="8">';
	for (var i = 0; i < gFriendList.length; i++) {
		var friendData = gFriendList[i];

		if (i % colNum == 0) {
			friendHtml += '<tr>';
		}
		friendHtml += '<td align="center" class="greyplain" valign="bottom">';
		var friendId = friendData.getField(opensocial.Person.Field.ID);
		var friendName = friendData.getField(opensocial.Person.Field.NAME);
		var thumbnail = friendData.getField(opensocial.Person.Field.THUMBNAIL_URL);
		
		if (mode != "friend_list") {
			var aTag = '<a href="javascript:void(0)" class="whiteplain" onclick="document.friendForm.check' + friendId + '.checked = true;">';
			friendHtml += '<div align="center" style="width: 95px; overflow: hidden; white-space: nowrap;">' + aTag + '<img src="' + thumbnail + '" border="0"/></a>';
			if (mode != "pending_list") {
				friendHtml += '<br /><input type="checkbox" name="check' + friendId + '"/>';
			}
			else {
				friendHtml += '<br /><input type="checkbox" name="check' + friendId + '" checked="checked"/>';
			}
			friendHtml += aTag + friendName + '</a></div> ';
		}
		else {
			friendHtml += '<div align="center" class="whiteplain" style="width: 95px; overflow: hidden; white-space: nowrap;">';
			friendHtml += '<a href="http://www.myspace.com/' + friendId + '" target="_blank" style="color: #FFFFFF"><img src="' + thumbnail + '" border="0"/><br /> ';
			friendHtml += friendName + '</a></div> ';
		}
		
		friendHtml += '</td>';
		if (i % colNum == colNum - 1) {
			friendHtml += '</tr>';
		}
	}
	var count = gFriendList.length;
	if (count == 0) {
		if (mode == "pending_list") {
			friendHtml += '<tr><td class="whiteplain">You don\'t have any pending friend requests.</td></tr>';
		}
		else if (mode == "friend_list") {
			friendHtml += '<tr><td class="whiteplain">You don\'t have any friends in your team.</td></tr>';
		}
		else {
			friendHtml += '<tr><td class="whiteplain">All your friends are your team members.<br>Please find more friends.</td></tr>';
		}
	}
	else if (count % colNum != 0) {
		var moreColumms = colNum - (count % colNum);
		for (var i = 0; i < moreColumms; ++i) {
			friendHtml += '<td><img src="http://petfarm.stunme.com/images/pix.gif" width="75" height="75" border="0"/></td>';
		}
		friendHtml += '</tr>';
	}
	friendHtml += '</table></form>';
	friendHtml += '</div>';
	gFriendHtml = friendHtml;
	viewInvite();
}
function getFriends(start, functionCall) {
	var req = opensocial.newDataRequest();
	var params = {};
	params[opensocial.DataRequest.PeopleRequestFields.FIRST] = start; 
   	params[opensocial.DataRequest.PeopleRequestFields.MAX] = gFriendBatchSize;
   	req.add(req.newFetchPeopleRequest(opensocial.DataRequest.Group.VIEWER_FRIENDS, params), 'viewerFriends');
    req.send(getFriendsResponse);
	
	function getFriendsResponse(response) {
        var friendsResponse = response.get('viewerFriends');
		if (friendsResponse.hadError()) {
			functionCall();
		}
		else {
			var friendsData = friendsResponse.getData();
			if (friendsData.size() > 0){
				friendsData.each(
					function(friendData) {
						var friendId = friendData.getField(opensocial.Person.Field.ID);	
						var isListed = false;
						if (gInviteMode == 'pending_list' || gInviteMode == 'friend_list') {
							for (var i = 0; i < gFriendIncludedIdList.length; ++i) {
								if (gFriendIncludedIdList[i] == friendId) {
									isListed = true;
									break;
								}
							}
						}
						else {
							isListed = true;
							for (var i = 0; i < gFriendExcludedIdList.length; ++i) {
								if (gFriendExcludedIdList[i] == friendId) {
									isListed = false;
									break;
								}
							}
						}
						if (isListed)
							gFriendList.push(friendData);
					}
				);
				start += gFriendBatchSize;
				if (start >= gFriendMax)
					functionCall();
				else
					getFriends(start, functionCall);
			}
			else {
				functionCall();
			}

		}
	}
}
function getFriendListCallback(data, url, errored) {
	if (!errored) {
		var friendlistText = data.text;
		if (friendlistText != '0') {
			var newFriendIdList = friendlistText.split("|");
			if (gInviteMode == 'pending_list' || gInviteMode == 'friend_list') {
				gFriendIncludedIdList = newFriendIdList;
			}
			else {
				gFriendExcludedIdList = newFriendIdList;
			}
		}
		
		getFriends(0, function () {
			getInviteHtml();
		});
	} 
	else {
		// server error
		document.getElementById('unavailable').style.display = 'block';
		document.getElementById('loading').style.display = 'none';
	}
}
function getFriendList() {
	var url;
	if (gInviteMode == 'pending_list') {
		url = 'http://petfarm.stunme.com/widgets/pet_farm/opensocial/friend/pending_list?user_id=' + gViewer.getId();;
	}
	else {
	   url = 'http://petfarm.stunme.com/widgets/pet_farm/opensocial/friend/list?user_id=' + gViewer.getId();;
	}
	var timestamp = new Date().getTime();
	url += '&timestamp=' + timestamp;
	var params = {};
	params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
	gadgets.io.makeRequest(url, getFriendListCallback, params);
}
function switchToInvite() {
	switchToInviteByMode("invite_start");
}
function switchToInviteByMode(mode) {
	gInviteMode = mode;
	// mode can be "invite_start" "invite_team" "friend_list" "pending_list"
	document.getElementById('main').style.display = 'none';
	document.getElementById('loading').style.display = 'block';
	document.getElementById('invite').innerHTML = '';
	
	gFriendList = new Array();
	gFriendIncludedIdList = new Array();
	gFriendExcludedIdList = new Array();
	getFriendList();
}
function selectAllFriends() {
	for (var i = 0; i < gFriendList.length; i++) {
		var friendData = gFriendList[i];
		var friendId = friendData.getField(opensocial.Person.Field.ID);	 
		eval('document.friendForm.check' + friendId).checked = true;
	}
}
function deselectAllFriends() {
	for (var i = 0; i < gFriendList.length; i++) {
		var friendData = gFriendList[i];
		var friendId = friendData.getField(opensocial.Person.Field.ID);	 
		eval('document.friendForm.check' + friendId).checked = false;
	}
}
function acceptRejectFriendsCallback(data, url, errored) {
	if (!errored) {
		document.getElementById('friends').innerHTML = '<span class="whitehead">All your friend requests have been processed.</span><br /><a href="javascript:void(0)" onclick="javascript:switchToInviteByMode(\'invite_team\');" class="whiteplain">invite more friends</a><br /><div style="height: 500px;">&nbsp;</div>';
	} 
	else {
		// server error
		document.getElementById('main').style.display = 'none';
		document.getElementById('unavailable').style.display = 'block';
	}
}
function acceptRejectFriends() {
    var friendIds = '';
	for (var i = 0; i < gFriendList.length; i++) { 
		var friendData = gFriendList[i];
		var friendId = friendData.getField(opensocial.Person.Field.ID);	 
		if (eval('document.friendForm.check' + friendId).checked) {
			friendIds += friendId + '|';
		}
	}
	var url = 'http://petfarm.stunme.com/widgets/pet_farm/opensocial/friend/accept_decline_all';
	var params = {};
	var postdata = {};
	postdata['subscriber_id'] = gSubscriberId;
	postdata['sum'] = gSum;
	postdata['accept_user_ids'] = friendIds;
	params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
	params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
	gadgets.io.makeRequest(url, acceptRejectFriendsCallback, params);	
}
function acceptAllFriends() {
    var friendIds = '';
	var url = 'http://petfarm.stunme.com/widgets/pet_farm/opensocial/friend/accept_all';
	var params = {};
	var postdata = {};
	postdata['subscriber_id'] = gSubscriberId;
	postdata['sum'] = gSum;
	params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
	params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);	
	gadgets.io.makeRequest(url, acceptRejectFriendsCallback, params);	
}
function inviteSelectedFriends(mode) {
	document.getElementById('invite_error').style.display = 'none';
	gInviteMode = mode;
	gFriendIdArray = new Array();
	for (var i = 0; i < gFriendList.length; i++) { 
		var friendData = gFriendList[i];
		var friendId = friendData.getField(opensocial.Person.Field.ID);	 
		if (eval('document.friendForm.check' + friendId).checked) {
			gFriendIdArray.push(friendId);
		}
	}
	gFriendIndex = 0;
	if (gFriendIdArray.length == 0) {
		document.getElementById('invite_error').style.display = 'block';
		return;
	}
	inviteNextFriend();
}
function recordInviteCallback(data, url, errored) {
	++gFriendIndex;
	inviteNextFriend();
}
function recordInvite(result) {
	if (result == MyOpenSpace.PostTo.Result.SUCCESS) {
		var url = 'http://petfarm.stunme.com/widgets/pet_farm/opensocial/friend/add';
		var params = {};
		var postdata = {};
		postdata['subscriber_id'] = gSubscriberId;
		postdata['sum'] = gSum;
		postdata['friend_user_id'] = gFriendIdArray[gFriendIndex];
		params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
		params[gadgets.io.RequestParameters.POST_DATA] = gadgets.io.encodeValues(postdata);
		gadgets.io.makeRequest(url, recordInviteCallback, params);		
	}
	else {
		++gFriendIndex;
		inviteNextFriend();
	}
}
function inviteNextFriend() {
	if (gFriendIndex < gFriendIdArray.length) {
		inviteFriend(gFriendIdArray[gFriendIndex], recordInvite);
	}
}

function inviteFriend(userId, callback) {
	var thisFriend = null;
	for (var i = 0; i < gFriendList.length; i++) {
		var friendData = gFriendList[i];
		var friendId = friendData.getField(opensocial.Person.Field.ID);	 	
		if (friendId == userId) {
			thisFriend = friendData;
		}
	};
	if (thisFriend == null) {
		return;
	}
	if (gInviteMode == 'invite_start') {
		var subject = 'A gift for you!';
		var comment = 
	'Hey ' + thisFriend.getField(opensocial.Person.Field.NAME) + ', I have a gift for you! Click to pick it up now!<br /><br />' +
	'<a href="http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=119142" target="_top">' +
	'<img src="http://petfarm.stunme.com/images/pet_farm/gift_sticker.gif" alt="Pick up your gift" border="0" /></a><br />' +
	'<a href="http://www.stunme.com" target="_blank">' +
	'<img src="http://petfarm.stunme.com/images/stunme_comment_bar_250.gif" alt="virtual pets" border="0" /></a>';
		postInvite(subject, comment, thisFriend, 'COMMENTS', callback);
	}
	else {
		var subject = 'Join my virtual pet team!';
		var comment = 
	'Hey ' + thisFriend.getField(opensocial.Person.Field.NAME) + ', join my virtual pet team!<br /><br />' +
	'<a href="http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=119142" target="_top">' +
	'<img src="http://petfarm.stunme.com/images/pet_farm/join_my_team_sticker.gif" alt="Virtual Pets" border="0" /></a><br />' +
	'<a href="http://www.stunme.com" target="_blank">' +
	'<img src="http://petfarm.stunme.com/images/stunme_comment_bar_250.gif" alt="virtual pets" border="0" /></a>';
		postInvite(subject, comment, thisFriend, 'COMMENTS', callback);
	}
}

function invite() {
	var subject = "Do you want my pets?";
	var html = 'Hi,<br />' +
			  'I want to trade my pets.<br /><br />If you don\'t have any pets, <a href="http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=119142" target="_top">click here</a> to start your virtual pet farm.';
	postInvite(subject, html, gViewer, 'BULLETINS', null);
}

function inviteAccessory() {
	var subject = "Check out my new item on Virtual Pet Farm";
	var html = 'Hi,<br />' +
			  'I bought a new item for my pet. Please check it out on my profile.<br /><br /><a href="http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=119142" target="_top">Click here</a> to go to your own virtual pet farm.';
	postInvite(subject, html, gViewer, 'BULLETINS', null);
}

function inviteNewPet() {
	var subject = "Check out my new pet on Virtual Pet Farm";
	var html = 'Hi,<br />' +
			  'I\'ve just got a new pet. Please check it out on my profile.<br /><br /><a href="http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=119142" target="_top">Click here</a> to go to your own virtual pet farm.';
	postInvite(subject, html, gViewer, 'BULLETINS', null);
}

function inviteAndViewInvite() {
	var subject = "Cute virtual pets for you";
	var html = 'Hi,<br />' +
			  '<a href="http://profile.myspace.com/Modules/Applications/Pages/Canvas.aspx?appId=119142" target="_top">Click here</a> to see which pets you\'ve got. Let me know so we can trade.';
	postInvite(subject, html, gViewer, 'BULLETINS', switchToInvite);
}

function postInvite(subject, html, receiver, where, callback) {
	var postType = MyOpenSpace.PostTo.Targets[where];
	var osToken = MyOpenSpace.MySpaceContainer.OSToken;
	var message = opensocial.newMessage(html);
	message.setField(opensocial.Message.Field.TITLE, subject);
	message.setField(opensocial.Message.Field.TYPE, postType);
	opensocial.Container.get().postTo(osToken, message, receiver, callback);	
}

// OFFERS PAGE

function viewOffersCallback(data, url, errored) {
	if (!errored) {
		document.getElementById('invite').innerHTML = data.text;
		document.getElementById('invite').style.display = 'block';
		document.getElementById('loading').style.display = 'none';
	} 
	else {
		// server error
		document.getElementById('unavailable').style.display = 'block';
		document.getElementById('loading').style.display = 'none';
	}
}
function switchToOffers() {
	if (gViewer != undefined) {
		var userId = gViewer.getId();
		document.getElementById('main').style.display = 'none';
		document.getElementById('loading').style.display = 'block';
		document.getElementById('invite').innerHTML = '';
		var	url = 'http://petfarm.stunme.com/widgets/pet_farm/opensocial/offers?user_id=' + userId;
		var params = {};
		params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.GET;
		gadgets.io.makeRequest(url, viewOffersCallback, params);
	}
}
