// This file creates the forms for all of the NFL players.
//

///////// VARS //////////
//
//

// List of track NAMES
var _TrackName = [];
// List of the mp3 URLs
var _TrackURL = [];
// List of artist names
var _ArtistName = [];


//
//
//////////////////////////



/////// Functions ////////
//
//

// This function will check all of the text boxes and determine
// whether or not we should disable or enable certain buttons.
//
function CheckButtons(){
 
   // Hold our form.
   var form = document.PlaylistForm;

   // First, check to see if we have ANYTHING on our
   // playlist...
   if(form.Playlist.length <= 0 || form.Playlist.length == undefined)
   {
      // If NOTHING on the list, disable the send button, 
      // remove, and remove all buttons.
      form.Submit.disabled = true;
      form.Remove.disabled = true;
      form.RemoveAll.disabled = true;
   }
   else // disable it.
   {
      form.Submit.disabled = false;
      form.Remove.disabled = false;
      form.RemoveAll.disabled = false;
   }   

   // Next, we check to see if there's anything in the Track Name && Track Location
   // list boxes. Both the TrackName and TrackURL boxes HAVE TO BE POPULATED WITH TEXT!
   // If not, there's no reason to add anything to the list now is there?
   if(form.TrackLocation.value != undefined && form.TrackLocation.value != "" &&
      form.TrackName.value != undefined && form.TrackName.value != "")
   {
      // If there's something there...
      form.Add.disabled = false;
   }
   else
      form.Add.disabled = true;
}


// Clear the textboxes
//
function ClearTextBoxes(){
	document.PlaylistForm.TrackName.value = "";
	document.PlaylistForm.TrackLocation.value = "";
        document.PlaylistForm.ArtistName.value = "";
}

// This will add the track info SPECIFICALLY TO
// PlaylistForm.Playlist
//
function AddTrack(){
	// First, check to see if we have both a title AND a url.
	// if not, then we need to display an error message
	// in the empty text box.	
	var Name = document.PlaylistForm.TrackName.value;
	var URL = document.PlaylistForm.TrackLocation.value;
	var Artist = document.PlaylistForm.ArtistName.value;
        
        // Make sure they have a track name and URL!!!
        // I don't really care about artist name.
        //
        if(Name == "" || Name == undefined)
	{
		alert("Remember, you must give this track a name.");
		return;
	}
	if(URL == "" || URL == undefined)
	{
		alert("You must provide a URL");
		return;
	}

        // Add the track name to the playlist to show the user.
	Track(document.PlaylistForm.TrackName.value, document.PlaylistForm.Playlist);

	// Save the track name
	_TrackName.push(Name);
	// ...and save the track location
	_TrackURL.push(URL);
        // ...and the artist name IF there is one.
        if(document.PlaylistForm.ArtistName.value != "" &&
           document.PlaylistForm.ArtistName.value != undefined)
        {
           _ArtistName.push(Artist);
        }
        else
           _ArtistName.push(" ");

	// Now clear the boxes.
	ClearTextBoxes();
}

// This will add the track to the element passed in.
//
// IN: The name of the track
//     The element to add the track to.
//
function Track(TrackText, AddToElement){
	var NewTrack = document.createElement("OPTION");
	NewTrack.text = TrackText;
	NewTrack.value = "TrackTitle";
	AddToElement.options.add(NewTrack);
}

// This will remove the selected index SPECIFICALLY from
// PlaylistForm.Playlist.
//
function RemoveTrack(){
	Remove(document.PlaylistForm.Playlist, document.PlaylistForm.Playlist.selectedIndex);
}

// Will do what the name says...Will even clear the arrays.
// Specifically Designed for the PlaylistForm.Playlist element
//
function RemoveAllTracks(){

	while(document.PlaylistForm.Playlist.length)
		Remove(document.PlaylistForm.Playlist, 0);
}

// Remove the option in an index.
//
// IN: The element to remove from.
//
function Remove(RemoveFromElement, Index){

	// Get the selected index and remove it from
	// the element and the TrackName arrary and
	// the TrackURL array.
	//
	var index = Index;
	
	if(index == -1 || index == undefined)
		return;
	
	// Element
	RemoveFromElement.remove(index);
	
	// Track Name array - Just remove the selected index, nothing more.
	_TrackName.splice(index, 1);
	
	// Track URL array - Just remove the selected index, nothing more.
	_TrackURL.splice(index - 1, 1);

        // The Artist Name array - Just remove the selected index, nothing more.
        _ArtistName.splice(index - 1, 1);

	// Now set the selected index as the one currently selected
	if(index == 0)
		RemoveFromElement.selectedIndex = index;
	else
		RemoveFromElement.selectedIndex = index - 1;

	// Make sure we removed the correct track.
	//alert(_TrackName);
}

// This function will take the arrays, format them for sending, and input it into our
// sending element.
//
function FormatVars(){
   var size = _TrackName.length;
   var _name = "";
   var _url = "";
   var _artist = "";
   //alert(size);

   // if the tracklist size is 0, then we will leave this place.
   if(size <= 0 || size == undefined)
      return;

   for(var i = 0; i < size; i++)
   {
      // Now format
      _name += _TrackName[i];
      _url += _TrackURL[i];
      _artist += _ArtistName[i];

      // If there is still another name to add, then we'll add
      // our parsing seperator.
      if(i + 1 < size)
      {
        _name += "%%";
        _url += "%%";
        _artist += "%%";
      }
   }

   // Since we're down here, we're done. Now we need to
   // add the strings to their elements.
   document.PlaylistForm.TrackListNameArray.value = _name;
   document.PlaylistForm.TrackListURLArray.value = _url;
   document.PlaylistForm.ArtistNameArray.value = _artist;

//  alert(_artist);

   // Now send it!
   document.PlaylistForm.submit();
}

// This will input the form for any NFL player.
function InputNFLForm(PlayerName, PlayerStyle){

document.write('<table><tr><td><form onkeypress="CheckButtons()" onmousemove = "CheckButtons()" onclick="CheckButtons()" name = "PlaylistForm" onsubmit = "return false" action="http://www.JWorksStudios.com/FreePlayer/GenNFL.php?t=' + PlayerName + '&s=' + PlayerStyle + '" method="post"><b><text style = "color: rgb(255, 0, 0);">*</text>Track Name:</b><br><input name = "TrackName" type = "text" size = "50"><br><br><b><text style = "color: rgb(255, 0, 0);">*</text>Track URL:</b> (<text style="color: rgb(255, 0, 0);">http://www.</text>????.com/track.mp3)<br>&nbsp;&nbsp;<a href = \"http://www.jworksstudios.com/faq/#mp3_urls\" style = \"color: #888888; font-size: 0.8em;\" target = \"_blank\">Where can I get mp3 urls?</a><br><input name = "TrackLocation" type = "text" size = "50"><br><br><b>Artist Name</b><br><input name = "ArtistName" type = "text" size = "50"><br><br><center><b>This is your playlist</b></center><select type = "multiple" name = "Playlist" size = 10 style = "width: 325px;"></select><br><center><input type = "button" name = "Add" value = "Add Track" onclick = "AddTrack()">&nbsp|&nbsp<input type = "button" name = "Remove" value = "Del" onclick ="RemoveTrack()">&nbsp|&nbsp<input type = "button" name = "RemoveAll" value = "Del All" onclick = "RemoveAllTracks()">&nbsp|&nbsp<input type = "button" name = "Submit" Value = "FINISHED!" onclick = "FormatVars()"></center><input type = "hidden" name = "TrackListNameArray" value = "This will be the track list name array."><input type = "hidden" name = "TrackListURLArray" value = "This will be the track list URL array"><input type = "hidden" name = "ArtistNameArray" value = "This will be the list of artist names"></form></td></tr></table>');

}


// This function will display ANY .swf.
//
// IN: Complete .swf URL (http://...) (with quotes)
//     Width - Default is 450
//     Height - Default is 300
//     BGCOLOR - pass STRING RGB values, no HEX. - Pass "000000" not "0x000000". Black ("000000") is default.
//     WMODE - The window mode. Pass "transparent" (with quotes) or "opaque" (with quotes)
//                 "opaque" is default.
function ShowNFLSWF(SWFURL, WIDTH, HEIGHT, BGCOLOR, WMODE){

// Check to see if we got any arguments.
//
// ONLY SWFURL is not defaulted.
//
if(!SWFURL)
   SWFURL = "";
if(!WIDTH)
   WIDTH = 450;
if(!HEIGHT)
   HEIGHT = 300;
if(!BGCOLOR)
   BGCOLOR = "000000";
if(!WMODE)
   WMODE = "opaque";

document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0"');
document.write(' height="' + HEIGHT + '" width="' + WIDTH + '">');
document.write('<param name="wmode" value="' + WMODE + '">');
document.write('<param name="movie"');
document.write(' value="' + SWFURL + '">');
document.write('<param name="quality" value="high">');
document.write('<param name="bgcolor" value="#' + BGCOLOR + '">');
document.write('<embed src = "' + SWFURL + '" quality="high"');
document.write(' bgcolor="#' + BGCOLOR + '"');
document.write(' wmode="' + WMODE + '"');
document.write(' type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"');
document.write(' height="' + HEIGHT + '" width="' + WIDTH + '">');
document.write('</object>');
}

//
//
/////// Functions ////////

