

var URLClickedOn = "";

function documentEvent(e) 
{
	var answer = true;
	var elem = null;
	var elemSrc = "";
	
	if(!e)
		e = window.event;
	
	if(navigator.appName == 'Netscape') 
	{
		elemSrc = e.target.toString();
		elem = e.target;
	
		if(elem.toString().indexOf("Image") >= 0) 
		{
			elem = elem.parentNode;
			elemSrc = elem.toString();
		}	
	}
	else
	{
		elem = e.srcElement;
		
		if(e.srcElement.href)
			elemSrc = e.srcElement.href;
		else 
			elemSrc = "";
			
		if(elemSrc.length > 0) 
		{
			//Check to see if we have a image or a link.
			if(elemSrc.indexOf("jpg") >= 0 || elemSrc.indexOf("gif") >= 0 || elemSrc.indexOf("png") >= 0) {
				//Figure out if the parent element is a hyper link or not.
				elem = elem.parentNode;
	
				if(elem.href)
					elemSrc = elem.href;
				else
					elemSrc = "";
			}
		}	
	}

	elemSrcOrig = elemSrc;
	elemSrc = elemSrc.toLowerCase();

	if(elemSrc.length > 0) 
	{		
        // check to see if a url has been clicked
        // we will probably need to test this for mailto: link etc

		// Per client:  eStore link ("http://www.gohands.com") should open in the same window and not have the leaving site disclaimer.
        if ((elemSrc.indexOf("http") >= 0)  && (elemSrc.indexOf("gohands") < 0))
        {
            // if the local url isn't included
            //if (elemSrc.indexOf("mosshogg") < 0)
            if (
				(elemSrc.indexOf("mosshogg") < 0) && 
				(elemSrc.indexOf("abcstaging") < 0) && 
				(elemSrc.indexOf("almondboard") < 0) && 
				(elemSrc.indexOf("almond-board") < 0) && 
				(elemSrc.indexOf("199.199.209.134") < 0)
				(elemSrc.indexOf("californiaalmonds.co.uk") < 0)
				)
            {
				//var disclaimerBox = document.getElementById("disclaimerBox");
				//disclaimerBox.style.visibility = 'block';
				SectionOpenClose('disclaimerBox','open');
				scroll(0,0);
				URLClickedOn = elemSrcOrig;
				answer = false;
                // alert the user - popup a new window, give them a dialog, whatever
                //answer = confirm("you're now leaving the almond board site");
            }
        }

        //window.routeEvent(e);
        return answer;
    }
}

// adding a global event handler, these may need to be adjusted to account for exising event handlers from MOSS
//document.captureEvents(Event.CLICK);
document.onclick = documentEvent;

function leaveSite(leave) 
{
	var eStoreLink = 0;
	if(leave)
	{
		// Per client:  eStore link ("http://www.gohands.com") should open in the same window and not have the leaving site disclaimer.
		eStoreLink = URLClickedOn.indexOf("gohands.com");

		if (eStoreLink > 0)
			window.location = URLClickedOn;
    	else
    		window.open(URLClickedOn);
    }
		
	SectionOpenClose('disclaimerBox','close');	
}

