//Functions to add tags
function addPlaylist(filename, userID){
	playlist_id = $('#existingplaylist').val();

	if(userID > 0  && filename != ''){
		$.ajax({
		   type: "GET",
		   url: "/playlist_ajax.php",
		   data: 'action=add&playlist_id='+playlist_id+'&userID='+userID+'&filename='+filename,
		   success: function(data){
				playlistFormUpdate(data);
		   }
		 });
	}else{
		alert('You Must Login to Add a video to a playlist.');
		$('#playlistname').effect('highlight', "#ff0000", 10000);
		// startcolor: , duration: 10});
	}
}

function addtoNewPlaylist(filename, userID){
	var playlistname = $('#playlistname').val();
 	if(playlistname != ''){
		if(userID > 0  && filename != ''){
			$.ajax({
				type: "GET",
			   	url: "/playlist_ajax.php",
				data: 'action=addtonew&playlistname='+playlistname+'&userID='+userID+'&filename='+filename,
			   	success: function(data){
					playlistFormUpdate(data);
			   	}
			 });
		}else{
			alert('You Must Login to Add a video to a playlist.');
		}
	}else{
		alert('Playlist name cannot be blank.  Please enter a title.');
	}
}


//Need two functions because we can add suggested videos and artists videos from the player page and need to update similar code with same ids
function addPlaylist2(filename, userID){
	var playlist_id = $('#existingplaylist2').val();
	if(userID > 0  && filename != ''){
			$.ajax({
			   type: "GET",
			   url: "/playlist_ajax.php",
			   data: 'action=add&playlist_id='+playlist_id+'&userID='+userID+'&filename='+filename,
			   success: function(data){
					playlistFormUpdate2(data);
			   }
			 });
	}else{
		alert('You Must Login to Add a video to a playlist.');
	}
}

function addtoNewPlaylist2(filename, userID){
	
	var playlistname = $('#playlistname2').val();
	if(playlistname != ''){
		if(userID > 0  && filename != ''){
			$.ajax({
			   type: "GET",
			   url: "/playlist_ajax.php",
			   data: 'action=addtonew&playlistname='+playlistname+'&userID='+userID+'&filename='+filename,
			   success: function(data){
					playlistFormUpdate2(data);
			   }
			 });
		}else{
			alert('You Must Login to Add a video to a playlist.');
		}
	}else{
		alert('Playlist name cannot be blank.  Please enter a title.');
		$('plalylistname2').effect('highlight', {}, 10000);
		//new Effect.Highlight('playlistname2', { startcolor: '#ff0000', duration: 10});
	}
}


function removePlaylist(id, filename, oid, userID, playlist_id){
	if(userID > 0  && oid != '' && filename != ''){
			$.ajax({
			   type: "GET",
			   url: "/playlist_ajax.php",
			   data: 'action=remove&playlist_id='+playlist_id+'&userID='+userID+'&oid='+oid+'&filename='+filename,
			   success: function(data){
					$("li[name='"+id+"']").fadeOut();
			   }
			 });

	}else{
		alert('You Must Login to Remove a video from your playlist.');
	}
}

function deletePlaylist(userID, playlist_id){
	if(userID > 0 ){
		$.ajax({
		   type: "GET",
		   url: "/playlist_ajax.php",
		   data: 'action=delete&playlist_id='+playlist_id+'&userID='+userID,
		   success: function(data){
	   			$('#playlist_'+playlist_id).fadeOut(700);
		   }
		 });
	}else{
		alert('You Must Login to Remove a video from your playlist.');
	}

}

function playlistFormUpdate(data){
	$('#playlistform').hide();
	$('#playlistmessage').text(data);
	setTimeout("parent.$.fn.colorbox.close()", 1500);
}

function playlistFormUpdate2(data){
	$('#playlistform2').hide();
	$('#playlistmessage2').text(data);
	$('#playlistmessage2').effect('highlight', {}, 1500);
	setTimeout("parent.$.fn.colorbox.close()", 1500);
}

