// EMAIL SCRAPING PREVENTION
// Protect Inline Email Addresses from Scraping
function sendMailTo(name, company, domain){
    locationstring = "mai" + "lto:" + name + "@" + company + "." + domain;
    window.location.replace(locationstring);
}

// Javascript Print Function for Print This Page links
function printdoc() {
	window.print();
}

// EXTERNAL LINKS HANDLER
// Open link in new window, without status message
function newWindow(url) {
		window.open(url, null,"");
}
// Open status message, if user clicks "Confirm", then open in new window
function confirmExit(url) {
	var retString = "You are about to leave the website" + '\n\n' + "Are you sure you wish to do so?";
	var answer = confirm (retString);
	if (answer) {
		window.open(url, null,"");
	}
}
function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
			anchor.setAttribute("href", "javascript:newWindow('" + anchor.getAttribute("href") + "');" );
		}
	}
}
window.onload = externalLinks;

// JQUERY IMAGE REPLACEMENT
// Replaces text in resultsstatus div with image
var $j = jQuery.noConflict();
$j(document).ready(function() {
	$j('div.resultsstatus').each(function() {
	  string = $j(this).text();
	  filename = string.toLowerCase().replace(/ /g, '-').replace(/([^0-9a-z-])/g,'');
	  $j(this).html('<img src="/template/jbrhomes/images/status-imgs/' + filename + '.png" alt="' + string + '" />');
	});
});
