//onerror=handleErr;
var txt="";
var host_name = 'http://'+top.location.host;
var ffltr=1; 

function handleErr(msg,url,l)
{
txt="There was an error on this page.\n\n";
txt+="Error: " + msg + "\n";
txt+="URL: " + url + "\n";
txt+="Line: " + l + "\n\n";
txt+="Click OK to continue.\n\n";
alert(txt);
return true;
}

var result_url="/video-old/search.jhtml?query=";
var preview_url="/video-old/detail.jhtml?query=";
var apiID = '1x1jhj64466mi12ia';

var global_featured_count=0;
var global_videos_count  =0;
var page= 0;
var tabno = 0;
var global_var_stat = 0;
var video_page_name='';
var video_page_title='';


var tabName      =  ["Best Match", "Most Viewed", "Highest Rated", "Most Recent"];
var sortValue    =  ["vrank", "mostPopular", "highestRated", "mostRecent"];
var subName      =  ["Today", "This Week", "This Month", "All Time"];
var subSortValue =  ["mostPopularToday", "mostPopularThisWeek", "mostPopularThisMonth", "mostPopular"];

var LST_VID      = null;
var LST_FEA      = null;
var LST_CHA_FEA1 = null;
var LST_CHA_FEA2 = null;
var LST_CHA_FEA3 = null;
var PRE          = null;   // object for  video details, in preview page
var PRE_REL_VID  = null;   // object for  related - video details, in preview page

var tabfiltertext = '<a href="#;" onclick="sortBy(\''+ subSortValue[0] +'\');switchSubheader(1);"><b>'+ subName[0] +'</b></a> | <a href="#;" onclick="sortBy(\''+ subSortValue[1] +'\');switchSubheader(2);"><b>'+ subName[1] +'</b></a> | <a href="#;" onclick="sortBy(\''+ subSortValue[2] +'\');switchSubheader(3);"><b>'+ subName[2] + '</b></a> | <span><b>'+ subName[3] +'</b></span>';


// ##### SEARCH RESULTS #####
function searchVideoLoad(  query  ) { 
	// truveo object for listing video results/relatedchannels/related tags	
	LST_VID = new TruveoVideoSearch(apiID);
    LST_VID.query= query;
	LST_VID.showAdult = ffltr;
	LST_VID.results = 12;
	LST_VID.showRelatedItems = 1;
	LST_VID.tagResults=50;
	LST_VID.channelResults=25;
	//LST_VID.attachEvent('onerror', 'handleError(errorCode, errorMessage);');
	LST_VID.attachEvent('onload', 'searchLoad( reloadStateFlag,LST_VID );');
	LST_VID.attachEvent('onupdate', 'listUpdate(methodName,LST_VID);');
	
	LST_VID.initialize();

	// creating objects, for getting innerHTML to the specified id.
	RES_VIDEOS	        = new VideosList("ResultsDiv1");  // best match
	RES_VIDEOS.setTruncate(50);
	RES_VIDEOS.setShowQuery(true);
	RES_VIDEOS.setShowRating(true);
	RES_VIDEOS.setFooterText("See More Videos >");
	RES_CHAN	= new ChannelMenu("tv_list_chan");      // related channels for the queryterm
	RES_TAGS    = new RelatedTags("tv_list_tags");       // related tags for the queryterm
	//RES_PAG     = new Pagination("tv_paging");
}

//#####  FEATURED VIDESO #####
function listFeaturedVideosLoad( query ){
	// truveo object for listing featured videos on righthand 
	LST_FEA = new TruveoVideoSearch(apiID);
	LST_FEA.query= query;
	LST_FEA.showAdult = ffltr;
	LST_FEA.results=5
	LST_FEA.attachEvent('onload', 'searchLoad(reloadStateFlag,LST_FEA);');
	LST_FEA.attachEvent('onupdate', 'listUpdate(methodName, LST_FEA);');
	LST_FEA.initialize();

	// creating objects, for getting the innerHTMl of featured videos.	
	RES_FEA_VIDEOS = new VideosList("res_fea_vdo");
	RES_FEA_VIDEOS.setTruncate(50);
	RES_FEA_VIDEOS.setShowQuery(true);
	RES_FEA_VIDEOS.setShowRating(true);
	RES_FEA_VIDEOS.setHeaderText("Featured Videos");
	RES_FEA_VIDEOS.setFooterText("See All AOL Videos >");
}



/// channel specific 1
function channelSpecific1( query  )
{
	// truveo object for listing channel Specific videos on Featured Channels
	LST_CHA_FEA1 = new TruveoVideoSearch(apiID);
	LST_CHA_FEA1.query= query;
	LST_CHA_FEA1.showAdult=ffltr;
	LST_CHA_FEA1.results=4;
	LST_CHA_FEA1.attachEvent('onload', 'searchLoad(reloadStateFlag, LST_CHA_FEA1);');
	LST_CHA_FEA1.attachEvent('onupdate', 'listUpdate(methodName, LST_CHA_FEA1);');
	LST_CHA_FEA1.initialize();

	RES_CHA_FEA_VIDEOS1 = new VideosList("tv_list_chan_1");
	RES_CHA_FEA_VIDEOS1.setSmallModuleView(true);
	RES_CHA_FEA_VIDEOS1.setShowQuery(true);
	RES_CHA_FEA_VIDEOS1.setShowRating(false);
	RES_CHA_FEA_VIDEOS1.setTruncate(20);
}
/// channel specific 2
function channelSpecific2( query  )
{
	// truveo object for listing channel Specific videos on Featured Channels
	LST_CHA_FEA2 = new TruveoVideoSearch(apiID);
	LST_CHA_FEA2.query= query;
	LST_CHA_FEA2.showAdult=ffltr;
	LST_CHA_FEA2.results=4;
	LST_CHA_FEA2.attachEvent('onload', 'searchLoad(reloadStateFlag, LST_CHA_FEA2);');
	LST_CHA_FEA2.attachEvent('onupdate', 'listUpdate(methodName, LST_CHA_FEA2);');
	LST_CHA_FEA2.initialize();

	RES_CHA_FEA_VIDEOS2 = new VideosList("tv_list_chan_2");
	RES_CHA_FEA_VIDEOS2.setSmallModuleView(true);
	RES_CHA_FEA_VIDEOS2.setShowQuery(true);
	RES_CHA_FEA_VIDEOS2.setShowRating(false);
	RES_CHA_FEA_VIDEOS2.setTruncate(20);
}

/// channel specific 3
function channelSpecific3( query  )
{
	// truveo object for listing channel Specific videos on Featured Channels
	LST_CHA_FEA3 = new TruveoVideoSearch(apiID);
	LST_CHA_FEA3.query= query;
	LST_CHA_FEA3.showAdult=ffltr;
	LST_CHA_FEA3.results=4;
	LST_CHA_FEA3.attachEvent('onload', 'searchLoad(reloadStateFlag, LST_CHA_FEA3);');
	LST_CHA_FEA3.attachEvent('onupdate', 'listUpdate(methodName, LST_CHA_FEA3);');
	LST_CHA_FEA3.initialize();

	RES_CHA_FEA_VIDEOS3 = new VideosList("tv_list_chan_3");
	RES_CHA_FEA_VIDEOS3.setSmallModuleView(true);
	RES_CHA_FEA_VIDEOS3.setShowQuery(true);
	RES_CHA_FEA_VIDEOS3.setShowRating(false);
	RES_CHA_FEA_VIDEOS3.setTruncate(20);
}

function searchLoad( reloadStateFlag, TObj ){


 searchVideos( TObj.query, TObj.start, TObj );
}

function searchVideos(query,start,TObj) { 
    
   
	if (arguments.length < 1) { TObj.getVideos(); }
	else if (arguments.length < 2) { TObj.getVideos(query); }
	else { TObj.getVideos(query, start); }
}

// error code and error message.
function handleError(errorCode, errorMessage) {
	alert("ERROR: Code " + errorCode + "; " + errorMessage);
}

function listUpdate( methodB, Obj )
{
//alert( Obj.VideoSet);

	//alert( "methodB" + methodB);
	// when object is LST_CHA_FEA1,  will fetch the featured channel  videos of ( channel1 in the channellist)
	if( (methodB == "getVideos") && ( Obj == LST_CHA_FEA1)  )
	{
		//alert( "case 1" );
		RES_CHA_FEA_VIDEOS1.refresh( Obj);
	}
	// when object is LST_CHA_FEA2,  will fetch the featured channel  videos of ( channel2 in the channellist)
	else if( (methodB == "getVideos") && ( Obj == LST_CHA_FEA2)  )
	{
		//alert( "case 2" );
		RES_CHA_FEA_VIDEOS2.refresh( Obj );
	}
	// when object is LST_CHA_FEA3,  will fetch the featured channel  videos of ( channel3 in the channellist)
	else if( (methodB == "getVideos") && ( Obj == LST_CHA_FEA3)  )
	{
		//alert( "case 3" );
		RES_CHA_FEA_VIDEOS3.refresh( Obj );
	}
	// when object is LST_FEA,  will fetch the featured videos of right column
	else if( (methodB == "getVideos")  && (Obj==LST_FEA)  )
	{
		///alert( "case 4" );
		global_featured_count = Obj.VideoSet.totalResultsAvailable;
		//RES_FEA_VIDEOS.refresh( Obj.VideoSet, Obj.query );  NP: commented 
		
	}
	// when object is LIST_VID and there is a sort function in the query. used when clicking on sort functions
	else if((Obj==LST_VID)  &&  (Obj.query.indexOf("sort:") > 0)  )
	{
		//alert( "global_var_stat" + global_var_stat );
		//alert( "case 5" );
		global_videos_count = Obj.VideoSet.totalResultsAvailable;	

		if( global_videos_count < 1 && global_featured_count < 1 )
		{ 
			if(  element_o( "tv_vcontainer_dis" ) ) {  p_o("tv_vcontainer_dis").style.width="948px;"; }
			if(  element_o( "res_fea_vdo" ) )       {  p_o("res_fea_vdo").style.display="none";     }
			if(  element_o( "tv_feach_dis" ) )      {  p_o("tv_feach_dis").style.display="none";    }
			if(  element_o( "tv_rel_ser_dis" ) )    {  p_o("tv_rel_ser_dis").style.display="none";  }
			if(  element_o( "tv_tabs_block" ) )    {  p_o("tv_tabs_block").style.display="none";  }

			var theSTML = '';
			theSTML +='<div align="center"><br/><br/>Your search for <b>'+ Obj.query + '</b> did not return any results.<br/>';
			theSTML +='To get more results, we recommend that you<br/>';

			theSTML +='<ul><li>use fewer words in your query,</li>';
		    theSTML +='<li> check your spelling,</li>';
			theSTML +='<li> remove any double quotes, or</li>';
			theSTML +='<li> rephrase your search using synonyms or related words.</li><ul></div>';

			if(  element_o( "ResultsDiv1" ) )     { p_o( "ResultsDiv1" ).innerHTML=theSTML; }

		}else if( global_featured_count  < 1 ){  
			//alert( "5.1" );
			if(  element_o( "tv_vcontainer_dis" ) ) {  p_o("tv_vcontainer_dis").style.width="948px"; }
			if(  element_o( "res_fea_vdo" ) )       {  p_o("res_fea_vdo").style.display="none";     }
			if(  element_o( "tv_feach_dis" ) )      {  p_o("tv_feach_dis").style.display="none";    }
			if(  element_o( "tv_rel_ser_dis" ) )    {  p_o("tv_rel_ser_dis").style.display="none";  }
			RES_VIDEOS.setShowPagination( true );	
			RES_VIDEOS.refresh( Obj );
		}else if (  ( global_featured_count  > 1 ) &&  (global_var_stat == 2)  ){

			//alert(  "5.2" )
			RES_VIDEOS.setShowNumResults(8);
			RES_VIDEOS.refresh( Obj );  // fetch video resuls
			RES_FEA_VIDEOS.refresh( LST_FEA );
			RES_CHAN.refresh(Obj);
			RES_TAGS.refresh(Obj);
		}else{
			//alert( "5.3" );
			RES_VIDEOS.refresh( Obj );
		}
		if(  element_o( "topQuery2" ) )   { p_o( "topQuery2" ).value=Obj.query;   p_o( "topQuery2" ).className="nobg";   }
		if(  element_o( "topfQuery2" ) )   { p_o( "topfQuery2" ).value=Obj.query; p_o( "topfQuery2" ).className="nobg";  }
	}
	else
	{
		///  case 1 : if total results available is < 30  its a standard mode
		global_videos_count = Obj.VideoSet.totalResultsAvailable;
		//alert( global_videos_count );
		//alert( global_featured_count);

		if( global_videos_count < 1 && global_featured_count < 1 )
		{ 
			if(  element_o( "tv_vcontainer_dis" ) ) {  p_o("tv_vcontainer_dis").style.width="948px"; }
			if(  element_o( "res_fea_vdo" ) )       {  p_o("res_fea_vdo").style.display="none";     }
			if(  element_o( "tv_feach_dis" ) )      {  p_o("tv_feach_dis").style.display="none";    }
			if(  element_o( "tv_rel_ser_dis" ) )    {  p_o("tv_rel_ser_dis").style.display="none";  }

			if(  element_o( "tv_tabs_block" ) )    {  p_o("tv_tabs_block").style.display="none";  }
			


			var theSTML = '';
			theSTML +='<div align="center" ><br/><br/>Your search for <b>'+ Obj.query + '</b> did not return any results.<br/>';
			theSTML +='To get more results, we recommend that you<br/>';

			theSTML +='<ul><li>use fewer words in your query,</li>';
		    theSTML +='<li> check your spelling,</li>';
			theSTML +='<li> remove any double quotes, or</li>';
			theSTML +='<li> rephrase your search using synonyms or related words.</li><ul></div>';

			if(  element_o( "ResultsDiv1" ) )     { p_o( "ResultsDiv1" ).innerHTML=theSTML; }

		}
		else if( global_videos_count < 30 )
		{
			if( Obj.VideoSet )
			{
				//alert( "6.1");
				RES_VIDEOS.setShowPagination( true );
				RES_VIDEOS.refresh( Obj );  // fetch video resuls
			}
			else
			{
				if(  element_o( "tv_tabs_block" ) )    {  p_o("tv_tabs_block").style.display="none";  }
				var theSTML = '';
				theSTML +='<div align="center" ><br/><br/>Your search for <b>'+ Obj.query + '</b> did not return any results.<br/>';
				theSTML +='To get more results, we recommend that you<br/>';

				theSTML +='<ul><li>use fewer words in your query,</li>';
			    theSTML +='<li> check your spelling,</li>';
				theSTML +='<li> remove any double quotes, or</li>';
				theSTML +='<li> rephrase your search using synonyms or related words.</li><ul></div>';

				if(  element_o( "ResultsDiv1" ) )     { p_o( "ResultsDiv1" ).innerHTML=theSTML; }

			}
			if(  element_o( "tv_vcontainer_dis" ) ) {  p_o("tv_vcontainer_dis").style.width="948px"; }
			if(  element_o( "res_fea_vdo" ) )       {  p_o("res_fea_vdo").style.display="none";     }
			if(  element_o( "tv_feach_dis" ) )      {  p_o("tv_feach_dis").style.display="none";    }
			if(  element_o( "tv_rel_ser_dis" ) )    {  p_o("tv_rel_ser_dis").style.display="none";  }


		}     /////  case 2 : if total results > 30 and total featured results < 1 its a standard mode
		else if( ( global_videos_count > 30  &&  global_featured_count  < 1 )  ||  (  Obj.query.indexOf("channel:")  > -1 ) || ( Obj.query.indexOf("tag:")  > -1 )    ){
			//alert( "6.2" );

			
			RES_VIDEOS.setShowPagination( true );	
			RES_VIDEOS.refresh( Obj );  // fetch video resuls
			if(  element_o( "tv_vcontainer_dis" ) )  {  p_o("tv_vcontainer_dis").style.width="948px"; }
			if(  element_o( "res_fea_vdo" ) )        {  p_o("res_fea_vdo").style.display="none";     }
			if(  element_o( "tv_feach_dis" ) )       {  p_o("tv_feach_dis").style.display="none";    }
			if(  element_o( "tv_rel_ser_dis" ) )     {  p_o("tv_rel_ser_dis").style.display="none";  }
			

		}else ///  otherwise  : its a composite mode 
		{
			//alert( "6.3" );
			RES_VIDEOS.setShowNumResults(8);
			RES_VIDEOS.refresh( Obj );  // fetch video resuls
			RES_FEA_VIDEOS.refresh( LST_FEA );
			RES_CHAN.refresh(Obj);
			RES_TAGS.refresh(Obj);
		}
		if(  element_o( "topfQuery2" ) )     { p_o( "topQuery2" ).value=Obj.query; p_o( "topQuery2" ).className="nobg"; }
		if(  element_o( "topfQuery2" ) )     { p_o( "topfQuery2" ).value=Obj.query;p_o( "topfQuery2" ).className="nobg";  }

	}
}

//  #####  PREVE PAGE OBJECTS #####
/** using two objects for preview page 
1.videoPreviewLoad         -- to get the preview details of the specific video ( query : id:videoID )
2.videoPreviewRelatedLoad  -- to get the relted channels/categories/tags and videos ( query : sim:videoID )	
*/
//#####   PREVIEW LOAD ##### 
function videoPreviewLoad( query )
{	
	PRE = new TruveoVideoSearch(apiID);
	PRE.query= query;
	PRE.showAdult= ffltr;
	PRE.attachEvent('onload', 'prevLoad(reloadStateFlag, PRE);');
	PRE.attachEvent('onupdate', 'prevUpdate(methodName, PRE);');
	PRE.initialize();

	AOL_PREV_DETAILS            = new PreviewDetails("tv_pre_det");
}
function prevLoad( reloadStateFlag, TObj ) {
	prevVideos(TObj.query,TObj.start, TObj );
}
function prevVideos(query, start, TObj) { 
	if (arguments.length < 2) { TObj.getVideos(query); }
	else {TObj.getVideos(query, start);}
}

/*    Preivew Related Videos/categories/channels/tags  */
function videoPreviewRelatedLoad( query )
{
	PRE_REL_VID = new TruveoVideoSearch(apiID);
	PRE_REL_VID.query= query;
	PRE_REL_VID.showAdult=ffltr;
	PRE_REL_VID.showRelatedItems=1;
	PRE_REL_VID.tagResults=50;
	PRE_REL_VID.channelResults=50;
	PRE_REL_VID.categoryResults=50;
	PRE_REL_VID.attachEvent('onload', 'prevLoad(reloadStateFlag, PRE_REL_VID);');
	PRE_REL_VID.attachEvent('onupdate', 'prevUpdate(methodName, PRE_REL_VID);');
	PRE_REL_VID.initialize();

	AOL_PREV_RELATED_VIDEOS     = new VideosList("tv_rel_vdo");
	AOL_PREV_RELATED_VIDEOS.setHeaderText("Related Videos");
	AOL_PREV_RELATED_VIDEOS.setTruncate(50);
	AOL_PREV_RELATED_VIDEOS.setFooterText("See all related videos >");
	AOL_PREV_RELATED_VIDEOS.setShowQuery(false);
	AOL_PREV_RELATED_VIDEOS.setShowRating(true);


	AOL_PREV_RELATED_CHANNELS   = new RelatedChannels( "tv_rel_cha" );
	AOL_PREV_RELATED_CATEGORIES = new RelatedCategories( "tv_rel_cat" );
       AOL_PREV_RELATED_TAGS       = new RelatedTags("tv_rel_tags" );

}

function prevUpdate( methodB, Obj )
{
	if( (methodB == "getVideos")  && ( Obj.query.indexOf("id:") >= 0) && ( Obj.VideoSet.totalResultsAvailable == 1) && (Obj==PRE)  )
	{
		AOL_PREV_DETAILS.refresh( Obj.VideoSet );
	}

	if(  (methodB == "getVideos") && (Obj==PRE_REL_VID) )
	{
		AOL_PREV_RELATED_CHANNELS.refresh(Obj);
		AOL_PREV_RELATED_CATEGORIES.refresh(Obj);
		AOL_PREV_RELATED_TAGS.refresh(Obj);
		AOL_PREV_RELATED_VIDEOS.refresh(Obj);
	}
}  /// END of  Preview Load 

// #####  preview snag load #####

function videoPreviewSnagLoad( query )
{	
	PSNG = new TruveoVideoSearch(apiID);
	PSNG.query= query;
	PSNG.attachEvent('onload', 'prevSnagLoad(reloadStateFlag, PSNG);');
	PSNG.attachEvent('onupdate', 'prevSnagUpdate(methodName, PSNG);');
	PSNG.initialize();

	AOL_PREV_SNAG_DETAILS  = new PreviewSnagDetails("tv_pre_snag_det");
}
function prevSnagLoad( reloadStateFlag, TObj ) {
	prevSnagVideos(TObj.query,TObj.start, TObj );
}
function prevSnagVideos(query, start, TObj) { 
	if (arguments.length < 2) { TObj.getVideos(query); }
	else {TObj.getVideos(query, start);}
}

function prevSnagUpdate( methodB, Obj )
{
	if( (methodB == "getVideos")  && ( Obj.query.indexOf("id:") >= 0) && ( Obj.VideoSet.totalResultsAvailable == 1) && (Obj==PSNG)  )
	{
		AOL_PREV_SNAG_DETAILS.refresh( Obj.VideoSet );
	}
}  /// END of  Preview Load 

// #####  Related Videos/Featured Videos / ChannelSpecific Videos #####   
/** function is used to display the videolisting like videoimage, videotitle, channel, 
category, views, rating and pagination
*/
var VideosList   = function (containerID)
{
	var showHeader = true;
//	var charLimit = 16;			// The maximum number of characters to display in each menu item.
	var showquery = true;
	var headerText= ""; 
	var footerText= "";
	var smallModuleView = false;
	var userRatingCountThreshold = 1;
	var showPagination=false;
	var truncateChar = 0;
	var showNumResults = 0;
	var showRating = false;

	var position=0;
	var pageresults=0;
	var page  =0;
	var totalpages = 0;
	var abc = 0;

	//public function 
	this.getHTML = function(Obj) {

		var VideoSet=Obj.VideoSet;	
		var query = Obj.query;
		var qry_before_truncate = query;	

		query = query.replace(/\s?channel:\S*(\s*\S*)*\S*/gi, '');
		query = query.replace(/\s?category:\S*(\s*\S*)*\S*/gi, '');
		query = escape(query);

		var theHTML = '';
		var theHTMLPage = '';
             
		if ( this.getHeaderText() != undefined  ) { theHTML += '<h2>'+ this.getHeaderText() + '</h2>'; }

		if (("totalResultsReturned" in VideoSet) && (VideoSet.totalResultsReturned > 0)) {

			for (var i=0; i < 2; i++) {
			var theVideo = VideoSet.Video[i]; 
                     
				if( theVideo ){
					if( this.getSmallModuleView() ){theHTML += '<div class="tv_videoitem tv_list_feat" style="_display:block">'; }
					else{
						if( i == 1) theHTML += '<div class="tv_videoitem modsmall" style="_display:block"  id ="vblock">';
						else        theHTML += '<div class="tv_videoitem modsmall" style="_display:block">';       
             				}
		       
                                  theHTML += '<a href="javaScript:playVideo(\''+theVideo.videoUrl+'\');"><img src="'+theVideo.thumbnailUrl+'" class="thumbnail" title="'+theVideo.title+'" alt="'+theVideo.title+'"/></a>';
                                                    
					if( this.getSmallModuleView()) {theHTML += '<div class="tv_tabs tv_feat">';} 
					else{
						theHTML += '<div class="tv_abs">';
						}


                         var tmp_str = theVideo.title;
					if( this.getTruncate() > 0  && tmp_str.length > this.truncateChar ){
						//alert( "trun" );
						theHTML += '<div class="tv_head"><a href="javaScript:playVideo(\''+theVideo.videoUrl+'\');"  alt="'+theVideo.title+'" title="'+theVideo.title+'"><b>'+VSUTIL.truncateString(theVideo.title, this.getTruncate())+'</b></a></div>';
					}else{
						//alert( "no" );
						theHTML += '<div class="tv_head"><a href="javaScript:playVideo(\''+theVideo.videoUrl+'\');"  alt="'+theVideo.title+'" title="'+theVideo.title+'"><b>'+ theVideo.title+'</b></a></div>';
					}
					
					theHTML += '<ul>';

					// check the condition to show the query term in query	
  				     if(this.getShowQuery())
     			            {
                                  	if( "channel" in theVideo && theVideo.channel.length > 17 ){

					  if( "channel" in theVideo ) { theHTML += '<li>Channel: ' + VSUTIL.truncateString(theVideo.channel, 17) + '</a></li>'; }
                                  }else{ 
                                    if( "channel" in theVideo ) { theHTML += '<li>Channel: ' + VSUTIL.escapeHTML(theVideo.channel) + '</a></li>'; }
                                  } 
					if( "category" in theVideo && theVideo.category.length > 17 ){

					  if( "category" in theVideo ) { theHTML += '<li>Category: ' + VSUTIL.truncateString(theVideo.category, 17) + '</a></li>'; }
                                  }else{ 
                                    if( "category" in theVideo ) { theHTML += '<li>Category: ' + VSUTIL.escapeHTML(theVideo.category) + '</a></li>'; }
                                  }
                                  if( "tags" in theVideo && theVideo.tags.length > 21 ){

					  if( "tags" in theVideo ) { theHTML += '<li>Tags: ' + VSUTIL.truncateString(theVideo.tags, 21) + '</a></li>'; }
                                  }else{ 
                                    if( "tags" in theVideo ) { theHTML += '<li>Tags: ' + VSUTIL.escapeHTML(theVideo.tags) + '</a></li>'; }
                                  }

						// rating should come here   N.P:

						/*if( "userRating" in theVideo && this.getShowRating() )
						{
							var rating = Math.round(theVideo.userRating) * 10;
							// rating
							theHTML +='<li class="clear_rating"><div style="padding:0; font-weight:bold; float:left; margin-right:5px;">Rating :</div>';
							theHTML +='<div style="float:left; width:60px; height:12px;"><ul class="star-rating">';
							theHTML +='<li style="width:'+ rating +'px;font-size:8px;" class="current-rating" id="currentrating'+theVideo.id+'"> </li>';
							theHTML +='</ul></div>';
							theHTML +='</li>';
						}*/

						//if (("userRatingCount" in theVideo) && (parseInt(theVideo.userRatingCount) >= userRatingCountThreshold)) { 
						//	theHTML += '<li>Rating:  <span>(rated '+theVideo.userRatingCount+' time'+(theVideo.userRatingCount==1?'':'s')+')</span></li>';
						//}

					}else
					{
					if( "channel" in theVideo && theVideo.channel.length > 17 ){

					  if( "channel" in theVideo ) { theHTML += '<li>Channel: ' + VSUTIL.truncateString(theVideo.channel, 17) + '</a></li>'; }
                                  }else{ 
                                    if( "channel" in theVideo ) { theHTML += '<li>Channel: ' + VSUTIL.escapeHTML(theVideo.channel) + '</a></li>'; }
                                  } 
					if( "category" in theVideo && theVideo.category.length > 17 ){

					  if( "category" in theVideo ) { theHTML += '<li>Category: ' + VSUTIL.truncateString(theVideo.category, 17) + '</a></li>'; }
                                  }else{ 
                                    if( "category" in theVideo ) { theHTML += '<li>Category: ' + VSUTIL.escapeHTML(theVideo.category) + '</a></li>'; }
                                  }
                                  if( "tags" in theVideo && theVideo.tags.length > 21 ){

					  if( "tags" in theVideo ) { theHTML += '<li>Tags: ' + VSUTIL.truncateString(theVideo.tags, 21) + '</a></li>'; }
                                  }else{ 
                                    if( "tags" in theVideo ) { theHTML += '<li>Tags: ' + VSUTIL.escapeHTML(theVideo.tags) + '</a></li>'; }
                                  }

						/*if( "userRating" in theVideo && this.getShowRating() )
						{
							var rating = Math.round(theVideo.userRating) * 10;
							// rating
							theHTML +='<li class="clear_rating"><div style="padding:0; font-weight:bold; float:left; margin-right:5px;">Rating :</div>';
							theHTML +='<div style="float:left; width:60px; height:12px;"><ul class="star-rating">';
							theHTML +='<li style="width:'+ rating +'px;font-size:8px;" class="current-rating" id="currentrating'+theVideo.id+'"> </li>';
							theHTML +='</ul></div>';
							theHTML +='</li>';
						}*/

					}
					if ("viewCount" in theVideo || "dateFound" in theVideo ) { 
						theHTML += '<li>Views: <span>';
						if( "viewCount" in theVideo ) { theHTML += theVideo.viewCount; } else theHTML += '0';
						if ("dateFound" in theVideo) { theHTML += '&nbsp;|&nbsp;' + VSUTIL.getShortDateString(theVideo.dateFound); }
						theHTML += '</span></li>'; 
					}
					//if ("runtime" in theVideo) { theHTML += '<li style="font-weight:normal;">' + VSUTIL.getRuntimeString(theVideo.runtime) + '</li>'; } 
					//getShortDateString

					theHTML += '</ul>';
					theHTML += '</div>';
					theHTML += '</div>';
				}   // the vide ends 
                             
			
			}  // end for

			if( this.getShowPagination() )	{
				
				theHTML +='<div class="clearBoth"> </div>';
				theHTML += '<div class="padr10 pagenumber margin10">';	
				theHTML += '<div id="pagination">';
				theHTMLPage += '<div id="pagination">';
				theHTML += '<div class="pgCon" width="100%">';
				theHTMLPage += '<div class="pgCon" width="100%">';
				
				var from  = parseInt( VideoSet.firstResultPosition) + 1;
				var to    = parseInt( VideoSet.firstResultPosition ) + parseInt(VideoSet.totalResultsReturned );

				// pagination starts here 
				theHTML += '<div class="pg_results"><b>Showing Results ' + from   + '-'+ to +' of '+VideoSet.totalResultsAvailable + '</b></div>';

				position = VideoSet.firstResultPosition;
				var resultsavail = VideoSet.totalResultsAvailable;
				totalpages = parseInt( resultsavail )/Obj.results  + 1;
               
				if( position > 0 ){	page = (position / Obj.results)+1; }
                else{page = 1;  start = 1; end=10;}

				if(page > 6){ start= page-5; end = page+4; }
				else if( page <= 6 && page > 1 ) { start= page-1; end = page+8;	}
			
				if( Obj.hasPreviousPage())
				{
					var pa = parseInt(page - 1);
					theHTML +='<div class="page nxttxt"><a href="#" onClick="goToPage('+ pa +')"><b> Prev  </b></a></div>';
					theHTMLPage +='<div class="page nxttxt"><a href="#" onClick="goToPage('+ pa +')"><b> Prev  </b></a></div>';
				}

				

				for( var i=start; i<=end; i++ )
				{
					if(  page == i && totalpages >= 2 ){
						theHTML += '<div class="page  currentPage"><b>' + i + '</b></div>';
						theHTMLPage += '<div class="page  currentPage"><b>' + i + '</b></div>';
					}else if (  page == i && totalpages < 2 )
					{
						var abc = 1;
						theHTMLPage + '<div class="pageblank">.&nbsp;<div>';
					}else{
						if ( i < totalpages && totalpages >= 2 ){
						theHTML += '<div class="page"><a href="#" onClick="goToPage('+ i +')"><b>' + i + '</b></a></div>';
						theHTMLPage += '<div class="page"><a href="#" onClick="goToPage('+ i +')"><b>' + i + '</b></a></div>';
						}
					}
				}
				if( Obj.hasNextPage())
				{
					var pa = parseInt(page + 1 ); 
					theHTML +='<div class="page nxttxt"><a href="#" onClick="goToPage('+ pa +')"><b>  Next </b></a></div>';
					theHTMLPage +='<div class="page nxttxt"><a href="#" onClick="goToPage('+ pa +')"><b>  Next </b></a></div>';
				}

			    theHTML += '</div>';
				theHTMLPage += '</div>';
				theHTML += '<div class="clearBoth"> </div>';
				theHTMLPage += '<div class="clearBoth"> </div>';
				theHTML += '</div>';
				theHTMLPage += '</div>';
	
				if(  element_o( "top_pag" ) )  {
				if(  abc != 1 )	{ p_o( "top_pag" ).style.display = 'block'; }else { p_o( "top_pag" ).style.display = 'none';  }
					p_o( "top_pag" ).innerHTML = theHTMLPage;  
				}
			}
			else
			{
			//theHTML += '<div class="searchfooter">';
			
			if(this.getShowNumResults() > 0 )
			{
				var from  = parseInt( VideoSet.firstResultPosition) + 1;
				var to    = parseInt( VideoSet.firstResultPosition ) + parseInt(VideoSet.totalResultsReturned );

				theHTML += '<div id="seemorevideos" class="seemorevideos">';
				theHTML += '<span><b>Showing Results  '+  from +'-'+ to +' of '+ VideoSet.totalResultsAvailable + '</b></span>'; 
				theHTML += '<a id="aolmod_seeall" href="/video-old/search.jhtml?query='+VSUTIL.escapeHTML(qry_before_truncate)+'&amp;type=standard&amp;familyfilter='+ffltr+'">';

				if ( this.getFooterText() != undefined  ) { theHTML += this.getFooterText(); }
				else theHTML +='See All Videos >';

				theHTML += '</a>';

				theHTML += '</div>';
			}else{
				/*theHTML += '<div id="seemorevideos">';
				theHTML += '<a id="aolmod_seeall" href="/video-old/search.jhtml?query='+VSUTIL.escapeHTML(qry_before_truncate)+'&amp;type=standard&amp;familyfilter='+ffltr+'">';
				if ( this.getFooterText() != undefined  ) { theHTML += this.getFooterText(); }
				else theHTML +='See All Videos >';

				theHTML += '</a>';
				theHTML += '</div>';*/
			}
			//theHTML += '</div>';
			}
			}  // end if 
		else { 
			
			//theHTML += 'no related videos'; 
			if(  element_o( containerID ) )  { p_o( containerID ).style.display = 'none'; }
		}
		return(theHTML);
	}  // end public function getHTML

	this.refresh = function(Object) {
		if (Object.VideoSet) {    
			if(  element_o( containerID ) )  { p_o( containerID ).innerHTML = this.getHTML(Object);  }
		}
	}
	// Function clear() will display nothing in this menu.
	this.clear = function() {
		if(  element_o( containerID ) )  { p_o( containerID ).innerHTML = ''; }
	}
	this.setShowQuery = function(bool) {
		this.showquery = bool;
	}
	// Returns the value of the current view.
	this.getShowQuery = function() {
		return(this.showquery);
	}
	this.setHeaderText = function( text ) {
		this.headerText = text;
	}
	// Returns the value of the current view.
	this.getHeaderText = function() {
		return(this.headerText);
	}

	this.setFooterText = function( text ) {
		this.footerText = text;
	}
	// Returns the value of the current view.
	this.getFooterText = function() {
		//return(this.footerText);
                return;
	}


	// to show the small module view 
	this.setSmallModuleView = function( bool )
	{
		this.smallModuleView = bool;
	}
	this.getSmallModuleView = function( )
	{
		return this.smallModuleView;
	}

	// set the boolean value to show the pagination 
	this.setShowPagination = function( bool )
	{
		this.showPagination = bool;
	}
	this.getShowPagination = function( )
	{
		//return (this.showPagination);
                return false;
	}

	// set the truncate number of characters 
	this.setTruncate = function( num )
	{
		this.truncateChar = num;
	}
	this.getTruncate = function( )
	{
		return this.truncateChar;
	}
	// to show number of results  
	this.setShowNumResults = function( num )
	{
		this.showNumResults = num;
	}
	this.getShowNumResults = function ( )
	{
		return this.showNumResults;
	}

	// set the boolean value to show the pagination 
	this.setShowRating = function( bool )
	{
		this.showRating = bool;
	}
	this.getShowRating = function( )
	{
		return (this.showRating);
	}



}   // end function VideosList


// ##### Preview Details #####
var PreviewDetails = function ( containerID )
{
	var showHeader = true;
	var charLimit = 200;			// The maximum number of characters to display in each menu item.
	//public function 
	this.getHTML = function(VideoSet,query) {
	var theHTML = '';
	var theShare= '';
	var userRatingCountThreshold = 1;

// alert( VideoSet.totalResultsReturned + "returned" );

	if (("totalResultsReturned" in VideoSet) && (VideoSet.totalResultsReturned > 0)) {
		for (var i=0; i < VideoSet.totalResultsReturned; i++) {
		var theVideo = VideoSet.Video[i]; 
			if( theVideo ){
				if ("title" in theVideo)  { theHTML += '<h1>' + VSUTIL.escapeHTML(theVideo.title) + '</h1>'; }
				theHTML += '<div class="tv_video tv_bc">';	

			//alert( theVideo.thumbnailUrl  + "thumbnail url ");
			//alert( theVideo.videoPlayerEmbedTag  + "embed tag");

				// dispalying embedded tag
				if( "videoPlayerEmbedTag" in theVideo && theVideo.videoPlayerEmbedTag!="" ) { theHTML += '<div  style="text-align:center">'+ theVideo.videoPlayerEmbedTag+'</div>' ;   }
				else if ( "thumbnailUrl"  in theVideo)
				{
					//preview image generated with thumbnail	
					theHTML +='<div id="tv_pre_det">';
					theHTML +='<div class="vid_pre">';
					theHTML +='<div id="largethumb" class="smallthumbdetail">';
					theHTML +='<div id="ne">';
					theHTML +='<div id="nec" style="background-image: url('+ theVideo.thumbnailUrl +'); background-repeat: repeat;">';
					theHTML +='<a href=""/>';
					theHTML +='<div id="neo"/>';
					theHTML +='<div id="neoc">';
				    theHTML +='<a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); "></a>';
					theHTML +='<span class="playVideo">';
				    theHTML +='<a href="javascript:playVideo(\''+theVideo.videoUrl+'\','+theVideo.id+'); ">';
				    theHTML +='<img border="0" src="../../video-old/i/ply_btn.gif"/>';
					theHTML +='<span class="playVideo">Play Video</span>';
			        theHTML +='</a>';
				    theHTML +='</span>';
		            theHTML +='<p class="vidOver"> This video can only be played from the original site where it is hosted. <br/>Click here to open a new window and play this video from';
		            theHTML +='<br/>';
    				theHTML += theVideo.channelUrl;
			        theHTML += '<br/>';
				    theHTML += '</p>';
				    theHTML += '</div></div></div></div></div></div></div>';
				}
				//<!-- video Details  -->	
				theHTML += '<div class="tv_vidcont">';
				theHTML += '<h2>'+VSUTIL.escapeHTML(theVideo.title)+'</h2>';
				theHTML += '<span class="tv_vid">';
				if( "description" in theVideo )  
				{
					var desc = theVideo.description;	
					if(desc.length > charLimit){
					theHTML += '<p  class="desc">'+VSUTIL.truncateString(desc, charLimit)+'<span class="show">.</span><span class="hide" id="desc">'+ theVideo.description +'</span></p>';
					theHTML += '<span>(<a id="descmore" class="descmore" href="Javascript:showePopup(\'desc\',\'epopupContent\')">more</a>)</span><div id="epopupContent" class="epopup" style="position:relative;"></div>';  // epopupContent
					}else
					{theHTML += '<p id="desc" class="desc">' + theVideo.description + '</p>';}
				}
				theHTML += '<ul>';
				if( "channel" in theVideo ) { theHTML += '<li>Channel: <a href="'+result_url+'channel:'+VSUTIL.escapeHTML(theVideo.channel)+'&familyfilter='+ffltr+'">' + VSUTIL.escapeHTML(theVideo.channel) + '</a></li>'; }
				if ("dateFound" in theVideo) { theHTML += '<LI>Added:  ' +theVideo.dateFound+'</li>'; }
				//if ("dateProduced" in theVideo) { theHTML += '<li>Added:'+VSUTIL.escapeHTML(theVideo.dateProduced) + '</li>'; } 
				if ("runtime" in theVideo) { theHTML += '<li>Duration: '+VSUTIL.getRuntimeString(theVideo.runtime)+ '</li>'; } 

				
				if( "userRating" in theVideo )
				{
				var rating = Math.round(theVideo.userRating) * 10;
				// rating
				theHTML +='<li class="clear_rating"><div style="padding:0; float:left; margin-right:5px;" id="tv_ratings_block">Rating: </div> ';
				theHTML +='<div style="float:left; width:60px; height:12px; position:relative;"><ul class="star-rating">';
				theHTML +='<li style="width:'+ rating +'px;" class="current-rating" id="currentrating"></li>';
					theHTML +='<li><a class="one-stars" title="1/5" href="javascript:submitRating('+theVideo.id+', 1);" id="'+theVideo.id+'_star1">1</a></li>';
					theHTML +='<li><a class="two-stars" title="2/5" href="javascript:submitRating('+theVideo.id+', 2);" id="'+theVideo.id+'_star2">2</a></li>';
					theHTML +='<li><a class="three-stars" title="3/5" href="javascript:submitRating('+theVideo.id+', 3);" id="'+theVideo.id+'_star3">3</a></li>';
					theHTML +='<li><a class="four-stars" title="4/5" href="javascript:submitRating('+theVideo.id+', 4);" id="'+theVideo.id+'_star4">4</a></li>';
					theHTML +='<li><a class="five-stars" title="5/5" href="javascript:submitRating('+theVideo.id+', 5);" id="'+theVideo.id+'_star5">5</a></li>';
				theHTML +='</ul></div>';
					theHTML += ' (rated '+theVideo.userRatingCount+' time'+(theVideo.userRatingCount==1?'':'s')+')</li>';
				}
				else{
				theHTML +='<li class="clear_rating"><div style="padding:0; float:left; margin-right:5px;"  id="tv_notratings_block">Not Yet Rated: </div><div style="float:left; width:60px; height:12px;position:relative;"><ul class="star-rating">';
				theHTML +='<li style="width:'+ rating +'px;" class="current-rating" id="currentrating"></li>';
					theHTML +='<li><a class="one-stars" title="1/5" href="javascript:submitRating('+theVideo.id+', 1);" id="'+theVideo.id+'_star1">1</a></li>';
					theHTML +='<li><a class="two-stars" title="2/5" href="javascript:submitRating('+theVideo.id+', 2);" id="'+theVideo.id+'_star2">2</a></li>';
					theHTML +='<li><a class="three-stars" title="3/5" href="javascript:submitRating('+theVideo.id+', 3);" id="'+theVideo.id+'_star3">3</a></li>';
					theHTML +='<li><a class="four-stars" title="4/5" href="javascript:submitRating('+theVideo.id+', 4);" id="'+theVideo.id+'_star4">4</a></li>';
					theHTML +='<li><a class="five-stars" title="5/5" href="javascript:submitRating('+theVideo.id+', 5);" id="'+theVideo.id+'_star5">5</a></li>';
				theHTML +='</ul></div>';
				}

				//VSUTIL.getRatingButtons(theVideo.id)
				if ("category" in theVideo) { theHTML += '<li>Category: <a href="'+result_url+'category:'+VSUTIL.escapeHTML(theVideo.category)+'">' + VSUTIL.escapeHTML(theVideo.category) + '</a> </li>'; } 
				theHTML += '</ul>';
				theHTML += '</span>';
				theHTML += '</div>';
				theHTML += '</div> '; //<!-- video ends here -->

				if(  element_o( "videourl" ) )  { p_o( "videourl" ).value =  host_name+'/video-old/detail.jhtml?query='+theVideo.id; }
				if(  element_o( "embed_code" ) )  { p_o( "embed_code" ).value =  theVideo.videoResultEmbedTag; }


				var pre_wid = '<a  rel="gb_page_center[425,130]" title="Preview" href="'+host_name+'/video-old/snagpreview.jhtml?id='+theVideo.id+'"> Preview this widget </a>';
				if(  element_o( "prev_wid" ) )  { p_o( "prev_wid" ).innerHTML =  pre_wid; }

				var video_page_name = host_name+'/video-old/detail.jhtml?query='+theVideo.id;

				video_name = theVideo.title;
				abc = video_name.replace(/\'/g,' ');
				vid_name = abc.replace(/\"/g,' ');


				theShare += '<span class="share_cate" style="margin-top: 6px; margin-right: 12px;">';
				theShare += '<a style="font-size: 12px; margin-right: 12px;" onclick="launchIM(\'' + video_page_name +'\',\''+ vid_name +'\'); return false;" href="javascript:void(0);" shape="rect" class="pi_Runningman"> IM This </a> |';
				theShare += '<a style="margin-left: 12px; font-size: 12px;" onclick="launchEmail(\''+video_page_name +'\',\''+ vid_name +'\'); return false;" href="javascript:void(0);" shape="rect" class="pi_Send"> E-mail This</a>';
				theShare += '</span>';


				if(  element_o( "share_con" ) )  { p_o( "share_con" ).innerHTML =  theShare; }

				//document.getElementById( "videourl" ).value= 'http://www.aol.in/video-old/detail.html?query='+theVideo.id;
				//document.getElementById( "embed_code" ).value=theVideo.videoResultEmbedTag;

			}   // the vide ends 
		}  // end for
	}  // end if 
	else { theHTML += 'no preview details available'; }
	return(theHTML);
	}  // end public function getHTML

	this.refresh = function(VideoSet, query) {
		if (VideoSet) {
			if(  element_o( containerID ) )  { p_o( containerID ).innerHTML = this.getHTML(VideoSet, query);  }
		}
	}
	// Function clear() will display nothing in this menu.
	this.clear = function() {
		if(  element_o( containerID ) )  { p_o( containerID ).innerHTML = ''; }
	}
}  //  END PreviewDetails

// ##### SNAG DETAILS #####
var PreviewSnagDetails = function ( containerID )
{
	var showHeader = true;
	var charLimit = 100;			// The maximum number of characters to display in each menu item.
	//public function 
	this.getHTML = function(VideoSet,query) {
	var theHTML = '';

	if (("totalResultsReturned" in VideoSet) && (VideoSet.totalResultsReturned > 0)) {
		for (var i=0; i < VideoSet.totalResultsReturned; i++) {
		var theVideo = VideoSet.Video[i]; 
			if( theVideo ){

				// dispalying embedded tag
				if( "videoResultEmbedTag" in theVideo ) { theHTML += '<div>'+ theVideo.videoResultEmbedTag+'</div>' ;   }

			}   // the vide ends 
		}  // end for
	}  // end if 
	else { theHTML += 'no preview details available'; }
	return(theHTML);
	}  // end public function getHTML

	this.refresh = function(VideoSet, query) {
		if (VideoSet) {


			///alert( this.getHTML(VideoSet, query) );
			if(  element_o( containerID ) )  { p_o( containerID ).innerHTML = this.getHTML(VideoSet, query);  }
		}
	}
	// Function clear() will display nothing in this menu.
	this.clear = function() {
		if(  element_o( containerID ) )  { p_o( containerID ).innerHTML = ''; }
	}
}  //  END PreviewDetails


//  #####  Related Channels ##### 
var RelatedChannels = function( 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 = 30;			// The maximum number of characters to display in each menu item.
	var showcount = false; 

	//public function 
	this.getHTML = function(Obj) {
		var ChannelSet = Obj.ChannelSet;
		var query = Obj.query;
		var theHTML = '';
		var myArr=new Array();
		var fontsize ='12px';

		// for sorting purpose i am converting it as array.
		for (var i=0; i < ChannelSet.totalResultsReturned; i++) {
			myArr[i]=new Array(ChannelSet.Channel[i].name , ChannelSet.Channel[i].count,i);
		}
		myArr.sort();
		
		if (showHeader) { theHTML += '<h2>Related Channels</h2>'; }
		if (("totalResultsReturned" in ChannelSet) && (ChannelSet.totalResultsReturned > 0)) {

		theHTML += '<div class="relate_chn">';	
			for (var i=0; i < myArr.length; i++) {

				//alert( myArr[i] );
				var channelName =  myArr[i][0];
				var channelCount = myArr[i][1];
				var channelIndex = myArr[i][2];

				if(  channelIndex < 1  ){ fontsize = "18px";}
				else if(  channelIndex > 40 ){  fontsize = "12px";}
				else if( (channelIndex > 30) && (channelIndex <40 )){ fontsize = "13px";}
				else if( (channelIndex > 20) && (channelIndex <30 )){ fontsize = "14px";}
				else if( (channelIndex > 10) && (channelIndex <20 )){ fontsize = "15px";}
				else if( (channelIndex > 0 ) && (channelIndex <10 )){ fontsize = "16px";}
				else {fontsize="12px";}


				if( this.getShowCount() )
				{
					theHTML += '<a href="'+result_url+'channel:%22'+VSUTIL.escapeHTMLString(channelName)+'%22&type=standard&familyfilter='+ffltr+'"  style="font-size:'+ fontsize  +'; " rel="'+channelCount+'">'+ VSUTIL.escapeHTML(VSUTIL.truncateString(channelName, charLimit)).replace(/\s*/gi,""); +'('+channelCount+')</a>'+' ';
				}else
				{
					theHTML += '<a href="'+result_url+'channel:%22'+VSUTIL.escapeHTMLString(channelName)+'%22&type=standard&familyfilter='+ffltr+'" style="font-size:'+ fontsize  +'; " rel="'+channelCount+'">'+VSUTIL.escapeHTML(VSUTIL.truncateString(channelName, charLimit)).replace(/\s*/gi,"");+'</a>'+ ' ';
				}
			}
		theHTML += '</div><div class="clr"></div>';
		}
		else { 
			//theHTML += 'no related channels';
			if(  element_o( containerID ) )  { p_o( containerID ).style.display = 'none'; }
		}
		return(theHTML);
	}
	this.setShowCount = function(bool) {
		showcount = boo;
	}
	// Returns the value of the current view.
	this.getShowCount = function() {
		return(showcount);
	}
	// 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(Object) {
		if (Object.ChannelSet) { 
			if(  element_o( containerID ) )  { p_o( containerID ).innerHTML = this.getHTML(Object);  }
			//document.getElementById( containerID ).innerHTML = this.getHTML(ChannelSet,query); 
		}
	}
	// Function clear() will display nothing in this menu.
	this.clear = function() {
		if(  element_o( containerID ) )  { p_o( containerID ).innerHTML  = ''; }
		//document.getElementById( containerID ).innerHTML = '';
	}
}  // end Related Channels



//    ##### Related Categories #####
var RelatedCategories = function(containerID) {
	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);
	var showHeader = true;  	// The boolean that determines if a menu header is displayed.
	var charLimit = 30;			// The maximum number of characters to display in each menu item.
	var showcount = false;
	// PUBLIC METHODS:		
	// Function getHTML() returns HTML to display a menu containing the categories provided in the CategorySet object.
	this.getHTML = function(Obj) {
		var CategorySet = Obj.CategorySet;
		var query = Obj.query;
		var theHTML = '';
		var myArr=new Array();
		var fontsize ='18px';


		// for sorting purpose i am converting it as array.
		for (var i=0; i < CategorySet.totalResultsReturned; i++) {
			myArr[i]=new Array(CategorySet.Category[i].name , CategorySet.Category[i].count, i);
		}
		myArr.sort();

		if (showHeader) { theHTML += '<h2>Related Categories</h2>'; }
		if (("totalResultsReturned" in CategorySet) && (CategorySet.totalResultsReturned > 0)) {
		theHTML += '<div class="relate_chn">';
			for (var i=0; i < myArr.length; i++) {
				var categoryName = myArr[i][0];
				var categoryCount = myArr[i][1];
				var categoryIndex = myArr[i][2];

				if( categoryIndex < 1 ){ fontsize = "18px";}
				else if( categoryIndex > 40 ){  fontsize = "12px";}
				else if( (categoryIndex > 30) && (categoryIndex <40 )){ fontsize = "13px";}
				else if( (categoryIndex > 20) && (categoryIndex <30 )){ fontsize = "14px";}
				else if( (categoryIndex > 10) && (categoryIndex <20 )){ fontsize = "15px";}
				else if( (categoryIndex > 0 ) && (categoryIndex <10 )){ fontsize = "16px";}
				else {fontsize="12px";}

				if ( this.getShowCount() )
				{
					theHTML += '<a href="'+result_url+'category:%22'+ VSUTIL.escapeHTMLString(categoryName)+'%22&familyfilter='+ffltr+'" style="font-size:'+ fontsize  +'; "   rel="'+categoryCount+'">'+ VSUTIL.escapeHTML(VSUTIL.truncateString(categoryName, charLimit)).replace(/\s*/gi,"");+'('+categoryCount+')</a>';
				}else
				{
					theHTML += '<a href="'+result_url+'category:%22'+ VSUTIL.escapeHTMLString(categoryName) +'%22&familyfilter='+ffltr+'" style="font-size:'+ fontsize  +';" rel="'+  categoryCount+'">'+VSUTIL.escapeHTML(VSUTIL.truncateString(categoryName, charLimit)).replace(/\s*/gi,"");+'</a>';
				}
			}
		theHTML += '</div><div class="clr"></div>';
		}
		else {
			if(  element_o( containerID ) )  { p_o( containerID ).style.display = 'none'; }
			//theHTML += 'no related categories';
		}
		return(theHTML);
	}
	this.setShowCount = function(bool) {
		showcount = boo;
	}
	// Returns the value of the current view.
	this.getShowCount = function() {
		return(showcount);
	}
	// 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(Object) {
		if (Object.CategorySet) { 
			if(  element_o( containerID ) )  { p_o( containerID ).innerHTML = this.getHTML(Object); }
			//document.getElementById( containerID ).innerHTML = this.getHTML(CategorySet, query); 
		}
	}
	// Function clear() will display nothing in this menu.
	this.clear = function() {
		if(  element_o( containerID ) )  { p_o( containerID ).innerHTML = ''; }
		//document.getElementById( containerID ).innerHTML= '';
	}
}


// ##### Related Tags #####
var RelatedTags = function(containerID) {
	// PRIVATE ATTRIBUTES:
	var container = document.getElementById(containerID);
	var showHeader = true;  	// The boolean that determines if a menu header is displayed.
	var charLimit = 30;			// The maximum number of characters to display in each menu item.
	var showcount = false;
	// PUBLIC METHODS:		
	// Function getHTML() returns HTML to display a menu containing the tags provided in the TagSet object.
	this.getHTML = function( Obj ) {

		var TagSet = Obj.TagSet;
		var query = Obj.query;
		var theHTML = '';
		var myArr=new Array();
		var fontsize ='';
		
			// for sorting purpose i am converting it as array.
			for (var i=0; i < TagSet.totalResultsReturned; i++) {
				 
				myArr[i]=new Array( TagSet.Tag[i].name , TagSet.Tag[i].count, i);
			}
			myArr.sort();

			//alert(myArr);

			if (showHeader) { theHTML += '<h2><nobr>Related Tags</h2>'; }
			if (("totalResultsReturned" in TagSet) && (TagSet.totalResultsReturned > 0)) {
			theHTML += '<div class="relate_chn">';
	
			for (var i=0; i < myArr.length; i++) {

				//alert( myArr[i] );
				var tagName = myArr[i][0];
				var tagCount = myArr[i][1];
				var tagindex = myArr[i][2];

				if( tagindex < 1 )	{ fontsize = "18px";}
				else if( tagindex > 40 ){  fontsize = "12px";}
				else if( (tagindex > 30 ) && (tagindex <40 ) ){ fontsize = "13px";}
				else if( (tagindex > 20 ) && (tagindex <30 ) ){ fontsize = "14px";}
				else if( (tagindex > 10 ) && (tagindex <20 ) ){ fontsize = "15px";}
				else if( (tagindex > 0  ) && (tagindex < 10) ){ fontsize = "16px";}
				else{fontsize="12px;"}

				if ( this.getShowCount() )
				{
					theHTML += '<a href="'+result_url+'tag:%22'+VSUTIL.escapeHTMLString(tagName)+'%22&type=standard&familyfilter='+ffltr+'"  style="font-size:'+ fontsize  +';"  rel="'+tagCount+'">'+tagName.replace(/\s*/gi,"");+'('+tagCount+') </a> ';
				}
				else
				{
					theHTML += '<a href="'+result_url+'tag:%22'+VSUTIL.escapeHTMLString(tagName)+'%22&type=standard&familyfilter='+ffltr+'"  style="font-size:'+ fontsize  +';" rel="'+tagCount+'">'+ tagName.replace(/\s*/gi,"");+'</a> ';
				}
			}
			theHTML += '</div><div class="clr"></div>';
		}
		else { 
			//theHTML += 'no related tags'; 
			if(  element_o( containerID ) )  { p_o( containerID ).style.display = 'none'; }
		}
		return(theHTML);
	}
	this.setShowCount = function(bool) {
		showcount = boo;
	}
	// Returns the value of the current view.
	this.getShowCount = function() {
		return(showcount);
	}
	// 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(Object) {
		if (Object.TagSet) { 
			if(  element_o( containerID ) )  { p_o( containerID ).innerHTML = this.getHTML( Object); }
			//document.getElementById( containerID ).innerHTML = this.getHTML(TagSet,query); 
			}
	}
	// Function clear() will display nothing in this menu.
	this.clear = function() {
		if(  element_o( containerID ) )  { p_o( containerID ).innerHTML = '';}
		//document.getElementById( containerID ).innerHTML = '';
	}
}


// Function ChannelMenu() is a view object for displaying a menu of channels returned in the ChannelSet object.
var ChannelMenu = function(containerID) {
	
	// PRIVATE ATTRIBUTES:
	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.
 	var containerID = containerID;

	// PUBLIC METHODS:		
	// Function getHTML() returns HTML to display a menu containing the channels provided in the ChannelSet object.
	this.getHTML = function(Obj) {

		//p_o(containerID).innerHTML ="loading...";
		var ChannelSet = Obj.ChannelSet;
		var query = Obj.query;

		query = query.replace(/\s?channel:\S*(\s*\S*)*\S*/gi, '');
		query = query.replace(/\s?category:\S*(\s*\S*)*\S*/gi, '');

		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;

				if(i == 0){ document.getElementById( "tv_head_chan_1" ).innerHTML=channelName;   
				channelSpecific1( query+ " channel:"+VSUTIL.escapeHTML(channelName));   }
				if(i == 1){ document.getElementById( "tv_head_chan_2" ).innerHTML=channelName;	 
				channelSpecific2( query+ " channel:"+VSUTIL.escapeHTML(channelName));   }
				if(i == 2){ document.getElementById( "tv_head_chan_3" ).innerHTML=channelName;   
				channelSpecific3( query+ " channel:"+VSUTIL.escapeHTML(channelName));   }
				theHTML += '<div><nobr><a href="'+result_url+query+' channel:%22'+VSUTIL.escapeHTMLString(channelName)+'%22&familyfilter='+ffltr+'"><b>'+VSUTIL.escapeHTML(VSUTIL.truncateString(channelName, charLimit))+' ('+channelCount+')</b></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(Object) {
		if (Object.ChannelSet) {  
			if(  element_o( containerID ) )  { p_o( containerID ).innerHTML = this.getHTML(Object); }
			//document.getElementById(containerID).innerHTML = this.getHTML(ChannelSet,query); 
		}
	}
	
	// Function clear() will display nothing in this menu.
	this.clear = function() {
		if(  element_o( containerID ) )  { p_o( containerID ).innerHTML = ''; }
		//document.getElementById(containerID).innerHTML = '';
	}
}

// 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+ ":"+seconds);
	}
	// 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," ");
		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," ");
		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();

// Function playVideo() adds the video with the specified id to the recent videos list (if logged in) and then
// opens a new browser window to load the specified videoUrl.
function playVideo(videoUrl, id) {
	addRecentVideo(id);
	window.open(videoUrl, '', 'width=800,height=800,location=no,menubar=no,resizable=yes,scrollbars=yes');
}
function addRecentVideo(id) { PRE.addRecentVideo(id); }

// Function sortBy() modifies the query string to include the provided sort option and retrieves a new set of videos.
function sortBy(sortOption, tabno ) {    // NP : tabno is not using anywhere
	p_o('ResultsDiv1').innerHTML = "<div align='center'>Loading...</div>";
	global_var_stat = 1;
	LST_VID.showRelatedItems = 0;
    LST_VID.query= LST_VID.query.replace(/\s?sort:\S*/gi, "") + " sort:" + sortOption;
	searchVideos(LST_VID.query, 0, LST_VID);
	global_var_stat = 0;
}

// Function submitRating() submits the rating integer (1-5) for the video with the specified id value.
function submitRating(videoId, rating) {   

	if( element_o( "tv_ratings_block" ) ) p_o('tv_ratings_block').innerHTML = "saving.. ";
	if( element_o( "tv_notratings_block" ) ) p_o('tv_notratings_block').innerHTML = "saving.. ";
	PRE_REL_VID.submitRating(videoId, rating); 
	if( element_o( "tv_ratings_block" ) ) p_o('tv_ratings_block').innerHTML = "Thanks!";
	if( element_o( "tv_notratings_block" ) ) p_o('tv_notratings_block').innerHTML = "Thanks!";
	if( element_o( "currentrating" ) ) p_o('currentrating').style.width = rating * 10;


}

function goToPage(pageNum) {
	//alert( pageNum );
	LST_VID.goToPage(pageNum)
}

function element_o(o){  
	if( document.getElementById( o )  )	{ return true;
	}else{
		return false;
	}
}


function switchTab(tabnum) {
	
	var outTab = '<ul class="tv_videotabs">';
    switch (tabnum) 
    {
        case 1: outTab += '<li id="tab_1" class="active"><b>' + tabName[0] + '</b></li><li id="tab_2" class=""><a  href="#;" onclick="sortBy(\''+ sortValue[1] +'\', 2);switchTab(2);"><b>' + tabName[1] + '</b></a></li><li id="tab_3" class=""><a href="#;" onclick="sortBy(\''+ sortValue[2] +'\', 3);switchTab(3);"><b>' + tabName[2] + '</b></a></li><li id="tab_4" class=""><a href="#;" onclick="sortBy(\''+ sortValue[3] +'\',4);switchTab(4);"><b>' + tabName[3] + '</b></a></li>';
				//p_o('tabfilterheader').innerHTML ='';
			    if(  element_o( "tabfilterheader" ) )     {  	p_o('tabfilterheader').style.display ='none'; }
                break;

        case 2: outTab += '<li id="tab_1" ><a  href="#;" onclick="sortBy(\''+ sortValue[0] +'\', 1);switchTab(1);"><b>' + tabName[0] + '</b></a></li><li id="tab_2" class="active"><b>' + tabName[1] + '</b></li><li id="tab_3" class=""><a href="#;" onclick="sortBy(\''+ sortValue[2] +'\',3);switchTab(3);"><b>' + tabName[2] + '</b></a></li><li id="tab_4" class=""><a href="#;" onclick="sortBy(\''+ sortValue[3] +'\',4);switchTab(4);"><b>' + tabName[3] + '</b></a></li>';
				if(  element_o( "tabfilterheader" ) )     {	p_o('tabfilterheader').style.display ='block';}
				if(  element_o( "tabfilterheader" ) )     {p_o('tabfilterheader').innerHTML = tabfiltertext;}
                break;

        case 3: outTab += '<li id="tab_1" ><a  href="#;" onclick="sortBy(\''+ sortValue[0] +'\',1);switchTab(1);"><b>' + tabName[0] + '</b></a></li><li id="tab_2" class=""><a  href="#;" onclick="sortBy(\''+ sortValue[1] +'\',2);switchTab(2);"><b>' + tabName[1] + '</b></a></li><li id="tab_3" class="active"><b>' + tabName[2] + '</b></a></li><li id="tab_4" class=""><a href="#;" onclick="sortBy(\''+ sortValue[3] +'\',4);switchTab(4);"><b>' + tabName[3] + '</b></a></li>';
				if(  element_o( "tabfilterheader" ) )     {p_o('tabfilterheader').style.display ='none';}
                break;

        case 4: outTab += '<li id="tab_1" ><a  href="#;" onclick="sortBy(\''+ sortValue[0] +'\',1);switchTab(1);"><b>' + tabName[0] + '</b></a></li><li id="tab_2" class=""><a  href="#;" onclick="sortBy(\''+ sortValue[1] +'\',2);switchTab(2);"><b>' + tabName[1] + '</b></a></li><li id="tab_3" class=""><a href="#;" onclick="sortBy(\''+ sortValue[2] +'\',3);switchTab(3);"><b>' + tabName[2] + '</b></a></li><li id="tab_4" class="active"><b>' + tabName[3] + '</b></li>';
				if(  element_o( "tabfilterheader" ) )     { p_o('tabfilterheader').style.display ='none';}
                break;
    }
    outTab += "</ui>";
    if(  element_o( "tv_tabs_block" ) )  {  p_o('tv_tabs_block').innerHTML = outTab; }
}

function switchSubheader (subnum) {
    var outTab = '';
    switch (subnum) {
        case 1: outTab =  '<b>' + subName[0] + '</b>'  + ' | <a href="#;" onclick="sortBy(\''+ subSortValue[1] +'\');switchSubheader(2);"><b>'+ subName[1] +'</b></a> | <a href="#;" onclick="sortBy(\''+ subSortValue[2] +'\');switchSubheader(3);"><b>'+ subName[2] + '</b></a> | <a href="#;" onclick="sortBy(\''+ subSortValue[3] +'\');switchSubheader(4);"><b>'+ subName[3] +'</b></a>';
				break;

        case 2: outTab = '<a href="#;" onclick="sortBy(\''+ subSortValue[0] +'\');switchSubheader(1);"><b>'+ subName[0] +'</b></a> | <b>'+ subName[1] +'</b> | <a href="#;" onclick="sortBy(\''+ subSortValue[2] +'\');switchSubheader(3);"><b>'+ subName[2] + '</b></a> | <a href="#;" onclick="sortBy(\''+ subSortValue[3] +'\');switchSubheader(4);"><b>'+ subName[3] +'</b></a>';
				break;

        case 3: outTab = '<a href="#;" onclick="sortBy(\''+ subSortValue[0] +'\');switchSubheader(1);"><b>'+ subName[0] +'</b></a> | <a href="#;" onclick="sortBy(\''+ subSortValue[1] +'\');switchSubheader(2);"><b>'+ subName[1] +'</b></a> | <b>'+ subName[2] + '</b> | <a href="#;" onclick="sortBy(\''+ subSortValue[3] +'\');switchSubheader(4);"><b>'+ subName[3] +'</b></a>';
				break;

        case 4: outTab = '<a href="#;" onclick="sortBy(\''+ subSortValue[0] +'\');switchSubheader(1);"><b>'+ subName[0] +'</b></a> | <a href="#;" onclick="sortBy(\''+ subSortValue[1] +'\');switchSubheader(2);"><b>'+ subName[1] +'</b></a> | <a href="#;" onclick="sortBy(\''+ subSortValue[2] +'\');switchSubheader(3);"><b>'+ subName[2] + '</b></a> | <b>'+ subName[3] + '</b>' ;
				break;
    } 
    subHeaderHTML = outTab;
   if(  element_o( "tabfilterheader" ) )     { p_o('tabfilterheader').innerHTML = outTab; }
}



//#### JS #####
function clearDefaultText(obj) {
var target = obj.value
/**
if (target == "") {
  headerQuery = obj.value;
  obj.value = '';
  obj.className="nobg";
}
*/
}

function replaceDefaultText(obj) {
headerQuery = ""
var target = obj.value.trim();
obj.value = (target == "") ?  headerQuery : target;

/**	if (obj.value == "") {
	  obj.className="";
	}*/
}

function escapeHTMLString(string) {
    var newstr = string.replace(/%/g, "%25");
    newstr = newstr.replace(/\//g, "%2F");
	newstr = newstr.replace(/\&/g,'amp;' );

	//newstr = newstr.replace(/\"/g,'%22' );
    return(newstr);		
}

function srchSub(id){
    var frm=document.av_search;
    frm.q.value=frm.q.value;
    if(id==151) {
        if(frm.q.value!="") {
	    var frmValue = frm.q.value;
		var frmFltr  = frm.familyFilter.value;
	    var frmStr = escape(frmValue);  //HTMLString
	     var loc_searchurl = '/video-old/search.jhtml?query='+frmStr+'&familyfilter='+frmFltr;
		//var loc_searchurl = '/video-old/search.jhtml?query='+frmStr;
	    if(frm.q.value!="" && frm.familyFilter.value!=0) {
	        window.location = loc_searchurl;
	    } else {
	        window.location = loc_searchurl+'&familyFilter=0';
	    }
	    return false;
	 }
		return false;
    } else{
        if(frm.q.value!=""){frm.submit();return false;}
    }
    return true;
}
function srchfSub(id){
    var frmfoot=document.av_fsearch;
    frmfoot.q.value=frmfoot.q.value;
    if(id==151) {
        if(frmfoot.q.value!="") {
            var frmfootValue = frmfoot.q.value;
			var frmFltr  = frmfoot.familyFilter.value;
	     var frmfootStr = escapeHTMLString(frmfootValue);
	     var loc_searchurl = "/video-old/search.jhtml?query="+frmfootStr+'&familyfilter='+frmFltr;
		 //var loc_searchurl = "/video-old/search.jhtml?query="+frmfootStr;
	     if(document.av_search.familyFilter.value!=0) {
	         window.location = loc_searchurl;
	     } else {
	         window.location = loc_searchurl+"&familyFilter=0";
	     }
	 }
	 return false;
    } 
}





var ua = navigator.userAgent.toLowerCase();
var _message = "";

	function showePopup(det_id, containerid ) {
	var epopupContent = p_o(containerid);
	var obj = p_o(det_id);
	epopupContent.style.top = obj.offsetTop + "px";
	epopupContent.style.left = obj.offsetLeft  + "px";
	epopupContent.innerHTML = "<a class='close_but' href='javascript:hideePopup(&#39;"+ containerid +"&#39;)'>x</a><p class='det_desc_epopup'>" + obj.innerHTML + "</p>";
	epopupContent.style.display = "block";
}
function hideePopup(containerid) {
	p_o(containerid).style.display = "none";
	p_o(containerid).innerHTML = "";
}
function launchIM(url,text) {
	var is_aol = ua.indexOf('aol') != -1;
	var is_cs2000 = ua.indexOf("cs 2000") != -1;
	var isInClient = (is_aol || is_cs2000);
	if (isInClient) {
	    launchIMFromClient(url,text);
	} else {
		launchIMFromBrowser(url,text);
	}
}

function closeIM() {
    var im_node = p_o("imlayer");
    im_node.style.display = "none";
}

function aimUrlLogic() {
    var ff = ua.indexOf('firefox')!= -1;
    var aolExp = (ua.indexOf('america online browser')!= -1)&& (parseFloat(ua.substring(ua.indexOf('rev')+3))>= 1.2);
    var safari = ua.indexOf('safari')!= -1;

    if(!ff && !aolExp && !safari)
        _message = escape(_message);

    window.location = 'aim:GoIm?message=' + escape(_message);
}

function launchEmail(url,text) {
    if(url && url.length){
        text = (text)? text : document.title;
        var is_netscape = ua.indexOf('netscape') != -1;

        if(is_netscape){
            url = escape (url);
            text = escape (text);
        }
        document.location='mailto:?subject=' + escape (text)+ '&body=' + escape (text + '\n\n' + url);
    }
}
function launchIMFromClient(url,text) {
    url  = (url)  ? url  : top.currUrl;
    text = (text) ? text : document.title;
    shareUrl = 'aol://9293::' + '<a href="' + url + '">' + text + '</a>';
    document.location = shareUrl;
}
function launchIMFromBrowser(url,text) {
	if(url && url.length){
        text = (text)? text : document.title;
        _message = "<a href=\""+url+"\">"+text+"</a>";
	}

    var im_node = p_o("imlayer");
	im_node.style.display = "block";
}

function playVideo(videoUrl) {
	window.open(videoUrl, '', 'width=800,height=800,location=no,menubar=no,resizable=yes,scrollbars=yes');
}


