var req;        
var ans = false;
var x=null;     

function ajaxinit() {
  x = null;
  var msxmlhttp = new Array(
  'Msxml2.XMLHTTP',
  'Msxml2.XMLHTTP.3.0',
  'Msxml2.XMLHTTP.4.0',
  'Msxml2.XMLHTTP.5.0',
  'Microsoft.XMLHTTP');
  for(var i=0; i<msxmlhttp.length; i++) {
    try {
      x = new ActiveXObject(msxmlhttp[i]);
      break;
    } catch (e) {
      x = null;
    }
  }

  if(!x && typeof XMLHttpRequest!="undefined") {
    try { x = new XMLHttpRequest(); }
    catch(e) { x = null; }
  }
}
function ajaxreq(page,userfunc) {
  if(x!=null) {
    ans = false;
    return;
  }
  ajaxinit(); 
  if(x==null) {
    ans = false;
    userfunc('S');
    return;
  }
  x.open('POST', page, true);
  x.setRequestHeader("Method", "POST" + page + " HTTP/1.1");
  x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

  x.onreadystatechange = function() {
    if(x.readyState!=4)
    return;
    if(x.status!=200) {
      ans = false;
      x = null;
      userfunc('S');
      return;
    }
    ans = true;
    x = null;
    userfunc('S');
    return;
  };

  x.send(req);
}

function $(element) { return document.getElementById(element); }
function ly_comment() {
  if($('user').value=='') { $('user').focus(); return; }
  if($('text').value=='') { $('text').focus(); return; }
  req = "title=网友留言";
  req += "&name=" + $('user').value;
  req += "&content=" + $('text').value;
  ly();
}
function ly() {
  if(arguments[0]!='S') {
    ajaxreq("ly.php",ly);
  } else {
    if(ans==false) {
      alert("留言失败！");
    } else {
      ans = false;
      ly_return();
      alert("留言成功，感谢您的宝贵意见！");
    }
  }
}
function ly_return() {
  $('user').value='';
  $('text').value='';
}

