/*
 * AddIntelligence Identificação | Client Side | Versão 1.0
 */
 
//global
var addi_cliente_iddefault = 1;
 
function carregaAddIntelligence(url_acessorestrito)
{
	var function_reload = "carregaAddIntelligence('" + url_acessorestrito + "');";

	if (document.getElementById("ifrAddIntelligence"))
	{
		try
		{
			var link = document.getElementById("ifrAddIntelligence").contentWindow.location.href;
			link = link.replace(url_acessorestrito + '?','');

			var temp = new Array();
			temp = link.split('@');

			if (temp.length == 7)
			{
				document.getElementById("addi_campanha").value = URLDecode(temp[0]);
				document.getElementById("addi_grupo").value = URLDecode(temp[1]);
				document.getElementById("addi_peca").value = URLDecode(temp[2]);
				document.getElementById("addi_portal").value = URLDecode(temp[3]);
				document.getElementById("addi_canal").value = URLDecode(temp[4]);
				document.getElementById("addi_pagina").value = URLDecode(temp[5]);
				document.getElementById("addi_espaco").value = URLDecode(temp[6]);
			}
					
			if(document.getElementById("addi_idpublicacao").value == '')
				setTimeout(function_reload,1000);
		}
		catch(err)
		{
			setTimeout(function_reload,1000);
		}
    }
    else
    {
		setTimeout(function_reload,1000);
	}
}



function preparaAddIntelligence(nomeloja, url_acessorestrito) 
{
	var function_reload = "preparaAddIntelligence('" + nomeloja + "','" + url_acessorestrito + "');";

	if (document.getElementById("ifrAddIntelligence"))
	{
		document.getElementById("ifrAddIntelligence").contentWindow.location.href = 'https://servico.addintelligence.com.br/ContentServer/identificacao/addi_identificacao.asp?loja=' + nomeloja + '&url_loja_acessorestrito=' + url_acessorestrito + '&iddefault=' + addi_cliente_iddefault;
		carregaAddIntelligence(url_acessorestrito);
	}
	else
	{
		setTimeout(function_reload,1000);
	}
}

function URLDecode(psEncodeString)
{
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  return unescape(String(psEncodeString).replace(lsRegExp, " "));
}

