// JavaScript Document
// JavaScript Document
var xmlHttp;
var ffpath;
var nnn;

function getChannel(chanid)
{ 
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request");
    return;
  }

  var url="get_channel.php";
  url=url+"?chid="+chanid;
  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function getChannel3(chanid, tid)
{ 
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request");
    return;
  }

  var url="/lib/get_channel.php";
  url=url+"?chid="+chanid;
  if (chanid == "ETN1") 
  {
    url = url+"&tid="+tid;
  }
  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function getChannel2(chanid, tid)
{ 
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request");
    return;
  }

  var url="etnlib/get_channel2.php";
  url=url+"?chid="+chanid+"&tid="+tid;

  xmlHttp.onreadystatechange=stateChanged;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function stateChanged() 
{ 
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  { 
    var resStr = xmlHttp.responseText;
    var resArr = resStr.split(",");
	if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1 ) 
	{
		//document.getElementById("MediaPlayer").src=resArr[0];
		document.getElementById("MediaPlayer").url=resArr[0];
		document.getElementById("MediaPlayer").controls.play();
	}
	else
	{
		document.getElementById("MediaPlayer").url=resArr[0];
	}
    document.getElementById("ch_name").innerHTML=resArr[1];

  } 
}

function GetXmlHttpObject()
{
  var xmlHttp=null;
  try
  {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch (e)
  {
    //Internet Explorer
    try
    {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e)
    {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

var maxCategories = 6;
function divHideShow(divid) 
{
	var tempDiv = document.getElementById(divid);
	if (tempDiv.style.display == 'none')
	{
		tempDiv.style.display = 'block';
		mainLink.style.display = 'block';
	}
	else 
	{
		tempDiv.style.display = 'none';
	}
}

function linksHideShow(divid, nn, maxnum) 
{
    var mainLink = document.getElementById(divid+nn);
	var tempDiv;
    if (mainLink.style.display == 'block')
	{
		mainLink.style.display = 'none';
	}
	else
	{
		for (i=1; i <= maxnum; i++)
		{
			tempDiv = document.getElementById(divid+i);
			tempDiv.style.display = 'none';
		}
		mainLink.style.display = 'block';
		mainLink.style.display = 'block';
	}
}


var radioXml = "etnxml/radio.xml";
var xmlDoc;
var xmlCh;

function parseXML()
{
try //Internet Explorer
  {
  xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
  }
catch(e)
  {
  try //Firefox, Mozilla, Opera, etc.
    {
    xmlDoc=document.implementation.createDocument("","",null);
    }
  catch(e)
    {
    alert(e.message);
    return;
    }
  }
 xmlDoc.async=false;
 xmlDoc.load(radioXml);
 
}

<!--get elements -->
function showChannel(i) 
{
  chName = (xmlCh[i].getElementsByTagName("NAME")[0].childNodes[0].nodeValue);
  document.write("<a href='#' onClick='playChannel("+i+");'>"+chName+"</a><br/>");
}


function playChannel(i) 
{
  chName = (xmlCh[i].getElementsByTagName("NAME")[0].childNodes[0].nodeValue);
  chUrl = (xmlCh[i].getElementsByTagName("URL")[0].childNodes[0].nodeValue);
  chDesc = (xmlCh[i].getElementsByTagName("DESCR")[0].childNodes[0].nodeValue);
  txt = "<b>" + chName + "</b><br/>" + chDesc + "<br/>";
  document.getElementById('RDESC').innerHTML = txt;
  if (navigator.userAgent.toLowerCase().indexOf("firefox") != -1 ) 
  {
	  document.getElementById('FRADIO').src =chUrl;
 	  document.getElementById('FRADIO').src =chUrl;
  }
  else
  {
	  document.getElementById("RADIO").pause();
	  document.getElementById('RADIO').FileName =chUrl;
	  document.getElementById('RADIO').play();
  }
}


function isChanLive(i, chLang)
{
  var xs = xmlCh[i].getElementsByTagName("SCHED");

   var sType = xs[0].getAttribute("type");
   var sTime;
   var eTime;
   var myLang = (xmlCh[i].getElementsByTagName("LANG")[0].childNodes[0].nodeValue);
   if (chLang != myLang) 
   {
      return false;
    }

   if (sType == "A") 
   {
     return true;
   }
   if (sType == "D")
   {
     sTime = xs[0].getElementsByTagName("DAILY")[0].getAttribute("start");
	 eTime = xs[0].getElementsByTagName("DAILY")[0].getAttribute("end");
	 if (todSrv > sTime && todSrv < eTime) 
	 {
	    return true;
     }
   }

   if (sType == "W")
   {
     var xt = xs[0].getElementsByTagName(dowSrv);
     if (xt.length == 0) 
     {
        return false;
     }
     sTime = xt[0].getAttribute("start");
     eTime = xt[0].getAttribute("end");
      if (todSrv > sTime && todSrv < eTime) 
     {
	    return true;
     }
   }

   return false;
}

function openWebSite(url)
{
	window.open(url, "etn_links", "location=0, menubar=0, toolbar=0, resizable=1, scrollbars=1");
}

function getDirList(fpath, nn)
{ 
  nnn = nn;
  ffpath = fpath;
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request");
    return;
  }

  var url="dir_list.php";
  if (fpath != "") {
	  url=url+"?fpth="+fpath;
  }
  xmlHttp.onreadystatechange=stateChangedFile;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function getDirList2(ch, fpath, nn)
{ 
  nnn = nn;
  ffpath = fpath;
  xmlHttp=GetXmlHttpObject();
  if (xmlHttp==null)
  {
    alert ("Browser does not support HTTP Request");
    return;
  }

  var url="dir_list2.php?ch="+ch;
  if (fpath != "") {
	  url=url+"&fpth="+fpath;
  }
  xmlHttp.onreadystatechange=stateChangedFile;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function callGetDirList(fpath, nn)
{
	var vsId = "vsel"+nn;
	var nfpath = unescape(fpath) + "\\" + document.getElementById(vsId).value;
	getDirList(nfpath, nn);
}

function deleteVFile(nn)
{
	var eId = 'vfile'+nn;
	document.getElementById(eId).value = "";
      eId = 'vdur'+nn;
	document.getElementById(eId).value = "";
	eId = 'vselc'+nn;
	document.getElementById(eId).innerHTML = "";
}

function stateChangedFile() 
{ 
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
  { 
	var pStr = '';
	var respStr = xmlHttp.responseText;
	var respArr = new Array();
	var entryArr = new Array();
	var eId;
	var selStr = ffpath + "\\ : " +
	             "<select id='vsel"+nnn+"' onChange=\"callGetDirList('"+ escape(ffpath) + "','" + nnn + "');\">\n"+
				 "  <option> --Selec a videdo--</option>\n";
    if (respStr.match('qqqqqq'))
	{
        respArr = respStr.split(',');
		eId = 'vfile'+nnn;
		document.getElementById(eId).value = ffpath;
		eId = 'vdur'+nnn;
		document.getElementById(eId).value = respArr[1];
		eId = 'vselc'+nnn;
		//document.getElementById(eId).innerHTML = "";
		var vstr = ffpath.replace(/.\\/, "/");
		document.getElementById(eId).innerHTML = "<a href='mms://www.ouretn.net/etn_vod" + vstr.replace(/\\/g, "/") + "?tid=" + vtid + "'>Play</a>";
	}
	else
	{
		respArr = respStr.split('*');
		for (i=0; i<respArr.length; i++)
		{
			rStr = respArr[i];
			entryArr = rStr.split(':');
			selStr = selStr + "  <option value=\""+entryArr[0]+"\">"+entryArr[0]+"</optoin>\n";
  		} 
		selStr = selStr + "</select>\n";
		eId = 'vselc'+nnn;
		document.getElementById(eId).innerHTML = selStr;
	}
  }
}


function muteUnmute(pid, imgid) {
  pobj = document.getElementById(pid);
  iobj = document.getElementById(imgid);
  if (pobj.settings.mute) {
     pobj.settings.mute = false;
     iobj.src = 'etnimage/mutes.png';
  } 
  else {
     pobj.settings.mute = true;
     iobj.src = 'etnimage/unmutes.png';
  }
}
