/*
	javascript for media players @ gospelsingers.at
	based on JWPlayer V5.8
	copyright(c)2011: OmanBros.com Internetdienstleistungen GmbH
	author: TheGismo
	last update: 2011-11-14

        list of functions:
        	gmp_call(anum)
        	gmp_getplayerids()
        	gmp_play(anum,aidx,aevent)
        	gmp_setallinactive(anum)
        	gmp_writetitle(anum,aidx,atxt)
        	gmp_newitem(anum,afile)

        	gmp_create_html_long_inline(anum,atxtidle,atxtmedia)
        	gmp_create_html_short_inline(anum,atxtidle,atxtmedia)
        	gmp_create_html_ultrashort_inline(anum,atxtidle,atxtmedia)
        	gmp_create_html_playlist(anum,atxtidle,atxtmedia)
        	gmp_create_html_video(anum,atxtidle,atxtmedia)
        	gmp_create_html_videolist(anum,atxtidle,atxtmedia)

        	gmp_setup_long_inline(anum,aplaylist,arepeat,aautostart,atxtidle,atxtmedia)
        	gmp_setup_short_inline(anum,aplaylist,arepeat,aautostart,atxtidle,atxtmedia)
        	gmp_setup_ultrashort_inline(anum,aplaylist,arepeat,aautostart,atxtidle,atxtmedia)
        	gmp_setup_playlist(anum,aplaylist,arepeat,aautostart,atxtidle,atxtmedia)
        	gmp_setup_video(anum,aplaylist,arepeat,aautostart,atxtidle,atxtmedia)
        	gmp_setup_video_nonhq(anum,aplaylist,arepeat,aautostart,atxtidle,atxtmedia)
        	gmp_setup_videolist(anum,aplaylist,arepeat,aautostart,atxtidle,atxtmedia)

		ConfiguratorCheckForm(aobj,asend)

                // google specifics
	        getClient(address,action,title)
	        getSessionCookie(address,action,title)
	        callTrackFunc(trackAction,trackTitle)
*/

GMP_JWPLAYER = "/fileadmin/templates/jwplayer/";
GMP_MEDIA = "/fileadmin/media/";
GMP_ICONS = "/fileadmin/icons/";
GMP_AUTOSTART = true;
GMP_NOAUTOSTART = false;
GMP_NOREPEAT = "none";
GMP_REPEATSINGLE = "single";
GMP_PLAYLIST = "list";
GMP_REPEAT = "always";
GMP_STDMEDIATXT = "Media Player wird geladen...";
GMP_STDIDLETXT = "&laquo; Klicken Sie bitte auf den Start-Button!";
GMP_STDPLAYLISTTXT = "Playlist wird geladen...";
GMP_STDVIDEOLISTTXT = "Videolist wird geladen...";
PDFMAIL_CONF = "/fileadmin/configurator/";

/*
	gmp_call() short call for jwplayer(), where [anum] is the
	number of the player extracted to "gmp-instance[anum]-container"
*/
function gmp_call(anum) {
  return jwplayer("gmp-instance"+anum+"-container");
} // end function gmp_call

/*
	gmp_getplayerids() returns an array of
	div-IDs starting with "gmp-instance"
*/
function gmp_getplayerids() {
  var div_tags = document.getElementsByTagName("div");
  var instances = new Array();
  if (div_tags) {
    for (var i=0;i<div_tags.length;i++) {
      var temp = div_tags[i].id;
      if (temp.indexOf("gmp-instance") == 0 && temp.indexOf("-container") == -1) instances.push(temp);
    }
  }
  return instances;
} // end function gmp_getplayerids

/*
	gmp_play() starts a specific media file in a playlist [aidx]
	of a specific player [anum] and stops and resets all
	other players' playlists, if there are any
	if called inside an event function [aevent] should not be null,
	otherwise an infinite loop will be created!
*/
function gmp_play(anum,aidx,aevent) {
  var instances = gmp_getplayerids();
  for (var i=0;i<instances.length;i++)
    if (instances[i] != "gmp-instance"+anum)
      with (gmp_call(instances[i].substr(12)*1)) {
        playlistItem(0);
        stop();
      }
  if (!aevent) with (gmp_call(anum)) {
    playlistItem(aidx);
    play(true);
  }
} // end function gmp_play

/*
	gmp_setallinactive() sets all items in a playlist of
	a specific player [anum] inactive
*/
function gmp_setallinactive(anum) {
  with (gmp_call(anum)) {
    var playlist = getPlaylist();
    for (var i=0;i<playlist.length;i++)
      document.getElementById("gmp-i"+anum+"-title"+i).className = "gmp-inactive";
  }
} // end function gmp_setallinactive

/*
	gmp_writetitle() writes the current title of the playlist item
	to the respective div. [aidx] is the index of the playlist item and
	[anum] is the number of the player
	if [atxt] has been set then, instead of the title, this text is written
*/
function gmp_writetitle(anum,aidx,atxt) {
  div = document.getElementById("gmp-i"+anum+"-title");
  div.innerHTML = (!atxt?gmp_call(anum).getPlaylistItem(aidx).title : atxt);
} // end function gmp_writetitle

/*
	gmp_newitem(anum,afile) loads one new file into the playlist
	of the player represented by [anum] setting the player
	"visible" or "hidden" depending on [afile].
	if it exists then the player is visible, otherwise it is hidden.
	the filename/-path is automatically prefixed with GMP_MEDIA, which
	represents the path to the media files
*/
function gmp_newitem(anum,afile) {
  var playerobj = document.getElementById("gmp-instance"+anum);
  var temp = afile.split("|~|");
  if (temp && temp[1]) {
    playerobj.style.visibility="visible";
    gmp_call(anum).load(
      { file: GMP_MEDIA+temp[1],
        title: temp[0] }
    );
  } else {
    playerobj.style.visibility="hidden";
    gmp_call(anum).stop();
  }
}

/*
	gmp_create_html_long_inline() creates the necessary HTML container for the
	media player
	[anum] is the number of the player
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDIDLETXT
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/
function gmp_create_html_long_inline(anum,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDIDLETXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  document.writeln(
    '<div id="gmp-instance'+anum+'" class="gmp-instance-long-inline">\n'+
    '  <div class="gmp-inline">\n'+
    '    <div id="gmp-instance'+anum+'-container">'+atxtmedia+'</div>\n'+
    '  </div>\n'+
    '  <div id="gmp-i'+anum+'-title" class="gmp-inlinetitle">'+atxtidle+'</div>\n'+
    '</div>\n'
  );
} // end function gmp_create_html_long_inline

/*
	gmp_create_html_short_inline() creates the necessary HTML container for the
	media player
	[anum] is the number of the player
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDIDLETXT
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/
function gmp_create_html_short_inline(anum,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDIDLETXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  document.writeln(
    '<div id="gmp-instance'+anum+'" class="gmp-instance-short-inline">\n'+
    '  <div class="gmp-inline">\n'+
    '    <div id="gmp-instance'+anum+'-container">'+atxtmedia+'</div>\n'+
    '  </div>\n'+
    '  <div id="gmp-i'+anum+'-title" class="gmp-inlinetitle">'+atxtidle+'</div>\n'+
    '</div>\n'
  );
} // end function gmp_create_html_short_inline

/*
	gmp_create_html_ultrashort_inline() creates the necessary HTML container for the
	media player
	[anum] is the number of the player
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDIDLETXT (not used)
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/
function gmp_create_html_ultrashort_inline(anum,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDIDLETXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  document.writeln(
    '<div id="gmp-instance'+anum+'" class="gmp-instance-ultrashort-inline">\n'+
    '  <div class="gmp-inline">\n'+
    '    <div id="gmp-instance'+anum+'-container">'+atxtmedia+'</div>\n'+
    '  </div>\n'+
    '</div>\n'
  );
} // end function gmp_create_html_ultrashort_inline

/*
	gmp_create_html_playlist() creates the necessary HTML container for the
	media player
	[anum] is the number of the player
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDPLAYLISTTXT
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/
function gmp_create_html_playlist(anum,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDPLAYLISTTXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  document.writeln(
    '<div id="gmp-instance'+anum+'" class="gmp-instance-norm">\n'+
    '  <div> <!-- firefox hack to place the list below the player and not above! -->\n'+
    '    <div id="gmp-instance'+anum+'-container">'+atxtmedia+'</div>\n'+
    '  </div> <!-- end firefox hack -->\n'+
    '  <div id="gmp-i'+anum+'-title" class="gmp-title gmp-list">'+atxtidle+'</div>\n'+
    '</div>\n'
  );
} // end function gmp_create_html_playlist

/*
	gmp_create_html_video() creates the necessary HTML container for the
	media player
	[anum] is the number of the player
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDIDLETXT
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/
function gmp_create_html_video(anum,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDPLAYLISTTXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  document.writeln(
    '<div id="gmp-instance'+anum+'" class="gmp-instance-norm">\n'+
    '  <div id="gmp-instance'+anum+'-container">'+atxtmedia+'</div>\n'+
    '</div>\n'
  );
} // end function gmp_create_html_video

/*
	gmp_create_html_videolist() creates the necessary HTML container for the
	media player
	[anum] is the number of the player
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDVIDEOLISTTXT
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/
function gmp_create_html_videolist(anum,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDVIDEOLISTTXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  document.writeln(
    '<div id="gmp-instance'+anum+'" class="gmp-instance-norm">\n'+
    '  <div> <!-- firefox hack to place the list below the player and not above! -->\n'+
    '    <div id="gmp-instance'+anum+'-container">'+atxtmedia+'</div>\n'+
    '  </div> <!-- end firefox hack -->\n'+
    '  <div id="gmp-i'+anum+'-title" class="gmp-title gmp-list">'+atxtidle+'</div>\n'+
    '</div>\n'
  );
} // end function gmp_create_html_videolist

/*
	gmp_create_html_configurator_block() creates the necessary HTML container for the
	media player
	[anum] is the number of the player
	[atitle] ... title text
	[aplaylistarray] ... array with playlist (title/value pairs)
	[aplaylist] ... playlist definition (array of strings, indexes into [aplaylistarray])
	[ahelptext] ... help text, if exists shown with a "question mark"
	[arepeat] ... repeat items
		"none": do nothing (stop playback) whenever a file is completed
		"list": play each file in the playlist once, stop at the end
		"always": continously play the file (or all files in the playlist)
		"single": continously repeat the current file in the playlist
		 (or use GMP_xxx definitions)
	[aautostart] ... start automatically, false or true (or use GMP_xxx definitions)
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDIDLETXT
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/
function gmp_create_html_configurator_block(anum,atitle,aplaylistarray,aplaylist,ahelptext,arepeat,aautostart,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDVIDEOLISTTXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  document.writeln(
    '<div class="configurator_block"><label for="configurator_song'+anum+'"><b>'+atitle+'</b></label><br />\n'+
    '  <select id="configurator_song'+anum+'" name="'+atitle+'" class="configurator_song" onchange="gmp_newitem('+anum+',this.value)">\n'+
    '    <option value="">(Bitte ausw&auml;hlen...)</option>\n'
  );
  if (aplaylistarray && aplaylist) for (var i=0;i<aplaylist.length;i++) {
    document.writeln('    <option value="'+aplaylistarray[aplaylist[i]].title+'|~|'+aplaylistarray[aplaylist[i]].value+'">'+
                     aplaylistarray[aplaylist[i]].title+'</option>\n');
  }
  document.writeln('  </select>\n');

  if (ahelptext) document.writeln(
    '  <a href="javascript:" class="tt"><img src="'+GMP_ICONS+'icon_hilfe.gif" alt="Info" />\n'+
    '    <span class="tooltip"><span class="top"></span><span class="middle">'+ahelptext+'</span><span class="bottom"></span></span>\n'+
    '  </a>');

  gmp_setup_ultrashort_inline(anum,[],arepeat,aautostart,atxtidle,atxtmedia);
  document.writeln('</div>\n');
} // end function gmp_create_html_configurator_block

/*
	gmp_setup_long_inline()
	[anum] ... number of player
	[aplaylist] ... playlist definition (array or object)
	[arepeat] ... repeat items
		"none": do nothing (stop playback) whenever a file is completed
		"list": play each file in the playlist once, stop at the end
		"always": continously play the file (or all files in the playlist)
		"single": continously repeat the current file in the playlist
		 (or use GMP_xxx definitions)
	[aautostart] ... start automatically, false or true (or use GMP_xxx definitions)
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDIDLETXT
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/
function gmp_setup_long_inline(anum,aplaylist,arepeat,aautostart,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDIDLETXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  gmp_create_html_long_inline(anum,atxtidle,atxtmedia);
  gmp_call(anum).setup({
    flashplayer: GMP_JWPLAYER+"player.swf",
    controlbar: "bottom",
    dock: "false",
    icons: "false",
    height: 24,
    width: 280,
    volume: 40,
    autostart: (aautostart?aautostart:"false"),
    repeat: (arepeat?arepeat:"none"),
    skin: GMP_JWPLAYER+"skins/gospellong.zip",
/*    plugins: {sharing: {link: false}}, */
    playlist: aplaylist,
    events: {
      onPlaylistItem: function(event) {
        if (gmp_call(anum).getState() != "IDLE") gmp_writetitle(anum,event.index);
      },
      onPlay: function(event) {
        var idx = gmp_call(anum).getPlaylistItem().index;
        gmp_play(anum,idx,event);
        gmp_writetitle(anum,idx);
        var trackName = gmp_call(anum).getPlaylistItem().title;
        callTrackFunc('Player',trackName);
      },
      onIdle: function(event) {
        gmp_writetitle(anum,0,atxtidle);
      }
    }
  });
} // end function gmp_setup_long_inline

/*
	gmp_setup_short_inline()
	[anum] ... number of player
	[aplaylist] ... playlist definition (array or object)
	[arepeat] ... repeat items
		"none": do nothing (stop playback) whenever a file is completed
		"list": play each file in the playlist once, stop at the end
		"always": continously play the file (or all files in the playlist)
		"single": continously repeat the current file in the playlist
		 (or use GMP_xxx definitions)
	[aautostart] ... start automatically, false or true (or use GMP_xxx definitions)
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDIDLETXT
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/
function gmp_setup_short_inline(anum,aplaylist,arepeat,aautostart,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDIDLETXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  gmp_create_html_short_inline(anum,atxtidle,atxtmedia);
  gmp_call(anum).setup({
    flashplayer: GMP_JWPLAYER+"player.swf",
    controlbar: "bottom",
    dock: "false",
    icons: "false",
    height: 24,
    width: 98,
    volume: 40,
    autostart: (aautostart?aautostart:"false"),
    repeat: (arepeat?arepeat:"none"),
    skin: GMP_JWPLAYER+"skins/gospelshort.zip",
/*    plugins: {sharing: {link: false}}, */
    playlist: aplaylist,
    events: {
      onPlaylistItem: function(event) {
        if (gmp_call(anum).getState() != "IDLE") gmp_writetitle(anum,event.index);
      },
      onPlay: function(event) {
        var idx = gmp_call(anum).getPlaylistItem().index;
        gmp_play(anum,idx,event);
        gmp_writetitle(anum,idx);
        var trackName = gmp_call(anum).getPlaylistItem().title;
        callTrackFunc('Player',trackName);
      },
      onIdle: function(event) {
        gmp_writetitle(anum,0,atxtidle);
      }
    }
  });
} // end function gmp_setup_short_inline

/*
	gmp_setup_ultrashort_inline()
	[anum] ... number of player
	[aplaylist] ... playlist definition (array or object)
	[arepeat] ... repeat items
		"none": do nothing (stop playback) whenever a file is completed
		"list": play each file in the playlist once, stop at the end
		"always": continously play the file (or all files in the playlist)
		"single": continously repeat the current file in the playlist
		 (or use GMP_xxx definitions)
	[aautostart] ... start automatically, false or true (or use GMP_xxx definitions)
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDIDLETXT
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/
function gmp_setup_ultrashort_inline(anum,aplaylist,arepeat,aautostart,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDIDLETXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  gmp_create_html_ultrashort_inline(anum,atxtidle,atxtmedia);
  gmp_call(anum).setup({
    flashplayer: GMP_JWPLAYER+"player.swf",
    controlbar: "bottom",
    dock: "false",
    icons: "false",
    height: 24,
    width: 98,
    volume: 40,
    autostart: (aautostart?aautostart:"false"),
    repeat: (arepeat?arepeat:"none"),
    skin: GMP_JWPLAYER+"skins/gospelshort.zip",
/*    plugins: {sharing: {link: false}}, */
    playlist: aplaylist,
    events: {
      onPlay: function(event) {
        var idx = gmp_call(anum).getPlaylistItem().index;
        gmp_play(anum,idx,event);
        var trackName = gmp_call(anum).getPlaylistItem().title;
        //alert('Player '+anum );
        myttitle = "Hoerbeispiel "+anum+", "+trackName;
        callTrackFunc('Player',myttitle);
      }
    }
  });
} // end function gmp_setup_ultrashort_inline

/*
	gmp_setup_playlist()
	[anum] ... number of player
	[aplaylist] ... playlist definition (array or object)
	[arepeat] ... repeat items
		"none": do nothing (stop playback) whenever a file is completed
		"list": play each file in the playlist once, stop at the end
		"always": continously play the file (or all files in the playlist)
		"single": continously repeat the current file in the playlist
		 (or use GMP_xxx definitions)
	[aautostart] ... start automatically, false or true (or use GMP_xxx definitions)
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDPLAYLISTTXT
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/

function gmp_setup_playlist(anum,aplaylist,arepeat,aautostart,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDPLAYLISTTXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  gmp_create_html_playlist(anum,atxtidle,atxtmedia)
  gmp_call(anum).setup({
    flashplayer: GMP_JWPLAYER+"player.swf",
    controlbar: "bottom",
    dock: "false",
    icons: "false",
    height: 24,
    width: 500,
    volume: 40,
    autostart: (aautostart?aautostart:"false"),
    repeat: (arepeat?arepeat:"none"),
    skin: GMP_JWPLAYER+"skins/gospellong.zip",
/*    plugins: {sharing: {link: false}}, */
    playlist: aplaylist,
    events: {
      onReady: function(event) {
        div = document.getElementById("gmp-i"+anum+"-title");
        var playlist = gmp_call(anum).getPlaylist();
        var temp = "";
        for (var i=0;i<playlist.length;i++) {
          temp += '<div id="gmp-i'+anum+'-title'+i+'" class="gmp-inactive" title="'+playlist[i].title+
            '" onclick="gmp_play('+anum+','+i+');">'+(i<9?"0":"")+(i+1)+" - "+playlist[i].title+'</div>';
        }
        // callTrackFunc(&quot;Playlist&quot;, &quot;'+playlist[i].title+'&quot;);
        div.innerHTML = temp;
      },
      onPlaylistItem: function(event) {
        gmp_setallinactive(anum);
        div = document.getElementById("gmp-i"+anum+"-title"+event.index);
        div.className = "gmp-active";
      },
      onPlay: function(event) {
        var idx = gmp_call(anum).getPlaylistItem().index;
        gmp_play(anum,idx,event);
        var trackName = gmp_call(anum).getPlaylistItem().title;
        callTrackFunc('Player',trackName);
      }
    }
  });
} // end function gmp_setup_playlist

/*
	gmp_setup_video()
	[anum] ... number of player
	[aplaylist] ... playlist definition (array or object)
	[arepeat] ... repeat items
		"none": do nothing (stop playback) whenever a file is completed
		"list": play each file in the playlist once, stop at the end
		"always": continously play the file (or all files in the playlist)
		"single": continously repeat the current file in the playlist
		 (or use GMP_xxx definitions)
	[aautostart] ... start automatically, false or true (or use GMP_xxx definitions)
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDIDLETXT
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/
function gmp_setup_video(anum,aplaylist,arepeat,aautostart,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDIDLETXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  gmp_create_html_video(anum,atxtidle,atxtmedia);
  gmp_call(anum).setup({
    flashplayer: GMP_JWPLAYER+"player.swf",
    controlbar: "bottom",
    dock: "false",
    icons: "false",
    height: 360,
    width: 500,
    volume: 40,
    autostart: (aautostart?aautostart:"false"),
    repeat: (arepeat?arepeat:"none"),
    skin: GMP_JWPLAYER+"skins/gospelvideo.zip",
/*    plugins: {sharing: {link: false}}, */
    playlist: aplaylist,
    events: {
      onPlay: function(event) {
        var idx = gmp_call(anum).getPlaylistItem().index;
        gmp_play(anum,idx,event);
	var trackName = gmp_call(anum).getPlaylistItem().title;
	callTrackFunc('Video',trackName);
      }
    }
  });
} // end function gmp_setup_video

/*
	gmp_setup_video_nonhq()
	[anum] ... number of player
	[aplaylist] ... playlist definition (array or object)
	[arepeat] ... repeat items
		"none": do nothing (stop playback) whenever a file is completed
		"list": play each file in the playlist once, stop at the end
		"always": continously play the file (or all files in the playlist)
		"single": continously repeat the current file in the playlist
		 (or use GMP_xxx definitions)
	[aautostart] ... start automatically, false or true (or use GMP_xxx definitions)
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDIDLETXT
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/
function gmp_setup_video_nonhq(anum,aplaylist,arepeat,aautostart,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDIDLETXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  gmp_create_html_video(anum,atxtidle,atxtmedia);
  gmp_call(anum).setup({
    flashplayer: GMP_JWPLAYER+"player.swf",
    controlbar: "bottom",
    dock: "false",
    icons: "false",
    height: 360,
    width: 500,
    volume: 40,
    autostart: (aautostart?aautostart:"false"),
    repeat: (arepeat?arepeat:"none"),
    skin: GMP_JWPLAYER+"skins/gospellong.zip",
/*    plugins: {sharing: {link: false}}, */
    playlist: aplaylist,
    events: {
      onPlay: function(event) {
        var idx = gmp_call(anum).getPlaylistItem().index;
        gmp_play(anum,idx,event);
	var trackName = gmp_call(anum).getPlaylistItem().title;
	callTrackFunc('Video',trackName);
      }
    }
  });
} // end function gmp_setup_video_nonhq

/*
	gmp_setup_videolist()
	[anum] ... number of player
	[aplaylist] ... playlist definition (array or object)
	[arepeat] ... repeat items
		"none": do nothing (stop playback) whenever a file is completed
		"list": play each file in the playlist once, stop at the end
		"always": continously play the file (or all files in the playlist)
		"single": continously repeat the current file in the playlist
		 (or use GMP_xxx definitions)
	[aautostart] ... start automatically, false or true (or use GMP_xxx definitions)
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDIDLETXT
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/
function gmp_setup_videolist(anum,aplaylist,arepeat,aautostart,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDIDLETXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  gmp_create_html_videolist(anum,atxtidle,atxtmedia);
  gmp_call(anum).setup({
    flashplayer: GMP_JWPLAYER+"player.swf",
    controlbar: "bottom",
    dock: "false",
    icons: "false",
    height: 360,
    width: 500,
    volume: 40,
    autostart: (aautostart?aautostart:"false"),
    repeat: (arepeat?arepeat:"none"),
    skin: GMP_JWPLAYER+"skins/gospelvideo.zip",
/*    plugins: {sharing: {link: false}}, */
    playlist: aplaylist,
    events: {
      onReady: function(event) {
        div = document.getElementById("gmp-i"+anum+"-title");
        var playlist = gmp_call(anum).getPlaylist();
        var temp = "";
        for (var i=0;i<playlist.length;i++) {
          temp += '<div id="gmp-i'+anum+'-title'+i+'" class="gmp-inactive" title="'+playlist[i].title+
            '" onclick="gmp_play('+anum+','+i+')">'+(i<9?"0":"")+(i+1)+" - "+playlist[i].title+'</div>';
        }
        div.innerHTML = temp;
      },
      onPlaylistItem: function(event) {
        gmp_setallinactive(anum);
        div = document.getElementById("gmp-i"+anum+"-title"+event.index);
        div.className = "gmp-active";
      },
      onPlay: function(event) {
        var idx = gmp_call(anum).getPlaylistItem().index;
        gmp_play(anum,idx,event);
      }
    }
  });
} // end function gmp_setup_videolist

/*
	gmp_setup_configurator_block()
	[anum] ... number of player
	[atitle] ... title text
	[aplaylistarray] ... array with playlist (title/value pairs)
	[aplaylist] ... playlist definition (array of strings, indexes into [aplaylistarray])
	[ahelptext] ... help text, if exists shown with a "question mark"
	[arepeat] ... repeat items
		"none": do nothing (stop playback) whenever a file is completed
		"list": play each file in the playlist once, stop at the end
		"always": continously play the file (or all files in the playlist)
		"single": continously repeat the current file in the playlist
		 (or use GMP_xxx definitions)
	[aautostart] ... start automatically, false or true (or use GMP_xxx definitions)
	[atxtidle] ... optional text if player is in idle mode, otherwise GMP_STDIDLETXT
	[atxtmedia] ... optional text if player is not loaded yet, otherwise GMP_STDMEDIATXT
*/
function gmp_setup_configurator_block(anum,atitle,aplaylistarray,aplaylist,ahelptext,arepeat,aautostart,atxtidle,atxtmedia) {
  if (!atxtidle) atxtidle = GMP_STDIDLETXT;
  if (!atxtmedia) atxtmedia = GMP_STDMEDIATXT;
  gmp_create_html_configurator_block(anum,atitle,aplaylistarray,aplaylist,ahelptext,arepeat,aautostart,atxtidle,atxtmedia);
} // end function gmp_setup_configurator_block

/*
	ConfiguratorCheckForm(aobj,asend)
*/
function ConfiguratorCheckForm(aobj,asend) {
  var aidName = aobj.idName;
  var aidEmail = aobj.idEmail;

  if (asend) {
    if (aidName.value && aidEmail.value) {
      if (!isEmail(aidEmail.value)) {
        alert("Bitte geben Sie eine gültige E-Mail-Adresse ein,\n"+
              "wenn Sie die Daten an X-Act übermitteln möchten!");
        return false;
      }
    } else if (aidName.value || aidEmail.value) {
      alert("Bitte geben Sie sowohl einen Namen als auch eine gültige E-Mail-Adresse ein,\n"+
            "wenn Sie die Daten an X-Act übermitteln möchten!");
      return false;
    } else {
      alert("Wir benötigen von Ihnen einen Namen und eine gültige E-Mail-Adresse,\n"+
            "bevor Sie die Daten an X-Act übermitteln können!");
      return false;
    }
  }

  aobj.action = PDFMAIL_CONF+"pdfcreate.php";
  return true;
} // end function ConfiguratorCheckForm

function getClient(address,action,title) {
  //erstellen des requests
  var req = null;

  try {
    req = new XMLHttpRequest();
  }
  catch (ms) {
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (nonms) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (failed) {
        req = null;
      }
    }
  }

  if (req == null) alert("Error creating request object!");

  //anfrage erstellen (GET, url ist localhost,
  //request ist asynchron

  newTitle = title.replace(/&lsaquo; &nbsp;/g, "");
  if (window.location.host == 'neu.gospelsingers.test')
    var myUrl = "http://neu.gospelsingers.test/ip.php?address="+address+"&action="+action+"&title="+newTitle;
  else
    var myUrl = "http://www.gospelsingers.at/ip.php?address="+address+"&action="+action+"&title="+newTitle;
  //req.open("GET", 'http://www.gospelsingers.at/ip.php?address=address&action=action&title=title', true);
  req.open("GET", myUrl, true);

  //Beim abschliessen des request wird diese Funktion ausgeführt
  req.onreadystatechange = function() {
    switch (req.readyState) {
      case 4:
        if (req.status != 200) {
          //alert("Fehler:"+req.status);
          //alert("Fehler:"+myUrl);
        } else {
	  document.cookie = "GaClientID="+ req.responseText;
          document.cookie=req.responseText;
          //alert(req.responseText);
          //schreibe die antwort in den div container mit der id content
        }
    	break;
      default: return false;
    }
  };

  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  req.send(null);
} // end function getClient

function getSessionCookie(address,action,title) {
  getClient(address,action,title);
  allcookies = document.cookie;
  phpcookie = allcookies.split("GaClientID=");
  phpcookie = phpcookie[1].split(";");
  phpcookie = phpcookie[0]*1;
  return phpcookie;
} // end function getSessionCookie

/*
	Function to call google-analytics event-tracking:

	Paramters:
	trackAction (Description of Action, e.g. Playlist, Player, ...)
	trackTitle (Songtitle or Player ID)
*/
function callTrackFunc(trackAction,trackTitle) {
//  alert(trackAction+"-"+trackTitle);
//  return;
  trackAddress = window.location.pathname;
//  alert(window.location.pathname);
  _gaq.push(['_trackEvent', trackAddress, trackAction, trackTitle, getSessionCookie(trackAddress,trackAction,trackTitle)]);
} // end function callTrackFunc

