var sniffernet=1; var exit_=100; var entry_=0; var nosurvey_=100; var insec_=1;
var repbaseurl="http://www.opinea.com/fr/images/sitecrm"
var exit=exit_;
var entry=entry_;
var nosurvey=0;
var exiturl=repbaseurl+"/stealth.htm";

var entryurl="http://survey.opinea.com/s?s=1454"; 
var pid="crmmetrixbdfrq29";
var cookieexp=3*24*30
var wtx=(screen.width);
var htx=(screen.height);
var wtx2=((wtx-270)*0.5);

function writeCookie(name, value, hours)
{
  var expire = "";
  if(hours != null)
  {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire +";path=/;";
}


function readCookie(name)
{
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0)
  { 
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    { 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

function GetParam(name)
{
  var start=location.search.indexOf("?"+name+"=");
  if (start<0) start=location.search.indexOf("&"+name+"=");
  if (start<0) return '';
  start += name.length+2;
  var end=location.search.indexOf("&",start)-1;
  if (end<0) end=location.search.length;
  var result=location.search.substring(start,end);
  var result='';
  for(var i=start;i<=end;i++) {
    var c=location.search.charAt(i);
    result=result+(c=='+'?' ':c);
  }
  return unescape(result);
}

writeCookie("crm_cookieEnabled","1",20);
var cookieEnabled=readCookie("crm_cookieEnabled");
if(cookieEnabled=="1")
{
	var visitctr=readCookie("ctr");	
	if (visitctr!="1")
	{
		if (document.referrer&&document.referrer!="")
		{
			writeCookie("refer",document.referrer,20);			
		}
		writeCookie("ctr","1",20);
	}

}
else
{
	sniffernet=2;
}
function hideAd(divId) 
{ 
	if (document.layers) document.layers[divId].visibility = 'hide';
	else if (document.all) document.all[divId].style.visibility = 'hidden';
	else if (document.getElementById) document.getElementById(divId).style.visibility = 'hidden';
}

function showAd(divId) 
{ 
	if (document.layers) document.layers[divId].visibility = 'show';
	else if (document.all) document.all[divId].style.visibility = 'visible';
	else if (document.getElementById) document.getElementById(divId).style.visibility = 'visible';
}

function create(divId) 
{ 
	if (document.layers) document.layers[divId].visibility = 'show';
	else if (document.all) document.all[divId].style.visibility = 'visible';
	else if (document.getElementById) document.getElementById(divId).style.visibility = 'visible';
}

function adDown(divId) 
{ 
	state=typeof topPos;
	var fposi;
	if (divId=='bg')
	{
	fposi=0;
	}
	else
	{
	fposi=80;
	}

	if(state=='undefined') {topPos=-440;}
	if(topPos < fposi)
	{ 
		topPos+=40;
		if (document.layers)
		{
			document.layers[divId].top = topPos;
		}
		else
		{
			if(document.all)
			{
				document.all[divId].style.top = topPos;
			}
			else
			{
				if(document.getElementById)
				{
					document.getElementById(divId).style.top = topPos;
				}
			}
		}
		
		{setTimeout("adDown('"+divId+"');",5);}
	 }
}

function entryfx()
{
	var win2=window.open(entryurl,'entry_survey','top=0,left=0,height='+screen.height*0.4+',width='+screen.width*0.4+',resizable=yes,scrollbars=yes');
	if(win2!=null)
	{
		win2.focus();
		writeCookie("crmseen","seen",cookieexp);
	}
	hideAd('entry_pop');

}

function stealthfx()
{
	var win2=window.open(exiturl,'stealth','height=10,width=10,scrollbars=yes,toolbars=no,location=no,resizable=yes');
	if(win2!=null)
	{
		win2.blur();
		writeCookie("crmseen","seen",cookieexp);
	}
	hideAd('stealth_pop');

	window.focus();
}

function crmlinkfx()
{
popupWin = window.open('http://panel.opinea2.fr/','open_window','menubar, toolbar, location, directories, status, scrollbars, resizable, dependent, width=640, height=480, left=100, top=100')
}



function nosurveyfx(divId)
{
	hideAd(divId);
	writeCookie("crmseen","seen",20);
}
var thiscookie=readCookie("crmseen");

if (parseInt(navigator.appVersion) >= 4 && navigator.javaEnabled()) 
{
document.write('<div id="entry_pop" style="">');
document.write('</div>');

document.write('<div id="stealth_pop" style="">');
document.write('<table id="Tableau_01" width="260" height="300" border="0" cellpadding="0" cellspacing="0">');
document.write('<tr>');
document.write('<td width="260" height="254" colspan="3"><img src="'+repbaseurl+'/images/haut.jpg" width="260px" height="254px" border="0"></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td width="55" height="33"><img src="'+repbaseurl+'/images/left.jpg" width="55px" height="33px" border="0"></td>');
document.write('<td width="150" height="33"><a href="javascript:stealthfx();"><img src="'+repbaseurl+'/images/oui.jpg" width="150px" height="33px" border="0"></a></td>');
document.write('<td width="55" height="33"><img src="'+repbaseurl+'/images/left.jpg" width="55px" height="33px" border="0"></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td width="55" height="33"><img src="'+repbaseurl+'/images/left.jpg" width="55px" height="33px" border="0"></td>');
document.write('<td width="150" height="33"><a href="javascript:nosurveyfx(\'stealth_pop\');"><img src="'+repbaseurl+'/images/non.jpg" width="150px" height="33px" border="0"></a></td>');
document.write('<td width="55" height="33"><img src="'+repbaseurl+'/images/left.jpg" width="55px" height="33px" border="0"></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td valign="top" height="20" colspan="3">&nbsp;</td>');
document.write('</tr>');
document.write('</table>');
document.write('</div>');


  if (document.layers) document.layers.entry_pop.left = 10;
  else if (document.all) document.all.entry_pop.style.left = 10;
  else if (document.getElementById) document.getElementById("entry_pop").style.left = 10;
  
  if (document.layers) document.layers.entry_pop.zIndex = 1000;
  else if (document.all) document.all.entry_pop.style.zIndex = 1000;
  else if (document.getElementById) document.getElementById("entry_pop").style.zIndex = 1000;
  
  if (document.layers) document.layers.stealth_pop.left = 10;
  else if (document.all) document.all.stealth_pop.style.left = 10;
  else if (document.getElementById) document.getElementById("stealth_pop").style.left = 10;
  
  if (document.layers) document.layers.stealth_pop.zIndex = 1000;
  else if (document.all) document.all.stealth_pop.style.zIndex = 1000;
  else if (document.getElementById) document.getElementById("stealth_pop").style.zIndex = 1000;


 hideAd('entry_pop')
 hideAd('stealth_pop') 

}
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function JSFX_FloatDiv(id, sx, sy)
{
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

	el.floatIt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 40);
	}
	return el;
}
if (sniffernet==1)
{
	timerfx();
	document.write("<img id='imgx' height='0' width='0'>");

}
var secs = insec_;
var timerID = null;
var timerRunning = false;
var delay = 1000;

function timerfx()
{ 
	if (secs==0)
    {
        if(timerRunning)
        clearTimeout(timerID);
    	timerRunning = false;
		recontact_crmfx();
		window.onerror=null;
    }
    else
    {
        //self.status = secs;
        secs = secs - 1;
        timerRunning = true;
        timerID = self.setTimeout("timerfx()", delay);
    }
}


function recontact_crmfx()
{
	var agt=navigator.userAgent.toLowerCase();
	var client=(agt.indexOf("msie"));
	var thiscookie=readCookie("crmseen");
	if(thiscookie!="seen")
	{
		rndNumber=readCookie("rndNumber");
			var x;
			x=Math.random()*100;
		if (x<=entry)
		{
			showAd('entry_pop');
			adDown('entry_pop');
			JSFX_FloatDiv("entry_pop", wtx2,150).floatIt();
			imgfx('entry');
		}
			if (x>(100-exit))
		{
			showAd('stealth_pop');
			adDown('stealth_pop');
			JSFX_FloatDiv("stealth_pop", wtx2,150).floatIt();
			imgfx('exit');
		}

		if (x>entry && x<=(100-exit))
		{
			writeCookie("crmseen","seen",20);
		}
		
	}
}
function imgfx(x)
{
	var elem = document.getElementById("imgx");
	//elem.src = "http://panel.opinea2.fr/invitetrack.asp?project="+x+"popin_"+pid;
}


function loadStyleSheet(file)
{
	var script = document.createElement('link');
	script.rel = 'stylesheet';
	script.type = 'text/css';
	script.href = file;
	if (typeof(script.onreadystatechange) == 'undefined') // W3C
		script.onload = function(){ this.onload = null;  };
	else // IE
		script.onreadystatechange = function(){ if (this.readyState != 'loaded' && this.readyState != 'complete') return; this.onreadystatechange = null;  }; // Unset onreadystatechange, leaks mem in IE
	document.getElementsByTagName('head')[0].appendChild(script);
}

loadStyleSheet(repbaseurl+"/style2.css");
