/****************************************************
*													*
*	 FilitTV 2007-2008, Leeburstroghm 				*
*													*
****************************************************/
/* setup variables */
var clips;
var ppv_vkey;
var ppv_vid;
var ppv_uid;
var globalFeaturedBG='bgcolor="#FFFFE1"';
var globalFeaturedTXT='<em>Featured TV Program</em><br>';

var beaconIMG = '<img width="0" height="0" style="width: 0px; height: 0px;" alt="" src="';

/* set up objects */


/* Variables used for guide effects */
fadeLength = .5;
guideState = 0;		// guide open 1 or closed 0
guideTtop = -202;	// Top Target when opening ABSOLUTE
guideT = 120;		// Target when closed ABSOLUTE
guidePos = guideT;	// Current position STARTS Closed
guideWorking = 0; 		// to stop click happy people

/* variable for menu items and guideResult*/
searchState = 1;	// basic search 1, or Advanced search 0
guideResultState = "splash"; // Keep track of guide result area display. this is the first that is up

/* variable for guide Select functions */

// basic search
// assoc array as ('country','channel','topics',)
// Index 0 stores the currently selected entry <div ID> - 0item is set to default 
// Index 1 is the data.
// to set background colors and send id for searching
guideselectList = new Array(); 	
guideselectList['country'] = new Array(2);
guideselectList['country'][0] = '0country';

guideselectList['channel'] = new Array(2);
guideselectList['channel'][0] = '0channel';

guideselectList['topic'] = new Array(2);
guideselectList['topic'][0] = '0topic';			



// advanced search, Multiple Selections!!
guideselectListAdv = new Object();
guideselectListAdv['adv_country'] = new Array();
guideselectListAdv['adv_channel'] = new Array();


// setup CPAINT AJAX object for us
// this is done in the myjavascriptfx.js as cp

/**************************************************
*
* Functions
*
***************************************************/

// get the ppvkeycode for this program viewkey
function playppv(frm){
	// set feedback and say Processing...
	document.getElementById('ppvmsg').innerHTML="Processing...";
	// make ajax call to get this show ppv keycode
	thisKey = frm.keycode.value;
	cp.call('ajax/filitvajax.php', 'get_ppvkey', startppv, ppv_vkey, thisKey);
	return false;
}

function startppv(rs){
	//alert(frm.keycode.value+' - '+ppv_vkey);
	try{	
		er=rs.getElementsByTagName('error');
		if(er[0].childNodes[0].nodeValue != 'none'){
			alert('Error: '+er[0].childNodes[0].nodeValue);
		}else{
			thistag=rs.getElementsByTagName('isvalid');
			if(thistag[0].childNodes[0].nodeValue == 'true'){
				document.getElementById('ppv_popup').style.display = "none";
				// make ajax call to update this video viewed number
				cp.call('ajax/filitvajax.php', 'set_vdoviewed', vdoviewed_set, ppv_vid, ppv_uid);
				
				// make ajax call to recieve info about this video to populate current show
				cp.call('ajax/filitvajax.php', 'get_vdoinfo', set_currentvdo_info, ppv_vid);
				
				// make ajax call to get the commercials for this show
				cp.call('ajax/filitvajax.php', 'get_playlist', makePlayList, ppv_vkey);
				document.getElementById('ppvmsg').innerHTML="&nbsp;";
			}else{
				document.getElementById('ppvmsg').innerHTML="Invalid or Expired PPV Key Code!";
			}
		}
	}catch(Err){		
		alert('Server Problem StartPPV '+Err);
	}
}

// create the very first playlist commercials
function createFirstPlaylist(){
	// make ajax call to get the commercials
	cp.call('ajax/filitvajax.php', 'get_playlist', makePlayList, 1);
}

// function to take a viewKey and make a new playlist
// this includes a commercial at begining and end.
// and send to the player to play. Also update the times viewed/bandwidth
function playThisShow(vtype, vkey, vid, uid){
	if(vtype != "ppv"){
	// make ajax call to update this video viewed number
	cp.call('ajax/filitvajax.php', 'set_vdoviewed', vdoviewed_set, vid, uid);
	
	// make ajax call to recieve info about this video to populate current show
	cp.call('ajax/filitvajax.php', 'get_vdoinfo', set_currentvdo_info, vid);
	
	// make ajax call to get the commercials playlist for this show
	cp.call('ajax/filitvajax.php', 'get_playlist', makePlayList, vkey);
	}else{
		ppv_vkey = vkey;
		ppv_vid = vid;
		ppv_uid = uid;
		popup_show('ppv_popup', 'ppv_popup_drag', 'ppv_popup_exit', 'screen-center', 0, 0);
	}
}

function makePlayList(rs){
	try{	
		er=rs.getElementsByTagName('error');
		if(er[0].childNodes[0].nodeValue != 'none'){
			alert('Error: '+er[0].childNodes[0].nodeValue);
		}else{
			var x=rs.getElementsByTagName('row');	
			var r_data = new Object(); // store the values
			
			for(d=0;d<x[0].childNodes.length; d++){		
			//alert(x[i].childNodes[d].hasChildNodes());
				var thisKey = x[0].childNodes[d].nodeName;
				if ( x[0].childNodes[d].hasChildNodes() ) {							
				
					r_data[ thisKey ] = x[0].childNodes[d].childNodes[0].nodeValue;
				}else{							
					r_data[ thisKey ] = ' ';							
				}
			}
			
			if(r_data['flvideo'] != 'advt'){
				
				if(r_data['flvideo']=='url'){
					var thisVideo = URLDecode(r_data['url']);
					document.getElementById('videodisclaimer').innerHTML="This TV Program is streaming from the TV Station's server, not FiliTV. FiliTV can not guarantee the speed of this server.";
				}else{
					document.getElementById('videodisclaimer').innerHTML="&nbsp;";
					var thisVideo = r_data['vtype']+"/"+r_data['flvideo'];
				}
				if(r_data['ad1'] =='url'){
					var ad1video=r_data['ad1url'];
				}else{
					var ad1video='advt/'+r_data['ad1'];
				}
				
				if(r_data['ad2'] =='url'){
					var ad2video=r_data['ad2url'];
				}else{
					var ad2video='advt/'+r_data['ad2'];
				}
				
				var link1 = r_data['ad1link'];
				document.getElementById('beacon1').innerHTML=beaconIMG+URLDecode(r_data['ad1lg'])+'"/>';
				
				var link2 = r_data['ad2link'];
				document.getElementById('beacon2').innerHTML=beaconIMG+URLDecode(r_data['ad2lg'])+'"/>';
				fpConf.playList = [
				{ name: 'ad1', url: ad1video, linkUrl: link1, linkWindow: '_blank', controlEnabled: true, showOnLoadBegin: true, duration: r_data['ad1_duration'] },
					{ name: 'program', url: thisVideo},
				{ name: 'ad2', url: ad2video, linkUrl:link2, linkWindow: '_blank', controlEnabled: true, showOnLoadBegin: true, duration: r_data['ad2_duration'] }
				];
			}else{
				// this is the home page commercials or Search Result Commercials.
				if(r_data['ad1'] =='url'){
					var ad1video=r_data['ad1url'];
				}else{
					var ad1video='advt/'+r_data['ad1'];
				}
				
				if(r_data['ad2'] =='url'){
					var ad2video=r_data['ad2url'];
				}else{
					var ad2video='advt/'+r_data['ad2'];
				}
				
				if(r_data['ad3'] =='url'){
					var ad3video=r_data['ad3url'];
				}else{
					var ad3video='advt/'+r_data['ad3'];
				}
				
				var link1 = r_data['ad1link'];
				document.getElementById('beacon1').innerHTML=beaconIMG+URLDecode(r_data['ad1lg'])+'"/>';
				
				var link2 = r_data['ad2link'];
				document.getElementById('beacon2').innerHTML=beaconIMG+URLDecode(r_data['ad2lg'])+'"/>';
				var link3 = r_data['ad3link'];
				document.getElementById('beacon3').innerHTML=beaconIMG+URLDecode(r_data['ad3lg'])+'"/>';
				
				fpConf.playList = [
				{ name: 'ad1', url: ad1video, linkUrl: link1, linkWindow: '_blank', controlEnabled: true, showOnLoadBegin: true, duration: r_data['ad1_duration'] },
				{ name: 'ad2', url: ad2video, linkUrl:link2, linkWindow: '_blank', controlEnabled: true, showOnLoadBegin: true, duration: r_data['ad2_duration'] },
				{ name: 'ad3', url: ad3video, linkUrl:link3, linkWindow: '_blank', controlEnabled: true, showOnLoadBegin: true, duration: r_data['ad3_duration'] }
			];
			}
			
			setFlowPlayerConfig();
		}
	
	}catch(Err){		
		alert('Server Problem makePlaylist '+Err);
	}
}



/****************************************************
*
*		AJAX Functions		
*
****************************************************/

/////////////////////////////////////////////
// AJAX calls to php file

// get spotlight station results
function get_spStation(sid, srt, page){

	document.getElementById('guideSearchResult').innerHTML='Processing...';
	tglGuideResult('searchResult');
	cp.call('ajax/filitvajax.php', 'get_spStationResult', set_spstationsearchresult, sid, srt, page);	
}

// Spotlight get results
function get_spsearchresult(srt, page){
	cp.call('ajax/filitvajax.php', 'get_spSearchResult', set_spsearchresult);	
}

// flag this video as innapropriate
function vdo_inappro(viewkey){
	cp.call('ajax/filitvajax.php', 'flag_inappro', vdo_flagged, viewkey);	
}
// Advnaced Search Result
function get_asearchresult(country, channel, tags, srt, page){

//	alert(advcountries+' '+advchannels+' '+tags);
	cp.call('ajax/filitvajax.php', 'get_advSearchResult', set_asearchresult, country, channel, tags, srt, page);	
}
// Highes Rated get results
function get_hrsearchresult(srt, page){
	cp.call('ajax/filitvajax.php', 'get_hrSearchResult', set_hrsearchresult, srt, page);	
}

// Most Watched get results
function get_mwsearchresult(srt, page){
	cp.call('ajax/filitvajax.php', 'get_mwSearchResult', set_mwsearchresult, srt, page);	
}

// basic search get results
function get_bsearchresult(country, chid, tag, srt, page){
	//Sometimes the server takes a long time. so we want feedback..
	//var rdiv=document.getElementById('guideSearchResult');
	//rdiv.innerHTML='<div align="center"><br><br>Processing...</div>';
	cp.call('ajax/filitvajax.php', 'get_basicSearchResult', set_bsearchresult, country, chid, tag, srt, page);	
}

// basic search get tags
function get_bsearchtags(country, chid){
	//alert("country "+country+" channel "+chid);
	cp.call('ajax/filitvajax.php', 'get_basicSearchTags', set_bsearchtags, country, chid);	
}

// function to send comments about this video
function send_vdo_comment(network, vdotitle){
	// do for field check
	if(document.getElementById('msg_details').value == ""){
		var error="Please provide a comment!";
	}else{
		var message = document.getElementById('msg_details').value;
	}	
	if(error){
		alert(error);
	}else{
		//alert(network+' '+vdotitle+' '+ document.getElementById('msg_details').value);
		// make ajax call to send message/comment about current show
		cp.call('ajax/filitvajax.php', 'send_message', message_sent, network, vdotitle, message);
	}	
}

///////////////////////////////////////////
// AJAX Call Back Functions

// use the returned information and build the In the Spotlight list
function set_spsearchresult(rs){
	try{	
		er=rs.getElementsByTagName('error');
		if(er[0].childNodes[0].nodeValue != 'none'){
			alert('Error: '+er[0].childNodes[0].nodeValue);
		}else{
			var spdiv=document.getElementById('guideSPResult');
			var thisValue;
			
			var x=rs.getElementsByTagName('row');						// rows returned from query
			
			var r_data = new Object(); // store this rows data
			
			// top part of results layout
			var myhtml = '<table width="96%" class="guideSearchResult" border="0" cellspacing="2" cellpadding="2"><tr><td class="moduleEntryDetails">Click on a TV Station Title to view its available TV programs .</td></tr>';
			
			for (i=0;i<x.length;i++)
				{
					// setup vars to be used for this entry
					for(d=0;d<x[i].childNodes.length; d++){		
					//alert(x[i].childNodes[d].hasChildNodes());
						var thisKey = x[i].childNodes[d].nodeName;
						if ( x[i].childNodes[d].hasChildNodes() ) {							
						
					 		r_data[ thisKey ] = x[i].childNodes[d].childNodes[0].nodeValue;
						}else{							
							r_data[ thisKey ] = ' ';							
						}
				   	}
					var description = URLDecode( r_data['description']);

					// begin body layout
					myhtml+='<tr>  <td valign="top" class=guideSearchResult><a href="javascript:;" class="guideSearchResultTitle" onclick="get_spStation(\''+r_data["sid"]+'\', \'title\', 1);">'+r_data["st_name"]+'</a>  '+r_data["st_city"]+' '+r_data["st_state"]+' | '+broadcast+' '+by+' '+network+' <A href="'+baseurl+'uprofile.php?UID='+r_data["uid"]+'" target=_blank>'+r_data["username"]+'</A><br>'+description+'</td></tr>';
				
				}
				// footer layout
				myhtml +='</table>';
				spdiv.innerHTML=myhtml;
				
		}

	}catch(Err){		
		alert('Server Problem SP '+Err);
	}
}

// use the returned information and build the SpotLight Station video list
function set_spstationsearchresult(rs){
	try{	
		er=rs.getElementsByTagName('error');
		if(er[0].childNodes[0].nodeValue!='0'){ 
			if(er[0].childNodes[0].nodeValue != 'none'){
				alert('Error: '+er[0].childNodes[0].nodeValue);
			}else{
						
				var rdiv=document.getElementById('guideSearchResult');
				var thisValue;
				
				var x=rs.getElementsByTagName('row');						// rows returned from query
				
				var jsc=rs.getElementsByTagName('jscode');				// get the jscode to use for sorting. it is -> get_bsearchresult('$country', '$chid', '$tag'
				var jscode = URLDecode( jsc[0].childNodes[0].nodeValue );
				
				var p=rs.getElementsByTagName('pagination');				// get the paging html
				var pagination = URLDecode( p[0].childNodes[0].nodeValue );var p=rs.getElementsByTagName('pagination');				// get the paging html
				var pagination = URLDecode( p[0].childNodes[0].nodeValue );
				
				var t=rs.getElementsByTagName('total');						// get the total results
				var total = URLDecode( t[0].childNodes[0].nodeValue );
				
				var r_data = new Object(); // store this rows data
				
				// top part of results layout
				var myhtml = '<table width="96%" class="guideSearchResult" border="0" cellspacing="2" cellpadding="2"><tr><td class="moduleEntryDetails"><div align="center"><strong>'+total+'</strong> matching TV Programs. Sort By: <a href="javascript:;" onclick="'+jscode+', \'title\', 1)">Title</a> | <a href="javascript:;" onclick="'+jscode+', \'ntwk\', 1)">Network</a> | <a href="javascript:;" onclick="'+jscode+', \'st\', 1)">Station</a> | <a href="javascript:;" onclick="'+jscode+', \'mr\', 1)">Date Added</a> | <a href="javascript:;" onclick="'+jscode+', \'mv\', 1)">Most Watched</a> | <a href="javascript:;" onclick="'+jscode+', \'tr\', 1)">Top Rated</a><br /><br />'+pagination+'</div>Click on a program Title to start watching.</td></tr>';
				
				for (i=0;i<x.length;i++)
					{
						// setup vars to be used for this entry
						for(d=0;d<x[i].childNodes.length; d++){		
						//alert(x[i].childNodes[d].hasChildNodes());
							var thisKey = x[i].childNodes[d].nodeName;
							if ( x[i].childNodes[d].hasChildNodes() ) {							
							
								r_data[ thisKey ] = x[i].childNodes[d].childNodes[0].nodeValue;
							}else{							
								r_data[ thisKey ] = ' ';							
							}
						} 
						var rated = URLDecode( r_data['rating'] );
						var description = URLDecode( r_data['description']);
						// create video type readout
						if(r_data["type"] == "ppv"){
							var vtype = 'Pay Per View <em>( $'+r_data['ppv_amount']+' )</em>';
						}else{
							var vtype = '';
						}
						
						// begin body layout
						myhtml+='<tr>  <td valign="top" class=guideSearchResult><a href="javascript:;" class="guideSearchResultTitle" onclick="playThisShow(\''+r_data["type"]+'\', \''+r_data["vkey"]+'\', \''+r_data["vid"]+'\', \''+r_data["uid"]+'\');">'+r_data["title"]+'</a> '+rated+' <strong>'+vtype+'</strong> Added: '+r_data["addtime"]+'<br />'+runtime+': '+r_data["duration"]+' '+minutes+'. '+viewed+' '+r_data["viewnumber"]+' '+times+'<br> '+broadcast+' '+by+' '+network+' <A href="'+baseurl+'uprofile.php?UID='+r_data["uid"]+'" target=_blank>'+r_data["username"]+'</A> '+station+' <A href="javascript:;">'+r_data["st_name"]+'</a> '+r_data["st_city"]+' '+r_data["st_state"]+' <br /><strong>'+tags+':</strong> <em>'+r_data["keywords"]+'</em><br>'+description+'</td></tr>';
					
					}
					// footer layout
					myhtml +='<tr><td align="center" class="moduleEntryDetails">'+pagination+'</td></tr></table>';
					rdiv.innerHTML=myhtml;
					
			}
		}else{
			var rdiv=document.getElementById('guideSearchResult');
			rdiv.innerHTML='<div align="center"><br><br><strong>There are no TV Programs available at this time that match this criteria.<br><em>Please Try Again.</em></strong>';
		} // end if error
	
	}catch(Err){		
		alert('Server Problem '+Err);
	}
}

// use the returned information and build the Highest Rated Video list
function set_hrsearchresult(rs){
	try{	
		er=rs.getElementsByTagName('error');
		if(er[0].childNodes[0].nodeValue != 'none'){
			alert('Error: '+er[0].childNodes[0].nodeValue);
		}else{
			var hrdiv=document.getElementById('guideHRResult');
			var thisValue;
			
			var x=rs.getElementsByTagName('row');						// rows returned from query
			
			var jsc=rs.getElementsByTagName('jscode');				// get the jscode to use for sorting. it is -> get_bsearchresult('$country', '$chid', '$tag'
			var jscode = URLDecode( jsc[0].childNodes[0].nodeValue );
			
			var p=rs.getElementsByTagName('pagination');				// get the paging html
			var pagination = URLDecode( p[0].childNodes[0].nodeValue );
			
			var t=rs.getElementsByTagName('total');						// get the total results
			var total = URLDecode( t[0].childNodes[0].nodeValue );
			
			var r_data = new Object(); // store this rows data
			
			// top part of results layout
			var myhtml = '<table width="96%" class="guideSearchResult" border="0" cellspacing="2" cellpadding="2"><tr><td class="moduleEntryDetails"><div align="center"><strong>'+total+'</strong> matching TV Programs. Sort By: <a href="javascript:;" onclick="'+jscode+'\'title\', 1)">Title</a> | <a href="javascript:;" onclick="'+jscode+'\'ntwk\', 1)">Network</a> | <a href="javascript:;" onclick="'+jscode+'\'st\', 1)">Station</a> | <a href="javascript:;" onclick="'+jscode+'\'mr\', 1)">Date Added</a> | <a href="javascript:;" onclick="'+jscode+'\'mv\', 1)">Most Watched</a> | <a href="javascript:;" onclick="'+jscode+'\'tr\', 1)">Top Rated</a><br /><br />'+pagination+'</div>Click on a program Title to start watching.</td></tr>';
			
			for (i=0;i<x.length;i++)
				{
					// setup vars to be used for this entry
					for(d=0;d<x[i].childNodes.length; d++){		
					//alert(x[i].childNodes[d].hasChildNodes());
						var thisKey = x[i].childNodes[d].nodeName;
						if ( x[i].childNodes[d].hasChildNodes() ) {							
						
					 		r_data[ thisKey ] = x[i].childNodes[d].childNodes[0].nodeValue;
						}else{							
							r_data[ thisKey ] = ' ';							
						}
				   	} 
					var rated = URLDecode( r_data['rating'] );
					var description = URLDecode( r_data['description']);
					
					// create video type readout
					if(r_data["type"] == "ppv"){
						var vtype = 'Pay Per View <em>( $'+r_data['ppv_amount']+' )</em>';
					}else{
						var vtype = '';
					}
					if(r_data["featured_expire"] == 1){
						var bgcolor=globalFeaturedBG;
						var isFeatured = globalFeaturedTXT;
					}else{
						var bgcolor='';
						var isFeatured ='';
					}
					// begin body layout
					myhtml+='<tr><td valign="top" '+bgcolor+' class="guideSearchResult">'+isFeatured+'<a href="javascript:;" class="guideSearchResultTitle" onclick="playThisShow(\''+r_data["type"]+'\', \''+r_data["vkey"]+'\', \''+r_data["vid"]+'\', \''+r_data["uid"]+'\');">'+r_data["title"]+'</a> '+rated+' <strong>'+vtype+'</strong>  Added: '+r_data["addtime"]+'<br />'+runtime+': '+r_data["duration"]+' '+minutes+'. '+viewed+' '+r_data["viewnumber"]+' '+times+'<br />'+broadcast+' '+by+' '+network+' <a href="'+baseurl+'uprofile.php?UID='+r_data["uid"]+'" target=_blank>'+r_data["username"]+'</a> '+station+' <strong>'+r_data["st_name"]+'</strong> '+r_data["st_city"]+' '+r_data["st_state"]+' <br /><strong>'+tags+':</strong> <em>'+r_data["keywords"]+'</em><br />'+description+'</td></tr>';
				
				}
				// footer layout
				myhtml +='<tr><td align="center" class="moduleEntryDetails">'+pagination+'</td></tr></table>';
				hrdiv.innerHTML=myhtml;
				
		}

	}catch(Err){		
		alert('Server Problem HR '+Err);
	}
}

// use the returned information and build the Most Watched video list
function set_mwsearchresult(rs){
	try{	
		er=rs.getElementsByTagName('error');
		if(er[0].childNodes[0].nodeValue != 'none'){
			alert('Error: '+er[0].childNodes[0].nodeValue);
		}else{
			var mwdiv=document.getElementById('guideMWResult');
			var thisValue;
			
			var x=rs.getElementsByTagName('row');						// rows returned from query
			
			var jsc=rs.getElementsByTagName('jscode');				// get the jscode to use for sorting. it is -> get_bsearchresult('$country', '$chid', '$tag'
			var jscode = URLDecode( jsc[0].childNodes[0].nodeValue );
			
			var p=rs.getElementsByTagName('pagination');				// get the paging html
			var pagination = URLDecode( p[0].childNodes[0].nodeValue );
			
			var t=rs.getElementsByTagName('total');						// get the total results
			var total = URLDecode( t[0].childNodes[0].nodeValue );

			var r_data = new Object(); // store this rows data
			
			// top part of results layout
			var myhtml = '<table width="96%" class="guideSearchResult" border="0" cellspacing="2" cellpadding="2">      <tr> <td class="moduleEntryDetails"><div align="center">Sort By: <a href="javascript:;" onclick="'+jscode+'\'title\', 1)">Title</a> | <a href="javascript:;" onclick="'+jscode+'\'ntwk\', 1)">Network</a> | <a href="javascript:;" onclick="'+jscode+'\'st\', 1)">Station</a> | <a href="javascript:;" onclick="'+jscode+'\'mr\', 1)">Date Added</a> | <a href="javascript:;" onclick="'+jscode+'\'mv\', 1)">Most Watched</a> | <a href="javascript:;" onclick="'+jscode+'\'tr\', 1)">Top Rated</a><br /><br /> '+pagination+'</div> Click on a program Title to start watching.</td></tr>';
			
			for (i=0;i<x.length;i++)
				{
					// setup vars to be used for this entry
					for(d=0;d<x[i].childNodes.length; d++){		
					//alert(x[i].childNodes[d].hasChildNodes());
						var thisKey = x[i].childNodes[d].nodeName;
						if ( x[i].childNodes[d].hasChildNodes() ) {							
						
					 		r_data[ thisKey ] = x[i].childNodes[d].childNodes[0].nodeValue;
						}else{							
							r_data[ thisKey ] = ' ';							
						}
				   	} 
					var rated = URLDecode( r_data['rating'] );
					var description = URLDecode( r_data['description']);
					
					// create video type readout
					if(r_data["type"] == "ppv"){
						var vtype = 'Pay Per View <em>( $'+r_data['ppv_amount']+' )</em>';
					}else{
						var vtype = '';
					}
					
					if(r_data["featured_expire"] == 1){
						var bgcolor=globalFeaturedBG;
						var isFeatured = globalFeaturedTXT;
					}else{
						var bgcolor='';
						var isFeatured ='';
					}
					
					// begin body layout
					myhtml+='<tr><td valign="top" '+bgcolor+' class="guideSearchResult">'+isFeatured+'<a href="javascript:;" class="guideSearchResultTitle" onclick="playThisShow(\''+r_data["type"]+'\', \''+r_data["vkey"]+'\', \''+r_data["vid"]+'\', \''+r_data["uid"]+'\');">'+r_data["title"]+'</a> '+rated+' <strong>'+vtype+'</strong>  Added: '+r_data["addtime"]+'<br />'+runtime+': '+r_data["duration"]+' '+minutes+'. '+viewed+' '+r_data["viewnumber"]+' '+times+'<br />'+broadcast+' '+by+' '+network+' <a href="'+baseurl+'uprofile.php?UID='+r_data["uid"]+'" target=_blank>'+r_data["username"]+'</a> '+station+' <strong>'+r_data["st_name"]+'</strong> '+r_data["st_city"]+' '+r_data["st_state"]+' <br /><strong>'+tags+':</strong> <em>'+r_data["keywords"]+'</em><br />'+description+'</td></tr>';
				
				}
				// footer layout
				myhtml +='<tr><td align="center" class="moduleEntryDetails">'+pagination+'</td></tr></table>';
				mwdiv.innerHTML=myhtml;
				
		}

	}catch(Err){		
		alert('Server Problem MW '+Err);
	}
}

// use the returned information and build the Advanced search video list
function set_asearchresult(rs){
	try{	
		er=rs.getElementsByTagName('error');
		// if error = 0, no records were returned, otherwise there is data or error
		if(er[0].childNodes[0].nodeValue!='0'){ 
			if(er[0].childNodes[0].nodeValue != 'none'){
				alert('Error: '+er[0].childNodes[0].nodeValue);
			}else{
				var rdiv=document.getElementById('guideSearchResult');
				var thisValue;
				
				var x=rs.getElementsByTagName('row');						// rows returned from query
				
				var jsc=rs.getElementsByTagName('jscode');				// get the jscode to use for sorting. it is -> get_bsearchresult('$country', '$chid', '$tag'
				var jscode = URLDecode( jsc[0].childNodes[0].nodeValue );
				
				var p=rs.getElementsByTagName('pagination');				// get the paging html
				var pagination = URLDecode( p[0].childNodes[0].nodeValue );
				
				var a=rs.getElementsByTagName('ad');					// get the ad
				var ad = URLDecode( a[0].childNodes[0].nodeValue );
				
				var t=rs.getElementsByTagName('total');						// get the total results
				var total = URLDecode( t[0].childNodes[0].nodeValue );
				
				var r_data = new Object(); // store this rows data
				
				// top part of results layout
				var myhtml = '<table width="96%" class="guideSearchResult" border="0" cellspacing="2" cellpadding="2"><tr><td class="moduleEntryDetails"><div align="center">'+ad+'<br><br><strong>'+total+'</strong> matching TV Programs. Sort By: <a href="javascript:;" onclick="'+jscode+', \'title\', 1)">Title</a> | <a href="javascript:;" onclick="'+jscode+', \'ntwk\', 1)">Network</a> | <a href="javascript:;" onclick="'+jscode+', \'st\', 1)">Station</a> | <a href="javascript:;" onclick="'+jscode+', \'mr\', 1)">Date Added</a> | <a href="javascript:;" onclick="'+jscode+', \'mv\', 1)">Most Watched</a> | <a href="javascript:;" onclick="'+jscode+', \'tr\', 1)">Top Rated</a><br /><br />'+pagination+'</div>Click on a program Title to start watching.</td></tr>';
				
				for (i=0;i<x.length;i++)
					{
						// setup vars to be used for this entry
						for(d=0;d<x[i].childNodes.length; d++){		
						//alert(x[i].childNodes[d].hasChildNodes());
							var thisKey = x[i].childNodes[d].nodeName;
							if ( x[i].childNodes[d].hasChildNodes() ) {							
							
								r_data[ thisKey ] = x[i].childNodes[d].childNodes[0].nodeValue;
							}else{							
								r_data[ thisKey ] = ' ';							
							}
						} 
						var rated = URLDecode( r_data['rating'] );
						var description = URLDecode( r_data['description']);
						// for ppv
						if(r_data["type"] == "ppv"){
							var vtype = 'Pay Per View <em>( $'+r_data['ppv_amount']+' )</em>';
						}else{
							var vtype = '';
						}	
						if(r_data["featured_expire"] == 1){
							var bgcolor=globalFeaturedBG;
							var isFeatured = globalFeaturedTXT;
						}else{
							var bgcolor='';
							var isFeatured ='';
						}
						// begin body layout
						myhtml+='<tr>  <td valign="top" '+bgcolor+' class=guideSearchResult>'+isFeatured+r_data["score"]+' <a href="javascript:;" class="guideSearchResultTitle" onclick="playThisShow(\''+r_data["type"]+'\', \''+r_data["vkey"]+'\', \''+r_data["vid"]+'\', \''+r_data["uid"]+'\');">'+r_data["title"]+'</a> '+rated+' <strong>'+vtype+'</strong> Added: '+r_data["addtime"]+'<br />'+runtime+': '+r_data["duration"]+' '+minutes+'. '+viewed+' '+r_data["viewnumber"]+' '+times+'<br> '+broadcast+' '+by+' '+network+' <A href="'+baseurl+'uprofile.php?UID='+r_data["uid"]+'" target=_blank>'+r_data["username"]+'</A> '+station+' <A href="javascript:;">'+r_data["st_name"]+'</a> '+r_data["st_city"]+' '+r_data["st_state"]+' <br /><strong>'+tags+':</strong> <em>'+r_data["keywords"]+'</em><br>'+description+'</td></tr>';
					
					}
					// footer layout
					myhtml +='<tr><td align="center" class="moduleEntryDetails">'+pagination+'</td></tr></table>';
					rdiv.innerHTML=myhtml;
					
			}// end results
		}else{
			var rdiv=document.getElementById('guideSearchResult');
			rdiv.innerHTML='<div align="center"><br><br><strong>There are no TV Programs available at this time that match this criteria.<br><em>Please Try Again.</em></strong>';
		} // end if error

	}catch(Err){		
		alert('Server Problem '+Err);
	}
}

// use the returned information and build the Basic search video list
function set_bsearchresult(rs){
	try{	
		er=rs.getElementsByTagName('error');
		if(er[0].childNodes[0].nodeValue!='0'){ 
			if(er[0].childNodes[0].nodeValue != 'none'){
				alert('Error: '+er[0].childNodes[0].nodeValue);
			}else{
				var rdiv=document.getElementById('guideSearchResult');
				var thisValue;
				
				var x=rs.getElementsByTagName('row');						// rows returned from query
				
				var jsc=rs.getElementsByTagName('jscode');				// get the jscode to use for sorting. it is -> get_bsearchresult('$country', '$chid', '$tag'
				var jscode = URLDecode( jsc[0].childNodes[0].nodeValue );
				
				var p=rs.getElementsByTagName('pagination');				// get the paging html
				var pagination = URLDecode( p[0].childNodes[0].nodeValue );
				
				var t=rs.getElementsByTagName('total');						// get the total results
				var total = URLDecode( t[0].childNodes[0].nodeValue );
				
				var a=rs.getElementsByTagName('ad');				// get the ad
				var ad = URLDecode( a[0].childNodes[0].nodeValue );

				var r_data = new Object(); // store this rows data
				
				// top part of results layout
				var myhtml = '<table width="96%" class="guideSearchResult" border="0" cellspacing="2" cellpadding="2"><tr><td class="moduleEntryDetails"><div align="center">'+ad+'<br><br><strong>'+total+'</strong> matching TV Programs. Sort By: <a href="javascript:;" onclick="'+jscode+', \'title\', 1)">Title</a> | <a href="javascript:;" onclick="'+jscode+', \'ntwk\', 1)">Network</a> | <a href="javascript:;" onclick="'+jscode+', \'st\', 1)">Station</a> | <a href="javascript:;" onclick="'+jscode+', \'mr\', 1)">Date Added</a> | <a href="javascript:;" onclick="'+jscode+', \'mv\', 1)">Most Watched</a> | <a href="javascript:;" onclick="'+jscode+', \'tr\', 1)">Top Rated</a><br /><br />'+pagination+'</div>Click on a program Title to start watching.</td></tr>';
				
				for (i=0;i<x.length;i++)
					{
						// setup vars to be used for this entry
						for(d=0;d<x[i].childNodes.length; d++){		
						//alert(x[i].childNodes[d].hasChildNodes());
							var thisKey = x[i].childNodes[d].nodeName;
							if ( x[i].childNodes[d].hasChildNodes() ) {							
							
								r_data[ thisKey ] = x[i].childNodes[d].childNodes[0].nodeValue;
							}else{							
								r_data[ thisKey ] = ' ';							
							}
						} 
						var rated = URLDecode( r_data['rating'] );
						var description = URLDecode( r_data['description']);
						// create video type readout
						if(r_data["type"] == "ppv"){
							var vtype = 'Pay Per View <em>( $'+r_data['ppv_amount']+' )</em>';
						}else{
							var vtype = '';
						}
						
						if(r_data["featured_expire"] == 1){
							var bgcolor=globalFeaturedBG;
							var isFeatured = globalFeaturedTXT;
						}else{
							var bgcolor='';
							var isFeatured ='';
						}						
						
						// begin body layout
						myhtml+='<tr>  <td valign="top" '+bgcolor+' class=guideSearchResult>'+isFeatured+'<a href="javascript:;" class="guideSearchResultTitle" onclick="playThisShow(\''+r_data["type"]+'\', \''+r_data["vkey"]+'\', \''+r_data["vid"]+'\', \''+r_data["uid"]+'\');">'+r_data["title"]+'</a> '+rated+' <strong>'+vtype+'</strong> Added: '+r_data["addtime"]+'<br />'+runtime+': '+r_data["duration"]+' '+minutes+'. '+viewed+' '+r_data["viewnumber"]+' '+times+'<br> '+broadcast+' '+by+' '+network+' <A href="'+baseurl+'uprofile.php?UID='+r_data["uid"]+'" target=_blank>'+r_data["username"]+'</A> '+station+' <A href="javascript:;">'+r_data["st_name"]+'</a> '+r_data["st_city"]+' '+r_data["st_state"]+' <br /><strong>'+tags+':</strong> <em>'+r_data["keywords"]+'</em><br>'+description+'</td></tr>';
					
					}
					// footer layout
					myhtml +='<tr><td align="center" class="moduleEntryDetails">'+pagination+'</td></tr></table>';
					rdiv.innerHTML=myhtml;
					
			}// end results
		}else{
			var rdiv=document.getElementById('guideSearchResult');
			rdiv.innerHTML='<div align="center"><br><br><strong>There are no TV Programs available at this time that match this criteria.<br><em>Please Try Again.</em></strong>';
		} // end if error, no records returned
		

	}catch(Err){		
		alert('Server Problem '+Err);
	}
}

// function to update the current show info
function set_currentvdo_info(rs){
	try{	
		if(er[0].childNodes[0].nodeValue != 'none'){
			alert(er[0].childNodes[0].nodeValue);
		}else{
			// only one record so set i to 0
			i=0;
			var rdiv=document.getElementById('currentResult');
			var thisValue;
			
			var r_data = new Object(); 		// store this rows data
			
			var x=rs.getElementsByTagName('row');
			
			// setup vars to be used for this entry
			for(d=0;d<x[i].childNodes.length; d++){		
			//alert(x[i].childNodes[d].hasChildNodes());
				var thisKey = x[i].childNodes[d].nodeName;
				if ( x[i].childNodes[d].hasChildNodes() ) {			
					r_data[ thisKey ] = x[i].childNodes[d].childNodes[0].nodeValue;
				}else{							
					r_data[ thisKey ] = ' ';							
				}
			} 

			
			
			// set up image if there is one.
			if(r_data["islogo"]=='true'){
				var thisLogo='<img src="'+ntwk_img_url+'/'+r_data['uid']+'.jpg" border="0"/>';
			}else{
				var thisLogo ='';
			}
			
			//setup location info if there is any
			if(r_data["v_location"]){
				var onlocation ='<br />On Location at: '+r_data['v_location'];
				
				// If there is location information, show the country
				if(r_data["v_country"]){
					onlocation +=', '+r_data['v_country'];	
				}
			}else{
				var onlocation = '';
			}
			
			
			var rated = URLDecode( r_data["rating"] );
			var description = URLDecode( r_data["v_description"] );
			var st_description = URLDecode( r_data["st_description"] );
			
			var myhtml ='<table width="98%" border="0" cellpadding="3" cellspacing="3" class="guideSearchResult">  <tr>    <td width="200" align="left" valign="top" class=guideSearchResult>'+broadcast+' '+by+' '+network+':        <table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#43745C"><tr>  <td><table width="100%" border="0" cellpadding="1" cellspacing="0">    <tr>      <td><table width="100%" border="0" cellspacing="0" cellpadding="0">  <tr>    <td align="left" valign="top" ><a href="'+baseurl+'uprofile.php?UID='+r_data["uid"]+'" target="_blank">'+thisLogo+'</a></td>    <td align="left" valign="top" class="guideSearchResult"><a href="'+baseurl+'uprofile.php?UID='+r_data["uid"]+'" target="_blank">'+r_data["username"]+'</a><br />      '+r_data["country"]+'</td>  </tr>      </table></td>    </tr>    <tr>      <td align="left" class="moduleEntryDetails">'+station_information+': <br />'+r_data["st_name"]+'<br />      '+r_data["st_city"]+' '+r_data["st_state"]+'<br />      <em>'+st_description+'</em> </td>    </tr>  </table></td>  </tr>      </table></td>    <td valign="top" class=guideSearchResult><span class="guideSearchResultTitle">'+r_data["title"]+'</span> '+runtime+': '+r_data["duration"]+' '+minutes+'. '+viewed+' '+r_data["viewnumber"]+' '+times+''+onlocation+'<br />'+description+'<br /><table width="100%" border="0" align="left" cellpadding="0" cellspacing="0"><tr>  <td width="50%" align="left" valign="top"><DIV class=moduleEntryDetails ID="divVoteResult">      <!-- Showing vote -->      <TABLE BORDER=0 ID="idVoteView"><TR>  <TD>Average from (</TD>  <TD>'+r_data["ratedby"]+'</TD>  <TD>votes )</TD></TR>      </TABLE>    <DIV ID=idViewVoteResult> '+rated+' </DIV>    <DIV>    <TABLE ID="tblViewResult">  <TR>    <TD></TD>    <TD></TD>    <TD></TD>    <TD></TD>    <TD></TD>    <TD></TD>  <TR>      </TABLE>    </DIV>  </DIV>  <div id="ratingDiv" style="TEXT-ALIGN: left">  <div class="moduleEntryDetails" id="voteProcess"> Rate this TV Program.! <br />      <NOBR> <a href="javascript:;" onclick="fxRate(\''+r_data["viewkey"]+'\',2,\'voteProcess\',\'voteProcessthank\',\''+r_data["vid"]+'\')"><img class="rating" src="'+imgurl+'blank_star.png" border="0" /></a> <a href="javascript:;" onclick="fxRate(\''+r_data["viewkey"]+'\',4,\'voteProcess\',\'voteProcessthank\',\''+r_data["vid"]+'\')"> <img class="rating" src="'+imgurl+'blank_star.png" border="0" /></a> <a href="javascript:;" onclick="fxRate(\''+r_data["viewkey"]+'\',6,\'voteProcess\',\'voteProcessthank\',\''+r_data["vid"]+'\')"><img class="rating" src="'+imgurl+'blank_star.png"  border="0" /></a> <a href="javascript:;" onclick="fxRate(\''+r_data["viewkey"]+'\',8,\'voteProcess\',\'voteProcessthank\',\''+r_data["vid"]+'\')"><img class="rating" src="'+imgurl+'blank_star.png"  border="0" /></a> <a href="javascript:;" onclick="fxRate(\''+r_data["viewkey"]+'\',10,\'voteProcess\',\'voteProcessthank\',\''+r_data["vid"]+'\')"><img class="rating" src="'+imgurl+'blank_star.png"  border="0" /></a> </NOBR> </div>  <div id="voteProcessthank" style="display:none"> Thanks for rating! </div></div><div id="vdo_inappro" class=moduleEntryDetails>Please help keep this site clean.<br />Flag this TV Program: <a href="javascript:;" onclick="vdo_inappro(\''+r_data["viewkey"]+'\')">Inappropriate!</a></div></td>   </tr>      </table></td>     </tr></table><input style="FONT-SIZE: 10px; TEXT-ALIGN: center" readonly size=62 value="'+baseurl+'index.php?viewkey='+r_data["viewkey"]+'" name=r_data["vid"]eo_link /><br />'+share_this_video_with_friends+'! '+copy_and_paste+'.    <div id="vdomessage" align="center">  <table width=50% cellpadding=5 cellspacing=1>    <!--<tr><td align=right><b>Subject:</b></td><td><input id="msg_subject" type="text" name="msg_subject" value="" maxlength=200 size=50></td></tr>-->    <tr>  <td align="center">Send this network a comment about this TV Program.<br /><textarea id="msg_details" name="msg_details" cols=50 rows=5></textarea>      </td>    </tr><tr><td  align=center><a href="javascript:;" onclick="send_vdo_comment(\''+r_data["uid"]+'\', \''+r_data["title"]+'\' );">  <div id="btnSearchResult" class="guideMenuitem" style="display:block">Send Comment</div></a></td></tr>  </table></div>';
			
				rdiv.innerHTML=myhtml;	
				tglGuideResult('current');
				tglGuideContent();
				tglGuide();
			}

	}catch(Err){		
		alert('Server Problem '+Err);
	}
}

// use the info and build the topics list
function set_bsearchtags(btags){
	try{	
		if(er[0].childNodes[0].nodeValue != 'none'){
			alert(er[0].childNodes[0].nodeValue);
		}else{
			var tl=document.getElementById('topics');
			if(btags.getElementsByTagName('tag').item(0).firstChild.data != 'empty'){
				var thisValue;
				var msg = ' values - ';
				var x=btags.getElementsByTagName('tag');			
				var myhtml = '<div id="0topic" class="guidelistitemselected">Select a Topic</div>';
				for (i=0;i<x.length;i++)
					{
						thisValue = x[i].childNodes[0].nodeValue;
						myhtml +='<a onclick="guideListSelect(\''+(i+1)+'topic\',  \'topic\', \''+thisValue+'\', 0);doBasicSearch();" href="javascript:;"><div id="'+(i+1)+'topic" class="guidelistitem">'+thisValue+'</div></a>';
						
						//msg += ' ' +x[i].childNodes[0].nodeValue;
					}
					tl.innerHTML=myhtml;	
					//alert(msg);
			}else{
				tl.innerHTML='<div align="center"></br><strong><em>No TV Programs found.</br> Please make another selection!</em></strong></div>';			
			}
		} // end if error
	}catch(Err){		
		alert('Server Problem '+Err);
	}
}

// did video view get set
function vdoviewed_set(rs){
	er=rs.getElementsByTagName('error');
	if(er[0].childNodes[0].nodeValue != 'none'){
		alert(er[0].childNodes[0].nodeValue);
	}
}

// did comment get sent
function message_sent(rs){
	er=rs.getElementsByTagName('error');
	if(er[0].childNodes[0].nodeValue != 'none'){
		alert(er[0].childNodes[0].nodeValue);
	}
	var rdiv=document.getElementById('vdomessage');
	rdiv.innerHTML = '<div align="center"><br><strong><em>Message sent!</em></strogn></div>';
}

// did vdo_flagged get set
function vdo_flagged(rs){
	er=rs.getElementsByTagName('error');
	if(er[0].childNodes[0].nodeValue != 'none'){
		alert(er[0].childNodes[0].nodeValue);
	}
	var rdiv=document.getElementById('vdo_inappro');
	rdiv.innerHTML = '<div><br><strong><em>TV Program has been FLAGGED!</em></strogn></div>';
}

/****************************************************
*
*		GUIDE Functions		
*
****************************************************/
function tglgdbg(x){
// tgl the guide bg
// 1 is amber
// 2 is green
// 3 is blue
	switch(x){
		case 1:
			document.getElementById('guideBG').style.background="url(images/guide_bg_amber.jpg)";
			getStyleClass('guide').style.scrollbarArrowColor='#bb6c1f';
			getStyleClass('guide').style.scrollbarBaseColor='#bb6c1f';
			getStyleClass('guide').style.scrollbarFaceColor='#ffba76';
			getStyleClass('guide').style.scrollbarTrackColor='#ffba76';
			getStyleClass('guide').style.scrollbarDarkshadowColor='#bb6c1f';
			getStyleClass('guide').style.scrollbarHighlightColor='#954a00';
			getStyleClass('guide').style.scrollbarShadowColor='#954a00';
			
			break;
		case 2:
			document.getElementById('guideBG').style.background="url(images/guide_bg_green.jpg)";
			getStyleClass('guide').style.scrollbarArrowColor='#345651';
			getStyleClass('guide').style.scrollbarBaseColor='#345651';
			getStyleClass('guide').style.scrollbarFaceColor='#73D3C8';
			getStyleClass('guide').style.scrollbarTrackColor='#73D3C8';
			getStyleClass('guide').style.scrollbarDarkshadowColor='#345651';
			getStyleClass('guide').style.scrollbarHighlightColor='#46918A';
			getStyleClass('guide').style.scrollbarShadowColor='#46918A';
			break;
		case 3:
			document.getElementById('guideBG').style.background="url(images/guide_bg_blue.jpg)";
			getStyleClass('guide').style.scrollbarArrowColor='#363f3c';
			getStyleClass('guide').style.scrollbarBaseColor='#363f3c';
			getStyleClass('guide').style.scrollbarFaceColor='#f0f3f8';
			getStyleClass('guide').style.scrollbarTrackColor='#f0f3f8';
			getStyleClass('guide').style.scrollbarDarkshadowColor='#a6afac';
			getStyleClass('guide').style.scrollbarHighlightColor='#a7afac';
			getStyleClass('guide').style.scrollbarShadowColor='#a7afac';
			break;
			
	}
}
function doBasicSearch(){
	//alert('Build Basic Search query, send ajax and create result!!');
	
	// call the ajax function with the stored values for this search (country, channel, starting page)
	get_bsearchresult(guideselectList['country'][1], guideselectList['channel'][1], guideselectList['topic'][1], 'title', 1);
	
	// now get commercials for this search topic
	cp.call('ajax/filitvajax.php', 'get_playlist', makePlayList, 1, guideselectList['topic'][1]);
	
	//document.getElementById('searchsql').innerHTML = 'BASIC SEARCH CRITERIA<br>Country  '+guideselectList['country'].toString()+'<br>Channel '+guideselectList['channel'].toString()+'<br>Topic '+guideselectList['topic'].toString();
	document.getElementById('guideSearchResult').innerHTML = '<div aling="center">PROCESSING...</div>';
	tglGuideResult('searchResult');
}

function doAdvSearch(){

	// check to see if we have something to search on
	var isOK = 0;
	var gotCountry = guideselectListAdv['adv_country'].length;
	var gotChannel = guideselectListAdv['adv_channel'].length;
	
	// remove white spaces, tabs extra space from keyords
	var tempkeyWords = new String(document.getElementById('advKeywords').value);
	var keyWords = tempkeyWords.replace(/\s\s+/g, ' ');

	// strip out any leading and trailing spaces if there are keywords
	if(keyWords.length){
		if(keyWords.charCodeAt(0) == 32){
			keyWords = keyWords.substr(1);
		}
		// Check for trailing space
		if(keyWords.charCodeAt(keyWords.length-1) == 32){
			keyWords = keyWords.slice(0, -1);
		}
	}
	
	//var keywordsArr = keyWords.split(' ');
	var gotKeywords = keyWords.length;
	//alert(keyWords.length+' keyWords.length | gotKeyWords '+gotKeywords);
	
	// is everything filled out correctly
	if(gotCountry && gotChannel && gotKeywords){
		
		// create a text String of the values for countryies, channels, keywords
		var advcountries='|';
		var advchannels='|';
		
		for(var i=0; i<guideselectListAdv['adv_country'].length; i++){
			advcountries+=guideselectListAdv['adv_country'][i][1]+'|';
		}
		for(var i=0; i<guideselectListAdv['adv_channel'].length; i++){
			advchannels+=guideselectListAdv['adv_channel'][i][1]+'|';
		}
		// call the ajax function with the stored values for this search (country, channel, starting page)
		get_asearchresult(advcountries, advchannels, keyWords, 'scr', 1);
		
		// create comercials from topics		
		cp.call('ajax/filitvajax.php', 'get_playlist', makePlayList, 1, keyWords);

		document.getElementById('guideSearchResult').innerHTML = '<div aling="center">PROCESSING...</div>';
		tglGuideResult('searchResult');

	}else{
		alert('Please fill in All Search Criteria');

	}

}

function getTopics(){

	// get the list of topics for the basic search
	var isOk = 0;
	var isCountry = 0;
	var isChannel = 0;

	// first check to make sure a country AND Channel has been selected

	if( guideselectList['country'][0].charAt(0) != '0' ){isCountry = 1;}
	if( guideselectList['channel'][0].charAt(0) != '0' ){isChannel = 1;}

	

	// if both have been selected, show topics

	if(isCountry && isChannel){
		// do sql and AJAX to populate topics
		// show topics
		get_bsearchtags(guideselectList['country'][1], guideselectList['channel'][1]);
		document.getElementById("basicSearchTopics").style.display = 'block';
	}	

}

// toggle guideResult displays
function tglGuideResult(newDisplay){

	// if current state is not newDisplay!
	if(guideResultState != newDisplay){
		if(!guideWorking){
			guideWorking = 1; // turn off all changes until wee are done with the current ones
			// hide current display
			new Effect.toggle(guideResultState, 'appear', {duration: fadeLength, queue: 'end'});	
			new Effect.toggle(newDisplay, 'appear', {duration: fadeLength, queue: 'end', afterFinish:function(){guideWorking = 0;} });
			guideResultState = newDisplay;
		} // end if we are not working
		
	}

}

// toggle search options between basic and advanced
function tglSearch(){

	if(searchState){
	// set to advanced	
		searchState = 0
	
			new Effect.toggle('basicSearch', 'appear', {duration: fadeLength, queue: 'end'});	
			new Effect.toggle('advancedSearch', 'appear', {duration: fadeLength, queue: 'end', afterFinish:function(){searchState = 0;} });
			
		document.getElementById("btnAsearch").style.display='none';
		document.getElementById("btnBsearch").style.display='block';

	}else{
	// set to basic
		document.getElementById("btnBsearch").style.display='none';
		document.getElementById("btnAsearch").style.display='block';

		searchState = 1;	
			new Effect.toggle('advancedSearch', 'appear', {duration: fadeLength, queue: 'end'});	
			new Effect.toggle('basicSearch', 'appear', {duration: fadeLength, queue: 'end'});
	}
}

// visual cue for selecting and deselcting items 
// also populates Arrays with the data from the selection
function guideListSelect(thisID, whichList, mydata, style){
	// thisID is the id to set selected or deselect
	// whichList Array is country, channel, topic etc
	// style is basic ord advanced = 1 
	if(style){
		// this is the advanced search, we have multiple selections possible
		// first, if we ar selecting an item that is already selected
		// take it out of the array and deselect it.

		if(document.getElementById(thisID).className == 'guidelistitemselected'){
		// it is already selected, deselect it, go through the array and pull it out!

			document.getElementById(thisID).className = 'guidelistitem';
			// document.getElementById(whichList).setActive();

			// loop through array and look for this selected option value
			for(var i=0; i < guideselectListAdv[whichList].length; i++){				
				if(thisID == guideselectListAdv[whichList][i][0]){
					
					// Found, so pull it out of the array of values
					guideselectListAdv[whichList].splice(i, 1);
					break;
				}
			}
		}else{

			// it is not already selected, so set it selected and populate the array
			document.getElementById(thisID).className = 'guidelistitemselected';
			//var newIndex = guideselectListAdv[whichList].length;
			//alert(whichList+" | "+thisID+' | '+mydata+' | '+newIndex+' index');
			var dataArray = new Array();
			dataArray[0] = thisID;
			dataArray[1] = mydata;
			guideselectListAdv[whichList].push(dataArray);
		}		

	}else{ // this is the basic and single select items

		// set the last selected to transparent
		document.getElementById(guideselectList[whichList][0]).className='guidelistitem';		

		// SET THIS TO USE THE CSS style and do not change JUST THE COLOR
		// so that we can change the color format to amber!!!
		document.getElementById(thisID).className='guidelistitemselected';
		guideselectList[whichList][0] = thisID;
		guideselectList[whichList][1] = mydata;
		if(whichList != 'topic'){
			// remove any tags that may already be their!
			document.getElementById('topics').innerHTML='<div align="center">Processing...</div>';
			getTopics();
		}
	}
}

// toggle ALL content in the guide for slide on and slide off
// used in conjunction with tglGuide
function tglGuideContent(){

	// this is to show the content after the guide starts to move on the screen
	// it speeds things up ALOT

	new Effect.toggle('guideContent', 'appear', {duration: fadeLength+.5});
}


// toggles the visible state of the guide. SLIDE UP with EASEING

function tglGuide(){

	// check if guide is open or closed 1 is open
	if(guideState){

		// closed so open it
		var obj = document.getElementById("guide");
		new Effect.Move(obj, {x: 2, y: guideT, mode: 'absolute'});
		document.getElementById("guidetgl2").style.display = 'none';
		document.getElementById("guidetgl1").style.display = 'block';				
		guideState = 0;

	}else{

		// open so close it
		var obj = document.getElementById("guide");
		new Effect.Move(obj, {x: 2, y: guideTtop, mode: 'absolute'});
		document.getElementById("guidetgl2").style.display = 'block';
		document.getElementById("guidetgl1").style.display = 'none';
		guideState = 1;

	}
}


/* Macromedia needed functions */
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/**************************************************************************
 * FLOWPLAYER
 * Init and setup FlowPlayer. This example file shows 'advanced' features like
 * playlists and configuring with JavaScript. FlowPlayer.html is a simpler example.
 *
 */

var flowPlayer1;
function flowinit() {
	if (document.getElementById) {
		flowPlayer1 = document.getElementById("FlowPlayer");
    }
	
	// FlowPlayer configuration
	fpConf = {
	// for FMS:
	//	streamingServerURL: 'rtmp://cyzy7r959.rtmphost.com/flowplayer',
	// for red5:
	//	streamingServerURL: 'rtmp://localhost:1935/oflaDemo',
		playList: clips,
		//noVideoClip: { url: 'no_video.png', duration: '30' },
	//	baseURL: 'http://www.filitv.com/',
		useSmoothing: true,
		autoPlay: true,
		menuItems: [ true, true, true, true, true, false ],
		autoBuffering: true,
		startingBufferLength: 10,
		initialScale: 'orig',
//		initialScale: 'fit',
		showPlayListButtons: true,
		autoRewind: true,
		loop: true
	}

	setFlowPlayerConfig();
}

// wait for the page to fully load before initializing
// window.onload = flowinit;

function setFlowPlayerConfig() {
	// alert(fpConf.baseURL+" | "+clips[0].url);
	flowPlayer1.setConfig(fpConf);
}


/****************************************************
*
*		OTHER Functions		
*
****************************************************/
// used to change styleShhet definitions
// getStyleClass('aStyleClass').style.display = 'inline'
function getStyleClass (className) {
	for (var s = 0; s < document.styleSheets.length; s++)
	{
		if(document.styleSheets[s].rules)
		{
			for (var r = 0; r < document.styleSheets[s].rules.length; r++)
			{
				if (document.styleSheets[s].rules[r].selectorText == '.' + className)
				{
					return document.styleSheets[s].rules[r];
				}
			}
		}
		else if(document.styleSheets[s].cssRules)
		{
			for (var r = 0; r < document.styleSheets[s].cssRules.length; r++)
			{
				if (document.styleSheets[s].cssRules[r].selectorText == '.' + className)
					return document.styleSheets[s].cssRules[r];
			}
		}
	}
	
	return null;
}

// used to decode encoded strings sent from ajax calls
function URLDecode(psEncodeString)
{
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  return unescape(String(psEncodeString).replace(lsRegExp, " "));
}
 
// all these are used to populate the other guide screens on first start!
window.onload = function(){	
//alert("load");
MM_preloadImages('images/guide_bg_blue.jpg','images/guide_bg_amber.jpg','images/guid_x_over_09.gif','images/guid_u_over_09.gif','images/guideMenu_over.gif'); 

// do create first play list for premium commercial spot and initialize flowplayer
createFirstPlaylist();
flowinit();


// go get the Highest rated and most watched results.. and populate
get_mwsearchresult("mv", 1);
get_hrsearchresult("tr", 1);
get_spsearchresult();

// initial Playlist. first commercial, that sort of thing.. 
// to be replaced with the vdofile if url vkey is sent. 


	if(urlvdo == 'yes'){
		
		//var clips = [{ name: 'video', url: uvflvdoname}];
		//cp.call('ajax/filitvajax.php', 'get_playlist', makePlayList, uvvkey);
		playThisShow(uvvtype, uvvkey, uvvid, uvuid);
	}

}
