var http_request=null;

 function sComForm()
  {
	 var Form=document.forms["comForm"];
         
         var tcomment=Form.comment.value;
         
         var tpImgCode=Form.imgcode.value;
        
         if(Form.like[0].checked==true)
            tlike=1;
         else if(Form.like[1].checked==true)
            tlike=2;
         else if(Form.like[2].checked==true) 
            tlike=3;
         
         tcomment=tcomment.replace(/(^\s*)|(\s*$)/g, "");
         tpImgCode=tpImgCode.replace(/(^\s*)|(\s*$)/g, "");
	 if(tcomment=="" )
	 {
		alert("评论的内容不能为空！");
		Form.comment.focus();
		return false;
	 }
	 
	 if(tpImgCode=="" )
	 {
		alert("验证码不能为空！");
		Form.imgcode.focus();
		return false;
	 }
	 
	 if( tcomment.length<5 || tcomment.length>1000 )
	 {
		alert("评论的内容不能小于5 大于 1000 个字符！");
		Form.comment.focus();
		return false;
	 }
	 
	 var reurl="comment=" + escape(tcomment) + "&softId=" + escape(Form.softId.value) + "&pImgCode=" + escape(tpImgCode)+ "&like="+escape(tlike);
	
	 var ref=function()
	      {
		  
		  if (http_request.readyState == 4) { 
                    
                     if (http_request.status == 200) {
                          var requestText=http_request.responseText;
                          if(requestText=="OK") 
				 {
					Form.comment.value="";
					Form.imgcode.value="";
					alert("评论写入成功,需要管理员审核");
				 }else if(requestText=="code") {alert('验证码不正确');}
				  
                         } else { alert("评论暂不能保存,错误代码"+http_request.status);} }

		}
	      send_request("/comment.asp",reurl,ref);
          }

function send_request(url,Temp,ref) 
	  {
		http_request=myxmlhttp();
		if (http_request==null) { 
			window.alert("不能创建XMLHttpRequest对象实例.");
			return false;
		}
		http_request.onreadystatechange = ref; 
		// 确定发送请求的方式和URL以及是否同步执行下段代码
		http_request.open("Post", url, true);
		http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		http_request.send(Temp);
	 }


//初始化xmlhttp对象
function myxmlhttp()
{
	var A=null;
	try
	{
		A=new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			A=new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(oc)
		{
			if (typeof XMLHttpRequest != "undefined" );
			{
				A=new XMLHttpRequest();
			}
		}
	} 
 
	return A;
}

function requestTake()
{
	
	if(oHttpReq2.readyState == 4 && oHttpReq2.status == 200)
	{
		
		return true;
	}
}

function killvote(url)
{
 
 oHttpReq2.open("GET",url,false);
 
 oHttpReq2.onreadystatechange =requestTake;
 oHttpReq2.send(null);
 if(oHttpReq2.responseText=="1") alert("你今天已经评价过此软件."); else alert('恭喜你,评价成功,谢谢你的支持.');
  
 
 } 


var oHttpReq= myxmlhttp();
var oHttpReq2= myxmlhttp();
function posttobbs(s_id)
{
	ie = (document.all)? true:false
	if (ie){
	      try{	
                fShowWaiting();
                oHttpReq.open("get", '/softtobbs.asp?id='+s_id, false);
                oHttpReq.send("");
                var d=bytes2BSTR(oHttpReq.responseBody);	
		
		window.clipboardData.setData('text', d);
		window.setTimeout(hiddenMsg,1000);
               }catch(e){window.clipboardData.setData('text', "Null");window.setTimeout(hiddenMsg,1000);}
	}
}

function posttoblog(s_id)
{


ie = (document.all)? true:false
	if (ie){
	      try{	
                fShowWaiting();
                oHttpReq.open("get", '/softtoblog.asp?id='+s_id, false);
                oHttpReq.send("");
                var d=bytes2BSTR(oHttpReq.responseBody);	
		
		window.clipboardData.setData('text', d);
		window.setTimeout(hiddenMsg,1000);
               }catch(e){window.clipboardData.setData('text', "Null");window.setTimeout(hiddenMsg,1000);}
	}


}

function hiddenMsg()
{
	var obj = document.getElementById('tbMsg');
	obj.style.display="none";
}

function fShowWaiting(){
	try{
		var msg = document.getElementById("tbMsg");
		var o = get_position();
		msg.style.left=o.x;
		msg.style.top=o.y;
		msg.style.display = "";
	}catch(e){

	}
}
function get_position(){
	var e = window.event.srcElement;
	var e1=e;
	var l=e.offsetLeft;t=e.offsetTop; 
	while(e=e.offsetParent){t+=e.offsetTop;l+=e.offsetLeft;};
	l+=e1.scrollWidth; 
	t+=e1.scrollHeight;
	return {x: l, y: t};
}

document.writeln("<script language=vbscript>");
document.writeln("Function bytes2BSTR(vIn)");
document.writeln("dim i");
document.writeln("strReturn = \"\"");
document.writeln("For i = 1 To LenB(vIn)");
document.writeln("ThisCharCode = AscB(MidB(vIn,i,1))");
document.writeln("If ThisCharCode < &H80 Then");
document.writeln("strReturn = strReturn & Chr(ThisCharCode)");
document.writeln("Else");
document.writeln("NextCharCode = AscB(MidB(vIn,i+1,1))");
document.writeln("strReturn = strReturn & Chr(CLng(ThisCharCode) * &H100 + CInt(NextCharCode))");
document.writeln("i = i + 1");
document.writeln("End If");
document.writeln("Next");
document.writeln("bytes2BSTR = strReturn");
document.writeln("End Function");
document.writeln("<\/script>")