// Global 50 Template Javascript 

// This is for resizing the window
//
function rz() {
var agent = navigator.userAgent.toLowerCase();
	if (((agent.indexOf("cs 2000 7") != -1 ) || (agent.indexOf("cs2000 7") != -1 )) && ((window.innerWidth < 782) && (window.screen.availWidth > 781))) {
	window.resizeTo(782, window.outerHeight);
	}
}

// Poll check for max number of selections
function checkMaxSelections(theform, selectedAnswer, maxAnswers) {
    var numChecked = 0;
    for (counter=0; counter<theform.elements.length; counter++) {
    	if (theform.elements[counter].checked)  {
    	numChecked = numChecked + 1;
    	}
    
    	if (numChecked > maxAnswers) {
    		alert("You may only select " + maxAnswers + ".");
    		theform.elements[selectedAnswer].checked = 0;
    	}
    }
}

// Flash detection code will be updated after QE pass 
//
var detectedVersion = -1;
var detectedmVersion;
function getFlashVersion (baseVersion) {
	if (detectedVersion != -1) return detectedVersion;
	if (baseVersion == null) baseVersion = 10;

	if (navigator.plugins != null && navigator.plugins.length > 0) {
		var pluginRef = navigator.plugins['Shockwave Flash'];
		if (pluginRef != null) {
			var verIndex = pluginRef.description.indexOf (".");
			detectedVersion = parseInt (pluginRef.description.substr (verIndex - 1, 1));
			detectedmVersion = pluginRef.description.substr (verIndex +2);
		}
	}
	else if (navigator.userAgent.indexOf("MSIE") != -1 && parseInt(navigator.appVersion) >= 4 && navigator.platform == "Win32") {
		document.write('<scr' + 'ipt language="VBScript"\> \nPrivate i, x\nOn Error Resume Next\nMM_FlashControlInstalled = False\nFor i = ' + baseVersion + ' To 1 Step -1\n');
		document.write('Set x = CreateObject("ShockwaveFlash.ShockwaveFlash." & i)\nMM_FlashControlInstalled = IsObject(x)\nIf MM_FlashControlInstalled Then\ndetectedVersion = CStr(i)\nExit For\nEnd If\nNext\n');		
		document.write('</scr' + 'ipt\> \n');
	}
	return detectedVersion;
}
function flashEmbed (movieName, failOverImage, failOverURL, width, height, baseVersion) {
	var version = getFlashVersion (baseVersion);
	if ((version != -1) && (version >= baseVersion)) {
		writeFlashTag (movieName, width, height, baseVersion);
	}
	else {
		document.write ('<a href = "' + failOverURL + '"><img src = "' + failOverImage + '" width="' + width + '" height="' + height + '" border = "0"></a>');
	}
}
function writeFlashTag (movieName, width, height, baseVersion) {
	document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=' + baseVersion + ',0,0,0" width="' + width + '" height="' + height + '">\n<param name="movie" value="' + movieName + '">\n<param name=quality value=high>\n');
	document.write ('<embed src="' + movieName + '" TYPE="application/x-shockwave-flash" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" width=' + width + ' height=' + height + '></embed>\n</object>');		
}
getFlashVersion ();


// Netscape Radio functions
//
 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') {
		//alert("Phase II Player detected for station " + stationID);
		document.location = "http://channels.netscape.com/ns/music/radio/launch.jsp?s="+stationID;
	} else {
		var docDomain = window.location.hostname;
		//alert(docDomain);
		var docPath = window.location.pathname;
		//alert(docPath);
		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 (docDomain.indexOf("member") > -1) {
				docPath = "";
			}
		} else {
			docPath = "";	
		}
		if ((docDomain.indexOf(".netscape.com") > -1) && (docDomain.indexOf("channels") == -1)) {
			docPath = "";
		}
		var trackradioURL = "http://" + docDomain + docPath + "/wrap/linker.jsp?floc=" + strFlocCode + "&ref=";
		var radioURL = "http://radio.netscape.com/aolradio/ns/html/PlayRadioNow.htm";
		//alert(trackradioURL);
		//alert(radioURL);
		if (stationID!='') {
			radioURL += escape('?openplayer=true&channel=' + stationID);
		}else{
			radioURL += escape('?openplayer=true');
		}
		if ((docDomain.indexOf("member.office") > -1)||(docDomain.indexOf("member-lab") > -1)){
			alert("launch URL constructed:\n"+trackradioURL+"\n"+radioURL);
		}
		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.")!=-1) );
		var is_ie6 = (is_ie && (is_major == 4) && (userAgt.indexOf("msie 6.")!=-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_minor >= 4.00) && (is_minor < 5.00));
		var isNS6=((userAgt.indexOf('netscape')!=-1) && (userAgt.indexOf('6.')!=-1));
		var isNS7=((userAgt.indexOf('netscape')!=-1) && (userAgt.indexOf('7.')!=-1));
		var isNScompliant = (isNS && (is_major >= 5) && !isNS6 && !isNS3 && !isNS4x);
		var isClient = ((userAgt.indexOf('cs2000')!=-1) || (userAgt.indexOf('cs 2000')!=-1));
		if ((docDomain.indexOf("member.office") > -1)||(docDomain.indexOf("member-lab") > -1)){
			alert ("Note:  DON'T PANIC!  This data displays only on the Dev Servers.\n\nuserAgt=" + userAgt+"\nisWin="+isWin+"\nis_major="+is_major+"\nis_minor="+is_minor+"\nis_ie="+is_ie+"\nis_ie3="+is_ie3+"\nis_ie4="+is_ie4+"\nis_ie5="+is_ie5+"\nis_ie6="+is_ie6+"\nisIEcompliant="+isIEcompliant+"\nisNS="+isNS+"\nisNS3="+isNS3+"\nisNS4="+isNS4+"\nisNS4x="+isNS4x+"\nisNS6="+isNS6+"\nisNS7="+isNS7+"\nisNScompliant="+isNScompliant+"\nisClient="+isClient);
		}
		if (isWin && (isNScompliant || isIEcompliant || isClient)) {   
			if (is_ie5||is_ie6)	{
				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);
				if ((docDomain.indexOf("member.office") > -1)||(docDomain.indexOf("member-lab") > -1)){
					alert("iFrame source will be:\n"+trackradioURL +"\n"+ radioURL);
				}
				iFrame.src = trackradioURL + radioURL;
			}
		} else {
			//go to sampler sell page
			if (stationID) {
				var samplerUrl = radioURL + escape('?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;
				}
				//alert(samplerUrl);
			} else {
				radioURL += escape('?samplerpage=true');
				radioURL = trackradioURL + radioURL;
				window.location.href = radioURL;
				//alert(radioURL);
			}
		}
	}
}


