
function CreateRequestObject() {
	if (navigator.appName == "Microsoft Internet Explorer") {
		return new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		return new XMLHttpRequest();
	}
}

var ajax = CreateRequestObject();

function ExBlock(obj) {
	i = obj.s.indexOf(":");
	if ((i == -1) || (i > 5)) {
		obj.errno = 1;
		return;
	}
	x = obj.s.substring(0,i);
	l = parseInt(x);
	obj.bk = obj.s.substring(i+1,i+l+1);
	obj.s = obj.s.substring(i+l+1,obj.s.length);
}

function bker(s) {
	this.s = s;
	this.bk = "";
	this.errno = 0;
}

function AxRequest(sURL,postparams) {
	if ((ajax.readyState == 0) || (ajax.readyState == 4)) {
		ajax = CreateRequestObject();
		ajax.open("post",sURL,true);
		ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		ajax.onreadystatechange = HandleResponse;
		ajax.send(postparams);
	} else {
		bContinu = confirm("Previous click is not finished processing. Click \'Ok\' to allow it to continue, click \'Cancel\' to cancel it.");
		if (bContinu == false) {
			ajax.abort();
			alert("Operation aborted.");
		}
	}
}

function ChangeTab(property,newtab) {
	AxRequest("ax_feed_tabs.php?property=" + property + String.fromCharCode(38) + "tab=" + newtab);
}

function HandleResponse() {
	if (ajax.readyState == 4) {
		try {
			stx = ajax.status;
		} catch (e) {
			alert (e.name + ": " + e.message); stx = -1;
		}
		if (stx == 200) {
			var sResponse = ajax.responseText;
			o = new bker(sResponse);
			while (o.s != "") {
				ExBlock(o);
				if (o.errno == 1) {
					document.getElementById("ifbyphone_repl").innerHTML = sResponse;
					return;
				}
				sFirst = o.bk;
				ExBlock(o);
				sSecond = o.bk;
				document.getElementById(sFirst).innerHTML = sSecond;
			}
		} else {
			if (stx == -1) {
				alert("Unable to contact the server. Please check your network connection.");
			} else {
				alert("Request failed: Server returned error code " + ajax.status + ": " + ajax.statusText);
			}
		}
	}
}

function SubmitPhoneNumber() {
	btn = document.getElementById("call_btn");
	btn.src="images2/ibp1p.gif";
	postparams = "npa=" + document.getElementById("npa").value + "&nnx=" + document.getElementById("nnx").value + "&line=" + document.getElementById("line").value;
	AxRequest("ax_ifbyphone.php",postparams);
	return false;
}

function autofocs(field, limit, next, evt) {
	evt = (evt) ? evt : event;
	var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
	var nxo = document.getElementById(next);
	if (charCode > 31 && field.value.length == limit) {
		nxo.focus();
	}
}


