// set a custom icon for when a user bookmarks the app to the home screen
//<link rel="apple-touch-icon" href="/path/to/icon.png" /> 
// hide the browser chrome
//<meta name="apple-mobile-web-app-capable" content="yes" /> 
//set the phone status bar style; can be grey, black, or black translucent
//<meta name="apple-mobile-web-app-status-bar-style" content="black" />

function get( name )
{
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
	var results = regex.exec( window.location.href );
	if( results == null )
		return "";
	else
		return results[1];
}

function return2br(dataStr) 
{
	return dataStr.replace(/(\r\n|\r|\n)/g, "<br />");
}

var mode=parseInt(get("mode"));
var loaded_framework=false;
var loaded=false;
var xmlhttp;
var server=get("server");
var channel=get("ch");
var category=get("cat");
var premid=parseInt(get("id"));
var speed=get("speed");
var limit=parseInt(get("limit"));
var start=1;
var LastStart=1;
var URLtkt="";
var autoplay=get("autoplay");
var URLcat_pwd="";
var URLcat="";
var MovieWidth=parseInt(get("mw"));
var MovieHeight=parseInt(get("mh"));
var Active_mid;
var qt=parseInt(get("qt"));
var html5=parseInt(get("html5"));
var Intro=0;

var keyStr = "ABCDEFGHIJKLMNOP" +
             "QRSTUVWXYZabcdef" +
             "ghijklmnopqrstuv" +
             "wxyz0123456789+/" +
             "=";

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}

function encode64(input) {
   input = escape(input);
   var output = "";
   var chr1, chr2, chr3 = "";
   var enc1, enc2, enc3, enc4 = "";
   var i = 0;

   do {
      chr1 = input.charCodeAt(i++);
      chr2 = input.charCodeAt(i++);
      chr3 = input.charCodeAt(i++);

      enc1 = chr1 >> 2;
      enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
      enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
      enc4 = chr3 & 63;

      if (isNaN(chr2)) {
         enc3 = enc4 = 64;
      } else if (isNaN(chr3)) {
         enc4 = 64;
      }

      output = output +
         keyStr.charAt(enc1) +
         keyStr.charAt(enc2) +
         keyStr.charAt(enc3) +
         keyStr.charAt(enc4);
      chr1 = chr2 = chr3 = "";
      enc1 = enc2 = enc3 = enc4 = "";
   } while (i < input.length);

   return output;
}

function loadgetXMLtkt(mid)
{
	xmlhttp=null;
	if (window.XMLHttpRequest) // code for IE7+, Firefox, Chrome, Opera, Safari
	{
		xmlhttp=new XMLHttpRequest();
	}
	else // code for IE5, IE6
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	//xmlhttp.onreadystatechange=ongetXMLtktResponse;
	xmlhttp.open("GET","http://"+server+"/getXMLtkt.php?ch="+channel+"&id="+mid+"&speed="+speed,false);
	xmlhttp.send(null);
	ongetXMLtktResponse();
}

function setQuality(new_speed)
{
	speed=new_speed;
	
	if (speed==1)
	{
		the_br="56";
	}
	else if (speed==3)
	{
		the_br="256";
	}
	else
	{
		the_br="128";
	}
	return;
}

function ongetXMLtktResponse()
{
	if(xmlhttp.readyState!=4) return;
	if(xmlhttp.status!=200)
	{
		alert("Problem retrieving XML data from "+server);
		return;
	}
	
	//Check for error
	req_Result=parseInt(XMLMovieList.documentElement.getElementsByTagName("Result")[0].getAttribute('id'));
	if (req_Result>0)
	{
		alert ("Error "+req_Result+"! "+XMLMovieList.documentElement.getElementsByTagName("Result")[0].firstChild.nodeValue);
		return;
	}
	tkt=xmlhttp.responseXML.documentElement.getElementsByTagName("Ticket")[0].firstChild.nodeValue;
	URLtkt="&tkt="+tkt;
}

function set_cat_pwd()
{
	loaded=false; //Reload the channel...
	URLcat_pwd="&cat_pwd="+document.getElementById("catpwdfld").value;
	loadXMLMovieList('http://'+server+'/XMLMovieList.php?ch='+channel+URLcat+'&speed='+speed+'&start=1&limit='+limit+URLcat_pwd+'&FullInfo=1');
}

function reloadmove(url, imgURL)
{
	//Get a ticket, we most likelly need it ;-)
	loadgetXMLtkt(Active_mid);
	url=url+URLtkt;
	URLtkt="";
		
	url=url+"&m_pwd="+encode64(document.getElementById('m_pwdfld').value);
	document.getElementById('nc_x_body_movie_title').innerHTML=""; //Removes the pw field.
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)) || (qt==1) || (html5==1))
	{
		if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)) || (html5==1))
		{
			if(autoplay=="true")
			{
				txt="<video src=\""+url+"\" controls=\"controls\" autoplay=\"autoplay\" height=\""+MovieHeight+"\" width=\""+MovieWidth+"\" poster=\""+imgURL+"\" "+AndroidVideoStr+"></video>";
			}
			else
			{
				txt="<video src=\""+url+"\" controls=\"controls\" height=\""+MovieHeight+"\" width=\""+MovieWidth+"\" poster=\""+imgURL+"\" "+AndroidVideoStr+"></video>";
			}
			
			//txt="<OBJECT CLASSID=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" CODEBASE=\"http://www.apple.com/qtactivex/qtplugin.cab\" width=\""+ MovieWidth +"\"height=\""+MovieHeight+"\" ><PARAM NAME=\"src\" VALUE=\""+imgURL+"\" ><PARAM NAME=\"href\" VALUE=\""+url+"\" ><PARAM NAME=\"target\" VALUE=\"myself\" ><PARAM NAME=\"autoplay\" VALUE=\""+autoplay+"\" ><PARAM NAME=\"scale\" VALUE=\"tofit\" ><PARAM NAME=\"controller\" VALUE=\"true\" ><EMBED SRC=\""+imgURL+"\" href=\""+url+"\" TYPE=\"video/mp4\" PLUGINSPAGE=\"http://www.apple.com/quicktime/download\" width=\""+ MovieWidth +"\" height=\""+MovieHeight+"\" AUTOPLAY=\""+autoplay+"\" scale=\"tofit\" controller=\"true\" target=\"myself\"></EMBED></OBJECT>";
		}
		else
		{
			mh=MovieHeight+16;
			txt="<OBJECT CLASSID=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" CODEBASE=\"http://www.apple.com/qtactivex/qtplugin.cab\" width=\""+ MovieWidth +"\"height=\""+mh+"\" ><PARAM NAME=\"src\" VALUE=\""+url+"\" ><PARAM NAME=\"target\" VALUE=\"myself\" ><PARAM NAME=\"autoplay\" VALUE=\""+autoplay+"\" ><PARAM NAME=\"scale\" VALUE=\"tofit\" ><PARAM NAME=\"controller\" VALUE=\"true\" ><EMBED SRC=\""+url+"\" TYPE=\"video/mp4\" PLUGINSPAGE=\"http://www.apple.com/quicktime/download\" width=\""+ MovieWidth +"\"height=\""+mh+"\" AUTOPLAY=\""+autoplay+"\" scale=\"tofit\" controller=\"true\" target=\"myself\"></EMBED></OBJECT>";
		}
	}
	else
	{
		
		//Check if we should use a preroll
		if (Intro==1)
		{
			if (category>0)
			{
				url=url.replace(/getMovie.php/, "getMoviePlaylist.php")+"&ch="+channel+"&cat="+category;
			}
			else
			{
				url=url.replace(/getMovie.php/, "getMoviePlaylist.php")+"&ch="+channel;
			}
			type="&repeat=list";
		}
		else
		{
			type="&type=video";
		}
		
		mh=MovieHeight+19;
		txt="<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0\" width=\""+ MovieWidth +"\"height=\""+mh+"\" align=\"middle\"><param name=\"movie\" value=\"http://"+server+"/flash/player.swf\" /><param name=\"allowfullscreen\" value=\"true\" /><PARAM NAME=FlashVars VALUE=\"image="+URLEncode(imgURL)+"&file="+URLEncode(url)+type+"&autostart="+autoplay+"&linkfromdisplay=false\"><embed src=\"http://"+server+"/flash/player.swf\" width=\""+ MovieWidth +"\"height=\""+mh+"\" name=\"mymovie\" align=\"middle\" allowfullscreen=\"true\" type=\"application/x-shockwave-flash\" flashvars=\"image="+URLEncode(imgURL)+"&file="+URLEncode(url)+type+"&autostart="+autoplay+"&linkfromdisplay=false\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" /></object>";
	}
	document.getElementById('nc_x_body_movie_head').innerHTML=txt;
}

function showMoviePage(index)
{
	x=XMLMovieList.documentElement.getElementsByTagName("Movie")[index];
	
	try
	{
		id=parseInt(x.getAttribute("id"));
		Active_mid=id;
	}
	catch (er)
	{
		alert ("XML Error! (no id)");
	}
	
	try
	{
		tkt=parseInt(x.getAttribute("tkt"));
	}
	catch (er)
	{
		alert ("XML Error! (no tkt)");
	}
	
	try
	{
		m_pwd=parseInt(x.getAttribute("m_pwd"));
	}
	catch (er)
	{
		alert ("XML Error! (no pwd)");
	}
	
	try
	{
		url=x.getElementsByTagName("HTTPURL")[0].firstChild.nodeValue;
	}
	catch (er)
	{
		alert ("XML Error! (no HTTPURL)");
	}
	
   	{
   		try
		{
			imgURL=x.getElementsByTagName("ThumbNail")[0].getAttribute("url");
		}
  			catch (er)
		{}
	}
	
	//Override the speed parameter
	url=url.replace(/br=/, "blob=");
	url=url+"&br="+the_br;
	
	//Do we need a password
	if (m_pwd==1)
	{
		txt="<div id=\"nc_x_body_movie\"><div id=\"nc_x_body_movie_title\"><h1>This movie requires a password!</h1><h2>Password: <input id=\"m_pwdfld\" type=\"password\" name=\"pass\" size=\"16\" value=\"\" onKeyDown=\"if(event.keyCode==13) reloadmove('"+url+"', '"+imgURL+"');\"> <input id=\"m_pwdbtn\" type=\"button\" name=\"Submit\" onclick=\"reloadmove('"+url+"', '"+imgURL+"')\" value=\"Submit\" /></h2></div>";
	}
	else
	{
		if (tkt==1)
		{
			loadgetXMLtkt(Active_mid);
			url=url+URLtkt;
			URLtkt="";
		}
		txt="<div id=\"nc_x_body_movie\"><div id=\"nc_x_body_movie_title\"><H2></H2></div>";
	}
	
	//Print the movie tag
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)) || (qt==1) || (html5==1))
	{
		if (m_pwd==1)
		{
			txt=txt+"<div id=\"nc_x_body_movie_head\"><img src=\""+imgURL+"\"></div>";
		}
		else
		{
			if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)) || (html5==1))
			{
				if(autoplay=="true")
			{
				txt=txt+"<div id=\"nc_x_body_movie_head\"><video src=\""+url+"\" controls=\"controls\" autoplay=\"autoplay\" height=\""+MovieHeight+"\" width=\""+MovieWidth+"\" poster=\""+imgURL+"\" "+AndroidVideoStr+"></video></div>";
			}
			else
			{
				txt=txt+"<div id=\"nc_x_body_movie_head\"><video src=\""+url+"\" controls=\"controls\" height=\""+MovieHeight+"\" width=\""+MovieWidth+"\" poster=\""+imgURL+"\" "+AndroidVideoStr+"></video></div>";
			}
				
				
				//txt=txt+"<div id=\"nc_x_body_movie_head\"><OBJECT CLASSID=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" CODEBASE=\"http://www.apple.com/qtactivex/qtplugin.cab\" width=\""+ MovieWidth +"\"height=\""+MovieHeight+"\" ><PARAM NAME=\"src\" VALUE=\""+imgURL+"\" ><PARAM NAME=\"href\" VALUE=\""+url+"\" ><PARAM NAME=\"target\" VALUE=\"myself\" ><PARAM NAME=\"autoplay\" VALUE=\""+autoplay+"\" ><PARAM NAME=\"scale\" VALUE=\"tofit\" ><PARAM NAME=\"controller\" VALUE=\"true\" ><EMBED SRC=\""+imgURL+"\" href=\""+url+"\" TYPE=\"video/mp4\" PLUGINSPAGE=\"http://www.apple.com/quicktime/download\" width=\""+ MovieWidth +"\"height=\""+MovieHeight+"\" AUTOPLAY=\""+autoplay+"\" scale=\"tofit\" controller=\"true\" target=\"myself\"></EMBED></OBJECT></div>";
			}
			else
			{
				mh=MovieHeight+16;
				txt=txt+"<div id=\"nc_x_body_movie_head\"><OBJECT CLASSID=\"clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B\" CODEBASE=\"http://www.apple.com/qtactivex/qtplugin.cab\" width=\""+ MovieWidth +"\"height=\""+mh+"\" ><PARAM NAME=\"src\" VALUE=\""+url+"\" ><PARAM NAME=\"target\" VALUE=\"myself\" ><PARAM NAME=\"autoplay\" VALUE=\""+autoplay+"\" ><PARAM NAME=\"scale\" VALUE=\"tofit\" ><PARAM NAME=\"controller\" VALUE=\"true\" ><EMBED SRC=\""+url+"\" TYPE=\"video/mp4\" PLUGINSPAGE=\"http://www.apple.com/quicktime/download\" width=\""+ MovieWidth +"\"height=\""+mh+"\" AUTOPLAY=\""+autoplay+"\" scale=\"tofit\" controller=\"true\" target=\"myself\"></EMBED></OBJECT></div>";
			}
		}
	}
	else
	{
		if (m_pwd==1)
		{
			txt=txt+"<div id=\"nc_x_body_movie_head\"><img src=\""+imgURL+"\"></div>";
		}
		else
		{
			
			//Check if we should use a preroll
			if (Intro==1)
			{
				if (category>0)
				{
					url=url.replace(/getMovie.php/, "getMoviePlaylist.php")+"&ch="+channel+"&cat="+category;
				}
				else
				{
					url=url.replace(/getMovie.php/, "getMoviePlaylist.php")+"&ch="+channel;
				}
				type="&repeat=list";
			}
			else
			{
				type="&type=video";
			}
		
			mh=MovieHeight+19;
			txt=txt+"<div id=\"nc_x_body_movie_head\"><object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0\" width=\""+ MovieWidth +"\"height=\""+mh+"\" align=\"middle\"><param name=\"movie\" value=\"http://"+server+"/flash/player.swf\" /><param name=\"allowfullscreen\" value=\"true\" /><PARAM NAME=FlashVars VALUE=\"image="+URLEncode(imgURL)+"&file="+URLEncode(url)+type+"&autostart="+autoplay+"&linkfromdisplay=false\"><embed src=\"http://"+server+"/flash/player.swf\" width=\""+ MovieWidth +"\"height=\""+mh+"\" name=\"mymovie\" align=\"middle\" allowfullscreen=\"true\" type=\"application/x-shockwave-flash\" flashvars=\"image="+URLEncode(imgURL)+"&file="+URLEncode(url)+type+"&autostart="+autoplay+"&linkfromdisplay=false\" pluginspage=\"http://www.adobe.com/go/getflashplayer\" /></object></div>";
		}
	}
	
	//Print the movie text
	try
	{
	txt=txt+"<div id=\"nc_x_body_movie_body\"><H1>"+x.getElementsByTagName("Title")[0].firstChild.nodeValue+"</H1>";
	}
	catch (er)
	{
		txt=txt+"<div id=\"nc_x_body_movie_body\"><H1>Untitled</H1>";
	}
	try
	{
	txt=txt+"<H2>"+x.getElementsByTagName("Heading")[0].firstChild.nodeValue+"</H2>";
	}
	catch (er)
	{}
	try
	{
	txt=txt+"<H3>"+x.getElementsByTagName("SubHeading")[0].firstChild.nodeValue+"</H3>";
	}
	catch (er)
	{}
	try
	{
	txt=txt+"<p>Duration: "+x.getElementsByTagName("Duration")[0].firstChild.nodeValue+"</p>";
	}
	catch (er)
	{}
	try
	{
	//txt=txt+"<p>"+x.getElementsByTagName("Body")[0].firstChild.nodeValue+"</p>";
	txt=txt+"<p>"+return2br(x.getElementsByTagName("Body")[0].firstChild.nodeValue)+"</p>";
	}
	catch (er)
	{}
	
	s=window.location+"";
	//Here we also need to remove any previous id=123
	if (s.indexOf("id=") == -1) //No id=123
	{
		
		if (s.indexOf("?") == -1) //? or &
		{
			txt=txt+"<p class=\"lnk\">Link to this movie: "+s+"?id="+id+"</p>";
		}
		else
		{
			txt=txt+"<p class=\"lnk\">Link to this movie: "+s+"&id="+id+"</p>";
		}
		
		
		
		
	}
	else //There is a id=123
	{
		//l=s.indexOf("id=")-1;
		s=s.substr(0,s.indexOf("id=")-1);
		
		if (s.indexOf("?") == -1) //? or &
		{
			txt=txt+"<p class=\"lnk\">Link to this movie: "+s+"?id="+id+"</p>";
		}
		else
		{
			txt=txt+"<p class=\"lnk\">Link to this movie: "+s+"&id="+id+"</p>";
		}
		
	}
		
	
	if (mode==1)
	{
		
	}
	
	txt=txt+"</div>";//Close nc_x_body_movie_body
	txt=txt+"<div id=\"nc_x_body_movie_foot\"></div>";
	txt=txt+"</div>";//Close nc_x_body_movie
	
	
	if (mode==1) //How do we do with the back button????....
	{
		txt=txt+"<div id=\"nc_x_body_bak\" onclick=\"loadXMLMovieList('http://'+server+'/XMLMovieList.php?ch='+channel+URLcat+URLcat_pwd+'&speed='+speed+'&start='+LastStart+'&limit='+limit)\"><H2>&lt;&lt; BACK</H2></div>";

		document.getElementById('nc_body_menu_body').innerHTML=txt;
	}
	else
	{
		document.getElementById('nc_body_movie').innerHTML=txt;
	}
}

function loadXMLMovieList(url)
{
	//alert (url);
	xmlhttp=null;
	if (window.XMLHttpRequest) // code for IE7+, Firefox, Chrome, Opera, Safari
	{
		xmlhttp=new XMLHttpRequest();
	}
	else // code for IE5, IE6
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	//xmlhttp.onreadystatechange=onloadXMLMovieListResponse;
	xmlhttp.open("GET",url,false); //Load synchron
	xmlhttp.send(null);
	onloadXMLMovieListResponse();
}

function loadCategory(new_cat)
{
	if (parseInt(new_cat)==-1)
	{
		return;
	}
	else if (parseInt(new_cat)==0)
	{
		category=0;
		URLcat="";
		URLcat_pwd="";
	}
	
	else
	{
		URLcat_pwd="";
		category=new_cat;
		URLcat="&cat="+category;
	}
	loadXMLMovieList('http://'+server+'/XMLMovieList.php?ch='+channel+URLcat+'&speed='+speed+'&start=1&limit='+limit);	
}

function onloadXMLMovieListResponse()
{
	if(xmlhttp.readyState!=4) return;
	if(xmlhttp.status!=200)
	{
		alert("Problem retrieving XML data from "+server);
		//return;
	}
	
	XMLMovieList=xmlhttp.responseXML;
	
	//Check for error
	req_Result=parseInt(XMLMovieList.documentElement.getElementsByTagName("Result")[0].getAttribute('id'));
	if (req_Result>0)
	{
		if (req_Result==603)
		{
			if (loaded_framework==false)
			{
				loaded_framework=true;
				document.write("<div id=\"navicast\"><div id=\"nc_title\"></div><div id=\"nc_head\"></div><div id=\"nc_body\"><div id=\"nc_body_movie\"><div id=\"nc_body_movie_title\"></div><div id=\"nc_body_movie_head\"></div><div id=\"nc_body_movie_body\"></div><div id=\"nc_body_movie_foot\"></div></div><div id=\"nc_body_menu\"></div></div><div id=\"nc_foot\"><p><a href=\"http://www.navicast.net/\" target=\"_blank\">Powered by Navicast®</a></p></div></div>");
			}
			
			txt="<div id=\"nc_head_catpwd\"><h1>This category requires a password!</h1><p>&nbsp;</p><h2>Password: <input id=\"catpwdfld\" type=\"password\" name=\"pass\" size=\"16\" value=\"\" onKeyDown=\"if(event.keyCode==13) set_cat_pwd();\"> <input id=\"catpwdbtn\" type=\"button\" type=\"button\" name=\"Submit\" onclick=\"set_cat_pwd()\" value=\"Submit\" /></h2><p>&nbsp;</p></div>";
			
			//loaded=false; //only on execution :-)
			document.getElementById('nc_body_movie').innerHTML="";
			document.getElementById('nc_body_menu').innerHTML="";
			document.getElementById('nc_head').innerHTML=txt;
			
		}
		else if (req_Result==604)
		{
			alert ("Error: "+req_Result+"! "+XMLMovieList.documentElement.getElementsByTagName("Result")[0].firstChild.nodeValue+" You may need to define a category.");	
		}
		else
		{
			alert ("Error "+req_Result+"! "+XMLMovieList.documentElement.getElementsByTagName("Result")[0].firstChild.nodeValue);
		}
		return;
	}
	
	
	//No Error
	if (loaded==false) //Setup innitial channel values
	{
		loaded=true;
		
		try
		{
			ChTitle=XMLMovieList.documentElement.getElementsByTagName("ChannelName")[0].firstChild.nodeValue;
		}
		catch (er)
		{
			ChTitle="Untitled Channel";
		}
		
		Intro=parseInt(XMLMovieList.documentElement.getElementsByTagName("Intro")[0].getAttribute('active'));
		
		if (loaded_framework==false)
		{
			//Draw the basic framework
			loaded_framework=true;
			document.title = ChTitle;
			document.write("<div id=\"navicast\"><div id=\"nc_title\"><H1>"+ChTitle+"</H1></div><div id=\"nc_head\"></div><div id=\"nc_body\"><div id=\"nc_body_movie\"><div id=\"nc_body_movie_title\"></div><div id=\"nc_body_movie_head\"></div><div id=\"nc_body_movie_body\"></div><div id=\"nc_body_movie_foot\"></div></div><div id=\"nc_body_menu\"></div></div><div id=\"nc_foot\"><p><a href=\"http://www.navicast.net/\" target=\"_blank\">Powered by Navicast®</a></p></div></div>");
			
		}
		else //We have entered in a password protected channel and now need to inject the channel title.
		{
			document.getElementById('nc_head').innerHTML=""; //Clear all channel category login text
			document.getElementById('nc_title').innerHTML="<H1>"+ChTitle+"</H1>";
		}
		
		if (mode>1)
		{
			//alert ("here");
			showMoviePage(0);
			txt="";
		}
		
		//Dra the title
		txt="<div id=\"nc_body_menu_title\"><H1>"+ChTitle+"</H1></div>";
		
		//Draw the category popup
		try
		{
			x=XMLMovieList.documentElement.getElementsByTagName("Category");
			
			if (x.length>0)
			{
				xy=x.length;
				txt=txt+"<div id=\"nc_body_menu_head\"><h2><select id=\"catsel\" type=\"select\" onChange=\"loadCategory(this.options[this.selectedIndex].value)\">";
				
				if (!category) //No category set.
				{
					txt=txt+"<option selected value=\"-1\">Select a Category</option>";
					txt=txt+"<option value=\"0\">All</option>";
				}
				else
				{
					txt=txt+"<option value=\"-1\">Select a Category</option>";
				}
				
				for (i=0;i<xy;i++)
				{
					
					if (parseInt(x[i].getAttribute('id'))==category)
					{
						
						try
						{
							name=XMLMovieList.documentElement.getElementsByTagName("CategoryName")[0].firstChild.nodeValue;
						}
						catch (er)
						{
							name="!Untitled!";
						}
						txt=txt+"<option selected value=\""+x[i].getAttribute('id')+"\">"+name+"</option>";
						xy=xy-1;
					}
					else
					{
						try
						{
							name=x[i].getAttribute('name');
						}
						catch (er)
						{
							name="!Untitled!";
						}
						txt=txt+"<option value=\""+x[i].getAttribute('id')+"\">"+name+"</option>";
					}
				}
				txt=txt+"</select></h2></div>";
			}
			else
			{
				txt=txt+"<div id=\"nc_body_menu_head\"><h2>	</h2></div>";
			}
		}
  		catch (er)
		{}
		
		//Draw the Movie List div
		txt=txt+"<div id=\"nc_body_menu_body\"></div>";
		
		//Draw the Quality popup and Search field
		txt=txt+"<div id=\"nc_body_menu_foot\"><h2>";
		txt=txt+"<select id=\"Qsel\" type=\"select\" onChange=\"setQuality(this.options[this.selectedIndex].value)\">";
				if (speed==1)
				{
					
					if (iphod<1)
					{
						txt=txt+"<option selected value=\"1\">Low Quality</option>";
						txt=txt+"<option value=\"2\">Medium Quality</option>";
						txt=txt+"<option value=\"3\">High Quality</option>";
					}
					else
					{
						txt=txt+"<option selected value=\"1\">Low Quality</option>";
						txt=txt+"<option value=\"2\">High Quality</option>";
					}
				}
				else if (speed==2)
				{
					if (iphod<1)
					{
						txt=txt+"<option value=\"1\">Low Quality</option>";
						txt=txt+"<option selected value=\"2\">Medium Quality</option>";
						txt=txt+"<option value=\"3\">High Quality</option>";
					}
					else
					{
						txt=txt+"<option value=\"1\">Low Quality</option>";
						txt=txt+"<option selected value=\"2\">High Quality</option>";
					}
				}
				else
				{
					txt=txt+"<option value=\"1\">Low Quality</option>";
					txt=txt+"<option value=\"2\">Medium Quality</option>";
					txt=txt+"<option selected value=\"3\">High Quality</option>";
				}
		
		txt=txt+"</select><input id=\"fndfld\" type=\"search\" placeholder=\"Movie Search\" autosave=\"keywords\" results=\"5\" onKeyDown=\"if(event.keyCode==13) loadXMLMovieList('http://'+server+'/XMLMovieList.php?ch='+channel+URLcat+'&speed='+speed+'&start=1&limit='+limit+URLcat_pwd+'&find='+document.getElementById('fndfld').value)\"><input id=\"fndbtn\" type=\"button\" onclick=\"loadXMLMovieList('http://'+server+'/XMLMovieList.php?ch='+channel+URLcat+'&speed='+speed+'&start=1&limit='+limit+URLcat_pwd+'&find='+document.getElementById('fndfld').value)\" value=\"Search\" /></h2></div>";
		//alert (txt);
		
		document.getElementById('nc_body_menu').innerHTML=txt;
		
	}
	
	if (premid>0)
	{
		premid=0;
		if (mode==1)
		{
			document.getElementById('nc_body_menu_body').innerHTML=txt;
			showMoviePage(0);
		}
		else
		{
			loadXMLMovieList("http://"+server+"/XMLMovieList.php?ch="+channel+URLcat+"&speed="+speed+"&start="+start+"&limit="+limit+"&FullInfo=1");
			//reload the movie list
			//document.getElementById('nc_body_movie').innerHTML=txt;
		}
		
	}
	else
	{
	//Draw the Movie List in to the sub_head
	txt="<div id=\"nc_body_menu_body_list\">";
	row="";
	x=XMLMovieList.documentElement.getElementsByTagName("Movie");
	for (i=0;i<x.length;i++)
	{
		
		if (row=="nc_body_menu_body_list_oddrow")
		{
			row="nc_body_menu_body_list_evenrow";
		}
		else
		{
			row="nc_body_menu_body_list_oddrow";
		}
		
		txt=txt+"<div id=\""+row+"\" onclick=\"showMoviePage('"+i+"')\">";

		try
		{
		txt=txt+"<img class=\"thumb\" src=\"" + x[i].getElementsByTagName("ThumbNail")[0].getAttribute("url") + "\">";
		}
  		catch (er)
		{
			txt=txt+"<img class=\"thumb\">";
		}
		
		try
		{
			txt=txt+"<h1 class=\"lrow\">"+x[i].getElementsByTagName("Title")[0].firstChild.nodeValue+"</h1>";
		}
  		catch (er)
		{
			txt=txt+"<H1 class=\"lrow\">Untitled</H1>";
		}
		
		try
		{
			txt=txt+"<h2 class=\"lrow\">"+x[i].getElementsByTagName("Heading")[0].firstChild.nodeValue+"</h2>";
		}
  		catch (er)
		{}
		
		try
		{
		txt=txt+"<h3 class=\"lrow\">"+x[i].getElementsByTagName("SubHeading")[0].firstChild.nodeValue+"</h3>";
		}
		catch (er)
		{}
  		
		try
		{
		txt=txt+"<p class=\"ldur\">Duration: "+x[i].getElementsByTagName("Duration")[0].firstChild.nodeValue+"</p>";
		}
		catch (er)
		{}
		
		try
		{
		//txt=txt+"<p class=\"lrow\">"+x[i].getElementsByTagName("Body")[0].firstChild.nodeValue+"</p>";
		txt=txt+"<p>"+return2br(x.getElementsByTagName("Body")[0].firstChild.nodeValue)+"</p>";
		}
		catch (er)
		{}
  		
		txt=txt+"</div>";
	}
	
	txt=txt+"</div>";
	
	//------------List Navigation-------------//
	x=XMLMovieList.documentElement.getElementsByTagName("Movies");
	txt=txt+"<div id=\"nc_body_menu_body_list_nav\">";
	LastStart=x[0].getAttribute("from");
	if (LastStart>1)
	{
		prev=Math.max(1,parseInt(x[0].getAttribute("from"))-limit);
		txt=txt+"<div id=\"nc_body_menu_body_list_nav_prv\" onclick=\"loadXMLMovieList('http://'+server+'/XMLMovieList.php?ch='+channel+URLcat+'&speed='+speed+'&start='+prev+'&limit='+limit+URLcat_pwd+'&find='+document.getElementById('fndfld').value)\"><H2>&lt;&lt; BACK</H2></div>";
	}
	else
	{
		txt=txt+"<div id=\"nc_body_menu_body_list_nav_prv\"><H2>&nbsp;</H2></div>";
	}
	
	if (parseInt(x[0].getAttribute("of"))>parseInt(x[0].getAttribute("to")))
	{
		start=parseInt(x[0].getAttribute("to"))+1;
		txt=txt+"<p>Movie " + x[0].getAttribute("from") + " to " + x[0].getAttribute("to") + " of " + x[0].getAttribute("of") + "</p><div id=\"nc_body_menu_body_list_nav_nxt\" onclick=\"loadXMLMovieList('http://'+server+'/XMLMovieList.php?ch='+channel+'&speed='+speed+'&start='+start+'&limit='+limit+URLcat+URLcat_pwd+'&find='+document.getElementById('fndfld').value)\"><H2>NEXT &gt;&gt;</H2></div></div>";
	}
	else
	{
		txt=txt+"<p>Movie " + x[0].getAttribute("from") + " to " + x[0].getAttribute("to") + " of " + x[0].getAttribute("of") + "</p><div id=\"nc_body_menu_body_list_nav_nxt\"><h2>&nbsp;</h2></div></div>";
	}
	//------------List Navigation-------------//
	
	document.getElementById('nc_body_menu_body').innerHTML=txt;
	}
}

function GoNCP()
{
	if (navigator.userAgent.match(/Android/i))
	{
		AndroidVideoStr="onclick=\"this.play();\"";
	}
	else
	{
		AndroidVideoStr="";
	}
	
	if (!mode)
	{
		mode=1;
	}
	
	if (!speed)
	{
		if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)))
		{
			speed=1;
		}
		else
		{
			speed=2;
		}
	}
	
	if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) || (navigator.userAgent.match(/Android/i)))
	{
		iphod=1;
		mode=1;
		if (speed>2)
		{
			speed=2;
		}
		MovieWidth=288;
		MovieHeight=182;
	}
	else
	{
		iphod=0;
	}
	
	setQuality(speed)
	
	if((!MovieWidth) || (!MovieHeight))
	{
		MovieWidth=288;
		MovieHeight=182;
	}
	
	if (!channel)
	{
		alert ("Missing required channel ID!");
	}
	
	if (!limit)
	{
		limit=4;
	}
	
	if (limit<1)
	{
		limit=1;
	}
	
	if (limit>40)
	{
		limit=40;
	}
	
	if (!autoplay)
	{
		autoplay="true";	
	}
	
	if (!server)
	{
		server=document.domain;
	}
	
	if (category>0)
	{
		URLcat=("&cat="+category);
	}
	
	if (premid>0)
	{
		loadXMLMovieList("http://"+server+"/XMLMovieInfo.php?ch="+channel+URLcat+"&mid="+premid+"&speed="+speed+"&start="+start+"&limit="+limit+"&FullInfo=1");
	}
	else
	{
		loadXMLMovieList("http://"+server+"/XMLMovieList.php?ch="+channel+URLcat+"&speed="+speed+"&start="+start+"&limit="+limit+"&FullInfo=1");
	}
}
