function disablePeopleInputs() {
	o = document.frmcitymatch;
	o.email.readOnly = true;
	o.salute.readOnly = true;
	o.first_name.readOnly = true;
	o.last_name.readOnly = true;
	o.mid_name.readOnly = true;
	o.degree.readOnly = true;
	o.title.readOnly = true;
	o.organization.readOnly = true;
	o.address1.readOnly = true;
	o.address2.readOnly = true;
	o.city.readOnly = true;
	o.state.readOnly = true;
	o.zip1.readOnly = true;
	o.zip2.readOnly = true;
	o.phone1.readOnly = true;
	o.phone2.readOnly = true;
	o.phone3.readOnly = true;
	o.extension.readOnly = true;
	o.fax1.readOnly = true;
	o.fax2.readOnly = true;
	o.fax3.readOnly = true;
	o.website.readOnly = true;
}
function enablePeopleInputs() {
	o = document.frmcitymatch;
	o.email.readOnly = false;
	o.salute.readOnly = false;
	o.first_name.readOnly = false;
	o.last_name.readOnly = false;
	o.mid_name.readOnly = false;
	o.degree.readOnly = false;
	o.title.readOnly = false;
	o.organization.readOnly = false;
	o.address1.readOnly = false;
	o.address2.readOnly = false;
	o.city.readOnly = false;
	o.state.readOnly = false;
	o.zip1.readOnly = false;
	o.zip2.readOnly = false;
	o.phone1.readOnly = false;
	o.phone2.readOnly = false;
	o.phone3.readOnly = false;
	o.extension.readOnly = false;
	o.fax1.readOnly = false;
	o.fax2.readOnly = false;
	o.fax3.readOnly = false;
	o.website.readOnly = false;
}
function readPeople(email) {
	if (checkEMail(email)) {
		var o = document.getElementById("email_status");
		o.style.display = "";
		disablePeopleInputs();
		url  = "calls/read_people.php?email="+escape(email);
		http_request = getHTTPObject();
		http_request.onreadystatechange = onGetCommentsResponse;
		http_request.open("GET", url, true);
		http_request.send(null);
	}
}

//handle xmlHTTP onreadystatechange event
function onGetCommentsResponse() {
	if(http_request.readyState == 4) {
		if (http_request.responseText!="INVALID") {
			var xmlDocument;
			if (document.all) {
				xmlDocument = new ActiveXObject("Microsoft.XMLDOM");
				xmlDocument.loadXML(http_request.responseXML.xml);
				people = xmlDocument.documentElement;
			} else {
				xmlDocument = http_request.responseXML;
				people = xmlDocument.firstChild;
			}
			o = document.frmcitymatch;
			o.pid.value = people.attributes ? people.attributes[0].value : "";
			if (people.attributes) {
				var salute =  String(people.attributes[1].value);
				var found = false;
				for (var i=0; i<o.salute.options.length; i++) {
					if (o.salute.options[i].value==salute) {
						o.salute.selectedIndex = i;
						found = true;
						break;
					}
				}
				if (!found) {
					o.salute.options[0].selected = true;
				}
			} else {
				o.salute.options[0].selected = true;
			}
			o.first_name.value = people.attributes ? String(people.attributes[2].value) : "";
			o.last_name.value = people.attributes ? String(people.attributes[3].value) : "";
			o.mid_name.value = people.attributes ? String(people.attributes[4].value) : "";
			o.degree.value = people.attributes ? String(people.attributes[5].value) : "";
			o.title.value = people.attributes ? String(people.attributes[6].value) : "";
			o.organization.value = people.attributes ? String(people.attributes[7].value) : "";
			o.address1.value = people.attributes ? String(people.attributes[8].value) : "";
			o.address2.value = people.attributes ? String(people.attributes[9].value) : "";
			o.city.value = people.attributes ? String(people.attributes[10].value) : "";
			o.state.value = people.attributes ? String(people.attributes[11].value) : "";
	
			zip = people.attributes ? String(people.attributes[12].value) : "";
			zips = zip.split("-");
			o.zip1.value = zips.length>0 ? zips[0] : "";
			o.zip2.value = zips.length>1 ? zips[1] : "";
			
			phone = people.attributes ? String(people.attributes[13].value) : "";
			phone = phone.replace("(", "");
			phone = phone.replace(") ", "-");
			phones = phone.split("-");
			o.phone1.value = phones.length>0 ? phones[0] : "";
			o.phone2.value = phones.length>1 ? phones[1] : "";
			o.phone3.value = phones.length>2 ? phones[2] : "";

			o.extension.value = people.attributes ? String(people.attributes[14].value) : "";

			fax = people.attributes ? String(people.attributes[15].value) : "";
			fax = fax.replace("(", "");
			fax = fax.replace(") ", "-");
			faxs = fax.split("-");
			o.fax1.value = faxs.length>0 ? faxs[0] : "";
			o.fax2.value = faxs.length>1 ? faxs[1] : "";
			o.fax3.value = faxs.length>2 ? faxs[2] : "";

			o.website.value = people.attributes ? String(people.attributes[16].value) : "";
		}
		enablePeopleInputs();
		var o = document.getElementById("email_status");
		o.style.display = "none";
	}
}

function getHTTPObject() {
	var o;
	try {
		if(window.XMLHttpRequest) {
			o = new XMLHttpRequest();
		} else {
			o = new ActiveXObject("Microsoft.XMLHTTP");
		}
	} catch(e) {
		o = false;
	}
	return o;
}
