// JavaScript Document
var ci_bIE = (navigator.userAgent.toLowerCase().indexOf("msie") > -1);
var ci_bSafari = (navigator.userAgent.toLowerCase().indexOf("safari") > -1);
var ci_bMozilla = (!ci_bIE && !ci_bSafari);


if (document.getElementById("PleaseWait") != null) document.getElementById("PleaseWait").style.display = "none";

// update to true if the deal of the week coupon is showing
var dowCoupon = false
var ci_dealofweekpid
var gInitAdSource = false;
var gContext = "";
var gPageNum = 0;

var tab_lc = 0
var tab_sc = 0
var tab_cc = 0



// SET GLOBAL HEADER
		
function SetNavMenuLinks(actNavMenu, showCpnCarrier)
{

	// create featured today section
	if ((actNavMenu == "bd-printable") && (typeof(ci_FeaturedPrograms) !="undefined")) 
		SetFeaturedToday()
	
	// hidde Holiday Tabs	
	if (document.getElementById('NavTabContainerTable') != null ) 
	{
		document.getElementById('NavTabContainerTable').style.display = "none";
		document.getElementById('NavTabContainerTable').style.height = "0px";
		
	}
	
// Login / Register links at the page header:
	 
	var queryString = GetQueryString();


	var fName = GetWelcomeName()
	
	// create super saver signup section
	if (document.getElementById("supersaverBox") != null && document.getElementById("supersaverBox") !="undefined") 
		SuperSaver_box()
		
	// create daily deal section
	if (typeof(DailyDealLnk) != "undefined" && DailyDealLnk)
	{
	    if (document.getElementById("DailyDealBox") != null && document.getElementById("DailyDealBox") !="undefined") 
	    {
		    document.getElementById("DailyDealBox").innerHTML = DisplayDealyDeal();
		    document.getElementById("DailyDealBox").style.display = 'block';
	    }
	}
	
	//Coupon Caddy section
	DisplayCouponCaddy();
	
    if( fName != null )
       {
		  if (fName == "") 
			   personalization = "Welcome&nbsp;" 
		  else
          	   personalization = "Welcome, " + fName + "&nbsp;<em>(<a href='javascript:bb_signoff()'>I'm not " + fName + "</a>)</em>" 
				
		  //personalization += "&nbsp;|&nbsp;<a href='/couponweb/Login.aspx?" + queryString + "'>Sign Off</a>";
		  personalization += "&nbsp;|&nbsp;<a href='javascript:bb_signoff()'>Sign Off</a>";
       }
    else
       {
          //personalization = "<a href='/couponweb/Login.aspx?" + queryString + "' title='Sign-in to the Member Center'>Sign In</a> | <a href='/couponweb/Register.aspx?" + queryString + "' title='Sign-up and get exclusive access to special savings from Coupons.com'>Register</a>";
var	personalization = "<a href='javascript:openHeaderLoginWin();' title='Sign-in to the Member Center'>Sign In</a> | <a href='javascript:openHeaderRegWin();' title='Sign-up and get exclusive access to special savings from Coupons.com'>Sign Up</a>";
       }	
	document.getElementById("user").innerHTML = personalization 

// top navigation menu links:

<!-- LOCAL updates: top navigation image -->

	
	var CookieLocal = "cpnLocalTab" +GetQueryStringValue('pid')
	
	var showLocal = false	
	var addLocalTab = ""
	
    var bLocalTab = GetCookie(CookieLocal)
	
    if (bLocalTab != null)
	{
		addLocalTab =  "_Local"
		showLocal = true
		tab_lc = 1
	}
	//else if (document.getElementById('localOfferTabOff') != null)
	else if (typeof (ci_localOffersSupported) != "undefined" && ci_localOffersSupported)
	{
		showLocal = true
		addLocalTab =  "_Local"			
		SetCookie(CookieLocal,1,0,"/",null,null)
		tab_lc = 1
		
	}
<!-- END LOCAL updates: top navigation image -->

<!-- Savings Cards updates: top navigation image -->

		
	var CookieCard = "cpnCardsTab" +GetQueryStringValue('pid')

	var showSavCards = false
	var addSavCardsTab = ""
	
    var bSavCardsTab = GetCookie(CookieCard)
	
    if (bSavCardsTab != null)
	{
		addSavCardsTab =  "_Cards"
		showSavCards = true
		tab_sc = 1
	}

	else if (document.getElementById('eOfferTabOff') != null)
	{
		showSavCards = true
		addSavCardsTab =  "_Cards"			
		SetCookie(CookieCard,1,0,"/",null,null)
		tab_sc = 1
		
	}

<!-- END Savings Cards updates: top navigation image -->
<!-- Coupon Codes tab: top navigation image -->

		
	var CookieCodes = "cpnCodesTab" + GetQueryStringValue('pid')

	var showCpnCodes = false
	var addCodesTab = ""
	
    var bCodesTab = GetCookie(CookieCodes)
	
    if (bCodesTab != null)
	{
		addCodesTab = '_Codes'
		showCpnCodes = true
		tab_cc = 1
	}

	else if (typeof(CouponsCodesTab) != "undefined" && CouponsCodesTab )
	{
		showCpnCodes = true
		addCodesTab = '_Codes'			
		SetCookie(CookieCodes,1,0,"/",null,null)
		tab_cc = 1		
	}

<!-- END Coupon Codes updates: top navigation image -->

	var strPageHeader


	
   strPageHeader = '<div id="navWrap' + addSavCardsTab  + addLocalTab + addCodesTab + '">'
   strPageHeader +='<ul id="nav' + addSavCardsTab  + addLocalTab + addCodesTab + '">'
   strPageHeader +='<div id="pageNavMenu' + addSavCardsTab + addLocalTab + addCodesTab + '" class="' + actNavMenu + '">'
   strPageHeader +='<li id="nav1' + addSavCardsTab + addLocalTab + addCodesTab + '"><a href="/couponweb/offers.aspx?' + queryString + '" accesskey="2" title="Print free coupons from your favorite brands">Coupons</a></li>'

   if (showSavCards) 
{
   strPageHeader +='  <li id="nav2' + addSavCardsTab + addLocalTab + addCodesTab + '"><a href="/couponweb/eoffers.aspx?' + queryString + '" accesskey="3" title="Register and add coupons to your store loyalty cards">Savings Cards</a></li>'
}

   if (showLocal) 
{
   strPageHeader +='  <li id="nav3' + addSavCardsTab + addLocalTab + addCodesTab + '"><a href="/couponweb/localoffers.aspx?' + queryString + '" accesskey="3" title="Find savings for restaurants and businesses in your area">Local Coupons</a></li>'
}

   if (showCpnCodes) 
{
   strPageHeader +='  <li id="nav4' + addSavCardsTab + addLocalTab  + addCodesTab + '"><a href="http://www.coupons.com/coupon-codes/" accesskey="3" title="Get Coupon Codes and save when you shop online">Coupon Codes</a></li>'
}

if (! showSavCards && !showLocal && !showCpnCodes)
{
	strPageHeader +='  <li id="nav4"><a href="/couponweb/Recipes/Main.aspx?' + queryString + '" accesskey="4" title="Recipes">Recipes</a></li>'
}
	strPageHeader +='  <li id="nav5' + addSavCardsTab + addLocalTab + addCodesTab + '"><a href="/couponweb/register.aspx?' + queryString + '" accesskey="5" title="Sign-up and get access to special savings from Coupons.com">Members Center</a></li>'
	strPageHeader +='  <li id="nav6' + addSavCardsTab + addLocalTab + addCodesTab + '"><a href="/couponweb/aboutus.aspx?' + queryString + '" accesskey="6" title="Learn about the different ways you can save with Coupons.com">More</a></li>'
	
	strPageHeader +='  </div>'
	strPageHeader +='  </ul>'
	strPageHeader +='</div>'
	
	


	document.getElementById("navWrapArea").innerHTML = strPageHeader;
	

	var pageName = curPageName()

    var strSidebarNav = '<div style="position: relative;z-index:100000000;"><div id="FlyOutDiv" style="position: absolute;z-index:100000000;"></div></div>'
		
	if (showLocal)
		strSidebarNav += "<div id='asyncPlaceholder_2271922_UID'></div>"
		//strSidebarNav += "<div id='asyncPlaceholder_2274238_UID'></div>"
	//    strSidebarNav += DisplayRDC()


	strSidebarNav += '<li id="accCoupons"><h4><a href="/couponweb/offers.aspx?' + queryString + '" ' + (actNavMenu == 'bd-printable' ? 'class="selected"' : '' ) + ' >COUPONS</a></h4><div id="listCategory"></div></li>'
	
	
	if (showSavCards)
	{
		strSidebarNav +=  '<li id="accCards"><h4><a href="/couponweb/eoffers.aspx?' + queryString + '" ' + (actNavMenu == 'bd-cards' ? 'class="selected"' : '' ) + ' >SAVINGS CARDS</a></h4><div id="listCardsCategory"></div></li>'
		
	}
	
	if (showLocal)
	{
		strSidebarNav +=  '<li id="accLocal"><h4><a href="/couponweb/localoffers.aspx?' + queryString + '" ' + (actNavMenu == 'bd-local' ? 'class="selected"' : '' ) + ' >LOCAL COUPONS</a></h4><div id="listLocalCategory"></div></li>'
	}
	
	
	if (showCpnCodes)
	{
		strSidebarNav +=  '<li id="accOnlineSavings"><h4><a href="http://www.coupons.com/coupon-codes/" ' + (actNavMenu == 'bd-codes' ? 'class="selected"' : '' ) + ' >COUPON CODES</a></h4></li>'
	}
	
	if (actNavMenu == 'bd-about' || actNavMenu == 'bd-members' || actNavMenu == 'bd-recipes')
	{
		strSidebarNav +=  '<li id="accRecipes"><h4><a href="/couponweb/Recipes/Main.aspx?' + queryString + '" ' + (actNavMenu == 'bd-recipes' ? 'class="selected"' : '' ) + ' >RECIPES</a></h4><div id="listRecipes"></div></li>'
	}

	//if (typeof(DailyDealLnk) != "undefined" && DailyDealLnk && pageName != 'login' && pageName != 'emailsignup')
	//if (typeof(DailyDealLnk) != "undefined" && DailyDealLnk)
	//strSidebarNav +=  DisplayDealyDeal()
	
	document.getElementById("sidebarNav").innerHTML = strSidebarNav
	

	if (actNavMenu == "bd-cards")
	{
		document.getElementById("dvPrintBtn").innerHTML = "<h5><a href='javascript:btnWhatonCard()' title='What is on my card?'>What is on my card? &raquo</a></h5>"
		
	}
		 
	if (showCpnCarrier == 0 ){
		
		document.getElementById("util").style.display = "none"
		document.getElementById("sbH4-FeaturedToday").style.display = "none"
		document.getElementById("featuredBrends").style.display = "none"
		document.getElementById("zip").style.display = "none"
		
		}
		
}


// -- set cookie for user name to user at Welcome message

function GetWelcomeName()
{
	
    var strUser = GetCookie("cpnUser")
	
    if (typeof(ci_regObj) !="undefined")
	{
	
	
		if( ci_regObj.isLoggedIn > 0 && ci_regObj.email != '')
		{
			var user = ci_regObj.user.replace(/^\s+/,'').replace(/\s+$/,'');
			//if ( ci_regObj.isAutoreg <= 0 )
			//{
				if (strUser == null) SetCookie("cpnUser",user,0,"/",null,null); 
				return user
			//}
				
		}
		else if (strUser != null)
		{
				DeleteCookie( "cpnUser", "/", "" );
				return null
		}
	}
	else
		return strUser
	 

}

// ---- SuperSaver_NavLink
function SuperSaver_box(){	
	
	var strHTML = '<h3>SuperSavers save more!</h3>'
+'			Sign up for our weekly newsletter to receive coupons by email!'
+'        <div class="btnSignUp">'
+'             <img src="http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/btn-SignMeUp-large.gif" onclick="SuperSaver_su()"/>'
+'        </div>'

	document.getElementById("supersaverBox").innerHTML = strHTML
};

function SuperSaver_su(){
	var fName = GetWelcomeName()
	var queryString = 'pid='+ GetQueryStringValue ('pid') + '&zid=' + GetQueryStringValue ('zid')  + '&nid=' + GetQueryStringValue ('nid')
	var htmlLink;
	if( fName != null ) {
		htmlLink = "/couponweb/register.aspx?" + queryString;
	}
    else  {
		SetCookie("cpnSSbox",1,0,"/",null,null)
        htmlLink = "/couponweb/emailsignup.aspx?" + queryString;
	};
	
	//toolbar 
	setCouponToolbarFlag();
	window.location = htmlLink
};

function setCouponToolbarFlag(){
	if (typeof(TPI) !="undefined"){
		var oToolbar = new TPI.Toolbar("CT2559647");
		var oReturn = oToolbar.IsVisible();
		var bbcpnToolbar = GetCookie("cpnToolbar");
		if (oReturn.returnValue){
			if (bbcpnToolbar == null) SetCookie("cpnToolbar",1,0,"/",null,null)
		}
		else {
			if (bbcpnToolbar != null) DeleteCookie( "cpnToolbar", "/", "" ); 
		};
	};
};



function RotateAllAds(sContext,bInitAdSource,nPage)
{
	//alert("RotateAllAds Context='" + sContext + "' bInitAdSource=" + bInitAdSource + " nPage='" + nPage + "'");
	// Default sContext if parameter is missing
	if (sContext == "undefined" || sContext == null ) sContext = "";
	
	// Put parameters used in the call to RotateAdPlacement in a set of
	// global variables so it can be accessed by calls triggered by setTimeout
	gInitAdSource = bInitAdSource;
	gContext = sContext;
	gPageNum = nPage;
	// sContext is the context identifier indicating what page type is displaying
	// the ads
	// bInitSource calls AdBlob only for IFrames where the src has not yet been assigned.
	
	RotateAdPlacement("cimRightBanner",160,600,"INSERT_SECTION_CODE_HERE",bInitAdSource,gContext,gPageNum);
	setTimeout("RotateAdPlacement(\"cimBelowRightBanner\",160,210,\"INSERT_SECTION_CODE_HERE\",gInitAdSource,gContext,gPageNum)",1500);
	// Delay is shorter since there will never be a db delay for any placement other than the RightBanner
	setTimeout("RotateAdPlacement(\"cimFtrBanner\",728,90,\"INSERT_SECTION_CODE_HERE\",gInitAdSource,gContext,gPageNum)",2500);
}


function RotateAdPlacement(sPlacement,AdWidth,AdHeight,SectionCode,bInitAdSource,sContext,nPage)
{
// rotate ad banner. Parameters specify the location of the ad placement and 
// the dimensions of the Ad.
var rBannerFrame = document.getElementById(sPlacement);
if( rBannerFrame != null )
{
	var mac = "";
	var zip = "";
	var userInfo = GetCookie("UserInfo");
	if(userInfo != null)
	{
	mac = GetCookieVal(userInfo,"mac");
	zip = GetCookieVal(userInfo,"ZIP");
	}

	if(zip.length == 0)
	{
		var sessionInfo = GetCookie("SessionInfo");
		if(sessionInfo != null)
		{
			zip = GetCookieVal(sessionInfo,"ZIP");
		}
	}
	// See what page the ad is being displayed on. If is needed to handle mac urls
	var url = document.URL;
	var pg;
	if (url.indexOf("/") > -1)
            pg =(url.substring(url.lastIndexOf("\/")+1,url.lastIndexOf("\.")));
	else
            pg =(url.substring(url.lastIndexOf("\\")+1,url.lastIndexOf("\.")));
        
	var pzn = GetQueryStringValue ('pid') + GetQueryStringValue ('zid') + GetQueryStringValue ('nid');
	
	//alert("Displaying Placement=" + sPlacement + " sContext='" + sContext + "'" + " spage=" + pg + " npage=" + nPage);
	
	// Delete any existing child objects within the IFrame.  These are created by PointRoll ads and need
	// to be cleaned up before the next ad is displayed.
	// NOTE: The ad IFRAME should always be placed within a div containing nothing but the IFrame.  This allows
	// for safe cleanup of any objects inserted by PR.
	DeleteIFrameSiblings(rBannerFrame);
	
	// Make sure the IFrame is sized properly.
	if (AdWidth==160 && AdHeight==600)
	{
	    rBannerFrame.style.height="620px";
	    rBannerFrame.style.width="160px"; 
	}
	else if (AdWidth==160 && AdHeight==210)
	{
	    rBannerFrame.style.height="210px";
	    rBannerFrame.style.width="160px"; 
	}
	else if (AdWidth==728 && AdHeight==90)
	{
	    rBannerFrame.style.height="90px";
	    rBannerFrame.style.width="729px"; 
	}

	if (!bInitAdSource || rBannerFrame.src == "")
	{
		rBannerFrame.src = "http://couponbar.coupons.com/adblob.asp?AdSize=" + AdWidth + "x" + AdHeight + 
		                   "&pzn=" + pzn + 
		                   "&sectioncode=" + SectionCode + 
		                   "&req=" + (new Date()).getTime() + 
		                   "&zip=" + zip + 
		                   "&did=" + mac +
		                   "&spage=" + pg +
		                   "&npage=" + nPage;
	}
	else
	{
		//alert("Src already set");
	}
}
}

// Remove all siblings of the specified IFrame. This is done to clean up any divs created by the PointRoll
// IFrame breaking code.  Unfortunately, this code was not created to handle the situation where the PointRoll 
// ad is refreshed without loading the entire page, therefore the need for this code.
function DeleteIFrameSiblings(IFrame)
{
  if (IFrame != null)
  {
    // Get the parent of the IFrame
    var parent = IFrame.parentNode;
    // Ignore call if it was made for a root node
    if (parent != null)
    {
      //alert("Found IFRAME Parent. id=" + parent.getAttribute('id'));
      var siblings = parent.childNodes;
      // remove all siblings of the IFrame 
      for (var i=siblings.length-1; i>=0; i--)
      {
        if (siblings[i] != IFrame)
        {
          //alert("Deleting sibling. id=" + siblings[i].getAttribute('id'));
          parent.removeChild(siblings[i]);
        }
      }
    }
  }
}


//Dealy Deal
function OpenDealyDealFlyOut(yPos)
{

	
     var zip = "";

     var userInfo = GetCookie("UserInfo");

     if (userInfo != null)
         zip =  GetCookieVal(userInfo,"ZIP");

     if (zip.length == 0)
		 zip = ci_sObj.zip
	
    var pzn = GetQueryStringValue ('pid') + GetQueryStringValue ('zid') + GetQueryStringValue ('nid');

 
   var TAFDiv = document.getElementById('FlyOutDiv');    
   var FlyoutHTML;

	var strBid = GetQueryStringValue("bid")
	if ((strBid == null || strBid == "") && typeof(ci_sObj) !="undefined") 
		strBid = ci_sObj.sessionid 
	
	//var strUserEmail = ""
	//if (typeof(ci_regObj) !="undefined" && ci_regObj.isLoggedIn > 0 && ci_regObj.email != '') 
	//	strUserEmail = ci_regObj.email

		FlyoutHTML = '<div class="dealyDealFlyout">'
			+' 	<p class="closeX"><a href="javascript:CloseFlyoutWin()" class="close">Close</a></p>'			
			+' <div class="flyiFrame">'
			+'<iframe id="ciContentFramecode" src="http://dailydeal.coupons.com/iframe/'+ zip
			//+'<iframe id="ciContentFramecode" src="http://coupons.dailydealrqa.com/iframe/'+ zip			
			+'?lc='+ tab_lc +'&sc='+ tab_sc +'&cc=' + tab_cc + '&bid='+ strBid 
			+ '&pid='+ GetQueryStringValue ('pid') + '&zid=' + GetQueryStringValue ('zid')  + '&nid=' + GetQueryStringValue ('nid') + '&theme=1" frameborder="0" width="680px" height="630px" scrolling="no"></iframe>'
		    + '</div>'
            //+'<p class="moreCps2"><a href="javascript:CloseFlyoutWin()" class="arrOrgRt">Close window</a></p>'
		    + '</div>'

   var scrollYPos = ( window.pageYOffset || document.documentElement.scrollTop );       
		
		
		yPosDiff = 200
		
        TAFDiv.style.left = '200px';
        TAFDiv.style.top  = (yPos - yPosDiff +scrollYPos) + 'px';
		
        if( yPos-290 < 0 )
        {
            window.scrollTo(0,scrollYPos+(yPos-295));
        } 
		
   TAFDiv.innerHTML = FlyoutHTML;
}

function DisplayDealyDeal() 
{

	var strHTML = '<h4 class="sbH4" id="sbH4-DailyDeal" onclick="var e = arguments[0] || window.event; OpenDealyDealFlyOut(e.clientY); return false;"  style="cursor: hand; cursor: pointer;">Daily Deal</h4>'
		 +' <div class="ddeal"  onclick="var e = arguments[0] || window.event; OpenDealyDealFlyOut(e.clientY); return false;">'
		 +'            <div class="dealWrap"><img src="http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/dd_calendar.gif"/>'
		 +'                <div class="dealTxt">'
		 +'                     <h3>Save up to 90% on Family Fun, Sports, Restaurants, Events & More!</h3>'
		 +'               </div>'
		 +'           </div>'
		 +'      </div>';
		 
	// Wrap the DD area with the tag needed to show that is is associated with an IE8 slice
	//strHTML = '<div class="hslice" id="DDSlice"><span class="entry-title" style="display:none">Coupons.com Daily Deal</span>' + strHTML + '</div>';
	

	return strHTML
}


function CloseFlyoutWin(){ 
	if (document.getElementById("FlyOutDiv") != null){
        var FlyOutDiv = document.getElementById('FlyOutDiv');
        FlyOutDiv.style.left = "-2000px";
	};
};

function curPageName(){
	// See what page the ad is being displayed on. If is needed to handle mac urls
	var url = document.URL;
	var pg;
	if (url.indexOf("/") > -1)
            pg =(url.substring(url.lastIndexOf("\/")+1,url.lastIndexOf("\.")));
	else
            pg =(url.substring(url.lastIndexOf("\\")+1,url.lastIndexOf("\.")));
        
	return pg.toLowerCase() 
};

//RDC
function RenderRDC()
{
    var zipCode = document.getElementById("txtZipRdc").value;

    if( zipCode.length != 5 )
        document.getElementById("rdcFlyError").style.display = 'block';
    else    
        window.open('http://www.restaurant.com/rdc_site2.net/listings.aspx?prti=4661&PageSize=0&Page=1&sorting=Relevance&Zip='+zipCode+'&SearchRadius=15','RDC','width=1200,height=750,toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes')
}

function OpenRDCFlyOut(yPos)
{
     var zip = "";

     var userInfo = GetCookie("UserInfo");

     if (userInfo != null)
         zip =  GetCookieVal(userInfo,"ZIP");

     //if( typeof(document.getElementById(ci_controlPrefix + "ZipCode")) != "undefined" && document.getElementById(ci_controlPrefix + "ZipCode") != null ) 
     //   zip = document.getElementById(ci_controlPrefix + "ZipCode").value;
            
     if(zip.length == 0)
		 zip = ci_sObj.zip
   
    var pzn = GetQueryStringValue ('pid') + GetQueryStringValue ('zid') + GetQueryStringValue ('nid');

 
   var TAFDiv = document.getElementById('FlyOutDiv');    
   var FlyoutHTML;

	var strBid = GetQueryStringValue("bid")
	if ((strBid == null || strBid == "") && typeof(ci_sObj) !="undefined") 
		strBid = ci_sObj.sessionid 
	
	//var strUserEmail = ""
	//if (typeof(ci_regObj) !="undefined" && ci_regObj.isLoggedIn > 0 && ci_regObj.email != '') 
	//	strUserEmail = ci_regObj.email

        if(zip.length == 0)
            zip = 'Enter your zipcode'
          
        var FlyoutHTML = '<div style="position: relative; width: 583px; height: 542px; z-index: 100000;'
        FlyoutHTML += (ci_bIE ? "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/rdc_flyoutBg.png', sizingMethod='scale');" : "background: url(http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/rdc_flyoutBg.png) no-repeat;" ) + '"></div>'
          
            
		FlyoutHTML += '<div class="rdcFlyout">'
        + '<p class="closeX"><a href="javascript:CloseFlyoutWin()" class="close">Close</a></p>'
        + '<div class="rdcFlyContent">'
        + '<h3><span style="color: #019ae2;">Save up to 80%</span> on Restaurant Gift Certificates.</h3>'
        + '<div class="rdcFlyTxt">Enter your zip code below to see restaurants in your area. Pick the certificates you want and the discount will be applied to your shopping cart.</div>'
        + '<div id="rdcFlyError">Please enter a valid zip code.</div>'
        + '<div>'
        + '<div class="rdcFlyZip">'
        + '<input type="text" onkeypress="var e = arguments[0] || window.event; if(e.keyCode == 13) return false;" onkeydown="var e = arguments[0] || window.event; if(e.keyCode == 13) { ChooseNewZip(); }" onblur="if(this.value==\'\') {this.value=\''+zip+'\';}" onfocus="this.value=\'\'" value="'+zip+'" id="txtZipRdc" name="txtZipRdc">'
        + '</div>'
        + '<div class="rdcFlyBtn"><a title="Find Restaurants" href="javascript:RenderRDC();">Find Restaurants</a></div>'
        + '</div>'
        + '<div>Find new gift certificates every day for restaurants serving: American, Italian, Asian, Mexican, Pizza, Seafood, Steak and More!</div>'
        + '</div>'
        + '</div>'

   var scrollYPos = ( window.pageYOffset || document.documentElement.scrollTop );       
		
		
		yPosDiff = 170
		
        TAFDiv.style.left = '200px';
        TAFDiv.style.top  = (yPos - yPosDiff +scrollYPos) + 'px';
		
        if( yPos-290 < 0 )
        {
            window.scrollTo(0,scrollYPos+(yPos-295));
        } 
		
   TAFDiv.innerHTML = FlyoutHTML;
}

function DisplayRDC() 
{

	var strHTML = '<h4 class="sbH4" id="sbH4-RDC" onclick="var e = arguments[0] || window.event; OpenRDCFlyOut(e.clientY); return false;"  style="cursor: hand; cursor: pointer;">Daily Deal</h4>'
		 +' <div class="rdcTile"  onclick="var e = arguments[0] || window.event; OpenRDCFlyOut(e.clientY); return false;">'
		 +'            <div class="rdcWrap"><img src="http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/RDC_plateFork.gif"/>'
		 +'                <div class="rdcTxt">'
		 +'                     <h3>Save up to 80% on Local Dining</h3>'
		 +'               </div>'
		 +'           </div>'
		 +'      </div>'
		 +'<div style="position: absolute; left: -10000px; top: -10000px;"><img src="http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/rdc_flyoutBg.png"></div>';
		 
	// Wrap the DD area with the tag needed to show that is is associated with an IE8 slice
	//strHTML = '<div class="hslice" id="DDSlice"><span class="entry-title" style="display:none">Coupons.com Daily Deal</span>' + strHTML + '</div>';
	

	return strHTML
}

// global Login header
function openHeaderRegWin(){
	if (document.getElementById("dvPopupWin") != null){		
        var TAFDiv = document.getElementById('dvPopupWin');
        TAFDiv.style.left = "-2000px";
	};
	   	var TAFDiv = document.getElementById('FlyOutDiv');    
  		var FlyoutHTML;
        FlyoutHTML = '<div id="bb_dvRegister" style="'
        FlyoutHTML += (ci_bIE ? "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/bg_loginHover_header.png', sizingMethod='scale');" : "background: url(http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/bg_loginHover_header.png) no-repeat;" ) + '"></div>'          
            
		FlyoutHTML +='<div class="bb_ProgressBar" id="bb_RegProgressBar">'
       
+'       	<p class="closeX"><a href="javascript:CloseFlyoutWin(0)" class="close">Close</a></p>'
+'			<img src="http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/progress_bar.gif"/>'        
+' 		 </div>'

+'		<div class="headerLogin_ajcontent" id="bb_RegWin"><div class="headerLogin_fbpage">'
    
+'       <p class="closeX"><a href="javascript:CloseFlyoutWin()" class="close">Close</a></p>'
    
+'       <div class="headerLogin_ajheader">'
+' 			<h5>Sign Up</h5> '
    	
+'        	<ul>'
+'           	<li>Already a member?</li>'
+'            	<li><a href="javascript:openHeaderLoginWin();">Sign In</a></li>'
+'       	</ul>'
+'        </div>'
        
+'        <p>Sign up for free and get exclusive access to members-only savings, rewards and special promotions from Coupons.com</p>'
        
+'        <hr class="headerLogin_aj_hr300" />'

if (typeof(SupportFBConnect) != "undefined"  && SupportFBConnect != null && SupportFBConnect == 1){          
	FlyoutHTML +='<p>Provide your info and sign up through your Facebook account:</p>'
        
+'        <a href="javascript:bb_fblogin(0);"><img src="http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/FB_SignUp.gif" alt="Sign up with Facebook" /></a>'
      
+'        <div class="bb_dverrMsg" id="bb_errRegMsg"></div>'    
      
+'		<div class="inputInfo">'
+'        	<p>Or enter your info below:</p>'
}else{
	FlyoutHTML +='<div class="bb_dverrMsg" id="bb_errRegMsg"></div>'
+		'<div class="inputInfo">'
+'        	<p>Enter your info below:</p>'
};
	
	FlyoutHTML +='<div class="field">'
+'            	<label>Email Address</label>'
+'                <input type="text" id="bb_regemail" name="bb_regemail" />'
+'            </div>'
            
+'            <div class="field">'
+'            	<label>Password</label>'
+'                <input type="password" id="bb_regpsw" name="bb_regpsw" />'
+'            </div>'
            
+'            <div class="chkboxarea">'
            
+'                <div class="chkboxfield">'
+'                    <input type="checkbox" id="bb_regOpt1" name="bb_regOpt1" checked="yes"/>'
+'                    <label>Send me the weekly SuperSaver (<a href="http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_include/supersaver.html" target="popup" onClick="bb_wOpen(\'http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_include/supersaver.html\', \'Sample\', 600, 700); return false;">sample</a>) and other special Coupons.com offers.</label>'
+'                </div>'
                
+'                <div class="chkboxfield">'
+'                    <input type="checkbox" id="bb_regOpt2" name="bb_regOpt2"  checked="yes"/>'
+'                    <label>Send me offers from Coupons.com partners.</label>'
+'               </div>'

+'                <div class="chkboxfield">'
+'                    <input type="checkbox" id="bb_regTerms" name="bb_regTerms" />'
+'                    <label>I agree to the <a href="http://www.couponsinc.com/Corporate/Terms.aspx" target="_new">Terms of Use</a> and <a href="http://www.couponsinc.com/Corporate/Privacy.aspx" target="_new">Privacy Policy</a>.</label>'
+'                </div>'
                
+'            </div>'
         		
+'            <a href="javascript:bb_SignUpUser();"><img class="btnLoginBtn" src="http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/btn_sign_up2.gif" alt="Sign Up" /></a>'
           
+'        </div>'      
    
+'    	</div>'
+'    </div>'	
		
    TAFDiv.style.left = '280px';
    TAFDiv.style.top  = '-70px';		
    TAFDiv.innerHTML = FlyoutHTML;	
};

function openHeaderLoginWin(){
	if (document.getElementById("dvPopupWin") != null){		
        var TAFDiv = document.getElementById('dvPopupWin');
        TAFDiv.style.left = "-2000px";
	};
	   	var TAFDiv = document.getElementById('FlyOutDiv');    
  		var FlyoutHTML;
        FlyoutHTML = '<div id="bb_dvLogin" style="'
        FlyoutHTML += (ci_bIE ? "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/bg_loginHover_header.png', sizingMethod='scale');" : "background: url(http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/bg_loginHover_header.png) no-repeat;" ) + '"></div>'          
            
		FlyoutHTML +='<div class="bb_ProgressBar" id="bb_LogProgressBar">'       
+'       	<p class="closeX"><a href="javascript:CloseFlyoutWin(0)" class="close">Close</a></p>'
+'			<img src="http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/progress_bar.gif"/>'        
+' 		 </div>'

+'		<div class="headerLogin_ajcontent" id="bb_LogWin"><div class="headerLogin_fbpage">'
    
+'       <p class="closeX"><a href="javascript:CloseFlyoutWin()" class="close">Close</a></p>'
   
+'       <div class="headerLogin_ajheader">'
+' 			<h5>Sign In</h5> '
    	
+'        	<ul>'
+'               <li>Not a member?</li>'
+'            	 <li><a href="javascript:openHeaderRegWin();">Sign Up</a></li>'
+'          </ul>'
+'        </div>'

+'        <hr class="headerLogin_aj_hr300" />'

if (typeof(SupportFBConnect) != "undefined"  && SupportFBConnect != null && SupportFBConnect == 1){  	
	FlyoutHTML +='<p>Sign in using your Facebook account:</p>'
        
+'        <a href="javascript:bb_fblogin(1);"><img src="http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/FB_login.gif" alt="Login with Facebook" /></a>'
        
+'        <div class="bb_dverrMsg" id="bb_errLogMsg"></div> '   

+'		<div class="inputInfo">'
+'        	<p>Or enter your info below:</p>'
} 
else {
	FlyoutHTML +='<div class="bb_dverrMsg" id="bb_errLogMsg"></div> '   

+'       <div class="inputInfo">'
+'        	<p>Enter your info below:</p>'
}
            
FlyoutHTML +='<div class="field">'
+'            	<label>Email Address</label>'
+'                <input type="text" id="bb_logemail" name="bb_logemail" />'
+'            </div>'
            
+'            <div class="field">'
+'            	<label>Password</label>'
+'                <input type="password" id="bb_logpsw" name="bb_logpsw" onkeydown="var e = arguments[0] || window.event; if(e.keyCode == 13) {bb_LoginUser();}"/>'
+'                <label><a href="javascript:openHeaderFogetPswWin();">Forgot your password?</a></label>'
+'            </div> '           
 
+'            <div class="chkboxarea">'
+'                <div class="chkboxfield">'
+'                     <input type="checkbox" id="bb_LogRemMe" name="bb_LogRemMe"  checked="yes"/>'
+'                     <label>Remember Me</label>'
+'                </div>'
+'			</div>'
         		
+'            <a href="javascript:bb_LoginUser();"><img class="btnLoginBtn" src="http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/btn_sign_in.gif" alt="Sign In" /></a>'            
     
+'        </div> '     
    
+'    	<p style="margin-top:35px;"><a href="http://www.couponsinc.com/Corporate/Terms.aspx" target="_new">Terms of Use</a> and <a href="http://www.couponsinc.com/Corporate/Privacy.aspx" target="_new">Privacy Policy</a></p>'
+'</div>'	
		
        TAFDiv.style.left = '280px';
        TAFDiv.style.top  = '-70px';		
   		TAFDiv.innerHTML = FlyoutHTML;	
};
function openHeaderFogetPswWin(){        

	   	var TAFDiv = document.getElementById('FlyOutDiv');    
  		var FlyoutHTML;
        FlyoutHTML = '<div style="position: relative; width:439px; height:477px; z-index: 100000;'
        FlyoutHTML += (ci_bIE ? "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/bg_loginHover_header.png', sizingMethod='scale');" : "background: url(http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/bg_loginHover_header.png) no-repeat;" ) + '"></div>'          
            
		FlyoutHTML += ' <div class="headerLogin_ajcontent"> <div class="headerLogin_fbpage">'
    
+'       <p class="closeX"><a href="javascript:CloseFlyoutWin()" class="close">Close</a></p>'
   
+'       <div class="headerLogin_ajheader">'
+' 			<h5>Sign In</h5> '
    	
+'        	<ul>'
+'               <li>Not a member?</li>'
+'            	 <li><a href="javascript:openHeaderRegWin();">Sign Up</a></li>'
+'          </ul>'
+'        </div>'

+'        <hr class="headerLogin_aj_hr300" />'
        
+'        <div class="bb_dverrMsg" id="bb_errFogPaswMsg"></div> '   
      
+'		<div class="inputInfo">'
+'        	<p>&nbsp;</p>'
            
+'            <div class="field">'
+'            	<label>Email Address</label>'
+'                <input type="text" id="bb_fogotemail" name="bb_fogotemail" />'
+'            </div>'
         		
+'            <a href="javascript:bb_SendPsw();"><img class="btnLoginBtn" src="http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/btn_sendreminder_red.gif" alt="Sign In" /></a>'            
     
+'        </div> '     
    
+'    	<p style="margin-top:35px;"><a href="http://www.couponsinc.com/Corporate/Terms.aspx" target="_new">Terms of Use</a> and <a href="http://www.couponsinc.com/Corporate/Privacy.aspx" target="_new">Privacy Policy</a></p>'
+'    </div>'	
		
        TAFDiv.style.left = '280px';
        TAFDiv.style.top  = '-70px';		
   		TAFDiv.innerHTML = FlyoutHTML;	
};
//-----
function bb_LoginUser(){
	var pid = GetQueryStringValue ('pid');
	var nid = GetQueryStringValue ('nid');
	var strEmail = document.getElementById("bb_logemail").value;
	var strPasswd = document.getElementById("bb_logpsw").value;
	var remember = 0;
	if (document.getElementById("bb_LogRemMe").checked)	remember =1;	
	if (strEmail != '' && strPasswd != ''){
	  	document.getElementById("bb_LogWin").style.display = "none";
	  	document.getElementById("bb_LogProgressBar").style.display = "block";
		LogUserIn(strEmail, strPasswd, pid, nid, remember);
		setTimeout("bb_isUserLogin_ajax()",900);}
	else
		document.getElementById("bb_errLogMsg").innerHTML = "Please fill in your email and password";
};
//-----
var bb_cntUserLog = 0;
function bb_isUserLogin_ajax(){  
  if (ci_LoggedInUser == null && bb_cntUserLog == 10){
	  	document.getElementById("bb_LogWin").style.display = "block";
	  	document.getElementById("bb_LogProgressBar").style.display = "none";
 		document.getElementById("bb_errLogMsg").innerHTML = "We are experiencing difficulties. Please try again later";
		bb_cntUserLog = 0;
  };
  if (ci_LoggedInUser == null && bb_cntUserLog < 10){
     setTimeout("bb_isUserLogin_ajax()",300);
	 bb_cntUserLog ++;
     return; 
  };   
  if (ci_LoggedInUser != null){
	if (ci_LoggedInUser.IsLoggedIn == 1){		
		var pageName = curPageName();					  
		if (pageName == 'login') window.location.href ="offers.aspx?" + GetQueryString();
		if (pageName == 'eoffers') { ReDrawAfterLogin(); document.getElementById("dvHeadLogin").innerHTML = "" }
		bb_updateWelcomeMsg(ci_LoggedInUser.FName);	
		CloseFlyoutWin();	
	}
	else 
	  	document.getElementById("bb_LogWin").style.display = "block";
	  	document.getElementById("bb_LogProgressBar").style.display = "none";
		document.getElementById("bb_errLogMsg").innerHTML = "Invalid email or password";
  };
};
//-----
function bb_updateWelcomeMsg(fName){	 
	var queryString = GetQueryString();
	var personalization = "";

    if( fName != null ) {
		if(fName.replace(/\s/g,"") == "")		  
			 personalization = "Welcome&nbsp;" 
	    else
          	 personalization = "Welcome, " + fName + "&nbsp;<em>(<a href='/couponweb/Login.aspx?" + queryString + "'>I'm not " + fName + "</a>)</em>"; 
				
		personalization += "&nbsp;|&nbsp;<a href='/couponweb/Login.aspx?" + queryString + "'>Sign Off</a>";
 		document.getElementById("user").innerHTML = personalization; 
    };	
};
//----
function bb_CloseLoginWin(){ 
	if(document.getElementById('BrandFlyOutDiv') != null ){  
       var BrandFlyOutDiv = document.getElementById('BrandFlyOutDiv');
       BrandFlyOutDiv.style.left = "-2000px";
	};
};
//----
function bb_SignUpUser(){
	var strEmail = document.getElementById("bb_regemail").value;
	var strPasswd = document.getElementById("bb_regpsw").value;
	
	var PID = GetQueryStringValue ('pid');
	var NID = GetQueryStringValue ('nid');
	
	if (!bb_isEmailValid(strEmail))
		document.getElementById("bb_errRegMsg").innerHTML = "Invalid email address"
	else if (!bb_isPswValid(strPasswd))
		document.getElementById("bb_errRegMsg").innerHTML = "Invalid password. Please enter a password of 4 or more characters"	
	else if (strEmail.replace(/\s/g,"") == '' && strPasswd.replace(/\s/g,"") == '')
		document.getElementById("bb_errRegMsg").innerHTML = "Please fill in your email and password"
	else if (!document.getElementById("bb_regTerms").checked)
		document.getElementById("bb_errRegMsg").innerHTML = "You need to accept the terms of use to register"	
	else
	{
		var bb_SupSav = 0;
		var  bb_otherEmail = 0;
		if (document.getElementById("bb_regOpt1").checked) bb_SupSav = 1		
		if (document.getElementById("bb_regOpt2").checked) bb_otherEmail = 1
		
		document.getElementById("bb_RegWin").style.display = "none";
		document.getElementById("bb_RegProgressBar").style.display = "block";
			
		RegisterCouponWebUserWithOptIn(NID, PID, strEmail, strPasswd, 0, 0, '', bb_SupSav, bb_otherEmail, 0, 0)
		setTimeout("bb_submitNewUserStatus()",500)		
	};	
};
//-------
var bb_cntUserReg = 0
function bb_submitNewUserStatus(){
  if( ci_LoggedInUser == null && bb_cntUserReg < 15){
	  bb_cntUserReg ++;
      setTimeout("bb_submitNewUserStatus()",1000);
      return; 
  };  
  if (bb_cntUserReg == 15){
	  bb_cntUserReg = 0;
	  document.getElementById("bb_RegWin").style.display = "block";
	  document.getElementById("bb_RegProgressBar").style.display = "none";
	  document.getElementById("bb_errRegMsg").innerHTML = "We are experiencing difficulties. Please try again later";	  
	  return;
  };   
  if( ci_LoggedInUser != null){	  
		if (ci_LoggedInUser.IsLoggedIn == 1){
				var pageName = curPageName()					  
				if (pageName == 'login') window.location.href ="offers.aspx?" + GetQueryString()
				
				bb_updateWelcomeMsg("");
				CloseFlyoutWin();
		}
		else {
			document.getElementById("bb_RegWin").style.display = "block";
			document.getElementById("bb_RegProgressBar").style.display = "none";

			if (ci_RegisterUser.UserID == 1)
				document.getElementById("bb_errRegMsg").innerHTML = "Email address already registered";
			else 
				document.getElementById("bb_errRegMsg").innerHTML = "We are experiencing difficulties. Please try again later.";
		};	
  }; 
};
//-------
function bb_isPswValid(psw){
   var single_exp7 = /[\"]/ig	
   if(psw.replace(/\s/g,"") == "")
      return false;
   else 
   { 	
      if  ((psw.search(/\s/gi)) !=-1) return false; 		  
      if  ((psw.search(single_exp7)) !=-1) return false;		  
      if ( (psw.length < 4) || (psw.length > 10) ) return false;           
   }; 
   return true
};
//-------
function bb_isEmailValid(addr){   
    var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
    if((addr=='') ||(isWhitespace(addr))) return false;
    else {
        for (i=0; i<invalidChars.length; i++){if (addr.indexOf(invalidChars.charAt(i),0) > -1)   return false;}       
        for (i=0; i<addr.length; i++) {if (addr.charCodeAt(i)>127)  return false;}            

        var atPos = addr.indexOf('@',0);
        if (atPos == -1)  return false;
		if (atPos == 0)  return false;
        if (addr.indexOf('@', atPos + 1) > - 1) return false;
        if (addr.indexOf('.', atPos) == -1)  return false;
        if (addr.indexOf('@.',0) != -1) return false;
        if (addr.indexOf('.@',0) != -1) return false;
		if (addr.indexOf('..',0) != -1)  return false;

        var suffix = addr.substring(addr.lastIndexOf('.')+1);
        if (suffix.length < 2 || suffix.length > 3){
                 switch(suffix){
                  case 'travel':case 'museum':case 'info':case 'name':case 'aero': case 'asia': case 'coop':case 'jobs':case 'mobi':break;
                  default:  return false; };				 
        }; 
    };
	return true;
};
//-----
function bb_wOpen(url, name, w, h){
	w += 32;
	h += 96;
 	var win=window.open(url, name,'width='+ w +', height=' + h + ', '+'location=0, menubar=0, ' + 'status=0, toolbar=0, scrollbars=1 width=' + w + ' hight=' + h );
}
//-----
function bb_fblogin(signID) {
    FB.login(function(response) {
       if (response.authResponse) {
          //if (response.perms == 'email') {
             FB.api('/me', function(user) {
                     	
					  NID = GetQueryStringValue("nid");
					  PID = GetQueryStringValue("pid");
					  email = user.email;
					  extUID = user.id;
					  appID = '2412324777';
					  srcID = 1;
					  if (signID == 1){ // Sign In 
						remember = (document.getElementById("bb_LogRemMe").checked ? 1 : 0)
						Optin1 = 1;		
						Optin2 = 1;
					  }
					  else {// Sign Up
						remember = 0;
						Optin1 = (document.getElementById("bb_regOpt1").checked ? 1 : 0);		
						Optin2 = (document.getElementById("bb_regOpt2").checked ? 1 : 0);
					  }
					  RegisterFacebookUserWithOptIn(NID, PID, email, extUID, appID, srcID, remember, Optin1, Optin2, 0, 0);
					  
					  setTimeout("bb_isUserLogin_ajax()",900);
					
						});
          //} else { //alert("user is logged in but didn't grant any perms");
		  //       }
       } else {
                  //alert("user is not logged in");
					if (signID == 1) document.getElementById("bb_errLogMsg").innerHTML = "Facebook login failed";
					if (signID != 1) document.getElementById("bb_errRegMsg").innerHTML = "Facebook sign up failed";
         };
    }, {scope:'email' }); 
};
//------------
function bb_SendPsw(){
	 var PID = GetQueryStringValue ('pid');
	 var email = document.getElementById("bb_fogotemail").value
		if (!bb_isEmailValid(email))
			document.getElementById("bb_errFogPaswMsg").innerHTML = "Invalid email address"
		else {
			SendForgotPassword(email, PID);
			openHeaderLoginWin();
			if (document.getElementById("bb_errLogMsg"))
				document.getElementById("bb_errLogMsg").innerHTML = "Your password reminder was sent to your mailbox " + email
			//setTimeout("CloseFlyoutWin()",4000); 
		}
};
//------------
function bb_signoff(){
	if (typeof(ci_regObj) !="undefined" && ci_regObj != null){
		if( ci_regObj.extUID !="undefined" && ci_regObj.extUID != null && ci_regObj.extUID != "" &&  ci_regObj.extUID != 0){
				if (typeof(SupportFBConnect) != "undefined"  && SupportFBConnect != null && SupportFBConnect == 1)
					FB.logout(function(response) {});				
		}
	};	
	//FB.logout(function(response) {});
	window.location.href ="login.aspx?" + GetQueryString()
}
//------------
function isWhitespace (str)
{   
   // Is s empty?
   var reWhitespace = /^\s+$/
   return ((str == null) || (str.length == 0) || reWhitespace.test(str));
}



//CouponCaddy

function DisplayCouponCaddy(){					
	//if (typeof(IsCouponClubEnabled) !="undefined" && IsCouponClubEnabled != null){
	//	if (IsCouponClubEnabled == 1){	
	if (typeof(CouponFinderBox) != "undefined" && CouponFinderBox){
			if (document.getElementById("CouponCaddyBox") != null && document.getElementById("CouponCaddyBox") !="undefined") {
				
				var bb_savingsClubMember = bb_isSavingsClubMember();				
				var txtMsg = "Unlock this Savings Club feature and let the Coupon Finder help you discover the best printable coupons on the web.", txtMsgClass = "couponcaddyBox", txtMsgboxClass=" short160";
				if (bb_savingsClubMember == 1)	{txtMsg = "Let the Coupon Finder help you discover the best printable coupons on the web!"; txtMsgClass = "couponcaddyBox short95"; txtMsgboxClass = ""}
							
				document.getElementById("CouponCaddyBox").innerHTML = '<h4 class="sbH4" id="sbH4-CouponCaddy"'
				+' onclick="var e = arguments[0] || window.event; OpenCouponCaddyFlyOut(e.clientY); return false;"'
				+'>COUPON FINDER</h4>'
				+'<div  class="' + txtMsgClass + '" onclick="var e = arguments[0] || window.event; OpenCouponCaddyFlyOut(e.clientY); return false;">'
				+'   <div class="couponCaddyWrap'+ txtMsgboxClass +'">'
				+'   		<img src="http://download2.coupons.com/7/19/7125/1450/print.coupons.com/CouponWeb/Themes/CM_BigBlue/_images/SavingsClub_Logo_65.png">'              
				+	txtMsg             
				+'   </div>' 
				+'</div>';
				document.getElementById("CouponCaddyBox").style.display = 'block';
			};
		 };
	};	
//};


function OpenCouponCaddyFlyOut(yPos){

    var TAFDiv = document.getElementById('FlyOutDiv');    



	var FlyoutHTML = '<div class="couponcaddyFlyout">'
	if (yPos < 490) FlyoutHTML = '<div class="couponcaddyFlyout topArr">'
			FlyoutHTML +=' 	<p class="closeX"><a href="javascript:CloseFlyoutWin()" class="close">Close</a></p>'			
			+' <div class="flyiFrame">'
			+'   <iframe id="ciContentFramecode" src="http://couponfinder.coupons.com/couponfinder.asp" frameborder="0" width="590px" height="545px" scrolling="auto"></iframe>'
		    + '</div>'
		    + '</div>';

   var scrollYPos = ( window.pageYOffset || document.documentElement.scrollTop );
   TAFDiv.style.left = '200px';
   var bottomPos = document.documentElement.clientHeight;
	    
	if (yPos < 490){//arr top	
	   var yPosDiff = 220;		
	   TAFDiv.style.top  = (yPos - yPosDiff +scrollYPos) + 'px';		
	   if( yPos+510 > bottomPos ) window.scrollTo(0,scrollYPos+(yPos+510 -bottomPos)); 		
	   if( yPos < 105 ) window.scrollTo(0,scrollYPos - (110 - yPos));      		
	}
	else { //arr bottom
	   var yPosDiff = 570;		
	   TAFDiv.style.top  = (yPos - yPosDiff +scrollYPos) + 'px';		
	   if( yPos+125 > bottomPos )  window.scrollTo(0,scrollYPos+ 130 ); 
	};
   		
   TAFDiv.innerHTML = FlyoutHTML;
};

// is Savings Club
function bb_isSavingsClubMember(){
	var isSavingsClubMember = 0;
	if (typeof(IsCouponClubEnabled) !="undefined" && IsCouponClubEnabled != null){
		if (IsCouponClubEnabled == 1){
			if (typeof(ci_CCM) !="undefined" && ci_CCM != null){
					if (ci_CCM.Status != 0)	isSavingsClubMember = 1; // savings club member
			};
		};
	};
	return isSavingsClubMember;
};

// end --CouponCaddy
//AdTech
function AdTechGetKeyValue(name){
   var value = "", location = window.location.toString();	    
   if( location.indexOf(name+"=") > -1 )   {  value = location.substring(location.indexOf(name+"=")+name.length+1);  }
   return ( value.indexOf("&") > -1 ? decodeURI(value.substring(0,value.indexOf("&"))) : decodeURI(value));
};
function AdTechGetKeys(){
	var keyPid = AdTechGetKeyValue('pid'), keyZid = AdTechGetKeyValue('zid'), keyNid = AdTechGetKeyValue('nid');
	var keyValues = "sub1="+ keyPid +";sub2="+ keyZid +";sub3="+ keyNid +";sub4=" + keyPid + keyZid + keyNid + ";key=" + keyPid + keyZid + keyNid + ";";
	return keyValues;
};

