
/****************首页的所有js函数*********************************/
/*
*  片花、经典、手机电视、节目预告模块的点击函数
*/
function clickVideo(id,selectSortId)
{
	//获取该区域其他几个div层为隐藏，点击的div层为显示
	document.getElementById("week").style.display="none";
	document.getElementById("yugao").style.display="none";
	document.getElementById("1").style.display="none";
	document.getElementById("2").style.display="none";
	document.getElementById("3").style.display="none";
	//如果是节目预告层要同时显示星期层和内容层
	if(id=="yugao")
	{
		document.getElementById("week").style.display="block";
		document.getElementById("weekInfo").style.display="none";
	}else{
		document.getElementById("weekInfo").style.display="block";
	}
	document.getElementById(id).style.display="block";
	//将当前选中的层id赋值给隐藏表单域
	document.getElementById("type").value=id;
	document.getElementById("selectSort").value=selectSortId;  //当选中不同的类型时将频道隐藏表单域的值重置为1
	//document.getElementById("img1").style.display="block";
	//换图片
	document.getElementById("pianhuaImg").src="/images/images2/images/new_indexb_21.gif";
	document.getElementById("jingdianImg").src="/images/images2/images/new_index_23.gif";
	document.getElementById("dianshiImg").src="/images/images2/images/new_index_25.gif";
	document.getElementById("yugaoImg").src="/images/images2/images/new_index_27.gif";
	if(id=="1"){
		document.getElementById("pianhuaImg").src="/images/images2/images/new_index_21.gif";
	}else if(id=="3"){
		document.getElementById("jingdianImg").src="/images/images2/images/new_indexb_23.gif";
	}else if(id=="2"){
		document.getElementById("dianshiImg").src="/images/images2/images/new_indexb_25.gif";
	}else{
		document.getElementById("yugaoImg").src="/images/images2/images/new_indexb_27.gif";
	}
}

/*
*  产品与业务模块的点击函数
*/
function clickProduct(id)
{
	//alert(id);
	//获取该区域其他几个div层为隐藏，点击的div层为显示
	document.getElementById("cmmb").style.display="none";
	document.getElementById("sp").style.display="none";
	document.getElementById("activity").style.display="none";
	document.getElementById("guangbo").style.display="none";
	document.getElementById(id).style.display="block";
	//将当前选中的层id赋值给隐藏表单域
	document.getElementById("spType").value=id;
	//换图片
		document.getElementById("spPic").src="/images/images2/images/new_indexb_35.gif";
		document.getElementById("cmmbPic").src="/images/images2/images/new_index_37.gif";
		document.getElementById("activityPic").src="/images/images2/images/new_index_41.gif";
		document.getElementById("guangboPic").src="/images/images2/images/new_index_39.gif";
	if(id=="sp"){
		document.getElementById("spPic").src="/images/images2/images/new_index_35.gif";
	}else if(id=="cmmb"){
		document.getElementById("cmmbPic").src="/images/images2/images/new_indexb_37.gif";
	}else if(id=="activity"){
		document.getElementById("activityPic").src="/images/images2/images/new_indexb_41.gif";
	}else{
		document.getElementById("guangboPic").src="/images/images2/images/new_indexb_39.gif";
	}
}
/*
* 当点击视频（除预告）时，选中不同的频道显示出该频道该类型的视频列表 
*/
function changeSort(sortId)
{
	//获得当前的视频类型
	var type = document.getElementById("type").value;
	//给频道的隐藏表单域赋值
	document.getElementById("selectSort").value=sortId;
	//判断是否是手机电视
	if(type==2)
	{
		return;
	}
	//当点击预告并选中不同的频道时
	if(type=="yugao")
	{
		//获得当前的星期数
		var week=document.getElementById("selectWeek").value;
		var url="getParade.action?week="+week+"&sortId="+sortId;
		doPost(url,null,getParadeResponse);
	}else{
	var url="changeSortForType.action?videoType="+type+"&sortId="+sortId;
	//alert(url);
	doPost(url,null,response);
	}
	
}
/*
* 分页时取得下拉列表的页数值
*/
function pager(falg,content)
{
	//取得下拉列表的值
	var currPage = document.getElementById("selectPageNo").value;
	var url="";
	if(falg==1)
	{
		url="/news/newsListPage.action?currPage="+currPage+"&pageNo=-100";
	}else if(falg==2){
		url="/news/barFindNews.action?sortId=0&content="+content+"&currPage="+currPage+"&pageNo=-100";
	}
	window.location.href=url;
}
/*
* 手机电视二级页面下拉列表分页提交方法
*/
function pagerForMobiletv()
{
	//取得下拉列表的值
	var currPage = document.getElementById("selectPageNo").value;
	//alert(currPage);
	window.location.href="/video/mobileTV.action?currPage="+currPage+"&pageNo=-100";
}

/*
* 片花、经典二级页面下拉列表分页提交方法
*/
function pagerForPianhua()
{
	//取得下拉列表的值
	var currPage = document.getElementById("selectPageNo").value;
	//alert(currPage);
	window.location.href="/video/feature.action?&currPage="+currPage+"&pageNo=-100";
}

/*
* 视频搜索页面分页提交方法
*/
function pagerForFindVideo()
{
	//取得下拉列表的值
	var currPage = document.getElementById("selectPageNo").value;
	//alert(currPage);
	window.location.href="/video/feature.action?&currPage="+currPage+"&pageNo=-100";
}

/*
* 分页时取得下拉列表的页数值
*/
function pagerForProduct()
{
	//取得下拉列表的值
	var currPage = document.getElementById("selectPageNo").value;
	//alert(currPage);/product/secondProduct.action?type=1&currPage=0&pageNo=0&name=&model=&price=
	window.location.href="/product/secondProduct.action?currPage="+currPage+"&pageNo=-100";
}
/*
* 首页查看节目预告时点击不同星期
*/
function getParade(week)
{
	//从频道的隐藏表单域获得当前的频道编号
	var sortId=document.getElementById("selectSort").value;
	//给星期的隐藏表单域赋值为选中的星期数
	document.getElementById("selectWeek").value=week;
	//换星期的背景
	document.getElementById("week1").style.background="";
	document.getElementById("week2").style.background="";
	document.getElementById("week3").style.background="";
	document.getElementById("week4").style.background="";
	document.getElementById("week5").style.background="";
	document.getElementById("week6").style.background="";
	document.getElementById("week7").style.background="";
	document.getElementById("week"+week).style.background="url(/images/index_53b.gif) no-repeat";
	var url="getParade.action?week="+week+"&sortId="+sortId;
	//alert(url);
	doPost(url,null,getParadeResponse);
}
/**
*  页头或菜单的js函数
*/
function header(id)
{
	if(id=="firstPage")
	{
		document.getElementById(id).src="/images/index_09b.gif";
		document.getElementById('product').src="/images/index_10.gif";
		document.getElementById('bar').src="/images/index_11aa.gif";
		document.getElementById('service').src="/images/index_12.gif";
		//document.getElementById('kongjian').src="/images/index_13.gif";
		window.location.href="../firstPage.action";
	}else if(id=="product"){
		document.getElementById(id).src="/images/index_10b.gif";
		document.getElementById('firstPage').src="/images/index_09.gif";
		document.getElementById('bar').src="/images/index_11aa.gif";
		document.getElementById('service').src="/images/index_12.gif";
		//document.getElementById('kongjian').src="/images/index_13.gif";
		window.location.href="";
	}else if(id=="bar"){
		document.getElementById(id).src="/images/index_11b.gif";
		document.getElementById('product').src="/images/index_10.gif";
		document.getElementById('firstPage').src="/images/index_09.gif";
		document.getElementById('service').src="/images/index_12.gif";
		//document.getElementById('kongjian').src="/images/index_13.gif";
	}else if(id=="service"){
		document.getElementById('firstPage').src="/images/index_09.gif";
		document.getElementById('product').src="/images/index_10.gif";
		document.getElementById('bar').src="/images/index_11aa.gif";
		document.getElementById(id).src="/images/index_12b.gif";
		document.getElementById('kongjian').src="/images/index_13.gif";
		window.location.href="/static/service.jsp";
	}
}

/**
*  上载视频用户注册的提交函数
*/
function uploadRigester()
{
	var username=document.getElementById("username").value;
	var password=document.getElementById("password").value;
	if(username=="" || username==null || password=="" || password==null)
	{
		document.getElementById("info").value="用户名和密码不能为空！";
		//alert("用户名和密码不能为空！");
		return null;
	}
	var uploadUser=document.getElementById("uploadUser");
	var url="username="+username+"&password="+password;
	//alert(uploadUser.action);
	doPost(url,null,uploadLoginRes);
}

/**
*  上载视频用户登录的提交函数
*/
function uploadLogin()
{
	var username=document.getElementById("username").value;
	//encodeURIComponent(username);
	var password=document.getElementById("password").value;
	if(username=="" || username==null || password=="" || password==null)
	{
		document.getElementById("info").innerHTML="<font color='red'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用户名和密码不能为空！</font>";
		return null;
	}
	//window.location.href="/uploadLogin.action?username="+username+"&password="+password;
	var url="/uploadLogin.action?";
	var value="username="+username+"&password="+password;
	doPost(url,value,uploadLoginRes);
}
/**
*  搜索产品的提交函数
*/
function selectPro()
{
	//第一步：取得几个下拉列表的值
	var type=document.getElementById("type").value;
	var name=document.getElementById("name").value;
	var model=document.getElementById("model").value;
	var price=document.getElementById("price").value;
	//将品牌、型号编码转换
	encodeURIComponent(name);
	encodeURIComponent(model);
	var url="/product/secondProduct.action?type="+type+"&name="+name+"&model="+model+"&price="+price+
			"&currPage=0&pageNo=0";
	//提交之前将查询按钮禁用，以防反复点击影响效率
	//document.getElementById("proFind").style.disabled=false;
	//alert();
	window.location.href=url;
}
/**
*  首页站内搜索提交函数barSarchForPlay()
*/
function barSarch()
{
	//得到输入的值
	var content=document.getElementById("content").value;
	if(content.length<2)
	{
		document.getElementById("barFindInfo").innerHTML="<font color='red'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;内容长度不能小于2</font>";
		document.getElementById("content").focus();
		return;
	}else{
		document.getElementById("barFindInfo").innerHTML="";
		encodeURIComponent(content);
	}
	//取得搜索的类型
	var type=document.getElementById("select").value;
	if(type==1)
	{
		window.open("/video/barFindVideo.action?sortId=0&content="+content+"&pageNo=0&currPage=0");
	}else{
		window.open("/news/barFindNews.action?sortId=0&content="+content+"&pageNo=0&currPage=0");
	}
}
/**
*  播放页面搜索视频提交函数barSarchForPlay()
*/
function barSarchForPlay()
{
	//得到输入的值
	var content=document.getElementById("content").value;
	if(content.length<2)
	{
		document.getElementById("barFindInfo").innerHTML="<font color='red'>内容长度不能小于2</font>";
		document.getElementById("content").focus();
		return;
	}else{
		document.getElementById("barFindInfo").innerHTML="";
		encodeURIComponent(content);
	}
	window.open("/video/barFindVideo.action?sortId=0&content="+content+"&pageNo=0&currPage=0");
}

/*********************************************Ajax方法 *****************************************************/
var xmlHttp = null;

function createXMLHttp(){
	try{
		xmlHttp = new XMLHttpRequest();//非ie浏览器
	}catch(e){
		try{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//ie5
		}catch(e){
			try{
				xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");//ie6
			}catch(e){
				xmlHttp = null;
				alert("不支持异步的浏览器！");
			}
		}
	}
}

function doPost(url,value,responseM)
{
	//alert("doPost()");
    try
    {
        createXMLHttp();
        if(xmlHttp!=null)
        {
            xmlHttp.onreadystatechange=responseM;
            xmlHttp.open("POST",url,false);
            //http_request.setRequestHeader("Content-Length",value.length); 
            xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            xmlHttp.send(value);
        }
    }
    catch(e)
    {
        return false;
    }   
}

function response()
{
	//alert("处理函数");
	if(xmlHttp.readyState==4)
	{
		//alert("---"+xmlHttp.responseText+"---");
		var divType=document.getElementById("type").value;
		var divId=document.getElementById(divType);
		divId.innerHTML=xmlHttp.responseText;
		divId.style.display="block";
	}
}

function getParadeResponse()
{
	//alert("处理函数");
	if(xmlHttp.readyState==4)
	{
		//alert("---"+xmlHttp.responseText+"---");
		document.getElementById("yugao").innerHTML=xmlHttp.responseText;
	}
}

//上载用户登录的响应函数（未使用，登录成功后直接到上载页面，未使用ajax请求）
function uploadLoginRes()
{
	//alert("处理函数");
	if(xmlHttp.readyState==4)
	{
		//alert("---"+xmlHttp.responseText+"---");
		if(xmlHttp.responseText=="true") //如果登陆成功跳转到上载页面
		{
			window.open("/static/videoUpload.jsp");
		}else{  //失败则给出提示信息
			document.getElementById("info").innerHTML=xmlHttp.responseText;
		}
	}
}
