document.writeln('<script type="text/javascript" src="http://resource.elong.com/webunion/searchboxjs/cities.js"></script>');
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:460px;margin:0 auto;text-align:center;border:1px solid #2960c4;background:#e4f2ff;padding-bottom:10px;}');
document.writeln('#searchbox_elong h3{background:#2960c4;height:27px;line-height:27px; text-align:center;}');
document.writeln('#searchbox_elong h3 a{display:block;background:url(http://resource.elong.com/webunion/searchboxjs/lowticket/v/blue/images/bg.gif) 0px -27px no-repeat; width:74px; height:19px; float:right; margin:3px 10px 0px 0px;_margin-right:5px;}');
document.writeln('#searchbox_elong .hotel{background:url(http://resource.elong.com/webunion/searchboxjs/lowticket/v/blue/images/bg.gif) no-repeat;padding-left:40px;height:27px;font-size:14px;color:#fff;font-weight:bold;line-height:27px;line-height:28px\9;text-align:left;margin-left:20px; overflow:hidden;}');
document.writeln('#searchbox_elong p{margin-top:5px;height:20px;padding:0px 15px; text-align:left;}');
document.writeln('#searchbox_elong p select{font-size:12px;*font-family:"宋体";width:106px;height:20px;}');
document.writeln('#searchbox_elong p input{width:40px;height:21px\9;line-height:17px\9;margin:0;overflow:hidden;}');
document.writeln('');
document.writeln('#searchbox_elong .air_tab{clear:both;margin:5px 10px 0px 10px; padding-top:5px;}');
document.writeln('#searchbox_elong .air_tab li{display:block;float:left;height:22px;line-height:22px;line-height:24px\9; 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 .air_tab h4{font-family:"宋体"; font-size:14px; font-weight:bold; color:#2960c4;float:right;padding-top:3px; height:20px; line-height:20px; overflow:hidden}');
document.writeln('#searchbox_elong .air_tab h4 a{font-family:"宋体"; font-size:14px; font-weight:bold; color:#2960c4; text-decoration:none;}');
document.writeln('#searchbox_elong .air_tab h4 a:hover{color:#bb1a1a;}');
document.writeln('#searchbox_elong .list{padding:5px 0px 5px 10px;border:1px solid #c8d3de; margin:0px 10px;clear:both; background:#f5f7fe;*padding-top:2px;}');
document.writeln('#searchbox_elong .list li{width:55px; float:left; display:inline; padding-right:5px;}');
document.writeln('#searchbox_elong .list dl{zoom:1;}');
document.writeln('#searchbox_elong .list dt{line-height:1.4em; text-align:right;}');
document.writeln('#searchbox_elong .list dd{height:25px;line-height:25px; text-align:right;padding-top:3px;}');
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('');
document.writeln('</style>');
document.writeln('');
document.writeln('<div id="searchbox_elong">');
document.writeln('<h3><a href="javascript:;"  title="艺龙旅行网"></a><div class="hotel">7日机票特价日历</div></h3>');
document.writeln('<p>出发城市：');
document.writeln('<select  id="fromCities" name="DEPART_CITY"><option value="" selected="selected">Beijing 北京</option></select>');
document.writeln('&nbsp;&nbsp;&nbsp;&nbsp;到达城市：');
document.writeln('<select id="toCities" name="DEST_CITY"><option value="" selected="selected">Shanghai 上海</option></select>');
document.writeln('&nbsp;&nbsp;&nbsp;<input type="button" value="查询" />');
document.writeln('</p>');
document.writeln('<div class="air_tab">');
document.writeln('<ul><h4></h4><li id="li_go" class="air_on">去程</li><li id="li_back" class="air_off">回程</li></ul>');
document.writeln('<div style="clear:both"></div>');
document.writeln('</div>');
document.writeln('<div class="list">');
document.writeln('<dl id="go_box" style="display:block;">');
document.writeln('<div style="clear:both"></div>');
document.writeln('</dl>');
document.writeln('<dl id="back_box" style="display:none;">');
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='';
    $.each(data,function(i,item){
        html = html + '<li><dt>'+ formatdate(item.Date)  +'<br />'+ 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></li>';    
    });
    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) {}

