//*************************** 说明 ***************************//
// 创 建 者：
// 日    期：2007-11-1
// 功能说明：输出年度、地区、数据字典，其中地区列表可实现联动菜单功能。
// 修改说明：无。
//************************************************************//


//联动下拉菜单操作部分
//联动
function select_change( child_select, parent_select  ,startitem)
{
	var state_array ;
	var child_select_num ;
	var i ;
	var city_array ;
	child_select.selectedIndex = 0 ;
	if( parent_select == "-1" )
	{
		child_select.options.length = 1 ;
			
		return ;	
	}
	parent_select = parent_select.replace(" " , "_" ) ;
	parent_select = parent_select.replace(" " , "_" ) ;
	state_array = eval( parent_select ) ;
	child_select_num = state_array.length/2 +1 ;
	child_select.options.length = child_select_num ;
	
	if(startitem == null)
	{
		for( i=1 ; i<child_select_num ; i++ )
		{
			child_select.options[i].value = state_array[(i-1)*2] ;
			child_select.options[i].text = state_array[(i-1)*2+1] ;
		
		}
	}
	else
	{
		child_select.options.length = child_select_num-1 ;
		for( i=0 ; i<child_select_num-1 ; i++ )
		{
			child_select.options[i].value = state_array[(i)*2] ;
			child_select.options[i].text = state_array[(i)*2+1] ;

			if(i == 0)
			{
				child_select.selectedIndex = i ;
			}
		
		}
	}

}

//设置下拉菜单内容
function set_select_options( select_name, array , selected_option ,startitem)
{
	//startitem:开始项，为空则从1开始，否则从0开始
	
	var select_num ;
	var i ;
	
	select_num = array.length/2 +1 ;
	
	select_name.options.length = select_num ;
	select_name.selectedIndex = 0 ;
	
	if(startitem == null)
	{
		for( i=1 ; i<select_num ; i++ )
		{
			select_name.options[i].value = array[(i-1)*2] ;
			select_name.options[i].text = array[(i-1)*2+1] ;
		
			if( array[(i-1)*2] == selected_option )
				select_name.selectedIndex = i ;
		}
	}
	else
	{
		select_name.options.length = select_num -1;
		for( i=0 ; i<select_num-1 ; i++ )
		{
			select_name.options[i].value = array[(i)*2] ;
			select_name.options[i].text = array[(i)*2+1] ;
		
			if(i == 0)
			{
				select_name.selectedIndex = i ;
			}
			
			if( array[(i)*2] == selected_option )
				select_name.selectedIndex = i ;
		}
	}
}





//输出年份下拉列表
function YearList(listname,syear,eyear,selectyear,script)
{
	//listname:列表名
	//syear：开始年份，如果未设置，则取当前年的前后三十年；若设置了一个值，则取设置的年份到当前年份。
	//eyear：结束年份，若未设置开始年份，此年份不起使用；若设置了开始年份，此年份做为结束年份。
	//selectyear：选择的年份。
	//script：要执行的脚本语句。
	
	scriptdate = "";
	
	var currentyear = new Date().getFullYear();//当前年
	var startyear;
	var endyear;
	var scriptdate = "<select id='" + listname + "' name='" + listname + "' ";
	
	if(script != null && script != "")
	{
		scriptdate += " onchange=" + script;
	}
	
	scriptdate +=  ">";

	if(syear == null || syear == "" )
	{
		startyear = currentyear - 30;
		endyear = currentyear + 30;
	}
	else
	{
		startyear = syear;
		if(eyear == null || eyear == "")
		{
			endyear = currentyear;
		}
		else
		{
			endyear = eyear;
		}
	}
	
	for(var i=startyear;i<=endyear;i++)
	{
		scriptdate += "<option value='" + i + "'";
		if(selectyear == null || selectyear == "")
		{
			if(i == currentyear)
			{
				scriptdate += " selected='true'";
			}
		}
		else
		{
			if(i == selectyear)
			{
				scriptdate += " selected='true'";
			}
		}
		scriptdate += ">" + i + "</option>";
	}
	scriptdate += "</select>";
	
	document.write(scriptdate);
} 


//输出地区下拉列表
function AreaList(formname,listname,selectid,mustselect,childname,childselectid,childmustselect,width,childwidth,clewvalue)
{
	//formname：表单名
	//listname：列表名
	//selectid:选中的项目
	//mustselect:必选
	//childname：下级列表名，若为空则只显示省份列表
	//childselectid:选中的子项目
	//childmustselect:下级列表必选
	//width：生成下拉列表的宽度
	//childwidth：下级列表宽度
	//clewvalue:添加提示选项的内容
	var content = "";
	
	content = "<select id=\"" + listname + "\" name=\"" + listname + "\"";
	if(childname != null && childname != "")
	{
		content += " onChange=\"select_change(window.document." + formname + "." + childname + " ,window.document." + formname + "." + listname + ".options[selectedIndex].value";
		if(childmustselect != null && childmustselect)
		{
			content += ",0";
		}
		content +=  ");\"";
	}
	if(width != null && width)
	{
		content += " style='width:" + width + "px;' CssClass='listbox'";
	}
	content += ">";
	if(mustselect == null || mustselect == "")
	{
		content += "<option selected value=\"-1\">";
		

		if(clewvalue != null && clewvalue != "")
		{
			content += clewvalue;
		}
		else
		{
			content += "选择省份";
		}
		content += "</option>";

	
	}
	content += "<script>set_select_options( window.document." + formname + "." + listname + ", Provinces, \"" + selectid + "\"";
	
	if(mustselect != null && mustselect)
	{
		content += ",0 ";
	}
	
	content += ") ;</script>";

	
	content += "</select>";
	
	
	if(childname != null && childname != "")
	{
	
		content += "<select id=\"" + childname + "\" name=\"" + childname + "\"";
		if(childwidth != null && childwidth)
		{
			content += " style='width:" + childwidth + "px;'";
		}
		content += ">";

		if(childmustselect == null || childmustselect == "")
		{
			if(clewvalue != null && clewvalue != "")
		    {
			   content += "<option selected value=\"-1\">"+clewvalue+"</option>";
			}
			else
			{
			   content += "<option selected value=\"-1\">选择城市</option>";
			}
		}

		if(childselectid != null && childselectid != "")
		{
			content += "<script>set_select_options( window.document." + formname + "." + childname + "," + selectid + ", \"" + childselectid + "\"";

			if(childmustselect != null && childmustselect)
			{
				content += ",0 ";
			}
	
			content += ") ;</script>";

		}
		
		
		content += "</select>";

	}
	document.write(content);
	
	
	content = "";
	if(mustselect != null && mustselect != "" && (selectid == null || selectid == "-1" || selectid == "" ))
	{
		//城市
		content = "<script>select_change(window.document." + formname + "." + childname + " ,window.document." + formname + "." + listname + ".options[0].value";
		if(childmustselect != null && childmustselect)
		{
			content += ",0";
		}
		content +=  ");</script>";
		
		document.write(content);

	}

}






//输出数据字典下拉列表
function DictionaryList(DictionaryName,formname,listname,selectid,mustselect,width,clewvalue)
{
	//DictionaryName:字典名
	//formname:表单名
	//listname:列表名
	//selectid:选中的项目
	//mustselect:必选
	//width:生成下拉列表的宽度
	//clewvalue:添加提示选项的内容
	var content = "";
	
	content = "<select id=\"" + listname + "\" name=\"" + listname + "\"";
	if(width != null && width)
	{
		content += " style='width:" + width + "px;'";
	}
	content += ">";
	if(mustselect == null || mustselect == "")
	{
		content += "<option selected value=\"-1\">";
		if(clewvalue != null && clewvalue != "")
		{
			content += clewvalue;
		}
		else
		{
			content += "--请选择--";
		}
		content += "</option>";
	}
	content += "<script>set_select_options( window.document." + formname + "." + listname + ", " + DictionaryName + ", \"" + selectid + "\"";
	if(mustselect != null && mustselect)
	{
		content += ",0 ";
	}
	
	content += ") ;</script>";
	content += "</select>";
	
	document.write(content);
}



//输出数据字典复选框列表
function DictionaryCheckbox(DictionaryName,cbname,selectid,css)
{
	//DictionaryName:字典名
	//cbname:复选框名
	//selectid:选中的项目
	//css:样式
	var content = "";
	
	var cb_num ;
	var i ;
	var ifExist;//是否包含
	cb_num = DictionaryName.length/2 +1 ;
	

	for( i=1 ; i<cb_num ; i++ )
	{
		content += "<input type=\"checkbox\" name=\"" + cbname + "\" id=\"" + cbname + i + "\" value=\"" + DictionaryName[(i-1)*2] + "\"";
		if(css != null && css != "")
		{
			content += " class=\"" + css + "\" ";
		}
		
		if(selectid != null && selectid != "")
		{
			ifExist = selectid.indexOf(DictionaryName[(i-1)*2]);
			if(ifExist != -1)
			{
				content += " checked ";
			}
		}
		
		content += ">" + DictionaryName[(i-1)*2+1] + "&nbsp;&nbsp;"; 

	}
	document.write(content);
}

//输出项目类别联动下拉列表
function InfoTypeList(formname,listname,selectid,mustselect,childname,childselectid,childmustselect,width,childwidth,clewvalue)
{
	//formname：表单名
	//listname：列表名
	//selectid:选中的项目
	//mustselect:必选
	//childname：下级列表名，若为空则只显示省份列表
	//childselectid:选中的子项目
	//childmustselect:下级列表必选
	//width：生成下拉列表的宽度
	//childwidth：下级列表宽度
	//clewvalue:添加提示选项的内容
	var content = "";
	
	content = "<select id=\"" + listname + "\" name=\"" + listname + "\"";
	if(childname != null && childname != "")
	{
		content += " onChange=\"select_change(window.document." + formname + "." + childname + " ,window.document." + formname + "." + listname + ".options[selectedIndex].value";
		if(childmustselect != null && childmustselect)
		{
			content += ",0";
		}
		content +=  ");\"";
	}
	if(width != null && width)
	{
		content += " style='width:" + width + "px;'";
	}
	content += ">";
	if(mustselect == null || mustselect == "")
	{
		content += "<option selected value=\"-1\">";
		

		if(clewvalue != null && clewvalue != "")
		{
			content += clewvalue;
		}
		else
		{
			content += "请选择";
		}
		content += "</option>";

	
	}
	content += "<script>set_select_options( window.document." + formname + "." + listname + ", Categories, \"" + selectid + "\"";
	
	if(mustselect != null && mustselect)
	{
		content += ",0 ";
	}
	
	content += ") ;</script>";

	
	content += "</select>";
	
	
	if(childname != null && childname != "")
	{
	
		content += "<select id=\"" + childname + "\" name=\"" + childname + "\"";
		if(childwidth != null && childwidth)
		{
			content += " style='width:" + childwidth + "px;'";
		}
		content += ">";

		if(childmustselect == null || childmustselect == "")
		{
			if(clewvalue != null && clewvalue != "")
		    {
			   content += "<option selected value=\"-1\">"+clewvalue+"</option>";
			}
			else
			{
			   content += "<option selected value=\"-1\">请选择</option>";
			}
		}

		if(childselectid != null && childselectid != "")
		{
			content += "<script>set_select_options( window.document." + formname + "." + childname + "," + selectid + ", \"" + childselectid + "\"";

			if(childmustselect != null && childmustselect)
			{
				content += ",0 ";
			}
	
			content += ") ;</script>";

		}
		
		
		content += "</select>";

	}
	document.write(content);
	
	
	content = "";
	if(mustselect != null && mustselect != "" && (selectid == null || selectid == "-1" || selectid == "" ))
	{
		//城市
		content = "<script>select_change(window.document." + formname + "." + childname + " ,window.document." + formname + "." + listname + ".options[0].value";
		if(childmustselect != null && childmustselect)
		{
			content += ",0";
		}
		content +=  ");</script>";
		
		document.write(content);

	}

}

//输出创业人群类别联动下拉列表
function CrowdTypeList(formname,listname,selectid,mustselect,childname,childselectid,childmustselect,width,childwidth,clewvalue)
{
	//formname：表单名
	//listname：列表名
	//selectid:选中的项目
	//mustselect:必选
	//childname：下级列表名，若为空则只显示省份列表
	//childselectid:选中的子项目
	//childmustselect:下级列表必选
	//width：生成下拉列表的宽度
	//childwidth：下级列表宽度
	//clewvalue:添加提示选项的内容
	var content = "";
	
	content = "<select id=\"" + listname + "\" name=\"" + listname + "\"";
	if(childname != null && childname != "")
	{
		content += " onChange=\"select_change(window.document." + formname + "." + childname + " ,window.document." + formname + "." + listname + ".options[selectedIndex].value";
		if(childmustselect != null && childmustselect)
		{
			content += ",0";
		}
		content +=  ");\"";
	}
	if(width != null && width)
	{
		content += " style='width:" + width + "px;'";
	}
	content += ">";
	if(mustselect == null || mustselect == "")
	{
		content += "<option selected value=\"-1\">";
		

		if(clewvalue != null && clewvalue != "")
		{
			content += clewvalue;
		}
		else
		{
			content += "请选择";
		}
		content += "</option>";

	
	}
	
	content += "<script>set_select_options( window.document." + formname + "." + listname + ", Big_Crowd, \"" + selectid + "\"";
 
	if(mustselect != null && mustselect)
	{
		content += ",0 ";
	}
	
	content += ") ;</script>";

	
	content += "</select>";
	
	
	if(childname != null && childname != "")
	{
	
		content += "<select id=\"" + childname + "\" name=\"" + childname + "\"";
		if(childwidth != null && childwidth)
		{
			content += " style='width:" + childwidth + "px;'";
		}
		content += ">";

		if(childmustselect == null || childmustselect == "")
		{
			if(clewvalue != null && clewvalue != "")
		    {
			   content += "<option selected value=\"-1\">"+clewvalue+"</option>";
			}
			else
			{
			   content += "<option selected value=\"-1\">请选择</option>";
			}
		}

		if(childselectid != null && childselectid != "")
		{
			content += "<script>set_select_options( window.document." + formname + "." + childname + "," + selectid + ", \"" + childselectid + "\"";

			if(childmustselect != null && childmustselect)
			{
				content += ",0 ";
			}
	
			content += ") ;</script>";

		}
		
		
		content += "</select>";

	}
 
	document.write(content);
	
	
	content = "";
	if(mustselect != null && mustselect != "" && (selectid == null || selectid == "-1" || selectid == "" ))
	{
	
		content = "<script>select_change(window.document." + formname + "." + childname + " ,window.document." + formname + "." + listname + ".options[0].value";
		if(childmustselect != null && childmustselect)
		{
			content += ",0";
		}
		content +=  ");</script>";
		
		document.write(content);

	}

}

