﻿
function XHConn()
{
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+ ((sURL.indexOf("?")==-1)? "?":"&")+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { firstPost = true; return false; }
    return true;
  };
  return this;
}
function GetData(webFile, fnWhenDone)
{
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	myConn.connect(webFile, "GET", "", fnWhenDone);	
}
function PostData(webFile, data, fnWhenDone)
{
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	myConn.connect(webFile, "POST", data, fnWhenDone);
}
String.prototype.trim = function() 
{ 
return this.replace(/(^[\s]*)|([\s]*$)/g, ""); 
}
function sb(text,link,contact,remark)
{
    if(text.trim()=="")
    {
        alert("请输入名称！");
        $("txtName").focus();
        return;
    }
    if(link.trim()==""||link.indexOf("http://")==-1||link.trim()=="http://")
    {
        alert("请输入正确网址！例如：http://www.yef88.com");
        $("txtUrl").focus();
        return;
    }
    var str = 'text='+escape(text)+'&link='+escape(link)+'&contact='+contact+'&remark='+remark+'&'+Math.random();
    //alert(str);
    GetData('/js_s/addfriend.aspx?'+str,fsb);
}
function fsb(obj)
{
    switch(obj.responseText)
    {
        case 'ok':
            alert('提交成功，谢谢您对云E坊的支持，我们会尽快联系你。');
            location.reload();
            break;
       case 'exist':
       alert('该网址已经被提交过了。在我们未对该地址做出审核之前，请勿重复提交');
            location.reload();
            break;
        default:
            break;
    }
}