//onItemColor="#B7F385";
//normalItemColor="#DBF9BB";
//selectedItemColor="#DBF9BB";

maxChannelDisplay = 5;
onItemColor="#F0F0F0";
normalItemColor="#FFFFFF";
selectedItemColor="#DBF9BB";
itemSelected=0;
update=0;

if (window.XMLHttpRequest)
{	// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp=new XMLHttpRequest();
}
else
{	// code for IE6, IE5
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","xml/chlist.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML; 

function getParam()
{
	queryStr = window.location.search.substring(1);
	queryStrArray = queryStr.split("&");
 
	param1 = queryStrArray[0].split("=")[0];
	
	//param1 = queryStr.split("=")[0];
	
	
	if(param1 == "ch")
	{
		//chselected = queryStr.split("=")[1];
		chselected = queryStrArray[0].split("=")[1];
		//document.getElementById("channel"+chselected).bgColor =selectedItemColor;
		return chselected;
	}
	else if(param1=="update")
	{
		update = queryStrArray[0].split("=")[1];
	}
	return 0;
}
function getChannelName(id)
{
	return xmlDoc.getElementsByTagName("name")[id-1].childNodes[0].nodeValue;
}
function getChannelBitrate(id)
{
	return xmlDoc.getElementsByTagName("bitrate")[id-1].childNodes[0].nodeValue;
}
function getChannelViews(id)
{
	return xmlDoc.getElementsByTagName("views")[id-1].childNodes[0].nodeValue;
}
function getChannelAvailability(id)
{
	return xmlDoc.getElementsByTagName("availability")[id-1].childNodes[0].nodeValue;
}
function getChannelThumbnail(id)
{
	return xmlDoc.getElementsByTagName("thumbnail")[id-1].childNodes[0].nodeValue;
}
function getChannelPrivilege(id)
{
	return xmlDoc.getElementsByTagName("privilege")[id-1].childNodes[0].nodeValue;
}
function mouseOver(id)
{
	document.getElementById("channel"+id).style.backgroundColor =onItemColor;
}
function mouseOut(id)
{
	if(id==itemSelected)
	{
		document.getElementById("channel"+id).style.backgroundColor =selectedItemColor;
		return;
	}
	document.getElementById("channel"+id).style.backgroundColor =normalItemColor;
}
function mouseDown(id)
{
	if(itemSelected!=0)
	{
		document.getElementById("channel"+itemSelected).style.backgroundColor =normalItemColor;
	}
	itemSelected=id;
	document.getElementById("channel"+id).style.backgroundColor =selectedItemColor;
	window.location = "simp_i.html?ch="+id;
}
function showHeader()
{
	/*
	document.write("<table width =\"617\" height=\"30\" bgColor=#000000 cellpadding=\"0\" ><tr><td width =\"80%\" style=\"PADDING-LEFT: 5px;\" align=\"left\" ><font color=white size=\"3\" face=\"arial\"><b>");
	var playChannel=getParam();
	if(playChannel!=0)
		document.write(getChannelName(playChannel));

	document.write("</b></font></td><td  width =\"20%\"align=\"right\" NOWRAP style=\"PADDING-RIGHT: 5px;\" ><font color=white size=\"3\" face=\"arial\">");
	if(playChannel!=0)
		document.write(getChannelBitrate(playChannel));
	document.write("</font></td></tr> </table>");
	*/
	var playChannel=getParam();
	if(playChannel!=0){
		document.getElementById('channel_name').innerHTML=getChannelName(playChannel);
		document.getElementById('channel_bitrate').innerHTML=getChannelBitrate(playChannel);
	}
}
function showPlayer()
{
	document.write("<table id=\"browserPlayer\" width=\"100%\" height=\"100%\" border=0 cellpadding=\"0\" cellspacing=\"0\" ><tr><td>");
	showHeader();
	document.write("</td></tr><tr><td><object id=\"fsplayer\" width=\"800\" height=\"525\"  classid=clsid:2051A1D5-1825-4575-ABB7-C772B85E2DF7>");
	document.write("<iframe src=\"installp_i.html\" width=\"800\" height=\"525\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" ><p>Your browser does not support iframes.</p></iframe></object></td></tr></table>");
}
function truncate(txtText){
	txtLen=50;
	etc='...';
	break_words= false;
	middle=false;

    if (txtLen==0) return '';

    if (txtText.length>txtLen){
        txtLen-=Math.min(txtLen,etc.length);
        if (!break_words && !middle) {
            txtText=txtText.substr(0, txtLen+1).replace('/\s+?(\S+)?$/', '');
        }
        if(!middle) {
            return txtText.substr(0, txtLen) + etc;
        } else {
            return txtText.substr(0, txtLen/2) + etc + txtText.substr(-txtLen/2); 
        }
    } else {
        return txtText;
    }
}

function showChannels()
{
	x=xmlDoc.getElementsByTagName("channel");
	for(i=1;i<=x.length;i++){
		if(getChannelPrivilege(i)==0 && getChannelAvailability(i)==1)
		{
			chName=getChannelName(i);
			document.write(
			'<li id="channel'+i+'"  style="list-style-type:none;cursor:pointer" onMouseOver="mouseOver('+i+');" onMouseOut="mouseOut('+i+');" onMouseDown="mouseDown('+i+');">'+
			'<table><tr><td width="200" style="padding-left:5px;"><div title="'+chName+'"><font  face="Impact">'+truncate(chName)+'</font></div></td><td rowspan="3"><img src='+getChannelThumbnail(i)+' style="border:#bdb16e solid 2px;width:67;height:50;" /></td></tr>'+
			'<tr><td style="padding-left:5px;"><font size=2 color="#A0A0A0" face="arial">Bit-rate</font> <font size=2 color="#000" face="arial">'+getChannelBitrate(i)+'</font></td></tr>'+
			'<tr><td style="padding-left:5px;"></td></tr></table>'+ 
			'</li>');
		}
	}
	
}
