

//for topnav.html
function indexlocation(){
	document.location.href='./index.jsp';
}
function catreslocation(){
	document.location.href='./resSerAction.do?method=getCatResListHp&catid=16';
}
function ucantheaterlocation(){
	document.location.href='./index.jsp';
}
function downlocation(){
	document.location.href='./download.jsp';
}
function helplocation(){
	document.location.href='./help.jsp';
}
function searchresinputFocus(){
	if($('searchres').value == 'search'){
		$('searchres').value = '';
	}
	$('searchres').style.background = '#CCFFCC';
	$('searchres').style.color = '#003366';
}
function searchresinputBlur(){
	if($('searchres').value == ''){
		$('searchres').value = 'search';
	}
	$('searchres').style.background = '#FFF';
	$('searchres').style.color = '#aaa';
}


//for catres refresh
function catresRefresh(startIndex,totalCount,catid){
	url = './resSerAction.do?method=getCatResMoreHp&catid='+catid+'&startIndex='+startIndex+'&totalCount='+totalCount;
	//alert(url);
	document.location.href=url;
}


//for searchres
function searchres(){

	var key = $('searchres').value;

	
   var s='',ss,sss;

   ss = key.split("'");
   for(i=0;i<ss.length;i++){
	   s+=ss[i];

   }

   key=s;
   sss = key.split(" ");
   if(sss.length-1==key.length){
	   return;
   }


	if(key == '' || key == 'search'){
		$('searchres').value='';
		return;
	}

	url='./resSerAction.do?method=getSearchResHp&key='+encodeURIComponent(key);
	document.location.href=url;
}
function searchresRefresh(startIndex,totalCount,key){
	url = './resSerAction.do?method=getSearchResHp&key='+encodeURIComponent(key)+'&startIndex='+startIndex+'&totalCount='+totalCount;
	//alert(url);
	document.location.href=url;
}
function searchResKeyDown(){
    if (event.keyCode == 13){
        event.returnValue=false;
        event.cancel = true;
        searchres();
    }
}

function onSelectInput(){
	var src = event.srcElement;

	if (src.type == "text")
	{
		//if (p_selectedElement)
		//{
		//	p_selectedElement.style.background = p_defaultBackColor;
		//}
		src.style.background = "#FFFFCC";
		p_selectedElement = src;
	}
}

//一个div下所有的input 全选或全不选
function divcheckall(divname,ischecked){
	var objs=$(divname).getElementsByTagName("INPUT");
	for(var i=0;i<objs.length;i++){
		if(objs[i].type=='checkbox'){
			if(ischecked == 'true'){
				objs[i].checked = true;
			}else{
				objs[i].checked = false;
			}
		}
	}
}

//切换resdetail.jsp页面上下载按钮时令背景图片发生变化
function changepic(status){
	var button = $('downbutton');
	if(status == 'out'){
		button.src = 'images/xz1.gif';
	}else if(status == 'over'){
		document.getElementById("ftpradio").checked=false;
		document.getElementById("downradio").checked=true;
		document.getElementById("resdetaildownload").style.cssText=".resdetaildownload{width:95%;height:28%;margin:5px;border-bottom:1px dotted #000;display:inline}";
		document.getElementById('ftpresdetaildownload').style.display ="none";
		button.src = 'images/xz2.gif';
	}
}


function ftpchangepic(status){
	var button = $('ftpdownbutton');
	if(status == 'out'){
		button.src = 'images/speeddown1.gif';
	}else if(status == 'over'){
		document.getElementById("ftpradio").checked=true;
		document.getElementById("downradio").checked=false;
		document.getElementById('resdetaildownload').style.display ="none";
		document.getElementById("ftpresdetaildownload").style.cssText=".resdetaildownload{width:95%;height:28%;margin:5px;border-bottom:1px dotted #000;display:inline}";
		button.src = 'images/speeddown2.gif';
	}
}
//鼠标经过img元素时改变引用图片(mouseover,mouseout事件)
function changeBkPicByDd(id,image){
	var img = $(id);
	img.src = image;
}

var loginStatus='T';
//for user
function chklogin(){

	var userid = $('userid');
	var pwd = $('pwd');
	
	var div = $('div_null');
	var div_error = $('div_error');

    if(userid.value.indexOf("'")>=0){
		alert("用户名输入有误!");
		userid.focus();
		return 
	}

	if(userid.value == '' || pwd.value == ''){
		//	
			div.style.display = "inline";
		    div_error.style.display = "none";

		//alert("用户名和密码不能为空!");
	 		return;	
	 }
    
	var url = './userSerAction.do?';
	var pars = 'method=login&userid='+encodeURIComponent(userid.value)+'&pwd='+encodeURIComponent(pwd.value);


	new Ajax.Request(url,{method:'post',parameters:pars,onComplete :login});

	
}
//ajax call_back function
function login(transport){	

	var status_longin = $('status');

	var userid = $('userid');
	var pwd = $('pwd');
	var status=0;
	var arr=transport.responseText.split(";"); 
	status=parseInt(arr[0]);
	var msg=arr[1]; 
	
	//status=parseInt(transport.responseText);
	if(status==0){	
		userid.value = '';
		pwd.value ='';
		var div_null = $('div_null');
	    var div_error = $('div_error');
		div_error.style.display = "inline";
		div_null.style.display = "none";
		//alert("用户名和密码不正确!");
	}
	if(status==1){
		var str =' <INPUT TYPE="HIDDEN" id="status" type="text" value="1" /> <table width="146" border="0" cellspacing="0" cellpadding="0">';
        str +='<tr>';
		str +='<td></td';
        str +='</tr>';
        str +='<tr>';
        str +='<td colspan="2" align="center">&nbsp;</td>';
        str +=' </tr>';
        str +='<tr>';
        str +='<td height="22" colspan="2" align="left" class="zi">'+msg+' 您好：</td>';
        str +='</tr>';
		str +='<tr>';
        str +='<td colspan="2" class="zi" align="left">欢迎来到惠普优看高清电视剧场</td>';
        str +='</tr>';
		str +='<tr>';
        str +=' <td colspan="2" align="left">&nbsp;</td>';
        str +='</tr>';
        str +='<tr>';
        str +=' <td height="42" align="center"><img src="images/yhdl-xgzl.gif" width="69" height="22" style="CURSOR: pointer" onclick="JavaScript:userudate()"/>&nbsp;&nbsp;<img src="images/exit-button.gif" width="69" height="22" style="CURSOR: pointer" onclick="JavaScript:exitUser()"/></td>';
        str +='<td align="right"></td>';
        str +='</tr>';
        str +='</table>';

		loginInput($('login'),str);
	//	var d = $('login');
 	//	d.style.display ="none";
	//	var div_update = $('div_update');
 	//	div_update.style.display ="inline";
	}
	if(status==2)
	{
		var str =' <INPUT TYPE="HIDDEN" id="status" type="text" value="1" /> <table width="146" border="0" cellspacing="0" cellpadding="0">';
        str +='<tr>';
		str +='<td></td';
        str +='</tr>';
        str +='<tr>';
        str +='<td colspan="2" align="center">&nbsp;</td>';
        str +=' </tr>';
		str +='<tr>';
        str +='<td colspan="2" class="zi" align="left">欢迎来到惠普优看高清电视剧场,您还可以注册成为优看会员 </td>';
        str +='</tr>';
		str +='<tr>';
        str +=' <td colspan="2" align="left">&nbsp;</td>';
        str +='</tr>';
        str +='<tr>';
        str +=' <td height="42" align="center"><img src="images/yhdl-zc.gif" width="69" height="22" style="CURSOR: pointer" onclick="JavaScript:register()"/>&nbsp;&nbsp;<img src="images/exit-button.gif" width="69" height="22" style="CURSOR: pointer" onclick="JavaScript:exitUser()"/></td>';
        str +='<td align="right"></td>';
        str +='</tr>';
        str +='</table>';
		loginInput($('login'),str);
	}

	if(status==1||status==2){
		setCookie("HP_UCANTV_NAME",userid.value,30);
		setCookie("HP_UCANTV_PWD",pwd.value,30);
	}
}


function loginInput(t, c)
{
	t.innerHTML = c
}

function register(){
	document.location.href='./zcxx.jsp'
}
function findPwd(){
	document.location.href='./zhmm.jsp'
}

function userudate(){

		url='./userSerAction.do?method=searchUser';
		document.location.href=url;

}

function userupdate(){
	var status=document.getElementById('status').value;
	if(status=="2"){
		alert("你还没有注册!");
		return;
	}else{
		url='./userSerAction.do?method=searchUser';
		document.location.href=url;
	}
}




function exitUser(){

	delCookie("HP_UCANTV_NAME");
	delCookie("HP_UCANTV_PWD");	
	url='./userSerAction.do?method=exitUser';
	document.location.href=url;
}

function autoLogin(){

	var u=getCookie("HP_UCANTV_NAME")
	var p=getCookie("HP_UCANTV_PWD")
	if(u=="nocookie"){
		return;
	}
	var url = './userSerAction.do?';
	var pars = 'method=login&userid='+encodeURIComponent(u)+'&pwd='+encodeURIComponent(p);


	new Ajax.Request(url,{method:'post',parameters:pars,onComplete :auto_login});




}
//ajax call_back function
function auto_login(transport){	
	var status_longin = $('status');

	var status=0;

	var arr=transport.responseText.split(";"); 
	status=parseInt(arr[0]);
	var msg=arr[1]; 
	if(status==1){
		var str =' <INPUT TYPE="HIDDEN" id="status" type="text" value="1" /> <table width="146" border="0" cellspacing="0" cellpadding="0">';
        str +='<tr>';
		str +='<td></td';
        str +='</tr>';
        str +='<tr>';
        str +='<td colspan="2" align="center">&nbsp;</td>';
        str +=' </tr>';
        str +='<tr>';
        str +='<td height="22" colspan="2" align="left" class="zi">'+msg+' 您好：</td>';
        str +='</tr>';
		str +='<tr>';
        str +='<td colspan="2" class="zi" align="left">欢迎来到惠普优看高清电视剧场</td>';
        str +='</tr>';
		str +='<tr>';
        str +=' <td colspan="2" align="left">&nbsp;</td>';
        str +='</tr>';
        str +='<tr>';
        str +=' <td height="42" align="center"><img src="images/yhdl-xgzl.gif" width="69" height="22" style="CURSOR: pointer" onclick="JavaScript:userudate()"/>&nbsp;&nbsp;<img src="images/exit-button.gif" width="69" height="22" style="CURSOR: pointer" onclick="JavaScript:exitUser()"/></td>';
        str +='<td align="right"></td>';
        str +='</tr>';
        str +='</table>';

		loginInput($('login'),str);

	}
	if(status==2)
	{
		var str =' <INPUT TYPE="HIDDEN" id="status" type="text" value="1" /> <table width="146" border="0" cellspacing="0" cellpadding="0">';
        str +='<tr>';
		str +='<td></td';
        str +='</tr>';
        str +='<tr>';
        str +='<td colspan="2" align="center">&nbsp;</td>';
        str +=' </tr>';
		str +='<tr>';
        str +='<td colspan="2" class="zi" align="left">欢迎来到惠普优看高清电视剧场,您还可以注册成为优看会员 </td>';
        str +='</tr>';
		str +='<tr>';
        str +=' <td colspan="2" align="left">&nbsp;</td>';
        str +='</tr>';
        str +='<tr>';
        str +=' <td height="42" align="center"><img src="images/yhdl-zc.gif" width="69" height="22" style="CURSOR: pointer" onclick="JavaScript:register()"/>&nbsp;&nbsp;<img src="images/exit-button.gif" width="69" height="22" style="CURSOR: pointer" onclick="JavaScript:exitUser()"/></td>';
        str +='<td align="right"></td>';
        str +='</tr>';
        str +='</table>';
		loginInput($('login'),str);
	}
}

function getCookie(name){

		var cookieString = new String(document.cookie);
		var cookieString1 = name+"=";
		var beginPosition = cookieString.indexOf(cookieString1);
		if (beginPosition == -1){
			return "nocookie";
		}
		cookieString1 = cookieString.substring(beginPosition + cookieString1.length);
		cookieString = cookieString1.indexOf(";");
		if(cookieString != -1)
		{
			cookieString = cookieString1.substring(0,cookieString);
			cookieString1 = cookieString;
		}
		return cookieString1;
}

function setCookie(cookieName,cookieValue,nDays){
		 var today = new Date();
		 var expire = new Date();
		 if (nDays==null || nDays==0) nDays=1;
		 expire.setTime(today.getTime() + 3600000*24*nDays);
		 document.cookie = cookieName+"="+escape(cookieValue)+"; path=/; expires="+expire.toGMTString();
}



function delCookie(name){
    var expdate = new Date(); 
    expdate.setTime(expdate.getTime() - (86400 * 1000 * 1)); 
    setCookie(name, "", expdate); 
 }

function loginDown(){
    if (event.keyCode == 13){
        chklogin();
    }
}

function call24(){
	
	try{
	var status = $('status');
		if(status.value=='1'||status.value=='2')
		{
				window.open('http://service.meecall.com/clickcall?dotype=page&user=ucantvhp&encript=52df830382717de4dd683a2c0e1d7264&phone');

		}else{
			alert('请登录系统');
			document.location.href='./index.jsp'
		}

     		}catch(e){
      //显示异常的详细信息
      		alert('请登录系统');
			document.location.href='./index.jsp'
		}
}