function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function viewPlayerII(url) { 

var FPII = window.open(url, 'flashPLAYerII', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=500,height=300,screenX=10,screenY=10,left=10,top=10');

}

function initPlayer() {
var isMac = (navigator.appVersion.indexOf("Mac") != -1);
if ( !isMac ) {

if (document.cookie) {

	if (navigator.userAgent.indexOf("Firefox")!=-1) {
		if (typeof document['flashplayerII'].SetVariable != "undefined") {
			document['flashplayerII'].SetVariable("cgiLoop", 0);
			setTimer();
		}
	} else

	if (document.getElementById) {
		if (typeof document.getElementById('flashplayerII').SetVariable != "undefined") {
			document.getElementById('flashplayerII').SetVariable("cgiLoop", 0);
			setTimer();
		}
	} else

	if (document.all) {
		if (typeof document.all['flashplayerII'].SetVariable != "undefined") {
			document.all['flashplayerII'].SetVariable("cgiLoop", 0);
			setTimer();
		}
	} else

	if (document.layers) {
		if (typeof window.document.flashplayerII.SetVariable != "undefined") {
			window.document.flashplayerII.SetVariable("cgiLoop", 0);
			setTimer();
		}
	} else

	if (document['flashplayerII']) {
		if (typeof document['flashplayerII'].SetVariable != "undefined") {
			document['flashplayerII'].SetVariable("cgiLoop", 0);
			setTimer();
		}
	} else

	if (window['flashplayerII']) {
		if (typeof window['flashplayerII'].SetVariable != "undefined") {
			window['flashplayerII'].SetVariable("cgiLoop", 0);
			setTimer();
		}
	}

}
}
}

function setTimer() {
  setTimeout("getPlayerAction()",1000);
}

function getPlayerAction() {

var playerAction = getCookie("trackSTACKerAction");

if (playerAction) {

	if (navigator.userAgent.indexOf("Firefox")!=-1) {
		if (typeof document['flashplayerII'].SetVariable != "undefined") {
			document['flashplayerII'].SetVariable("SetPlayerAction", playerAction);
		}
	} else

	if (document.getElementById) {
		if (typeof document.getElementById('flashplayerII').SetVariable != "undefined") {
			document.getElementById('flashplayerII').SetVariable("SetPlayerAction", playerAction);
		}
	} else

	if (document.all) {
		if (typeof document.all['flashplayerII'].SetVariable != "undefined") {
			document.all['flashplayerII'].SetVariable("SetPlayerAction", playerAction);
		}
	} else

	if (document.layers) {
		if (typeof window.document.flashplayerII.SetVariable != "undefined") {
			window.document.flashplayerII.SetVariable("SetPlayerAction", playerAction);
		}
	} else

	if (document['flashplayerII']) {
		if (typeof document['flashplayerII'].SetVariable != "undefined") {
			document['flashplayerII'].SetVariable("SetPlayerAction", playerAction);
		}
	} else

	if (window['flashplayerII']) {
		if (typeof window['flashplayerII'].SetVariable != "undefined") {
			window['flashplayerII'].SetVariable("SetPlayerAction", playerAction);
		}
	}

	deleteCookie("trackSTACKerAction");
}

setTimer();
}

function setPlayerAction(playerID,playerAction) {

  var isMac = (navigator.appVersion.indexOf("Mac") != -1);

  if ( !isMac ) {
  if (document.cookie) {
	var now = new Date();
	fixDate(now);
	now.setTime(now.getTime() + 5000);
	setCookie("trackSTACKerAction", playerAction, now);
  }
  }
  url = "./cgi-bin/player_action.cgi?read=0&write=1&playerID=" + playerID + "&playerAction=" + playerAction;
  var outGoing = new Image(); 
  outGoing.src = url;
}

function playerFunction(playerID,func) {

  var playerAction = func + "| | | ";
  setPlayerAction(playerID,playerAction);
}

function addPlaylist(playerID,func,url) {

  var playerAction = func + "|" + url + "| | ";
  setPlayerAction(playerID,playerAction);
}

function AddMP3(playerID,func,url,title,artist) {

  var playerAction = func + "|" + url + "|" + title + "|" + artist;
  setPlayerAction(playerID,playerAction);
}