<!--
function Program( title, description, id, start, end, liveNow, streamOnly, broadcastOnly, scheduleId, friendlyUrl, inPast )
{
	this.Title = title;
	this.Description = description;
	this.Id = id;
	this.Start = start;
	this.End = end;
	this.LiveNow = liveNow;
	this.StreamOnly = streamOnly;
	this.BroadcastOnly = broadcastOnly;
	this.ScheduleId = scheduleId;
	this.FriendlyUrl = friendlyUrl;
	this.InPast = inPast;
	return this;
}
function Genre(name,id)
{
	this.Name=name;
	this.Id=id;
	return this;
}
function Station( name, id, location, slogan, logo, strength, isHiDef )
{
	this.Name = name;
	this.Id = id;
	this.Location = location;
	this.Slogan = slogan;
	this.Logo = logo;
	this.Strength = strength;
	this.IsHiDef = isHiDef;
	
	return this;
}
Station.prototype.BroadcastImg = function()
{
	var img = document.createElement( "img" );
	if( this.Strength < 10 )
	{
		img.setAttribute( "src", IMAGE_PATH + "meter0" + this.Strength + ".gif" );
	}
	else
	{
		img.setAttribute( "src", IMAGE_PATH + "meter" + this.Strength + ".gif" );
	}
	return img;
}

function Location( city, state, country )
{
	this.City = city;
	this.State = state;
	this.Country = country;
}


function Topic( title, description, programSegmentId, isDownload, isOnDemand, streamId )
{
	this.Title = title;
	this.Description = description;
	this.ProgramSegmentId = programSegmentId;
	this.IsDownload = isDownload;
	this.IsOnDemand = isOnDemand;
	this.StreamId = streamId;
	
	//	... return the object that we have created
	return this;
}

function ProgramBasicInfo( id, title, description, hosts, weburl, rating, language, logo)
{
	this.Id = id;
	this.Title = title;
	this.Description = description;
	this.Hosts = hosts;
	this.WebUrl = weburl;
	this.Rating = rating;
	this.Language = language;
	this.Logo = logo;
	
	return this;
}

function Stream( url, mediaType, streamType, bandwidth, reliability, titleAlt, id )
{
	this.Url = url;
	this.MediaType = mediaType;
	this.StreamType = streamType;
	this.Bandwidth = bandwidth;
	this.Reliability = reliability;
	this.TitleAlt = titleAlt;
	this.Id = id;
	
	//	... create a DOM object that can be attached to any page 
	this.Render = function(useAnchor)
	{
		var streamImage = document.createElement("img");
		streamImage.setAttribute( "src", IMAGE_PATH + "type-"+this.MediaType.toLowerCase()+".gif");
		if( useAnchor )
		{
			var streamAnchor = document.createElement("a");
			streamAnchor.setAttribute( "href", this.Url );
			streamAnchor.setAttribute( "title", this.TitleAlt );
			streamAnchor.setAttribute( "alt", this.TitleAlt );		
			
			streamAnchor.appendChild( streamImage );
			return streamAnchor;
		}
		return streamImage;
	}
	
	return this;
}

//	... freq to be included along with region number for broadcase lookup service
function Broadcast( frequency, broadcastType )
{
	this.Frequency = frequency;
	this.BroadcastType = broadcastType;
	
	this.Render = function()
	{
		if( this.BroadcastType.toLowerCase() == "am" 
		|| this.BroadcastType.toLowerCase() == "fm" )
		{
			var broadcastNode = document.createTextNode( this.Frequency + ' ' + this.BroadcastType );			
			return broadcastNode;
		}
		
		return null;
	}
}
function ManualSource( url, frequency, band )
{
	this.Url=url;
	this.Frequency=frequency;
	if( band = "AM" )
		this.Band = "FM";
	else
		this.Band = "FM";

	this.Type="local";
	if( null == this.Frequency || this.Frequency == "" )
		this.Type="internet";
	return this;
}
function ListeningOption( station, manualSource, scheduleId, defaultStreamId, isLive, isPlayable, isRecordable, streams, broadcasts, startTimeString, startTime, durationSeconds, recurrence, recurMask, isLocal, friendlyUrl, listenType, listenTooltipText )
{
	this.Station = station;
	this.ManualSource=manualSource;
	this.ScheduleId = scheduleId;
	this.DefaultStreamId = defaultStreamId;
	this.IsLive = isLive;
	this.IsPlayable = isPlayable;
	this.IsRecordable = isRecordable;
	this.Streams = streams;
	this.Broadcasts = broadcasts;
	this.StartTimeString = startTimeString;
	this.StartTime = startTime;
	this.DurationSec = durationSeconds;
	this.Recurrence = recurrence;
	this.RecurObj = new Recurrence( recurMask );
	this.IsLocal = isLocal;
	this.FriendlyUrl = friendlyUrl;
	this.ListenType = listenType;
	this.ListenTooltipText = listenTooltipText;
	
	this.StreamImages = function() 
	{
		var images = "";
		var i = 0
		for( i = 0; i < this.Streams.Length; i++ )
		{
			images = images + this.Streams[i];
		}
	
	}
	
	this.LocalStrength = function()
	{
		return this.Station.Strength;
	}
	this.StopString = function()
	{
		var ret = "";
		var finishtime = this.StartTime + this.DurationSec;
		if( finishtime > 24*3600 )
		{
			if(finishtime < 2*24*3600)
			{
				ret = "tomorrow, ";	
			}
			else
			{
				ret += Math.floor(finishtime/24*3600);
				ret += "days, ";
			}
			finishtime = ( finishtime % ( 24*3600) );
		}
		var dt = new Date();
		var hr = Math.floor(finishtime/3600);
		finishtime = finishtime - hr*3600;
		var m = Math.floor(finishtime/60);
		dt.setHours(hr , m , finishtime - m*60 , 0 );
		ret += dt.formatDate("g:i A");
		return ret;	
	}
	this.DurationString = function()
	{
		if( this.DurationSec == 0 )
			return "0h, 0m";
		var hours = Math.floor(( this.DurationSec / 3600));
		var minutes = Math.floor(( this.DurationSec % 3600) / 60);
		var seconds = this.DurationSec % 60;
		var ret = "";
		var sep = "";
		if( hours > 1 )
		{
			ret = ret + hours + " hours" ;
			sep = ", ";
		}
		else if( hours == 1 )
		{
			ret = ret + "1 hour";
			sep = ", ";
		}
		if( minutes > 1 )
		{
			ret = ret + sep + minutes + " minutes";
			sep = ", ";
		}
		else if( minutes == 1 )
		{
			ret = ret + sep + "1 minute";
			sep = ", ";
		}
		if( seconds > 1 )
		{
			ret = ret + sep + seconds + " seconds";
		}
		else if( seconds == 1 )
		{
			ret = ret + sep + "1 second";
		}
		return ret;
	}
	this.IsHiDef = function()
	{
		return this.Station.IsHiDef;
	}
	
	return this;
}

ListeningOption.prototype.CurrentStartTime=function()
{
	if( this.StartTimeMinutes() == 0 ) {
		return this.StartTimeHours() + this.StartTimeAmPm().toLowerCase();
	} else {
		return this.StartTimeHours() + ":" + this.StartTimeMinutes() + this.StartTimeAmPm().toLowerCase();
	}
}

ListeningOption.prototype.StartTimeHours=function()
{
	var hours = Math.floor( this.StartTime / 3600 );
	hours = hours % 12;
	if( hours == 0 )
		hours = 12;
	return hours;
}
ListeningOption.prototype.StartTimeMinutes=function()
{
	return Math.floor( (this.StartTime % 3600) / 60 );
}
ListeningOption.prototype.StartTimeSeconds=function()
{
	return Math.floor( this.StartTime % 60 );
}
ListeningOption.prototype.StartTimeAmPm=function()
{
	var hours = Math.floor( this.StartTime / 3600 );
	return hours > 11 ? "PM" : "AM";
}
ListeningOption.prototype.SetStartTimeHours=function(h)
{
	h = h % 12;
	startHours = this.StartTimeHours()%12;
	this.DurationSec -= (h - startHours)*3600;
	this.NormalizeDuration();
	this.StartTime += (h - this.StartTimeHours())*3600;
}
ListeningOption.prototype.SetStartTimeMinutes=function(m)
{
	this.DurationSec -= (m-this.StartTimeMinutes())*60;
	this.NormalizeDuration();
	this.StartTime = Math.floor( this.StartTime / 3600 ) * 3600 + m*60 + this.StartTime % 60;
}
ListeningOption.prototype.SetStartTimeAmPm=function(ampm)
{
	if( this.StartTime >= 43200 && ampm == "AM" )
	{
		this.StartTime -= 43200;
		this.DurationSec += 43200;
	}
	else if( this.StartTime < 43200 && ampm == "PM" )
	{
		this.StartTime += 43200;
		this.DurationSec -= 43200;
	}
	this.NormalizeDuration();
}
ListeningOption.prototype.SetDuration=function(sec)
{
	if( sec > 0 )
	{
		this.DurationSec = ( sec % 86400);
	}
}
ListeningOption.prototype.SetSplittedDuration=function(new_hr,new_min)
{
	var hr = Math.floor( this.DurationSec / 3600 );
	var mn = Math.floor( ( this.DurationSec % 3600 ) / 60 );
	if(new_hr!=null && new_hr >= 0 && new_hr < 24)
	{
		hr = new_hr;
	}
	if(new_min!=null && new_min >= 0 && new_min < 60 )
	{
		mn = new_min;
	}
	this.DurationSec = hr*3600 + mn*60;
}
ListeningOption.prototype.SetStopTimeHours=function(h)
{
	h = h % 12;
	stopHours = this.StopTimeHours()%12;
	this.DurationSec+=(h-stopHours)*3600;
	this.NormalizeDuration();
}
ListeningOption.prototype.SetStopTimeMinutes=function(m)
{
	this.DurationSec+=(m-this.StopTimeMinutes())*60;
	this.NormalizeDuration();
}
ListeningOption.prototype.SetStopTimeAmPm=function(ampm)
{
	if( (this.StartTime+this.DurationSec) >= 43200 && ampm == "AM" )
	{
		this.DurationSec -= 43200;
	}
	else if( (this.StartTime+this.DurationSec) && ampm == "PM" )
	{
		this.DurationSec += 43200;
	}
	this.NormalizeDuration();
}
ListeningOption.prototype.NormalizeDuration=function()
{
	if( this.DurationSec > 86400 )
		this.DurationSec %= 86400;
	else if( this.DurationSec < 0 )
		this.DurationSec += 86400;
}
ListeningOption.prototype.StopTimeHours=function()
{
	var hours = Math.floor( (this.DurationSec + this.StartTime ) / 3600 );
	hours = hours % 12;
	if( hours == 0 )
		hours = 12;
	return hours;
}
ListeningOption.prototype.StopTimeMinutes=function()
{
	return Math.floor( ((this.StartTime + this.DurationSec)% 3600) / 60 );
}
ListeningOption.prototype.StopTimeSeconds=function()
{
	return Math.floor( (this.StartTime + this.DurationSec) % 60 );
}
ListeningOption.prototype.StopTimeAmPm=function()
{
	var hours = Math.floor( (this.StartTime + this.DurationSec) / 3600 );
	hours = hours % 24;
	return hours > 11 ? "PM" : "AM";
}


function PlayLocal( frequency, stationName, slogan, band )
{
	this.Frequency = frequency;
	this.StationName = stationName;
	this.Slogan = slogan;
	this.Band = band;
}

function RecordingSchedule( id, listeningOption, sourceSelectionType, isRecurring, recurrence, dateYear, dateMonth, dateDay )
{
	this.Id = id;
	this.ListeningOption = listeningOption;
	this.SourceSelectionType = sourceSelectionType;
	this.IsRecurring = isRecurring;
	this.Recurrence = recurrence;
	this.Date = new Date();
	this.Date.setFullYear( dateYear, dateMonth - 1, dateDay );
	
	return this;
}

RecordingSchedule.prototype.StartDate=function()
{
	var d = new Date(this.Date);
	var seconds = this.ListeningOption.StartTime;
	var hours = seconds / 3600;
	var minutes = (seconds % 3600 ) / 60;
	var seconds = seconds % 60;
	d.setHours( hours );
	d.setMinutes( minutes );
	d.setSeconds( seconds );
	return d;
}

RecordingSchedule.prototype.Hours=function()
{
	return this.ListenintOption.Duration
}


var Recurrence = function(recurMask)
{	
	this.RecurMask = recurMask;
	return this;
}
Recurrence.prototype.RecursSunday = function()
{
	return this.RecurMask & 64 ? true : false;
}
Recurrence.prototype.RecursMonday = function()
{
	return this.RecurMask & 1 ? true : false;
}
Recurrence.prototype.RecursTuesday = function()
{
	return this.RecurMask & 2 ? true : false;
}
Recurrence.prototype.RecursWednesday = function()
{
	return this.RecurMask & 4 ? true : false;
}
Recurrence.prototype.RecursThursday = function()
{
	return this.RecurMask & 8 ? true : false;
}
Recurrence.prototype.RecursFriday = function()
{
	return this.RecurMask & 16 ? true : false;
}
Recurrence.prototype.RecursSaturday = function()
{
	return this.RecurMask & 32 ? true : false;
}

Recurrence.prototype.Render=function()
{
	var ret = "";
	
	if( this.RecurMask == 7 )
		ret = "Mon-Wed";
	else if( this.RecurMask == 14 )
		ret = "Tue-Thu";
	else if( this.RecurMask == 15 )
		ret = "Mon-Thu";
	else if( this.RecurMask == 28 )
		ret = "Wed-Fri";
	else if( this.RecurMask == 30 )
		ret = "Tue-Fri";
	else if( this.RecurMask == 31 )
		ret = "Mon-Fri";
	else if( this.RecurMask == 56 )
		ret = "Thu-Sat";
	else if( this.RecurMask == 60 )
		ret = "Wed-Sat";
	else if( this.RecurMask == 62 )
		ret = "Tue-Sat";
	else if( this.RecurMask == 63 )
		ret = "Mon-Sat";
	else if( this.RecurMask == 112 )
		ret = "Fri-Sun";
	else if( this.RecurMask == 120 )
		ret = "Thu-Sun";
	else if( this.RecurMask == 124 )
		ret = "Wed-Sun";
	else if( this.RecurMask == 126 )
		ret = "Tue-Sun";
	else if( this.RecurMask == 127 )
		ret = "Mon-Sun";
	else
	{
		for( i = 0; i < 7; i++ )
		{
			var mask = 1 << i;
			if( ( this.RecurMask & mask ) > 0 )
			{
				if( ret.length > 0 )
					ret += ",";
				ret += getDay(i);
			}
		}
	}
	return ret;
}
var getDay=function(i)
{
	var ret = "";
	switch( i )
	{
		case 0:
			ret = "Mon";
			break;
		case 1:
			ret = "Tue";
			break;
		case 2:
			ret = "Wed";
			break;
		case 3:
			ret = "Thu";
			break;
		case 4:
			ret = "Fri";
			break;
		case 5:
			ret = "Sat";
			break;
		case 6:
			ret = "Sun";
			break;
	}
	return ret;
}
-->