﻿/********************************************
定义string缓冲区结构            
********************************************/
function str_Buf(){
	this.strs = new Array;		
}

str_Buf.prototype.append = function (str) {
	this.strs.push(str);
};

str_Buf.prototype.toString = function (str) {
	var result = this.strs.join("");
	return result;
};

/********************************************
用于将xml对象转化为BOM对象 视频列表
********************************************/
function showvideoinfo(v_objs, ilen, id)
{
	//确定显示数据层次
	var irow,icol;
	if(ilen > 24) ilen = 24;
	if(ilen >= 4)
	{
		irow = parseInt(ilen/4);	
	}
	else
	{
		irow = 0;
	}
	icol = ilen % 4;
	
	
	//设置表格属性
	var odiv1 = document.getElementById(id);
	var oTab1 =  document.createElement("table");
	oTab1.height = 100;
	odiv1.appendChild(oTab1);
	
	var oTbody1 = document.createElement("tbody");
	oTab1.appendChild(oTbody1);
	for(var i = 0; i <= irow; i++)
	{
		var oTr1 = document.createElement("tr");
		oTbody1.appendChild(oTr1);


		//确定td数目
		var inum;
		if(i == irow)
		{
			inum = icol;
		}
		else
		{
			inum = 4;	
		}
		
		
		for(var j = 0; j < inum; j++)
		{
			var oTd1 = document.createElement("td");
			var strBuf = new	str_Buf();
			strBuf.append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
			strBuf.append("<tr>");
			
			//填充行间空隙
			if(j == 0)
			{
			 	strBuf.append("<td align=\"left\">&nbsp;&nbsp;");	
			}
			else
			{
				strBuf.append("<td align=\"left\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");	
			}	
			
			
			//加载图片和连接
			strBuf.append("<a href=\"http://video.qq.com/videopl.htm?v=");
			strBuf.append(v_objs[i*4 + j].vid);
			strBuf.append("\" target=\"_blank\">");
			strBuf.append("<img width=\"100\" border=\"0\" height=\"75\" src=\"http://p.video.qq.com/1/");
			strBuf.append(v_objs[i*4 + j].vid);
			strBuf.append("_1.jpg \" /> </a> </td>");
			strBuf.append("</tr>");
			
			//加载作者 
			strBuf.append("<tr>");
			strBuf.append("<td><ul>");
			strBuf.append("<li>");
			strBuf.append(v_objs[i*4 + j].author);
			strBuf.append("</li>");
			strBuf.append("<li>视频助威</li>");
			
			//加载票数
			strBuf.append("<li>");
			strBuf.append(v_objs[i*4 + j].vote);
			strBuf.append("票</li>");
			
			strBuf.append("</ul> </td>");
			strBuf.append("</tr>");
			strBuf.append("<tr>");
			strBuf.append("<td><div align=\"center\">&nbsp;&nbsp;");
			strBuf.append("</div></td>");
			strBuf.append("</tr>");
			strBuf.append("</table>");
			oTd1.innerHTML = strBuf.toString();  
			oTr1.appendChild(oTd1);
		}
	}
}



/********************************************
用于将xml对象转化为BOM对象 视频列表
********************************************/
function showworkerinfo(v_objs, ilen, id)
{
	//确定显示数据层次
	var irow,icol;
	if(ilen > 24) ilen = 24;
	if(ilen >= 4)
	{
		irow = parseInt(ilen/4);	
	}
	else
	{
		irow = 0;
	}
	icol = ilen % 4;
	
	
	//设置表格属性
	var odiv1 = document.getElementById(id);
	var oTab1 =  document.createElement("table");
	oTab1.height = 100;
	odiv1.appendChild(oTab1);
	
	var oTbody1 = document.createElement("tbody");
	oTab1.appendChild(oTbody1);
	for(var i = 0; i <= irow; i++)
	{
		var oTr1 = document.createElement("tr");
		oTbody1.appendChild(oTr1);


		//确定td数目
		var inum;
		if(i == irow)
		{
			inum = icol;
		}
		else
		{
			inum = 4;	
		}
		
		
		for(var j = 0; j < inum; j++)
		{
			var oTd1 = document.createElement("td");
			var strBuf = new	str_Buf();
			strBuf.append("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">");
			strBuf.append("<tr>");
			
			//填充行间空隙
			if(j == 0)
			{
			 	strBuf.append("<td align=\"left\">&nbsp;&nbsp;");	
			}
			else
			{
				strBuf.append("<td align=\"left\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");	
			}	
			
			
			//加载图片和连接
			strBuf.append("<a href=\"http://video.qq.com/videopl.htm?v=");
			strBuf.append(v_objs[i*4 + j].vid);
			strBuf.append("\" target=\"_blank\">");
			strBuf.append("<img width=\"100\" border=\"0\" height=\"75\" src=\"http://p.video.qq.com/1/");
			strBuf.append(v_objs[i*4 + j].vid);
			strBuf.append("_1.jpg \" /> </a> </td>");
			strBuf.append("</tr>");
			
			//加载作者 
			strBuf.append("<tr>");
			strBuf.append("<td><ul>");
			strBuf.append("<li>");
			strBuf.append(v_objs[i*4 + j].author);
			strBuf.append("</li>");
			strBuf.append("<li>视频助威</li>");
			
			//加载票数
			strBuf.append("<li>");
			strBuf.append(v_objs[i*4 + j].vote);
			strBuf.append("票</li>");
			
			strBuf.append("</ul> </td>");
			strBuf.append("</tr>");
			strBuf.append("<tr>");
			strBuf.append("<td><div align=\"center\">&nbsp;&nbsp;");
			strBuf.append("</td></tr>");
			strBuf.append("</table>");
			oTd1.innerHTML = strBuf.toString();  
			oTr1.appendChild(oTd1);
		}
	}
}


/********************************************
用于将xml对象转化为BOM对象 排行榜
********************************************/
function showrankinfo(v_objs, ilen, id)
{
	//确定显示数据层次
	if(ilen > 10) ilen = 10;
	
	//设置表格属性
	var odiv1 = document.getElementById(id);	
	var oTab1 =  document.createElement("table");
	oTab1.className="tab0";
	odiv1.appendChild(oTab1);
	
	var oTbody1 = document.createElement("tbody");
	oTab1.appendChild(oTbody1);
		
	for(var i = 0; i < ilen; i++)
	{
		var oTr1 = document.createElement("tr");
		oTbody1.appendChild(oTr1);

		var oTd1 = document.createElement("td");
		var strBuf = new	str_Buf();
		strBuf.append("<td width=\"35\" align=\"left\"><span align=\"center\">&nbsp&nbsp");
		strBuf.append(i+1);
		strBuf.append("</span></td>");
		
		//填充数字空隙
		if(i == 9)
		{
			strBuf.append("<td width=\"162\"><span align=\"left\">&nbsp;");	
		}
		else
		{
			strBuf.append("<td width=\"162\"><span align=\"left\">&nbsp;&nbsp");	
		}
		
		strBuf.append("<a href=\"http://video.qq.com/videopl.htm?v=");
		strBuf.append(v_objs[i].vid);
		strBuf.append("\" target=\"_blank\" class=\"zt3\">");
		strBuf.append(v_objs[i].author);
		strBuf.append("</a></span></td>");
	
		oTd1.innerHTML = strBuf.toString();  
		oTr1.appendChild(oTd1);	
	}
}

/********************************************
定义video显示信息结构       
********************************************/
function v_obj(vid, vname, qq, author, time, vote)
{
	this.vid = vid;
	this.vname = vname;
	this.qq = qq;
	this.author = author;
	this.time = time;
	this.vote = vote;
}

/********************************************
将xml文件解析成xml对象       
********************************************/
function xml2obj(xml, id, t)
{
	//定义nodes内部结构部分 取出相应节点 并进行判断
	var nodes,qq,vid,vname,author,time,vote; 
	nodes = xml.selectNodes("//root/vl/vi");
 	if(!nodes) return;
	if(nodes.length == 0) return;
	
	//初始化video信息部分
	var v_objs = new Array(nodes.length);
	
	//将信息传入
	for(var i =0; i< nodes.length; i++)
  {
  	node 	 		= nodes.nextNode();
  	vid 	 		= g_vs.getValue(node,"i");
  	vname  		= g_vs.getValue(node,"n");
  	qq 		 		= g_vs.getValue(node,"u");
  	author 		= g_vs.getValue(node,"a");
  	time   		= g_vs.getValue(node,"t");
  	vote   		= g_vs.getValue(node,"o");
  	
 		v_objs[i] = new v_obj(vid, vname, qq, author, time, vote);
  }
  
  if(t == 0)
 	{
 		showvideoinfo(v_objs, nodes.length, id);	
 	}
 	if(t == 1)
  {
  	showrankinfo(v_objs, nodes.length, id);
  }
  if(t == 2)
  {
  	showworkerinfo(v_objs, nodes.length, id);
  }
}

/********************************************
用于处理首页面显示的对象
********************************************/
function onshowworker(xml, id)
{	
	//首页只处理8个的情况
	if(!xml) return;
	
	//获取元素个数
	var ntNode,ntValue;
	ntNode = xml.selectSingleNode("//root");
	ntValue = g_vs.getValue(ntNode,"nt");
	if(ntValue == 0) return;
	
		//根据返回值修改元素状态
	var iallpage = 0;
	var odiv1 	 =  document.getElementById("s_allpage");
	var otext1 	 =  document.getElementById("curr_page");
	var ohid1  	 =  document.getElementById("allnum");
	var ohid2  	 =  document.getElementById("allpage");

	
	if(ntValue == 0) 
	{
		iallpage = 0;
		odiv1.innerHTML = "[共" + 0 + "页]";
		ohid1.value  = 0;
		ohid2.value  = 1;
		otext1.value = 1;
	}
	else
	{
		iallpage = parseInt(ntValue/24);
		if(ntValue % 24 != 0)
		{
			iallpage += 1;
		}
		
		odiv1.innerHTML = "[共" + iallpage + "页]";
		ohid1.value = ntValue;
		ohid2.value = iallpage;
		
		if(parseInt(otext1.value) > iallpage)
		{
			otext1.value = iallpage;
		}
	}

	
	
	if(ntValue == 0) return;	
	xml2obj(xml, id, 2);
}

/********************************************
用于处理首页面显示的对象
********************************************/
function onshowrank(xml, id)
{	
	//首页只处理8个的情况
	if(!xml) return;
	
	//获取元素个数
	var ntNode,ntValue;
	ntNode = xml.selectSingleNode("//root");
	ntValue = g_vs.getValue(ntNode,"nt");
	if(ntValue == 0) return;
	
	xml2obj(xml, id, 1);
}

//处理页面类型
/********************************************
用于处理首页面显示的对象
********************************************/
function onshowindex(xml, id)
{
	/*
	var ntNode,ntValue;
	ntNode = xml.selectSingleNode("//root");
	ntValue = g_vs.getValue(ntNode,"nt");
	alert(ntValue);
	*/
	
	//首页只处理8个的情况
	if(!xml) return;
	
	//获取元素个数
	var ntNode,ntValue;
	ntNode = xml.selectSingleNode("//root");
	ntValue = g_vs.getValue(ntNode,"nt");
	if(ntValue == 0) return;
	
	xml2obj(xml, id, 0);
}


/********************************************
用于处理首页面显示的对象
********************************************/
function onshowmore(xml, id)
{
	//检查xml是否为空
	if(!xml) return;

	
	//获取元素个数
	var ntNode,ntValue;
	ntNode = xml.selectSingleNode("//root");
	ntValue = g_vs.getValue(ntNode,"nt");
	
	//根据返回值修改元素状态
	var iallpage = 0;
	var odiv1 	 =  document.getElementById("s_allpage");
	var otext1 	 =  document.getElementById("curr_page");
	var ohid1  	 =  document.getElementById("allnum");
	var ohid2  	 =  document.getElementById("allpage");

	
	if(ntValue == 0) 
	{
		iallpage = 0;
		odiv1.innerHTML = "[共" + 0 + "页]";
		ohid1.value  = 0;
		ohid2.value  = 1;
		otext1.value = 1;
	}
	else
	{
		iallpage = parseInt(ntValue/24);
		if(ntValue % 24 != 0)
		{
			iallpage += 1;
		}
		
		odiv1.innerHTML = "[共" + iallpage + "页]";
		ohid1.value = ntValue;
		ohid2.value = iallpage;
		
		if(parseInt(otext1.value) > iallpage)
		{
			otext1.value = iallpage;
		}
	
	}

	if(ntValue == 0) return;
	xml2obj(xml, id, 0);
}


/********************************************
js调用video cgi 获取视频节目相应信息              
********************************************/
function callvideo(w,c,s,e,id)
{	
	var strBuf = new str_Buf();
	strBuf.append("c=");  
	strBuf.append(c);
	strBuf.append("&s=");  
	strBuf.append(s);
	strBuf.append("&e=");  
	strBuf.append(e);
	
	//首页面状态
	if(w == 0)
	{	
		var flag = g_vs.sendRequest("http://mcd.qq.com/cgi-bin/mcd_GetXml", "post", strBuf.toString(), onshowindex, id, "", "", true);
	}
	//更多页面状态
	if(w == 1)
	{
		var flag = g_vs.sendRequest("http://mcd.qq.com/cgi-bin/mcd_GetXml", "post", strBuf.toString(), onshowmore, id, "", "", true);
	}
	//显示排行榜
	if(w == 2)
	{
		var flag = g_vs.sendRequest("http://mcd.qq.com/cgi-bin/mcd_GetXml", "post", strBuf.toString(), onshowrank, id, "", "", true);
	}
	
	//显示麦当老员工
	if(w == 3)
	{
		var flag = g_vs.sendRequest("http://mcd.qq.com/cgi-bin/mcd_GetXml", "post", strBuf.toString(), onshowworker, id, "", "", true);
	}
}

/********************************************************* 
### 函数名  : playv()
### 功能    : 从URL中读取类似CGI参数值
### 入参    : 变量名
### 出参    : 变量值
### 作者    : mokymo 
### 修改日期: 2004.11.08
*********************************************************/
function playMovie(v)
{
	var oTd1 =document.getElementById("mcdMovie");
	var strBuf = new	str_Buf();
	strBuf.append("<object id=\"flashplayer\" name=\"flashplayer\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"180\" height=\"155\">");
	strBuf.append("<param name=\"movie\" value=\"http://video.qq.com/res/qqplayerout.swf?v=");
	strBuf.append(v);
	strBuf.append("\"/> <param name=\"allowFullScreen\" value=\"true\" />");
	strBuf.append("<param name=\"flashvars\" value=\"autoReplay=true&autoStart=true&vid=");
	strBuf.append(v);
	strBuf.append("&cgi=http%3A//video.qq.com/bin/vrank%3Ftype%3D8%26start%3D39%26end%3D46\">");
	strBuf.append("<embed type=\"application/x-shockwave-flash\" src=\"http://video.qq.com/res/qqplayerout.swf?v=");
	strBuf.append(v);
	strBuf.append("\" width=\"283\" height=\"180\" id=\"flashplayer\" name=\"flashplayer\" quality=\"high\""); 
	strBuf.append("allowScriptAccess=\"sameDomain\" allowFullScreen=\"true\" flashvars=\"vid= "); 
	strBuf.append(v);
	strBuf.append("&cgi=http%3A//video.qq.com/bin/vrank%3Ftype%3D8%26start%3D39%26end%3D46\">");
	strBuf.append("</embed></object>");
	oTd1.innerHTML = strBuf.toString();
}


/********************************************************* 
### 函数名  : playv()
### 功能    : 从URL中读取类似CGI参数值
### 入参    : 变量名
### 出参    : 变量值
### 作者    : mokymo 
### 修改日期: 2004.11.08
*********************************************************/
function playStarMovie(v, autoReplay, iwidth, iheight)
{
	var strBuf = new	str_Buf();
	strBuf.append("<object id=\"flashplayer\" name=\"flashplayer\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"" + iwidth + "\" height=\"" + iheight + "\">");
	strBuf.append("<param name=\"movie\" value=\"http://video.qq.com/res/qqplayerout.swf?v=");
	strBuf.append(v);
	strBuf.append("\"/> <param name=\"allowFullScreen\" value=\"true\" />");
	strBuf.append("<param name=\"flashvars\" value=\"autoReplay=true&autoStart=");
	strBuf.append(autoReplay);
	strBuf.append("&vid=");
	strBuf.append(v);
	strBuf.append("&cgi=http%3A//video.qq.com/bin/vrank%3Ftype%3D8%26start%3D39%26end%3D46\">");
	strBuf.append("<embed type=\"application/x-shockwave-flash\" src=\"http://video.qq.com/res/qqplayerout.swf?v=");
	strBuf.append(v);
	strBuf.append("\" width=\""+ iwidth +"\" height=\"" +  iheight + "\" id=\"flashplayer\" name=\"flashplayer\" quality=\"high\""); 
	strBuf.append("allowScriptAccess=\"sameDomain\" allowFullScreen=\"true\" flashvars=\"vid= "); 
	strBuf.append(v);
	strBuf.append("&cgi=http%3A//video.qq.com/bin/vrank%3Ftype%3D8%26start%3D39%26end%3D46\">");
	strBuf.append("</embed></object>");
	document.writeln(strBuf.toString());
}

/********************************************************* 
### 函数名  : playv()
### 功能    : 从URL中读取类似CGI参数值
### 入参    : 变量名
### 出参    : 变量值
### 作者    : mokymo 
### 修改日期: 2004.11.08
*********************************************************/
function changeStarMovie(v, iwidth, iheight)
{
	var oTd1 =document.getElementById("mcdStarMovie");
	var strBuf = new	str_Buf();
	strBuf.append("<object id=\"flashplayer\" name=\"flashplayer\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" width=\"" + iwidth + "\" height=\"" + iheight + "\">");
	strBuf.append("<param name=\"movie\" value=\"http://video.qq.com/res/qqplayerout.swf?v=");
	strBuf.append(v);
	strBuf.append("\"/> <param name=\"allowFullScreen\" value=\"true\" />");
	strBuf.append("<param name=\"flashvars\" value=\"autoReplay=true&autoStart=true&vid=");
	strBuf.append(v);
	strBuf.append("&cgi=http%3A//video.qq.com/bin/vrank%3Ftype%3D8%26start%3D39%26end%3D46\">");
	strBuf.append("<embed type=\"application/x-shockwave-flash\" src=\"http://video.qq.com/res/qqplayerout.swf?v=");
	strBuf.append(v);
	strBuf.append("\" width=\""+ iwidth +"\" height=\"" +  iheight + "\" id=\"flashplayer\" name=\"flashplayer\" quality=\"high\""); 
	strBuf.append("allowScriptAccess=\"sameDomain\" allowFullScreen=\"true\" flashvars=\"vid= "); 
	strBuf.append(v);
	strBuf.append("&cgi=http%3A//video.qq.com/bin/vrank%3Ftype%3D8%26start%3D39%26end%3D46\">");
	strBuf.append("</embed></object>");
	oTd1.innerHTML = strBuf.toString();
}