	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 = "";
		if( !$C('NQ') && top.location.search) {
			var date = new Date();
			date.setTime(date.getTime() + (1000 * 60 * 60 * 24 * 48));
			document.cookie = "NQ=" + escape(top.location.search) + "; domain=.napster.com; path=/; expires=" + date.toGMTString();
			NQ = top.location.search;
		}
		else if( $C('NQ') != null ){
			NQ = unescape( $C('NQ') );
		}
	} 
	catch(e) {
	}
	
	var objCookieInterval = null;
	
	if( $C( 'COUNTRYCODE' ) == null || $C( 'COUNTRYCODE' ) == '' ){
		var objInterval = setInterval( function(){
			if(typeof dojo != 'undefined'){
				clearInterval( objInterval );
				var ccArgs= {
					url: "http://home.napster.com/cgi-bin/geo_data_xml.cgi?r=" + Math.random(), 
					//mimetype: "text/xml",
					handleAs: "xml",
					//load: function(type, xmlData, evt) {
					load: function(response, ioArgs) {
						//objAjaxData = xmlData.getElementsByTagName( 'result' )[0];
						objAjaxData = response.getElementsByTagName( 'result' )[0];
						var strCountryCode = '';
						strCountryCode = objAjaxData.getAttribute( 'content_country' );
						if (strCountryCode != null && strCountryCode.length > 0)
							if (strCountryCode != 'US')
								top.location.href = 'http://www.napster.com/';
						$C( 'COUNTRYCODE', strCountryCode );
						return response;
					},
					error: function(response, ioArgs) {
						//console.log("Failed COUNTRYCODE xhrGet");
						return response;
					}
				};
				dojo.xhrGet(ccArgs);
			}
		}, 50 );
	}


	var $SDATval = function(){
		if( arguments[0] != null ){
			var strSDATName = arguments[0];
			var strSDATValue = null;
			if( arguments.length == 2 )
				strSDATValue = arguments[1];
			var strSCCookieData = dojo.cookie( 'SDAT' ) ? dojo.cookie('SDAT') : "";
			if( arguments.length == 1 ){
				var aryDataPairs = strSCCookieData.split( '&' );
				for( intDataIndex = 0; intDataIndex < aryDataPairs.length; intDataIndex++ ){
					var intPosition = aryDataPairs[intDataIndex].indexOf('=');
					if( intPosition == -1 ) continue;
					var strDataName = aryDataPairs[intDataIndex].substring( 0, intPosition );
					var strDataValue = aryDataPairs[intDataIndex].substring( intPosition + 1 );
					if( strDataName == strSDATName ){
						if( objSDATata[strDataName] != null )
							return unescape( objSDATata[strDataName][strDataValue] );
						else
							return unescape( strDataValue );
					}
				}
			}
			else if( arguments.length == 2 ){
				var strSDATata = '';
				var aryDataPairs = strSCCookieData.split( '&' );
				var objSDAT = new Object();
				for( intDataIndex = 0; intDataIndex < aryDataPairs.length; intDataIndex++ ){
					var intPosition = aryDataPairs[intDataIndex].indexOf('=');
					if( intPosition == -1 ) continue;
					var strDataName = aryDataPairs[intDataIndex].substring( 0, intPosition );
					var strDataValue = aryDataPairs[intDataIndex].substring( intPosition + 1 );
					objSDAT[strDataName] = unescape( strDataValue );
				}
				objSDAT[strSDATName] = strSDATValue;
				for( var strValues in objSDAT ){
                                        if (strValues.indexOf('toSource') > -1) continue;
					if( objSDAT[strValues] != null && objSDAT[strValues] != 'null' )
						strSDATata += "&" + strValues + '=' + escape( objSDAT[strValues] );
                                }
				strSDATata = strSDATata.substring( 1 );
				dojo.cookie('SDAT',strSDATata, {path:'/', domain: '.napster.com'});
			}
		}
	}

