$(function(){



function getweather(aa){

////////////////////////////////////////////////////////////
$.ajax({
type: "GET",
url: "weather.php?city="+aa,
dataType: "xml",
success: function(data) {

$("#btResult").hide();
weatherHTML="";
weatherHTML+="<img src=\"http://vortex.accuweather.com/adc2004/common/images/wxicons/120x90/"+$(data).find("wxc").attr("icon")+".gif\" style=\"float:left;margin:10px;\" />";
weatherHTML+="城市：<em>"+$(data).find("local").attr("city")+"</em> 省份："+$(data).find("local").attr("state")+" 纬度："+$(data).find("local").attr("lat")+" 经度："+$(data).find("local").attr("lon")+" 时间："+$(data).find("local").attr("time")+" GMT时区："+$(data).find("local").attr("gmtdiff")+"";
weatherHTML+="<br />";
weatherHTML+="<em>"+$(data).find("wxc").attr("text")+"</em> 温度："+$(data).find("wxc").attr("temp")+" 温度感觉："+$(data).find("wxc").attr("rft")+" 湿度："+$(data).find("wxc").attr("hum")+" 能见度："+$(data).find("wxc").attr("vis")+"km ";

weatherHTML+="<br /><br style=\"clear:left;\"/><strong>以下是近期天气预报</strong>";

///////
$(data).find("day").each(function(){

weatherHTML+="<hr style=\"clear:left;\" /><img src=\"http://vortex.accuweather.com/adc2004/common/images/wxicons/120x90/"+$(this).find("wxf").attr("icon")+".gif\" style=\"float:left;margin:10px;\" />日期：<em>"+$(this).attr("date")+" 星期 "+$(this).attr("wday")+"</em><br />天气概述： "+$(this).find("txtlong").text()+"<br /> <em>白天</em> 最高温度："+$(this).find("wxf").attr("htmp")+" 最低温度："+$(this).find("wxf").attr("ltmp")+" 风向："+$(this).find("wxf").attr("wdir")+" <br />下雨可能性："+$(this).find("wxf").attr("rain")+" 下雪可能性："+$(this).find("wxf").attr("snow")+"<br /> <em>晚上</em> 最高温度："+$(this).find("nighttime").find("wxf").attr("htmp")+" 最低温度："+$(this).find("nighttime").find("wxf").attr("ltmp")+" 风向："+$(this).find("nighttime").find("wxf").attr("wdir")+" <br />下雨可能性："+$(this).find("nighttime").find("wxf").attr("rain")+" 下雪可能性："+$(this).find("nighttime").find("wxf").attr("snow")+"<br /><br />";

})
///////



$("#btResult").html(weatherHTML);
$("#btResult").show();

}
})
////////////////////////////////////////////////////////////

}


//ie form后面的 button默认不提交
$("#serachit").click(function(){$("form").submit()})

//表单提交
$("form").submit(function(){
if($("#searchstr").val()==""||$("#searchstr").val()=="请输入要查询的关键字"){$("#searchstr").val("请输入要查询的关键字");$("#searchstr").select();return false;}
})

//ui效果
$("#searchstr").hover(function(){$(this).addClass("hover");},function(){$(this).removeClass("hover");}).focus(function(){$(this).addClass("focus");}).blur(function(){$(this).removeClass("focus");});


//如果有关键字
if(city!=""){

////////////////////////////// ajax start
$.ajax({
 type: "GET",
        url: "findlocation.php?city="+city,
        dataType: "xml",
        success: function(data) {


if($(data).find("citylist").attr("intl")!="0"){  //如果有结果的话

$(data).find("location").each(function(){

	
$("<li></li>").html("<a title=\""+$(this).attr("location")+"\" href=\"#1\" >地名："+$(this).attr("city")+" 省:"+$(this).attr("state")+"</a>").appendTo("#btResult ol").find("a").click(function(){getweather($(this).attr("title"))});



})

$("#otry").show();
$("#btResult").show();


}else { //如果没有结果

$("#btResult").html("对不起，没有找到关于 <em>"+city+"</em> 的地名");
$("#btResult").show();

}
        },

error:function(){$("#btResult").html("出错，请刷新或者换个名字再试！")}

})
///////////////////////////////// ajax end


}else{$("#searchstr").focus().select()};

});
