
function showPhone(listingid) {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (exc) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (ex) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				xmlhttp = false;
			}
		}
	}
	if (xmlhttp) {
		xmlhttp.open("GET", '../countphoneclick.php?listing_id='+listingid, true);
		xmlhttp.send(null);
	}
	document.getElementById("phoneLink"+listingid).className = "controlPhoneHide";
	var x=document.getElementById("phoneNumber"+listingid);
	var phone_num = x.innerHTML;
	// Format phone number
	x.innerHTML = formatPhoneNumber(phone_num);
	document.getElementById("phoneNumber"+listingid).className = "controlPhoneShow";
}

function showFax(listingid) {
	try {
		xmlhttp = new XMLHttpRequest();
	} catch (exc) {
		try {
			xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (ex) {
			try {
				xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {
				xmlhttp = false;
			}
		}
	}
	if (xmlhttp) {
		xmlhttp.open("GET", '../countfaxclick.php?listing_id='+listingid, true);
		xmlhttp.send(null);
	}
	document.getElementById("faxLink"+listingid).className = "controlFaxHide";
	var x=document.getElementById("faxNumber"+listingid);
	var phone_num = x.innerHTML;
	// Format fax number.
	x.innerHTML = formatPhoneNumber(phone_num);
	document.getElementById("faxNumber"+listingid).className = "controlFaxShow";
}


function formatPhoneNumber(phone_number) {
	// Charles Smalley
	// 2009-09-29 - Added to format phone and faz numbers to standard (###) ###-####

	var phone1 = phone_number;
	phone1=phone1.replace("(","");
        phone1=phone1.replace(")","");
        phone1=phone1.replace("-","");
        phone1=phone1.replace("-","");
        phone1=phone1.replace(" ","");
        phone1=phone1.replace(" ","");
        var phone_out = "(" + phone1.substr(0,3) + ") " + phone1.substr(3,3) + "-" + phone1.substr(6,4);
	return phone_out;


}

