/*#	天气查询	#*/

WEATHER_CACHE_PATH = typeof(WEATHER_CACHE_PATH)!='undefined' ? WEATHER_CACHE_PATH : 'cache/weather/'	;
WEATHER_SPLIT_HTML	=	typeof(WEATHER_SPLIT_HTML)!='undefined' ? WEATHER_SPLIT_HTML : '<br />'	;

function parse_weather_weather_city_select(cs,city,weather_city_key){
	city = city ? city : ''	;
	weather_city_key = weather_city_key ? weather_city_key : 'weather_city'	;
	
	weather_city_se = $(document.createElement('select'));
	weather_city_se.attr('id',weather_city_key);
	op2 = $(document.createElement('option'));
	op2.text('地区');
	weather_city_se.append(op2);
	
	tmp = cs.split(',');
	if (tmp.length) {
		citys = new Array(tmp.length);
		for(i=0;i<tmp.length;i++){
			ct = tmp[i];
			tmp2 = ct.split('(');
			op2 = $(document.createElement('option'));
			x = $.trim(tmp2[0]);
			op2.attr('value',x);
			op2.text(x);
			if (x==city) {
				op2.attr('selected','selected');
			}
			weather_city_se.append(op2);
		}
	}
	
	return weather_city_se	;

}//-- end of function `parse_weather_weather_city_select`

function build_weather_area_select(div , prov , city , weather_prov_key , weather_city_key) {
	weather_prov_key	=	weather_prov_key ? weather_prov_key : 'weather_prov'	;
	weather_city_key	=	weather_city_key ? weather_city_key : 'weather_city'	;
	prov = prov ? prov : '江苏'	;
	city = city ? city : '苏州'	;

	obj	=	$('#'+div)	;
	prov_js	=	WEATHER_CACHE_PATH + 'provs.js'	 ;

	weather_prov_se	=	$(document.createElement('select'))	;
	weather_prov_se.attr('id' , weather_prov_key)	;
	
	op	=	$(document.createElement('option'))	;
	op.val('')	;
	op.text( '省を' )	;
	weather_prov_se.append(op)	;
	
	weather_city_se = parse_weather_weather_city_select('',city,weather_city_key);

	$.getJSON(prov_js , function(provs) {

		for( d in provs ) {
			op	=	$(document.createElement('option'))	;
			prov_name	=	provs[d].name[0]	;
			op.val( prov_name )	;
			op.text(prov_name);
			if ( prov==prov_name ) {
				op.attr('selected','selected');
				weather_city_se = parse_weather_weather_city_select(provs[d].citys,city,weather_city_key);
			}
			weather_prov_se.append(op)	;
		}

		weather_prov_se.change( function() {
			prov_name = $(this).val()	;
			for ( d in provs )	{
				if (provs[d].name[0]==prov_name)	{
					cs = parse_weather_weather_city_select(provs[d].citys,city,weather_city_key);

					$('#'+weather_city_key).empty();
					$('#'+weather_city_key).html( cs.html() );
					
					break	;
				}
			}
		})	;

		obj.append(weather_prov_se)	;
		obj.append(WEATHER_SPLIT_HTML);
		obj.append(weather_city_se)	;

	})	;
}//-- end of function `build_area_select`
