function getMyCollectionList(strUserID, type, searchKeyword,sortBy, page)
{
	if (page == undefined)
	{
		page = 0;
	}
	if (searchKeyword == undefined)
	{
		searchKeyword = "";
	}
	if (sortBy == undefined)
	{
		sortBy = "LATEST";
	}
	$.ajax({
		type: "POST",
		url: HTTP_SERVER+DIR_WS_HTTP+"ajaxMyCollection.php",
		data: "actionType=GET_MY_COLLECTION_"+type+"&strUserID="+strUserID+"&searchKeyword="+searchKeyword+"&sortBy="+sortBy+"&page="+page,

		success: function(msg){
			$('#my'+type).empty();
			$('#my'+type).html(msg);
		}
	});
}

function removeFromCollection(strCollID, strUserID, type, typeID, page)
{
	var txt = "Are you sure you want to remove "+ type +" from collection";
	$.prompt(txt,{		
		buttons:{Ok:-1,Cancel:0},
		submit:function(v,m,f){
			if(v == 0)
			{
				jQuery.ImpromptuClose();
			}
			else if(v == -1)
			{
				jQuery.ImpromptuClose();
				var objForm = document.frmMyCollectionSort;
				var searchKeyword = objForm.txtSortBy.value;
				var sortBy = objForm.cmbSortBy.value;
				if (page == undefined)
				{
					page = 0;
				}
				$.ajax({
					type: "POST",
					url: HTTP_SERVER+DIR_WS_HTTP+"ajaxMyCollection.php",
					data: "actionType=REMOVE_FROM_COLLECTION&strUserID="+strUserID+"&strCollID="+strCollID+"&type="+type+"&typeID="+typeID,
					success: function(msg){
						if (msg == 1)
						{
							var txt = '<img src="../../images/icons/check.png" width="64" height="64" border="0" alt="" align="absmiddle">Successfully removed from collection.';
							alertBox(txt, false);
							getMyCollectionList(strUserID, type, searchKeyword, sortBy, page);
						}
					}
				});
			}
			return false;
		}
	});	
}

function sortMyCollection(objForm, userID, selectedVal)
{
	var chkAllFlag = false;
	var searchKeyword = objForm.txtSortBy.value;
	var sortBy = objForm.cmbSortBy.value;
	var arrFrmElements = objForm.elements;
	
	if (sortBy == undefined)
	{
		sortBy = "LATEST";
	}

	if (selectedVal == undefined)
	{
		selectedVal = 'All';
	}

	if ($("input:checked").length > 0)
	{
		for (cntChk = 0 ; cntChk < arrFrmElements.length; cntChk++ )
		{
			if (arrFrmElements[cntChk].type == 'checkbox')
			{
				if (arrFrmElements[cntChk].value == "ALL" && arrFrmElements[cntChk].checked == true )
				{					
					chkAllFlag = true;
					if (selectedVal == 'All')
					{
						objForm.chkThemes.checked = false;
						objForm.chkWallpapers.checked = false;
						objForm.chkRingtones.checked = false;
					}
					else
					{
						objForm.chkAll.checked = false;
						chkAllFlag = false;
					}
				}
			}
		}
	}
	else
	{
		chkAllFlag = true;
	}


	if (chkAllFlag == true)
	{
		getMyCollectionList(userID, 'THEMES', searchKeyword, sortBy);
		getMyCollectionList(userID, 'WALLPAPERS', searchKeyword, sortBy);
		getMyCollectionList(userID, 'RINGTONES', searchKeyword, sortBy);
	}
	else
	{
		$("#myTHEMES").empty();
		$("#myWALLPAPERS").empty();
		$("#myRINGTONES").empty();

		for (cntChk = 0 ; cntChk < arrFrmElements.length; cntChk++ )
		{
			if (arrFrmElements[cntChk].type == 'checkbox')
			{
				if (arrFrmElements[cntChk].checked == true)
				{
					getMyCollectionList(userID, arrFrmElements[cntChk].value, searchKeyword,sortBy);
				}
			}
		}
	}
}