var EXBrowserUtil = new function(){
	
	/** Check if the client is IE */
	this.isIE = function(){return (navigator.appName.indexOf("Internet Explorer") >= 0);}

	/** Check if the client is IE7 */
	this.isIE7 = 
		function(){
			var verSTR = navigator.appVersion;
			if (verSTR != null && verSTR.indexOf("MSIE") >= 0)
			{
				var index_version_number = verSTR.indexOf("MSIE ")+5;
				var verNum = parseInt(verSTR.substring(index_version_number,index_version_number+1));
				return(verNum>=7);
			}
			return false;
		}
	
	/** Check if the client is Mozzila */
	this.isMozzila = function(){return (navigator.appName.indexOf("Netscape") >= 0);}

    this.attachEvent = function(eventName,functionElement,element){
        if (element == null){
            element = window;
        }
        
	    if (EXBrowserUtil.isIE()){
		    element.attachEvent("on"+eventName,functionElement);
	    }
	    else{
		    element.addEventListener(eventName,functionElement, false);
	    }
    }

	this.elementTop =
		function (element)
		{
			var curtop = 0;
			while (element != null && element.offsetParent != null){
				curtop += element.offsetTop
				element = element.offsetParent;
			}
			return curtop;
		}

	this.elementLeft = 
		function (element)
		{
			var curleft = 0;
			while (element != null && element.offsetParent != null){
				curleft += element.offsetLeft
				element = element.offsetParent;
			}
			return curleft;
		}
	this.elementWidth =
		function (element){
			if(element == null){
				return null;
			} 
			return element.offsetWidth;
	}

	this.elementHeight =
		function (element){
			if(element == null){
				return null;
			} 
			return element.offsetHeight;
	}
	

	this.querySt = 
		function(ji) {
		hu = window.location.search.substring(1);
		gy = hu.split("&");
		for (i=0;i<gy.length;i++) {
			ft = gy[i].split("=");
			if (ft[0] == ji) {
				return ft[1];
			}
		}
	}

}

function locateLink(){
	var marker = document.createElement("table");

	var row1 = marker.insertRow(0);
	var cell_1 = row1.insertCell(0);
	cell_1.colspan = 2;

	row2 = marker.insertRow(1);
	cell_21 = row2.insertCell(0);
	cell_22 = row2.insertCell(1);

	cell_21.innerHTML = "Powered by <a href='http://www.exchanges.net/_add-find-link.aspx' target='_blank'>exchanges.net</a>";
	cell_21.style.whiteSpace = "nowrap";
	cell_21.title = "Click to find how to add this tool to your site";
	
	
	cell_21.style.backgroundColor = "white";
	cell_21.style.width = "100px";
	cell_21.style.fontWeight = "bold";

//	cell_22.innerHTML = "<a href='http://www.exchanges.net' target='_blank'>Add this tool to your site</a>";
//	cell_21.style.whiteSpace = "nowrap";

	marker.style.border = "4px solid green";
	marker.style.position = "absolute";
	marker.style.width = "100px";
	marker.style.height= "50px";
	
	document.body.appendChild(marker);

	var anchors = document.getElementsByTagName("a");
	var urlToFind = EXBrowserUtil.querySt("exlink");

	if (urlToFind == null) {
	    marker.style.display = "none";
	    return;
	}

	for(var i=0;i<anchors.length;i++){
		var anchor = anchors[i];
		if (anchor.href.indexOf(urlToFind) >= 0)
		{
		    var top = (EXBrowserUtil.elementTop(anchor) -10) + "px";
			marker.style.top = top;
			
            var left = (EXBrowserUtil.elementLeft(anchor) - 5) + "px";
			marker.style.left = left;
			
			var width = (EXBrowserUtil.elementWidth(anchor) + 50) + "px";
			marker.style.width = width;
			
			row1.style.width = width;
			
			var height = (EXBrowserUtil.elementHeight(anchor) + 20) + "px";
			row1.style.height = height;

			var markerTop = marker.style.top;
			markerTop = markerTop.substr(0,markerTop.length-2);

			window.scrollBy(0,markerTop);

			SetOpacity(document.body, 90);
			SetOpacity(anchor, 100);
			break;
		}
	}
}

function SetOpacity(elem, opacityAsInt){
	var opacityAsDecimal = opacityAsInt;
    
    if (opacityAsInt > 100)
        opacityAsInt = opacityAsDecimal = 100; 
	else if (opacityAsInt < 0)
       opacityAsInt = opacityAsDecimal = 0; 
    
    opacityAsDecimal /= 100;

    if (opacityAsInt < 1)
        opacityAsInt = 1; // IE7 bug, text smoothing cuts out if 0
    
    elem.style.opacity = (opacityAsDecimal);
    elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

EXBrowserUtil.attachEvent("load",locateLink);

