function closeWindow(){
    window.close();
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function convertToHtml(str){

		str = str.replace(/&/g, "&amp;");
		str = str.replace(/</g, "&lt;");
		str = str.replace(/>/g, "&gt;");
		str = str.replace(/\n/g, "<br/>");

		
		return str;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function parameterChange(tid,fid,nick,userId){
   nick = encodeURIComponent(nick);
   window.location="message.action?tid="+tid+"&fid="+fid+"&nick="+nick+"&userId="+userId+"&popedom=0&operate=post";
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
function parameterExChange(tid,fid,nick,userId){
   nick = encodeURIComponent(nick);
   window.location="message.action?tid="+tid+"&fid="+fid+"&nick="+nick+"&userId="+userId+"&popedom=0&operate=post";
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function parameterMxChange(mid,nick,userId){
   nick = encodeURIComponent(nick);
   window.location="message.action?mid="+mid+"&nick="+nick+"&userId="+userId+"&popedom=0&operate=post";
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

function  messageParameterChange(tid,nick,userId){
   nick = encodeURIComponent(nick);
   window.location="message.action?tid="+tid+"&nick="+nick+"&userId="+userId+"&popedom=0&operate=reply";
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function  messageParameterMxChange(mid,nick,userId){
   nick = encodeURIComponent(nick);
   window.location="message.action?mid="+mid+"&nick="+nick+"&userId="+userId+"&popedom=0&operate=reply";
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

function connUrl(url, international){
	if(international == 'en_US'){
	   if(confirm('Are you confirm to this operation?')){
          window.location = url;
       }
    }else{
		if(confirm('你确定要执行此操作吗?')){
	       window.location = url;
	    }
	}  
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

//弹出窗口
function check_en_US(){
    if(confirm('Are you confirm to this operation?')){
       window.location = url;
    }
}

//弹出窗口
function check_zh_CN(){
    if(confirm('你确定要执行此操作吗?')){
       window.location = url;
    }
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

   function popedomURL(id){
		if(id==2){
		 document.getElementById("forum").innerHTML=
		 " <b>选择板块</b> <select id='fid' name='fid'><optgroup label='General'>"+	 
		 "<option value='1'>News about TVU networks</option><option value='5'>TVU Talk</option></optgroup>"+
		 "<optgroup label='Support'><option value='7'>TVUPlayer</option><option value='3'>TVUPlayer Problems</option>"+
		 "<option value='18'>TVUPlayer Beta Test</option><option value='28'>TVUBroadcast</option>"+
		 "<option value='24'>TVUBroadcast Problems</option></optgroup>"+
		 "<optgroup label='Channels'><option value='4'>TV Guide</option>"+
		 "<option value='6'>Suggestions</option><option value='29'>Your Channels</option></optgroup>"+
		 "<optgroup label='Sports'><option value='13'>Soccer</option><option value='14'>Basketball</option>"+
		 "<option value='15'>Football</option><option value='16'>Hockey</option>"+
		 "<option value='20'>Baseball</option><option value='21'>Cricket</option>"+
		 "<option value='22'>Rugby</option><option value='17'>Softball</option></optgroup>"+
		 "<optgroup label='Countries'><option value='240'>China</option><option value='241'>Finland</option>"+
		 "<option value='242'>France</option><option value='243'>Germany</option>"+
		 "<option value='244'>Japan</option>"+
		 "<option value='245'>Singapore</option><option value='246'>Spain</option>"+
		 "<option value='247'>Turkey</option><option value='440'>Italy</option></optgroup>"+
		 "<optgroup label='event'><option value='640'>event</option>"+
		 "<option value='641'>event</option></optgroup>"+
		 "<optgroup label='TVU Labs'><option value='840'>TVU Global</option>"+
		 "<option value='841'>TVUVOD</option><option value='1040'>TVUMobile</option>"+
		 "<option value='35'>Mac TVUPlayer</option><option value='36'>TVU PVR</option></optgroup></select>";
		}
	}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
 	
	function modify(){
		 var userId = document.getElementsByName("userId");
		 var popedom  = document.getElementsByName("popedom");
		 var fid  = document.getElementsByName("fid");
		 if(trim(userId[0].value) != ""){
	       if(!isNum(userId[0].value, "用户ID")){       
	         return ;
	       } 	
	       if(userId[0].value.length > 12){       
	         alert("用户ID长度不能超过12位!");
		     return ;
	       } 	     
	     }else{
	       alert("请填写用户ID!");
		   return ;
	     }	
		 
		 if(popedom[0].value ==2){
		   window.location = "./modifyPopedom.action?userId="+userId[0].value+"&popedom="+popedom[0].value+"&fid="+fid[0].value;
		 }else{		
		   window.location = "./modifyPopedom.action?userId="+userId[0].value+"&popedom="+popedom[0].value;
		 }
	}
	
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
 	
   function deleteTopicByTid(fid, international){
        var selectValue = "";
	   	var t = document.getElementsByName("title");
		var len = t.length;
		for(var i=0;i<len;i++){
			if(t[i].checked){
				selectValue += t[i].value +",";
			}
		}
		if(selectValue==""){
		  if(international == 'en_US'){
		    alert("Please choose the topic!");
		  }else{
		    alert("请选择要删除的帖子!");
		  }
		  return ;
		}
		
		if(international == 'en_US'){
		   if(confirm('Are you confirm to this operation?')){
	          window.location="delTopic.action?fid="+ fid +"&selectValue=" + selectValue;
	       }
	    }else{
			if(confirm('你确定要执行此操作吗?')){
		       window.location="delTopic.action?fid="+ fid +"&selectValue=" + selectValue;
		    }
		}  
	 }
  
 ////////////////////////////////////////////////////////////////////////////////////////////////////
  
  function deleteCollectByTid(fid, international){
        var selectValue = "";
	   	var t = document.getElementsByName("title");
		var len = t.length;
		for(var i=0;i<len;i++){
			if(t[i].checked){
				selectValue += t[i].value +",";
			}
		}
		if(selectValue==""){
		  if(international == 'en_US'){
		    alert("Please choose the topic!");
		  }else{
		    alert("请选择要删除的帖子!");
		  }
		  return ;
		}
		
	   if(international == 'en_US'){
		  if(confirm('Are you confirm to this operation?')){
	        window.location="un_collect.action?selectValue=" + selectValue;
	      }
	   }else{
		  if(confirm('你确定要执行此操作吗?')){
		    window.location="un_collect.action?selectValue=" + selectValue;
		  }
	   }  
  }
  
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

  function deleteDirtyByTid(){
        var selectValue = "";
	   	var t = document.getElementsByName("did");
		var len = t.length;
		for(var i=0;i<len;i++){
			if(t[i].checked){
				selectValue += t[i].value +",";
			}
		}
		if(selectValue==""){
		  alert("请选择要删除的帖子!");
		  return ;
		}
		if(confirm('你确实要删除吗?')){
		window.location="delete_dirty.action?selectValue=" + selectValue;
	   }
   }
   
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

   function deleteIpByTid(){
        var selectValue = "";
	   	var t = document.getElementsByName("bid");
		var len = t.length;
		for(var i=0;i<len;i++){
			if(t[i].checked){
				selectValue += t[i].value +",";
			}
		}
		if(selectValue==""){
		  alert("请选择要解封的IP!");
		  return ;
		}
		if(confirm('你确实要解封吗?')){
		window.location="delete_ip.action?selectValue=" + selectValue;
	   }
   }
////////////////////////////////////////////////////////////////////////////////////////////////////////////
  function deleteUserByTid(){
        var selectValue = "";
	   	var t = document.getElementsByName("sbid");
		var len = t.length;
		for(var i=0;i<len;i++){
			if(t[i].checked){
				selectValue += t[i].value +",";
			}
		}
		if(selectValue==""){
		  alert("请选择要解封的用户!");
		  return ;
		}
		if(confirm('你确实要解封吗?')){
		 document.ban_user_forum.action = "banById.action?selectValue=" + selectValue;		
		 document.ban_user_forum.submit();	
	   }
   }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
    function check_reply_form(international) {
		var f = document.getElementById('post_form');
	    var content = document.getElementById('topic.content');
		var verify  = document.getElementById('verify');
		
		if ( trim(content.value) == '' || content.value.length < 1 || content.value.length > 50100 ) {
		   if(international == 'en_US'){
		       alert('Please enter the content correctly');
		   }else{
		       alert('请认真填写内容');
		   }
		   return false;
		}
		
		if ( trim(verify.value) == '' || !checkint(verify.value)) {
		    if(international == 'en_US'){
		       alert('Please enter the verify correctly');
		    }else{
		       alert('请认真填写验证码');
		    }
			return false;
		}
			
		document.post_form.action = "reply_topic.action";		
		document.post_form.submit();	
	}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
  function opener_go(url) {
	 window.location = url;
  }
  
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
  function validatePostForm(f, international)
	{
	    var content = document.getElementById('topic.content');
		if (content.value.replace(/^\s*|\s*$/g, "").length == 0) {
			if(international == 'en_US'){
			    alert('please enter content');
			}else{
		    	alert('请输入内容');
			}
			return false;
		}
		
		if (content.value.length > 5000)  {
			if(international == 'en_US'){
			    alert('The number of the charactors should not be more than 5000');
			}else{
		    	alert('输入的内容不能超过5000字');
			}
			return false;
		}
		
		document.quick_form.action = "reply_topic.action";	

        document.quick_form.submit();	
	}
  
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
  function previewTopic(fid, international){
	    var f = document.getElementById('post_form');
		var title = document.getElementById('topic.title');
	    var content = document.getElementById('topic.content');
	    var verify  = document.getElementById('verify');
	    
		if ( trim(title.value) == '' || title.value.length < 1  || title.value.length > 100) {					   
		    if(international == 'en_US'){
		       alert('Please enter the title correctly');
		    }else{
		       alert('请正确填写标题');
		    }
			return false;
		}
		
	    if ( trim(content.value) == '' || content.value.length < 1 || content.value.length > 50100 ) {
		    if(international == 'en_US'){
		       alert('Please enter the content correctly');
		    }else{
		       alert('请认真填写内容');
		    }
			return false;
		}
		
	    if ( trim(verify.value) == '' || !checkint(verify.value)) {
		    if(international == 'en_US'){
		       alert('Please enter the verify correctly');
		    }else{
		       alert('请认真填写验证码');
		    }
			return false;
		}
		document.post_form.action = "preview_topic.action?fid=" +fid;	
		
		document.post_form.submit();	
  }
  
/////////////////////////////////////////////////////////////////////////////////////////////////////////////


function trim(inputString) {   
      if (typeof inputString != "string") { return inputString; }
      var retValue = inputString;
      var ch = retValue.substring(0, 1);
      while (ch == " ") { 
   //检查字符串开始部分的空格
          retValue = retValue.substring(1, retValue.length);
          ch = retValue.substring(0, 1);
      }
      ch = retValue.substring(retValue.length-1, retValue.length);
      while (ch == " ") {
         //检查字符串结束部分的空格
         retValue = retValue.substring(0, retValue.length-1);
         ch = retValue.substring(retValue.length-1, retValue.length);
      }
      while (retValue.indexOf("  ") != -1) { 
  //将文字中间多个相连的空格变为一个空格
         retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); 
      }
      return retValue;
} 

/////////////////////////////////////////////////////////////////////////////////////////////////////////////

function  checkint(string,name){   //带参数名字的
  var i,one;   
  if(string.length==0){
       return false;
   }
  for(i=1;i<=string.length;i++)   
  {   
    one=string.substring(i-1,i);   
      if(one<'0'||one>'9')   
      {   
        //alert("请输入"+ name +"数字数据!");   
        return false;             
      }  
      return true;       
  }      
}
 
 /////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
   function check_message_form(international) {
		var f = document.getElementById('post_message');
		var verify  = document.getElementById('verify');
		
	    if ( f['message.authorB.nick'].value.length < 1 ) {
			if(international == 'en_US'){
		       alert('This user does not exist!');
		     }else{
		       alert('用户不存在');
		     }
			return false;
		}
		
		if ( trim(f['message.title'].value) == '' || f['message.title'].value.length < 1 || f['message.title'].value.length > 130) {								
			 if(international == 'en_US'){
		       alert('Please enter the title correctly');
		     }else{
		       alert('请认真填写消息标题');
		     }
		     return false; 
		}
		if ( trim(f['message.content'].value) == '' || f['message.content'].value.length < 1 || f['message.content'].value.length > 50100 ) {
			if(international == 'en_US'){
		       alert('Please enter the content correctly');
		     }else{
		       alert('请认真填写消息内容');
		     }
		     return false;
		}
		
		if ( trim(verify.value) == '' || !checkint(verify.value)) {
		    if(international == 'en_US'){
		       alert('Please enter the verify correctly');
		    }else{
		       alert('请认真填写验证码');
		    }
			return false;
		}
	
		return true;
	}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 function check_register(international){
    var personWeb = document.getElementsByName('personWeb');
    var comeFrom  = document.getElementsByName('comeFrom');
    var profession= document.getElementsByName('profession');
    var hobby     = document.getElementsByName('hobby');
    var self  = document.getElementsByName('selfIntroduce');
    var signature= document.getElementsByName('signature');
    
    var personWeb_zh_CN ="'网站'字符数只能在1到100之间!";
    var personWeb_en_US ="The words number of web site is limitted between 1 and 100.";
    
    var comeFrom_zh_CN ="'来自'字数只能在1到100之间!";
    var comeFrom_en_US ="The words number of location is limitted between 1 and 100.";
    
    var profession_zh_CN ="'职业'字数只能在1到100之间!";
    var profession_en_US ="The words number of occupation is limitted between 1 and 100.";
    
    var hobby_zh_CN ="'兴趣'字数只能在1到100之间!";
    var hobby_en_US ="The words number of interests is limitted between 1 and 100.";
    
    var self_zh_CN ="'自我介绍'字数只能在1到1000之间!";
    var self_en_US ="The words number of biography is limitted between 1 and 1000.";
    
    var signature_zh_CN ="'个性签名'字数只能在1到100之间!";
    var signature_en_US ="The words number of signature is limitted between 1 and 100.";
 
    if(trim(personWeb[0].value) !="" && personWeb[0].value.length  > 100){
       if(international == 'en_US'){
         alert(personWeb_en_US);
       }else{
         alert(personWeb_zh_CN);
       }
       
       return false;
    }

    if(trim(comeFrom[0].value) !="" && comeFrom[0].value.length  > 100){
       if(international == 'en_US'){
         alert(comeFrom_en_US);
       }else{
         alert(comeFrom_zh_CN);
       }
       return false;
    }
    
    if(trim(profession[0].value) !="" && profession[0].value.length  > 100){
        if(international == 'en_US'){
         alert(profession_en_US);
       }else{
         alert(profession_zh_CN);
       }
       return false;
    }
    
    if(trim(hobby[0].value) !="" && hobby[0].value.length  > 100){
       if(international == 'en_US'){
         alert(hobby_en_US);
       }else{
         alert(hobby_zh_CN);
       }
       return false;
    }
    
    if(trim(self[0].value) !="" && self[0].value.length  > 1000){
       if(international == 'en_US'){
         alert(self_en_US);
       }else{
         alert(self_zh_CN);
       }
       return false;
    }
    
    if(trim(signature[0].value) !="" && signature[0].value.length  > 100){
       if(international == 'en_US'){
         alert(signature_en_US);
       }else{
         alert(signature_zh_CN);
       }
       return false;
    }
    
    document.person_register.action = "arvata.action";	
		
    document.person_register.submit();	
    
 }
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
   function checkLength(countMe) {
		var count = 0;
        var escapedStr = encodeURI(countMe)
        if (escapedStr.indexOf("%") != -1) {
            count = escapedStr.split("%").length - 1
            if (count == 0) count++;  //perverse case; can't happen with real UTF-8
            var tmp = escapedStr.length - (count * 3)
            count = count + tmp
        } else {
            count 
        }
        return count;
    }
///////////////////////////////////////////////////////////////////////////////////////////////////////
    function check_ip_form(){
        var Ip = document.getElementsByName('ip');
        var persistTime = document.getElementsByName('persistTime');
         //验证IP
	    if(trim(Ip[0].value) != ""){
	      if(!checkIp(Ip[0].value)){       
	        return ;
	      } 	     
	    }else{
	      alert("请填写IP地址!");
		  return false;
	    }
	    if(trim(persistTime[0].value) != ""){
	      if(!isNum(persistTime[0].value, "屏蔽时间")){       
	        return ;
	      } 	     
	    }else{
	      alert("请填写屏蔽时间!");
		  return false;
	    }	
        document.ip_form.action = "ip.action";	
		document.ip_form.submit();	
    }
////////////////////////////////////////////////////////////////////////////////////////////////////////
	//验证IP
	function checkIp(strpart){
	   var iparr=strpart.split(".");
	   if(iparr.length!=4){   
	       alert("请认真填写IP地址1!");
	       return false;
	   }else{
	       var part;
	       for(part in iparr)//循环四个IP字段 验证是否为数字
	       {
	        if(checkint(iparr[part],"IP")){       
	            if(parseInt(iparr[part])<0 || parseInt(iparr[part])>255)
	            {
	             alert("请认真填写IP地址!");
	             return false;
	            }
	        }else{
	            //alert("请认真填写IP地址!");
	            return false;
	        }
	       }
	   }
	   return true;
	}
////////////////////////////////////////////////////////////////////////////////////////////////////////
function  isNum(string,name){   //带参数名字的
  var i,one;   
  if(string.length==0){
       return false;
   }
  for(i=1;i<=string.length;i++)   
  {   
    one=string.substring(i-1,i);   
      if(one<'0'||one>'9')   
      {   
        alert("请输入"+ name +"数字数据!");   
        return false;             
      }  
      return true;       
  }      
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
	function banUser(){
	 var userId  = document.getElementsByName("userId");
	 var remark  = document.getElementsByName("remark");
	 if(trim(userId[0].value) != ""){
       if(!isNum(userId[0].value, "用户ID")){       
         return ;
       } 	
       if(userId[0].value.length > 12){       
         alert("用户ID长度不能超过12位!");
	     return ;
       } 	     
     }else{
       alert("请填写用户ID!");
	   return ;
     }	
     if(trim(remark[0].value) == ""){
       alert("请填写屏蔽理由!");
	   return ;
     }	
	 document.ban_user_form.action = "banById.action";	
	 document.ban_user_form.submit();	
	}