var zcLog = new Object;
function $(element) {
    return document.getElementById(element);
}
function zc(cid){ 	goZc(cid,'zc'); }
function fd(cid){	goZc(cid,'fd'); }
function zzc(cid){ 	goZc(cid,'zc','z'); }
function zfd(cid){	goZc(cid,'fd','z'); }
function goZc(cid,zctype)
{
	ajx.FuncCall = 'default';
	if(zcLog[cid]=='1'){ alert("不能重复投票"); return; }
	if(arguments[2]=='z')
		zcLog[cid]=2;
	else
		zcLog[cid]=1;
	var u = "/commentZc.php?type="+zctype+"&id="+cid;
	if(zctype=='zc')ajx.fget(u,afZc);
	else ajx.fget(u,afFd);
}
function afFd(msg,errno)
{
	if(errno=="1"){ alert("已经支持/反对过了"); return; }
	var cid = msg;
	if(zcLog[cid]==2)
		var cfo = $('zfd'+cid);
	else
		var cfo = $('fd'+cid);
	var fd = parseInt(cfo.innerText);
	cfo.innerText = fd+1;
}
function afZc(msg,errno)
{
	if(errno=="1"){ alert("已经支持/反对过了"); return; }
	var cid = msg;
	if(zcLog[cid]==2)
		var cfo = $('zzc'+cid);
	else
		var cfo = $('zc'+cid);
	var zc = parseInt(cfo.innerText);
	cfo.innerText = zc+1;
}
function quoteReply(vid)
{
	document.comForm.pid.value=vid;
	$('quoteReplyDiv').innerHTML= "引用回复<br>"+$("ct"+vid).innerHTML+"<br>";
	$('quoteReplyDiv').style.display="";
	document.comForm.comment.focus();
}
function deleteQuote(vid)
{
	$('quoteReplyDiv').style.display="none";
	document.comForm.pid.value=0;
}
function commitCom()
{
	ajx.FuncCall = 'default';
	var f=document.comForm;
	$('submitButton').disabled=true;
	var scObj = f.comment;
	if(scObj.value=="" || scObj.value=="欢迎发表您对此软件的看法")
	{
		scObj.value = "";
		scObj.focus();
		showmsg('请填写内容');
		$('submitButton').disabled=false;
		return false;
	}

	if(!checkAd(f.comment.value))
	{	
		showmsg('广告评论被禁止');
		$('submitButton').disabled=false;
		return false;
	}

	if(f.comment.value.length<3)
	{
		showmsg('字数要求大于3...');
		f.comment.focus();
		$('submitButton').disabled=false;
		return false;
	}
	//if(f.uName.value=='匿名人士'){f.uName.value=='';}
	showmsg('提交中...','blue');
	ajx.fpost( 'comForm' , afCommit );
}

function showmsg(msg)
{
	var fcolor = 'red';
	if(arguments[1])fcolor=arguments[1];
	$('cmmsg').innerHTML="<font color="+fcolor+">"+msg+"</font>";
}
function afCommit(msg,errno)
{
	if(errno==0){
		alert('发表成功');
		location.reload(true);
		//id=document.comForm.softId.value;
		//lj=id+".html#pl";//alert(lj);
		//window.location.href=lj;
		//location.reload(window.location.href=lj);
	}
	else{
		$('submitButton').disabled=false;
		showmsg('','blue');
		alert(msg);
	}
}

function quoteReply(vid)
{
	document.comForm.pid.value=vid;
	$('quoteReplyDiv').innerHTML= "引用回复<br>"+$("ct"+vid).innerHTML+"<br>";
	$('quoteReplyDiv').style.display="";
	$('qDiv').style.display="";
	height = document.getElementById("qDiv").offsetHeight;
	height1 = window.parent.document.getElementById("commentFrame").offsetHeight;
	a = height1+height;	
	window.parent.document.getElementById("commentFrame").height = a;
	//window.parent.commentFrame.height=1000;
	document.comForm.comment.focus();
}
function deleteQuote(vid)
{
	$('quoteReplyDiv').style.display="none";
	document.comForm.pid.value=0;
}

function checkAd(str)
{
	str = str.replace( "http://www.yxbao.com/","[[yxbaocom]]");
	reg=/http:\/\//i;
	reg2=/\w+(\.com|\.cn|\.org|\.net)/i;
	var r=str.search(reg);
	r2=str.search(reg2);
	if(r!=-1 || r2 !=-1)
		return false;
	else
	{
		str = str.replace(  "[[yxbaocom]]" , "http://www.yxbao.com/" );
		return true;
	}
	//alert(r + "=" + r2);
}

function toReply()
{
	document.comForm.comment.focus();
}

function afP(msg,errno)
{
	if(errno=="1")
	{
		var fm = document.comForm;
		$('submitButton').disabled = false;
		$('ttInfo').innerHTML = "<font color=red>"+msg+"</font>";
	}
	if(errno=="0")
	{
		//alert(msg);
		location.reload(true);
	}
}