//code for affiliate program captures referring url and sets cookie
    function getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
	endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
      }
    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 null;
	}
		
	//document.write("nwbyUref="+document.referrer);
	//alert("cookie="+document.cookie);
       //alert("="+document.referrer);
	nwbyUref=document.referrer;
	//backupUref=document.referrer;
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+7);
	document.cookie="cKbyRef="+escape(document.referrer)+"; expires="+exdate.toUTCString();
	var match = /northwestregisteredagent.com/.test(nwbyUref)
	//if (GetCookie("cKbyRef") != GetCookie("nwbyUref")) document.write("=");
	if (match == true){
		 //document.write(match);
	}else{
		    //document.write("false");
	   if ((GetCookie("nwbyUref") == null) || (GetCookie("cKbyRef") != GetCookie("nwbyUref"))) {   //set cookie if it is empty or new cookie if coming from new domain
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+7);
		document.cookie="nwbyUref="+escape(document.referrer)+"; expires="+exdate.toUTCString();
		document.cookie="cKbyRef="+escape(document.referrer)+"; expires="+exdate.toUTCString();
		//document.cookie="backupUref="+encodeURI(document.referrer)+"; expires="+exdate.toUTCString();  //2nd cookie set
                //document.write("<");
                //document.write(document.cookie);
		//document.write("<br>set: "+unescape(document.cookie));
		// document.write("<br>exp="+exdate.toUTCString());
	     }
	  }
	if (GetCookie("nwbyUref")){
		 //document.write("<br>"+GetCookie("nwbyUref"));
	}
	if (GetCookie("cKbyRef")){
		 //document.write("<br>"+GetCookie("cKbyRef"));
	}
////End affiliate code
		

