<!--
// ------------------------------------------------
//  	begin:  Boilerplate Cookie Functions
// ------------------------------------------------
var expdate = new Date ();
expdate.setTime (expdate.getTime() + (14 * 24 * 60 * 60 * 1000)); // 14 days from now

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;
}

function SetCookie (name, value) {
  var argv = SetCookie.arguments;
  var argc = SetCookie.arguments.length;
  var expires = (argc > 2) ? argv[2] : null;
  var path = (argc > 3) ? argv[3] : null;
  var domain = (argc > 4) ? argv[4] : null;
  var secure = (argc > 5) ? argv[5] : false;
  
  document.cookie = name + "=" + escape (value) +
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

function DeleteCookie (name) {
  var domain = "; domain=.nlpls.com";
  var path = "; path=/";
  var exp = new Date();
  exp.setTime (exp.getTime() - 1);  // This cookie is history
  var cval = GetCookie (name);
  if (cval != null)
    document.cookie = name + "=" + cval + domain + path + "; expires=" + exp.toGMTString();
}

// OUTDATED. For new coding, use "newGetCookieParam()".
// Some old functions may still depend on this version, so keep it
// for a while. -------------------------------------- 6/15/04, JH
// Get values for &name=value pairs. Pass func params as strings.
function getCookieParam(name, param) {
	var index    		= 0;
	var sep      		= "&";
	var chip     		= "";
	var chipVal  		= null;
	var start    		= 0;
	without_sep  		= 0;
	var next_sep 		= 0;
	var theCookieVal	= null;
	
	// theCookieVal == &q1=0&q2=0&q3=0...
	theCookieVal = GetCookie(name);
	
	if ( theCookieVal != null ) {
		chip = param;
		index = theCookieVal.indexOf(chip);
		start = index + 1;
		without_sep = theCookieVal.substring(start, theCookieVal.length);
		next_sep = without_sep.indexOf("&");
		
		// handle last one
		if ( next_sep == -1 ) {
			chipVal = without_sep;
		} else {
			chipVal = without_sep.substring(0, next_sep);
		}				
		index = chipVal.indexOf("=");
		start = index + 1;
		chipVal = chipVal.substring(start, chipVal.length);
	}
	return chipVal;
}

// ---------------------------------------------------------------------------------------
// Get values for &name=value pairs. Pass func params as strings.
// Called as: newGetCookieParam("myCookie", "uid") // do not pass "&" in paramName string
// ---------------------------------------------------------------------------------------
function newGetCookieParam(cookieName, paramName) {
	var index    		= 0;
	var sep      		= "&";
	var paramValue  	= null;
	var start    		= 0;
	var without_sep  	= 0;
	var next_sep 		= 0;
	var eqIndex		= 0;
	var theCookieVal	= null;
	var theParamName	= "";
	var theParamCheck	= 0;
	
	// We don't pass this function the '&' in the paramName so html-ing is easy.
	// But we put it back in here so we don't find duplicate terms in param substrings.
	// Therefore, all found params must begin with '&'.
	theParamName = "&" + paramName;
	
	// theCookieVal == &q1=0&q2=0&q3=0...
	theCookieVal = GetCookie(cookieName);
	
	if ( theCookieVal != null ) {
	
		index = theCookieVal.indexOf(theParamName);
		if ( index == -1 ) return null;
		
		// alert("index: " + index );
		
		start = index + 1;
		without_sep = theCookieVal.substring(start, theCookieVal.length);
		
		// Check to make sure we're not dealing with a substring of the paramName.
		eqIndex = without_sep.indexOf("=");	
		if ( eqIndex + 1 != theParamName.length ) {
			return null;
		}
		
		next_sep = without_sep.indexOf("&");
		
		// handle last one
		if ( next_sep == -1 ) {
			paramValue = without_sep;
		} else {
			paramValue = without_sep.substring(0, next_sep);
		}				
		index = paramValue.indexOf("=");
		start = index + 1;
		paramValue = paramValue.substring(start, paramValue.length);
	}
	return paramValue;
}


// -------------------------------------------------------------------
// Change a cookie param value, or add a new param.
// If the param is there, replace it.  If it's not there, add it. 
// -------------------------------------------------------------------
function changeAddCookieParam(cookieName, paramName, paramValue, expdate, path, domain  ) {

	if ( !cookieName || !paramName || !paramValue || !expdate ) return null;

	var index    		= 0;
	var sep      		= "&";
	var start    		= 0;
	var without_sep  	= 0;
	var next_sep 		= 0;
	var prefix			= ""
	var suffix			= ""
	var theCookieVal	= "";
	var theNewCookieVal	= "";
	var theParamName	= "";
	
	// We don't pass this function the '&' in the paramName so html-ing is easy.
	// But we put it back in here so we don't find duplicate terms in param substrings.
	// Therefore, all found params must begin with '&'.
	
	theParamName = "&" + paramName;
	theCookieVal	= GetCookie(cookieName);
	paramThere		= newGetCookieParam(cookieName, paramName);

	// &name=value pairs
	if ( paramThere != null ) {
	
		index = theCookieVal.indexOf(theParamName);
		
		// Save everything up to the param.
		prefix = theCookieVal.substring(0, index); // 
		
		// Get string from beginning of theParamName to end of cookie string
		without_sep = theCookieVal.substring(index+1, theCookieVal.length);
				
		// Within that, where does the next param begin?
		next_sep = without_sep.indexOf("&");
		
		// Is the param we're replacing the last one in the cookie string?
		if ( next_sep == -1 ) {
			// If so, do nothing. We've already got the prefix without the param in it.
		} else {
			// Get everything from the next param to end of cookie.
			suffix = without_sep.substring(next_sep, without_sep.length);
		}
		// Put it back together with the new paramValue
		theNewCookieVal = prefix + theParamName + "=" + paramValue + suffix;

	} else {    // If the param wasn't there, add it 
		if ( theCookieVal != null ) {
			theNewCookieVal = theCookieVal + theParamName + "=" + paramValue;
		} else {
			// If the cookie wasn't there, we're setting a new one, so
			// don't include the null value of theCookieVal or it will
			// show up as "null" in the first cookie value before params.
			theNewCookieVal = theParamName + "=" + paramValue;
		}
	}		  
	SetCookie (cookieName, theNewCookieVal, expdate, path, domain);
	return this;
}

function doDeleteCookieParam (cookieName, paramName, paramValue) {

	var domain = "; domain=.nlpls.com";
	var path = "; path=/";
	// var domain	= null;
	// var path 	= null;
	var expdate = new Date();		
	expdate.setTime( expdate.getTime() + (365 * 24 * 60 * 60 * 1000) ); // 365 days from now
	
	deleteCookieParam(cookieName, paramName, expdate, path, domain );
	
}

// -------------------------------------------------------------------
// Delete a param from a cookie and reset the cookie. This does NOT
// delete the whole cookie. 
// -------------------------------------------------------------------
function deleteCookieParam(cookieName, paramName, expdate, path, domain  ) {

	if ( !cookieName || !paramName || !expdate ) return null;

	var index    		= 0;
	var sep      		= "&";
	var start    		= 0;
	var without_sep  	= 0;
	var next_sep 		= 0;
	var prefix			= ""
	var suffix			= ""
	var theCookieVal	= "";
	var theNewCookieVal	= "";
	var theParamName	= "";
	
	// We don't pass this function the '&' in the paramName so html-ing is easy.
	// But we put it back in here so we don't find duplicate terms in param substrings.
	// Therefore, all found params must begin with '&'.
	
	theParamName = "&" + paramName;
	// alert("theParamName: " + theParamName  + "\n\n" + theCookieVal);

	theCookieVal	= GetCookie(cookieName);
	paramThere		= newGetCookieParam(cookieName, paramName);

	// &name=value pairs
	if ( paramThere != null ) {
	
		index = theCookieVal.indexOf(theParamName);
		
		// Save everything up to the param.
		prefix = theCookieVal.substring(0, index); // 
		
		// Get string from beginning of theParamName to end of cookie string
		without_sep = theCookieVal.substring(index+1, theCookieVal.length);
				
		// Within that, where does the next param begin?
		next_sep = without_sep.indexOf("&");
		
		// Is the param we're replacing the last one in the cookie string?
		if ( next_sep == -1 ) {
			// If so, do nothing. We've already got the prefix without the param in it.
		} else {
			// Get everything from the next param to end of cookie.
			suffix = without_sep.substring(next_sep, without_sep.length);
		}
		// Put it back together with the new paramValue
		// theNewCookieVal = prefix + theParamName + "=" + paramValue + suffix;
		theNewCookieVal = prefix + suffix;

	} else {    // if the param wasn't there
		// So there's nothing to do.
		return this;
	}		  
	SetCookie (cookieName, theNewCookieVal, expdate, path, domain);
	return this;
}


// ------------------------------------------------
//  	end:  Boilerplate Cookie Functions
// ------------------------------------------------

// ------------------------------------------------
//  	BEGIN:  Ancillary Cookie Functions
// ------------------------------------------------

	
	// We set a UID cookie for several reasons:
	// 	-- Anonymity: Visitors can fill in personal forms without giving their names.
	//	-- Referrer: How people found us -- most people can't remember, by the time we talk.
	//	-- Date first accessed: this is for us so we know the lag time between site
	//			updates and response.  Sometimes it's a long time between a first visit
	//			and a phone call.  Sometimes not.  Hopefully this is worth knowing.
	function always() {
		// if ( DomainCheck() ) { // No longer used. Domains are now separate.
		SetUIDcookie();
		gifmgr();
		// fixURL();
	}
	
	function fixURL() {
		// The only time we get a url with a query string is when we've been
		// redirected from www.nlpLearningSolutions.com with a referrer in tow.
		// Once the gifmgr() has handled that, here we get rid of the ugliness
		// of a typical google or other search engine referror/query string 
		// tacked on to the URL.
		var theURL = unescape(document.location);
		var theQueryStart = theURL.indexOf('?');
		var theCleanURL;
		
		if (theQueryStart > 0) { 
			theCleanURL = theURL.substring(0, theQueryStart);
			document.location.replace(theCleanURL);
		}
	}
	
	// www.nlplearningsolutions.com auto-forwards to the new www.nlpls.com,
	// maintaining the other parts of the URL.
	function DomainCheck() {
           var theURL = unescape(document.location);
		   var theReferrer = null;
           var newURL = null;
           var pattern = /\bnlplearningsolutions\b/ig; // used in theURL.replace
           var inThere = theURL.match(/nlplearningsolutions/g);
           var wwwThere = theURL.match(/www/g);
		   
		   theReferrer = unescape(document.referrer);

           if (inThere) {
                newURL = theURL.replace(pattern,"nlpls");
				escape(newURL);
				if ( theReferrer != null )
					document.location = newURL + "?" + theReferrer; // preserve referrer
				else
					document.location = newURL; // no referrer					
								
				return false;
		   } else {
		   		return true;
		   }
	}
	
	
	function SetUIDcookie() {
	
		var gotUID = null;
		var theCookieVal = null;
		var expdate = null;
		
		gotUID = GetCookie("NLS_UID");

		if ( gotUID == null ) {
			theCookieVal = ConstructUIDcookie();
			expdate = new Date();		
			expdate.setTime( expdate.getTime() + (365 * 24 * 60 * 60 * 1000) ); // 365 days from now
			SetCookie("NLS_UID", theCookieVal, expdate, "/", ".nlpls.com");
		} else {
			// If it's already there, reset it.  6/28/06.  Was empty, did nothing.
			theCookieVal = gotUID;
			expdate = new Date();		
			expdate.setTime( expdate.getTime() + (365 * 24 * 60 * 60 * 1000) ); // 365 days from now
			SetCookie("NLS_UID", theCookieVal, expdate, "/", ".nlpls.com");
		}
	}
	
	// For testing
	function ShowUIDcookie() {

		var gotUID = null;	
		gotUID = GetCookie("NLS_UID");

		if ( gotUID == null ) {
			alert("NLS_UID cookie not present" );
		} else {
			alert("NLS_UID cookie present: \n\n\t" + gotUID + "\n\n" +
				  "Full cookie: " + unescape(document.cookie) 
			);
			
		}
	}
	
	// Construct the value of a UID cookie.
	function ConstructUIDcookie() {
		var theUID = 0;
		var theDate = new Date();
		var theReferrer = "";
		var theCookieStr = "";
		var theADcampaignIndex = "";
		var theScreenDimensions = screen.width + "x" + screen.height; 
		
		theUID = makeRandomUID();  		// the UID is a random number
		theReferrer = getReferrer();	// the referrer is the site that linked to this page
		
		theCookieStr = "&uid=" + theUID + "&fa=" + theDate + "&scr=" + theScreenDimensions;
		if (theReferrer != "") {
			theCookieStr = theCookieStr + "&ref=" + theReferrer;
		}

		theADcampaignIndex = getQuerystring('aci'); // Eval ad campain(s) effectiveness
		if (theADcampaignIndex != "") {
			theCookieStr = theCookieStr + "&aci=" + theADcampaignIndex;
		}
		
		return theCookieStr;
	}

	
	// Create a random UID number
	function makeRandomUID() {
		var ia 		= 9301;
		var ic		= 49297;
		var im		= 233280;
		var number 	= 1000000;
				
		today = new Date();
		jran = today.getTime();
		jran = ( jran * ia + ic ) % im;
		
		uid = Math.ceil( ( jran / ( im * 1.0 ) ) * number);
		return uid;
	}
	
	// Get the referring page
	function getReferrer () {
		return document.referrer;
	}


// Get individual QUERY STRING parameters from the request to this page.  If no parameter, returns nothing.
// Call URL like this:  http://nlpls.com/test/getQueryStrJS.html?gaw=2233&ai=545
// Call function like this:  getQuerystring('ai')
//
function getQuerystring(key){  
	key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");  
	var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");  
	var qs = regex.exec(window.location.href);  
	
	if(qs == null)
		// return default_;  // this is the original version
		return "";
	else    
		return qs[1];
}

	/*************************************************************************\
	boolean isNum(String argvalue)
	return true if argvalue contains only numeric characters,
	else return false.
	\*************************************************************************/
	function isNum(argvalue) {
		argvalue = argvalue.toString();
		
		if (argvalue.length == 0)
			return false;
		
		for (var n = 0; n < argvalue.length; n++)
			if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
				return false;
		
		return true;
	}

	
// -------------------------------------------------------------------
//                   OTHER STANDARD FUNCTIONS
// -------------------------------------------------------------------


// -------------------------------------------------------------------
//                   HANDLE FORM ANSWERS
// -------------------------------------------------------------------
function setAnswer(theParamName, theParamValue) {
	
	var theUIDcookie	= GetCookie('NLS_UID');
	var paramThere		= newGetCookieParam('NLS_PRE', theParamName);		
	var expdate 		= new Date();		
	
	expdate.setTime( expdate.getTime() + (90 * 24 * 60 * 60 * 1000) ); // 90 days from now

	// Cookies enabled?
	if ( !theUIDcookie ) {
		alert("OOPS! Your browser has Cookies disabled!\n\n" +
			  "This form uses Cookies to collect your\n" +
			  "answers for your FREE SUMMARY page.\n\n" +
			  "Please enable your Cookies, reload this\n" +
			  "page, and select your answer again.\n\n" +
			  "THANKS! -- JDH"
		);
		return true;
	} 
	
	// If user checks a checkbox, then unchecks it, delete it's param.
	if ( !theParamValue ) { 
		deleteCookieParam("NLS_PRE", theParamName, expdate, "/", ".nlpls.com"  );
		return true;
	}
	
	changeAddCookieParam("NLS_PRE", theParamName, theParamValue, expdate, "/", ".nlpls.com" );
}


// Go to the next page in a form series
function nextPage(theNextPage) {
	var thePREcookie	= GetCookie('NLS_PRE');
	var theUIDcookie	= GetCookie('NLS_UID');
	
	if ( !theUIDcookie ) {
		alert("OOPS! Your browser has Cookies disabled!\n\n" +
			  "This form uses Cookies to collect your\n" +
			  "answers for your FREE SUMMARY page.\n\n" +
			  "Please enable your Cookies, reload this\n" +
			  "page, and select your answer again.\n\n" +
			  "THANKS! -- JDH"
		);
		return true;
	} else if ( !thePREcookie ) {
		alert("OOPS! Please select your answer and THEN click 'Continue'\n\n" +
			  "THANKS! -- JDH"
		);
		return true;
	} else {
		// top.location.href = theNextPage; // Break out of frames
		location.href = theNextPage; 
	}
}

// -------------------------------------------------------------------
// -------------------------------------------------------------------
/* -------------------------------------------------------------------
					MANAGE GIFS
USAGE: HTML: 
</head>
<body onload = "always();" >
<div id="gifDiv" style="position:absolute; top:0px; left:0px; width:110px; visibility:hidden; z-index:-20; background-color:#FFFFFF; layer-background-color:#FFFFFF;"></div>
------------------------------------------------------------------- */
function gifmgr() {
	var ie5, ie6, theRandNum, theText, thisUID;
	var theUserAgent = navigator.userAgent.toLowerCase();
	var theDate = new Date ();
	theDate = escape(theDate);
	ie5 = 0;
	ie6 = 0;
	theRandNum = makeRandomUID();
	
	theText = '<table cellspacing=0 cellpadding=1 border=0 width=20><tr><td bgcolor=#FFFCE5>';
	theText += '<table width=100% cellspacing=0 cellpadding=2 border=0 bgcolor=#FFFCE5><tr><td align=left>';
	thisUID = getCookieParam("NLS_UID", "uid"); // Don't delete this line!
	// theText += '<img src="http://www.nlpls.com/cgi-bin/gifmgr.cgi?' + theDate + '">';	
	theText += '<img src="http://www.nlpls.com/cgi-bin/gifmgr.cgi?' + checkTimeZone() + '">';	
	theText += '</font></td></tr></table></td></tr></table>';
	
    gifDiv.style.visibility = "visible"; // "visible" // "hidden"
    gifDiv.style.zindex = "-20";
    gifDiv.innerHTML = theText;
	// alert(theText);
	
}

function checkTimeZone() {
   var rightNow = new Date();
   var date1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
   var date2 = new Date(rightNow.getFullYear(), 6, 1, 0, 0, 0, 0);
   var temp = date1.toGMTString();
   var date3 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
   var temp = date2.toGMTString();
   var date4 = new Date(temp.substring(0, temp.lastIndexOf(" ")-1));
   var hoursDiffStdTime = (date1 - date3) / (1000 * 60 * 60);
   var hoursDiffDaylightTime = (date2 - date4) / (1000 * 60 * 60);
   if (hoursDiffDaylightTime == hoursDiffStdTime) { 
      return("GMT:" + hoursDiffStdTime); // No daylight savings time
   } else {
      return("GMTdst:" + hoursDiffStdTime); // Yes daylight savings time
   }
}


// -------------------------------------------------------------------
// Text area character limit control function
//
// Call with HTML in form like so:
//
// 		<textarea name="message2" wrap="physical" cols="28" rows="5" 
//			onKeyDown="textCntrl(document.myForm.message2, 125)" 
//		  	onKeyUp="textCntrl(document.myForm.message2, 125)" > 
//		</textarea>
//
// Note that you need both onKeyDown and onKeyUp because a user could theoretically
// fill up a field just holding a key down while his computer did a char repeat.
// -------------------------------------------------------------------

function textCntrl( field, maxlimit ) {
	if ( field.value.length > maxlimit ) {
	   field.value = field.value.substring(0, maxlimit);
	   alert("Sorry, you've reached the length limit for this answer!");
	}
}

 // This works in href links like this:  <a href="javascript:OpenChat()" >HERE</a>
function OpenChat() {
	window.open("http://chat.aplus.net/johnhoag/chatwindow.cgi?department=support&site=msg1&REFERER=Aplus", "AplusChat","height=310,width=500,status=no,toolbar=no,menubar=no,location=no");
}
	// -------------------------------------------
	// -------------------------------------------
	// -------------------------------------------
	// -------------------------------------------
	// -------------------------------------------
	// -------------------------------------------
	// -------------------------------------------

// -->

