var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


function outgoing_links()
{
	var links = document.getElementsByTagName("a");
	var urlRe = new RegExp("https?:\/\/((www\.)?)([a-zA-Z0-9\\_\\-\\.]*)\.([a-zA-Z]{1,5})/");
	for(var i=0;i<links.length;i++) 
    {
    	if (links[i].onclick == undefined)
		{
        	fullPath = links[i].href.toLowerCase();
			last4 = fullPath.substring(fullPath.length-4, fullPath.length);
            if (links[i].href.toLowerCase().indexOf("mailto:") > -1)
           	{
            	
           		links[i].onclick=function()
                {
                	href = this.href.toLowerCase();
                    emailLink = href.replace("mailto:","");
                    _gaq.push(['_trackEvent', 'Mails', 'Click', emailLink]);
                };
           	}
            else if(links[i].href.toLowerCase().indexOf("adkgetaways.com") == -1 && urlRe.test(links[i].href))
            {
            	links[i].onclick=function()
                {
                	href = this.href.toLowerCase();
					newlocation = this.href;
					
					if( this.target != '_blank' )
						this.removeAttribute("href");
                    re = /^https?:\/\/(www\.)?([^/]+)?/i;
                    href.match( re );
                    domainOnly =  RegExp.$2;
                    _gaq.push(['_trackEvent', 'Outgoing links', 'Click', domainOnly]);
					if( this.target != '_blank' )
						setTimeout('document.location = "' + newlocation + '"', 200);
                };
           	}
            else if( last4 == ".pdf" )
           	{
            	links[i].onclick=function()
                {
                	href = this.href;
                    splhref = href.split('/');
                    fileOnly = splhref[splhref.length-1];
                    _gaq.push(['_trackEvent','Downloads', 'PDF', fileOnly]);
                  };
             }
             else if( last4==".doc" )
           	{
            	links[i].onclick=function()
                {
                	href = this.href;
                    splhref = href.split('/');
                    fileOnly = splhref[splhref.length-1];
                    _gaq.push(['_trackEvent','Downloads', 'DOC', fileOnly]);
                  };
             }
                 
		}
	}
}

window.onload = function()
{
	outgoing_links();	
}
