var ua = navigator.userAgent.toLowerCase();
var isIE = ((ua.indexOf("msie") != -1) && (ua.indexOf("opera") == -1) && (ua.indexOf("webtv") == -1));
iconEventHandler();
function iconEventHandler (){
	if (document.addEventListener){
		// Intelligent browsers
		document.addEventListener("click", clickIcon , true);
	} else if (document.attachEvent) {
		// That beautiful browser IE
		document.attachEvent("onclick", clickIcon);
	}
}
function clickIcon (e) {
	var origElement;
	if (!e) e = window.event;
	if (e.srcElement){
		origElement = e.srcElement;
	} else if (e.target){
		origElement = e.target;
	} else {
		return;
	}

	if ( e.ctrlKey == false && e.type == "click" && e.button == 0){
		if(origElement.getAttribute("id") == "mailjaxclick" || origElement.getAttribute("id") == "mailjaxclicktext"){ 
			var altTop;
			var altLeft;
			if (isIE){
				altTop = document.body.scrollTop;
				altLeft = document.body.scrollLeft;
			} else {
				altTop = window.pageYOffset;
				altLeft = window.pageXOffset;				
			}
			//document.getElementById('emailjaxform').style.left = e.clientX + altLeft + 'px';
			//document.getElementById('emailjaxform').style.top = e.clientY + altTop + 'px';
			document.getElementById('emailjaxform').style.visibility = "visible";
			eventOff();
		} else if (origElement.getAttribute("id") == "jaxmailcancel" ){
			document.getElementById('emailjaxform').style.visibility = "hidden";
			eventOff();
		} else if (origElement.getAttribute("id") == "jaxmailsubmit"){
			var stuff = '<html>' + document.getElementById("container").innerHTML + '</html>';
			var from = document.getElementById('fromjaxmail').value;
			var to = document.getElementById('tojaxmail').value;
			var url = window.location.href.replace(/\#+/,"");
			var pg = url.match(/pg\=[\d]+/i);
			var lf = url.match(/lf\=[\d]+/i);
			var fromcheck = from.match(/^[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$/i);
			var tocheck = to.match(/^[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$/i);
			if (tocheck == null){
				alert("Please supply a valid email address for the recipient.");
				if (document.getElementById('tojaxmail').scrollIntoView()) { document.getElementById('tojaxmail').scrollIntoView(); }
				eventOff();
				return;
			}
			if (fromcheck == null){
				alert("Please supply a valid email as your sending address.");
				if (document.getElementById('fromjaxmail').scrollIntoView()) { document.getElementById('fromjaxmail').scrollIntoView(); }
				eventOff();
				return;				
			}
			var point;
			if (pg && lf){
				point = '&' + pg[0] + '&' + lf[0];
			} else {
				point = '';
			}
			var data = "site=" + encodeURIComponent(url) +"&sid="+Math.random() + point + '&tomail=' + to + '&frommail=' + from + '&pgcontent=' + encodeURIComponent(stuff);
			dispatchXmlHttpFormObject( displayReturn, url, data );
			document.getElementById('emailjaxform').style.visibility = "hidden";
			eventOff();
		} else if (1){
		} else {
			return;
		}
	}
	function eventOff() {
		if (e.stopPropagation) {
			e.stopPropagation();
			e.preventDefault();
		} else {
			e.cancelBubble = true;
			e.returnValue = false;
		}
	}
}
function displayReturn(){
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ 
		//alert(xmlHttp.responseText);
		
	} 
}
function createBookmarkLink(title) {
	url = window.location;
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite( url, title); }
	else if(window.opera && window.print) { // Opera Hotlist
		return true; 
	}
}
