var processed = false;
var processing = false;
var formValidationValue = false;
var xmlHttp = GetXmlHttpObject();

function GetXmlHttpObject()
{
  var xmlHttp1 = null;
  try
  {
    	// Firefox, Opera 8.0+, Safari
    	xmlHttp1=new XMLHttpRequest();
  }
  catch (e)
  {
    	// Internet Explorer
	try
	{
		xmlHttp1=new ActiveXObject("MSXML2.XMLHTTP");
	}
	catch (e)
	{
	    try
	    {
	      	xmlHttp1=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	    catch (e)
	    {
	      	alert("Couldn\'t Get XMLHttpRequest Object");
	    }
    	}
  }
  return xmlHttp1;
}

function sendStoreUserNameRequest(username)
{
	if(!processing)
	{
		processing = true;
		xmlHttp.open("get", "/vbforum/sv_streamproduct_storeuser.php?user=" + username, true);
		xmlHttp.onreadystatechange = handleStoreUserNameRequest;
		xmlHttp.send(null);
	}
}

function handleStoreUserNameRequest()
{
	if(xmlHttp.readyState == 4)
	{
	     if(product_option('ContentDelivery') != false)
		{
			var contentType = product_option('ContentDelivery').value;
		     if((contentType >= 15 && contentType <= 21) || contentType == 35 || contentType == 40 || contentType == 45 || contentType == 50 || contentType == 53 || contentType == 58 || contentType == 61)
		     {
				processing = false;
				alert('You must select a delivery method for this product.');
				self.location.hash = "#prod_opt";
			}
			else if(contentType % 2 == 0)
		     {
				if(xmlHttp.responseText == "failed")
			     {
					processing = false;
					alert('You must enter a valid 3D Buzz Forum username with this Method. This is separate from your store account username.');
					self.location.hash = "#prod_opt";
			     }
			     else if(xmlHttp.responseText == "success")
			     {
					processing = false;
					if(FormValidation()) document.orderform.submit();
				}
				else
					processing = false;
			}
			else
			{
				if(confirm('You are choosing to opt out of streaming delivery?'))
				{
					processing = false;
					if(FormValidation()) document.orderform.submit();
				}
				else
					processing = false;
			}
		}
		else
		{
			if(xmlHttp.responseText == "failed")
		     {
				processing = false;
				alert('You must enter a valid 3D Buzz username with this Product. This is separate from your store account username.');
				self.location.hash = "#prod_opt";
		     }
		     else if(xmlHttp.responseText == "success")
		     {
				processing = false;
				if(FormValidation()) document.orderform.submit();
			}
			else
				processing = false;
		}
	}
}