/* javascript for external pages */

function checkout(frm)
{
	ringtones = new Array();
	frm = document.getElementById(frm);
	flds = frm.getElementsByTagName("input");
	for (i = 0; i < flds.length; i++) {
		if (flds.item(i).type == "checkbox" && flds.item(i).checked == true)
		{
			ringtones[ringtones.length] = flds.item(i).value;
		}
		if (flds.item(i).type == "hidden" && flds.item(i).name == "action") {
			action = flds.item(i).value;
		}
	}
	if (ringtones.length == 0) {
		alert('Please make a selection');
	}
	else {
		url = document.getElementsByName("url").item(0).value;
		url = url + "?action=" + action + "&ringtones=" + ringtones;
//		window.open(url, "", "width=600,height=500,menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
		window.open(url, "", "width=820,height=640,menubar=no,location=no,resizable=yes,scrollbars=yes,status=no");
	}
}

var currently_playing = false; // is the player currently working ?
var tid;

function end_of_file()
{
	document.getElementById(tid).src = "play.gif";
	currently_playing = false;
}

function get_flash_movie_object(movieName)
{
	if (window.document[movieName]) 
  {
  	return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName];
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
  	return document.getElementById(movieName);
  }
}

function send_data_to_flash_movie(sData)
{
	var preview = get_flash_movie_object("mp3streamer");
	preview.Rewind();
  preview.SetVariable("/:testvar", sData);
  preview.GotoFrame(14);
}

function mute_sound()
{
	var flashMovie = get_flash_movie_object("mp3streamer");
	flashMovie.GotoFrame(19);
}

function play_mp3_url(url, tobj)
{
	//var tid = tobj.id;
	tid = tobj.id;

	if (currently_playing != false) // the mp3streamer has been started before
	{
		// see if the button that was pressed was the one from the song that was already playing
		var nobj = document.getElementById(currently_playing);
		if (tid == nobj.id)
		{
			// yes, the button clicked was the one that was playing, turn it off
			mute_sound();
			tobj.src = "play.gif";
			currently_playing = false;
		}
		else
		{
			/// no, the button clicked was not from the mp3 that was already streaming, turn the previous button off
			nobj.src = "play.gif";
			tobj.src = "mute.gif";
			currently_playing = tid;
			send_data_to_flash_movie(url);
		}
	}
	else
	{
		// first time the mp3streamer plays
		tobj.src = "mute.gif";
		currently_playing = tid;
		send_data_to_flash_movie(url);
	}
}
