//***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./Vicks.com Project.
//***Licensed For crmmetrix inc./Vicks.com Project.



//-------Declare the intercept rates (Should add up to 100%)
var exit=60;     //Enter percent
var entry=30;    //Enter percent
var nosurvey=10; //Enter percent
var exiturl="http://www.c-feedback.com/sitecrm/surveyenabler.htm"; //enter the stealth.htm path
var pid="vickssc08";

var sweep="http://espanol.vicks.com/enes/dcfeedback/us/pgworld/vickssc08/sweepstakes.asp";   //Sweepstakes URL
var privacy="http://www.pg.com/privacy/english/privacy_notice.html";   //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;
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);
}


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,23);			
		}
		writeCookie("ctr","1",23);
	}
	
		
	//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;
}

//--------------------------------------------------------------------------------------------------------------------------------
//-------------------------------------- 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*6);
	
	if(divId=='entry_pop')
	{
		imgfx('invite_entry=1');
	}
}

var exWidth=0;
if (document.getElementById) exWidth = (screen.width/2);
else if (document.all) exWidth = (document.body.offsetWidth/2);
else if (document.layers) exWidth = (screen.width/2);

var scWidth=0;
scWidth = exWidth-275;
function adDown(divId) 
{ 

	if (document.layers) document.layers[divId].display = 'block';
	else if (document.all) document.all[divId].style.display = 'block';
	else if (document.getElementById) document.getElementById(divId).style.display = 'block';
	
	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';
	
	state=typeof topPos;
	if(state=='undefined') {topPos=-700;}
	if(topPos < scWidth)
	//if(topPos < 0)

	{ 
		topPos+=20;
		if (document.layers)
		{
			document.layers[divId].left = topPos;
		}
		else
		{
			if(document.all)
			{
				document.all[divId].style.left = topPos;
			}
			else
			{
				if(document.getElementById)
				{
					document.getElementById(divId).style.left = topPos+'px';
				}
			}
		}
		
		if(divId=='stealth_pop')
		{setTimeout("adDown('stealth_pop');",5);}
		else
		{setTimeout("adDown('entry_pop');",5);}
	 }
}

function entryfx()
{
	hideAd('entry_pop');
	imgfx('invite_entry=1');
	var utmz_crm=readCookie("__utmz");
	var elem = document.getElementById("imgx");
	elem.src = "http://espanol.vicks.com/enes/dcfeedback/us/pgworld/vickssc08/sitecrm/MediaTrackIn.asp?pid="+pid+"&utmz="+utmz_crm;
	var win2=window.open('http://espanol.vicks.com/enes/dcfeedback/us/pgworld/vickssc08/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();
		writeCookie("crmseen","seen",30*24*6);
	}
}

function stealthfx()
{
	hideAd('stealth_pop');
	var win2=window.open(exiturl,'stealth','height=310,width=300,scrollbars=yes,toolbars=no,location=no,resizable=yes');
	if(win2!=null)
	{
		win2.blur();
		writeCookie("crmseen","seen",30*24*6);
		var utmz_crm=readCookie("__utmz");
		var elem = document.getElementById("imgx");
 		elem.src = "http://espanol.vicks.com/enes/dcfeedback/us/pgworld/vickssc08/sitecrm/MediaTrackIn.asp?pid="+pid+"&utmz="+utmz_crm;
	}
	window.focus();
}

function chkObject(inParent,theVal)
{
	if(inParent)
	{
		if (window.opener.document.layers) {return eval("window.opener.document.layers."+theVal+" != null");}
  		else if (window.opener.document.all) {return eval("window.opener.document.all."+theVal+" != null");}
  		else if (window.opener.document.getElementById) {return eval("window.opener.document.getElementById('"+theVal+"') != null");}
	}
	else
	{
		if (document.layers) {return eval("document.layers."+theVal+" != null");}
  		else if (document.all) {return eval("document.all."+theVal+" != null");}
  		else if (document.getElementById) {return eval("document.getElementById('"+theVal+"') != null");}
	}

}


if(sniffernet==1)
{

	if(parseInt(navigator.appVersion) >= 4) 
	{ 
		document.write('<div id="entry_pop" style="">');
		document.write('<div id="crm_header">');
		document.write('<img border="0" src="http://www.c-feedback.com/sitecrm/vicks_logo.jpg">');
		document.write('</div>');
		document.write('<div id="crm_content">');
		document.write('<p align="justify">Welcome to Vicks.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 ');
		document.write('click here to view our <a href="javascript:privacyfx();">Privacy Policy</a>.</p>');
		document.write('<ul id="btn_entry">');
		document.write('<li id="btn1"><a href="javascript:hideAd(\'entry_pop\');">No Thanks</a></li>');
		document.write('<li id="btn2"><a href="javascript:entryfx();">Take Survey</a></li>');
		document.write('</ul>');
		document.write('</div>');
		document.write('<div id="crm_footer"><table border="0" cellspacing="1" cellpadding="0" width="100%"><tr><td width="40%" align="right"><font color="#FFFFFF">Powered by</font>&nbsp;</td><td width="60%" align="left">');
		document.write('<a target="_blank" href="http://www.crmmetrix.com"><img border="0" src="http://www.c-feedback.com/sitecrm/crmlogo.jpg" alt="website satisfaction"></a></td></tr></table></div>');
		document.write('</div><!--[if lte IE 6.5]><![endif]-->');
		document.write('</div>');
		
		document.write('<div id="stealth_pop" style="">');
		document.write('<div id="crm_header">');
		document.write('<img border="0" src="http://www.c-feedback.com/sitecrm/vicks_logo.jpg">');
		document.write('</div>');
		document.write('<div id="crm_content">');
		document.write('<p align="justify">Welcome to Vicks.com. We invite you to provide your valuable insights to develop a better website. Survey will appear after you have completed visiting Vicks.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>');
		document.write('</ul>');
		document.write('</div>');
		document.write('<div id="crm_footer"><table border="0" cellspacing="1" cellpadding="0" width="100%"><tr><td width="40%" align="right"><font color="#FFFFFF">Powered by</font>&nbsp;</td><td width="60%" align="left">');
		document.write('<a target="_blank" href="http://www.crmmetrix.com"><img border="0" src="http://www.c-feedback.com/sitecrm/crmlogo.jpg" alt="website satisfaction"></a></td></tr></table></div>');
		document.write('</div><!--[if lte IE 6.5]><![endif]-->');
		document.write('</div>');
		
		if (document.layers) document.layers.entry_pop.left = -700;
		else if (document.all) document.all.entry_pop.style.left = -700;
		else if (document.getElementById) document.getElementById("entry_pop").style.left = -700 + 'px';
		
		if (document.layers) document.layers.entry_pop.top = 280;
		else if (document.all) document.all.entry_pop.style.top = 280;
		else if (document.getElementById) document.getElementById("entry_pop").style.top = 280 + 'px';
		
		if (document.layers) document.layers.entry_pop.display = 'none';
		else if (document.all) document.all.entry_pop.style.display = 'none';
		else if (document.getElementById) document.getElementById("entry_pop").style.display = 'none';
		
		if (document.layers) document.layers.entry_pop.visibility = 'hide';
		else if (document.all) document.all.entry_pop.style.visibility = 'hidden';
		else if (document.getElementById) document.getElementById("entry_pop").style.visibility = 'hidden';
		
		if (document.layers) document.layers.stealth_pop.left = -700;
		else if (document.all) document.all.stealth_pop.style.left = -700;
		else if (document.getElementById) document.getElementById("stealth_pop").style.left = -700 + 'px';
		
		if (document.layers) document.layers.stealth_pop.top = 280;
		else if (document.all) document.all.stealth_pop.style.top = 280;
		else if (document.getElementById) document.getElementById("stealth_pop").style.top = 280 + 'px';
		
		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 (chkObject(false,'content_ifr'))
		{
			if (document.layers) document.layers.content_ifr.zIndex = -1;
			else if (document.all) document.all.content_ifr.style.zIndex = -1;
			else if (document.getElementById) document.getElementById("content_ifr").style.zIndex = -1;
		}
	
		if (chkObject(false,'flashcontent'))
		{
			if (document.layers) document.layers.flashcontent.zIndex = 100;
			else if (document.all) document.all.flashcontent.style.zIndex = 100;
			else if (document.getElementById) document.getElementById("flashcontent").style.zIndex = 100;
		}
		
		
		if (document.layers) document.layers.entry_pop.zIndex = 1000000;
		else if (document.all) document.all.entry_pop.style.zIndex = 1000000;
		else if (document.getElementById) document.getElementById("entry_pop").style.zIndex = 1000000;
		
		if (document.layers) document.layers.stealth_pop.zIndex = 1000000;
		else if (document.all) document.all.stealth_pop.style.zIndex = 1000000;
		else if (document.getElementById) document.getElementById("stealth_pop").style.zIndex = 1000000;
	}


	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))
		{
			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)
		{
			
			adDown('entry_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",24);
			
			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)
{
	loadScript("http://www.c-feedback.com/us/pgworld/vickssc08/sitecrm/nifty.js");
	loadStyleSheet("http://www.c-feedback.com/us/pgworld/vickssc08/sitecrm/style2.css");
}
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);
}

