var weather=function(){
	var tmp=0;
	var style='gui';
	var SWther={};
    this.getWeather=function(city,type){//根据city的值获取天气信息 
		$.getScript("http://php.weather.sina.com.cn/iframe/index/w_cl.php?code=js&day=2&city="+city+"&dfc=3",function(){echo(city);});}
	function dis_img(weather){//显示不同天气对应的图片
		var route="./skin/weather/";//文件夹路径
		if(style=='unknow'){var forder='unknow';}
		  else{var forder='gui';}
		var style_img=route+forder+"/s_13.png";
		if(weather.indexOf("多云")!==-1||weather.indexOf("晴")!==-1){//多云转晴，以下类同 indexOf:包含字串
			style_img=route+forder+"/s_1.png";}
		else if(weather.indexOf("多云")!==-1&&weather.indexOf("阴")!==-1){
			style_img=route+forder+"/s_2.png";}
		else if(weather.indexOf("阴")!==-1&&weather.indexOf("雨")!==-1){
			style_img=route+forder+"/s_3.png";}
		else if(weather.indexOf("晴")!==-1&&weather.indexOf("雨")!==-1){
			style_img=route+forder+"/s_12.png";}
		else if(weather.indexOf("晴")!==-1&&weather.indexOf("雾")!==-1){
			style_img=route+forder+"/s_12.png";}
		else if(weather.indexOf("晴")!==-1){style_img=route+forder+"/s_13.png";}
		else if(weather.indexOf("多云")!==-1){style_img=route+forder+"/s_2.png";}
		else if(weather.indexOf("阵雨")!==-1){style_img=route+forder+"/s_3.png";}
	    else if(weather.indexOf("小雨")!==-1){style_img=route+forder+"/s_3.png";}
		else if(weather.indexOf("中雨")!==-1){style_img=route+forder+"/s_4.png";}
		else if(weather.indexOf("大雨")!==-1){style_img=route+forder+"/s_5.png";}
		else if(weather.indexOf("暴雨")!==-1){style_img=route+forder+"/s_5.png";}
		else if(weather.indexOf("冰雹")!==-1){style_img=route+forder+"/s_6.png";}
		else if(weather.indexOf("雷阵雨")!==-1){style_img=route+forder+"/s_7.png";}
		else if(weather.indexOf("小雪")!==-1){style_img=route+forder+"/s_8.png";}
		else if(weather.indexOf("中雪")!==-1){style_img=route+forder+"/s_9.png";}
		else if(weather.indexOf("大雪")!==-1){style_img=route+forder+"/s_10.png";}
		else if(weather.indexOf("暴雪")!==-1){style_img=route+forder+"/s_10.png";}
		else if(weather.indexOf("扬沙")!==-1){style_img=route+forder+"/s_11.png";}
		else if(weather.indexOf("沙尘")!==-1){style_img=route+forder+"/s_11.png";}
		else if(weather.indexOf("雾")!==-1){style_img=route+forder+"/s_12.png";}
		else{style_img=route+forder+"/s_2.png";}
        
		return style_img;
		}
function echo(city){ 
  //  uisy.query('return');
	 //$('#city').html(city); 
	 var w=[]; 
	 var T_weather_img=dis_img(window.SWther.w[city][0].s1);//今天天气的参数传递
	 var T_weather_img1=dis_img(window.SWther.w[city][0].s2);//今天天气的参数传递
	 /**
	 <tr>
	  <td></td>
	  <td>
	    <table>
	    	<tr>
	    		<td></td>
	    	</tr>
	    	<tr>
	    		<td></td>
	    	</tr>
	    </table>
	  </td>
	  <td></td>
	  <td></td>
	 </tr>
	 **/ 
	 w.push("<tr>");
	 w.push("<td style='width:98px;'>","<img width='30' src='"+T_weather_img+"' title='"+window.SWther.w[city][0].s1+"' alt='"+window.SWther.w[city][0].s1+"' />","</td>");
	 w.push("<td style='width:98px;'>");
	 w.push("<table>");
	 w.push('<tr>','<td class="f2">\u767D\u5929'+window.SWther.w[city][0].s1+'</td>','</tr>');
	 w.push('<tr>','<td class="f1">'+window.SWther.w[city][0].t1+'℃</td>','</tr>'); 
	 w.push('<tr>','<td class="f3">'+window.SWther.w[city][0].d1+'</td>','</tr>'); 
	 w.push("</table>");
	 w.push("</td>");
	  w.push("<td style='width:98px;'>","<img width='30' src='"+T_weather_img1+"' title='"+window.SWther.w[city][0].s2+"' alt='"+window.SWther.w[city][0].s2+"' />","</td>");
	 	 w.push("<td style='width:98px;'>");
	 w.push("<table>");
	 w.push('<tr>','<td class="f2">\u591C\u95F4'+window.SWther.w[city][0].s2+'</td>','</tr>');
	 w.push('<tr>','<td class="f1">'+window.SWther.w[city][0].t2+'℃</td>','</tr>'); 
	 w.push('<tr>','<td class="f3">'+window.SWther.w[city][0].d2+'</td>','</tr>'); 
	 w.push("</table>");
	 w.push("</td>"); 
	 w.push("</tr>");
	 $("#weather").find("table").append(w.join("")); 
	 
	}
	}
   var uisy={
		query:function(ent){//切换状态
			if(ent=='search'){
				$('#weather_sub >input').disabled===true;
				$('#weather_res_case').fadeOut(500,function(){$(this).addClass('common_hide')})}
            else if(ent=='return'){//出现下面的元素
				$('#weather_sub >input').disabled===false;
				$('#weather_res_case').fadeIn(500,function(){$(this).removeClass('common_hide')})}}
	    }
    var onEvent={
		onEvent:function(){
			var has_daluzai=onEvent.daluzai();
		    if(has_daluzai===true){
			    $('#weather_sub >input').click(function(){onEvent.searchWeather();})
					Enter_Ctrl('weather_search',13,"onEvent.searchWeather()");}},
		searchWeather:function(){
					uisy.query('search');
					var city=$('#weather_search >input').val();
					city=$.trim(city);weather_.getWeather(city);},
		daluzai:function(){
						var has_author=$('#weather_author');
						if(has_author.length===0){return false;}
						else{has_author.click(function(){go_URL('blank','');})
							return true;}},
		killError:function(){
					   function killErrors(){return true;}
					   window.onerror=killErrors;}
}

//页面以某方式跳转到某页面
function go_URL(type,url){if(type=='blank'){window.open(url,'');}else{window.location=url;}}

//利用keycode=13使得回车与点击查询按钮功能一致
function Enter_Ctrl(get_id,ent,fun){
	if(typeof(get_id)=='undefined'||get_id==''){//若get_id对象非空，则绑定keypress事件！
		var set_obj=$(document);}
	else{var set_obj=$('#'+get_id);}
    
	if(ent==13){
		set_obj.keypress(function(e){if(e.which==13||e.which==10){eval(fun);}})}
	else{set_obj.keypress(function(e){if(e.ctrlKey&&e.which==13||e.which==10){eval(fun);}})}
	
}
//
function def_value(get_id,msg){//输入框的默认提示
	var set_obj=$('#'+get_id).find('input');
    if(set_obj.val()==""){
		set_obj.val(msg);
		set_obj.css('color','#949494');
	}
    set_obj.click(function(){
		if($(this).val()==msg){
			$(this).val('');
			set_obj.css('color','');
		}});
	set_obj.bind("blur",function(){
		if($(this).val()==''){
			$(this).val(msg);
			set_obj.css('color','#949494');
		}});
}