document.writeln('<style>');
document.writeln('#searchbox_elong *{padding:0;margin:0; font-size:12px; font-family:Arial, Helvetica, sans-serif;line-height:1.5em;list-style:none;}');
document.writeln('#searchbox_elong img{border:0;}');
document.writeln('');
document.writeln('#searchbox_elong{width:200px;margin:0 auto;text-align:center;border:1px solid #2960c4;background:#fafcff;padding-bottom:10px;}');
document.writeln('#searchbox_elong h3{background:#2960c4;height:27px;line-height:27px; text-align:center;}');
document.writeln('#searchbox_elong .hotel{background:url(http://resource.elong.com/webunion/searchboxjs/lowticket/h/blue/images/bg.gif) 124px 0px no-repeat;width:160px;height:27px;font-size:14px;color:#fff;font-weight:bold;line-height:27px;text-align:left;margin:0px auto;}');
document.writeln('#searchbox_elong p{margin-top:5px;height:20px;padding-top:2px;}');
document.writeln('');
document.writeln('#searchbox_elong .air_tab{clear:both;margin:5px 10px 0px;}');
document.writeln('#searchbox_elong .air_tab li{display:block;float:left;height:22px;line-height:22px;line-height:24px; overflow:hidden;padding-top:5px;padding:0px 10px;cursor:pointer;border:1px solid #c8d3de;margin-bottom:-1px;margin-left:5px; display:inline;}');
document.writeln('#searchbox_elong .air_tab li.air_on{border-bottom:1px solid #f5f7fe; background:#f5f7fe;color:#2960c4; font-weight:bold;}');
document.writeln('#searchbox_elong .air_tab li.air_off{border-bottom:none;background:#fff; color:#777777;}');
document.writeln('#searchbox_elong .list{padding:5px 10px;border:1px solid #c8d3de; margin:0px 10px;clear:both; background:#f5f7fe;*margin-top:-5px;*padding-top:2px;}');
document.writeln('#searchbox_elong .list h4{font-family:"宋体"; font-size:14px; font-weight:bold; color:#2960c4;padding-bottom:5px 0px; border-bottom:2px solid #cccccc;}');
document.writeln('#searchbox_elong .list h4 a{font-family:"宋体"; font-size:14px; font-weight:bold; color:#2960c4; text-decoration:none;}');
document.writeln('#searchbox_elong .list h4 a:hover{color:#bb1a1a;}');
document.writeln('#searchbox_elong .list dl{zoom:1;}');
document.writeln('#searchbox_elong .list dt{float:left;width:95px;text-align:left;height:25px;line-height:25px;}');
document.writeln('#searchbox_elong .list dd{float:right;width:60px;height:25px;line-height:25px;text-align:right;}');
document.writeln('#searchbox_elong .list dd a{font-family:Arial; font-size:12px; text-decoration:underline; color:#003391; line-height:1.8em;}');
document.writeln('#searchbox_elong .list dd a:hover{color:#bb1a1a; text-decoration:none;}');
document.writeln('#searchbox_elong select{font-size:12px;*font-family:"宋体";width:106px;height:20px;}');
document.writeln('#searchbox_elong .air_tab input{width:40px;height:22px\9;line-height:18px\9;position:relative;float:right;margin:0; overflow:hidden;}');
document.writeln('</style>');
document.writeln('');
document.writeln('<script type="text/javascript" src="http://resource.elong.com/webunion/searchboxjs/cities.js"></script>');
document.writeln('<div id="searchbox_elong">');
document.writeln('<h3><div class="hotel">7日机票特价日历</div></h3>');
document.writeln('<p>出发城市：');
document.writeln('<select  id="fromCities" name="DEPART_CITY"><option value="" selected="selected">Beijing 北京</option></select><br /></p>');
document.writeln('<p>');
document.writeln('到达城市：');
document.writeln('<select id="toCities" name="DEST_CITY"><option value="" selected="selected">Shanghai 上海</option></select>');
document.writeln('</p>');
document.writeln('<div class="air_tab">');
document.writeln('<ul><input type="button" value="查询" /><li id="li_go" class="air_on">去程</li><li id="li_back" class="air_off">回程</li></ul>');
document.writeln('</div>');
document.writeln('<div class="list">');
document.writeln('<dl id="go_box" style="display:block;">');
document.writeln('<h4></h4>');
document.writeln('<dt></dd>');
document.writeln('<div style="clear:both"></div>');
document.writeln('</dl>');
document.writeln('<dl id="back_box" style="display:none;">');
document.writeln('<h4></h4>');
document.writeln('<dt></dd>');
document.writeln('<div style="clear:both"></div>');
document.writeln('</dl>');
document.writeln('</div>');
document.writeln('</div>');

var hotelcity="%u5317%u4EAC"; //cities.js设置需要
var len=10;
$(function(){
    $("#li_go").click(function () {
	$("#li_back,#li_go").removeAttr("class")
	$("#li_go").addClass("air_on")	
	$("#li_back").addClass("air_off")	
	$("#go_box").show();
	$("#back_box").hide();
	});
	
	$("#li_back").click(function () {
	$("#li_back,#li_go").removeAttr("class")
	$("#li_back").addClass("air_on")	
	$("#li_go").addClass("air_off")	
	$("#back_box").show();
	$("#go_box").hide();
	});
	
	$("#searchbox_elong :button").bind("click",change)
	
	loadData();
       
});

function loadData(){
    $.getJSON('http://union.elong.com/searchbox/LowTickets?from='+ fromcity +'&to=' + tocity +'&jsoncallback=?', 
                function(data){
                    $("#go_box").html(genhtml(data.Go,data.From,data.To));
                    $("#back_box").html(genhtml(data.Back,data.To,data.From));
                    $("#searchbox_elong h4").html(getCityPair(data.From,data.To));
                }
           );
}

function change(){
    fromcity=$("#fromCities").val();
    tocity=$("#toCities").val(); 
    loadData();
}

//h,v 不一样
function genhtml(data,from,to){
    var html='<h4></h4>';
    //<dt>11.18&nbsp;&nbsp;&nbsp;&nbsp;星期三</dt><dd><a href="javascript:;" >￥1230</a></dd>
    $.each(data,function(i,item){
        html = html + '<dt>'+ formatdate(item.Date)  +'&nbsp;&nbsp;&nbsp;&nbsp;'+ item.Week +'</dt>';
        html = html + '<dd><a href="'+ geturl(from,to,item.Date)  +'" target="_blank">';  
        if(item.Price>0){
            html = html + '￥'+ item.Price ;  
        }else{
             html = html + 'XXX' ;             
        }
        html = html + '</a></dd>';    
    });
    html = html + '<div style="clear:both"></div>';
    return  html;   
}

function geturl(from,to,date){
    return 'http://travel.elong.com/flights/TSearch.aspx?g=result&campaign_id='+ campaign_id +'&DEPART_CITY='+ from +'&DEST_CITY=' + to + "&FLY_DATE="+date;
}

function formatdate(input){
    var segs = input.split('-');
    return segs[1]+'.'+segs[2];
}
function getCityPair(from,to){
    return getCity(from) +'→' + getCity(to);
}
function getCity(code){
    var name='';
    $.each(aircities,function(i,item){
        if(item.Code==code){
            name = item.CnName;
        }
    });    
    return name;
}

//google-analytics
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

try {
var pageTracker = _gat._getTracker("UA-11239288-2");
pageTracker._setDomainName("none");
pageTracker._setAllowLinker(true);
pageTracker._trackPageview();
} catch(err) {}

