
var url = '/ajax/playlists.do?fChannelId=' + fChannelId;
if(fArtistId != null) url+= '&fArtistId=' + fArtistId;
url += '&aCmd=';

var ITEM_ID = 'iId='; 
var TYPE = 'type='; // 1 = Track, 2 = Video
var PLAYLIST_ID = 'pId=';
var PRODUCT_TYPE_ID = 'productType=';
var PLAYLIST_NAME = 'pName=';
 
function addItemToPlaylist(plId, itemId, productType)
{
 	requestData(url + '15&' +  ITEM_ID + itemId + '&' + PLAYLIST_ID + plId + '&' + PRODUCT_TYPE_ID + productType);
}
 
function createPlaylistAndAddItem(plName, itemId, productType, isFopl)
{
 	var newPlaylist = requestData(url + '15&' +  ITEM_ID + itemId + '&' + PLAYLIST_NAME + plName + '&' + PRODUCT_TYPE_ID + productType + '&isFopl=' + isFopl);
 	return newPlaylist;
}

function requestData(url)
{
	error = false;
	var returnObj = performAjaxRequest(url);
		
	if(returnObj.errorCode != 0)
	{
		// Set error message
		setError(returnObj);
		error=true;
	}
	else
	{
		return returnObj.response;
	}
}

function setError(returnObj)
{
	if(returnObj.errorMessage != null)
	{
		if(returnObj.errorCode == 10003)
			login();
		else
			popModal(returnObj.errorMessage,400,200,message['title'],'ok',null);
	}
	else
		popModal(message['unknownError'],400,200,message['title'],'ok',null);
		
	if(window.event) window.event.cancelBubble = true;	
}