var url="/";

function newXmlHttp()
{
	var xmlhttp
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try {
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
	} catch (e) {
		try {
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
		} catch (E) {
			xmlhttp=false
		}
	}
	@else
	xmlhttp=false
	@end @*/
	if (!xmlhttp && typeof XMLHttpRequest!='undefined')
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		}
		catch (e)
		{
			xmlhttp=false
		}
	}
	return(xmlhttp);
}

function myXMLHttpRequest()
{
	var xmlhttplocal;
	try
	{
		xmlhttplocal= new ActiveXObject("Msxml2.XMLHTTP")
	}
	catch(e)
	{
		try
		{
			xmlhttplocal= new ActiveXObject("Microsoft.XMLHTTP")
		}
		catch(E)
		{
			xmlhttplocal=false;
		}
	}
	if (!xmlhttplocal && typeof XMLHttpRequest!='undefined')
	{
		try
		{
			var xmlhttplocal = new XMLHttpRequest();
		}
		catch (e)
		{
			var xmlhttplocal=false;
			alert('couldn\'t create xmlhttp object');
		}
	}
	return(xmlhttplocal);
}


function sndReq(tid,rid,action)
{
	if ($('unit_'+rid)!=null)
	{
		var el = $('unit_'+rid);
    	el.innerHTML = '<div style="margin:3px 5px"><img src="http://icon.zdnet.com.cn/server/images/Load.gif" align="absmiddle" border="0"/>正在处理你的投票,请稍候</div>';
	}
		
	var xmlhttp=newXmlHttp();
    xmlhttp.open('get', '/techzone/comment/vote.php?act='+action+'&tid='+tid+'&pid='+rid,true);
    xmlhttp.onreadystatechange = function()
    {
		if(xmlhttp.readyState == 4)
		{
			if (xmlhttp.status == 200)
			{
				var response = xmlhttp.responseText;
				response = response.split('|');
				var s = response[0];
				var o = response[1];

				
				if ($("unit_"+rid) != null)
				{
					newDiv=$("unit_"+rid);
					newDiv.removeChild(newDiv.lastChild);
					draw(tid,rid,s,o,1);
				}
			}
		}
	}
    xmlhttp.send(null);
    setCookie("Vote" + tid + rid,"true")
}



//普通评论
function ReplyVote(tid,rid,s,o){
	document.write('<div id="unit_'+rid+'" style="float:right"></div>')
	var newDiv = document.getElementById("unit_"+rid);
	newDiv.style.margin="-3px 5px";
	var text = document.createTextNode("Loading ...");
	newDiv.appendChild(text);
	var _getCookie = getCookie("Vote" + tid + rid);
	if(_getCookie == null)
	{
		draw(tid,rid,s,o,0);
	}
	else
	{
		draw(tid,rid,s,o,1);
	}	
}

//热点评论
function ReplyVoteHot(tid,rid,s,o){
	document.write('<div id="hotunit_'+rid+'" style="float:right"></div>')
	var newDiv = document.getElementById("hotunit_"+rid);
	newDiv.style.margin="-3px 5px";
	var text = document.createTextNode("Loading ...");
	newDiv.appendChild(text);
	var _getCookie = getCookie("Vote" + tid + rid);
	if(_getCookie == null)
	{
		draw(tid,rid,s,o,0);
	}
	else
	{
		draw(tid,rid,s,o,1);
	}	
}


function getData(tid,rid,st)
{
	var xmlhttp=newXmlHttp();
	xmlhttp.open('get', url+'vote.aspx?Tid='+tid+'&rid='+rid,true);
    xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4)
		{
			if (xmlhttp.status == 200)
			{
				var response = xmlhttp.responseText;
				response = response.split('|');
				var s = response[0];
				var o = response[1];

				
				if ($("unit_"+rid) != null)
				{
					newDiv=$("unit_"+rid);
					newDiv.removeChild(newDiv.lastChild);
					draw(tid,rid,s,o,1);
				}				
			}
		}
    }
	xmlhttp.send(null);
	return null;
}

//重新绘制评论的图
function draw(tid,rid,s,o,st)
{
	var div = $("unit_" + rid);
	st = getCookie("Vote" + tid + rid);
	if(!st){
		div.innerHTML = '<a href="javascript:sndReq('+tid+', '+rid+', \'support\')"><img alt="支持" src="http://icon.zdnet.com.cn/techzone/images/qu_s.gif" align="absmiddle"/>支持('+s+')</a><a href="javascript:sndReq('+tid+', '+rid+', \'oppose\')"><img alt="反对" src="http://icon.zdnet.com.cn/techzone/images/qu_o.gif" align="absmiddle"/>反对('+o+')</a><a href="javascript:;" onclick="commnetcomment('+rid+')">[回复此帖]</a>';
	}else{
		div.innerHTML = '<a><img alt="支持" src="http://icon.zdnet.com.cn/techzone/images/qu_s.gif" align="absmiddle"/>支持('+s+')</a><a><img alt="反对" src="http://icon.zdnet.com.cn/techzone/images/qu_o.gif" align="absmiddle"/>反对('+o+')</a><a href="javascript:;" onclick="commnetcomment('+rid+')">[回复此帖]</a>';
	}
}

// JS 对 cookie 操作
function setCookie(name,value)
{
  var Days = 30; //此 cookie 将被保存 30 天
  var exp  = new Date();    //new Date("December 31, 9998");
  exp.setTime(exp.getTime() + Days*24*60*60*1000);
  document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString() + "";;
}

function getCookie(name)
{
  var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
  if(arr != null) return unescape(arr[2]); return null;
}

function disCookie(name,value)
{
  var exp  = new Date();    //new Date("December 31, 9998");
  exp.setTime(exp.getTime() + 24*60*60*1000);
  document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString() + "";;
  html = '<div class="qu_pin_name_right_left">您还没有登录. 请 <a href="http://www.zdnet.com.cn/zdnet/rms_login.php?forward=' +location.href+ '">登录</a></div>';
  document.getElementById('usernamediv').innerHTML = html;
}

function $() {
  var elements = new Array();

  for (var i = 0; i < arguments.length; i++) {
    var element = arguments[i];
    if (typeof element == 'string')
      element = document.getElementById(element);

    if (arguments.length == 1)
      return element;

    elements.push(element);
  }
  return elements;
}

//评论的一些函数

function comment_niming(show){
	document.getElementById('usernamediv').style.display = show ? '' : 'none';
	loginlink();
}
//登录链接
function loginlink(){
	var html;
	if(getCookie('_ZDNET_LOGINID')){
		html = 	'<div class="qu_pin_name_right_left">' + getCookie('_ZDNET_LOGINID') + ' <a href="#" onclick="disCookie(\'_ZDNET_LOGINID\',\'\');">退出</a><iframe name="disccookie" frameborder="0" width="0" height="0"></iframe></div>';
	}else{
		html = '<div class="qu_pin_name_right_left">您还没有登录. 请 <a href="http://www.zdnet.com.cn/zdnet/rms_login.php?forward=' +location.href+ '">登录</a></div>';
	}
	document.getElementById('usernamediv').innerHTML = html;
}


function comment_yanzhengma(){
	document.getElementById('yanzhengmadiv').innerHTML = '验证码：<input name="code" type="text" autocomplete="off" /><a href="javascript:;"title="换一张"><img id="codeimg" onclick="this.src+=1;" src="/techzone/comment/code.php?'+Math.random()+'" alt="点击更换验证码" align="absmiddle" /></a>';
}

//EnglishCommentstart

function comment_niming1(show){
	document.getElementById('usernamediv').style.display = show ? '' : 'none';
	loginlink1();
}
//登录链接
function loginlink1(){
	var html;
	if(getCookie('_ZDNET_LOGINID')){
		html = 	'<div class="qu_pin_name_right_left">' + getCookie('_ZDNET_LOGINID') + ' <a href="http://bbs.zdnet.com.cn/logging.php?action=logout">login out</a></div>';
	}else{
		html = '<div class="qu_pin_name_right_left">NOT LOGGED . Please <a href="http://www.zdnet.com.cn/zdnet/rms_login.php?forward=' +location.href+ '">Login</a></div>';
	}
	document.getElementById('usernamediv').innerHTML = html;
}


function comment_yanzhengma1(){
	document.getElementById('yanzhengmadiv').innerHTML = 'code ：<input name="code" type="text" autocomplete="off" /><a href="javascript:;"title="Change another"><img id="codeimg" onclick="this.src+=1;" src="/techzone/comment/code.php?'+Math.random()+'" alt="click to replace " align="absmiddle" /></a>';
}

//EnglistCommentend



//回复评论
function commnetcomment(pid){
	document.getElementById('commentcomment').value = pid;
	document.getElementById('focuscomment').scrollIntoView(false);
	//document.getElementById('content').focus();
}

//检查
function commentchk(f){

	//检查登录
	if(!f.anonymous[0].checked){
		if(!getCookie("_ZDNET_USERID")){
			alert("请先登录");
			return false;
		}
	}
	//检查内容
	if(f.content.value.length < 2){
		alert('请输入评论内容');
		return false;
	}
	
	//验证码
	if(!f.code || !f.code.value){
		alert('请输入验证码');
		return false;
	}
}


