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

	if(s_search.value == ""){
		alert("Prosimo vpisite kljucno besedo za iskanje!");
		s_search.focus();
		return false;
	}

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

function alert_download()
{
	alert("Za nemoteno prenasanje datotek iz strani, si prosimo vzemite nekaj trenutkov in prispevajte svoje mnenje na nasem forumu. Potrebni sta minimalno dve objavi za nadaljevanje prenasanja pesmi!");
}
/*
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 ((("0123456789abccddefghijklmnopqrsatuvwxyzABCCDEFGHIJKLMNOPQRSTUVWXYZ\! ").indexOf(keychar) > -1))
   		return true;
	else
		alert("Posebni znaki niso dovoljeni!");
		return false;
}
*/
function inject_radio()
{
	$.ajax({
   		beforeSend: function(){
			document.getElementById('player1').innerHTML = '<img src="/images/player_loading.gif"/>';
   		},
		url: "/radio.php",
		success: function(html){
			document.getElementById('player1').innerHTML = html;
		}
	});
}

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

function inject_player2(mp3, name)
{
	$.ajax({
   		beforeSend: function(){
			document.getElementById('player1').innerHTML = '<img src="/images/player_loading.gif" alt="Nalaganje..." />';
   		},
		type: "GET",
		url: "/streamyt.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="Nalaganje..." />';
   		},
		complete: function(){
			document.getElementById('player1').innerHTML = '';
		}
	});
}

function inject_getdata(link)
{
	$.ajax({
   		beforeSend: function(){
			document.getElementById('player1').innerHTML = '<font style=\"background-color:#555;color:#fff;\"><b>Pridobivanje podatkov!</b></font><img src="/images/player_loading.gif"/>';
   		},
		type: "GET",
		url: "/getdata.php",
		data: 'link='+link+'',
		success: function(html){
			document.getElementById('player1').innerHTML = html;
		}
	});
}
function close_getdata()
{
	$.ajax({
   		beforeSend: function(){
			document.getElementById('player1').innerHTML = '<img src="/images/player_loading.gif" alt="Nalaganje..." />';
   		},
		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("Trenutno ni omogoceno!");
}

function alert_disable_guest_dl()
{
	alert("Za prenos pesmi se prosimo prijavite oz. brezplacno registrirajte (povsem desno zgoraj).\nVzelo vam bo manj kot minuto casa!\n\nOb naslednjem obisku Mp3centra boste tako ze avtomatsko prijavljeni na stran in uporaba vseh funkcij bo zato hitra in preprosta.");
}

function alert_add_playlist()
{
	alert("Za dodajanje pesmi na playlisto se prosimo prijavite oz. brezplacno registrirajte (povsem desno zgoraj).\nVzelo vam bo manj kot minuto casa!\n\nOb naslednjem obisku Mp3centra boste tako ze avtomatsko prijavljeni na stran in uporaba vseh funkcij bo zato hitra in preprosta.");
}

function alert_add_video()
{
	alert("Za dodajanje videa na playlisto se prosimo prijavite oz. brezplacno registrirajte (povsem desno zgoraj).\nVzelo vam bo manj kot minuto casa!\n\nOb naslednjem obisku Mp3centra boste tako ze avtomatsko prijavljeni na stran in uporaba vseh funkcij bo zato hitra in preprosta.");
}

function addMP3(add)
{
	var answer = confirm("Potrdite, da zelite dodati pesem na playlisto.")
	if (answer)
	{
		doAddMP3(add);
	}
	
	function doAddMP3(add)
	{
		$.ajax({
   			beforeSend: function(){
				document.getElementById(add).innerHTML = 'Dodajanje...';
   			},
			type: "GET",
			url: "/index.php?p=addsong",
			data: '&' + add + '',
			async: false,
			success: function(msg){
				document.getElementById(add).innerHTML = '<img src="/images/check.png" alt="Dodano" />';
				alert("Opravljeno!");
			}
 		});
	}
}

function deleteMP3(remove)
{
	var answer = confirm("Ste prepricani?")
	if (answer)
	{
		doRemoveMP3(remove);
	}
	
	function doRemoveMP3(remove)
	{
		$.ajax({
   			beforeSend: function(){
				document.getElementById(remove).innerHTML = 'Odstranjujem';
   			},
			type: "GET",
			url: "/index.php?p=removesong",
			data: '&id=' + remove + '',
			async: false,
			success: function(msg){
				document.getElementById(remove).innerHTML = 'Odstranjeno';
				alert("Opravljeno!");
			}
 		});
	}
}

function addVideo(add)
{
	var answer = confirm("Ste prepricani?")
	if (answer)
	{
		doAddVideo(add);
	}
	
	function doAddVideo(add)
	{
		$.ajax({
   			beforeSend: function(){
				document.getElementById(add).innerHTML = 'Dodajam';
   			},
			type: "GET",
			url: "/index.php?p=addvideo",
			data: '&' + add + '',
			async: false,
			success: function(msg){
				document.getElementById(add).innerHTML = '<img src="/images/check.png" alt="Dodano" />';
				alert("Opravljeno!");
			}
 		});
	}
}

function deleteVideo(remove)
{
	var answer = confirm("Ste prepricani?")
	if (answer)
	{
		doRemoveVideo(remove);
	}
	
	function doRemoveVideo(remove)
	{
		$.ajax({
   			beforeSend: function(){
				document.getElementById(remove).innerHTML = 'Odstranjujem';
   			},
			type: "GET",
			url: "/index.php?p=removevideo",
			data: '&id=' + remove + '',
			async: false,
			success: function(msg){
				document.getElementById(remove).innerHTML = 'Odstranjeno';
				alert("Opravljeno!");
			}
 		});
	}
}

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('Preverjanje....').fadeIn(1000);
	//check the username exists or not from ajax
	$.post("/index.php?p=do_login",{ username:$('#username').val(),password:$('#password').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('Prijava v sistem...').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");
	_avatar = document.getElementById("avatar");
	_showprofile = document.getElementById("showprofile");
	_showplaylist = document.getElementById("showplaylist");
	_tel = document.getElementById("tel");
	_sig = document.getElementById("sig");
	_profile = document.getElementById("profile");
	_gender = document.getElementById("gender");
	_email.disabled = true;
	_fullname.disabled = true;
	_site.disabled = true;
	_country.disabled = true;
	_city.disabled = true;
	_avatar.disabled = true;
	_showprofile.disabled = true;
	_showplaylist.disabled = true;
	_tel.disabled = true;
	_sig.disabled = true;
	_profile.disabled = true;
	_gender.disabled = true;
	//remove all the class add the messagebox classes and start fading
	$("#msgbox").removeClass().addClass('messagebox').text('Preverjanje....').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:$('#country').val(),city:$('#city').val(),avatar:$('#avatar').val(), showprofile:$('#showprofile').val(), showplaylist:$('#showplaylist').val(), tel:$('#tel').val(),sig:$('#sig').val(), profile:$('#profile').val(), gender:$('#gender').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;
				_avatar.disabled = false;
				_showprofile.disabled = false;
				_showplaylist.disabled = false;
				_tel.disabled = false;
				_sig.disabled = false;
				_profile.disabled = false;
				_gender.disabled = false;
			}
			else 
			{
				$("#msgbox").fadeTo(800,0.1,
					function()  //start fading the messagebox
					{ 
						//add message and change the class of the box and start fading
						$(this).html('Podatki so bili uspesno shranjeni.').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('Preverjanje....').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('Geslo je bilo uspesno spremenjeno.').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('Preverjanje, prosimo pocakajte....').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(), fullname:$('#fullname').val(), gender:$('#gender').val(), ip:$('#ip').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("Registracija je bila uspesno zakljucena,<br /> sedaj se lahko prijavite v sistem (povsem zgoraj desno).").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("Registracija je bila uspe&#353;na.<br /> Na vas email smo poslali sporocilo, v katerem je povezava za aktivacijo vasega racuna. Ne pozabite preveriti tudi spam mape!").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\">Napaka pri posiljanju aktivacijskega sporocila na vas email naslov,<br /> prosimo sporocite to administratorju strani!</font><br /> Registracija je bila uspesno zakljucena,<br /> sedaj se lahko prijavite v sistem.").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\">Napaka pri posiljanju aktivacijskega sporocila na vas email naslov,<br /> prosimo sporocite to administratorju strani!</font><br /> Registracija je bila uspe&#353;no zaklju&#269;ena.").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");
	coptcha_forgotp = document.getElementById("coptcha");
	sumrand_forgotp = document.getElementById("sumrand");
	uname_forgotp.disabled = true;
	pass_forgotp.disabled = true;
	coptcha_forgotp.disabled = true;
	sumrand_forgotp.disabled = true;
	//remove all the class add the messagebox classes and start fading
	$("#msgbox").removeClass().addClass('messagebox').text('Preverjanje....').fadeIn(1000);
	//check the username exists or not from ajax
	$.post("/index.php?p=do_forgotpwd",{ username:$('#username').val(),email:$('#email').val(),coptcha:$('#coptcha').val(),sumrand:$('#sumrand').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;
				coptcha_forgotp.disabled = false;
				sumrand_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('Novo geslo je bilo poslano na vas email naslov. Preverite tudi spam mapo!.').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");
}
