
var xmlHttp
function nextSong(id)
{
var current = id;
if(current<10)
{
	current="0"+id;
}
//alert(current);
var reihenfolge = getCookie('playlist_user');
//alert(reihenfolge);
var length = reihenfolge.length/2;
//alert(length);
var a = 0;
var found = false;
while(length>0)
{
	if((reihenfolge[a]+reihenfolge[a+1])==current)
		{
			//alert(a);
			if(a+2==reihenfolge.length)
			{
				//alert(a+2);
				id = reihenfolge[0] + reihenfolge[1];
			}else{
				id = (reihenfolge[a+2]+""+reihenfolge[a+3]);
			}
		}
	length = length - 1;
	a=a+2;
}
//alert(id);
hidePlaySymbol(reihenfolge.length/2);
document.getElementById("playSign"+id).style.visibility="visible";

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var site="../javascripts/playsong";
url=site+".php";
url=url+"?id="+id;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedSong;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}



function previousSong(id)
{
var current = id;
if(current<10)
{
	current="0"+id;
}
//alert(current);
var reihenfolge = getCookie('playlist_user');
//alert(reihenfolge);
var length = reihenfolge.length/2;
var a = 0;
var found = false;
if((reihenfolge[a]+reihenfolge[a+1])==current){
	id = reihenfolge[reihenfolge.length-2]+reihenfolge[reihenfolge.length-1];
	found = true;
	//alert(found);
}else{
	a = a +2;
	length=length-1;
}
while(length>=0 && found == false)
{
	if((reihenfolge[a]+reihenfolge[a+1])==current)
		{
			id = (reihenfolge[a-2]+""+reihenfolge[a-1]);
			
		}
	length = length - 1;
	a=a+2;
}
//alert(id);
hidePlaySymbol(reihenfolge.length/2);
document.getElementById("playSign"+id).style.visibility="visible";

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
var site="../javascripts/playsong";
url=site+".php";
url=url+"?id="+id;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedSong;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}




function stateChangedSong() 
{ 
if (xmlHttp.readyState==4)
{ 
document.getElementById("playlist_head").innerHTML=xmlHttp.responseText;
}
}


function playPlaylistSong(id)
{
xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  }
  var reihenfolge = getCookie("playlist_user");
hidePlaySymbol(reihenfolge.length/2);
if(id<10)
{
	id="0"+id;
}
document.getElementById("playSign"+id).style.visibility="visible";

var site="../javascripts/playsong";
url=site+".php";
url=url+"?id="+id;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChangedSong;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function playlist_update(data)
{
	//alert(data);
	//var number = new Array();
	var nummer = "";
	var length = data.length -1;
	var zaehler = 1;
	var counter = 25;
	nummer = nummer + data[11] + data[12];
	//alert(nummer);
	//number[0] = data[11] + data[12];
	length = length - 12;
	while(length>0)
	{
	nummer = nummer + data[counter] + data[counter + 1];
	//number[zaehler] = data[counter];
	zaehler = zaehler + 1;
	counter = counter + 14;
	length = length - 14;
	}
	//alert(nummer);
	setCookie("playlist_user", nummer, 30);
	
}

function addBand(rows)
{
	var length = getCookie("playlist_user").length;
	var reihenfolge = getCookie("playlist_user");
	var addition = rows - length;
	var neu = reihenfolge;
	var a = 0;
	while(addition>0)
	{
		neu = neu + (rows - a);
		addition = addition -1;
	}
	setCookie("playlist_user", neu, 30);
}

function setFirstCookie(laenge)
{
	var length = laenge;
	length = length;
	var cookie="";
	var a =1;
	var b ="";
	while(length>0)
	{
			if(a<10)
			{
				b="0"+a;
			}else{
				b=a;
			}
			length=length-1;
			cookie=cookie+b;
			a=a+1;
	}
	setCookie("playlist_user",cookie,30);
	//alert(cookie);
}

function hidePlaySymbol()
{
	var a = getCookie("playlist_user").length;
	a = a/2;
	var b = 1;
	var c = "";
	while(a>0)
	{
		if(b<10)
		{
			c="0"+b;
		}else{
			c=b;
		}
		//alert(c);
		document.getElementById("playSign"+c).style.visibility="hidden";
		a=a-1;
		b=b+1;
	}
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name)
{
if (document.cookie.length>0)
 {
 c_start=document.cookie.indexOf(c_name + "=");
 if (c_start!=-1)
 {
 c_start=c_start + c_name.length+1;
 c_end=document.cookie.indexOf(";",c_start);
 if (c_end==-1) c_end=document.cookie.length;
 return unescape(document.cookie.substring(c_start,c_end));
 }
 }
return "";
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}