var imgwidth=700;
function $(id){return document.getElementById(id);}
function show(o){document.getElementById(o).style.display="block";}
function hide(o){document.getElementById(o).style.display="none";}
function geturl(url,id){
var http=false;
$(id).innerHTML='<span class="loading">&nbsp;&nbsp;</span>';
if(window.XMLHttpRequest){http=new XMLHttpRequest();if(http.overrideMimeType){http.overrideMimeType('text/plain');}}else if(window.ActiveXObject){try{http=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){try{http=new ActiveXObject("Microsoft.XMLHTTP");}catch(e){}}}
if(!http){alert('Cannot send an XMLHTTP request');return false;}
http.onreadystatechange=function(){if(http.readyState==4){$(id).innerHTML=http.responseText;}}
http.open("get", url, true);
http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
http.send(null);
}
function imgsize(){
	var img=document.getElementById("content").getElementsByTagName("img");
	for(var i=0; i<img.length;i++){
		if(img[i].width>imgwidth){img[i].width=imgwidth;img[i].style.width=imgwidth;img[i].title="View";img[i].style.cursor="pointer";img[i].border=0;img[i].onclick=function(e){window.open(this.src);}}
	}
}
function ctlent(_){
	if((_.ctrlKey&&_.keyCode==13)||(_.altKey&&_.keyCode==83))$("submit").click()
	}
function reloadcode(){
    //评论插件所在目录位置请自行修改
    $("sn_code").src="/plus/comment/code.asp?s="+Math.random()
    }
function makeRequest(url, functionName, httpType, sendData) {
    http_request = false;
    if (!httpType) httpType = "GET";
    if (window.XMLHttpRequest) { 
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/plain');
        }
        } else if (window.ActiveXObject) {
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        alert('Cannot send an XMLHTTP request');
        return false;
    }
    var changefunc="http_request.onreadystatechange = "+functionName;
    eval (changefunc);
    http_request.open(httpType, url, true);
    http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    http_request.send(sendData);
}
//发布评论内容
function contentcomment(id){
    $("submit").disabled=true;
    target_obj = $("comment_tip");
    var A=$('user'),B=$('comment_content'),C=$('sn'),D=$('email'),E=$('rates');
    var Cuser=A.value,Ccontent=B.value,Csn=C.value,Cemail=D.value,Crates=E.value;
    //评论插件所在目录位置请自行修改
    var Curl="/plus/comment/save.asp";
    var CsendData="id=" + id + "&user=" + escape(Cuser) + "&content=" + escape(Ccontent) + "&email=" + escape(Cemail) + "&rates=" + Crates + "&sn=" + Csn;
    makeRequest(Curl,"commentgreturn","POST",CsendData);
}
//HTTP 返回值处理
var waitSecond=5;
function commentgreturn(){
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            var vback=http_request.responseText.split('|');
            if(vback[0]=='False'){
                    waitSecond=0;
                    disabledButton("submit",waitSecond);
                    $("comment_content").focus();
                    target_obj.innerHTML = vback[1];
                    show('comment_tip');
                }
                else
                {
					commentAJAX($("id").value);
                    waitSecond=5;
                    disabledButton("submit",waitSecond);
                    $("comment_content").value="";
                    target_obj.innerHTML = vback[1];
                    show('comment_tip');
                }        
        }
        else
        {
        target_obj.innerHTML=http_request.responseText;
        }
    }
}
function disabledButton(A,B){
    $(A).disabled=true;
    $(A).value="Waiting for "+B+" seconds...";
    reloadcode();
    $("sn").value="";
    hide('sn_div');
    if(--B>0)setTimeout("disabledButton('"+A+"',"+B+")",1000);
    if(B<=0){
        $(A).value="Post";
        $(A).disabled=false;
        hide('comment_tip');
    }
    }
//获取评论内容
function commentAJAX(id){
    target_obj1 = $("comment_ajax");
    //评论插件所在目录位置请自行修改
    var Curl="/plus/comment/comment.asp?id=" + id;
    makeRequest(Curl,"commentAJAXreturn","get","");
}
//HTTP 返回值处理
function commentAJAXreturn(){
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            target_obj1.innerHTML=http_request.responseText;
    }
    }
}
