var request;
var queryString;
var reqStr;
/* Wrapper function for constructing a request object.
Parameters:
reqType: The HTTP request type, such as GET or POST.
url: The URL of the server program
asynch: Whether to send the request asynchronously or not.
respHandle: The name of the function that will handle the response.
Any fifth parameters represented as arguments[4], are the data a POST request is designed to send.
*/

function httpRequest(div,reqType,url,asynch,respHandle) 
{
	subject_id = div;
	//Mozilla-based browsers
	if(window.XMLHttpRequest)
	{
	request = new XMLHttpRequest();
	}
		else if (window.ActiveXObject)
		{
		request=new ActiveXObject("Msxml2.XMLHTTP");
		if (! request) 
		{
		request=new ActiveXObject("Microsoft.XMLHTTP");
		}
		}
		
		//very unlikely, but we test for a null request if neither ActiveXObject was initialized
		if(request)
		{
		//if the reqType parameter is POST, then 5th argument to the function is the POSTed data
			if(reqType.toLowerCase() != "post")
			{
			initReq(div,reqType,url,asynch,respHandle);
			}
			else
			{
			//the POSTed data
			//var args = arguments[4];
			//if(args != null && args.length > 0)
			{
			initReq(div,reqType,url,asynch,respHandle);
			//initReq(reqType,url,asynch,respHandle,args);
			}
			}
		}
		else
		{
		alert("Your browser does not permit the use of all of this applications features!");
		}
}

//Initialize a request object that is already constructed

function initReq(div,reqType,url,bool,respHandle)
{
	try
	{
	//Specify the function that will handle the HTTP response
	//request.onreadystatechange=handleResponse();
	request.onreadystatechange=respHandle;
	request.open(reqType,url,bool);
	//if the reqType parameter is POST, then the 5th argument to the function is the posted data
		if(reqType.toLowerCase() == "post")
		{
		request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
//var query = create_request_string("theForm");
		
		
		
		
		//BEGIN CREATING QUERY STRING
		var reqStr = "";

			for(i=0; i < document.getElementById('theForm').elements.length; i++)
			{
			isFormObject = false;

			switch (document.getElementById('theForm').elements[i].tagName)
			{
			case "INPUT":

			switch (document.getElementById('theForm').elements[i].type)
			{
			case "file":
			case "text":
			case "hidden":
			reqStr += document.getElementById('theForm').elements[i].name + "=" + encodeURIComponent(document.getElementById('theForm').elements[i].value);
			isFormObject = true;
			break;

			case "checkbox":
			if (document.getElementById('theForm').elements[i].checked)
			{
			reqStr += document.getElementById('theForm').elements[i].name + "=" + document.getElementById('theForm').elements[i].value;
			}
			else
			{
			reqStr += document.getElementById('theForm').elements[i].name + "=";
			}
			isFormObject = true;
			break;

			case "radio":
			if (document.getElementById('theForm').elements[i].checked)
			{
			reqStr += document.getElementById('theForm').elements[i].name + "=" + document.getElementById('theForm').elements[i].value;
			isFormObject = true;
			}
			}
			break;

			case "TEXTAREA":
			reqStr += document.getElementById('theForm').elements[i].name + "=" + encodeURIComponent(document.getElementById('theForm').elements[i].value);
			isFormObject = true;
			break;

			case "SELECT":
			var sel = theForm.elements[i];
			reqStr += sel.name + "=" + sel.options[sel.selectedIndex].value;
			isFormObject = true;
			break;
			}

			if ((isFormObject) && ((i+1)!= document.getElementById('theForm').elements.length))
			{
			reqStr += "&";
			}

			}		
		//END CREATING QUERY STRING
		
		
		
		
		
		//request.send('v=' + document.getElementById('theForm').elements[1].value);
		//request.send(arguments[4]);
		request.send(reqStr);
		}
		else
		{
		request.send(null);
		}
	}
	
	catch (errv)
	{
	alert(errv);
	}
}

function handleResponse() 
{
//document.getElementById("display").innerHTML = request.responseText;
	if(request.readyState == 4)
	{
		if(request.status == 200)
		{
		//alert("DAMMIT");
		//alert(request.responseText);
		document.getElementById(subject_id).innerHTML = request.responseText;
		}
		else
		{
		alert("A problem occurred.");
		}
	}
}

function sendData()
{
setQueryString();
var url="http://www.picvibe.com/includes/test.php";
httpRequest("POST",url,true);
}


function yes()
{
alert("DAMMIT");
}
