var xmlHttp;
var pUrl = '';
var dOptions;
var pContact = false;

function GetXmlHttpObject() 
{
  var xmlHttp=null;
  try
    {
    //ff
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    //ie
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    }
  return xmlHttp;
}

function displayReturnXHRT()
{ 
  if(xmlHttp.readyState==4) 
  {
    if(xmlHttp.responseText == false)
    {
	  alert('data returned was lost');
    }
    else 
	{
		var xhrt = xmlHttp.responseText;
		alert(xhrt);
    }
  }
}

function returnData(pUrl,requestedStr)
{
  xmlHttp = GetXmlHttpObject();
  if(xmlHttp == null)
  {
    alert("Your browser does not support ajax.");
  }
  else
	{
	var rLen = requestedStr.length;
	if(rLen > 0)
	  {

		//decide which file we're going to submit to
		alert(pUrl+requestedStr);
		uQuery = requestedStr;
		xmlHttp.onreadystatechange = displayReturnXHRT;
		xmlHttp.open("POST", pUrl);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", uQuery.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(uQuery);
	  }
	else 
	  {
		alert('Transmission error: XHR');
	  }
  }     
}

function doContact() 
{
	var f = document.contactForm;
	var fEmail = f.email.value;
	var fSubject = f.subject.value;
	var fComment = f.comment.value;

	var pUrl = '../inc/contact.inc.php';

	//make sure a user isn't sending multiple requests
	if(!pContact)
	{
		var pContact = true;
			
		if(fEmail == '' && fSubject == '' && fComment == '')
		{
			alert('enter some shit before you submit son');
		}
		else 
		{
			//turn data into string to send to functions.php
			var returnStr = 'email=' +fEmail+ '&subject=' +fSubject+ '&comment=' +fComment;
			returnData(pUrl,returnStr);
		}
	}
	else
	{
		alert('You\'ve already sent a comment.');
	}
}