var xmlHttp

function insertPost()
{
	// Check el anti-spam!
	if (document.form1.txtAS.value != 4)
	{
		alert("Please write the result of 1 + 3 in the Anti SPAM textbox")
		return
	}
	
	xmlHttp = GetXmlHttpObject()
	
	if (xmlHttp == null)
	{
		alert ("Browser does not support HTTP Request")
		return
	}
	
	// poner loading
	document.getElementById("txtResult").innerHTML="Validating and inserting your post..."
	
	var username = document.form1.txtUser.value;
	username = username.replace("&", "<ampersand>");
	
	var str = document.form1.txtPost.value;
	str = str.replace(/\n/g, "<br>");
	str = str.replace(/\r/g, "");
	str = str.replace(/&/g, "<ampersand>");
	
	// si el user y password no son nulos...
	if (document.form1.txtUser.value != "" && document.form1.txtPW != "")
	{
		var url="bbs_ajax.php?query=insertUser"
		url=url+"&username="+username
		url=url+"&password="+document.form1.txtPW.value
		url=url+"&url="+document.form1.txtURL.value
		url=url+"&post="+str
		//url=url+"&tag="+document.form1.selTag.value
		url=url+"&tag=None"
		url=url+"&sid="+Math.random()
		xmlHttp.onreadystatechange=stateChanged 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)	
	}
	
	else
	{
		var url="bbs_ajax.php?query=insert"
		url=url+"&nickname="+username
		url=url+"&url="+document.form1.txtURL.value
		url=url+"&post="+str
		//url=url+"&tag="+document.form1.selTag.value
		url=url+"&tag=None"
		url=url+"&sid="+Math.random()
		xmlHttp.onreadystatechange=stateChanged 
		xmlHttp.open("GET",url,true)
		xmlHttp.send(null)
	}
}

function stateChanged() 
{ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{ 
		document.getElementById("txtResult").innerHTML=xmlHttp.responseText 
	} 
}

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;
}