var arrTags = 
[
	{google:"Index", predicta:"", addInteligence:""},
	{google:"Index/PreHome", predicta:"", addInteligence:""},
	{google:"Index/PreHome/ClickEntenda", predicta:"", addInteligence:""},
	{google:"Index/PreHome/ClickAssine", predicta:"", addInteligence:""},
	{google:"Index/Loading", predicta:"", addInteligence:""},
	{google:"Index/Video", predicta:"", addInteligence:""},
	{google:"Index/Video/ClickSkip", predicta:"", addInteligence:""},
	{google:"Index/Video/Completo", predicta:"", addInteligence:""},
	{google:"Index/Corrente", predicta:"", addInteligence:""},
	{google:"Index/Corrente/Busca", predicta:"", addInteligence:""},
	{google:"Index/Participe", predicta:"", addInteligence:""},
	{google:"Index/Participe/Cadastro", predicta:"", addInteligence:""},
	{google:"Index/Participe/Cadastro/EnviadoComFoto", predicta:"", addInteligence:""},
	{google:"Index/Participe/Cadastro/EnviadoSemFoto", predicta:"", addInteligence:""},
	{google:"Index/Participe/Cadastro/EnviadoClickVerCorrente", predicta:"", addInteligence:""},
	{google:"Index/Convite", predicta:"", addInteligence:""},
	{google:"Index/Convite/EnvioOk", predicta:"", addInteligence:""},
	{google:"Index/Entenda", predicta:"", addInteligence:""},
	{google:"Index/LinkFilieSe", predicta:"", addInteligence:""},
];
// Quando aplicar no site, utilizar trackDebug = false;
var trackDebug = false;

// Quando as popups forem abertas sem nome, utilizamos este contador para o nome
var nWindowCount = 0;
var objOpener = null;

function getTag ( strGoogleTag, strReturnTag )
{
	for( var i=0; i<arrTags.length; i++ ) 
	{
		if (arrTags[i].google == strGoogleTag)
		{
			return arrTags[i][strReturnTag];
		}
	}
	return "";
}


function track( arParams )
{
	strTag = arParams[0];
	strURL = arParams[1];
	strWindow = arParams[2];
	nWidth = arParams[3];
	nHeight = arParams[4];
	booFocus = arParams[5];	
	
	
	if(strTag == "null" || strTag == "undefined") strTag = "";
	if(strURL == "null" || strURL == "undefined") strURL = "";
	if(strWindow == "null" || strWindow == "undefined") strWindow = "";
	if(nWidth == "null" || nWidth == "undefined") nWidth = "";
	if(nHeight == "null" || nHeight == "undefined") nHeight = "";
	if(booFocus == "null" || booFocus == "undefined") booFocus = null;
	booFocus = Boolean( booFocus );
	
	// Predicta
	var strPredictaTag = getTag(strTag, "predicta");
	if (strPredictaTag!="")
	{
		void( atmCLL(strPredictaTag) );
		if ( trackDebug ) alert( strPredictaTag );
	}
	/*
	// addInteligence
	var strAddInteligenceTag = getTag(strTag, "addInteligence");
	if (strAddInteligenceTag!="")
	{
		alert("Image tracker missing.\n AddInteligence won't work");
	}
	else
	{
		void( document.getElementById("image_tracker").src = strAddInteligenceTag );
		if ( trackDebug ) alert( strAddInteligenceTag );
	}*/

	
	// google analytics
	void( urchinTracker(strTag) );
	if ( trackDebug ) alert( strTag );
	if ( strURL )
	{
		switch ( strWindow )
		{
			case "pop_full":
				var objWindow = openPopupWindow(strURL);
				if (booFocus) objWindow.focus();
				break;
			
			case "pop":
				var objWindow = openPopupWindow(strURL, null, nWidth, nHeight);
				if (booFocus) objWindow.focus();
				break;
			
			case "_blank":
				var objWindow = window.open( strURL );
				if (booFocus) objWindow.focus();
				break;
				
			case "opener":
				try
				{
					window.opener.location.href = strURL;
					if (booFocus)
					{
						window.opener.focus();						
					}
				}
				catch(e)
				{
					try
					{
						objOpener.location.href = strURL;
						if (booFocus)
						{
							objOpener.focus();						
						}
					}
					catch(e)
					{
						objOpener = window.open(strURL, "_blank");
						if (booFocus)
						{
							objOpener.focus();						
						}
					}					
				}
				break;
		
			default:
				window.location = strURL;
		}				
	}
}



function openPopupWindow( strURL, strWindowName, nWidth, nHeight, booScrollBars )
{
	if (!strWindowName)
	{
		strWindowName = "window_" + nWindowCount;
		nWindowCount++;
	}
	
	if (!nWidth && !nHeight) booFull = true;

	nWidth = (nWidth) ? nWidth : screen.availWidth - 7;
	nHeight = (nHeight) ? nHeight : screen.availHeight - 8;	

	strScrollBars = (booScrollBars) ? "yes" : "no";
	
	var nLeft = (booFull) ? 0 : ( (window.screen.width  - nWidth) / 2 );
	var nTop =  (booFull) ? 0 : ( (window.screen.height - nHeight) / 2 );
	
	var strWindowsFeatures = 'leftmargin=0, topmargin=0, marginheight=0, marginwidth=0, toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars='+strScrollBars+', resizable=no, top='+nTop+', left='+nLeft+', screenX='+nLeft+', screenY='+nTop+', copyhistory=no, width='+nWidth+', height='+nHeight;
	
	var objWindow = window.open( strURL, strWindowName, strWindowsFeatures);
	return objWindow;
}