var EnderecoAtual = location.href;
var Referencia = document.referrer;
var PosicaoParametros = 0;
var Parametros = "";
var splitParametros;
var splitSubParametros;
var x = 0;
var NomeParametro = "";
var ValorParametro = "";
var Resultado = "";
var Endereco = "http://www.id360nm.com.br/";
var objAjax;
var ParametroComparativo = "idsite";
var IFrameObj;
var StatusEntrou = false;
var ID_ID360;

window.onerror = DesabilitaErros; 


function DesabilitaErros() { 
   return true; 
} 

function criarCookie(nome,valor,dias) {
   if (dias) {
	  if (dias == 0) {
		 var expiracao = "";
	  } else {		  
         var hoje = new Date();
	     hoje.setTime(hoje.getTime()+(dias*24*60*60*1000));
	     var expiracao = "; expires="+hoje.toGMTString();
	  }
   } else {
	  var expiracao = "";
   }
   document.cookie = nome+"="+valor+expiracao+";";
}
function lerCookie(nome) {
   var nomeEQ = nome + "=";
   var ca = document.cookie.split(';');
   for (var i = 0; i < ca.length; i++) {
	  var c = ca[i];
  	  while (c.charAt(0)==' ') {
	     c = c.substring(1,c.length);
	  }
	  if (c.indexOf(nomeEQ) == 0) {
	     return c.substring(nomeEQ.length,c.length);
 	  }
   }
   return null;
}
function apagarCookie(nome) {
   criarCookie(nome,"",-1);
}	  

function ConectarServidor(URL) {
   if (!document.createElement) {return true};
   var IFrameDoc;
   if (!IFrameObj && document.createElement) {
      try {
         var tempIFrame=document.createElement('iframe');
         tempIFrame.setAttribute('id','RSIFrame');
         tempIFrame.style.border='0px';
         tempIFrame.style.width='0px';
         tempIFrame.style.height='0px';
         IFrameObj = document.body.appendChild(tempIFrame);      
         if (document.frames) {
            IFrameObj = document.frames['RSIFrame'];
         }
      } catch(exception) {
         iframeHTML='\<iframe id="RSIFrame" style="';
         iframeHTML+='border:0px;';
         iframeHTML+='width:0px;';
         iframeHTML+='height:0px;';
         iframeHTML+='"><\/iframe>';
         document.body.innerHTML+=iframeHTML;
         IFrameObj = new Object();
         IFrameObj.document = new Object();
         IFrameObj.document.location = new Object();
         IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
         IFrameObj.document.location.replace = function(location) {
            this.iframe.src = location;
         }
      }
   }
  
   if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
      setTimeout('ConectarServidor()',10);
      return false;
   }
  
   if (IFrameObj.contentDocument) {
      IFrameDoc = IFrameObj.contentDocument; 
   } else if (IFrameObj.contentWindow) {
      IFrameDoc = IFrameObj.contentWindow.document;
   } else if (IFrameObj.document) {
      IFrameDoc = IFrameObj.document;
   } else {
      return true;
   }  
   IFrameDoc.location.replace(URL);
   return false;
}

//function VerificaParametros() {
   if (EnderecoAtual.length > 0) {
      PosicaoParametros = EnderecoAtual.indexOf("?");
      if (PosicaoParametros > 0) {
         Parametros = EnderecoAtual.substring(PosicaoParametros+1,EnderecoAtual.length);   
	     if (Parametros.length > 0) {
	        splitParametros = Parametros.split("&");
  	  	    if (splitParametros.length > 0) {
		       for (x = 0; x < splitParametros.length; x++) {
				  splitSubParametros = splitParametros[x].split("=");
			  	  if (splitSubParametros.length > 0) {
				     NomeParametro = splitSubParametros[0];
				     ValorParametro = splitSubParametros[1];				   
				     if (NomeParametro == ParametroComparativo) {
						if (lerCookie("ID_ID360") == null) {
						   randomico = Math.random();
						   criarCookie("ID_ID360",randomico,0);
						   criarCookie("ValorParametro",ValorParametro,0);
						   ID_ID360 = randomico;
						} else {						   
						   ValorParametro2 = ValorParametro;
						   ID_ID360 = lerCookie("ID_ID360");
						   ValorParametro = lerCookie("ValorParametro");
						   if (ValorParametro != ValorParametro2) {
						      randomico = Math.random();
							  apagarCookie("ID_ID360");
							  apagarCookie("ValorParametro");
						      criarCookie("ID_ID360",randomico,0);
						      criarCookie("ValorParametro",ValorParametro2,0);
						      ID_ID360 = randomico;							
							  ValorParametro = ValorParametro2;
						   }
						}
						ConectarServidor(Endereco + "idsite.asp?Parametro=" + ValorParametro + "&ID_ID360=" + ID_ID360 + "&Referencia=" + Referencia + "&Pagina=" + location.href);			
						StatusEntrou = true;
					 }
				  }
               }
            }
	     }
	  }
	  ID_ID360 = lerCookie("ID_ID360");
	  ValorParametro = lerCookie("ValorParametro");
	  if ((StatusEntrou == false) && (ID_ID360.length > 0) && (ValorParametro.length > 0)) {
         ConectarServidor(Endereco + "idsite.asp?Parametro=" + ValorParametro + "&ID_ID360=" + ID_ID360 + "&Referencia=" + Referencia + "&Pagina=" + location.href);					  
	  }
   }
//}