/*
Copyright Pop Com Blue Eagle Marketing Interativo e Tecnologia Ltda
Criado por Cássio Almeida
Versão: 1.1 - 13/09/2005
MULTISITES
*/
paginacarregada=0;
document.write( '<div id="trk" style="position:relative; left:0px; top:0px; width:1px; height:1px; z-index:1; background-color:#CCCCCC"></div>' );
function setVisitorID(semail, semail_ant, suserID,resx,resy,versao) { 
	var today = new Date();
	var zero_date = new Date(0,0,0); 
	today.setTime(today.getTime() - zero_date.getTime()); 
	var cookie_expire_date = new Date(today.getTime() + (90 * 86400000)); 
	Set_Cookie('obtxEMAIL',semail,cookie_expire_date,"/"); 
	Set_Cookie('obtxuserID',suserID,cookie_expire_date,"/"); 
	email_ant=semail_ant;
	userId=suserID;
	email=semail;
	pic1= new Image(1,1); 
	pic1.src='http://iv30.popasp2.com.br/lwart/trk_api.asp?em=' + email + '&ema=' + email_ant + '&ss=' + sessao + '&uId=' + userId + '&mid=' + smid + '&pid=' + pid + '&siteid=' + siteid + '&resx=' + resx + '&resy=' + resy + '&ver=' + versao;
	//window.open('http://iv30.popasp2.com.br/lwart/trk_api.asp?em=' + email + '&ema=' + email_ant + '&ss=' + sessao + '&uId=' + userId + '&mid=' + smid + '&pid=' + pid + '&siteid=' + siteid + '&resx=' + resx + '&resy=' + resy + '&ver=' + versao)
	//window.open( 'http://iv30.popasp2.com.br/lwart/trk_api.asp?em=' + email + '&ema=' + email_ant + '&ss=' + sessao + '&uId=' + userId + '&mid=' + smid + '&pid=' + pid + '&siteid=' + siteid + '&resx=' + resx + '&resy=' + resy + '&ver=' + versao )
	//MM_setTextOfLayer('trk','',strk)
} 
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}
function setSessionID() { 
	sessao=Get_Cookie('SessionID');
	if (!sessao) {
		sessao=parseInt(Math.random()*1000000000,10);
		Set_Cookie('SessionID',sessao,'',"/"); 
	}
	Set_Cookie('obtxSMID',smid,'',"/"); 
} 
function novoUserId() { 
	return(parseInt(Math.random()*1000000000,10));
} 
function Get_Cookie(name) { 
   var start = document.cookie.indexOf(name+"="); 
   var len = start+name.length+1; 
   if ((!start) && (name != document.cookie.substring(0,name.length))) return null; 
   if (start == -1) return null; 
   var end = document.cookie.indexOf(";",len); 
   if (end == -1) end = document.cookie.length; 
   return unescape(document.cookie.substring(len,end)); 
} 
function Set_Cookie(name,value,expires,path,domain,secure) { 
    var cookieString = name + "=" +escape(value) + 
       ( (expires) ? ";expires=" + expires.toGMTString() : "") + 
       ( (path) ? ";path=" + path : "") + 
       ( (domain) ? ";domain=" + domain : "") + 
       ( (secure) ? ";secure" : ""); 
    document.cookie = cookieString; 
} 
function FlashCookie(semail,semail_ant,modo,sessao,suserID){
	temp='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="1" height="1">';
	temp+='  <param name="movie" value="/fltrk.swf?email=' + semail + '&email_ant=' + semail_ant + '&modo=' + modo + '&sessao=' + sessao + '&userID=' + suserID +  '">';
	temp+='  <param name="quality" value="high">';
	temp+='  <embed src="/fltrk.swf?email=' + semail + '&email_ant=' + semail_ant + '&modo=' + modo + '&sessao=' + sessao + '&userID=' + suserID + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="1" height="1"></embed>';
	temp+='</object>';
	MM_setTextOfLayer('trk','',temp)
}
function detectFlash(){
	var flashinstalled = 0;
	if (navigator.plugins && navigator.plugins.length){
		x = navigator.plugins["Shockwave Flash"];
		if (x){
			return true;
		}else{
			return false;
		}
		if (navigator.plugins["Shockwave Flash 2.0"]){
			return true;
		}
	}else if (navigator.mimeTypes && navigator.mimeTypes.length){
		x = navigator.mimeTypes['application/x-shockwave-flash'];
		if (x && x.enabledPlugin)
			return true;
		else
			return false;
	}
	return true;
}
function getVar(name){
	get_string = document.location.search;         
	return_value = '';
	name_index = get_string.indexOf(name + '=');
	if(name_index != -1){
		get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
		end_of_value = get_string.indexOf('&');
		if(end_of_value != -1) value = get_string.substr(0, end_of_value);                
		else value = get_string;                
		return_value = value;
	}
	space = return_value.indexOf('+');
	while(space != -1){ 
		return_value = return_value.substr(0, space) + ' ' + 
		return_value.substr(space + 1, return_value.length);
		space = return_value.indexOf('+');
	}
	return(return_value);        
}

if(typeof siteid=="undefined")
	siteid=0;
if(typeof pid!="undefined"){
	var smid=getVar("mid");
	if(smid=="")
		smid=Get_Cookie('obtxSMID');
	if(smid=='null' || smid=='NULL')
		smid=0;

	var email=getVar("em");
	var email_ant="";
	var sessao="";
	var	userId="";
	
	userId=Get_Cookie('obtxuserID');
	if(!userId || userId=='undefined')
		userId=novoUserId();
	setSessionID();
	if(email==""){
		email=Get_Cookie('obtxEMAIL');
		if(typeof email=="undefined" || email=='' || email=='undefined' || email=='null')
			email="tracking@anonimo.com.br";
		email_ant=email;
	}else{
		email_ant=Get_Cookie('obtxEMAIL');
		if(!email_ant)
			email_ant='';
	}
}
function faz_tracking(){
	// Está sendo chamado de dqm_script.js pois precisa ser chamado no onload da página.
	if(typeof pid!="undefined"){
		if(detectFlash()){
			if(email!=email_ant){
				FlashCookie(email,email_ant,1,sessao,userId);
			} else {
				FlashCookie(email,email_ant,0,sessao,userId);
			}
		}else{
			setVisitorID(email, email_ant, userId);
		}
	}
}
function click_pop(qp, url){
	if(typeof siteid=="undefined")
		siteid=0
	strk='http://iv30.popasp2.com.br/lwart/trk_api.asp?em=' + email + '&ema=' + email_ant + '&ss=' + sessao + '&uId=' + userId + '&mid=' + smid + '&pid=' + qp + '&rt=' + url + "&siteid=" + siteid;
	self.location=strk;
}
function click_pop_window(qp, url, janela, prm){
	if(typeof siteid=="undefined")
		siteid=0
	strk='http://iv30.popasp2.com.br/lwart/trk_api.asp?em=' + email + '&ema=' + email_ant + '&ss=' + sessao + '&uId=' + userId + '&mid=' + smid + '&pid=' + qp + '&rt=' + url + "&siteid=" + siteid;
	nwin1 = window.open(strk,janela,prm);
	setTimeout('nwin1.focus();',300);
}
function click_flash(qp){
	pid=qp;
	FlashCookie(email,email_ant,0,sessao,userId);
}
function click_flash_email(qp,tem){
	pid=qp;
	email=tem;
	email_ant=Get_Cookie('obtxEMAIL');
	if(!email_ant)
		email_ant='';
	FlashCookie(email,email_ant,1,sessao,userId);
}
