function addOptionList( selectBox, idList, nameList )
{
	for( var i = 0; i < idList.length; i++ )
	{
		addOption( selectBox, nameList[ i ], idList[ i ] );
	}
}

function adFormSetRegion( id )
{
	var box = document.adForm.region;

	for( i = 0; i < box.length; i++ )
	{
		if( box.options[ i ].value == id ) box.options[ i ].selected = true;
	}
}

function adFormSetMunicipality( id )
{
	var box = document.adForm.municipality;

	for( i = 0; i < box.length; i++ )
	{
		if( box.options[ i ].value == id ) box.options[ i ].selected = true;
	}
}

function adFormRegionBoxEvent( id )
{
	var box = document.adForm.municipality;

	removeAllOptions( box );

	if( Number( id ) < 100 )
	{
		addOption( box, mpAdNoMunChosen, 0 );

		switch( id )
		{
			case "1":
				addOptionList( box, stockholm_1_id, stockholm_1_name );
				break;

			case "3":
				addOptionList( box, uppsala_3_id, uppsala_3_name );
				break;

			case "4":
				addOptionList( box, sodermanland_4_id, sodermanland_4_name );
				break;

			case "5":
				addOptionList( box, ostergotland_5_id, ostergotland_5_name );
				break;

			case "6":
				addOptionList( box, jonkoping_6_id, jonkoping_6_name );
				break;

			case "7":
				addOptionList( box, kronoberg_7_id, kronoberg_7_name );
				break;

			case "8":
				addOptionList( box, kalmar_8_id, kalmar_8_name );
				break;

			case "9":
				addOptionList( box, gotland_9_id, gotland_9_name );
				break;

			case "10":
				addOptionList( box, blekinge_10_id, blekinge_10_name );
				break;

			case "12":
				addOptionList( box, skane_12_id, skane_12_name );
				break;

			case "13":
				addOptionList( box, halland_13_id, halland_13_name );
				break;

			case "14":
				addOptionList( box, vastra_gotaland_14_id, vastra_gotaland_14_name );
				break;

			case "17":
				addOptionList( box, varmland_17_id, varmland_17_name );
				break;

			case "18":
				addOptionList( box, orebro_18_id, orebro_18_name );
				break;

			case "19":
				addOptionList( box, vastmanland_19_id, vastmanland_19_name );
				break;

			case "20":
				addOptionList( box, dalarna_20_id, dalarna_20_name );
				break;

			case "21":
				addOptionList( box, gavleborg_21_id, gavleborg_21_name );
				break;

			case "22":
				addOptionList( box, vasternorrland_22_id, vasternorrland_22_name );
				break;

			case "23":
				addOptionList( box, jamtland_23_id, jamtland_23_name );
				break;

			case "24":
				addOptionList( box, vasterbotten_24_id, vasterbotten_24_name );
				break;

			case "25":
				addOptionList( box, norrbotten_25_id, norrbotten_25_name );
				break;

			default:
				removeAllOptions( box );
				addOption( box, mpAdChooseRegFirst, 0 );
				break;
		}
	}
	else
	{
		addOption( box, mpAdNoMunAvail, 0 );
	}
}

function adFormSetMainCategory( id )
{
	var box = document.adForm.cat;

//	alert(box.length);

	for( i = 0; i < box.length; i++ )
	{
		if( box.options[ i ].value == id ) box.options[ i ].selected = true;
	}
}

function adFormSetSubCategory( id )
{
	var box = document.adForm.sub;

	for( i = 0; i < box.length; i++ )
	{
		if( box.options[ i ].value == id ) box.options[ i ].selected = true;
	}
}

subCategoryIDs = new Array(); // fylls på från page.c
subCategoryNames = new Array();

function adFormCategoryBoxEvent( id )
{
	var box = document.adForm.sub;
	removeAllOptions( box );

	id = Number( id );
	var ids = subCategoryIDs[ id ];
	var names = subCategoryNames[ id ];

	if( ids && names )
	{
		addOption( box, mpAdNoSubChosen, 0 );
		addOptionList( box, ids, names );
	}
	else
	{
		addOption( box, mpAdChooseCatFirst, 0 );
	}
}
