//Functions to add tags
function addPlaylist(filename, userID){
	var existingplaylist = document.getElementById('existingplaylist');
	playlist_id = existingplaylist.value;

	if(userID > 0  && filename != ''){
		var opt = {
			// Use POST
			method: 'get',
			// Send this lovely data
			// Handle successful response
			onComplete: function(t){ 
				playlistFormUpdate(t);
			},		
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}
		}
		new Ajax.Request('/playlist_ajax.php?action=add&playlist_id='+playlist_id+'&userID='+userID+'&filename='+filename, opt);
	}else{
		alert('You Must Login to Add a video to a playlist.');
		new Effect.Highlight('playlistname', { startcolor: '#ff0000', duration: 10});
	}


}

function addtoNewPlaylist(filename, userID){
	var playlistname = document.getElementById('playlistname');
	playlistname = encodeURIComponent(playlistname.value);
	if(playlistname != ''){
		if(userID > 0  && filename != ''){
			var opt = {
				// Use POST
				method: 'get',
				// Send this lovely data
				// Handle successful response
				onComplete: function(t){ 
					playlistFormUpdate(t);
				},		
				// Handle other errors
				onFailure: function(t) {
					alert('Error ' + t.status + ' -- ' + t.statusText);
				}
			}
			new Ajax.Request('/playlist_ajax.php?action=addtonew&playlistname='+playlistname+'&userID='+userID+'&filename='+filename, opt);
		}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 existingplaylist = document.getElementById('existingplaylist2');
	playlist_id = existingplaylist.value;

	if(userID > 0  && filename != ''){
		var opt = {
			// Use POST
			method: 'get',
			// Send this lovely data
			// Handle successful response
			onComplete: function(t){ 
				playlistFormUpdate2(t);
			},		
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}
		}
		new Ajax.Request('/playlist_ajax.php?action=add&playlist_id='+playlist_id+'&userID='+userID+'&filename='+filename, opt);
	}else{
		alert('You Must Login to Add a video to a playlist.');
	}


}

function addtoNewPlaylist2(filename, userID){
	var playlistname = document.getElementById('playlistname2');
	playlistname = encodeURIComponent(playlistname.value);
	if(playlistname != ''){
		if(userID > 0  && filename != ''){
			var opt = {
				// Use POST
				method: 'get',
				// Send this lovely data
				// Handle successful response
				onComplete: function(t){ 
					playlistFormUpdate2(t);
				},		
				// Handle other errors
				onFailure: function(t) {
					alert('Error ' + t.status + ' -- ' + t.statusText);
				}
			}
			new Ajax.Request('/playlist_ajax.php?action=addtonew&playlistname='+playlistname+'&userID='+userID+'&filename='+filename, opt);
		}else{
			alert('You Must Login to Add a video to a playlist.');
		}
	}else{
		alert('Playlist name cannot be blank.  Please enter a title.');
		new Effect.Highlight('playlistname2', { startcolor: '#ff0000', duration: 10});
	}

}


function removePlaylist(id, filename, oid, userID, playlist_id){
	if(userID > 0  && oid != '' && filename != ''){
		var opt = {
			// Use POST
			method: 'get',
			// Send this lovely data
			// Handle successful response
			onComplete: function(t){ 
				//alert(t.responseText);
				Effect.Fade(id, {duration: .7});
				
				//var row = document.getElementById(id);
				//row.style.display = 'none';
			},		
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}
		}
		new Ajax.Request('/playlist_ajax.php?action=remove&playlist_id='+playlist_id+'&userID='+userID+'&oid='+oid+'&filename='+filename, opt);
	}else{
		alert('You Must Login to Remove a video from your playlist.');
	}
}

function deletePlaylist(userID, playlist_id){
	if(userID > 0 ){
		var opt = {
			// Use POST
			method: 'get',
			// Send this lovely data
			// Handle successful response
			onComplete: function(t){ 
				Effect.Fade('playlist_'+playlist_id);
			},		
			// Handle other errors
			onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			}
		}
		new Ajax.Request('/playlist_ajax.php?action=delete&playlist_id='+playlist_id+'&userID='+userID, opt);
	}else{
		alert('You Must Login to Remove a video from your playlist.');
	}

}

function playlistFormUpdate(t){
	var playlistform = document.getElementById('playlistform');
	playlistform.style.display = "none";
	var playlistmessage = document.getElementById('playlistmessage');
	playlistmessage.innerHTML = t.responseText;
	
}

function playlistFormUpdate2(t){
	var playlistform2 = document.getElementById('playlistform2');
	playlistform2.style.display = "none";
	var playlistmessage2 = document.getElementById('playlistmessage2');
	playlistmessage2.innerHTML = t.responseText;
	new Effect.Highlight('playlistmessage2', {duration: 1.5} );
	setTimeout("myLightWindow.deactivate()", 1500);
	
}