function createXMLHttpRequest() 
{
   try { return new XMLHttpRequest(); } catch(e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }
 
function requestDone(hreq, action)
{
	if (hreq.readyState == 4) 
	{
		if (hreq.status == 200)
			action(hreq.responseText);
		else 
			alert('There was a problem with the request: ' + hreq.status + hreq.responseText);
	}
}

function getRequest(url, parameters, action) 
{
	var http_request = createXMLHttpRequest();
	if(!http_request)
		window.alert("Could not createXMLHttpRequest");
	http_request.onreadystatechange = function() {requestDone(http_request, action);}
//	window.alert("Filling Models 2" + url + " " + parameters);
	var urlp = url + "?" + parameters;
//		window.alert("URL: " + urlp);
	http_request.open('GET', urlp, true);
	http_request.send(null);

}

function postRequest(url, parameters, action) 
{
	var http_request = createXMLHttpRequest();
	if(!http_request)
		window.alert("Could not createXMLHttpRequest");
	http_request.onreadystatechange = function() {requestDone(http_request, action);}
//	window.alert("Filling Models 2" + url + " " + parameters);
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

function fillFromForm(fo)
{
	var i;
	var getstr = '';
	var E = fo.getElementsByTagName("input");		// Elements
	var S = fo.getElementsByTagName("select");		// Random selects
	var T = fo.getElementsByTagName("textarea");	// Textareas
//	window.alert("Elements " + E.length + " Text " + T.length);
	for (i=0; i < S.length; i++)
	{
		var el = S[i].name + "=" + S[i].options[S[i].selectedIndex].value + "&";
		getstr += el;
	}
	for (i=0; i < E.length; i++) 
	{
		if (E[i].type == "text") 
			getstr += E[i].name + "=" + E[i].value + "&";
			
		else if (E[i].type == "checkbox") 
		{
			if (E[i].checked) 
				getstr += E[i].name + "=" + E[i].value + "&";
			else 
				getstr += E[i].name + "=&";
		}
		else if (E[i].type == "radio") 
		{
			if (E[i].checked) 
				getstr += E.name + "=" + E[i].value + "&";
		}
		else if(E[i].type == "hidden")
			getstr += E[i].name + "=" + E[i].value + "&";
	}
	// Textareas
	for (i=0; i < T.length; i++) 
	{
		getstr += T[i].name + "=" + T[i].value + "&";
	}
	return getstr;
}


onload=function()
{
	//var e=document.getElementById("email");
	var e=document.getElementById("email");
	var p=document.getElementById("phone");
	
	if(e.value != "" && p.value != "")
	{
		document.getElementById("email").value = "";
		document.getElementById("phone").value = "";
		location.reload();
	}
}


