//<!--
//*****************************************************************************************************
// 	VSView1: A library of sample view object for displaying AOL video search results on a web page.
// 	Copyright (c) 2006,  AOL LLC.
// 	All rights reserved.
//*****************************************************************************************************

// Function VideoPanel1() is a view object for displaying a set of video search results in a grid view, list view, detail view or full view.
var VideoPanel1 = function(containerID) {  

	// PRIVATE ATTRIBUTES:
	var view = 2;  			// The integer for the view to draw: 0 == grid, 1 == list, and 2 == detail (default).
	var container = document.getElementById(containerID);

	// PUBLIC METHODS:
	// Function getVideoSetGridHTML() takes two arguments, the VideoSet data object returned by the AJAX API, and the name of the AJAX 
	// method most recently invoked by the AOLVideoSearchAPI.  This function returns the HTML table that will display a grid view of each 
	// Video in the VideoSet.
	this.getVideoSetGridHTML = function(VideoSet, methodName) {
		var minCellWidth = 130;
		var cellsPerRow = Math.floor(container.offsetWidth/minCellWidth);
		var rows = Math.ceil(VideoSet.totalResultsReturned/cellsPerRow);
		var theHTML = '';
		theHTML += '<table style="width: 100%; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse; vertical-align: top;">';
		for (var j=0; j < rows; j++) {
			theHTML += '<tr>';
			for (var k=0; k < cellsPerRow; k++) {
				var i = (j * cellsPerRow) + k; 
				theHTML += '<td align="center" valign="top" style="padding: 12px 4px 12px 4px;">';
				if (i >= VideoSet.Video.length) { theHTML += '&nbsp;'; }
				else {
					var theVideo = VideoSet.Video[i];
					if (theVideo) {
						theHTML += '<div style="width: '+minCellWidth+'px;">';
						theHTML += '<a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);"><img src="'+theVideo.thumbnailUrl+'" class="thumbnail" alt="click to play video"/></a>';
						if (("editorsPick" in theVideo) && (parseInt(theVideo.editorsPick) == 1)) { theHTML += '<div class="callout">FEATURED</div>'; }
						theHTML += '<div><a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.title, 40))+'</a></div>';
						if ("runtime" in theVideo) { theHTML += '<div><nobr>'+VSUTIL.getRuntimeString(theVideo.runtime)+'</nobr></div>'; }
						theHTML += '<div><nobr><span class="label">Added:</span> '+VSUTIL.getShortDateString(theVideo.dateFound)+'</nobr></div>';
						if ("channel" in theVideo) { theHTML += '<div><nobr><span class="label">From:</span> <a href="javascript:getVideos(\'channel:&quot;'+VSUTIL.escapeHTMLString(theVideo.channel)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.channel, 15))+'</a></nobr></div>'; }
						if ("viewCount" in theVideo) { theHTML += '<div><nobr><span class="label">Views:</span> '+theVideo.viewCount+'</nobr></div>'; }
						theHTML += '<div><a href="javascript:getVideos(\'id:'+theVideo.id+'\'); void(0);">show details</a></div>';
						theHTML += '</div>';
					}
				}
				theHTML += '</td>';
			}
			theHTML += '</tr>';
		}
		theHTML += '</table>';
		return(theHTML);
	}

	// Function getVideoSetListHTML() takes two arguments, the VideoSet data object returned by the AJAX API, and the name of the AJAX method 
	// most recently invoked by the AOLVideoSearchAPI.  This funciton returns the HTML table that will display a list view of each Video in 
	// the VideoSet.
	this.getVideoSetListHTML = function(VideoSet, methodName) {
		var theHTML = '';
		theHTML += '<table style="width: 100%; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse; vertical-align: top;" border="0" cellpadding="4">';
		for (var i=0; i < VideoSet.totalResultsReturned; i++) {
			var theVideo = VideoSet.Video[i];
			if (theVideo) {
				theHTML += '<tr class="'+(i%2==1?'evenVideo':'oddVideo')+'">';
				theHTML += '<td class="title"><nobr><a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.title, 40))+'</a></nobr></td>';
				if (("editorsPick" in theVideo) && (parseInt(theVideo.editorsPick) == 1)) { theHTML += '<td class="callout"><nobr>FEATURED</nobr></td>'; }
				else { theHTML += '<td>&nbsp;</td>'; }
				if ("category" in theVideo) { 
					theHTML += '<td><nobr>'+VSUTIL.escapeHTML(theVideo.category)+' ';
					if ("rating" in theVideo) { theHTML += '('+VSUTIL.escapeHTML(theVideo.rating)+')'; }		
					theHTML += '</nobr></td>';
				}
				else { theHTML += '<td>&nbsp;</td>'; }
				if ("runtime" in theVideo) { theHTML += '<td><nobr>'+VSUTIL.getRuntimeString(theVideo.runtime)+'</nobr></td>'; }
				else { theHTML += '<td>&nbsp;</td>'; }
				if ("dateFound" in theVideo) { theHTML += '<td><nobr>'+VSUTIL.getShortDateString(theVideo.dateFound)+'</nobr></td>'; }
				else { theHTML += '<td>&nbsp;</td>'; }
				if ("buyUrl" in theVideo) { theHTML += '<td><nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.buyUrl)+'">buy ('+theVideo.buyPrice+')</a></nobr></td>'; }		
				else if ("rentUrl" in theVideo) { theHTML += '<td><nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.rentUrl)+'">rent ('+theVideo.rentPrice+')</a></nobr></td>'; }
				else if ("subscribeUrl" in theVideo) { theHTML += '<td><nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.subscribeUrl)+'">subscribe ('+theVideo.subscribePrice+')</a></nobr></td>'; }
				else if ("registerUrl" in theVideo) { theHTML += '<td><nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.registerUrl)+'">register</a></nobr></td>'; }
				else if ("hiDefVideoUrl" in theVideo) { theHTML += '<td><nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.hiDefVideoUrl)+'">play in hi-def</a></nobr></td>'; }
				else { theHTML += '<td>&nbsp;</td>'; }
				theHTML += '<td><nobr><a href="javascript:getVideos(\'id:'+theVideo.id+'\'); void(0);">details</a></nobr></td>';
				theHTML += '</tr>';
			}
		}
		theHTML += '</table>';
		return(theHTML);			
	}
	
	// Function getVideoSetDetailHTML() takes two arguments, the VideoSet data object returned by the AJAX API, and the name of the AJAX method 
	// most recently invoked by the AOLVideoSearchAPI.  This method returns the HTML table that will display a detail view of each Video in the VideoSet.
	this.getVideoSetDetailHTML = function(VideoSet, methodName) {
		var userRatingCountThreshold = 1;
		var theHTML = '';
		theHTML += '<table style="width: 100%; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse; vertical-align: top;" border="0" cellpadding="4">';
		for (var i=0; i < VideoSet.totalResultsReturned; i++) {
			var theVideo = VideoSet.Video[i]; 
			if (theVideo) {
				theHTML += '<tr class="'+(i%2==1?'evenVideo':'oddVideo')+'">';
				theHTML += '<td style="width: 1%; vertical-align: top;">';
				theHTML += '<a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);"><img src="'+theVideo.thumbnailUrl+'" class="thumbnail" alt="click to play video"/></a>';
				if (("editorsPick" in theVideo) && (parseInt(theVideo.editorsPick) == 1)) { theHTML += '<div class="callout">FEATURED</div>'; }
				theHTML += '</td>';
				theHTML += '<td style="width: 100%; padding-left: 0px;">';
				theHTML += '<div class="title" style="padding-bottom: 2px;"><a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);">'+VSUTIL.escapeHTML(theVideo.title)+'</a></div>';
				theHTML += '<div style="padding-bottom: 2px;">';
				theHTML += '<nobr><span class="label">Added:</span> '+VSUTIL.getShortDateString(theVideo.dateFound)+'</nobr>&nbsp;&nbsp;';
				if ("runtime" in theVideo) { theHTML += '|&nbsp;&nbsp;<wbr><nobr><span class="label">Runtime:</span> '+VSUTIL.getRuntimeString(theVideo.runtime)+'</nobr>&nbsp;&nbsp;'; }
				if ("quality" in theVideo) { theHTML += '|&nbsp;&nbsp;<wbr><nobr><span class="label">Quality:</span> '+theVideo.quality+'</nobr>'; }
				theHTML += '</div>';
				if ("description" in theVideo) { theHTML += '<div style="padding-bottom: 2px;">'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.description, 250))+'</div>'; }
				theHTML += '<div style="padding-bottom: 2px;">';
				if ("category" in theVideo) { theHTML += '<nobr><span class="label">Category:</span> <a href="javascript:getVideos(\'category:&quot;'+VSUTIL.escapeHTMLString(theVideo.category)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(theVideo.category)+'</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("rating" in theVideo) { theHTML += '<nobr>('+VSUTIL.escapeHTML(theVideo.rating)+')</nobr>&nbsp;&nbsp;<wbr>'; }		
				if ("channel" in theVideo) { theHTML += '<nobr><span class="label">Channel:</span> <a href="javascript:getVideos(\'channel:&quot;'+VSUTIL.escapeHTMLString(theVideo.channel)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(theVideo.channel)+'</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("distributor" in theVideo) { theHTML += '<nobr><span class="label">Distributor:</span> <a href="javascript:getVideos(\'distributor:&quot;'+VSUTIL.escapeHTMLString(theVideo.distributor)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(theVideo.distributor)+'</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if (("showName" in theVideo) && ("showUrl" in theVideo)) { theHTML += '<nobr><span class="label">Show:</span> <a href="javascript:getVideos(\'show:&quot;'+VSUTIL.escapeHTMLString(theVideo.showName)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(theVideo.showName)+'</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("episodeName" in theVideo) { theHTML += '<nobr><span class="label">Episode:</span> <a href="javascript:getVideos(\'&quot;'+VSUTIL.escapeHTMLString(theVideo.episodeName)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(theVideo.episodeName)+'</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("artist" in theVideo) { theHTML += '<nobr><span class="label">Artist:</span> <a href="javascript:getVideos(\'artist:&quot;'+VSUTIL.escapeHTMLString(theVideo.artist)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(theVideo.artist)+'</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("album" in theVideo) { theHTML += '<nobr><span class="label">Album:</span> <a href="javascript:getVideos(\'album:&quot;'+VSUTIL.escapeHTMLString(theVideo.album)+'&quot;\'); void(0);">'+VSUTIL.escapeHTML(theVideo.album)+'</a></nobr>'; }
				theHTML += '</div>';
				if ("tags" in theVideo) { theHTML += '<div style="padding-bottom: 2px;"><span><span class="label">Tags:</span> '+VSUTIL.getTagsHTML(theVideo.tags, 10)+'</span></div>'; }
				theHTML += '<div style="padding-bottom: 2px;">';
				if ("viewCount" in theVideo) { theHTML += '<nobr><span class="label">Views:</span> '+theVideo.viewCount+'</nobr>&nbsp;&nbsp;<wbr>'; }
				if (("userRatingCount" in theVideo) && (parseInt(theVideo.userRatingCount) >= userRatingCountThreshold)) { 
					theHTML += '<nobr><span class="label">Rating:</span> '+theVideo.userRating+' (rated '+theVideo.userRatingCount+' time'+(theVideo.userRatingCount==1?'':'s')+')</nobr>&nbsp;&nbsp;<wbr>';
				}
				theHTML += '<nobr><span class="label">Rate this video:</span>'+VSUTIL.getRatingButtons(theVideo.id)+'</nobr>&nbsp;&nbsp;<wbr>';
				if ("vRank" in theVideo) { theHTML += '<nobr><span class="label">VRank:</span> '+theVideo.vRank+'</nobr>'; }
				theHTML += '</div>';
				theHTML += '<div style="padding-bottom: 2px;">';
				if ("hiDefVideoUrl" in theVideo) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.hiDefVideoUrl)+'" target="_blank">view in high quality</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("previewVideoUrl" in theVideo) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.previewVideoUrl)+'" target="_blank">preview this video</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("registerUrl" in theVideo) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.registerUrl)+'">register to view</a></nobr>&nbsp;&nbsp;<wbr>'; }
				if ("subscribeUrl" in theVideo) { 
					if (theVideo.subscribePrice) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.subscribeUrl)+'">subscribe to view ('+theVideo.subscribePrice+')</a></nobr>&nbsp;&nbsp;<wbr>'; }
					else { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.subscribeUrl)+'">subscribe to view</a></nobr>&nbsp;&nbsp;<wbr>'; }
				}
				if ("rentUrl" in theVideo) { 
					if (theVideo.rentPrice) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.rentUrl)+'">rent this video ('+theVideo.rentPrice+')</a></nobr>&nbsp;&nbsp;<wbr>'; }
					else { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.rentUrl)+'">rent this video</a></nobr>&nbsp;&nbsp;<wbr>'; }
				}
				if ("buyUrl" in theVideo) { 
					if (theVideo.buyPrice) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.buyUrl)+'">buy this video ('+theVideo.buyPrice+')</a></nobr>'; }
					else { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.buyUrl)+'">buy this video ('+theVideo.buyPrice+')</a></nobr>'; }
				}		
				theHTML += '</div>';		
				theHTML += '<div style="padding-bottom: 2px;">';
				theHTML += '<nobr><a href="javascript:getVideos(\'id:'+theVideo.id+'\'); void(0);">show details</a></nobr>&nbsp;&nbsp;';
				theHTML += '|&nbsp;&nbsp;<wbr><nobr><a href="javascript:getVideos(\'sim:'+theVideo.id+'\'); void(0);">show more like this</a></nobr>&nbsp;&nbsp;';
				if (methodName.indexOf("getFavoriteVideos") >= 0) {
					theHTML += '|&nbsp;&nbsp;<wbr><nobr><a href="javascript:removeFavorite('+theVideo.id+'); void(0);">remove from favorites</a></nobr>';
				}
				else {
			// abbas2000		theHTML += '|&nbsp;&nbsp;<wbr><nobr><a href="javascript:addFavorite('+theVideo.id+'); void(0);">add to favorites</a></nobr>';
				}
				theHTML += '</div>';
				theHTML += '</td>';
				theHTML += '</tr>';
			}
		}
		theHTML += '</table>';
		return(theHTML);
	}
	
	// Function getVideoFullHTML() takes three arguments, the VideoSet data object returned by the AJAX API, the name of the AJAX method most recently
	// invoked by the AOLVideoSearchAPI, and the previousQuery executed by the API (for the back button).  This function returns the HTML to display 
	// the complete detailed view of all displayable metadata fields in the first video of the VideoSet.
	this.getVideoSetFullHTML = function(VideoSet, methodName, previousQuery) {
		var theVideo = VideoSet.Video[0];
		var theHTML = '';
		if (!theVideo) { return(theHTML); } 
		theHTML += '<div style="padding: 10px 10px 10px 10px;">';
		theHTML += '<table style="border: 0px; border-style: none; border-collapse: collapse; vertical-align: top;" cellpadding="4">';
		theHTML += '<tr>';
		theHTML += '<td style="width: 1%;">';
		theHTML += '<a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);"><img align="right" src="'+theVideo.thumbnailUrl+'" class="thumbnail" alt="click to play video"/></a>';
		theHTML += '</td>';
		theHTML += '<td>';
		theHTML += '<div class="title"><a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); void(0);">'+VSUTIL.escapeHTML(theVideo.title)+'</a></div>';
		if ("description" in theVideo) { theHTML += '<div>'+VSUTIL.escapeHTML(theVideo.description)+'</div>'; }
		theHTML += '</td>';
		theHTML += '</tr>';
		if ("id" in theVideo) { theHTML += '<tr><td class="label"><nobr>Id:</nobr></td><td>'+theVideo.id+'</td></tr>'; }
		if (("channel" in theVideo) && ("channelUrl" in theVideo)) { theHTML += '<tr><td class="label"><nobr>Channel:</nobr></td><td><a href="'+VSUTIL.escapeHTMLString(theVideo.channelUrl)+'">'+VSUTIL.escapeHTML(theVideo.channel)+'</a></td></tr>'; }
		if ("dateFound" in theVideo) { theHTML += '<tr><td class="label"><nobr>Date Added:</nobr></td><td>'+VSUTIL.getDateString(theVideo.dateFound)+'</td></tr>'; }
		if ("vRank" in theVideo) { theHTML += '<tr><td class="label"><nobr>VRank:</nobr></td><td>'+theVideo.vRank+'</td></tr>'; }
		if ("textRelevancy" in theVideo) { theHTML += '<tr><td class="label"><nobr>Relevance rank:</nobr></td><td>'+theVideo.textRelevancy+'</td></tr>'; }
		if ("referrerPageUrl" in theVideo) { theHTML += '<tr><td class="label"><nobr>Referrer Page:</nobr></td><td><a href="'+VSUTIL.escapeHTMLString(theVideo.referrerPageUrl)+'">'+VSUTIL.escapeHTML(VSUTIL.truncateString(theVideo.referrerPageUrl, 100))+'</a></td></tr>'; }
		if ("actor" in theVideo) { theHTML += '<tr><td class="label"><nobr>Starring:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.actor)+'</td></tr>'; }
		if ("director" in theVideo) { theHTML += '<tr><td class="label"><nobr>Directed By:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.director)+'</td></tr>'; }
		if ("writer" in theVideo) { theHTML += '<tr><td class="label"><nobr>Written By:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.writer)+'</td></tr>'; }
		if ("producer" in theVideo) { theHTML += '<tr><td class="label"><nobr>Produced By:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.producer)+'</td></tr>'; }
		if ("artist" in theVideo) { theHTML += '<tr><td class="label"><nobr>Artist:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.artist)+'</td></tr>'; }
		if ("album" in theVideo) { theHTML += '<tr><td class="label"><nobr>Album:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.album)+'</td></tr>'; }
		if ("distributor" in theVideo) { theHTML += '<tr><td class="label"><nobr>Distributed By:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.distributor)+'</td></tr>'; }
		if ("author" in theVideo) { theHTML += '<tr><td class="label"><nobr>Author:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.author)+'</td></tr>'; }
		if ("copyright" in theVideo) { theHTML += '<tr><td class="label"><nobr>Copyright:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.copyright)+'</td></tr>'; }
		if ("rating" in theVideo) { theHTML += '<tr><td class="label"><nobr>Rating:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.rating)+'</td></tr>'; }
		if ("runtime" in theVideo) { theHTML += '<tr><td class="label"><nobr>Runtime:</nobr></td><td>'+VSUTIL.getRuntimeString(theVideo.runtime)+'</td></tr>'; }
		if ("category" in theVideo) { theHTML += '<tr><td class="label"><nobr>Category:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.category)+'</td></tr>'; }
		if ("tags" in theVideo) { theHTML += '<tr><td class="label"><nobr>Tags:</nobr></td><td>'+VSUTIL.getTagsHTML(theVideo.tags, 100)+'</td></tr>'; }
		if (("showName" in theVideo) && ("showUrl" in theVideo)) { theHTML += '<tr><td class="label"><nobr>Show:</nobr></td><td><a href="'+VSUTIL.escapeHTMLString(theVideo.showUrl)+'">'+VSUTIL.escapeHTML(theVideo.showName)+'</a></td></tr>'; }
		if ("episodeName" in theVideo) { theHTML += '<tr><td class="label"><nobr>Episode Name:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.episodeName)+'</td></tr>'; }
		if ("episodeNumber" in theVideo) { theHTML += '<tr><td class="label"><nobr>Episode Number:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.episodeNumber)+'</td></tr>'; }
		if ("seasonNumber" in theVideo) { theHTML += '<tr><td class="label"><nobr>Season Number:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.seasonNumber)+'</td></tr>'; }
		if ("country" in theVideo) { theHTML += '<tr><td class="label"><nobr>Country:</nobr></td><td>'+theVideo.country+'</td></tr>'; }
		if ("language" in theVideo) { theHTML += '<tr><td class="label"><nobr>Language:</nobr></td><td>'+theVideo.language+'</td></tr>'; }
		if ("dateProduced" in theVideo) { theHTML += '<tr><td class="label"><nobr>Date Produced:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.dateProduced)+'</td></tr>'; }
		if ("live" in theVideo) { theHTML += '<tr><td class="label"><nobr>Live Stream:</nobr></td><td>'+(theVideo.live==1?'Yes':'No')+'</td></tr>'; }
		if ("editorsPick" in theVideo) { theHTML += '<tr><td class="label"><nobr>Featured Video:</nobr></td><td>'+(theVideo.editorsPick==1?'Yes':'No')+'</td></tr>'; }
		if ("viewCount" in theVideo) { theHTML += '<tr><td class="label"><nobr>View Count:</nobr></td><td>'+theVideo.viewCount+'</td></tr>'; }
		if ("favoriteCount" in theVideo) { theHTML += '<tr><td class="label"><nobr>Favorite Count:</nobr></td><td>'+theVideo.favoriteCount+'</td></tr>'; }
		if (("userRating" in theVideo) && ("userRatingCount" in theVideo)) { theHTML += '<tr><td class="label"><nobr>User Rating:</nobr></td><td>'+theVideo.userRating+' (rated '+theVideo.userRatingCount+' time'+(theVideo.userRatingCount==1?'':'s')+')</td></tr>'; }
		if ("thumbnailUrlLarge" in theVideo) { theHTML += '<tr><td class="label"><nobr>Large Thumbnail:</nobr></td><td><a href="'+theVideo.thumbnailUrlLarge+'">'+VSUTIL.truncateString(theVideo.thumbnailUrlLarge, 100)+'</a></td></tr>'; }
		if ("quality" in theVideo) { theHTML += '<tr><td class="label"><nobr>Quality:</nobr></td><td>'+theVideo.quality+'</td></tr>'; }
		if ("formats" in theVideo) { theHTML += '<tr><td class="label"><nobr>Formats:</nobr></td><td>'+theVideo.formats+'</td></tr>'; }
		if ("bitrate" in theVideo) { theHTML += '<tr><td class="label"><nobr>Bitrate:</nobr></td><td>'+theVideo.bitrate+'</td></tr>'; }
		if ("width" in theVideo) { theHTML += '<tr><td class="label"><nobr>Video Width:</nobr></td><td>'+theVideo.width+' px</td></tr>'; }
		if ("height" in theVideo) { theHTML += '<tr><td class="label"><nobr>Video Height:</nobr></td><td>'+theVideo.height+' px</td></tr>'; }
		if ("fileSize" in theVideo) { theHTML += '<tr><td class="label"><nobr>File Size:</nobr></td><td>'+theVideo.fileSize+'</td></tr>'; }
		if ("frameRate" in theVideo) { theHTML += '<tr><td class="label"><nobr>Frame Rate:</nobr></td><td>'+theVideo.frameRate+'</td></tr>'; }
		if ("codec" in theVideo) { theHTML += '<tr><td class="label"><nobr>Video Codec:</nobr></td><td>'+VSUTIL.escapeHTML(theVideo.codec)+'</td></tr>'; }
		theHTML += '<tr><td></td><td>';
		if ("hiDefVideoUrl" in theVideo) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.hiDefVideoUrl)+'" target="_blank">view in high quality</a></nobr>&nbsp;&nbsp;<wbr>'; }
		if ("previewVideoUrl" in theVideo) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.previewVideoUrl)+'" target="_blank">preview this video</a></nobr>&nbsp;&nbsp;<wbr>'; }
		if ("registerUrl" in theVideo) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.registerUrl)+'">register to view</a></nobr>&nbsp;&nbsp;<wbr>'; }
		if ("subscribeUrl" in theVideo) { 
			if (theVideo.subscribePrice) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.subscribeUrl)+'">subscribe to view ('+theVideo.subscribePrice+')</a></nobr>&nbsp;&nbsp;<wbr>'; }
			else { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.subscribeUrl)+'">subscribe to view</a></nobr>&nbsp;&nbsp;<wbr>'; }
		}
		if ("rentUrl" in theVideo) { 
			if (theVideo.rentPrice) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.rentUrl)+'">rent this video ('+theVideo.rentPrice+')</a></nobr>&nbsp;&nbsp;<wbr>'; }
			else { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.rentUrl)+'">rent this video</a></nobr>&nbsp;&nbsp;<wbr>'; }
		}
		if ("buyUrl" in theVideo) { 
			if (theVideo.buyPrice) { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.buyUrl)+'">buy this video ('+theVideo.buyPrice+')</a></nobr>'; }
			else { theHTML += '<nobr><a href="'+VSUTIL.escapeHTMLString(theVideo.buyUrl)+'">buy this video ('+theVideo.buyPrice+')</a></nobr>'; }
		}		
		theHTML += '</td></tr>';		
		theHTML += '<tr><td></td><td>';
		theHTML += '<nobr><a href="javascript:getVideos(\''+VSUTIL.escapeHTMLString(previousQuery)+'\'); void(0);">return to search results</a></nobr>&nbsp;&nbsp;';
		theHTML += '|&nbsp;&nbsp;<wbr><nobr><a href="javascript:getVideos(\'sim:'+theVideo.id+'\'); void(0);">show more like this</a></nobr>&nbsp;&nbsp;';
		if (methodName.indexOf("getFavoriteVideos") >= 0) {
			theHTML += '|&nbsp;&nbsp;<wbr><nobr><a href="javascript:removeFavorite('+theVideo.id+'); void(0);">remove from favorites</a></nobr>';
		}
		else {
			theHTML += '|&nbsp;&nbsp;<wbr><nobr><a href="javascript:addFavorite('+theVideo.id+'); void(0);">add to favorites</a></nobr>';
		}
		theHTML += '</td></tr>';		
		theHTML += '</table>';
		theHTML += '</div>';
		return(theHTML);
	}

	// Function getWatchlistSetHTML() takes one argument, the WatchlistSet data object returned by the AJAX API, and returns
	// the HTML table that will display the items in the WatchlistSet.
	this.getWatchlistSetHTML = function(WatchlistSet) {
		var theHTML = '';
		theHTML += '<table style="width: 100%; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse; vertical-align: top;" border="0" cellpadding="6">';
		for (var i=0; i < WatchlistSet.totalResultsReturned; i++) {
			var theWatchlist = WatchlistSet.Watchlist[i];
			var theQuery = theWatchlist.query;
			if ("title" in theWatchlist) { var theTitle = theWatchlist.title; }
			else { var theTitle = theQuery; }
			if ("rssUrl" in theWatchlist) { var theRssUrl = theWatchlist.rssUrl; }
			theHTML += '<tr class="'+(i%2==1?'evenVideo':'oddVideo')+'">';
			theHTML += '<td class="title" width="90%"><a href="javascript:getVideos(\''+VSUTIL.escapeHTMLString(theQuery)+'\'); void(0);">'+VSUTIL.escapeHTML(theTitle)+'</a></td>';
			theHTML += '<td><nobr><a href=\''+VSUTIL.escapeHTML(theRssUrl)+'\'>get RSS feed</a></nobr></td>';
			theHTML += '<td><nobr><a href="javascript:removeWatchlist(\''+VSUTIL.escapeHTMLString(theQuery)+'\'); void(0);">delete this watchlist</a></nobr></td>';
			theHTML += '</tr>';
		}
		theHTML += '</table>';
		return(theHTML);			
	}

	// Function displayMessage() will display the provided text message in the view container.
	this.displayMessage = function(message) {
		var theHTML = '';
		theHTML += '<table style="width: 100%; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse; vertical-align: top;" cellpadding="10">';
		theHTML += '<tr><td style="text-align: center;">';
		theHTML += VSUTIL.escapeHTML(message);
		theHTML += '</td></tr>';		
		theHTML += '</table>';
		container.innerHTML = theHTML;
	}

	// Set the value of the view to draw (e.g. 0 == grid view, 1 == list view, and 2 == detail view) then refresh the display.
	this.setView = function(viewInt) {
		view = viewInt;
	}
	
	// Returns the value of the current view.
	this.getView = function() {
		return(view);
	}

	// Function displayFullView() displays the full view of a single video record.
	this.displayFullView = function(aolvs, previousQuery) {
		if (aolvs.VideoSet) {
			container.innerHTML = this.getVideoSetFullHTML(aolvs.VideoSet, aolvs.method, previousQuery);
		}
	}

	// Function displayWatchlistSet() displays the current WatchlistSet in the video results panel.
	this.displayWatchlists = function(aolvs) {
		if (aolvs.WatchlistSet) {
			if (aolvs.WatchlistSet.totalResultsReturned == 0) { this.displayMessage('There are no watchlists available.'); }
			else { container.innerHTML = this.getWatchlistSetHTML(aolvs.WatchlistSet); }
		}		
	}

	// Function refresh() will draw the HTML for this widget into the container tag.  This function takes one argument, the AOLVideoSearch object
	// that contains all of the data returned by the AJAX API.  If this object contains a valid VideoSet, then all of the videos in the VideoSet
	// will be displayed in either grid, detail or list view.  If there are no videos in the VideoSet, then display a helpful message.  If there 
	// is only one video in the VideoSet, then display the full view of the available video metadata. 
	this.refresh = function(aolvs) {
		if (aolvs.VideoSet) {
			var VideoSet = aolvs.VideoSet;
			if (view == 0) { container.innerHTML = this.getVideoSetGridHTML(VideoSet, aolvs.method); }
			else if (view == 1) { container.innerHTML = this.getVideoSetListHTML(VideoSet, aolvs.method); }
			else { container.innerHTML = this.getVideoSetDetailHTML(VideoSet, aolvs.method); }
		}
	}
}


// Function TitleBar1() is a view object for displaying a title above a set of video search results.  This title bar will 
// display the approriate title text as well as the pagination buttons and a link to an RSS feed.
var TitleBar1 = function(containerID) {
	
	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);

	// PUBLIC METHODS:		
	// Function getHTML() returns HTML to display a title bar for a set of video search results.  This function takes three arguments, the VideoSet
	// object, the query string for the most recent query, and the method name for the most recent method call.
	this.getHTML = function(VideoSet, query, methodName) {
		var theHTML = '';
		theHTML += '<table style="width: 100%; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse;" cellpadding="0">';
		theHTML += '<tr>';
		theHTML += '<td style="text-align: left;">';
		theHTML += '<span class="header">' + VSUTIL.escapeHTML(VideoSet.title) + '</span>';
		if (methodName.indexOf("truveo.videos.getVideos") >= 0) {
			theHTML += '&nbsp;&nbsp;<wbr><nobr>(';
	//		if ("rssUrl" in VideoSet) { theHTML += '<a href=\''+VSUTIL.escapeHTML(VideoSet.rssUrl)+'\'>get RSS</a>&nbsp;|&nbsp;'; }
	// abbas2000		theHTML += '<a href="javascript:addWatchlist(\''+VSUTIL.escapeHTMLString(query)+'\'); void(0);">save to watchlists</a>';
			theHTML += ')</nobr>';
		}
		else if (methodName.indexOf("truveo.users.getRecentVideos") >= 0) {
			theHTML += '&nbsp;&nbsp;<wbr><nobr>(';
			theHTML += '<a href="javascript:clearRecentVideos(); void(0);">clear recent videos</a>';
			theHTML += ')</nobr>';
		}
		theHTML += '</td>';
		theHTML += '<td style="text-align: right;">';
		theHTML += (parseInt(VideoSet.firstResultPosition) + 1) + ' to ' + (parseInt(VideoSet.firstResultPosition) + parseInt(VideoSet.totalResultsReturned)) + ' of ' + VideoSet.totalResultsAvailable;
		theHTML += '</td>';
		theHTML += '</tr>';		
		theHTML += '<tr>';
		theHTML += '<td style="text-align: left;">';
		if (hasPreviousPage()) { theHTML += '<a href="javascript:previousPage(); void(0);">&lt;&lt;previous</a>'; } else { theHTML += '&nbsp;'; }
		theHTML += '</td>';
		theHTML += '<td style="text-align: right;">';
		if (hasNextPage()) { theHTML += '<a href="javascript:nextPage(); void(0);">next&gt;&gt;</a>'; } else { theHTML += '&nbsp;'; }
		theHTML += '</td>';
		theHTML += '</tr>';		
		theHTML += '</table>';
		return(theHTML);
	}
	
	// Function displayTitle() displays the provided message in the title bar.
	this.displayTitle = function(message) {
		var theHTML = '';
		theHTML += '<table style="width: 100%; margin: 0 0 0 0; border: 0px; border-style: none; border-collapse: collapse;" cellpadding="0">';
		theHTML += '<tr><td style="text-align: left;">';
		if (message == '') { theHTML += '<span class="header">&nbsp;</span>'; } else { theHTML += '<span class="header">' + VSUTIL.escapeHTML(message) + '</span>'; }
		theHTML += '</td></tr>';
		theHTML += '<tr><td>&nbsp;</td></tr>';
		theHTML += '</table>';
		container.innerHTML = theHTML;
	}

	// Function refresh() will draw the HTML for this widget into the container tag.  This function takes one mandatory argument, the AOLVideoSearch 
	// object that contains the response data from the AJAX API.  If the AOLVideoSearch object contains a valid VideoSet, then the provided title
	// will be displayed for the given video set.  Otherwise, if the AOLVideoSearch object contains a valid WatchlistSet, then an appropriate title
	// will be displayed for the set of watchlists.
	this.refresh = function(aolvs) {
		if (aolvs.VideoSet) {
			if (aolvs.VideoSet.totalResultsReturned == 0) { this.displayTitle(aolvs.VideoSet.title); }
			else { container.innerHTML = this.getHTML(aolvs.VideoSet, aolvs.query, aolvs.method); }
		}
	}
}


// Function CategoryMenu1() is a view object for displaying a menu of categories returned in the CategorySet object.
var CategoryMenu1 = function(containerID) {
	
	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);
	var showHeader = true;  	// The boolean that determines if a menu header is displayed.
	var showAllBtn = true;		// The boolean that determines if an 'all' category is included in menu.
	var charLimit = 16;			// The maximum number of characters to display in each menu item.

	// PUBLIC METHODS:		
	// Function getHTML() returns HTML to display a menu containing the categories provided in the CategorySet object.
	this.getHTML = function(CategorySet) {
		var theHTML = '';
		if (showHeader) { theHTML += '<div class="menuHeader"><nobr>Refine By Category:</nobr></div>'; }
		if (showAllBtn) { theHTML += '<div><nobr><a href="javascript:getVideosByCategory(\'all\'); void(0);">All Categories</a></nobr></div>'; }
		if (("totalResultsReturned" in CategorySet) && (CategorySet.totalResultsReturned > 0)) {
			for (var i=0; i < CategorySet.totalResultsReturned; i++) {
				var categoryName = CategorySet.Category[i].name;
				var categoryCount = CategorySet.Category[i].count;
				theHTML += '<div><nobr><a href="javascript:getVideosByCategory(\''+VSUTIL.escapeHTMLString(categoryName)+'\'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(categoryName, charLimit))+' ('+categoryCount+')</a></nobr></div>';
			}
		}
		else { theHTML += 'no related categories'; }
		return(theHTML);
	}
	
	// Function refresh() will draw the HTML for this widget into the container tag.  This function takes one argument, the CategorySet data 
	// object returned by the AJAX API.
	this.refresh = function(CategorySet) {
		if (CategorySet) { container.innerHTML = this.getHTML(CategorySet); }
	}
	
	// Function clear() will display nothing in this menu.
	this.clear = function() {
		container.innerHTML = '';
	}
}


// Function ChannelMenu1() is a view object for displaying a menu of channels returned in the ChannelSet object.
var ChannelMenu1 = function(containerID) {
	
	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);
	var showHeader = true;  	// The boolean that determines if a menu header is displayed.
	var showAllBtn = true;		// The boolean that determines if an 'all' category is included in menu.
	var charLimit = 16;			// The maximum number of characters to display in each menu item.

	// PUBLIC METHODS:		
	// Function getHTML() returns HTML to display a menu containing the channels provided in the ChannelSet object.
	this.getHTML = function(ChannelSet) {
		var theHTML = '';
		if (showHeader) { theHTML += '<div class="menuHeader"><nobr>Refine By Channel:</nobr></div>'; }
		if (showAllBtn) { theHTML += '<div><nobr><a href="javascript:getVideosByChannel(\'all\'); void(0);">All Channels</a></nobr></div>'; }
		if (("totalResultsReturned" in ChannelSet) && (ChannelSet.totalResultsReturned > 0)) {
			for (var i=0; i < ChannelSet.totalResultsReturned; i++) {
				var channelName = ChannelSet.Channel[i].name;
				var channelCount = ChannelSet.Channel[i].count;
				theHTML += '<div><nobr><a href="javascript:getVideosByChannel(\''+VSUTIL.escapeHTMLString(channelName)+'\'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(channelName, charLimit))+' ('+channelCount+')</a></nobr></div>';
			}
		}
		else { theHTML += 'no related channels'; }
		return(theHTML);
	}
	
	// Function refresh() will draw the HTML for this widget into the container tag.  This function takes one argument, the ChannelSet data 
	// object returned by the AJAX API.
	this.refresh = function(ChannelSet) {
		if (ChannelSet) { container.innerHTML = this.getHTML(ChannelSet); }
	}
	
	// Function clear() will display nothing in this menu.
	this.clear = function() {
		container.innerHTML = '';
	}
}


// Function TagMenu1() is a view object for displaying a menu of tags returned in the TagSet object.
var TagMenu1 = function(containerID) {
	
	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);
	var showHeader = true;  	// The boolean that determines if a menu header is displayed.
	var showAllBtn = true;		// The boolean that determines if an 'all' category is included in menu.
	var charLimit = 16;			// The maximum number of characters to display in each menu item.

	// PUBLIC METHODS:		
	// Function getHTML() returns HTML to display a menu containing the tags provided in the TagSet object.
	this.getHTML = function(TagSet) {
		var theHTML = '';
		if (showHeader) { theHTML += '<div class="menuHeader"><nobr>Refine By Tag:</nobr></div>'; }
		if (showAllBtn) { theHTML += '<div><nobr><a href="javascript:getVideosByTag(\'all\'); void(0);">All Tags</a></nobr></div>'; }
		if (("totalResultsReturned" in TagSet) && (TagSet.totalResultsReturned > 0)) {
			for (var i=0; i < TagSet.totalResultsReturned; i++) {
				var tagName = TagSet.Tag[i].name;
				var tagCount = TagSet.Tag[i].count;
				theHTML += '<div><nobr><a href="javascript:getVideosByTag(\''+VSUTIL.escapeHTMLString(tagName)+'\'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(tagName, charLimit))+' ('+tagCount+')</a></nobr></div>';
			}
		}
		else { theHTML += 'no related tags'; }
		return(theHTML);
	}
	
	// Function refresh() will draw the HTML for this widget into the container tag.  This function takes one argument, the TagSet data 
	// object returned by the AJAX API.
	this.refresh = function(TagSet) {
		if (TagSet) { container.innerHTML = this.getHTML(TagSet); }
	}
	
	// Function clear() will display nothing in this menu.
	this.clear = function() {
		container.innerHTML = '';
	}
}


// Function UserMenu1() is a view object for displaying a menu of users returned in the UserSet object.
var UserMenu1 = function(containerID) {
	
	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);
	var showHeader = true;  	// The boolean that determines if a menu header is displayed.
	var showAllBtn = true;		// The boolean that determines if an 'all' category is included in menu.
	var charLimit = 16;			// The maximum number of characters to display in each menu item.

	// PUBLIC METHODS:		
	// Function getHTML() returns HTML to display a menu containing the users provided in the UserSet object.
	this.getHTML = function(UserSet) {
		var theHTML = '';
		if (showHeader) { theHTML += '<div class="menuHeader"><nobr>Refine By User:</nobr></div>'; }
		if (showAllBtn) { theHTML += '<div><nobr><a href="javascript:getVideosByUser(\'all\'); void(0);">All Users</a></nobr></div>'; }
		if (("totalResultsReturned" in UserSet) && (UserSet.totalResultsReturned > 0)) {
			for (var i=0; i < UserSet.totalResultsReturned; i++) {
				var userName = UserSet.User[i].name;
				var userCount = UserSet.User[i].count;
				theHTML += '<div><nobr><a href="javascript:getVideosByUser(\''+VSUTIL.escapeHTMLString(userName)+'\'); void(0);">'+VSUTIL.escapeHTML(VSUTIL.truncateString(userName, charLimit))+' ('+userCount+')</a></nobr></div>';
			}
		}
		else { theHTML += 'no related users'; }
		return(theHTML);
	}
	
	// Function refresh() will draw the HTML for this widget into the container tag.  This function takes one argument, the UserSet data 
	// object returned by the AJAX API.
	this.refresh = function(UserSet) {
		if (UserSet) { container.innerHTML = this.getHTML(UserSet); }
	}

	// Function clear() will display nothing in this menu.
	this.clear = function() {
		container.innerHTML = '';
	}
}


// Function LoginButton1() is a view object to display a stateful login button.  If the user is not logged in, the 
// button displays 'login', if the user is logged in, the button displays 'logout'.
var LoginButton1 = function(containerID) {

	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);

	// PUBLIC METHODS:		
	this.refresh = function(isLoggedIn) {
		var theHTML = '';
		if (isLoggedIn) { theHTML += 'You are logged in: <a href="javascript:logout(); void(0);">logout</a>'; }
		else { theHTML += 'You are not logged in: <a href="javascript:login(); void(0);">login</a>'; }
		container.innerHTML = theHTML;
	}
}


// Function VSUtilities() is an object that contains a variety of utility methods for processing video search results metadata.
// These methods are available in the global VSUTIL object.
var VSUtilities = function() {
	
	// PUBLIC METHODS:
	// Function getDateString() takes the dateFound string, in RFC 2822 format (see http://www.faqs.org/rfcs/rfc2822),
	// and returns a long-format string suitable for display in a web page.  For example "Thursday, March 09, 2006 12:53:14 PM".
	this.getDateString = function(dateFound) {
		var theDate = new Date(dateFound);
		return(theDate.toLocaleString());
	}
	
	// Function getShortDateString() takes the dateFound srting, in RFC 2822 format (see http://www.faqs.org/rfcs/rfc2822),
	// and returns a short-format string representing the elapsed time.  For example, "1 minute ago", "3 days ago", "2 years ago", etc..
	this.getShortDateString = function(dateFound) {
		var theDate = new Date(dateFound);
		var now = new Date();
		var elapsedTime = now.getTime() - theDate.getTime();
		var seconds = Math.round(elapsedTime/1000);
		if (seconds < 60) { return(seconds+" second"+(seconds==1?'':'s')+" ago"); }
		var minutes = Math.round(elapsedTime/(1000*60));
		if (minutes < 60) { return(minutes+" minute"+(minutes==1?'':'s')+" ago"); }	
		var hours = Math.round(elapsedTime/(1000*60*60));	
		if (hours < 24) { return(hours+" hour"+(hours==1?'':'s')+" ago"); }
		var days = Math.round(elapsedTime/(1000*60*60*24));
		if (days < 30) { return(days+" day"+(days==1?'':'s')+" ago"); }	
		var months = Math.round(elapsedTime/(1000*60*60*24*30));
		if (months < 12) { return(months+" month"+(months==1?'':'s')+" ago"); }	
		var years = Math.round(elapsedTime/(1000*60*60*24*30*12));
		return(years+" year"+(years==1?'':'s')+" ago");
	}
	
	// Function getRuntimeString() takes the runtime string, which represents the duration of the video in seconds, 
	// and returns an appropriate human-readable string.
	this.getRuntimeString = function(runtime) {
		var totalSeconds = parseInt(runtime);
		var minutes = Math.floor(totalSeconds/60);
		var seconds = totalSeconds - (minutes * 60);
		return(minutes+"min "+seconds+"sec");
	}

	// Function getTagsHTML() takes two arguments, the string containing the comma-delimited list of tag names and the 
	// the maximum number of tags to return in the response.  This function returns an HTML string where each tag is
	// a clickable link.
	this.getTagsHTML = function(tags, maxTags) {
		var tagArray = tags.split(",", maxTags);
		var theHTML = '';
		var theTag = '';
		for (var i=0; i < tagArray.length; i++) {
			theTag = VSUTIL.trim(tagArray[i]);
			theHTML += '<nobr><a href="javascript:getVideos(\'tag:&quot;'+this.escapeHTMLString(theTag)+'&quot;\'); void(0);">'+this.escapeHTML(theTag)+'</a></nobr>&nbsp;&nbsp;<wbr>';
		}
		return(theHTML);
	}
	
	// Function getRatingButtons() returns the HTML that will draw a simple set of buttons to allow the user to rate a video
	// by 1, 2, 3, 4 or 5.
	this.getRatingButtons = function(id) {
		var theHTML = '&nbsp;';
		for (var i=1; i <= 5; i++) {
			theHTML += '<a href="javascript:submitRating('+id+','+parseInt(i)+'); void(0);">'+i+'</a>&nbsp;';
		}
		return(theHTML);
	}
	
	// Function truncateString() takes two arguments, the original string and the maximum number of characters to return
	// in the new string.  This function returns a truncated version of the string, appended with an ellipsis, if the 
	// original string is longer than maxChar characters.  Note that the use of HTML entities in the string may cause 
	// the length of the truncated string to vary.  A check is provided in this method to avoid truncating html entities.
	this.truncateString = function(string, maxChar) {
		if (string && (string.length > maxChar)) {
			var index = string.indexOf(";", maxChar);
			if ((index >= 0) && ((index - maxChar) < 10)) { maxChar = index+1; }
			return(string.substr(0, maxChar)+'...');
		}
		else { return(string); }
	}
	
	// Function escapeHTML() takes a string as an argument and returns a new string where the following characters are replaced
	// by their HTML entity equivalents: &, <, >, ", '.
	this.escapeHTML = function(string) {
		var newstr = string.replace(/&/g,"&amp;");
		newstr = newstr.replace(/</g,"&lt;");
		newstr = newstr.replace(/>/g,"&gt;");
		newstr = newstr.replace(/'/g,"&#039;");
		newstr = newstr.replace(/"/g,"&quot;");
		return(newstr);
	}
	
	// Function escapeString() takes a string as an argument and returns a new string where all single and double quotes in the original
	// string have been escaped.
	this.escapeString = function(string) {
		var newstr = string.replace(/'/g,"\'");
		return(newstr.replace(/"/g,'\"'));
	}
	
	// Function escapeHTMLString takes a string as an argument and returns a new string where the following characters are replaced
	// by their HTML entity equivalents: &, <, >, ", '.  Additionally, single and double quotes are double escaped.
	this.escapeHTMLString = function(string) {
		var newstr = string.replace(/&/g,"&amp;");
		newstr = newstr.replace(/</g,"&lt;");
		newstr = newstr.replace(/>/g,"&gt;");
		newstr = newstr.replace(/'/g,"\\&#039;");
		newstr = newstr.replace(/"/g,"\\&quot;");
		return(newstr);		
	}

	// Function escapeRegExp takes a string as an argument and returns a new string where the following regular expression special
	// characters are preceded by a backslash: ^ $ . * + ? = ! : | \ / ( ) [ ] { }
	this.escapeRegExp = function(string) {
		var newstr = string.replace(/\^/g,"\^");
		newstr = newstr.replace(/\$/g,"\$");
		newstr = newstr.replace(/\./g,"\.");
		newstr = newstr.replace(/\*/g,"\*");
		newstr = newstr.replace(/\+/g,"\+");
		newstr = newstr.replace(/\?/g,"\?");
		newstr = newstr.replace(/\=/g,"\=");
		newstr = newstr.replace(/\!/g,"\!");
		newstr = newstr.replace(/\:/g,"\:");
		newstr = newstr.replace(/\|/g,"\|");
		newstr = newstr.replace(/\\/g,"\\");
		newstr = newstr.replace(/\//g,"\/");
		newstr = newstr.replace(/\(/g,"\(");
		newstr = newstr.replace(/\)/g,"\)");
		newstr = newstr.replace(/\[/g,"\[");
		newstr = newstr.replace(/\]/g,"\]");
		newstr = newstr.replace(/\{/g,"\{");
		newstr = newstr.replace(/\}/g,"\}");
		return(newstr);		
	}
	
	// Function trim() removes any leading or trailing spaces from the specified string.
	this.trim = function(string) {
		while(''+string.charAt(0) == ' ') string = string.substring(1, string.length);
		while(''+string.charAt(string.length-1)==' ') string = string.substring(0, string.length-1);
		return(string);
	}
}
VSUTIL = new VSUtilities();

//-->
