// Copyright (c) 2003, Android Technologies, Inc. All rights reserved.

var gListingId = -1; // Each page must provide it's own FindWhat listing id.
// var gWaitForImgchk = false;
var gDebug = false;

var gClicked = new Array();

// ---------------------------------------------------------------

function isHyperLink(htmlElement)
{
	if (htmlElement)
	{
		// Check element itself.
		if (
			(htmlElement.tagName == "A") ||
			(htmlElement.tagName == "a")
		   )
			return htmlElement;
				
		// Check parent of element.		
		if (htmlElement.parentElement)
		{
			if (
				(htmlElement.parentElement.tagName == "A") ||
				(htmlElement.parentElement.tagName == "a")
			   )	
				return htmlElement.parentElement;
		}
	}
	
	return null;
} // function isHyperLink(htmlElement)

function onClick(e)
{
	if (gDebug)
		alert("onclick!")
		
	if (!e)
		// Internext Explorer, get event from global window
		//  event property.
		e = window.event;
		
	// If it is a hyperlink, display the current document,
	//  the referring document, and the text of the
	//  hyperlink, and it's href property.
	var hyperLinkElement = isHyperLink(e.srcElement);
	if (hyperLinkElement)
	{
		/*
		var S = "doc: " + document.location.href;
		S += "\n";
		S += "ref : " + document.referrer; 
		S += "\n";
		S += "href: " + hyperLinkElement.href;
		S += "\n";
		S += "text: " + hyperLinkElement.innerText;
		S += "\n";
		
		alert(S);
		*/
		
		// Stop double-clicking.
		if (gDebug)
			alert("Checking for previous click (iKey).");
		var iKey = escape(hyperLinkElement.href);
		
		if (!gClicked[iKey])
		{
			var ichk =
				document.getElementById("admon");
				
			if (ichk)
			{
				if (gDebug)
						alert("Setting ichk SRC.");
			
				var S  = "http://www.wordblogger.com/service/linkchk.php?";
				    S += "ref=" + document.referrer;
				    S += "&doc=" + document.location.href;
				    S += "&link_text=" + hyperLinkElement.innerText;
				    S += "&link_href=" + hyperLinkElement.href;
				if (gDebug)
					alert("Setting src to " + S + ".")
	
			    ichk.src = S;
	//	var newwin =
	//		 window.open(S,"newwin","left=1,top=1");
			} // if (ichk)
			
			gClicked[iKey] = iKey;
		} // if (!gClicked[hyperLinkElement.href])
	} // if (isHyperLink(e.srcElement))
		
	
	// debugger;
}
		
if (document.addEventListener)
{
	// DOM Level 2 Event model.
	if (gDebug)
		alert("Installing event listener.")
	document.addEventListener("onclick", onClick, true);
}
else if (document.attachEvent)
{
	// Internet Explorer 5.x or greater Event model.
	if (gDebug)
		alert("Attaching event.")
	document.attachEvent("onclick", onClick);
}	

