<!-- start scripting
// pca.js
// draws, decides and stores PCA values.

var gPCABaseURL = "http://www.live365.com";

// Define Globals
var gLeftMargin			= 0;
var gLeftMarginImg		= '<img src="' + gPCABaseURL + '/images/dot.gif" width="' + gLeftMargin + '" height="1">';
var gBoxVertSpacing		= '<img src="' + gPCABaseURL + '/images/dot.gif" width="1" height="5">';
var gRightSideBarWidth	= "100%";
var gCellPadding		= 3;
var gFileName			= document.location.pathname;
var iLastSlash			= gFileName.lastIndexOf("/");
gFileName				= gFileName.slice(iLastSlash + 1);
var gUser 				= DetermineUser("user");			// Get user ID for UserBox
var gSessionId			= DetermineUser("sessionid");	
var gLoggedIn 			= (gUser != "");


// THIS IS TEMPORARY TO SERVE ONLY SPONSORS UNTIL WE'RE READY TO TURN ON USER BOX FOR THE WHOLE SITE
function TempDrawSideBarRight(content1,content2,redirectURL,suppressLoginBox,suppressSponsor,site,genre,suppressCTA,adNumber)
{
	
	// handle undefined variables		
	if (TempDrawSideBarRight.arguments.length < 1 || TempDrawSideBarRight.arguments[0] == "")
		content1 = false;
	else
	if (TempDrawSideBarRight.arguments.length < 2 || TempDrawSideBarRight.arguments[1] == "")
		content2 = false;
	else
	if (TempDrawSideBarRight.arguments.length < 3 || TempDrawSideBarRight.arguments[3] == "")
		redirectURL = gPCABaseURL + "/home/";
	if (TempDrawSideBarRight.arguments.length < 6)
		site = "..";
	if (TempDrawSideBarRight.arguments.length < 7)
		genre = (content1) ? content1 : "";	
	if (TempDrawSideBarRight.arguments.length < 8 || TempDrawSideBarRight.arguments[7] == "")
		suppressCTA = false;
	if (TempDrawSideBarRight.arguments.length < 9 || TempDrawSideBarRightarRight.arguments[8] == "")
		adNumber = 100;

	if (!suppressSponsor) {
		DrawSponsorBox(pageLocation,genre,adNumber);
		document.write(gBoxVertSpacing);
	}

	printBoxes(content1,content2);
}


// DrawSideBar() -- top level
//   draws components of sidebar on the right side of the layout.
//   content1 = optional = defines high level organization
//   content2 = optional = defines second teir organization
//   suppressLogin = optional = doesn't display the login box
//   suppressSponsor = optional = doesn't display the sponsor box
//   redirectURL = optional = if not present, will assume redirect back to the page you are currently on.
//   suppressCTA = optional = doesn't display any CTAs.. used for popup displays.
function DrawSideBarRight(content1,content2,redirectURL,suppressLoginBox,suppressSponsor,site,genre,suppressCTA,adNumber) 
{
	
	// handle undefined variables		
	if (DrawSideBarRight.arguments.length < 1 || DrawSideBarRight.arguments[0] == "")
		content1 = false;
	if (DrawSideBarRight.arguments.length < 2 || DrawSideBarRight.arguments[1] == "")
		content2 = false;
	if (DrawSideBarRight.arguments.length < 3 || DrawSideBarRight.arguments[2] == "")
		redirectURL = gPCABaseURL + "/home/";
	if (DrawSideBarRight.arguments.length < 6)
		site = "..";
	if (DrawSideBarRight.arguments.length < 7)
		genre = (content1) ? content1 : "";	
	if (DrawSideBarRight.arguments.length < 8 || DrawSideBarRight.arguments[7] == "")
		suppressCTA = false;
	if (DrawSideBarRight.arguments.length < 9 || DrawSideBarRight.arguments[8] == "")
		adNumber = 100;

	if (!suppressLoginBox) {
		DrawUserBox(redirectURL,site,genre,content1);		// draw UserBox
		document.write(gBoxVertSpacing);
	}
	
	if (!suppressSponsor) {
		DrawSponsorBox(pageLocation,genre,adNumber);
		document.write(gBoxVertSpacing);
	}
	
	if (content1 == "home") {
		printHomePageRight(content1,content2,pageLocation,genre);
	} else {
		if (!suppressCTA)
			printBoxes(content1,content2);
	}

	if (content1 == "listen") {
		// DrawLegends is in directory.js
		// gLegend is defined in main_head.html
		
		if (gLegend.indexOf('M') != -1)
			DrawLegends("main", gUser, gRightSideBarWidth);

		if (gLegend.indexOf('L') != -1)
			DrawLegends("listeners", gUser, gRightSideBarWidth);

		if (gLegend.indexOf('R') != -1)
			DrawLegends("ratings", gUser, gRightSideBarWidth);

		if (gLegend.indexOf('A') != -1)
			DrawLegends("attributes", gUser, gRightSideBarWidth);
	}
}


// DetermineUser()
//   call with flag for what part of the sessionid cookie to read.
function DetermineUser(flag) 
{
	var sid = ReadCookie("sessionid");  // access cookie

	if (sid) {
		if (flag == "user"){
			return sid.slice(0, sid.indexOf(':'));
		} else if (flag == "sessionid")
			return sid.slice(sid.indexOf(':') + 1);
	} else {
		return "";
	}
}


// DrawSponsorBox()
function DrawSponsorBox(sourceFile, genre, maxTiles)
{
	var numTiles = 3; // number of tiles to draw
	
	var tile;
	var firstTile = 2; // tile 1 is reserved for the banner
	var currentDate = new Date();
	var tm = currentDate.getTime();

	if (numTiles > maxTiles)
		numTiles = maxTiles;

	document.write('<table border="0" width="100%" cellspacing="0" cellpadding="' + gCellPadding + '">');	
	
	if (numTiles > 1)
		DrawTitleRow("Sponsors");
	else
		DrawTitleRow("Sponsor");

	document.write('<tr><td id="userbox" align="center" width="' + gRightSideBarWidth + '">');
	document.write('<img src="' + gPCABaseURL + '/images/dot.gif" width="1" height="5"><br>');

	for (tile = firstTile; tile < firstTile + numTiles; tile++) {
		DrawSponsor(sourceFile, genre, tile, tm);
		document.write('<br><img src="' + gPCABaseURL + '/images/dot.gif" width="1" height="5"><br>');
	}
	
	document.write('</td></tr>');
	document.write('</table>');
} // DrawSponsorBox()


// DrawTitleRow()
//   title = required
//   colspan = optional = used to span more than one column as in the user box.
function DrawTitleRow(title, colspan)
{
	if (DrawTitleRow.arguments.length < 1)
		colspan = "1";
	colspan = 'colspan="' + colspan + '"';
	document.write('<tr><td  ' + colspan + ' id="questionhead" width="' + gRightSideBarWidth + '">');
	document.write(title);
	document.write('</td></tr>');
}


// DrawSubTitleRow()
//   title = required
//   colspan = optional = used to span more than one column as in the user box.
function DrawSubTitleRow(title, colspan)
{
	if (DrawSubTitleRow.arguments.length < 1)
		colspan = "1";
	colspan = 'colspan="' + colspan + '"';
	document.write('<tr align="left"><td  ' + colspan + ' id="pcasubtitle" width="' + gRightSideBarWidth + '">');
	document.write(title);
	document.write('</td></tr>');
}

// DrawByLineRow()
//   byline = required
function DrawBylineRow(byline)
{
	document.write('<tr><td id="questionsubtext" width="' + gRightSideBarWidth + '">');
	document.write(byline);
	document.write('</td></tr>');
}


// DrawUserBox()
//   user = required
//   site = optional
//   genre = optional (used in directory, and changes buttons if on Presets directory)
function DrawUserBox(redirectURL,site,genre,content1)
{
	// initialize vars
	redirectURL = escape(redirectURL);
	var size = (navigator.appName == "Netscape") ? 5 : 10;
	var tmd = new Date();
	var tm = tmd.getTime();
	if (DrawUserBox.arguments.length < 3)
		site = "..";
	if (DrawUserBox.arguments.length < 4)
		genre = "";
	var target = (site == "..") ? "_self" : "_blank";

	// start HTML output
//	document.write('<table border="0" width="' + gRightSideBarWidth + '" cellpadding="' + gCellPadding + '" cellspacing="0">');
	document.write('<table border="0"  width="100%" cellpadding="' + gCellPadding + '" cellspacing="0">');

	if (gLoggedIn)
		DrawTitleRow("You are logged in:", "2");
	else
		DrawTitleRow("Log In:", "2");

	if (!gLoggedIn) {
		document.write('<FORM NAME="LoginInForm" ACTION="' + gPCABaseURL + '/cgi-bin/login.cgi" METHOD="post">');
		document.write('<input type="hidden" name="url" value="' + redirectURL + '">');
		document.write('<input type="hidden" name="success" value="' + gPath + '">');
	}

	document.write('<tr><td width="74" align="right" id="login">');
	document.write(gLeftMarginImg + 'Username: </td><td id="userbox" nowrap align="left" width="90">');
	
	if (gLoggedIn) {
		document.write('<b>' + gUser + '</b></td>');
	} else {
		document.write('<input type="hidden" name="site" value="' + site + '">');
		document.write('<input type="text" name="membername" size="' + size + '" id="searchinput"></td></tr>');
		document.write('<tr><td width="74" align="right" id="login">');
		document.write(gLeftMarginImg + 'Password: </td><td id="userbox" nowrap align="left" width="90">');
		document.write('<input type="password" name="password" size="' + size + '" id="searchinput"></td></tr>');
        document.write('<tr><td colspan=2 align="center" id="login">');
        document.write('remember&nbsp;me: <input type="checkbox" name="rememberme" value="Y"></td></tr>');
        document.write('<tr><td colspan=2 align="center" id="login"">');
		document.write('<input type="Image" src="' + gPCABaseURL + '/home/images/login.gif" alt="Login" width="39" height="19" border="0" vspace="3"></td></tr>');
        document.write('<tr><td colspan=2 align="center" id="login">');
		document.write('<a href="' + gPCABaseURL + '/registration/index.html" target=' + target + '>sign up now</a><br>');
		document.write('<a href="/members/login.live?action=forgot&url=' + escape(pageLocation) + '">forgot your password?</A></td></tr></FORM>');
	}

	document.write('<tr><td colspan=2 align="center" id="userbox">');

	if (content1 == "listen" || content1 == "home") {
		if (gLoggedIn) {
			if (genre == "Presets")
				document.write('<a href="' + gPCABaseURL + '/cgi-bin/directory.cgi?site=' + site + '"><img src="' + gPCABaseURL + '/images/returntodir.gif" width="146" height="18" border="0" vspace="0" hspace="0" alt="Return to Directory"></a><br>');
			else
				document.write('<a href="' + gPCABaseURL + '/cgi-bin/directory.cgi?site=' + site + '&genre=Presets"><img src="' + gPCABaseURL + '/images/tomypresets.gif" width="146" height="18" border="0" vspace="0" hspace="0" alt="Go to My Presets"></a><br>');
		} else
			document.write('<a href="javascript:alert(\'You must be logged in to go to your list of Presets\')"><img src="' + gPCABaseURL + '/images/tomypresets-dim.gif" width="146" height="18" border="0" vspace="0" hspace="0" alt="Go to My Presets"></a><br>');
		document.write('<img src="' + gPCABaseURL + '/images/dot.gif" height="5" width="1"><br>');
		document.write('<a href="' + gPCABaseURL + '/cgi-bin/personalize.cgi?redirectUrl=' + redirectURL + '" target=' + target + '><img src="' + gPCABaseURL + '/images/changesettings.gif" width="146" height="18" vspace="0" hspace="0" border="0" alt="Change my Settings"></a><br>');
	}

	if (gLoggedIn)
		document.write('<a href="' + gPCABaseURL + '/interact/acctinfo.live?url=' + redirectURL + '&' + tm + '"><img src="' + gPCABaseURL + '/images/memberprofile.gif" width="146" height="18" border="0" vspace="0" hspace="0" alt="Member Profile"></a><br>');

	if (gLoggedIn) {
		document.write('<img src="' + gPCABaseURL + '/images/dot.gif" height="5" width="1"><br>');
		document.write('<a href="' + gPCABaseURL + '/cgi-bin/login.cgi?url=' + redirectURL + '&action=out&' + tm + '"><img src="' + gPCABaseURL + '/images/logout.gif" width="146" height="18" border="0" vspace="0" hspace="0" alt="Log Out"></a>');
	}
	document.write('</td></tr></table>');
}

// Determine content
function printBoxes(content1,content2) 
{
	for (i = 0; i < aContent1.length; i++) {
		if (aContent1[i]) {
			document.write('<table border="0" width="100%" cellspacing="0" cellpadding="' + gCellPadding + '">');
			DrawTitleRow(aContent1[i]);
			i++;
			DrawBylineRow(aContent1[i]);
			document.write('</table>');
			document.write(gBoxVertSpacing);
		} else {
			return false;
		}
	}
}


function printHomePageRight(content1,content2,pageLocation,genre,adNumber)
{

	if (printHomePageRight.arguments.length < 5 || printHomePageRight.arguments[4] == "")
		adNumber = 100;

	DrawNewUserBox();
	
	document.write(gBoxVertSpacing);
	
	DrawESP();
	
	document.write(gBoxVertSpacing);
	
	DrawSponsorBox(pageLocation,genre,adNumber);
	
	document.write(gBoxVertSpacing);
	
	DrawNewsletterBox();
	
	document.write(gBoxVertSpacing);
	

	printBoxes(content1,content2);
}


function DrawESP()
{
	var i;
	var arr;
	var cName  = 0;
	var cDesc  = 1;
	var cGenre = 2;
	var cSpeed = 3;
	var cBlurb = 4;
	var cCount = 5;

	document.write('<table border="0" width="100%" cellspacing="0" cellpadding="' + gCellPadding + '">');
	DrawTitleRow("Editor\'s Station Picks","2");


	if (ReadCookie("bitrate") >= 56) {
		DrawSubTitleRow("High Bandwidth (T1/DSL/Cable)",2);
		arr = gESPHigh;
	} else {
		DrawSubTitleRow("Low Bandwidth (14K,28K,33K,56K)",2);
		arr = gESPLow;
	}

	i = 0;
	while (i < arr.length) {
		document.write('<tr valign="top">')
		document.write('<td width="10" valign="top" id="questionsubtext">')
		document.write('<A href=\'javascript:LaunchBroadcast365("'+ arr[i + cName] +'")\'>');
		document.write('<img src="' + gPCABaseURL + '/images/listen-sm-picks.gif" width="15" height="15" border="0" alt="Click to listen" vspace="0" hspace="0"><BR></a>')
		document.write('<img src="' + gPCABaseURL + '/images/dot.gif" height="8" width="1"><BR>')

		DrawPreset(arr[i + cName], arr[i + cDesc])

		document.write('</td>')
		document.write('<td bgcolor="000033" valign="top" id="questionsubtext">')
		document.write('<A href=\'javascript:LaunchBroadcast365("'+ arr[i + cName] +'")\'><b>');
		document.write(arr[i + cDesc] + '</a><BR> (' + arr[i + cGenre] + ') (' + arr[i + cSpeed] + ')</b><br>')
		document.write(arr[i + cBlurb])
		document.write('</td>')
		document.write('</tr>')

		i += cCount;
	}

	DrawTitleRow('<a href=\"' + gPCABaseURL + '/cgi-bin/directory.cgi\">Check out ' + TotalStations + ' other stations',2);
	document.write('</table>')
}

// end scripting -->
