﻿function setCookie(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 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 "";
}


function showOptin(type, location, pageviews, delay) {		
	timeDelay = delay * 1000;

	// retrieve cookies ( if they exist )
	var optinCookie = getCookie("optin");
	var pageViewCookie = getCookie("pageviews");
	
	if ( optinCookie == "yes" ) {
	// if optinCookie is set to yes, the user already saw the popup,
	// so we'll just increment the page views
		pageViewCookie++;
		setCookie("pageviews", pageViewCookie, 365);
	} else if ( ( pageViewCookie <= 0 || pageViewCookie >= pageviews ) && type == "pageviews" ) {
	// if there are no page views or more than 5 page views, we don't want to show the popup yet...
	// BUT we do want to increment this value and reset the value of the pageView cookie
		pageViewCookie++;
		setCookie("pageviews", pageViewCookie, 365);
	} else {
	// we haven't run into any road blocks yet, so we should show the popup now
		pageViewCookie++;
		setCookie("pageviews", pageViewCookie, 365);
		
		if ( ( getCookie("pageviews") && type == "pageviews" && pageViewCookie == pageviews ) || ( getCookie("pageviews") && type == "delay" ) ) {
		// if our cookie doesn't exist, the user must be blocking cookies so we're not going to show any popups
			setTimeout("tb_show('Get our FREE Naming Guide','" + location + "?KeepThis=true&TB_iframe=true&height=700&width=850&modal=true',null);",timeDelay);
			setTimeout("setCookie('optin', 'yes', 365)", timeDelay);				
		} else {
			//alert("cookies are disabled");
		}
	}

}		

function POP(url) {
			
	setCookie('optin', 'yes', 365);
}

