function checkInp()
{
	s_search = document.getElementById("txtSearch");
	s_submit = document.getElementById("cmdSearch");

	if(s_search.value == ""){
		alert("Pls input a word to search!");
		s_search.focus();
		return false;
	}

	s_submit.disabled = true;
	s_submit.value = "Process...";
	return true;
}

function restrictChars(myfield, e)
{
	var key;
	var keychar;

	if (window.event)
		key = window.event.keyCode;
	else if (e)
		key = e.which;
	else
   		return true;	

	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
   	return true;
	// numbers + alphabetic chars
	else if ((("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-.,\"' ").indexOf(keychar) > -1))
   		return true;
	else
		alert("Special character allowed  - . , \" ' and spaces");
		return false;
}

function inject_player(mp3, name)
{
	$.ajax({
   		beforeSend: function(){
			document.getElementById('player1').innerHTML = '<img src="images/player_loading.gif" alt="Loading..." />';
   		},
		type: "GET",
		url: "stream.php",
		data: 'url='+mp3+'&name='+name+'',
		success: function(html){
			document.getElementById('player1').innerHTML = html;
		}
	});
}

function close_player()
{
	$.ajax({
   		beforeSend: function(){
			document.getElementById('player1').innerHTML = '<img src="images/player_loading.gif" alt="Loading..." />';
   		},
		complete: function(){
			document.getElementById('player1').innerHTML = '';
		}
	});
}

function LoadContent(pf1, pf2, pf3)
{
	$.get("display.php", { q: pf1, src: pf2, page: pf3 },
		function(html){
			$('#' + pf2 + '').replaceWith(html);
		}
	);
}

function LoadContentVideo(pf1, pf2, pf3, pf4)
{
	$.get("display.php", { q: pf1, src: pf2, page: pf3, type: pf4 },
		function(html){
			$('#' + pf2 + '').replaceWith(html);
		}
	);
}

function alert_disable_dl()
{
	alert("Currently Disabled!");
}

function alert_disable_guest_dl()
{
	alert("Pls Login to Download!");
}

function alert_add_playlist()
{
	alert("Pls Login to Add song in your Playlist!");
}

function alert_add_video()
{
	alert("Pls Login to Add video in your Playlist!");
}

function addMP3(add)
{
	var answer = confirm("Are you sure you want to add this in your MP3 playlist?")
	if (answer)
	{
		doAddMP3(add);
	}
	
	function doAddMP3(add)
	{
		$.ajax({
   			beforeSend: function(){
				document.getElementById(add).innerHTML = 'Adding';
   			},
			type: "GET",
			url: "index.php?p=addsong",
			data: '&' + add + '',
			async: false,
			success: function(msg){
				document.getElementById(add).innerHTML = '<img src="images/check.png" alt="Added" />';
				alert("Success!");
			}
 		});
	}
}

function deleteMP3(remove)
{
	var answer = confirm("Are you sure you want to delete this Song?")
	if (answer)
	{
		doRemoveMP3(remove);
	}
	
	function doRemoveMP3(remove)
	{
		$.ajax({
   			beforeSend: function(){
				document.getElementById(remove).innerHTML = 'Deleting';
   			},
			type: "GET",
			url: "index.php?p=removesong",
			data: '&id=' + remove + '',
			async: false,
			success: function(msg){
				document.getElementById(remove).innerHTML = 'Deleted';
				alert("Success!");
			}
 		});
	}
}

function addVideo(add)
{
	var answer = confirm("Are you sure you want to add this in your Video playlist?")
	if (answer)
	{
		doAddVideo(add);
	}
	
	function doAddVideo(add)
	{
		$.ajax({
   			beforeSend: function(){
				document.getElementById(add).innerHTML = 'Adding';
   			},
			type: "GET",
			url: "index.php?p=addvideo",
			data: '&' + add + '',
			async: false,
			success: function(msg){
				document.getElementById(add).innerHTML = '<img src="images/check.png" alt="Added" />';
				alert("Success!");
			}
 		});
	}
}

function deleteVideo(remove)
{
	var answer = confirm("Are you sure you want to delete this Video?")
	if (answer)
	{
		doRemoveVideo(remove);
	}
	
	function doRemoveVideo(remove)
	{
		$.ajax({
   			beforeSend: function(){
				document.getElementById(remove).innerHTML = 'Deleting';
   			},
			type: "GET",
			url: "index.php?p=removevideo",
			data: '&id=' + remove + '',
			async: false,
			success: function(msg){
				document.getElementById(remove).innerHTML = 'Deleted';
				alert("Success!");
			}
 		});
	}
}