function getXmlHttpObject()  
{  
    var xmlHttp=null;  
    try  
    {  
        // Firefox, Opera 8.0+, Safari  
        xmlHttp=new XMLHttpRequest();  
    }  
    catch (e)  
    {  
        // Internet Explorer  
        try  
        {  
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");  
        }  
        catch (e)  
        {  
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  
        }  
    }  
    return xmlHttp;  
}

function send_request() {
    var DIVID=document.getElementById("commentid");
    if(DIVID)
    {
        var  xmlhttp = getXmlHttpObject();
        var url = window.location.href;
        var  param = "url="+url;    
        xmlhttp.open("POST", '/passport/comment.php', false);
        xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xmlhttp.send(param);
        // 处理返回信息的函数
        DIVID.innerHTML = xmlhttp.responseText;
    }
}

function send_comment(){
    var comment=document.form_comment.comment.value;
    var incheckcode=document.form_comment.checkCode.value;
    var DIVID=document.getElementById("commentid");

    var  xmlhttp = getXmlHttpObject();
    var url = window.location.href;
    var  param = "url="+url+"&comment="+comment+"&incheckcode="+incheckcode;    
    xmlhttp.open("POST", '/passport/comment.php', false);
    xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xmlhttp.send(param);
    // 处理返回信息的函数
    DIVID.innerHTML = xmlhttp.responseText;
	document.getElementById("insert").disabled="true";
	document.form_comment.checkCode.value="";
}

function disp_checkcode(){
    var DIVID=document.getElementById("showCheckCode");

    var  xmlhttp = getXmlHttpObject();
    var  param = 'nocache='+new Date().getTime();    
    xmlhttp.open("GET", '/passport/getPictureCheckCode.htm', false);
    xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    xmlhttp.send(param);
    // 处理返回信息的函数
    DIVID.innerHTML = xmlhttp.responseText;
}

window.onload=function(){
    send_request();
}

function onerror(){
	//alert("您的操作有误！");
}
//生成并显示验证码
function getCheckCodeFun(checkCode){
	document.getElementById("showCheckCode").style.display='block';
	getCheckCode1(checkCode);	//生成验证码
	//checkCode.focus();
}
//生成验证码
function getCheckCode1(checkCode){
	disp_checkcode();
	//document.getElementById("showCheckCode").style.display='block';
	checkCode.focus();
}
//隐藏验证码显示框
function showCheckCodeClear(){
	document.getElementById("showCheckCode").style.display='none';
}
/***********验证验证码是否正确*******************************/
function checkCheckCode(inCheckCode){
	if(inCheckCode!=""){
		var loader=new net.AjaxRequest("/passport/checkCheckCode.php?inCheckCode="+inCheckCode+"&nocache="+new Date().getTime(),deal_checkCheckCode,onerror,"GET");
	}
}
function deal_checkCheckCode(h){
	var h=this.req.responseText;
	h=h.replace(/\s/g,"");	//去除字符串中的Unicode空白符
	if(h==1){
		document.getElementById("resultMessage").removeChild(document.getElementById("resultMessage").childNodes[0]);
		document.getElementById("resultMessage").appendChild(document.createTextNode(" "));
		document.getElementById("messageImg").src="/image/dui2.gif";
		document.getElementById("resultMessage").removeChild(document.getElementById("resultMessage").childNodes[0]);
		document.getElementById("resultMessage").appendChild(document.createTextNode("正确！"));
		document.getElementById("insert").disabled="";
		showCheckCodeClear();
	}else{
		document.getElementById("messageImg").src="/image/cuo2.gif";
		document.getElementById("resultMessage").removeChild(document.getElementById("resultMessage").childNodes[0]);
		document.getElementById("resultMessage").appendChild(document.createTextNode("不正确！"));
		document.getElementById("insert").disabled="none";
	}
}

var net=new Object();
//编写构造函数
net.AjaxRequest=function(url,onload,onerror,method,params){
  this.req=null;
  this.onload=onload;
  this.onerror=(onerror) ? onerror : this.defaultError;
  this.loadDate(url,method,params);
}
//编写用于初始化XMLHttpRequest对象并指定处理函数，最后发送HTTP请求的方法
net.AjaxRequest.prototype.loadDate=function(url,method,params){
  if (!method){
    method="GET";
  }
  if (window.XMLHttpRequest){
    this.req=new XMLHttpRequest();
  } else if (window.ActiveXObject){
    this.req=new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (this.req){
    try{
      var loader=this;
      this.req.onreadystatechange=function(){
        net.AjaxRequest.onReadyState.call(loader);
      }

      this.req.open(method,url,true);
	  if(method=="POST"){
		this.req.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	  }
      this.req.send(params);
    }catch (err){
      this.onerror.call(this);
    }
  }
}

//重构回调函数
net.AjaxRequest.onReadyState=function(){
  var req=this.req;
  var ready=req.readyState;
  if (ready==4){
    if (req.status==200 ){
      this.onload.call(this);
    }else{
      this.onerror.call(this);
    }
  }
}
//重构默认的错误处理函籹
net.AjaxRequest.prototype.defaultError=function(){
  alert("错误数据\n\n回调状态:"+this.req.readyState+"\n状态: "+this.req.status);
}

