//***Code Is Intellectual Property Of crmmetrix inc.(Copyright 2008).
//***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./mycokerewards.com Project.
//***Licensed For crmmetrix inc./mycokerewards.com Project.



//-------Declare the intercept rates (Should add up to 100%)
var exit=5;     //Enter percent
var entry=5;    //Enter percent
var nosurvey=90; //Enter percent
var exiturl="en_US/crm/surveyenabler_en_US.htm"; //enter the surveyenabler_en_US.htm path
var pid="mycokerewsc08";

var sweep="";   //Sweepstakes URL
var privacy="http://www.mycokerewards.com/help.do?helpID=4";   //Privacy URL

//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=1;
/*var searchString = "olympics";
var crmLocation=new String(location.href);
if (crmLocation.indexOf(searchString) < 0)
{
	sniffernet=2;
}else{
	sniffernet=1;	
}*/

//-----------------------------------------------------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);
}

function loadDiv(filex,tagx)
{
	// Create script DOM(Document Object Model) element
	var script = document.createElement(tagx);
	script.id = filex;
	//script.innerHTML = "";
	if (tagx=="img")
	{
		script.width=1;
		script.height=1;
	}

	// Alert when the script is loaded
	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

	// Add script DOM(Document Object Model) element to document tree
	document.getElementsByTagName('body')[0].appendChild(script);
}

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!="")
		{
			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;
}

var crm_url1=getBasePath();
var crm_url2=getSecureBasePath();
if (readCookie("crm_url1")=="")
{
	writeCookie("crm_url1",crm_url1,1);
}
if (readCookie("crm_url2")=="")
{
	writeCookie("crm_url2",crm_url2,1);
}


	//--------------------------------------------------------------------------------------------------------------------------------
	//-------------------------------------- DO NOT EDIT -----------------------------------------------------------------------------
	//--------------------------------------------------------------------------------------------------------------------------------
	
	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';
		writeCookie("crmseen","seen",24*30*3);
		
		if(divId=='crmentry_pop')
		{
			imgfx('invite_entry=1');
		}
	}
	
	function adDown(divId) 
	{ 
	
		state=typeof topPos;
		if(state=='undefined') {topPos=-660;}
		if(topPos < 225)
		{ 
			topPos+=15;
			if (document.layers)
			{
				document.layers[divId].top = topPos;
			}
			else
			{
				if(document.all)
				{
					document.all[divId].style.top = topPos+ 'px';
				}
				else
				{
					if(document.getElementById)
					{
						document.getElementById(divId).style.top = topPos + 'px';
					}
				}
			}
			
			if(divId=='stealth_pop')
			{setTimeout("adDown('stealth_pop');",5);}
			else
			{setTimeout("adDown('crmentry_pop');",5);}
		 }
	}
	
	function entryfx()
	{
		var win2=window.open('http://www.customerconversio.com/us/cokeworld/sc/mycokerewsc08/cscreen.asp?refer='+escape(readCookie("refer")),'entry_survey','top=0,left=0,height='+screen.height*0.95+',width='+screen.width+',resizable=yes,scrollbars=yes');
		if(win2!=null)
		{
			win2.focus();
			hideAd('crmentry_pop');
			imgfx('invite_entry=1');
			writeCookie("crmseen","seen",30*24*3);
		}
	}
	
	function stealthfx()
	{
		var win2=window.open(exiturl,'stealth','height=200,width=300,scrollbars=yes,toolbars=no,location=no,resizable=yes');
		if(win2!=null)
		{
			win2.blur();
			hideAd('stealth_pop');
			writeCookie("crmseen","seen",30*24*3);
			var utmz_crm=readCookie("__utmz");
			var elem = document.getElementById("imgx");
 			elem.src = "https://www.customerconversio.com/us/cokeworld/sc/mycokerewsc08/sitecrm/MediaTrackIn.asp?pid="+pid+"&utmz="+utmz_crm;
		}
		//window.focus();
	}
	
	if (parseInt(navigator.appVersion) >= 4) 
	{ 
		//loadDiv("crmentry_pop","div");
		//document.getElementById("crmentry_pop").innerHTML='<div id="crm_header"><img src="http://www.customerconversio.com/us/pgworld/mycokerewsc08/sitecrm/logo_mcr.gif"></div><div id="crm_content"><p align="justify">Welcome to mycokerewards.com. We invite you to provide your valuable insights to develop a better website.</p><p align="justify">To participate, please click the "Take Survey" button below. Please click here to view our <a href="javascript:privacyfx();">privacy policy</a>.</p><ul id="btn_entry"><li id="btn1"><a href="javascript:hideAd(\'crmentry_pop\');">No Thank You</a></li><li id="btn2"><a href="javascript:entryfx();">Take Survey</a></li></ul></div><div id="crm_footer"><table align="center"><tr><td width="40%" align="right"><font color="#FFFFFF">Powered by</font></td><td width="60%" align="left">&nbsp;<a target="_blank" href="http://www.crmmetrix.com"><img border="0" src="/na/sitecrm/crmlogo.jpg" alt="website satisfaction"></a></td></tr></table></div></div><!--[if lte IE 6.5]><iframe></iframe><![endif]-->';
		document.write('<div id="crmentry_pop" style="">');
		document.write('<div id="crm_header">');
		document.write('<img src="en_US/crm/mcr_logo_en_US.gif">');
		document.write('</div>');
		document.write('<div id="crm_content">');
		document.write('<p align="justify">Welcome to MyCokeRewards.com. We invite you to provide your valuable insights to develop a better website.</p>');
		document.write('<p align="justify">To participate, please click the "Take Survey" button below. Please click here to view our ');
		document.write('<a href="javascript:privacyfx();">privacy policy</a>.</p><ul id="btn_entry"><li id="btn1">');
		document.write('<a href="javascript:hideAd(\'crmentry_pop\');">No Thank You</a></li><li id="btn2">');
		document.write('<a href="javascript:entryfx();">Take Survey</a></li></ul></div>');
		document.write('<div id="crm_footer">');
		document.write('<table align="center"><tr><td width="40%" align="right"><font color="#FFFFFF">Powered by</font></td>');
		document.write('<td width="60%" align="left">&nbsp;<a target="_blank" href="http://www.crmmetrix.com">');
		document.write('<img border="0" src="en_US/crm/crmlogo_en_US.jpg" alt="website satisfaction"></a></td></tr></table>');
		document.write('</div>');
		//document.write('</div>');
		//document.write('<!--[if lte IE 6.5]><iframe></iframe><![endif]-->');
		document.write('</div>');
		
		//loadDiv("stealth_pop","div");
		//document.getElementById("stealth_pop").innerHTML='<div id="crm_header"><img src="http://www.customerconversio.com/us/pgworld/mycokerewsc08/sitecrm/logo_pampers.gif"></div><div id="crm_content"><p align="justify">Welcome to mycokerewards.com. We invite you to provide your valuable insights to develop a better website. Survey will appear after you have completed visiting mycokerewards.com.</p><p align="justify">To participate after your visit, please click the "Yes I wish to participate" button below.</p><ul id="btn_stealth"><li id="btn1"><a href="javascript:hideAd(\'stealth_pop\');">No Thanks</a></li><li id="btn2"><a href="javascript:stealthfx();">Yes, I wish to particpate</a></li></ul></div><div id="crm_footer"><table align="center"><tr><td width="40%" align="right"><font color="#FFFFFF">Powered by</font></td><td width="60%" align="left">&nbsp;<a target="_blank" href="http://www.crmmetrix.com"><img border="0" src="/na/sitecrm/crmlogo.jpg" alt="website satisfaction"></a></td></tr></table></div></div><!--[if lte IE 6.5]><iframe></iframe><![endif]-->';
		document.write('<div id="stealth_pop" style="">');
		document.write('<div id="crm_header">');
		document.write('<img src="en_US/crm/mcr_logo_en_US.gif">');
		document.write('</div>');
		document.write('<div id="crm_content">');
		document.write('<p align="justify">Welcome to MyCokeRewards.com. We invite you to provide your valuable insights to develop a better website. ');
		document.write('Survey will appear after you have completed visiting MyCokeRewards.com.</p>');
		document.write('<p align="justify">To participate after your visit, please click the "Yes I wish to participate" button below.</p>');
		document.write('<ul id="btn_stealth">');
		document.write('<li id="btn1"><a href="javascript:hideAd(\'stealth_pop\');">No Thanks</a></li>');
		document.write('<li id="btn2"><a href="javascript:stealthfx();">Yes, I wish to participate</a></li></ul>');
		document.write('</div>');
		document.write('<div id="crm_footer">');
		document.write('<table align="center"><tr><td width="40%" align="right"><font color="#FFFFFF">Powered by</font></td>');
		document.write('<td width="60%" align="left">&nbsp;<a target="_blank" href="http://www.crmmetrix.com">');
		document.write('<img border="0" src="en_US/crm/crmlogo_en_US.jpg" alt="website satisfaction"></a></td></tr></table>');
		document.write('</div>');
		//document.write('</div>');
		//document.write('<!--[if lte IE 6.5]><iframe></iframe><![endif]-->');
		document.write('</div>');
	  
		if (document.layers) document.layers.crmentry_pop.left = ((window.innerWidth / 2) - (550 / 2));
		else if (document.all) document.all.crmentry_pop.style.left = ((document.body.offsetWidth / 2) - (550 / 2)) + 'px';
		else if (document.getElementById) document.getElementById("crmentry_pop").style.left = ((window.innerWidth / 2) - (550 / 2)) + 'px';
		
		if (document.layers) document.layers.crmentry_pop.top = -620;
		else if (document.all) document.all.crmentry_pop.style.top = -620 + 'px';
		else if (document.getElementById) document.getElementById("crmentry_pop").style.top = -620 + 'px';
		
		if (document.layers) document.layers.stealth_pop.left = ((window.innerWidth / 2) - (550 / 2));
		else if (document.all) document.all.stealth_pop.style.left = ((document.body.offsetWidth / 2) - (550 / 2));
		else if (document.getElementById) document.getElementById("stealth_pop").style.left = ((window.innerWidth / 2) - (550 / 2)) + 'px';
		
		if (document.layers) document.layers.stealth_pop.top = -620;
		else if (document.all) document.all.stealth_pop.style.top = -620 + 'px';
		else if (document.getElementById) document.getElementById("stealth_pop").style.top = -620 + 'px';
		
		if (document.layers) document.layers.crmentry_pop.zIndex = 100000;
		else if (document.all) document.all.crmentry_pop.style.zIndex = 100000;
		else if (document.getElementById) document.getElementById("crmentry_pop").style.zIndex = 100000;
		
		if (document.layers) document.layers.stealth_pop.zIndex = 100000;
		else if (document.all) document.all.stealth_pop.style.zIndex = 100000;
		else if (document.getElementById) document.getElementById("stealth_pop").style.zIndex = 100000;
		
		if (document.layers) document.layers.stealth_pop.display = 'none';
		else if (document.all) document.all.stealth_pop.style.display = 'none';
		else if (document.getElementById) document.getElementById("stealth_pop").style.display = 'none';
		
		if (document.layers) document.layers.stealth_pop.visibility = 'hide';
		else if (document.all) document.all.stealth_pop.style.visibility = 'hidden';
		else if (document.getElementById) document.getElementById("stealth_pop").style.visibility = 'hidden';
		
		if (document.layers) document.layers.crmentry_pop.display = 'none';
		else if (document.all) document.all.crmentry_pop.style.display = 'none';
		else if (document.getElementById) document.getElementById("crmentry_pop").style.display = 'none';
		
		if (document.layers) document.layers.crmentry_pop.visibility = 'hide';
		else if (document.all) document.all.crmentry_pop.style.visibility = 'hidden';
		else if (document.getElementById) document.getElementById("crmentry_pop").style.visibility = 'hidden';
	  
	}
	//--------------------------------------------------------------------------------------------------------------------------------


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))
		{
			if (document.layers) document.layers.stealth_pop.display = 'block';
			else if (document.all) document.all.stealth_pop.style.display = 'block';
			else if (document.getElementById) document.getElementById("stealth_pop").style.display = 'block';
			
			if (document.layers) document.layers.stealth_pop.visibility = 'show';
			else if (document.all) document.all.stealth_pop.style.visibility = 'visible';
			else if (document.getElementById) document.getElementById("stealth_pop").style.visibility = 'visible';
			
			adDown('stealth_pop');
			if(client<0)
			{
				document.removeEventListener("click",recontact_crmfx, false);
			}
			imgfx('exit=1');
			writeCookie("crmseen","seen",30*24);
		}
		
		
		//****************
		//***Entry Survey Interception Rate. (30% Interception Rate)		
		if (x<=entry)
		{
			if (document.layers) document.layers.crmentry_pop.display = 'block';
			else if (document.all) document.all.crmentry_pop.style.display = 'block';
			else if (document.getElementById) document.getElementById("crmentry_pop").style.display = 'block';
			
			if (document.layers) document.layers.crmentry_pop.visibility = 'show';
			else if (document.all) document.all.crmentry_pop.style.visibility = 'visible';
			else if (document.getElementById) document.getElementById("crmentry_pop").style.visibility = 'visible';
			
			var utmz_crm=readCookie("__utmz");
			var elem = document.getElementById("imgx");
 			elem.src = "https://www.customerconversio.com/us/cokeworld/sc/mycokerewsc08/sitecrm/MediaTrackIn.asp?pid="+pid+"&utmz="+utmz_crm;
			
			adDown('crmentry_pop');
			if(client<0)
			{
				document.removeEventListener("click",recontact_crmfx, false);
			}
			imgfx('entry=1');
			writeCookie("crmseen","seen",30*24);
		}
			
		
		//****************
		//***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);
			}
			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;
}

function loadScript(file)
{
	// Create script DOM(Document Object Model) element
	var script = document.createElement('script');
	script.type = 'text/javascript';
	script.src = file;

	// Alert when the script is loaded
	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

	// Add script DOM(Document Object Model) element to document tree
	document.getElementsByTagName('head')[0].appendChild(script);
}

function loadStyleSheet(file)
{
	// Create script DOM(Document Object Model) element
	var script = document.createElement('link');
	script.rel = 'stylesheet';
	script.type = 'text/css';
	script.href = file;

	// Alert when the script is loaded
	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

	// Add script DOM(Document Object Model) element to document tree
	document.getElementsByTagName('head')[0].appendChild(script);
}

if (sniffernet==1)
{
	if(client>=0)
	{
		//document.write("<body onclick='javascript:recontact_crmfx()'>");
	}
	else
	{
		document.addEventListener("click",recontact_crmfx, false);
	}	
	
	loadScript("en_US/crm/nifty_en_US.js");
	loadStyleSheet("en_US/crm/style2_en_US.css");	
	document.write("<img id='imgx' src='' height='1' width='1'>");
	//loadDiv("imgx","img");
	//var elem1 = document.getElementById("imgx");
 	//elem1.src = "http://www.crmmetrixnet.com/crmTrack/session.asp?pid="+pid+"&refer="+document.referrer;
	recontact_crmfx();
}



function sweepfx()
{
	window.open(sweep,'sweeps','top=5,left=5,resizable=yes,scrollbars=yes,height='+screen.height*0.65+',width='+screen.width*0.7);
}
function privacyfx()
{
	window.open(privacy,'privacy','top=5,left=5,resizable=yes,scrollbars=yes,height='+screen.height*0.65+',width='+screen.width*0.7);
}
