
// ---------------------
function checkCookie(url, PID, entrypoint) {
        var form_handle = document.keywordform;
		var Newurl;
		
		if(GetCookie("NMRME") != "") {
		   location.href = url;
           return true;
        } else {
			Newurl = 'https://secure.nwsource.com/reg/scr/signin.cfm?target=' + escape('http://' + location.hostname + url);
			location.href = Newurl;
			}
		
		/* This is for old registration using a popup Keep it here just in case
		   someone changes there mind and wants popups
        if(GetCookie("DID") != "" && GetCookie("MT") != "" && GetCookie("MT") != false ) {
		   location.href = url;
           return true;
           }

		if (location.search.indexOf("PID") == -1 ) {
			Newurl = 'http://seattletimes.nwsource.com/register/Register.pl?template=popup&referrer=' + escape('http://' + location.hostname + 
		  		 	 '/alert-mgr/?PID=' + PID + '&AgentName=');
			if (location.search.substring(1) != '') {
				Newurl = Newurl + escape('&' + location.search.substring(1));
				}

		} else {
			Newurl = 'http://seattletimes.nwsource.com/register/Register.pl?template=popup&referrer=' + escape('http://' + location.hostname + 
		  		 	 '/alert-mgr/?AgentName=');		
			if (location.search.substring(1) != '') {
				Newurl = Newurl + escape('&' + location.search.substring(1));
				}
			}
					 
		if (entrypoint == "create") {
				// old method of using popup
				// window.open(Newurl + escape('#Create'),'', 'status=0,menubar=0,scrollbars=0,resizable=1,location=0,directories=0, height=350, width=315');
				location.href = Newurl + escape('#Create');
		} else {
				// old method using popup
				// window.open(Newurl,'', 'status=0,menubar=0,scrollbars=0,resizable=1,location=0,directories=0, height=350, width=315');
				location.href = Newurl;
			}
		*/
        return false;
        }

		
		
// ---------------------
function GetCookie (name) { 
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
    i = document.cookie.indexOf(" ", i) +1;
    if (i == 0) break;
   } return false;
}

// ---------------------
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset,endstr));
}	


// ---------------------
function Logout() {
	var exp 		= new Date(); 
	
	setCookie(DID, "", exp.getTime() );
	setCookie(MT, "", exp.getTime() );
	location.href('http://' + location.hostname + '/autos/');
	}

	
// ---------------------
function setCookie(name, value, expire){
  	document.cookie = name + "=" + escape(value) + "; expires=" + expire;
}



