﻿var _gaq = _gaq || []; var site_name = "58";
_gaq.push(['_setAccount', 'UA-877409-4']);
_gaq.push(['_addOrganic', 'baidu', 'word']);
_gaq.push(['_addOrganic', 'soso', 'w']);
_gaq.push(['_addOrganic', 'vnet', 'kw']);
_gaq.push(['_addOrganic', 'sogou', 'query']);
_gaq.push(['_addOrganic', 'youdao', 'q']);
_gaq.push(['_setDomainName', '.58.com']);
_gaq.push(['_setAllowHash', false]);
_gaq.push(['_trackPageview']);


function bluring(){ 
if(event.srcElement.tagName=="A"||event.srcElement.tagName=="IMG") document.body.focus(); 
} 
document.onfocusin=bluring; 


function setFouce(num)
{
	if(num ==1)
	{
		document.getElementById("cha_1").className="chaThis";
		document.getElementById("sea_1").style.display ="block";
		document.getElementById("sea_2").style.display ="none";
		document.getElementById("cha_2").className="";
	}
	else
	{
		document.getElementById("cha_2").className="chaThis";
		document.getElementById("cha_1").className="";
		document.getElementById("sea_2").style.display ="block";
		document.getElementById("sea_1").style.display ="none";
	}
}
function huoche_piao(num)
{
	if(num ==1)
	{
		document.getElementById("huoche_zz").style.display ="block";
		document.getElementById("huoche_cc").style.display ="none";
		document.getElementById("huoche_dd").style.display ="none";
		document.getElementById("huoche_ee").style.display ="none";
	}
	else if(num ==2)
	{
		document.getElementById("huoche_cc").style.display ="block";
		document.getElementById("huoche_zz").style.display ="none";
		document.getElementById("huoche_dd").style.display ="none";
		document.getElementById("huoche_ee").style.display ="none";
	}
	else if(num ==3)
	{
		document.getElementById("huoche_dd").style.display ="block";
		document.getElementById("huoche_zz").style.display ="none";
		document.getElementById("huoche_cc").style.display ="none";
		document.getElementById("huoche_ee").style.display ="none";
	}
	else
	{
		document.getElementById("huoche_ee").style.display ="block";
		document.getElementById("huoche_zz").style.display ="none";
		document.getElementById("huoche_cc").style.display ="none";
		document.getElementById("huoche_dd").style.display ="none";
	}
}
function huoche_biao(num)
{
	var D1=document.getElementById("biao_zz");
	var D2=document.getElementById("biao_cc");
	var D3=document.getElementById("biao_zd");

	if(num ==1)	{
		D1.style.display="block";D2.style.display="none";D3.style.display="none";
	}
	else if(num ==2)
	{
		D2.style.display="block";D1.style.display="none";D3.style.display="none";
	}
	else
	{
		D3.style.display="block";D1.style.display="none";D2.style.display="none";
	}
}

//////
function searchHcpTel()
{
    if(document.getElementById("inputbox").value!=""&&document.getElementById("inputbox").value!="请输入您要订票的城市")
    {
        window.location.href="/dingpiao.html?city="+encodeURI(document.getElementById("inputbox").value);
    }
    else
    {
        alert("查询城市不可为空");
    }    
}

function changeTiao()
{
    var tbmsg=document.getElementById("tbmsg");
    var spanmymsg=document.getElementById("spanmymsg");
    if(tbmsg.style.display=="none")
    {
        tbmsg.style.display="block";
        spanmymsg.className="icon_close";
    }
    else{
        tbmsg.style.display="none";
        spanmymsg.className="icon_open";
    }
}

/////
function writeUserName() {
    if (!(document.cookie!=null&&document.cookie != '' && document.cookie != 'undefined')) {
        var exp = new Date(); exp.setTime(exp.getTime() + 30 * 24 * 60 * 60 * 1000);
        document.cookie = "supportcookie=true;domain=58.com;expires=" + exp.toGMTString();
        if (!(document.cookie != null && document.cookie != '' && document.cookie != 'undefined')) {
            document.write('<script type="text/javascript" src="http://user.58.com/UserLoginState.ashx"></script>');
            return true;
        }
    }
    var host = window.location.hostname;
    var hosthome = host.substr(0, host.indexOf("."));
    var outurl = window.location.href;
    var str = '<a href="http://www.58.com/fabu/" target="_self">发布信息</a> <a href="http://my.58.com/login/?path=' + outurl + '" target="_self">登录</a> <a href="http://my.58.com/reg/?city=' + hosthome + '" target="_self">注册</a>';

    var str2 = '<a href="http://www.58.com/fabu/" target="_self">发布信息</a> <a href="http://my.58.com/login/?path=' + outurl + '" target="_self">登录</a> <a href="http://my.58.com/reg/?city=' + hosthome + '" target="_self">注册</a>';

    try {
        if (GetCookies("UserName") != "") {
            var msgcount = parseInt(GetCookies("MsgUnReadTotal")) + parseInt(GetCookies("SystemUnReadTotal")) + parseInt(GetCookies("RequireFriendUnReadTotal")) + parseInt(GetCookies("CommentUnReadTotal"));
            str = '<a href="http://my.58.com/' + GetCookies("UserID") + '/">' + GetCookies("UserName") + '</a> <img alt="站内消息" hspace="4" src="http://pic2.58.com/images/icomail_open.gif" /><a  href="http://my.58.com/Liuyanjieshou/">(' + msgcount + ')</a> <a href="http://my.58.com/" target="_self">用户中心</a> <a href="http://www.58.com/fabu/" target="_self">发布</a> <a href="http://my.58.com/ajax/loginout/?path=' + outurl + '" target="_self">退出</a>';

            str2 = '<a href="http://my.58.com/' + GetCookies("UserID") + '/">' + GetCookies("UserName") + '</a> <img alt="站内消息" hspace="4" src="http://pic2.58.com/images/icomail_open.gif" /><a  href="http://my.58.com/Liuyanjieshou/">(' + msgcount + ')</a> <a href="http://my.58.com/" target="_self">用户中心</a> <a href="http://www.58.com/fabu/" target="_self">发布</a> <a href="http://my.58.com/ajax/loginout/?path=' + outurl + '" target="_self">退出</a>';
        }
        if (cityc()) { document.write(str2); }
        else { document.write(str); }

        return true;
    }
    catch (e) { document.write(str); return true; }
}
function GetCookies(name) {
    var arr = document.cookie.match(new RegExp(name + "=([^&;]+)"));
    if (arr != null) { return decodeURI(arr[1]); }
    return "";
}

//////
function selGo(urlstr)
{
	window.location = "http://"+window.location.hostname+urlstr;
}

function searchHcp(urlStr)
{
        var t=document.getElementById("shijian").value;
        var c=document.getElementById("s_keyword").value;
        var query="";
        if(t!="发车日期")
        {
           query="t="+t;
        }
        if(c!="请输入车次")
        {
            if(query!="")
            {
                query+="&c="+encodeURI(c);
            }
            else
            {
                query+="?c="+encodeURI(c);
            }
        }
        if(query!="")
        {
            if(urlStr.toString().indexOf("?")>-1)
            {
                urlStr+="&"+query; 
            }
            else
            {
                urlStr+="?"+query;
            }
            selGo(urlStr);
        }
        else
        {
            alert("请输入搜索信息！");
        }
}

function setTab(area,id) {                         ///切换通用多组
	var tabArea=document.getElementById(area);
	var contents=tabArea.childNodes;
	for(i=0; i<contents.length; i++) {
		if(contents[i].className=='tabcontent'){contents[i].style.display='none';}
	}
	document.getElementById(id).style.display='';
	var tabs=document.getElementById(area+'tabs').getElementsByTagName('a');
	for(i=0; i<tabs.length; i++) { tabs[i].className='tab'; }
	document.getElementById(id+'tab').className='tab curtab';
	document.getElementById(id+'tab').blur();
}
function searchpost()
{
     if(document.getElementById("s").value==""&document.getElementById("start").value==""&&document.getElementById("end").value=="")
    {
        alert("请输入出发城市目的城市或车次");
        return false;
    }
    var checi = document.getElementById("s");
    if(checi != "undifine" && checi.value != "")
    {
        if(isCheci(checi.value))
        {
            parent.location.href = "/"+ checi.value+"/";
        }
        else
        {
            alert("请输入正确格式的列车车次!~");
            return false;
        }
    }
    else
    {
        if(document.getElementById("start").value==""||document.getElementById("end").value=="")
        {
            alert("请输入出发城市与目的城市");
            return false;
        }
        var vars = document.getElementById("start");
        var vare = document.getElementById("end");
        var url = "/TranToListPage.aspx"
        if(vars.value != "undifine"&&vare.value != "undifine")
        {
            url = "/"+vars.value+"_"+vare.value;
        }
        //url += "_" + j + ".html";
        parent.location.href = url;
    }
}
function　isCheci(train)
{
    var patrn=/^([a-zA-Z]+)?\d+([a-zA-Z]+)?(\/([a-zA-Z]+)?\d+([a-zA-Z]+)?)*$/;
    if (!patrn.exec(train)) return false;
    return true;
}
function nTabs(thisObj,Num)
{ 
    if(thisObj.className == "curtab")return; 
    var tabObj = thisObj.parentNode.id; 
    var tabList = document.getElementById(tabObj).getElementsByTagName("a"); 
    for(i=0; i <tabList.length; i++) 
    { 
        if (i == Num) 
        { 
            thisObj.className = "curtab"; 
            document.getElementById(tabObj+"_Content"+i).style.display = "block"; 
        }
        else
        { 
            tabList[i].className = ""; 
            document.getElementById(tabObj+"_Content"+i).style.display = "none"; 
        } 
    } 
} 

//--------------------------浮动层
var prox;
 var proy;
 var proxc;
 var proyc;
 function show(id){/*--打开--*/
  clearInterval(prox);
  clearInterval(proy);
  clearInterval(proxc);
  clearInterval(proyc);
  var o = document.getElementById(id);
  o.style.display = "block";
  o.style.width = "1px";
  o.style.height = "1px";
  prox = setInterval(function(){openx(o,210)},10);
 }
 function openx(o,x){/*--打开x--*/
  var cx = parseInt(o.style.width);
  if(cx < x)
  {
   o.style.width = (cx + Math.ceil((x-cx)/5)) +"px";
  }
  else
  {
   clearInterval(prox);
   proy = setInterval(function(){openy(o,370)},10);
  }
 }
 function openy(o,y){/*--打开y--*/
  var cy = parseInt(o.style.height);
  if(cy < y)
  {
   o.style.height = (cy + Math.ceil((y-cy)/5)) +"px";
  }
  else
  {
   clearInterval(proy);  
  }
 }
 function closeed(id){/*--关闭--*/
  clearInterval(prox);
  clearInterval(proy);
  clearInterval(proxc);
  clearInterval(proyc); 
  var o = document.getElementById(id);
  if(o.style.display == "block")
  {
   proyc = setInterval(function(){closey(o)},10);  
  } 
 }
 function closey(o){/*--打开y--*/
  var cy = parseInt(o.style.height);
  if(cy > 0)
  {
   o.style.height = (cy - Math.ceil(cy/5)) +"px";
  }
  else
  {
   clearInterval(proyc);   
   proxc = setInterval(function(){closex(o)},10);
  }
 }
 function closex(o){/*--打开x--*/
  var cx = parseInt(o.style.width);
  if(cx > 0)
  {
   o.style.width = (cx - Math.ceil(cx/5)) +"px";
  }
  else
  {
   clearInterval(proxc);
   o.style.display = "none";
  }
 }
 
 //---------------------------------------公交 站　线　站站
 function cha1(cityp,keyword){

    keyword = keyword.replace(/\s+/g,"");
    if( keyword == "" || keyword =="请输入公交站点名称" || keyword =="请输入公交线路名称" )
    {
        return false;
    }
	var link = "http://";
	cityp = cityp.replace(/\s+/g,"");
	if(cityp!="")
	  jumpgo = cityp +".bus.58.com";
	 else
	  jumpgo = "bj.bus.58.com"; 

	link += jumpgo +"/z_"+keyword +"/";

	window.location.href = link;
	return false;
}

function cha2(cityp,keyword){

    keyword = keyword.replace(/\s+/g,"");
    if( keyword == "" || keyword =="请输入公交站点名称" || keyword =="请输入公交线路名称" )
    {
        return false;
    }
    
	var link = "http://";
    cityp = cityp.replace(/\s+/g,"");
	if(cityp!="")
	  jumpgo = cityp +".bus.58.com";
	 else
	  jumpgo = "bj.bus.58.com"; 

	link += jumpgo + "/x_"+keyword.trim() +"/";

	window.location.href = link;
	return false;
}

function cha3(cityp,start,end){
    start = start.replace(/\s+/g,"");
    end = end.replace(/\s+/g,"");
    if( start == "" || end == "")
    {
        return false;
    }
    var link = "http://";
    	cityp = cityp.replace(/\s+/g,"");
	if(cityp!="")
	  jumpgo = cityp +".bus.58.com";
	 else
	  jumpgo = "bj.bus.58.com"; 

	link += jumpgo + "/h_"+start+'_'+end+"/";
	window.location.href = link;
	return false;
}

//火车票订票电话页面智能提示
var currentInput;
var speed = 300;
document.domain = "58.com";
$(document).ready(function() {
    $("#inputbox").bind("focus", DingPiaoCityFocus);
    $("#inputbox").bind("blur", hideDiv);
    $("#inputbox").bind("keyup", hideDiv);
});

function DingPiaoCityFocus(event) {
    currentInput = event.target;
    if ($("#inputbox").val() == "请输入您要订票的城市")
        $("#inputbox").val("");
    $("#inputbox").css("color", "#000");
    if ($("#inputbox").val().indexOf("输入") > -1)
        $("#inputbox").val("");
    initSmartDiv(eval('(' + StationJson + ')').Station);
    ShowSmartSearch(event);
};

var hideDiv = function(event) {
    var key = window.event ? event.keyCode : event.which;
    if (key == 13) {
        searchHcpTel();
    }
    $("#divSmartList").hide();
};

var DingPiaoCityKeyUp = function(event) {
    var key = window.event ? event.keyCode : event.which;
    if (key == 13) {
        searchHcpTel();
    }
    if (key != 40 && key != 38) {
        getStationList($(event.target).val(), event);
    } else {
        if (key == 40) {
            Move(1);
        }
        if (key == 38) {
            Move(-1);
        }
    }
};

var Move = function(len) {
    if ($("#divSmartList").find("span").length < 1) return;
    var i = 0;
    var $item = $("#divSmartList span.current:eq(0)");
    var obj = new Object();
    obj.data = new Object();
    if ($("#divSmartList span").size() > 1) {
        if ($item.size() > 0) {
            $item.removeClass();
            if (len == 1 && $item.next("span")) {
                obj.data.arg = "#" + $item.next("span").attr("id");
            } else if (len == -1 && $item.prev("span")) {
                obj.data.arg = "#" + $item.prev("span").attr("id");
            }
        } else {
            obj.data.arg = "#" + $("#divSmartList span:eq(0)").attr("id");
        }
        SetColorOver(obj);
        ItemSelected(obj);
    }
}

var getStationList = function(arg, target) {
    if ($.trim(arg) != "") {
        $.getJSON("/ajax.aspx", { action: "station", "num": 6, key: escape($.trim(arg)) }, function(json) {
            initSmartDiv(json.Station);
            ShowSmartSearch(target);
        });
    }
};

var initSmartDiv = function(json) {
    var title = json.length > 0 ? "<div>用鼠标或↑↓选择</div>" : "<span>没有找到匹配项</span>";
    $("#divSmartList").html(title);
    for (var i = 1; i <= json.length; i++) {
        var item = $("<span></span>");
        item.bind("mousedown", { arg: "#item" + i }, ItemSelected);
        item.bind("mouseover", { arg: "#item" + i }, SetColorOver);
        item.bind("mouseout", { arg: "#item" + i }, SetColorOut);
        item.html(json[i - 1].Item);
        item.attr("id", "item" + i);
        item.attr("title", json[i - 1].Item);
        $("#divSmartList").append(item);
    }
};

var ShowSmartSearch = function(event) {
    var offset = $(event.target).offset();
    $("#divSmartList").css({ top: offset.top + 8 + $(event.target).height() + "px", left: offset.left });
    $("#divSmartList").css({ width: $(event.target).width() + 8 + "px" });
    $("#divSmartList").show(speed);
};

var ItemSelected = function(arg) {
    if ($(arg.data.arg).html())
        $(currentInput).val($(arg.data.arg).html());
};

var SetColorOver = function(arg) {
    $("#divSmartList span.current:eq(0)").removeClass();
    $(arg.data.arg).addClass("current");
};

var SetColorOut = function(arg) {
    $(arg.data.arg).removeClass();
}

//删除字符串两端的空格
String.prototype.trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
}

var StationJson = "{\"Station\":[{Item:\"北京\"},{Item:\"上海\"},{Item:\"深圳\"},{Item:\"广州\"},{Item:\"武汉\"},{Item:\"西安\"}]}";
