function ShowAreas()
{

	HideAll();
	var objTd;
	var objCbx;
	for(i=0 ;i<document.aspnetForm.sltCounty.length ;i++)
	{
		if(document.aspnetForm.sltCounty.options[i].selected==true)
		{
			if(document.aspnetForm.sltCounty.options[i].value == -1)
			{
				ShowAll();
			}
			else if(document.aspnetForm.sltCounty.options[i].value == 0)
			{
				//Do nothing...
			}
			else
			{
				objTd = document.getElementById("td"+document.aspnetForm.sltCounty.options[i].value);
				objTd.style.display="";
				//Gotland doesn't have a Show-all-boroughs, so if Gotland is chosen, 
				//we check Gotland and not Show-all-boroughs.
				if(document.aspnetForm.sltCounty.options[i].value == "09")
				{
					document.aspnetForm.cbxB0980.checked = true;
				}
				else
				{
					objCbx = document.getElementById("cbxB70" + document.aspnetForm.sltCounty.options[i].value);
					objCbx.checked = true;
				}
			}
		}
	}
}

function HideAll()
{
	var objTr = document.getElementById("td0");
	if(objTr != null) objTr.style.display="None";
	for(i=0 ;i<document.aspnetForm.sltCounty.length ;i++)
	{
		objTr = document.getElementById("td"+document.aspnetForm.sltCounty.options[i].value);
		if(objTr != null) objTr.style.display="None";
	}
}

function ShowAll()
{
	var objTr = document.getElementById("td0");
	if(objTr != null) objTr.style.display="";
	for(i=0 ;i<document.aspnetForm.sltCounty.length ;i++)
	{
		objTr = document.getElementById("td"+document.aspnetForm.sltCounty.options[i].value);
		if(objTr != null) objTr.style.display="";
	}
}

function ToggleSubTable(objCbx)
{
	var objTbl = document.getElementById("tbl" + objCbx.id.substring(4,8));
	if(objCbx.checked)	
		objTbl.style.display = "";
	else
		objTbl.style.display = "None";
	ClearMultiBoroughs();
}

function ClearSingleBoroughs(objCbxClicked)
{
	var aInputs = document.body.getElementsByTagName("input");
	var objCbx;
	for(idx = 0; idx < aInputs.length; idx++)
	{
		objCbx = aInputs[idx];
		if(objCbx.id.substring(0,4)=="cbxB")
		{
			objCbx.checked = false;
		}
	}
	//Hide table Stockholm
	document.getElementById("tbl0180").style.display = "None";
	//Hide table Göteborg
	document.getElementById("tbl1480").style.display = "None";
	//Hide table Malmö
	document.getElementById("tbl1280").style.display = "None";
	if(objCbxClicked!=null) objCbxClicked.checked = true;
}

function ClearMultiBoroughs()
{
	document.aspnetForm.cbxB7001.checked = false;
	document.aspnetForm.cbxB7012.checked = false;
	document.aspnetForm.cbxB7014.checked = false;
	document.aspnetForm.cbxB7010.checked = false;
	document.aspnetForm.cbxB7020.checked = false;
	document.aspnetForm.cbxB7021.checked = false;
	document.aspnetForm.cbxB7013.checked = false;
	document.aspnetForm.cbxB7023.checked = false;
	document.aspnetForm.cbxB7006.checked = false;
	document.aspnetForm.cbxB7008.checked = false;
	document.aspnetForm.cbxB7007.checked = false;
	document.aspnetForm.cbxB7025.checked = false;
	document.aspnetForm.cbxB7004.checked = false;
	document.aspnetForm.cbxB7003.checked = false;
	document.aspnetForm.cbxB7017.checked = false;
	document.aspnetForm.cbxB7024.checked = false;
	document.aspnetForm.cbxB7022.checked = false;
	document.aspnetForm.cbxB7019.checked = false;
	document.aspnetForm.cbxB7018.checked = false;
	document.aspnetForm.cbxB7005.checked = false;
}

function GetBoroughs(txtAreasID)
{
    var txtAreas = document.getElementById(txtAreasID);
	txtAreas.value = "";
	var aInputs = document.body.getElementsByTagName("input");
	var objCbx;
	var cbxID;
	var tempB="";
	var CheckNext = false;
	
	for(idx = 0; idx < aInputs.length; idx++)
	{
		objCbx = aInputs[idx];
		if((objCbx.id.substring(0,4)=="cbxB")&&(objCbx.checked)) 
		{
			//If id ends with 80 it's the largest borough in the county and there may be a sub-borough checked. 
			//In that case we won't be sending the borough id on.
			if(objCbx.id.substring(6,8)=="80")
			{
				tempB += objCbx.id.substring(4);
				CheckNext = true;
			}
			else
			{
				//if we CheckNext it's because the previous borough was a capital-borough.
				if(CheckNext)
				{
					//if this borough is a sub-borough we're not sending the capital on.
					if(objCbx.id.substring(0,5)=="cbxB7")
					{
						txtAreas.value += objCbx.id.substring(4);
						tempB="";
					}
					else
					{
						txtAreas.value += objCbx.id.substring(4);
					}
					CheckNext = false;
				}
				else
				{
					txtAreas.value += objCbx.id.substring(4);
				}
			}
		}
	}
    
	txtAreas.value = tempB + txtAreas.value;	
}

function SetBoroughs(Areas)
{

	if(Areas != "")
	{
		//Here we set which county is chosen
		switch(Areas.substring(0,2))
		{
			//all-boroughs in one county is checked, then position 2-4
			//show which county
			case("70"):
			{
				document.aspnetForm.sltCounty.value = Areas.substring(2,4);
				break;
			}
			//one of the sub-buroughs of Stockholm is checked
			case("71"):
			{
				document.aspnetForm.sltCounty.value = "01";
				document.aspnetForm.cbxB0180.checked = true;
				document.getElementById('tbl0180').style.display = "";
				break;
			}
			//one of the sub-buroughs of Göteborg is checked
			case("72"):
			{
				document.aspnetForm.sltCounty.value = "14";
				document.aspnetForm.cbxB1480.checked = true;
				document.getElementById('tbl1480').style.display = "";
				break;
			}
			//one of the sub-buroughs of Malmö is checked
			case("73"):
			{
				document.aspnetForm.sltCounty.value = "12";
				document.aspnetForm.cbxB1280.checked = true;
				document.getElementById('tbl1280').style.display = "";
				break;
			}
			default:
			{
				//Stockholm, Göteborg or Malmö is checked
				switch(Areas.substring(0,4))
				{
					case("0180"):
					    document.getElementById('tbl0180').style.display = "";
					    break;
					case("1280"):
					    document.getElementById('tbl1280').style.display = "";
					    break;
					case("1480"):
					    document.getElementById('tbl1480').style.display = "";
					    break;
				}
				document.aspnetForm.sltCounty.value = Areas.substring(0,2);
			}
		}
	}
	ShowAreas();
	ClearMultiBoroughs();

	var cbxName = "";
	var objCbx = null;
	//Check the checkboxes to be checked...
	for(idx = 0; idx < Areas.length/4; idx++)
	{
		objCbx = document.getElementById("cbxB" + Areas.substring(idx*4,(idx*4)+4));
		objCbx.checked = true;
	}

}




