﻿
/**
 * 生成sublocation或university的下拉菜单
 * object 下拉菜单对象，如work_sublocation
 * selectValue 对应的location的value
 * defaultValue 初始值
 * isUniversity 区别sublocation列表还是university列表
 * keepFirst 是否保留第一个选项，如"请选择"
 */
function redirect(object, selectValue, defaultValue, isUniversity, keepFirst)
{
	/**清空原有的選項**/
	if (keepFirst)
	{
		limit = 1;
	}
	else
	{
		limit = 0;
	}
	for (n = object.options.length; n >= limit; n--)
	{
		object.options[n] = null;
	}

	var newOption = '';
	
	var key;
	
	if (isUniversity)
	{
		for (key in university_array[selectValue])
		{
			newOption = new Option(university_array[selectValue][key], key);
			if (key == defaultValue)
			{
				newOption.selected = true;
			}
			object.options.add(newOption);
		}
	}
	else 
	{
		for (key in sublocation_array[selectValue])
		{
			newOption = new Option(sublocation_array[selectValue][key], key);
			if (key == defaultValue)
			{
				newOption.selected = true;
			}
			object.options.add(newOption);
		}
	}
}

