var esvr = 'http://comm.newspress.com/npcommerce/';
var WM_acceptsCookies = false;

if(document.cookie == '') {
    document.cookie = 'WM_acceptsCookies=yes'; // Try to set a cookie.
    if(document.cookie.indexOf('WM_acceptsCookies=yes') != -1) {
	WM_acceptsCookies = true; 
    }// If it succeeds, set variable
} else { // there was already a cookie
  WM_acceptsCookies = true;
}

function WM_readCookie(name) {
    if(document.cookie == '') { // there's no cookie, so go no further
	return false; 
    } else { // there is a cookie
	var firstChar, lastChar;
	var theBigCookie = document.cookie;
	firstChar = theBigCookie.indexOf(name);	// find the start of 'name'
	var NN2Hack = firstChar + name.length;
	if((firstChar != -1) && (theBigCookie.charAt(NN2Hack) == '=')) { // if you found the cookie
	    firstChar += name.length + 1; // skip 'name' and '='
	    lastChar = theBigCookie.indexOf(';', firstChar); // Find the end of the value string (i.e. the next ';').
	    if(lastChar == -1) lastChar = theBigCookie.length;
	    return unescape(theBigCookie.substring(firstChar, lastChar));
	} else { // If there was no cookie of that name, return false.
	    return false;
	}
    }	
} // WM_readCookie

function myunescape (str)
{
	str = '' + str;
	while (true)
	{
		var i = str . indexOf ('+');
		if (i < 0)
			break;
		str = str . substring (0, i) + ' ' + str . substring (i + 1, str . length);
	}
	return unescape (str);
}


function args_init ()
{
	args = new Array ();
	var argstring = window . location . search;
	if (argstring . charAt (0) != '?')
		return;
	argstring = argstring . substring (1, argstring . length);
	argarray = argstring . split ('&');
	var i;
	var singlearg;
	for (i = 0; i < argarray . length; ++ i)
	{
		//document.write(' loop '+ i);
                singlearg = argarray [i] . split ('=');
		if (singlearg . length != 2)
			continue;
		var key = myunescape (singlearg [0]);
		var value = myunescape (singlearg [1]);
		//document.write(' key '+ key + ' value ' + value);
		args [key] = value;
	}
}

function user_check_subscriber()
{
	emp = WM_readCookie('NPEmployee');
	if ((emp == 'true')  || (emp == '1')) return;
	psub = WM_readCookie('NPPrintSubscriber');
	if ((psub == 'true')  || (psub == '1')) return;
	esub = WM_readCookie('NPElectronicSubscriber');
	if ((esub == 'true')  || (esub == '1')) return;
	args_init();
	if (typeof args["tref"] != 'undefined') return;

	reg = WM_readCookie('NPRegistered');	
	if ((reg == 'true')  || (reg == '1'))
		location.replace(esvr+'subscribeForm.htf?hst='+location.host+'&fwd='+location.pathname);
          else
		location.replace(esvr+'registerForm.htf?hst='+location.host+'&fwd='+location.pathname);
}

function addDays(myDate,days) {
    return new Date(myDate.getTime() + days*24*60*60*1000);
}

function good_domain() {
    if (location.host == 'www.sbcoast.com')
       {
	location.replace('http://www.newspress.com'+location.pathname);
        return false;
        }
    else
       return true; 

}

function update_check()
{
   var ecRandom = Math.round(10000*Math.random()) + 1;
   var npup = WM_readCookie('NPUpdate');
   var skip = (new Date() < new Date(npup));
   if (skip) return true;
   args_init();
   if (typeof args["nref"] != 'undefined') return true;
   if (typeof args["tref"] != 'undefined') return true;
   location.replace(esvr+'updateUser.htf?hst='+location.host+'&fwd='+location.pathname+'&cook='+WM_acceptsCookies+'&from=srchcksub&v=9'+'&cookie='+document.cookie+'&u='+npup+'&r='+ecRandom);
   return false;
}

if (good_domain() && update_check())
  user_check_subscriber();



document.write('<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#666666" VLINK="#666666" ALINK="#000099" MARGINWIDTH="5" MARGINHEIGHT="0">');
document.write('<center><img src="/masthead_450W.gif" alt="SB News-Press"></center><hr>');


