function init_location(major_location,sub_location,text_if_unselect,select_id)
{
	province = document.getElementById(select_id + '_location');
	city	   = document.getElementById(select_id + '_sublocation');
	province.options[0] = new Option(text_if_unselect,0);
	for(i=1;i<100;i++)
	{
		if(LSK[i] != undefined)
		{
			province.options[province.length] = new Option(LSK[i],i);
		}
	}
	if(LSK[major_location]!=undefined)
		province.value = major_location;
	else
		province.value = 0;
	city.options[0] = new Option(text_if_unselect,0);
	if(major_location > 0 && LSK[major_location]!=undefined && sub_location > 0)
	{
		for(i=1;i<100;i++)
		{
			city_id=major_location*100+i;
			if(LOK[major_location][city_id]!=undefined)
			{
				city.options[city.length] = new Option(LOK[major_location][city_id],city_id);
			}
		}
		if(LOK[major_location][sub_location]!=undefined)
			city.value=sub_location;
		else
			city.value=0;
	}
}

function change_location(major_location, select_id)
{
	city = document.getElementById(select_id + '_sublocation');
	city.length = 1;//forcibly change it to 1 to leave only the "text_if_unselect" option
	for(i=1;i<100;i++)
	{
		city_id = major_location * 100 + i;
		if(LOK[major_location][city_id] != undefined)
		{
			city.options[city.length] = new Option(LOK[major_location][city_id],city_id);
		}
	}
}

function get_location_name(location_id,text_if_unselect)
{
	if(location_id==0)
		return text_if_unselect;
	if(LSK[location_id]!=undefined)
		return LSK[location_id];//note the difference between LSK and LOK
	else
		return text_if_unselect;
}

function get_sublocation_name(location_id,sub_location_id,text_if_unselect)
{
	if(location_id==0||sub_location_id==0)
		return text_if_unselect;
	else if(LOK[location_id][sub_location_id]!=undefined)
		return LOK[location_id][sub_location_id];
	else
		return '';
}

function is_numeric(a_value)
{
	var legalSet="0123456789";
	return are_chars_all_legal(a_value, legalSet);
}

function are_chars_all_legal(sourceStr, legalSet)
{
	if(sourceStr=='')
		return false;
    var i, c;
    for (i=0; i < sourceStr.length; i++)
    {
        c=sourceStr.charAt(i);
    	//alert("for "+c+":"+legalSet.indexOf(c));
        if (legalSet.indexOf(c) <= -1)
		{
			//alert("char ["+c+"] in "+sourceStr+" is found in "+legalSet);
			return false;
		}
    }
    return true;
}
