	function getCookie() {
		var results = new Array();
		if (document.cookie.length > 0) {
			var cookie  = document.cookie;
			var cookies = cookie.split("\; ");
			for (var i = 0; i < cookies.length; i++) {
				var namevalue = cookies[i].split("=");
				results[namevalue[0]] = unescape(namevalue[1]);
			}
		}
		return results;
	}

	function setCookie( strCookieName, strCookieValue, objCookieExpires ){
		strCookie = strCookieName + '=' + escape ( strCookieValue ) + '; ';
        strCookie += 'domain=.napster.com; ';
		strCookie += 'path=/; ';
        if (objCookieExpires) {
    		strCookie += 'expires=' + objCookieExpires.toGMTString() +  ';';
        }
		document.cookie = strCookie;
	}
	
	var cookie = getCookie();

	var $C = function( strCookieName, strCookieValue, blnCookieExpire, strPath ){
		if( ( strCookieName != null || strCookieName != '' ) && strCookieValue == null ){
			var strResults = ''
			if( document.cookie.length > 0 ){
				var cookie  = document.cookie;
				var cookies = cookie.split( "\; " );
				for( var i = 0; i < cookies.length; i++ ){
					var namevalue = cookies[i].split( "=" );
					if( strCookieName == namevalue[0] ){
						strResults = unescape( namevalue[1] );
						break;
					}
				}
			}
			return strResults;
		}
		else if( !( strCookieName == null && strCookieName == '' ) && !( strCookieValue == null && strCookieValue == '' ) ){
			var strCookie = strCookieName + '=' + escape ( strCookieValue ) + '; ';
	        strCookie += 'domain=.napster.com; ';
			if( strPath != null )
				strCookie += 'path=' + strPath + '; ';
			else
				strCookie += 'path=/; ';
	        if( blnCookieExpire ){
				var objCookieExpires = new Date();
				objCookieExpires.setTime( objCookieExpires.getTime() - (1000 * 60 * 60 * 24 * 1) );
	    		strCookie += 'expires=' + objCookieExpires.toGMTString() +  ';';
	        }
			document.cookie = strCookie;
			return;
		}
	}

try {	
	var NQ = "";
	var req_string=top.location.search;
	if( !$C('NQ') && req_string) {
		var date = new Date();
		date.setTime(date.getTime() + (1000 * 60 * 60 * 24 * 48));		
		if (!req_string.match(/affiliate_id=/i)) {
			  var affiliate_id=7;
			  if (window.location.href.match(/home\.napster\.com\/ns\/music/)) { affiliate_id=192; }
     	  req_string = req_string + '&affiliate_id=' + affiliate_id;  	  
     }		
		document.cookie = "NQ=" + escape(req_string) + "; domain=.napster.com; path=/;";
		NQ = req_string;
	}	else if( $C('NQ') != null ){
		  NQ = unescape( $C('NQ') );
	}
} 
catch(e){}
	
	var objCookieInterval;
	
	if( $C( 'COUNTRYCODE' ) == null || $C( 'COUNTRYCODE' ) == '' ){
		if ( typeof( objCookieInterval ) == 'undefined' ) {
			objCookieInterval = setInterval( function(){
				if( typeof( Ajax ) == 'object' ){
					clearInterval( objCookieInterval );
					var myAjax = new Ajax.Request(
						"/geoXML" + "?r=" + Math.random(), {
							method: 'get',
							paramters: '',
							onComplete: function(){
								objXML = arguments[0].responseXML.documentElement;
								objAjaxData = objXML.getElementsByTagName( 'result' )[0];
								var strCountryCode = '';
								strCountryCode = objAjaxData.getAttribute( 'content_country' );
								$C( 'COUNTRYCODE', strCountryCode );
							}
						}
					);
				}
			}, 500 );
		}
	}
