/*======================================================================*\
|| #################################################################### ||
|| # PMNet Version 3.0												  #	||
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2003-2008 John Slone. All Rights Reserved. 			  #	||
|| # This file may not be redistributed in whole or significant part. # ||
|| #  																  # ||
|| #################################################################### ||
\*======================================================================*/

/* cddvd.js */


/*
 *		DVD List Functions
 */
var DVDList = {
	'search_string' : '-1',
	'update' : function ()
	{
		f = $("#dvdsearchForm");
		f.find("input[name*='date']").each(function(i){
			if ( $(this).val() == 'YYYY-MM-DD' ) { $(this).val(''); }
		});
		str = $("#dvdsearchForm").serialize();
		if ( str != this.search_string )
		{
			// Query has changed
			$.ajax({
				url : '/ajax.php',
				data : str,
				timeout : 3000,
				success : function(d) { DVDList.updateDVDTable(str,d); }
			});
			this.search_string = str;
			location.hash = str;
		}
	},
	'updateDVDTable' : function(s,d)
	{
		// Make sure they're still on the current search set
		if ( s == this.search_string )
		{
			$("#resultcount").html($(d).find('resultcount').text()+' results found.');
			$("#dvdTable tbody").html($(d).find('resulthtml').text());
			$("#dvdTable").trigger('update');
		}
	},
	'checkAnchor' : function()
	{
		s = location.hash.substring(1);
		this.search_string = s;
		$.ajax({
			url : '/ajax.php',
			data : s,
			timeout : 3000,
			success : function(d) { DVDList.updateDVDTable(s,d); }
		});
		resetVars(location.hash);
	}
	
};

var CDList = {
	search_string : "-1",
	update : function()
	{
		f = $("#cdsearchForm");
		f.find("input[name*='date']").each(function(i){
			if ( $(this).val() == 'YYYY-MM-DD' ) { $(this).val(''); }
		});
		str = $("#cdsearchForm").serialize();
		if ( str != this.search_string )
		{
			// Query has changed
			$.ajax({
				url : '/ajax.php',
				data : str,
				timeout : 3000,
				success : function(d) { CDList.updateCDTable(str,d); }
			});
			this.search_string = str;
			location.hash = str;
		}		
	},	
	updateCDTable : function(s,d)
	{
		// Make sure they're still on the current search set
		if ( s == this.search_string )
		{
			$("#resultcount").html($(d).find('resultcount').text()+' results found.');
			$("#cdTable tbody").html($(d).find('resulthtml').text());
			$("#cdTable").trigger('update');
		}
	},
	checkhash : function()
	{	
		s = location.hash.substring(1);
		this.search_string = s;
		$.ajax({
			url : '/ajax.php',
			data : s,
			timeout : 3000,
			success : function(d) { CDList.updateCDTable(s,d); }
		});
		resetVars(location.hash);
	}
};

var ViewCD = {
	
	getLyrics : function(langid, songid, el)
	{
		p = $(el).parents('tr.trackrow').find("div.lyricsbox");
		$.ajax({
			url : '/ajax.php',
			data : { 'action' : 'getlyrics', 'songid' : songid, 'langid' : langid },
			success : function(d) { ViewCD.addLyrics(d, p); }
		});
		return false;
	},
	
	addLyrics : function(data, el)
	{
		$(el).html(data);
	},
	
	updateLyrics : function(sel, songid)
	{
		p = $(sel).parents('tr.trackrow').find("div.lyricsbox");
		da = $(sel).parents('form.lyricsform').serialize();
		$.ajax({
			url : '/ajax.php',
			data : da,
			success : function(d) { ViewCD.addLyrics(d, p); }
		});
	},
	
	checkAnchor : function()
	{
		// Check to see if they want a particular track highlighted
		l = location.hash;
		if ( l.match(/Track-([0-9]+)/) )
		{
			$("tr#"+l).addClass('highlightrow');
		}
	},
	
	showEpisodes : function(trackid)
	{
		p = $("#track-eps-"+trackid);
		$.ajax({
			url : '/ajax.php',
			data : { 'action' : 'getbgmeps', 'trackid' : trackid },
			success : function(d)
			{
				p.html(d);
			}
		});
		return false;
	}
};


/*======================================================================*\
|| ####################################################################
|| # File Revision:    $Revision: 913 $
|| # Last Change:      $LastChangedDate: 2010-08-28 22:08:39 -0700 (Sat, 28 Aug 2010) $
|| # Last Commit By:   $Author: JDS $
|| ####################################################################
\*======================================================================*/
