/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
function XHConn () {
	var xmlhttp, bComplete = false;
	try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
	catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
	catch (e) { try { xmlhttp = new XMLHttpRequest(); }
	catch (e) { xmlhttp = false; }}}
	if (!xmlhttp) return null;
	this.connect = function(sURL, sMethod, sVars, fnDone) {
		if (!xmlhttp) return false;
		bComplete = false;
		sMethod = sMethod.toUpperCase();
		
		try {
			if (sMethod == "GET") {
				xmlhttp.open(sMethod, sURL+"?"+sVars, true);
				sVars = "";
			} else {
				xmlhttp.open(sMethod, sURL, true);
				xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
				xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			}
			xmlhttp.onreadystatechange = function() {
				if (xmlhttp.readyState == 4 && !bComplete) {
				  bComplete = true;
				  fnDone(xmlhttp);
				}
			};
			xmlhttp.send(sVars);
		} catch(z) { 
			return false; 
		}
		return true;
	};
	return this;
}//

/** ########## **/

function xh_result (objID, php, paramstr) {
	var myConn;
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) {
		var target = getObj (objID);
		target.innerHTML = oXML.responseText;
	}
	myConn.connect(php,"POST",paramstr, fnWhenDone);		
}// 

function xh_zipsearch (targetObjID, what) {
	var myConn;
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var fnWhenDone = function (oXML) {
		rt0 = oXML.responseText;
		a = rt0.split('#_#');
		
		var target = getObj (targetObjID);
		var oC = getObj ('fd_clreg[city]');

		if (a[0]==1) {
			oC.value=a[1];
			target.innerHTML = "";
			target.style.display="none";
		} else if (a[0]==2) {
			oC.value="";
			target.style.display="block";
			target.innerHTML = a[1]; 			
		} else if (a[0]==0) {	
			target.style.display="none";
			target.innerHTML = ""; 
		}
	}
	myConn.connect("/xh_zipsearch.php","POST","z="+what, fnWhenDone);			
}

function set_objID_value (obj, v) {
	if ( o = getObj(obj) ) {
			o.value = v;
	}
}

function xh_set_sel (x_str) {
	a  =  x_str.split("##|##");
	getObj('fd_clreg[zip]').value = a[0];
	getObj('fd_clreg[city]').value = a[1];
}

