// Hide actual e-mail addresses from spider programs harvesting e-mail addresses
function clickToEmail(user,domain,suffix) {
	var punct = "@";
	var linktxt = user + punct + domain + "." + suffix;
	document.write("<a href=" + "mai" + "lto:" + linktxt + ">" + " Click here to e-m" + "ail" + "</a>");
}

function hasAttribute(tag, attrName) {
	// Untested
	var attrs = tag.attributes;
	if (attrs.length==0) {
		return false;
                }
	if (!attrs.getAttribute(attrName)) {
		// covers both null return or empty string -- browser behavior is inconsistent
		// This approach works in DOM in general, not always in general Javascript
		return false;
	}
	return true;
}

function getPageMetaDesc() {
	//Get page description from meta tag. If no description is present, return an empty string.
	// Assumes first tag named description is best, expected to be a meta tag
	var tagsNamedDesc = document.getElementsByName("description");
                if (!tagsNamedDesc) {
		return "";		
                }
	var desc = tagsNamedDesc[0].getAttribute("CONTENT");	
                if (!desc) {
		return "";
	}
	return desc;	
}

function getBestPageDesc() {
	// Best page description, searching in order for meta description, <H1> tag, or title 
	// WARNING: when using this result in mailTo URLs, LinkedIn, etc., escape() it first!  
	var summary = getPageMetaDesc();
	if (summary.length > 0) {
		return summary + ".  ";
                }
	// Get the text of the first <h1> tag as the summary
	var hdrs = document.getElementsByTagName("h1");
	if (!hdrs.length) {
		summary=title;
	} else { 
		summary= hdrs[0].innerHTML;
                }
	// Adding period to tell if this script ran, or the basic HTML ran  - don't use period there
	alert("TEST getBestPageDesc: summary = " + summary + ".  ");
	return summary + ".  ";
}

function emailThisPage() { 
	// don't forget to return false in the calling link if it has basic html e-mailing
                var toAddress = "";
	var subj = escape("Interesting web page -- " + document.title);
	var bod= escape("I found this interesting web page -- " + document.title + " -- at \n ")  
		+ encodeURIComponent( location.href) 
		+ escape("\n\nA description is --\n" + getBestPageDesc() + "  \n\n") ;
	var newLink = "mailto:" + toAddress + "?subject=" + subj + "&body=" + bod;
	location.href = newLink;	
}

function sharePageDelicious() {
	window.open('http://www.delicious.com/save?v=5&noui&jump=close&url='+encodeURIComponent (location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,scrollbars=yes,resizable=yes,width=740,height=550'); 

}

function sharePageLinkedIn() {
	// Shares via LinkedIn, using page title, and first <h1> tag as the summary.
	// Don't forget to return false in the calling link if it has basic HTML functionality overidden by this. 
                var siteUrl = "http://www.linkedin.com/shareArticle";
                var pageUrl = encodeURIComponent( location.href);
	var title = escape(document.title);
	var summary = escape(getBestPageDesc());
	var source = escape("Greg Stanley and Associates web site");
	var newLink = siteUrl + "?mini=true" + "&url=" +  pageUrl + "&title=" + title + "&summary="  + summary  + "&source=" + source;
	// Keep the following all on one line, with no spaces!  
	window.open(newLink,'LinkedIn','width=570,height=570,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes');

}






