// 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;
    	}
    }
}

// return to comet
function rtc() {
  try {
      if (window.opener && !window.opener.closed) {
	window.opener.focus();
        return false;
    } else {
        return true;
    }
  } catch (e) {
     return true;
 }
}

// 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;
        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 (docDomain.indexOf("member") > -1) {
                docPath = "";
            }
        } else {
            docPath = "";	
        }
        if (((docDomain.indexOf(".netscape.com") > -1) || (docDomain.indexOf("cnn.com") > -1)) && (docDomain.indexOf("channels") == -1)) {
            docPath = "";
        }
        var trackradioURL = docPath + "/wrap/linker.jsp?floc=" + strFlocCode + "&ref=";
        if ((docDomain.indexOf(".office") > -1)||(docDomain.indexOf("-lab") > -1)||(docDomain.indexOf("-ill")>-1)){
            alert ( "docDomain="+docDomain );
            alert ( "docPath="+docPath );
        }
        var radioURL = "http://radio.netscape.com/aolradio/ns/html/PlayRadioNow.htm";
        if (stationID!='') {
            radioURL += escape('?openplayer=true&channel=' + stationID);
        } else {
            radioURL += escape('?openplayer=true');
        }
        if ((docDomain.indexOf(".office") > -1)||(docDomain.indexOf("-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(".office") > -1)||(docDomain.indexOf("-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);
            }
        }
    }
}

function hideImage() {
    document.getElementById('storyImage').style.display = 'none';
}

function showAltImage(source, altID) {
    source.onerror = "";
    source.style.display = "none";
    document.getElementById(altID).style.display = "inline";
    return true;
}
