var data = new Array();
data.push({country:"UnitedStates", carrier:"Alltel", product:"Alltel Radio", channels:[1,0,1,1,1,0,0,0,0,1,0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,0,1,0,1,0,0,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0]});

data.push({country:"UnitedStates", carrier:"Alltel", product:"XM Radio Mobile", channels:[0,1,0,0,0,0,1,0,0,0,1,0,0,1,0,0,0,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1]});

data.push({country:"UnitedStates", carrier:"nTelos", product:"MobiRadio", channels:[1,0,1,1,1,0,0,0,0,1,0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,0,1,0,1,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0]});

data.push({country:"UnitedStates", carrier:"Cellular South", product:"MobiRadio", channels:[1,0,1,1,1,0,0,0,0,1,0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,0,0,0,0,1,1,0,1,0,1,0,0,1,1,0,0,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,0,0,1,1,0,0,0,0,0]});

data.push({country:"UnitedStates", carrier:"AT&T", product:"MobiRadio", channels:[1,0,1,1,1,1,0,0,1,0,0,1,1,0,1,1,0,0,1,1,1,1,1,1,1,1,0,0,0,1,1,0,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,0,0,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0]});

data.push({country:"UnitedStates", carrier:"AT&T", product:"XM Radio Mobile", channels:[0,1,0,0,0,0,1,0,0,0,1,0,0,1,0,0,1,1,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,1,0,1,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,1,1,1,1,1,1,0,0,1,1,0,0,0,0,0,0,0,0,1,0,0,0,0,1,1,0]});

data.push({country:"Canada", carrier:"Not Available", product:"Not Available", channels:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]});
data.push({country:"Mexico", carrier:"Not Available", product:"Not Available", channels:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]});
data.push({country:"Ecuador", carrier:"Not Available", product:"Not Available", channels:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]});
data.push({country:"Brazil", carrier:"Not Available", product:"Not Available", channels:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]});
data.push({country:"Nicaragua", carrier:"Not Available", product:"Not Available", channels:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]});
data.push({country:"Peru", carrier:"Not Available", product:"Not Available", channels:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]});
data.push({country:"Dominican", carrier:"Not Available", product:"Not Available", channels:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]});

// radio stations
var channels = new Array();
channels.push("Comedy Time");
channels.push("The Pulse");
channels.push("70s");
channels.push("80s");
channels.push("90s");
channels.push("Adult Alternative - MA");
channels.push("POP2K");
channels.push("Air America");
channels.push("Alternative - MA");
channels.push("Rap");
channels.push("Classic Vinyl");
channels.push("Album Rock");
channels.push("Tunes for Tots");
channels.push("Alt Nation");
channels.push("Symphonic");
channels.push("Blues");
channels.push("B.B. King's Bluesville");
channels.push("BPM");
channels.push("Traditional Country ");
channels.push("Classic R&B");
channels.push("Classic Rock");
channels.push("Hot Jamz");
channels.push("Contemporary Christian");
channels.push("Dance");
channels.push("Urban Beat");
channels.push("Roadhouse");
channels.push("Classic Rewind");
channels.push("The Coffee House");
channels.push("Florida Gators");
channels.push("FOX News");
channels.push("FOX News Talk");
channels.push("Fuego-gone");
channels.push("Gospel");
channels.push("The Highway");
channels.push("Hottest Hits");
channels.push("The Joint");
channels.push("Flashback New Wave");
channels.push("Jazz");
channels.push("Light Classical");
channels.push("Lithium");
channels.push("Chart Toppers");
channels.push("Subterranean");
channels.push("National Stormwatch");
channels.push("NPR");
channels.push("Hit Country");
channels.push("New Age");
channels.push("Tranquility");
channels.push("Hurbano");
channels.push("R&B Hits");
channels.push("Radio Disney");
channels.push("Rap - MA");
channels.push("Real Jazz");
channels.push("Reggae");
channels.push("Latin Hits");
channels.push("Coffeehouse Rock");
channels.push("Rock En Espanol");
channels.push("Salsa");
channels.push("Holidays & Happenings");
channels.push("Rock en Espanol");
channels.push("Salsa");
channels.push("Singers & Standards-gone");
channels.push("Smooth Jazz");
channels.push("Smooth R&B-gone");
channels.push("Soft Hits");
channels.push("Golden Oldies");
channels.push("Soul Town");
channels.push("Soundscapes-gone");
channels.push("Heart &amp; Soul");
channels.push("The 70s");
channels.push("The 80s");
channels.push("The 90s");
channels.push("The Blend");
channels.push("The Roadhouse");
channels.push("The Heat");
channels.push("The Loft-xm gone");
channels.push("Modern Country");
channels.push("Top 20 on 20");
channels.push("Prime Country");
channels.push("TWC NE");
channels.push("TWC NW");
channels.push("TWC SE  ");
channels.push("TWC SW");
channels.push("US Country-xm gone");
channels.push("Viva-xm gone");
channels.push("Watercolors");
channels.push("XM Caf&eacute;-xm gone");
channels.push("SiriusXMU");
channels.push("Alternative");
channels.push("Alternative-MA");
channels.push("Outlaw Country");
channels.push("Area");
channels.push("The Groove");
channels.push("Caliente");
channels.push("SiriusXM Love");




//document.writeln( channels["Bravo's Flipping Out"] );
// country defined in containing file
//var country = "United States";

function dataByCountry(c)
{
	var a = new Array();
	
	for ( var i=0; i<data.length; ++i )
	{
		if ( data[i].country == c )
		{
			a.push(data[i]);
		}
	}
	return a;
}

// helper to append items to an option list
function appendOption( option, data )
{
	option.options.length += 1;
	option.options[option.options.length-1].value = data;
	option.options[option.options.length-1].text = data;
}

function initData()
{
	var dataSet = dataByCountry(country);
	
	var products = new Array();
	var cs = document.forms['theForm'].carrier;
	// only add unique items to the list
	var ulist = [];
	// is this item already in the list
	var uf = function(key)
	{
		var exists = false;
		
		if ( ulist[key] )
		{
			exists = true;
		}
		else
		{
			ulist[key] = true;						
		}

		return exists;
	};
					
	cs.options.length = 0;
	
	// fill out the carrier select box
	for (var i = 0; i < dataSet.length; ++i) 
	{
		if (!uf(dataSet[i].carrier)) 
		{
			appendOption(cs, dataSet[i].carrier);
		}
	}
	
	var carrier = cs.options[0].value;
	cs = document.forms['theForm'].product;
	cs.options.length = 0;

	// fill out the products box
	for ( var i=0; i<dataSet.length; ++i )				
	{
		if ( dataSet[i].carrier == carrier )
		{
			appendOption(cs, dataSet[i].product);
		}
	}
	
	getChannels();
}

function getProducts(who)
{
	var dataSet = dataByCountry(country);
	var carrier = document.forms['theForm'].carrier.options[document.forms['theForm'].carrier.selectedIndex].value;
	
	var cs = document.forms['theForm'].product;
	cs.options.length = 0;
	
	// fill out the products box
	for ( var i=0; i<dataSet.length; ++i )				
	{
		if ( dataSet[i].carrier == carrier )
		{
			appendOption(cs, dataSet[i].product);
		}
	}
	
	getChannels();
}

function getChannels(who)
{
	//alert(who.options[who.selectedIndex].value);
	var dataSet = dataByCountry(country);
	var carrier = document.forms['theForm'].carrier.options[document.forms['theForm'].carrier.selectedIndex].value;
	var product = document.forms['theForm'].product.options[document.forms['theForm'].product.selectedIndex].value;
					
	for ( var i=0; i<dataSet.length; ++i )
	{
		if ( dataSet[i].carrier == carrier && dataSet[i].product == product )
		{
			//alert("channels: " + dataSet[i].channels);
			displayChannels(dataSet[i].channels);
		}
	}
}

function displayChannels(list)
{
	var output = document.getElementById("output");
	output.innerHTML = "";
	
	//alert(list.length == channels.length);
	for (var i=0; i<list.length; ++i)
	{
		if ( list[i] == 1 )
		{
			output.innerHTML += " <span class=channel>" + channels[i] + "</span> | ";
		}
	}
}

if (window.addEventListener) //DOM method for binding an event
{
	window.addEventListener("load", initData, false)
}
else if (window.attachEvent) //IE exclusive method for binding an event
{
	window.attachEvent("onload", initData)
}
else if (document.getElementById) //support older modern browsers
{
	window.onload = initData;
}