// JavaScript Document
function show_menu()
{
	document.getElementById("menu").style.display = "block";
}
function hide_menu()
{
	document.getElementById("menu").style.display = "none";
}
function init()
{
	gc();
}
function clearselectie()
{
	if (confirm('Do you want to empty the list?'))
	{
		eraseCookie('akkoorden');
		var ch = document.getElementById("cookie_holder");
		ch.innerHTML = "";	
		ch.style.display = "none";
	}
}
function toonmijnselectie()
{
	gc();
}
function gc()
{   
  var ch = document.getElementById("cookie_holder");
  if (readCookie("akkoorden") != null)
   {
	   cookie_array = readCookie("akkoorden").split("&");	   
	   ch.style.display = "block";
	   html_str = '<div id="selectie"><div id="selectieheader" onclick="clearselectie();">X</div>';
	   for (i=0;i<cookie_array.length;i++)
	   {
			str = cookie_array[i];
			str2 = str.split(":").join('<div class="k">');
			html_str += '<div onclick="remove(' + i + ');">' + str2 + '</div></div>';
	   }
	   ch.innerHTML = html_str + "<div class='comment'>Click on a chordname to delete.</div></div>";
   }
   else
   {
		ch.innerHTML = "<div class='comment'>On the chords-pages you can click on chordnames to add the chord to the selection.</div>";
   }
} 
function trim_it(str)
{
	return (str.replace(/^\s+|\s+$/g, ''));
}
function sc(elem)
{   
	var str = elem.innerHTML;
	var str1 = str.split('<div class="k">');
	if (str1.length > 1)
	{
		str3 = str1[1].split('</div>')[0];
		str2 = str1[0];		
	}
	else
	{
		str1 = str.split('<DIV class=k>');
		str3 = str1[1].split('</DIV>')[0];
		str2 = str1[0];	
	}
	var tot_str = trim_it(str2) + ":" + trim_it(str3);
	//alert(tot_str);
	if (readCookie("akkoorden") != null)
    {
		var cookie_str = readCookie("akkoorden");
	}
	else
	{
		var cookie_str = "";
	}
	if (cookie_str.indexOf(tot_str) == -1)
	{
		if (cookie_str == "")
		{
			cookie_array = new Array(tot_str);
		}				
		else
		{
			cookie_array = cookie_str.split("&");
			if (cookie_array.length > 15)
			{
				cookie_array.unshift(tot_str);	
				cookie_array.pop();					
			}
			else
			{
				cookie_array.unshift(tot_str);
			}
		}
	}
	tot_str = cookie_array.join("&");
	createCookie("akkoorden", tot_str, 365);
	//gc();
}
function remove(index)
{
   if (confirm('Do you want to remove the chord from the list?'))
   {
	   cookie_array = readCookie("akkoorden").split("&");
	   var ch = document.getElementById("cookie_holder");
	   html_str = '<div id="selectie"><div id="selectieheader" onclick="clearselectie();">X</div>';
	   var cookie_array2 = new Array();
	   var j = 0;
	   if (cookie_array.length == 1)
	   {
			clearselectie();
	   }
	   else
	   {
		   for (i=0;i<cookie_array.length;i++)
		   {
				if (i != index)
				{
					str = cookie_array[i];
					cookie_array2.push(str);
					str2 = str.split(":").join('<div class="k">');
					html_str += '<div onclick="remove(' + j + ');">' + str2 + '</div></div>';
					j++;
				}
		   }
		   tot_str = cookie_array2.join("&");
		   createCookie("akkoorden", tot_str, 365);  
		   ch.innerHTML = html_str + '</div>';
	   }
   }
}
