var samplerWin = null;
//need this here for the sampler

function getNSRadioCookie(aName, aDocument) {
    if (!aDocument) aDocument = document;
    var myValue = null;
	// Locate the cookie value
    var myCookie;
    var cookieAsString = aDocument.cookie;
    var expression = new RegExp(aName + '=[^;]+');
    while (expression.test(cookieAsString)) {
        myCookie = cookieAsString.match(expression);
        cookieAsString = cookieAsString.replace(expression, "");
    }
    // Extract the cookie value
    if (myCookie) {
        var cookieValue = myCookie[0].match(/=(.*)/);
        if (cookieValue && (cookieValue.length > 1)) {
            myValue = cookieValue[1];
        }
    }
    return myValue;
}
function launchRadioNetscape(stationID, strFlocCode) {
	if (getNSRadioCookie("hasRadioPLus") == 'true') {
		document.location = "http://channels.netscape.com/ns/music/radio/launch.jsp?"+stationID;
	} else {
		var docDomain = window.location.hostname;
		var docPath = window.location.pathname;
		var pos = 0;
		var numof = -1;
		var i = -1;
		var twopos = -1;
		while (pos != -1) {
			pos = docPath.indexOf("/", i + 1);
			numof += 1;
			if (numof == 1) {
				twopos = pos;
			}
			i = pos;
		}
		if (numof > 1) {
			docPath = docPath.substring(0, twopos);
			if (docPath.indexOf("music") > -1) {
				docPath = "";
			}
		} else {
			docPath = "";	
		}
		if ((docDomain.indexOf(".netscape.com") > -1) && (docDomain.indexOf("channels") == -1)) {
			docPath = "";
		}		var trackradioURL = "";
		var radioURL = "http://radio.netscape.com/aolradio/ns/html/PlayRadioNow.htm";
		if (stationID) {
			radioURL += '?openplayer=true&channel=' + stationID;
		}
		var userAgt=navigator.userAgent.toLowerCase();
		var isWin=(userAgt.indexOf('win')!=-1);
		var is_major = parseInt(navigator.appVersion);
		var is_minor = parseFloat(navigator.appVersion);
		var is_ie = ((userAgt.indexOf("msie") != -1) && (userAgt.indexOf("opera") == -1));
		var is_ie3 = (is_ie && (is_major < 4));
		var is_ie4 = (is_ie && (is_major == 4) && (userAgt.indexOf("msie 4")!=-1) );
		var is_ie5 = (is_ie && (is_major == 4) && (userAgt.indexOf("msie 5.0")!=-1) );
		var isIEcompliant  = (is_ie && !is_ie3 && !is_ie4);
		var isNS  = ((userAgt.indexOf('netscape')!=-1) && (userAgt.indexOf('webtv')==-1) && (userAgt.indexOf('gecko')!=-1));
		var isNS3 = (isNS && (is_major == 3));
		var isNS4 = (isNS && (is_major == 4));
		var isNS4x = (isNS && (is_major >= 4) && (is_major < 5));
		var isNS60=((userAgt.indexOf('netscape')!=-1) && (userAgt.indexOf('6.0')!=-1));
		var isNScompliant = (isNS && (is_major >= 5) && !isNS60 && !isNS3 && !isNS4x);
		var isClient = ((userAgt.indexOf('cs2000')!=-1) || (userAgt.indexOf('cs 2000')!=-1));
		if (isWin && (isNScompliant || isIEcompliant || isClient)) {   
			if (is_ie5)	{
				iFrame = document.body.insertAdjacentHTML('beforeEnd','<div style="position: absolute; top: 0px; left: 0px; width: 1; height:1; visibility: hidden"><IFRAME width=1 height=1 src="' + trackradioURL + radioURL + '"></IFRAME></div>');
			} else {
			//launch player iframe
			iFrame = document.createElement('IFRAME');
			var s = iFrame.style;
			s.visibility='hidden';
			s.width=1;
			s.height=1;
			document.body.appendChild(iFrame);
			iFrame.src = trackradioURL + radioURL;
			}
		} else {
			//go to sampler sell page
			if (stationID) {
				var samplerUrl = radioURL + '&opensampler=true';
				samplerUrl = trackradioURL + samplerUrl;
				if ( navigator.appVersion.indexOf("Mac") != -1 && navigator.userAgent.indexOf("MSIE") != -1) {
					var playerwidth = 360;
					var playerheight = 150;
				} else {
					var playerwidth = 370;
					var playerheight = 157;
				}
				if ((samplerWin == null) || samplerWin.closed) {
					samplerWin = window.open(samplerUrl,'StationSampler','width='+ playerwidth +',height='+playerheight+',resizable=no,status=0');
				} else {
					samplerWin.location.href = samplerUrl;
				}
			} else {
				radioURL += '?samplerpage=true';
				radioURL = trackradioURL + radioURL;
				window.location.href = radioURL;
			}
		}
	}
}
