var http_request = false;
function ajaxMakeRequest(url, parameters) {
      http_request = false;
      if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            http_request.overrideMimeType('text/html');
         }
      } else if (window.ActiveXObject) { // IE
         try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
         } catch (e) {
            try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
         }
      }
      if (!http_request) {
         alert('Cannot create XMLHTTP instance');
         return false;
      }
     if(url=='act_survey.php') http_request.onreadystatechange = alertContentsSurvey;
      if(url=='act_contact.php') http_request.onreadystatechange = alertContentsContact;
	
	http_request.open('GET', url + parameters, true);
      http_request.send(null);
}

 
 
function alertContentsContact() {
	if (http_request.readyState == 4) {
	   if (http_request.status == 200) {
		result = http_request.responseText;
		document.getElementById('contactResults').innerHTML=result;
		document.getElementById('contactResults').style.display="block";
		if(result.indexOf('Thanks')>-1){
			document.getElementById('contactContent').style.display="none";
		}
	   } else {
		alert('There was a problem with the request.');
	   }
	}
} 
 
var getstr="";
function getAllNodes(nodeMaster){
	
	while (nodeMaster!=null) {
		//get info
		if (nodeMaster.tagName == "INPUT") {
			if (nodeMaster.type == "text") {
				getstr += nodeMaster.name + "=" + nodeMaster.value + "&";}
			if (nodeMaster.type == "checkbox") {
				if (nodeMaster.checked){
					getstr += nodeMaster.name + "=" + nodeMaster.value + "&";
				}else {
					getstr += nodeMaster.name + "=&";
				}
			}
			if (nodeMaster.type == "radio") {
				if (nodeMaster.checked) {
					getstr += nodeMaster.name + "=" + nodeMaster.value + "&";
				}
			}
		}else if (nodeMaster.tagName == "TEXTAREA") {
			getstr += nodeMaster.name + "=" + nodeMaster.value + "&";
		}else if (nodeMaster.tagName == "SELECT") {
			var sel = nodeMaster;
			getstr += sel.name + "=" + sel.options[sel.selectedIndex].value + "&";
		}
		
		if(nodeMaster.tagName == "DIV"||nodeMaster.tagName == "P"||nodeMaster.tagName == "SPAN"){//has children
			xChildGroup=getAllNodes(nodeMaster.firstChild);
		}
		
		nodeMaster=nodeMaster.nextSibling;
 	}
 	return getstr;
 }
 
function ajaxGatherResults(o,act) {
	urchinTracker('/maintenance/act_contact.php');
	getString="?"+getAllNodes(o.firstChild);
      ajaxMakeRequest(act,getString);
}