function show_hide(divName)
{
	if (document.getElementById) { obj=document.getElementById(divName) }
	else if (document.all) { obj=document.all[divName]; }
	if (obj) {
		if (obj.style.display == "none") { obj.style.display = '';}
		else { obj.style.display = 'none';}
	}
}

function show(el)
{
	if (document.getElementById) {
		obj = document.getElementById(el)
	} else if (document.all) {
		obj = document.all[el];
	}
	
	if (obj) obj.style.display = '';
}

function hide(el)
{
	if (document.getElementById) {
		obj = document.getElementById(el)
	} else if (document.all) {
		obj = document.all[el];
	}
	
	if (obj) obj.style.display = 'none';
}

function checkAll(name, checked)
{
	$("input[name='" + name + "']").attr('checked', checked);
}

function addToLibrary(songId)
{
	$.get(
		"/my/addtolibrary",
		{'song':songId},
		function(data){
			if (data == '1') {
				alert('Песента е успешно добавена в любими!');
			} else {
				alert('Песента вече е добавена в любими!');
			}
		}
	);
	
	return false;
}


function recordSettings(recordId, visibility, note)
{
	if (visibility == null) visibility = 0;
	if (note == null) note = '';
	
	$("#record_id").val(recordId)
	$("#visibility-" + visibility).attr('checked', 'checked');
	$("#note").val(note);
	$("#dlg-record-settings").dialog('open');
	return false;
}

function checkfld()
{
	p1 = document.getElementById('old_pass').value;
	p2 = document.getElementById('new_pass').value;
	p3 = document.getElementById('conf_pass').value;
	
	if(p1.length < 6){
		alert('Невалидна дължина на Стара парола!');
		return false;
	}
	
	if(p2.length < 6){
		alert('Невалидна дължина на новата парола!');
		return false;
	}

	if(p3.length < 6){
		alert('Невалидна дължина на новата парола!');
		return false;
	}
	
	if(p2 == p3)
	{
		return true;
	}
	else
	{
		alert('Двете пароли не съвпадат!');
		return false;
	}
}

function songVote(songId)
{
	$.get(
		"/karaoke/vote",
		{'song':songId},
		function(data){
			if (data !== '0') {
				alert('Заявката към песента е успешна!');
				document.getElementById('songvote'+songId).innerHTML = data;
			} else {
				alert('Вече сте направили заявка към тази песен.');
			}
		}
	);
	
	return false;
}



function checkuploadsong()
{
	art = document.getElementById('artist').value;
	sng = document.getElementById('song').value;
	ins = document.getElementById('inst').value;
	ori = document.getElementById('orig').value;
	
	if(!art)
	{
		document.getElementById('artisterror').innerHTML = 'Не сте въвели изпълнител';
		return false;
	}
	else document.getElementById('artisterror').innerHTML = '';
	
	if(!sng)
	{ 
		document.getElementById('songerror').innerHTML = 'Не сте въвели име на песен';
		return false;
	}
	else document.getElementById('songerror').innerHTML = '';
	
	if(getExt(ins) != 'mp3') 
	{
		document.getElementById('insterror').innerHTML = 'Инструментала трябва да е в mp3 формат!';
		return false;
	}
	else 
	{
		document.getElementById('insterror').innerHTML = '';
	}
	if(getExt(ori) != 'mp3') 
	{
		document.getElementById('origerror').innerHTML = 'Оригинала трябва да е в mp3 формат!';
		return false;
	}
	else 
	{
		document.getElementById('origerror').innerHTML = '';
	}
	
	if(document.getElementById('text').value == "")
	{
		document.getElementById('txterror').innerHTML = 'Моля добавете текст към песента!';
		return false;
	}
	else
	{
		document.getElementById('txterror').innerHTML = '';
	}

	show_hide('infotxt');
	show_hide('upldform');
	show_hide('preloader');
	
	return true;
}

function getExt(filename) {
   var dot_pos = filename.lastIndexOf(".");
   if(dot_pos == -1)
      return "";
   return filename.substr(dot_pos+1).toLowerCase();
}

function artistCheck(artist)
{
	$.get(
		"admin/request/artistcheck",
		{'artist':artist},
		function(data){
				document.getElementById('songsresults').innerHTML = data;
		}
				);
	return false;
}


