function emailPop(email,title){
	window.open('/emailWindow/email.php?email='+email+'&title='+title, 'emailform', 'width=530,height=390');	
}


function buildEmailPopups() {
	var emailLinks = new Array();
	var popLink = false;
	if (!document.createElement) return;
	var linkType = /mailto:/;
	//var ourDomain = /perryjohnson/i;
	var ourDomain = window.location.host;
	hostArray = ourDomain.split(".");
	ourDomain = hostArray[hostArray.length-2]+"."+hostArray[hostArray.length-1];
	ourDomain = eval("/"+ourDomain+"/i");
	
	anchors = document.getElementsByTagName("a");
		for (a=0;a<anchors.length;a++) {
		var link = anchors[a];
		// test if this is an email link and within our domain
		
		if ( (link.href.search(linkType) > -1)) {
			// add this to only search within ourDomain
			//  && ( link.href.search(ourDomain) > -1)
			//alert(link.href.replace('mailto:',''));
			link.onclick = function(){emailPop(this.href.replace('mailto:',''),this.title);return false;};
			/*
			new Ajax.Request('/emailWindow/checkSafeList.php', {method:'get',asynchronous:true,parameters:'email='+link.href.replace('mailto:','')+'&thatvar=Howdy',onSuccess:handleResponse, onFailure:function(){ } });
			//checkSafeList = new Ajax.Request('/emailWindow/checkSafeList.php', { method:'get',asynchronous:true, parameters:'email=$(\'perry@perryjohnson.info\')', onSuccess:function(){alert('successful')} });
			if(popLink == true){
			*/	
			}
		}		
	}
/*
function handleResponse(resp){
	if(resp.responseText.match('true')){
		popLink = true;
		link.onclick = function(){emailPop(this.href.replace('mailto:',''),this.title);return false;};
	}else if(resp.responseText.match("false")){
		popLink = false;
	}
}
}
*/





function addLoadHandler(handler)
{
	if(window.addEventListener)
	{
		window.addEventListener("load",handler,false);
	}
	else if(window.attachEvent)
	{
		window.attachEvent("onload",handler);
	}
	else if(window.onload)
	{
		var oldHandler = window.onload;
		window.onload = function piggyback()
		{
			oldHandler();
			handler();
		};
	}
	else
	{
		window.onload = handler;
	}
}
addLoadHandler(function(){ buildEmailPopups();});

function checkSafeListCallback(input){
	alert(input);	
}
