
/* ------------------------------------------------------------------------------------------------------------------------------ */
function processPAPCookie() {
	// this function is called below

	try {	
		var cookieLife 			= 180;	 
	
		var overwriteCookies 	= 1; 
		var scriptLoc 			= '';
		var affid 				= 0;
		
		// look for a query string on the URL
		var qs 					= location.search.substring(1); 
		
		// verify cookies enabled
		createCookie('test', '1', 1);
		var testVal = readCookie('test');
		eraseCookie('test');
		
		var hasCookies = 0;
		
		// cookies enabled and query string present
		if (testVal == '1' && qs.length > 0) {
			hasCookies = 1;
		
			if ((readCookie('apid') == null) || (overwriteCookies == 1)) { 
		
				// get the target apid parm from the query string
				var pairs = qs.split('&'); 
				for(var i = 0; i < pairs.length; i++) { 
					var pairs2 = pairs[i].split('='); 
					switch(pairs2[0].toLowerCase()) { 
						case 'apid': 
							affid = pairs2[1]; 
							break; 
					}
				}
			}
		} 
		 
		//If affid is set, then set a cookie. 
		if (affid != 0) { createCookie('apid', affid, cookieLife);
		
		} else {
			/*
			// *** policy changed to require apid parm on the url ***
			// set apid cookie from the PAP cookie if possible
			// see mainpage.js
			var papids	= getPAPIDs('cookie');
			if (papids) {
				if (papids.a) {
					createCookie('apid', papids.a, cookieLife);
					return;
				}
			}
			*/
		}
	}
	catch(err) {
		return;
	}

	return;
}
/* ------------------------------------------------------------------------------------------------------------------------------ */

processPAPCookie();