var account     	= getCookie('account');
var did_account 	= getCookie('did_account');
var did_newsletter  = getCookie('did_newsletter');
var did_sweeps  	= getCookie('did_sweeps_0708');
var have_photos  	= getCookie('have_photos');
var promo_unique_id	= getCookie('unique');
var trackingPromo   = getCookie('trackingPromo');
var flashHandlerPromotion = '';
var iframeCounter = 0; // safari seems to need unique ids for iframes for some reason that only latte liberals would understand
var promoPopInValidationCode = '';

function promoPopInFoodSubscribe() {
	promoPopInShowWindow('account_popin','','',420,600,'','/gp/popins/foodletter.html', false, 'newsletter-link');
}

function promoPopInSubscribe100Free() {
	promoPopInShowWindow("account_popin","","",420,600,'',"/gp/popins/subscribe.html?clktrk=global-bottom-promo-2", false, 'home-url-100free');
}

function promoPopInSubscribeBottomPromo() {
	promoPopInShowWindow("account_popin","","",420,600,'',"/gp/popins/subscribe.html", false, 'home-url-bottom-Promo');
}

function promoPopInSweepstakes() {
	promoPopInShowWindow('account_popin','','',420,600,'','/gp/popins/sweepstakes.html',false,'sweeps-chicklet');
}

function promoPopInUserProfile(user) {
	promoPopInShowWindow("profile_popin","","",660,3000,'',"/gp/popins/profile/" + user + ".html", false, '');
}

function promoPopInSubscribePopIn(custom_header) {
	promoPopInShowWindow("account_popin","","",420,600,'',"/gp/popins/subscribe.html?custom_header=" + custom_header, false, 'home-url-subscribe');
}

function promoPopInValidatePopIn() {
	promoPopInShowWindow("account_popin","","",420,600,'',"/gp/popins/validate.html?validate=" + promoPopInValidationCode, false, 'home-url-validate');
}

function promoPopInValidatePopInTickle() {
	promoPopInShowWindow("account_popin","","",420,600,'',"/gp/popins/validate.html?validate=" + promoPopInValidationCode, false, 'home-url-validate-tickle');
}


function promoPopInValidateReminderPopIn() {
	promoPopInShowWindow("account_popin","","",420,800,'',"/gp/popins/needvalidation.html", false, 'home-url-validate-reminder');
}

function promoPopInShowRegisterPopIn() {
	promoPopInShowWindow("account_popin","","",420,800,'',"/gp/popins/register.html", false, 'home-url-register');
}

function promoPopInShare() {
	url = escape('http://www.grandparents.com/');
	promoPopInShowWindow("share_popin","","",648,600,"","/gp/popins/emailfriend.html?url=" + url, false, 'share-url');
}

function S4() {
   return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}

function guid() {
   return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}


function getScrollTop() {
	var offset = 0;
	
	if(window.document.documentElement && window.document.documentElement.scrollTop) {
		offset=window.document.documentElement.scrollTop;
	}
	else if(window.document.body && (window.document.body.scrollTop != undefined)) {
		offset=window.document.body.scrollTop;
	}
	
	return offset;
}

function getWindowHeight() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  
  // window.alert( 'Width = ' + myWidth );
  // window.alert( 'Height = ' + myHeight );
  
  return myHeight;
}

function getScrollWidth()
{
   var w = window.pageXOffset ||
           document.body.scrollLeft ||
           document.documentElement.scrollLeft;
           
   return w ? w : 0;
}

function getScrollHeight()
{
   var h = window.pageYOffset ||
           document.body.scrollTop ||
           document.documentElement.scrollTop;
           
   return h ? h : 0;
}

function getDialogTop(popinHeight) {	
	var scrollTop 		= getScrollTop();
	var scrollHeight 	= getWindowHeight();
			
	var center = (scrollHeight - popinHeight) / 2;
	
	var popinTop = 0;
	
	if(is_ie6 || is_ie6up) {
		// alert('doing ie6');
		popinTop = center + scrollTop;
	}
	else {
		// alert('doing non ie6');
		popinTop = center;
	}
	
	if(popinTop < 10) {
		popinTop = 10;
	}
	
	return popinTop;
}


if(!getCookie('guid')) {
	setCookie('guid', guid(), 365);
}

function promoClickTrack(mode,promotion) {

	var page 		= document.location.href;
	var parentpage 	= '';
	
	if(!promotion) {
		promotion   = getCookie('clicktrack');
	}
	
	if(window.parent) {
		parentpage = window.parent.location.href;
	}

	var timestamp = new Date();     

	var trackpath = '/event-PAGE' + window.parent.location.pathname + '/LINK-FOLLOWED-' + escape(promotion) + '/ACTION-' + escape(mode);

	pageTracker._trackPageview(trackpath);
}

function setPromotion() {
}

function beginPromotion(promotion) {
	setCookie('clicktrack', promotion);
}

function logOut(destination) {
	setCookie('account','');
	setCookie('deals','');
	if(destination) {
		window.parent.location.href = destination;
	}
	else {
		window.parent.promoPopInInitialize();
		window.parent.doNewHeaderLoginStatus();
		window.parent.conditionalLoginStatus('article_comment_logged_in','article_comment_logged_out');
		window.parent.conditionalLoginStatus('welcome_logged_in','welcome_logged_out');
	}
}

var destinationOnClose = '';
function promoPopInSetCloseDestination(url) {
	destinationOnClose = url;
}

function promoPopInGoToCloseDestination(url) {
	if(destinationOnClose) {
		if(window.parent) {
			window.parent.location.href = destinationOnClose;
		}
		else {
			window.location.href = destinationOnClose;
		}
	}
}

function flashHandler(action, param1, param2) {
	if(action == 'close') {

		promoClickTrack('close');

		if(!param1) {
			param1 = 'promo_popin_div';
		}
		window.parent.promoPopInCloseWindow(param1);
		
	}
	else if(action == 'complete') {

		promoClickTrack('complete');

		if(!param1) {
			param1 = 'promo_popin_div';
		}
		window.parent.setCookie('promoPopInVisitTimeout', '');

		if(param2) {
			window.parent.document.location.href = unescape(param2);
		}
		else {
			window.parent.promoPopInInitialize();
			window.parent.doNewHeaderLoginStatus();
			window.parent.conditionalLoginStatus('article_comment_logged_in','article_comment_logged_out');
			window.parent.conditionalLoginStatus('welcome_logged_in','welcome_logged_out');
			window.parent.promoPopInCloseWindow(param1);
		}
	}
	else if(action == 'newsletter') {
		promoClickTrack('follow');
		document.location.href="/gp/popins/subscribe.html?f=promo_popin_div&email=" + escape(param1);
	}
	else if(action == 'newsletter1_close') {
		window.parent.promoPopInCloseWindow('promo_popin_div');
	}
	else if(action == 'newsletter1_subscribe') {
		promoClickTrack('follow');
		window.parent.promoPopInShowWindow("account_popin_div","","",420,600,"","/gp/popins/subscribe.html?email=" + escape(param1), false);
	}
	else if(action == 'newsletter_under') {
		promoClickTrack('follow');
		window.parent.promoPopInShowWindow('promo_popin_div',"","",420,600,"","/gp/popins/subscribe.html?email="  + escape(param1), false);
	}
	else if(action == 'register') {
		promoClickTrack('follow');
		document.location.href="/gp/popins/register.html?f=promo_popin_div&email=" + escape(param1);
	}
	else if(action == 'register_from_login') {
		promoClickTrack('follow');
		document.location.href="/gp/popins/register.html?f=login_top_div&destination=" + escape(param1);
	}
	else if(action == 'register_under') {
		promoClickTrack('follow');
		window.parent.promoPopInShowWindow('promo_popin_div',"","",420,600,"","/gp/popins/register.html?email=" + escape(param1), false);
	}
	else if(action == 'register_login') {
		promoClickTrack('follow');
		document.location.href="/gp/popins/register.html?f=login_div&email=" + escape(param1);
	}
	else if(action == 'getstartednow') {
		promoClickTrack('follow');
		window.parent.location.href='/gp/regphotobox/index.html?promotion=' + flashHandlerPromotion;
	}
	else if(action == 'register_photobox_under') {
		promoClickTrack('follow');
		window.parent.location.href = '/gp/regphotobox/index.html';
	}
	else if(action == 'account_settings') {
		promoClickTrack('account settings click');
		document.location.href = '/gp/popins/settings.html?f=account_popin';
	}
	else if(action == 'resend_validation') {
		promoClickTrack('account settings resend validation');
		document.location.href = '/gp/popins/settings.html?f=account_popin&resend_validation=1';
	}
	else if(action == 'seevideo') {
		promoClickTrack('picture box video');
		window.parent.location.href = '/gp/photobox/tutorial/index.html';
	}
	else if(action == 'invite') {
		promoClickTrack('follow');
		window.parent.location.href="/gp/photobox/invite/index.html?email=" + escape(param1);
	}
	else if(action == 'samplenewsletter') {
		promoClickTrack('sample newsletter click');
		openNewsletter('http://archive.grandparents.com/newsletter-archive/test.html',800,958);
	}
	else if(action == 'samplebabynewsletter') {
		promoClickTrack('sample baby newsletter click');
		openNewsletter('http://archive.grandparents.com/tests/baby-bulletin/wk20.html',800,958);
	}
	else if(action == 'privacypolicy') {
		promoClickTrack('privacy policy click');
		openNewsletter('/gp/privacy-policy.html',310,767);
	}
	else if(action == 'sweepstakesrules') {
		promoClickTrack('sweepstakes rules click');
		openNewsletter('/gp/sweepstakes-rules.html',310,767);
	}
	else if(action == 'kotacontestrules') {
		promoClickTrack('kota contest rules click');
		openNewsletter('/gp/kotacontest-rules.html',510,767);
	}
	else {
		alert('flash ' + action + ' param=' + param1);
	}
}

function promoPopInInitialize() {

	var params = getQueryStringParams();

	if(params['visit']) {
		setCookie('promoPopInVisitCount',params['visit'],365);
		setCookie('promoPopInVisitTimeout', '');
	}

	if(params['utm_medium'] == 'Email' && params['utm_source'] == 'Newsletter') {
		pageTracker._setVar('NewsletterSubscriber');
	}

	account     	= getCookie('account');
	did_account 	= getCookie('did_account');
	did_newsletter  = getCookie('did_newsletter');
	did_sweeps  	= getCookie('did_sweeps_0708');
	have_photos  	= getCookie('have_photos');

	var promoPopInVisitCount 	= getCookie('promoPopInVisitCount');
	var promoPopInVisitTimeout 	= getCookie('promoPopInVisitTimeout');

	reveal = document.getElementById('home_photobox_slideshow');
	if(reveal) {
		reveal.style.display = 'none';
	}

	if(!params['share']) {
		if(promoPopInVisitCount == 0) {
			var onHome = document.location.href.indexOf('/home/index.html');
			var noVideo = params['novideo'];
			if(onHome >= 0 && !noVideo) {
				setCookie('promoPopInVisitCount', 1 , 365);
				promoPopInShowWindow('promo_popin_div',145,'',927,525,'',"/gp/popins/firstvisit.html", true);
			}
		}
	}
}

var openPopIns = new Array();
promoPopInListenForResize();

function promoPopInRegisterPopIn(id,backgroundId,overId) {

	// alert('promoPopInRegisterPopIn ' + id);

	openPopIns[openPopIns.length] = id + ',' + backgroundId + ',' + overId;
}

function promoPopInDeletePopIn(theId) {
	
	var idx = promoPopInFindPopIn(theId);

	// alert('promoPopInDeletePopIn ' + theId);

	if(idx >= 0) {
		openPopIns.splice(idx,1);
	}
}

function promoPopInFindPopIn(theId) {
	var found = false;
	var idx;
	
	for(var i = 0; i < openPopIns.length; i++) {
		var divs = openPopIns[i].split(',');
		
		if(divs[0] == theId) {

			// alert('promoPopInFindPopIn ' + theId + ' found');

			found = true;
			idx = i;
		}
	}
	
	if(found) {
		return idx;
	}
	else {
		return -1;
	}
}

function promoPopInHandleResize() {	
	for(var i = 0; i < openPopIns.length; i++) {
		var divs = openPopIns[i].split(',');
		promoPopInOpen(divs[0], divs[1], 0, 0, 0, 0, divs[2], true);
	}
}

function promoPopInListenForResize() {

	
//	if (document.all){
//		document.body.onresize = promoPopInHandleResize;
//	} else {
  		if (window.addEventListener) {
      		window.addEventListener("resize", promoPopInHandleResize, false);
   		} 
   		else {
     		window.attachEvent("onresize", promoPopInHandleResize);
		}
//	}
}

function promoPopInStopListeningForResize() {
	
//	if (document.all){
//		document.body.onresize = resize_layers;
//	} else {
  		if (window.addEventListener) {
      		window.removeEventListener("resize", promoPopInHandleResize, false);
   		} 
   		else {
      		window.detatchEvent("onresize", promoPopInHandleResize);
		}
//	}
}

function findPosX(obj) {
	var curleft = 0;
	if(obj.offsetParent) {
		while(1) {
		  curleft += obj.offsetLeft;
		  if(!obj.offsetParent) { break; }
		  obj = obj.offsetParent;
		}
	}
	else if(obj.x) { curleft += obj.x; }
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if(obj.offsetParent) {
		while(1) {
		  curtop += obj.offsetTop;
		  if(!obj.offsetParent) { break; }
		  obj = obj.offsetParent;
		}
	}
	else if(obj.y) { curtop += obj.y; }
	return curtop;
}


function isMacFirefox2() {
  var userAgent = navigator.userAgent.toLowerCase();
  if (/firefox[\/\s](\d+\.\d+)/.test(userAgent)) {
    var ffversion = new Number(RegExp.$1);
    if (ffversion < 3 && userAgent.indexOf('mac') != -1) {
      return true;
    }
  }
}


function getViewportDimensions() {
    var intH = 0, intW = 0;
    
    if(self.innerHeight) {
       intH = window.innerHeight;
       intW = window.innerWidth;
    } 
    else {
        if(document.documentElement && document.documentElement.clientHeight) {
            intH = document.documentElement.clientHeight;
            intW = document.documentElement.clientWidth;
        }
        else {
            if(document.body) {
                intH = document.body.clientHeight;
                intW = document.body.clientWidth;
            }
        }
    }

    return {
        height: parseInt(intH, 10),
        width: parseInt(intW, 10)
    };
}


function promoPopInOpen(popinId, backgroundId, position_top, position_left, width, height, position_over, reposition) {

	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}

	var windowHeight = myHeight;
	var windowWidth = myWidth;
	var docHeight = document.body.offsetHeight;
	var docWidth = document.body.offsetWidth;

	var windowLeft = 0;
	var fullHeight = docHeight;
	var fullWidth  = docWidth;
	if (windowWidth > docWidth) {
		fullWidth = windowWidth;
		//need to start at window left, not document left
		windowLeft = Math.round( (docWidth - windowWidth)/2 );
	}
	if (windowHeight > docHeight) {
		fullHeight = windowHeight;
	}
	
	if(backgroundId) {
		var backgroundNode = document.getElementById(backgroundId);
		
		var h = 0;
		if (document.body.scrollHeight > document.body.offsetHeight) {
		 	h = document.body.scrollHeight; // all but Explorer Mac
		}
		else {
 			h = document.body.offsetHeight
		}
		
		backgroundNode.style.height 	= h+"px";
		backgroundNode.style.width 		= fullWidth+"px";
		backgroundNode.style.left 		= windowLeft+"px";
		backgroundNode.style.zIndex	    = 19998;

		backgroundNode.style.visibility = "visible";
	}
	
	// next, center and make the popin div visible
	var popinNode = document.getElementById(popinId);
	
	popinNode.style.display = "block";

	if(width) {
		popinNode.style.width	= width + "px";
	}
	
	if(height) {
		popinNode.style.height	= height + "px";
	}

	var popinHeight = popinNode.offsetHeight;
	var popinWidth  = popinNode.offsetWidth;

	var top  		= position_top;
	var left 		= position_left;
	var may_want_fixed = 0;
	
	if(position_over) {
		var position_over_obj = document.getElementById(position_over);
		left = findPosX(position_over_obj);
		top = findPosY(position_over_obj) - 24;
	}

	if(top) {
		popinNode.style.top = top + "px";
	}
	else {

		var ScrollTop = document.body.scrollTop;
		
		if (ScrollTop == 0) {
		 	if (window.pageYOffset) {
				ScrollTop = window.pageYOffset;
			}
			else {
				ScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
			}
		}    
    
    	popinNode.style.top = ScrollTop + 30;

	}

	if(left) {
		popinNode.style.left 	= left + "px";
	}
	else {
		popinNode.style.left = ""+( (windowWidth-popinWidth)/2 + windowLeft)+"px";
	}
	
	if(!reposition) {
		popinNode.style.zIndex	   = 20000;

		if(may_want_fixed) {
			if(is_ie6 || is_ie6up) {
				popinNode.style.position = 'absolute';
			}
			else {
				popinNode.style.position = 'fixed';
			}
		}
		else {
			popinNode.style.position = 'absolute';
		}

		popinNode.style.visibility = "visible";
	
		promoPopInRegisterPopIn(popinId, backgroundId, position_over);

		if(is_ie6) {			
			var mask = document.createElement('iframe');
			mask.style.display 		= 'block';
			mask.style.position		= 'absolute';
			mask.style.top			= 0;
			mask.style.left			= 0;
			mask.style.zIndex 		= -1;
			mask.style.filter 		= 'mask();';
			mask.style.width  		= popinNode.offsetWidth;
			mask.style.height 		= popinNode.offsetHeight;
			// mask.allowTransparency 	= true;
			mask.frameBorder		= 0;
			popinNode.appendChild(mask);
		}
	}
}

function delayedRemoveDiv(theId) {
	var popinNode = document.getElementById(theId);
	if(popinNode) {
		popinNode.parentNode.removeChild(popinNode);
	}
	else {
		alert('could not find ' + theId);
	}
}

function promoPopInClose(theId) {

	var idx = promoPopInFindPopIn(theId);

	var id 				= '';
	var backgroundId 	= '';
	var overId 			= '';

	if(idx >= 0) {
		var divs = openPopIns[idx].split(',');
		id 				= divs[0];
		backgroundId 	= divs[1];
		overId 			= divs[2];

		promoPopInDeletePopIn(theId);

		var popinNode = document.getElementById(id);
		if(popinNode) {
			popinNode.style.visibility = "hidden";
			// popinNode.parentNode.removeChild(popinNode);
			
			window.parent.setTimeout("delayedRemoveDiv('" + id + "')",10);
		}
		else {
			alert('could not delete ' + id);
		}
	
		if(backgroundId) {
			var backgroundNode = document.getElementById(backgroundId);
			if(backgroundNode) {
				backgroundNode.style.visibility = "hidden";
				backgroundNode.parentNode.removeChild(backgroundNode);
			}
			else {
				alert('could not delete ' + backgroundId);
			}
		}
	}
}


function promoPopInShowWindow(theId, top, left, width, height, position_over, url, modal, promotion) {

	// hack params for redesign ignore these params
	if(width == 420) { width = 660; }
	top='';
	left='';
	position_over='';
	modal = true;

	var backgroundId = '';
	
	if(modal && !isMacFirefox2()) {
		backgroundId = 'popinBackgroundDark';
		var bg = document.createElement('div'); 
		bg.setAttribute('id',backgroundId);
		bg.setAttribute('class','popinBackgroundDark');
		bg.setAttribute('className', 'popinBackgroundDark');
		document.body.appendChild(bg);
	}
	
	var popin = document.createElement('div'); 
	popin.setAttribute('id',theId);
	popin.style.zIndex = 20000;
	popin.style.height = height;
	document.body.appendChild(popin);
	
	var div = document.getElementById(theId);
	if(div) {
		if(url.indexOf('?') != -1) {
			url += '&f=' + theId;
		}
		else {
			url += '?f=' + theId;
		}

		if(promotion) {
			beginPromotion(promotion);
			promoClickTrack('follow');
			url += '&promotion=' + promotion;
		}

		if(url) {
			div.innerHTML = '<iframe id=iframe' + (iframeCounter++) + ' scrolling="no" allowtransparency="true" frameborder="0" marginwidth="0" marginheight="0" style="width:' + width + ';height:' + height + ';" src="' + url + '"></iframe>';
		}
		
		promoPopInOpen(theId, backgroundId, top, left, width, height, position_over, false);

	}
	else {
		alert('could not find div ' + theId);
	}
}

function promoPopInCloseWindow(theId) {
	promoPopInClose(theId);
	promoPopInGoToCloseDestination();
}

function promoPopInDoFirstVisit(revisit) {
	if(!did_newsletter && !did_account && !account) {
		var underDiv = document.getElementById('home_promo');
		if(underDiv) {
			if(revisit) {
				underDiv.style.height=173;
				underDiv.innerHTML = '<iframe id=iframe' + (iframeCounter++) + ' allowtransparency="true" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" style="width:300;height:173;margin:0px;padding:0px;" src="/gp/popins/firstvisit.html?under=1"></iframe>';
			}
			else {
				underDiv.style.height=173;
				underDiv.innerHTML = '<iframe id=iframe' + (iframeCounter++) + ' allowtransparency="true" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" style="width:300;height:173;margin:0px;padding:0px;" src="/gp/popins/firstvisit.html?under=1"></iframe>';
				setCookie('promoPopInVisitCount', 1 , 365);
				setCookie('promoPopInVisitTimeout', 1, 1);
				promoPopInShowWindow('promo_popin_div',145,'',927,525,'',"/gp/popins/firstvisit.html", true);
			}
		}
	}
	else {
		promoPopInDoSecondVisit('');
	}
}

function promoPopInDoSecondVisit(revisit) {
	if(!did_newsletter && !did_account && !account) {	
		var underDiv = document.getElementById('home_promo');
		if(underDiv) {
			if(revisit) {
				underDiv.style.height=146;
				underDiv.innerHTML = '<iframe id=iframe' + (iframeCounter++) + ' allowtransparency="true" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" style="width:300;height:146;margin:0px;padding:0px;" src="/gp/popins/storyvisit.html?revisit=1"></iframe>';
			}
			else {
				underDiv.style.height=146;
				underDiv.innerHTML = '<iframe id=iframe' + (iframeCounter++) + ' allowtransparency="true" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" style="width:300;height:146;margin:0px;padding:0px;" src="/gp/popins/storyvisit.html?under=1"></iframe>';
				setCookie('promoPopInVisitCount', 2 , 365);
				setCookie('promoPopInVisitTimeout', 1, 1);
			}
		}	
	}
	else {
		promoPopInDoThirdVisit('');
	}
}

function promoPopInDoThirdVisit(revisit) {
	if(!account && !did_account) {
		var underDiv = document.getElementById('home_promo');
		if(underDiv) {
			if(revisit) {
				underDiv.style.height=146;
				underDiv.innerHTML = '<iframe id=iframe' + (iframeCounter++) + ' allowtransparency="true" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" style="width:300;height:146;margin:0px;padding:0px;" src="/gp/popins/storyvisit.html?revisit=1"></iframe>';
			}
			else {
				underDiv.style.height=146;
				underDiv.innerHTML = '<iframe id=iframe' + (iframeCounter++) + ' allowtransparency="true" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" style="width:300;height:146;margin:0px;padding:0px;" src="/gp/popins/storyvisit.html?under=1"></iframe>';
				setCookie('promoPopInVisitCount', 3 , 365);
				setCookie('promoPopInVisitTimeout', 1, 1);
			}
		}
	}
	else {
		promoPopInDoFourthVisit('');
	}
}

function promoPopInDoFourthVisit(revisit) {
	var underDiv = document.getElementById('home_promo');
	
	var onHome = document.location.href.indexOf('/home/index.html');
	
	if(onHome >= 0) {
		if(underDiv) {
			underDiv.innerHTML = '<iframe id=iframe' + (iframeCounter++) + ' allowtransparency="true" scrolling="no" frameborder="0" marginwidth="0" marginheight="0" style="width:300;height:300;margin:0px;padding:0px;" src="/gp/popins/fourthvisit.html?under=1"></iframe>';
		}
	}
	else {
		if(underDiv) {
			underDiv.style.height=1;
		}
	}
}
