var sRegion;
var sCounty;
var sLocation;

var arrCOUNTY;
var arrLOCATION;

function InitResidence(RegionID,CountyID,LocationID)
{
	arrCOUNTY=strCOUNTY.split('|');
	arrLOCATION=strLOCATION.split('|');
	sRegion=document.getElementById('selRegion');
	sCounty=document.getElementById('selCounty');
	sLocation=document.getElementById('selLocation');

	SelectChangeAll(RegionID,CountyID,LocationID);
}

function SelectCounty(RegionID)
{
	var j=1;
	sCounty.length=1;
	if (sLocation) sLocation.length=1;
	if(RegionID.length>0)
	{
		var sValue;
		for(var i=0; i<arrCOUNTY.length; i++)
		{
			sValue=arrCOUNTY[i].split(',');
			if(sValue[0]==RegionID)
				sCounty.options[j++]=new Option(sValue[2],sValue[1]);
		}
	}
	else
	{
		for(var i=0; i<arrCOUNTY.length; i++)
		{
			sValue=arrCOUNTY[i].split(',');
			sCounty.options[j++]=new Option(sValue[2],sValue[1]);
		}
		sCounty.selectedIndex=0;
		if (sLocation) sLocation.selectedIndex=0;
	}
}

function SelectLocation(CountyID)
{
	if (!sLocation) return;

	var j=1;
	sLocation.length=1;
	
	if(CountyID.length>0)
	{
		var sValue;
		var selValue;
		for(var i=0; i<arrLOCATION.length; i++)
		{
			sValue=arrLOCATION[i].split(',');
			if(sValue[1]==CountyID)
			{
				selValue=sValue[0];
				sLocation.options[j++]=new Option(sValue[3],sValue[2]);
			}
		}
		
		if(selValue)	
		{
			for(var i=0; i<sRegion.length; i++)
			{
				if(sRegion.options[i].value==selValue)
				{
					sRegion.selectedIndex=i;
					break;
				}
			}
		}
	}
	else
	{
		for(var i=0; i<arrCOUNTY.length; i++)
		{
			sValue=arrCOUNTY[i].split(',');
			sCounty.options[j++]=new Option(sValue[2],sValue[1]);
		}
		sRegion.selectedIndex=0;
		sLocation.selectedIndex=0;
	}
}

function MapOpen(RegionID)
{
	var el=document.getElementById('MapFrame');
	if (el) document.body.removeChild(el);
	
	var el=document.createElement("IFRAME");
	el.scrolling='no';
	el.frameborder='no';
	el.border=0;
	el.id='MapFrame';
	el.src='index.php?SCREEN=map&RegionID='+RegionID;
	el.style.position='absolute';
	el.style.left='0px';
	el.style.top='0px';
	el.style.width='2px';
	el.style.height='0px';
	el.style.visibility='visible';
	el.style.zIndex=10000000;
	document.body.appendChild(el);

	return false;
}

function MapLoad(RegionID,CountyID)
{
	var frm=parent.document.getElementById('MapFrame');
	//frm.style.width=frm.style.height=0;
	var src='index.php?SCREEN=map&RegionID='+RegionID;
	if (CountyID) src+='&CountyID='+CountyID;
	frm.src=src;
}

function MapInit()
{
	var el=document.getElementById('Base');
	var frm=parent.document.getElementById('MapFrame');
	
	var w=el.offsetWidth+10;
	var h=el.offsetHeight+10;
	//if (w<300) w=300;
	//if (h<200) h=200;
	
	frm.style.width=w;
	frm.style.height=h;
	frm.style.top=((isIE?parent.document.body.clientHeight:parent.window.innerHeight)-parseInt(h))/2;
	frm.style.left=((isIE?parent.document.body.clientWidth:parent.window.innerWidth)-parseInt(w))/2;
}

function MapClose(RegionID,CountyID,LocationID)
{
	var doc=parent.document;

	arrCOUNTY=parent.strCOUNTY.split('|');
	arrLOCATION=parent.strLOCATION.split('|');
	sRegion=doc.getElementById('selRegion');
	sCounty=doc.getElementById('selCounty');
	sLocation=doc.getElementById('selLocation');

	SelectChangeAll(RegionID,CountyID,LocationID);

	var el=doc.getElementById('MapFrame');
	doc.body.removeChild(el);
}

function SelectChangeAll(RegionID,CountyID,LocationID)
{
	if (RegionID) 
	{
		SelectChange(sRegion,RegionID);
		SelectCounty(RegionID);
	}
	if (CountyID) 
	{
		SelectChange(sCounty,CountyID);
		SelectLocation(CountyID);
	}
	if (LocationID) 
		SelectChange(sLocation,LocationID);
}

function SelectChange(sel,id)
{
	if (!sel) return;
	for(var i=0; i<sel.options.length; i++)
		if(sel.options[i].value==id)
		{
			sel.selectedIndex=i;
			break;
		}
}

function ShowMenu(popupMenu)
{
	HideCombo=true;
  hideAllMenus();
	HideCombo=true;
  showMenu(document.getElementById(popupMenu),new Boundaries(event.clientX + document.body.scrollLeft, event.clientY + document.body.scrollTop), "horizontal");
  window.event.returnValue=false;  // disable the standard popup
}