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!");
			}
 		});
	}
}

function on_login()
{
	uname_login = document.getElementById("username");
	pass_login = document.getElementById("password");
	uname_login.disabled = true;
	pass_login.disabled = true;
	//remove all the class add the messagebox classes and start fading
	$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
	//check the username exists or not from ajax
	$.post("index.php?p=do_login",{ username:$('#username').val(),password:$('#password').val(),remember:$('#remember').val,rand:Math.random() } ,
		function(data)
		{
			if(data!='success')
			{
				$("#msgbox").fadeTo(200,0.1,
					function() //start fading the messagebox
					{ 
						//add message and change the class of the box and start fading
						$(this).html(data).addClass('messageboxerror').fadeTo(900,1);
					}
				);
				uname_login.disabled = false;
				pass_login.disabled = false;
			}
			else 
			{
				$("#msgbox").fadeTo(200,0.1,
					function()  //start fading the messagebox
					{ 
						//add message and change the class of the box and start fading
						$(this).html('Loggin in...').addClass('messageboxok').fadeTo(900,1,
							function()
							{ 
								//redirect to secure page
								document.location='index.php?p=myaccount';
							}
						);
					}
				);
			}		
		}
	);
	return false; //not to post the  form physically
}

function on_editp()
{
	_email = document.getElementById("email");
	_fullname = document.getElementById("fullname");
	_site = document.getElementById("site");
	_country = document.getElementById("country");
	_city = document.getElementById("city");
	_tel = document.getElementById("tel");
	_profile = document.getElementById("profile");
	_email.disabled = true;
	_fullname.disabled = true;
	_site.disabled = true;
	_country.disabled = true;
	_city.disabled = true;
	_tel.disabled = true;
	_profile.disabled = true;
	//remove all the class add the messagebox classes and start fading
	$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
	//check the username exists or not from ajax
	$.post("index.php?p=do_editaccount",{ email:$('#email').val(),fullname:$('#fullname').val(),site:$('#site').val(),country:geoip_country_name(),city: geoip_city(),tel:$('#tel').val(),profile:$('#profile').val(),rand:Math.random() } ,
		function(data)
		{
			if(data!='success')
			{
				$("#msgbox").fadeTo(200,0.1,
					function() //start fading the messagebox
					{ 
						//add message and change the class of the box and start fading
						$(this).html(data).addClass('messageboxerror').fadeTo(900,1);
					}
				);
				_email.disabled = false;
				_fullname.disabled = false;
				_site.disabled = false;
				_country.disabled = false;
				_city.disabled = false;
				_tel.disabled = false;
				_profile.disabled = false;
			}
			else 
			{
				$("#msgbox").fadeTo(200,0.1,
					function()  //start fading the messagebox
					{ 
						//add message and change the class of the box and start fading
						$(this).html('Your information has been successfully changed.').addClass('messageboxok').fadeTo(900,1,
							function()
							{ 
								//redirect to secure page
								document.location='index.php?p=myaccount';
							}
						);
					}
				);
			}		
		}
	);
	return false; //not to post the  form physically
}

function on_changep()
{
	_old_pwd = document.getElementById("old_pwd");
	_new_pwd1 = document.getElementById("new_pwd1");
	_new_pwd2 = document.getElementById("new_pwd2");
	_old_pwd.disabled = true;
	_new_pwd1.disabled = true;
	_new_pwd2.disabled = true;
	//remove all the class add the messagebox classes and start fading
	$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
	//check the username exists or not from ajax
	$.post("index.php?p=do_changepwd",{ old_pwd:$('#old_pwd').val(),new_pwd1:$('#new_pwd1').val(),new_pwd2:$('#new_pwd2').val(),rand:Math.random() } ,
		function(data)
		{
			if(data!='success')
			{
				$("#msgbox").fadeTo(200,0.1,
					function() //start fading the messagebox
					{ 
						//add message and change the class of the box and start fading
						$(this).html(data).addClass('messageboxerror').fadeTo(900,1);
					}
				);
				_old_pwd.disabled = false;
				_new_pwd1.disabled = false;
				_new_pwd2.disabled = false;
			}
			else 
			{
				$("#msgbox").fadeTo(200,0.1,
					function()  //start fading the messagebox
					{ 
						//add message and change the class of the box and start fading
						$(this).html('Password has successfully change.').addClass('messageboxok').fadeTo(900,1,
							function()
							{ 
								//redirect to secure page
								document.location='index.php?p=login';
							}
						);
					}
				);
			}		
		}
	);
	return false; //not to post the  form physically
}

function do_register()
{
	//remove all the class add the messagebox classes and start fading
	$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
	//check the username exists or not from ajax
	$.post("index.php?p=do_register",{ username:$('#username').val(), password:$('#password').val(), password2:$('#password2').val(), email:$('#email').val(), country:geoip_country_name(), city:geoip_city(), fullname:$('#fullname').val(), rand:Math.random() } ,
		function(data)
		{
			if(data!='register1' && data!='register2' && data!='register-1' && data!='register-2')
			{
				$("#msgbox").fadeTo(200,0.1,
					function() //start fading the messagebox
					{ 
						//add message and change the class of the box and start fading
						$(this).html(data).addClass('messageboxerror').fadeTo(900,1);
					}
				);
			}
			else 
			{
				if(data=='register1')
				{
					$("#msgbox").fadeTo(200,0.1,
						function() //start fading the messagebox
						{ 
							//add message and change the class of the box and start fading
							$(this).html("Registration was successfull.<br /> you can now login.").addClass('messageboxok').fadeTo(900,1);
						}
					);
				}
				else if(data=='register2')
				{
					$("#msgbox").fadeTo(200,0.1,
						function() //start fading the messagebox
						{ 
							//add message and change the class of the box and start fading
							$(this).html("Registration was successfull.<br /> Please go and check your email. <br /> You'll find how to activate your account.").addClass('messageboxok').fadeTo(900,1);
						}
					);
				}
				else if(data=='register-1')
				{
					$("#msgbox").fadeTo(200,0.1,
						function() //start fading the messagebox
						{ 
							//add message and change the class of the box and start fading
							$(this).html("<font class=\"error\">Faild sending registration email,<br /> please report this to the webmaster</font><br /> Registration was successfull.<br /> you can now login.").addClass('messageboxok').fadeTo(900,1);
						}
					);
				}
				else
				{
					$("#msgbox").fadeTo(200,0.1,
						function() //start fading the messagebox
						{ 
							//add message and change the class of the box and start fading
							$(this).html("<font class=\"error\">Faild sending registration email,<br /> please report this to the webmaster</font><br /> Registration was successfull.<br> Please go and check your email.<br> You'll find how to activate your account.").addClass('messageboxok').fadeTo(900,1);
						}
					);
				}
			}		
		}
	);
	return false; //not to post the  form physically
}

function on_forgotp()
{
	uname_forgotp = document.getElementById("username");
	pass_forgotp = document.getElementById("email");
	uname_forgotp.disabled = true;
	pass_forgotp.disabled = true;
	//remove all the class add the messagebox classes and start fading
	$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
	//check the username exists or not from ajax
	$.post("index.php?p=do_forgotpwd",{ username:$('#username').val(),email:$('#email').val(),rand:Math.random() } ,
		function(data)
		{
			if(data!='success')
			{
				$("#msgbox").fadeTo(200,0.1,
					function() //start fading the messagebox
					{ 
						//add message and change the class of the box and start fading
						$(this).html(data).addClass('messageboxerror').fadeTo(900,1);
					}
				);
				uname_forgotp.disabled = false;
				pass_forgotp.disabled = false;
			}
			else 
			{
				$("#msgbox").fadeTo(200,0.1,
					function()  //start fading the messagebox
					{ 
						//add message and change the class of the box and start fading
						$(this).html('New password has been sent to your email.').addClass('messageboxok').fadeTo(900,1,
							function()
							{ 
								//redirect to secure page
								document.location='index.php?p=login';
							}
						);
					}
				);
			}		
		}
	);
	return false; //not to post the  form physically
}


function onfocus_hide()
{
	$("#msgbox").hide("slow");
}