
// sends a request to showItem.asp
function evaluatezip() {
	var whatzip = document.getElementById('cFzip').value;
	if (whatzip.length == 5) {getready(whatzip);} else {alert('Please fill out the Zip Code field.'); document.getElementById('cFzip').focus;}
}
function getready(whatzip) {
	//--------------------------------//
	// Browser specific code
	if (window.XMLHttpRequest) {// Non-IE
		req = new XMLHttpRequest();
		if (!req) {alert('XMLHttpRequest object error'); return;}
	} else if (window.ActiveXObject) {// IE
		req = new ActiveXObject("Microsoft.XMLHTTP");
		if (!req) {alert('activex error'); return;}
	}
	//--------------------------------//
	// Get the values to send, set up the response function (below)
	var args='whattype='+document.getElementById('cFadtype').value+'&whatzip='+whatzip;
	req.onreadystatechange = getpocs;
	req.open("GET", 'http://'+thedomain+'/includes/consultationform.php?'+args, true);
	req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	//--------------------------------//
	// These are the POST variable in n1=v1&n2=v2 format
	req.send(null);
}

// Handles the response from the request sent by getready()
function getpocs() {
	//--------------------------------//
	// only if req shows "loaded"
	if (req.readyState == 4) {// only if "Complete"
		if (req.status == 200) {// only if "OK"
			//alert(req.responseText);
			// Get the values from the XML
			var totalrows = safeGetValue(req,'total',0);
			var pochtml = '<select name="cFadspecific" id="cFadspecific" style="float: none; display: block; width: 97px;">';
			for (i=0;i<=totalrows;i++) {pochtml = pochtml + '<option value="' + safeGetValue(req,'value',i) + '">' + safeGetValue(req,'label',i) + '</option>';}
			pochtml = pochtml + '</select>';
			if (totalrows > 0) {
				document.getElementById('cFadspecificdiv').style.display = 'block';
				document.getElementById('cFadspecificdiv').innerHTML = pochtml;
			} else {
				document.getElementById('cFadspecificdiv').style.display = 'none';
			}
			if (safeGetValue(req,'zipcoderegionid',0) > 0) {
				document.getElementById('cFschedulingdiv').style.display = 'block';
				document.getElementById('cFschedulenow').style.display = 'block';
				document.getElementById('cFrequestcall').style.display = 'none';
			} else {
				document.getElementById('cFschedulingdiv').style.display = 'none';
				document.getElementById('cFschedulenow').style.display = 'none';
				document.getElementById('cFrequestcall').style.display = 'block'
			}
		} else {
			alert("There was a problem retrieving the XML data:\n" + req.statusText);
		}
	}
}

// gets an XML value
function safeGetValue(req,tagName,i) {
	try {var nodeValue = req.responseXML.getElementsByTagName(tagName)[i].childNodes[0].nodeValue;}
	catch (e) {if(e['name']== 'TypeError') {nodeValue='';}}
	return nodeValue;
}
