var xmlobj;//定义XMLHttpRequest对象

function CreateXMLHttpRequest()
{
	xmlobj = false;
	xmlhttpObj = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
	
	if(window.XMLHttpRequest)
	{
		xmlobj = new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		for(i=0;i<xmlhttpObj.length;i++)
		{
			xmlobj = new ActiveXObject(xmlhttpObj[i]);
			if(xmlobj)
			{
				break;
			}
		}
	}
	else
	{
		alert("暂时不能创建XMLHttpRequest对象");
	}
}

function submit()
{
	if(document.getElementById("title").value=="")
	{
		alert("请输入文章标题！");
		document.getElementById("title").focus();
		return false;
	}
	if(document.getElementById("url").value=="")
	{
		alert("请输入文章链接！");
		document.getElementById("url").focus();
		return false;
	}
	CreateXMLHttpRequest();
	var param="title="+document.getElementById("title").value+"&url="+document.getElementById("url").value;
	xmlobj.onreadystatechange=StatHandler;
	xmlobj.open("POST","ext/submit.php",true);
	xmlobj.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlobj.send(param);
}

function StatHandler()
{
	if(xmlobj.readyState==4 && xmlobj.status==200)
	{
		if(xmlobj.responseText=="1")
		{
			alert("推荐成功，请等待管理员审核！");
			document.getElementById("title").value="";
			document.getElementById("url").value="";
		}
		else if(xmlobj.responseText=="2")
		{
			alert("博文地址需以http://blog.xmnn.cn/开头！");
		}
		else if(xmlobj.responseText=="3")
		{
			alert("该博文已被推荐过！");
		}
		else
		{
			alert("推荐失败!");
		}
	}
}