

function ShowAreasSublet()
{	
	HideAllSublet();
	var objTd;
	var objCbx;
	for(i=0 ;i<document.aspnetForm.sltCountySublet.length ;i++)
	{
		if(document.aspnetForm.sltCountySublet.options[i].selected==true)
		{
			if(document.aspnetForm.sltCountySublet.options[i].value == 0)
			{
				//Do nothing...
			}
			else
			{
				objTd = document.getElementById("tdS"+document.aspnetForm.sltCountySublet.options[i].value);
				objTd.style.display="";
			}
		}
	}
}

function HideAllSublet()
{
	for(i=0 ;i<document.aspnetForm.sltCountySublet.length ;i++)
	{
		objTr = document.getElementById("tdS"+document.aspnetForm.sltCountySublet.options[i].value);
		if(objTr != null) objTr.style.display="None";
	}
}

function ToggleSubTableSublet(objCbx)
{
	var objTbl = document.getElementById("tblS" + objCbx.id.substring(4,8));
	if(objCbx.checked)	
		objTbl.style.display = "";
	else
		objTbl.style.display = "None";
}

function ClearSingleBoroughsSublet(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)=="cbxS")
		{
			objCbx.checked = false;
		}
	}

	//Hide table Stockholm
	document.getElementById("tblS0180").style.display = "None";
	//Hide table Göteborg
	document.getElementById("tblS1480").style.display = "None";
	//Hide table Malmö
	document.getElementById("tblS1280").style.display = "None";
	if(objCbxClicked!=null) objCbxClicked.checked = true;

}

function GetBoroughsSublet(txtAreasID)
{
    var txtAreas = document.getElementById(txtAreasID);
    var oldValue = txtAreas.value;
	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)=="cbxS")&&(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)=="cbxS7")
					{
						txtAreas.value += objCbx.id.substring(4);
						tempB="";
					}
					else
					{
						txtAreas.value += objCbx.id.substring(4);
					}
					CheckNext = false;
				}
				else
				{
					txtAreas.value += objCbx.id.substring(4);
				}
			}
		}
	}
	var newValue = tempB + txtAreas.value;
	if(newValue == "")
	{
	    txtAreas.value = oldValue;
	}
	else
	{
	    txtAreas.value = tempB + txtAreas.value;
	}
}

function SetBoroughsSublet(Areas)
{
	//This row is to prohibit old zip code areas from screwing up the page...
	if(Areas.length%4!=0)Areas = "0180";

	if(Areas != "")
	{
		//Here we set which county is chosen
		switch(Areas.substring(0,2))
		{
			//one of the sub-buroughs of Stockholm is checked
			case("71"):
			{
				$('#sltCountySublet').val("01");				
				$('#cbxS0180').attr('checked', true);				
				$('#tblS0180').show();
				break;
			}
			//one of the sub-buroughs of Göteborg is checked
			case("72"):
			{
				$('#sltCountySublet').val("14");
				$('#cbxS1480').attr('checked', true);
				$('#tblS1480').show();
				break;
			}
			//one of the sub-buroughs of Malmö is checked
			case("73"):
			{
				$('#sltCountySublet').val("12");
				$('#cbxS1280').attr('checked', true);
				$('#tblS1280').show();
				break;
			}
			default:
			{
				//Stockholm, Göteborg or Malmö is checked
				switch(Areas.substring(0,4))
				{
					case("0180"):$('#tblS0180').show();break;
					case("1280"):$('#tblS1280').show();break;
					case("1480"):$('#tblS1480').show();break;
				}
				$('#sltCountySublet').val(Areas.substring(0,2));
			}
		}
	}
	ShowAreasSublet();

	var cbxName = "";
	var objCbx = null;
	//Check the checkboxes to be checked...
	for(idx = 0; idx < Areas.length/4; idx++)
	{
		objCbx = document.getElementById("cbxS" + Areas.substring(idx*4,(idx*4)+4));
		objCbx.checked = true;
	}
}



