var not_selected_marker = "";
var all_marker = "*";
var platform     = new Object();
var manufacturer = new Object();

platform["*"]     =   [{value:"Android OS", text:"Android OS"},
 					  {value:"BlackBerry", text:"BlackBerry"},
					  {value:"iPhone OS", text:"iPhone OS"},
					  {value:"Palm OS", text:"Palm OS"},
 					  {value:"Palm Web OS", text:"Palm Web OS"},
					  {value:"Symbian S60", text:"Symbian S60"},
					  {value:"Symbian UIQ", text:"Symbian UIQ"},
					  {value:"Windows Mobile Professional", text:"Windows Mobile Professional"},
					  {value:"Windows Mobile Standard", text:"Windows Mobile Standard"}];
platform["Nokia"]       =   [{value:"Symbian S60", text:"Symbian S60"}];
platform["Samsung"]     =   [{value:"Android OS", text:"Android OS"},
							{value:"Symbian S60", text:"Symbian S60"},
                            {value:"Windows Mobile Professional", text:"Windows Mobile Professional"},
                            {value:"Windows Mobile Standard", text:"Windows Mobile Standard"}];
platform["SonyEricsson"] = [{value:"Symbian UIQ", text:"Symbian UIQ"},
                            {value:"Windows Mobile Professional", text:"Windows Mobile Professional"}];
platform["Motorola"] = [{value:"Symbian UIQ", text:"Symbian UIQ"},
                            {value:"Windows Mobile Standard", text:"Windows Mobile Standard"}];
platform["HTC"]         =   [{value:"Android OS", text:"Android OS"},
							{value:"Windows Mobile Professional", text:"Windows Mobile Professional"},
                            {value:"Windows Mobile Standard", text:"Windows Mobile Standard"}];
platform["Palm"]        =   [{value:"Palm OS", text:"Palm OS"},
 					  		{value:"Palm Web OS", text:"Palm Web OS"},
                            {value:"Windows Mobile Professional", text:"Windows Mobile Professional"},
                            {value:"Windows Mobile Standard", text:"Windows Mobile Standard"}];
platform["BlackBerry"]         =   [{value:"BlackBerry", text:"BlackBerry"}];
platform["Apple"]       =   [{value:"iPhone OS", text:"iPhone OS"}];
platform["Asus"]        =   [{value:"Windows Mobile Professional", text:"Windows Mobile Professional"},
                            {value:"Windows Mobile Standard", text:"Windows Mobile Standard"}];
platform["HP"]          =   [{value:"Windows Mobile Professional", text:"Windows Mobile Professional"},
                            {value:"Windows Mobile Standard", text:"Windows Mobile Standard"}];
platform["Pantech"]     =   [{value:"Windows Mobile Standard", text:"Windows Mobile Standard"}];
platform["Toshiba"]     =   [{value:"Windows Mobile Standard", text:"Windows Mobile Standard"}];
platform["BenQ"]        =   [{value:"Windows Mobile Standard", text:"Windows Mobile Standard"}];

platform["LG"]     =   [{value:"Symbian S60", text:"Symbian S60"},
                            {value:"Windows Mobile Professional", text:"Windows Mobile Professional"},
                            {value:"Windows Mobile Standard", text:"Windows Mobile Standard"}];
platform["I-mate"]     =   [{value:"Windows Mobile Professional", text:"Windows Mobile Professional"},
                            {value:"Windows Mobile Standard", text:"Windows Mobile Standard"}];
platform["Eten"]     =   [{value:"Windows Mobile Professional", text:"Windows Mobile Professional"}];
platform["Other"]         =   [{value:"Android OS", text:"Android OS"},
							   {value:"Palm OS", text:"Palm OS"},
							   {value:"Symbian S60", text:"Symbian S60"},
							   {value:"Symbian UIQ", text:"Symbian UIQ"},
                            {value:"Windows Mobile Professional", text:"Windows Mobile Professional"},
                            {value:"Windows Mobile Standard", text:"Windows Mobile Standard"}];

manufacturer["*"] =   [{value:"Nokia", text:"Nokia"},
					   {value:"Samsung", text:"Samsung"},
					   {value:"SonyEricsson", text:"Sony Ericsson"},
					   {value:"Motorola", text:"Motorola"},
					   {value:"HTC", text:"HTC"},
					   {value:"Palm", text:"Palm"},
					   {value:"BlackBerry", text:"BlackBerry"},
					   {value:"Apple", text:"Apple"},
					   {value:"Asus", text:"Asus"},
					   {value:"HP", text:"HP"},
					   {value:"Pantech", text:"Pantech"},
					   {value:"Toshiba", text:"Toshiba"},
					   {value:"BenQ", text:"BenQ"},
					   {value:"LG", text:"LG"},
					   {value:"I-mate", text:"I-mate"},
					   {value:"Eten", text:"Eten"},
					   {value:"Other", text:"Other"}];
manufacturer["Symbian S60"] =   [{value:"Nokia", text:"Nokia"},
								 {value:"LG", text:"LG"},
                                {value:"Samsung", text:"Samsung"},
								{value:"Other", text:"Other"}];
manufacturer["Symbian UIQ"] =   [{value:"SonyEricsson", text:"Sony Ericsson"},
                                {value:"Motorola", text:"Motorola"},
								{value:"Other", text:"Other"}];
manufacturer["Windows Mobile Professional"] =   [{value:"HTC", text:"HTC"},
                                                {value:"Palm", text:"Palm"},
                                                {value:"Samsung", text:"Samsung"},
                                                {value:"SonyEricsson", text:"Sony Ericsson"},
                                                {value:"HP", text:"HP"},
                                                {value:"Asus", text:"Asus"},
                                                {value:"Toshiba", text:"Toshiba"},
                                                {value:"LG", text:"LG"},
												{value:"I-mate", text:"I-mate"},
												{value:"Eten", text:"Eten"},
												{value:"Other", text:"Other"}];
manufacturer["Windows Mobile Standard"]     =   [{value:"Samsung", text:"Samsung"},
                                                {value:"HTC", text:"HTC"},
                                                {value:"Motorola", text:"Motorola"},
                                                {value:"HP", text:"HP"},
                                                {value:"Pantech", text:"Pantech"},
                                                {value:"Toshiba", text:"Toshiba"},
                                                {value:"BenQ", text:"BenQ"},
                                                {value:"Asus", text:"Asus"},
												{value:"LG", text:"LG"},
												{value:"I-mate", text:"I-mate"},
												{value:"Other", text:"Other"}];
manufacturer["Palm OS"]        =   [{value:"Palm", text:"Palm"},
									{value:"Other", text:"Other"}];
manufacturer["Palm Web OS"]        =   [{value:"Palm", text:"Palm"},
									{value:"Other", text:"Other"}];

manufacturer["BlackBerry"]     =   [{value:"BlackBerry", text:"BlackBerry"}];
manufacturer["iPhone OS"]         =   [{value:"Apple", text:"Apple"}];
manufacturer["Android OS"]        =   [{value:"HTC", text:"HTC"},
									   {value:"Samsung", text:"Samsung"},
									{value:"Other", text:"Other"}];

function refreshListsOnManufacturerChange() {
    var chooser = document.getElementById("manufacturer_a");
    var choice = chooser.options[chooser.selectedIndex].value;
    if ( choice == "" )	{
		return;
	}
    var osChooser = document.getElementById("platform_a");
    var lastOs = osChooser.options[osChooser.selectedIndex].value;
    osChooser.options.length = 0;
	if ( choice == "*" ) {
		var manufacturerDb = manufacturer["*"];
		chooser.options[0] = new Option("-- Manufacturer --", "", true, false);
		for (var i = 0; i < manufacturerDb.length; i++) {
			chooser.options[i + 1] = new Option(manufacturerDb[i].text, manufacturerDb[i].value);
		}
	}
	var platformDb = platform[choice];
	var indexOffset = 1;
	osChooser.options[0] = new Option("-- Platform --", "", true, false);
	if ( choice != "*" )	{
		osChooser.options[indexOffset] = new Option("-- All Platforms --", "*", false, false);
		indexOffset++;
	}
	for (var i = 0; i < platformDb.length; i++) {
		var selected = false;
		if ( lastOs == platformDb[i].value ){
			selected = true;
		}
		osChooser.options[i + indexOffset] = new Option(platformDb[i].text, platformDb[i].value, false, selected);
	}
}

function refreshListsOnPlatformChange() {
    var chooser = document.getElementById("platform_a");
    var choice = chooser.options[chooser.selectedIndex].value;
    if ( choice == "" )	{
		return;
	}
    var manufacturerChooser = document.getElementById("manufacturer_a");
    var lastManufacturer = manufacturerChooser.options[manufacturerChooser.selectedIndex].value;
    manufacturerChooser.options.length = 0;
	if ( choice == "*" ) {
	    var platformDb = platform["*"];
		chooser.options[0] = new Option("-- Platform --", "", true, false);
		for (var i = 0; i < platformDb.length; i++) {
			chooser.options[i + 1] = new Option(platformDb[i].text, platformDb[i].value);
		}
	}
	var manufacturerDb = manufacturer[choice];
	var indexOffset = 1;
    manufacturerChooser.options[0] = new Option("-- Manufacturer --", "", true, false);
	if ( choice != "*" )	{
		manufacturerChooser.options[indexOffset] = new Option("-- All Manufacturers --", "*", false, false);
		indexOffset++;
	}
	for (var i = 0; i < manufacturerDb.length; i++) {
		var selected = false;
		if ( lastManufacturer == manufacturerDb[i].value ){
			selected = true;
		}
		manufacturerChooser.options[i + indexOffset] = new Option(manufacturerDb[i].text, manufacturerDb[i].value, false, selected);
	}
}

function resetLists( selectedManufacturer, selectedPlatform ) {
    var manufacturerChooser = document.getElementById("manufacturer_a");
    manufacturerChooser.options.length = 0;
    var platformChooser = document.getElementById("platform_a");
	platformChooser.options.length = 0;

	var manufacturerDb = manufacturer["*"];
    manufacturerChooser.options[0] = new Option("-- Manufacturer --", "", true, false);
	for (var i = 0; i < manufacturerDb.length; i++) {
		var selected = false;
		if ( selectedManufacturer == manufacturerDb[i].value ){
			selected = true;
		}
		manufacturerChooser.options[i + 1] = new Option(manufacturerDb[i].text, manufacturerDb[i].value, false, selected);
	}

	var platformDb = platform["*"];
	platformChooser.options[0] = new Option("-- Platform --", "", true, false);
	for (var i = 0; i < platformDb.length; i++) {
		var selected = false;
		if ( selectedPlatform == platformDb[i].value ){
			selected = true;
		}
		platformChooser.options[i + 1] = new Option(platformDb[i].text, platformDb[i].value, false, selected);
	}
}

