﻿



var displayDelay = 2500;
var footerheight = 92;	// total height of footer in pixels
var showbuttonheight = 30;	// total height of show button in pixels
var footeroverlap = 24;	// height of the 'overlap' portion only (semi-transparent)
var attributionoffset = 23;	// this offset adds some padding to the footer so that the attribution link is clickable
var slidespeed = 25;	// this is the speed that the footer will rise (lower number == faster) (milliseconds)
var slidestep = 10;	// this is the percentage step for each run of positionfooter
var donotshowLoggedin = false; // this will prevent the footer from showing to logged in users (presumably they're on your list)
var rememberShowHideState = false; // this indicates whether or not to recognize the show/hide state of the footer across pages

  if(readCookie('popunder'))
   {   
     donotshowLoggedin = true;
   }
   
   if(window.parent.location.toLowerCase().indexOf('tabid=57')>0)
   {
     
     donotshowLoggedin = true;
   }
   else if(window.parent.location.toLowerCase().indexOf('/tabid/57/')>0)
   {
      
      donotshowLoggedin = true;
   }
    else if(window.parent.location.toLowerCase().indexOf('checkout.aspx')>0)
   {
      
      donotshowLoggedin = true;
   }
   
   
 

function addLoadEvent(func) {
	if (donotshowLoggedin == false) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				oldonload();
				func();
			}
		}
	}
}

function registerHideme() {
	var hidelink = document.getElementById('hideme');
	hidelink.onclick = hidefooter;
	
}

function registerShowme() {
	var showlink = document.getElementById('optincrushershow');
	showlink.onclick = showfooter;
}

addLoadEvent(function() {
  
	registerHideme();
	registerShowme();
	
});

// layer animation
var showbuttonLayerStatus = Array ();
showbuttonLayerStatus['layerHeight'] = 0;
showbuttonLayerStatus['layerPosition'] = 0;

var footerLayerStatus = Array ();
footerLayerStatus['layerHeight'] = 0;
footerLayerStatus['layerPosition'] = 0;

function showfooterinitial() {
	if (rememberShowHideState && getCookie('show_hide_state') == 'hide') {
		setTimeout(function(){scrollLayer ('optincrushershow', showbuttonheight, 'show', footerLayerStatus)}, displayDelay);
	} else {
		setTimeout(function(){scrollLayer ('optincrusher', footerheight, 'show', showbuttonLayerStatus, true)}, displayDelay);
	}
}

function showfooter() {
	scrollLayer ('optincrusher', footerheight, 'show', showbuttonLayerStatus, true);
	scrollLayer ('optincrushershow', showbuttonheight, 'hide', footerLayerStatus);
	//delCookie('show_hide_state');	// delete cookie so that it shows by default
}

function hidefooter() {
	scrollLayer ('optincrusher', footerheight, 'hide', showbuttonLayerStatus, true);
	scrollLayer ('optincrushershow', showbuttonheight, 'show', footerLayerStatus);
	setCookie('show_hide_state','hide','/',31);	// don't show for a month, unless then show it
}

function scrollLayer ( whichLayer, height, action, statusArray, modifyBottomPadding ) {
	// get handle for the div to animate
	statusArray['layerToScroll'] = document.getElementById(whichLayer);

	// begin animation
	statusArray['layerHeight'] = height;
	statusArray['layerPosition'] = (action == 'show') ? 0:100; // statusArray['layerPosition'] is expressed as a percentage (out of 100);
	statusArray['layerTimeout'] = setInterval(function(){positionLayer(action, statusArray, modifyBottomPadding)}, slidespeed);
}

// position the layer (see scrollLayer which initializes the timeout for this function call)
function positionLayer(action, statusArray, modifyBottomPadding) {
	if (action == 'show') {
		statusArray['layerPosition'] += slidestep;
	} else if (action == 'hide') {
		statusArray['layerPosition'] -= slidestep;
	}

	// the magic 100s below indicate percentage with the layer approaching 100% shown/hidden
	statusArray['layerToScroll'].style.marginBottom = '-' + (((100 - statusArray['layerPosition']) / 100) * statusArray['layerHeight']) + 'px';

	// if I'm 100% deployed then finish footer
	if ((action == 'show' && statusArray['layerPosition'] >= 100) || (action == 'hide' && statusArray['layerPosition'] <= 0)) {
		clearTimeout(statusArray['layerTimeout']);
		if (modifyBottomPadding) statusArray['layerTimeout'] = setTimeout(function(){finishLayer(action, statusArray)}, 1);
	}
}

function finishLayer(action, statusArray) {
	// just in case we overdeployed in positionfooter(), ensure marginBottom is zero (0)
	statusArray['layerToScroll'].style.marginBottom = (action == 'hide') ? '-'+statusArray['layerHeight']+'px':'0px';	
	
	// increase padding at bottom of document so that page content isn't hidden under 
	// the footer when the page is scrolled all the way to the bottom
	document.body.parentNode.style.paddingBottom = (action == 'hide') ? attributionoffset + 'px':(statusArray['layerHeight'] - footeroverlap + attributionoffset) +'px';
	
	// here you could use AJAX (or similar) to log the popup hit for tracking purposes	
}

addLoadEvent(showfooterinitial);

// cookie management functions below 

function setCookie(c_name,value,path,expiredays) {
	var exdate = new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie = c_name + "=" + escape(value) + (path ? '; path=' + path : '') + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString());
   

}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

// this deletes the cookie when called
function delCookie(c_name) {
	var tmp = getCookie(c_name);
	if(tmp) { setCookie(c_name,tmp,'/',-1); }
}



//added new for cookies

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function createandsetcookie()
{
   if(!readCookie('popunder'))
   {
     createCookie('popunder','1',30);     
   }
}

this.addEvent = function(obj,type,fn){
 if(obj.attachEvent){
  obj['e'+type+fn] = fn;
  obj[type+fn] = function(){obj['e'+type+fn](window.event );}
  obj.attachEvent('on'+type, obj[type+fn]);
 } else {
  obj.addEventListener(type,fn,false);
 };
};
addEvent(window,"load",createandsetcookie);

//get querystring value

function getQuerystring(key)
{
  var  default_="blank";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.parent.location.href);
 
  if(qs == null)
    return default_;
  else
    return qs[1];
}


