//***Code Is Intellectual Property Of crmmetrix inc.(Copyright 2007).
//***The use os this code is permitted for this project only as per the license agreement.
//***Code Has Been Developed For The Sole Purpose Of crmmetrix inc./shuuemra-usa.com Project.
//***Licensed For crmmetrix inc./shuuemra-usa.com Project.



//-------Declare the intercept rates (Should add up to 100%)
var exit=60;     //Enter percent
var entry=0;    //Enter percent
var nosurvey=40; //Enter percent
var exiturl="/sitecrm/surveyenabler.aspx"; //enter the surveyenabler.htm path
var entryurl="/sitecrm/entry.aspx"; //enter the entry.htm path
var pid="lpureologysc09";


//Browser Sniffer
var agt=navigator.userAgent.toLowerCase();
var client=(agt.indexOf("msie"));

//Note : To deactivate project assign sniffernet=2;
//The below sniffernet code is to centrally activate,deactivate the project.
//The survey is by default disabled and its only enabled if the site visitor has cookies enabled
//on his system
var sniffernet;
//sniffernet=1;
sniffernet=2;


//-----------------------------------------------------FUNCTIONS---DO NOT EDIT BELOW THIS
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);
}

var crmhost_name=new String();
crmhost_name=readCookie("crmhost_name");
if(crmhost_name=="")
{
	writeCookie("crmhost_name",location.hostname,24);
	crmhost_name=location.hostname;
}
crmhost_name=crmhost_name.toLowerCase();
if(crmhost_name=="shu.qa.inspreview.com")
{
	exiturl="/Loreal.ShuUemura/sitecrm/surveyenabler.aspx"; //enter the surveyenabler.htm path
	entryurl="/Loreal.ShuUemura/sitecrm/entry.aspx"; //enter the entry.htm path
}


writeCookie("crm_cookieEnabled","1",20);	//writing cookie to check if cookies are enabled or disabled.
var cookieEnabled=readCookie("crm_cookieEnabled");	//reading the cookie value to see if cookie is written or not.

if(cookieEnabled=="1")
{

	//-------Determining whether this is the first visit to tagged page. Tracking the referer url.
	var visitctr=readCookie("ctr");
		
	if (visitctr!="1")
	{
		//-------Capturing Referring URL
		if (document.referrer&&document.referrer!="")
		{
			writeCookie("refer",document.referrer,20);			
		}
		writeCookie("ctr","1",20);
	}
	
	//reading popseen cookie to make sure the user hasn't taken the survey within past 6 months
	var thiscookie=readCookie("crmseen");

	//if((thiscookie!="seen")&&(client>0))
	if(thiscookie=="seen")
	{
		sniffernet=2;
	}

}
else
{
	sniffernet=2;
}



if (sniffernet==1)
{
	if(client>=0)
	{
		document.write("<body onclick='javascript:recontact_crmfx()'>");
	}
	else
	{
		document.addEventListener("click",recontact_crmfx, false);
	}	
		
	document.write("<img id='imgx' src='http://www.crmmetrixnet.com/crmTrack/session.asp?pid="+pid+"&refer="+document.referrer+"' height='1' width='1'>");
	recontact_crmfx();
}


function recontact_crmfx()
{
	var thiscookiex=readCookie("crmseen");
	if(thiscookiex!="seen")
	{

		//***Random Number Generated For Control Sample / Test Sample.
		rndNumber=readCookie("rndNumber");
		if(rndNumber=='')
		{
			var x;
			x=Math.random()*100;
			writeCookie("rndNumber",x,1);
		}
		else
		{
			var x;
			x=parseFloat(rndNumber);
		}
		
		
		//*************
		//***Exit Survey Interception Rate
		if (x>(100-exit))
		{
			var win2=window.open(exiturl,'surveyenabler','height=150,width=315,scrollbars=yes,toolbars=no,location=no,resizable=yes');
			if(win2!=null)
			{
				win2.blur();
				writeCookie("crmseen","seen",30*24);
				
				if(client<0)
				{
					document.removeEventListener("click",recontact_crmfx, false);
				}
				//document.write("<img src='https://www.crm-metrix.com/crmTrack/track.asp?pid="+pid+"&exit=1'>");
				imgfx('exit=1');
			}
			window.focus();
		}
		
		
		//****************
		//***Entry Survey Interception Rate. (30% Interception Rate)		
		if (x<=entry)
		{
			var win2=window.open(entryurl,'entry','top=5,left=5,height=400,width=600,scrollbars=yes,toolbars=no,location=no,resizable=yes');
			if(win2!=null)
			{
				win2.focus();
				writeCookie("crmseen","seen",30*24);
				
				if(client<0)
				{
					document.removeEventListener("click",recontact_crmfx, false);
				}
				imgfx('entry=1');
			}
		}
			
		
		//****************
		//***NO Survey Interception Rate (10% Interception Rate) 
		//(Cookie Expires In 20 Hrs)
		
		if (x>entry && x<=(100-exit))
		{
			//writing cookie which expires in 20 hrs
			writeCookie("crmseen","seen",20);
			
			if(client<0)
			{
				document.removeEventListener("click",recontact_crmfx, false);
			}
			//document.write("<img src='https://www.crm-metrix.com/crmTrack/track.asp?pid="+pid+"&nosurvey=1' height='1' width='1'>");
			imgfx('nosurvey=1');
		
		}
		
	}
	
}
//End bracket for function recontact_crmfx()

//--------------------------------------------------------------------------------------------------------------------------------------------------
//-------------------------- CRMMETRIX TRACKING CODES - DO NOT MODIFY ------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------------------------------------------
function imgfx(x)
{
	//document.write("<img src='https://www.crm-metrix.com/crmTrack/track.asp?pid="+pid+"&'+x>");
	var elem = document.getElementById("imgx");
 	elem.src = "http://www.crmmetrixnet.com/crmTrack/track.asp?pid="+pid+"&"+x;
}
