var isOK=1;
function showTime() {
        var time;
        var timer = document.getElementById("comment_timer");
        if(timer){
        	var value = timer.value;
        	value--;
        	if(value < 1) value =0;
        	timer.value = value;
        }
        setTimeout("showTime()",1000);
        
}

function ok_click(id,count_xx){
		comment_vote(id,"ok", count_xx);
	}

function no_click(id,count_xx){
		comment_vote(id,"no", count_xx);
	}

function debate_change_count(id,countxx, type){
        if(type=="ok"){
		  getObject('hits_ok').innerHTML="<a href='javascript:ok_click("+id+","+countxx+");'>&nbsp;<b>Useful for me</b>&nbsp;(&nbsp;"+countxx+"&nbsp;)</a>";
		}
         else if (type=="no"){	
		  getObject('hits_no').innerHTML="<a href='javascript:no_click("+id+","+countxx+");'>&nbsp;<b>Useless for me</b>&nbsp;(&nbsp;"+countxx+"&nbsp;)</a>";
		 }
	}

function getObject(objectId) {
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getObject






function comment_vote(id,type,hitscount){
		var url = "http://www.shippingonline.cn/port/ok_no_hits.asp?id=" + id+"&gd="+type+"&t="+Math.random();
        var timer = document.getElementById("comment_timer");
        var lastid = document.getElementById("comment_lastid");
		if(timer && timer.value > 0 && lastid && lastid.value==id){
			alert("Sorry,Please do not repeat the same operation in a short time.");
			return;
		}
		timer.value=5;
		lastid.value=id;

        var data = new Object();
        data.http = getHTTPObject();
		
        data.http.onreadystatechange = function(){
            	if (data.http.readyState == 4) {
 				    try{
				    	var response = data.http.responseXML.documentElement;
				    var status="OK";
                                       	if(status == "OK"){
							isOK=3;
							debate_change_count(id,hitscount+1, type);
						}else{
							isOK=2;
							alert ("Sorry,Send request failed, please try again.");
						}
			        } catch(e){
						isOK=2;
			        	alert ("Sorry,Send request failed, please try again." + e);
			        }
			   }
        }

        data.http.open("GET", url, true);
        data.http.send(null);
		if(isOK!=2){
		alert ("Thank you for your participation.");
		}

}





function getHTTPObject() {
        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;
}
