	var currtime = new Date();
	//var blockNewCpnForDays = new Date(currtime.getTime() + 604800000);
	//var couponExpirationDays = new Date(currtime.getTime() + 172800000);
	
	var blockNewCpnForDays;
	blockNewCpnForDays = 7;
	
	var couponExpirationDays;
	couponExpirationDays = 7;
	
	if(!Get_Cookie( 'moxreferafriend' )){
	
		if(!Get_Cookie( 'firstvisitpromo' ))
		{
			var sourcestring = document.location.href;
			var referstring = document.referrer;
			var couCode;
			var couDiscount;
			
	
			
		  if(Get_Cookie('newusercpn'))
		  {
		  		if(!Get_Cookie( 'firstvisitpromo' )) 
				{
	
					Set_Cookie( 'firstvisitpromo', 'true', blockNewCpnForDays);
					couCode = "true";
				}
		    Set_Cookie( 'addcpntobasket', Get_Cookie('newusercpn'), 3650);
	  		couCode = Get_Cookie('newusercpn');
			  couDiscount = "$10"; 
						document.write( "<div id='couponpopupBorder' style='display: block;'><\/div>"
								+ "<div id='couponpopBlackBorder' style='display: block;'><\/div>"
								+ "<div id='couponPopup' style='display: block;'>"
								+ "<div style='float:left; width: 76px; height:100px;text-align:center;margin-top:20px;'>"
								+ "<img src='/images/couponpopuplogo.png'/>"
								+ "<\/div>"
								+ "<div style='float:right; width:258px; height:230px;'>"
								+ "<p style='height:25px; font-weight:bold;margin-left:0px;margin-top: 0px;text-align:left;font-size:14px;'>Thanks for joining!<\/p>"
								+ "<p style='font-size:13px;'>The coupon code: <b>"
								+ couCode
								+ "<\/b>&nbsp;will automatically be added to your cart for "
								+ couDiscount
								+ " off any items you buy today.<\/p>"
								+ "<p style='margin-top: 8px;'>Enjoy shopping our indie designers and products!*<\/p>"
								+ "<p style='font-size:50px;height:50px; margin-top:3px;'>"
								+ couDiscount
								+ " off<\p>"
								+ "<p style='font-size:25px;'>From Moxsie to you!<\/p>"
								+ "<p style='font-size:13px;'>Sincerely, The Moxsie Team<\/p>"
								+ "<\/div>"
								+ "<div style='float:left;width: 344px; margin-top: 0px;'>"
								+ "<p style='font-size:10px;text-align:center'>*May not be combined with other promotions or other special offers.<\/p>"
								+ "<p style='text-align:center;padding-top:7px;'><img style='cursor: pointer;' src='/images/couponpopupclose.jpg' onclick='javascript:closecouponPopup();'/><\/p><\/div>"
								+ "<\/div>"
								+ "<div id='couponpopUpBg'><\/div>");
				couponWindow();
		}
		else
		{
			if(referstring.match('google.com') ||
			   sourcestring.match('utm_source=google') ||
			   sourcestring.match('utm_source=shopping.com') || 
			   referstring.match('polyvore.com' ) || 
			   referstring.match('bing.com') || 
			   sourcestring.match('utm_source=perez') || 
			   sourcestring.match('utm_source=dailycandy') ||
			   sourcestring.match('utm_source=yahoo-') ||
			   sourcestring.match('utm_source=shopzilla.com_feed') ||
			   sourcestring.match('utm_source=askmen-') ||
			   sourcestring.match('utm_source=NYMag_FashionAlert') ||
			   sourcestring.match('utm_source=designsponge') ||
			   sourcestring.match('utm_source=refinery29'))
			{

				if(!Get_Cookie( 'firstvisitpromo' )) 
				{
	
					Set_Cookie( 'firstvisitpromo', 'true', blockNewCpnForDays);
					couCode = "true";
				}
	
				if(referstring.match('google.com') || sourcestring.match('utm_source=google'))
				{
					couCode = "MOXSIEGUESTG305";				
					couDiscount = "15%"; 
				}			
				else if(sourcestring.match('utm_source=shopping.com'))
				{
					couCode = "MOXSIEGUESTS317";
					couDiscount = "15%"; 
				}
				else if(referstring.match('polyvore.com'))
				{
					couCode = "POLYMOX";
					couDiscount = "15%"; 
				}
	
				else if(referstring.match('bing.com'))
				{
					couCode = "BING924";
					couDiscount = "15%"; 
				}
	
				else if(sourcestring.match('utm_source=perez'))
				{
					couCode = 'PEREZ';
					couDiscount = "15%"; 
				}
				else if(sourcestring.match('utm_source=dailycandy'))
				{
					couCode = "DAILYCANDY";
					couDiscount = "20%"; 
				}
				else if(sourcestring.match('utm_source=yahoo-'))
				{
					couCode = 'TRENDSETTER';
					couDiscount = "20%"; 
				}
				else if(sourcestring.match('utm_source=shopzilla.com_feed'))
				{
					couCode = 'SHOPZGUEST';
					couDiscount = "15%"; 
				}
				else if(sourcestring.match('utm_source=askmen-'))
				{
					couCode = 'VDAY15';
					couDiscount = "15%"; 
				}
				else if(sourcestring.match('utm_source=NYMag_FashionAlert'))
				{
					couCode = 'NYMAG15';
					couDiscount = "15%"; 
				}
				else if(sourcestring.match('utm_source=designsponge'))
				{
					couCode = 'DESIGN15';
					couDiscount = "15%"; 
				}
				else if(sourcestring.match('utm_source=refinery29'))
				{
					couCode = 'REF15';
					couDiscount = "15%"; 
				}
				else {}
				Set_Cookie( 'addcpntobasket', couCode, couponExpirationDays);
				document.write( "<div id='couponpopupBorder' style='display: block;'><\/div>"
								+ "<div id='couponpopBlackBorder' style='display: block;'><\/div>"
								+ "<div id='couponPopup' style='display: block;'>"
								+ "<div style='float:left; width: 76px; height:100px;text-align:center;margin-top:20px;'>"
								+ "<img src='/images/couponpopuplogo.png'/>"
								+ "<\/div>"
								+ "<div style='float:right; width:258px; height:230px;'>"
								+ "<p style='height:25px; font-weight:bold;margin-left:0px;margin-top: 0px;text-align:left;font-size:14px;'>Welcome Indie Shoppers!<\/p>"
								+ "<p style='font-size:13px;'>The coupon code: <b>"
								+ couCode
								+ "<\/b>&nbsp;will automatically be added to your cart for "
								+ couDiscount
								+ " off any items you buy today.<\/p>"
								+ "<p style='margin-top: 8px;'><b>This is for a limited time<\/b>. Enjoy shopping our indie designers and products right now!*<\/p>"
								+ "<p style='font-size:50px;height:50px; margin-top:3px;'>"
								+ couDiscount
								+ " off<\p>"
								+ "<p style='font-size:25px;'>From Moxsie to you!<\/p>"
								+ "<p style='font-size:13px;'>Sincerely, The Moxsie Team<\/p>"
								+ "<\/div>"
								+ "<div style='float:left;width: 344px; margin-top: 0px;'>"
								+ "<p style='font-size:10px;text-align:center'>*May not be combined with other promotions or other special offers.<\/p>"
								+ "<p style='text-align:center;padding-top:7px;'><img style='cursor: pointer;' src='/images/couponpopupclose.jpg' onclick='javascript:closecouponPopup();'/><\/p><\/div>"
								+ "<\/div>"
								+ "<div id='couponpopUpBg'><\/div>");
				couponWindow();
			}//if
			} // else newusercpn

		}

}


	function Set_Cookie(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 Get_Cookie(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 eraseCookie(name) 
	{
		Set_Cookie(name,"",-1);
	}

function couponWindow()
{
	var clientHeight;
	var popTopPosition;
	
	/*clientHeight = window.innerHeight;*/
	clientHeight = document.documentElement.clientHeight;
	
	popTopPosition = (clientHeight - 320)/ 2;
	document.getElementById("couponpopupBorder").style.top = popTopPosition + "px";
	document.getElementById("couponpopBlackBorder").style.top = popTopPosition + 10 + "px";
	document.getElementById("couponPopup").style.top = popTopPosition + 18 + "px";
	document.getElementById("couponpopUpBg").style.height = clientHeight + "px";

}

function closecouponPopup()
{
	//new Ajax.Request('/close_cpn_popup.html', {
	var cpncode = Get_Cookie('addcpntobasket');
	new Ajax.Request('/checkout/cart/couponPost/?coupon_code=' + cpncode, {
	 	method: 'post'
	  });
		document.getElementById("couponPopup").style.display = "none";
		document.getElementById("couponpopBlackBorder").style.display = "none";
		document.getElementById("couponpopupBorder").style.display = "none";	
		document.getElementById("couponpopUpBg").style.display = "none";	
	}