﻿function fid(id) {
    return document.getElementById(id);
}

/*是否为IE6浏览器*/
function IsIE6() {
    return /MSIE (5\.5|6\.)/.test(navigator.userAgent);
}

/*顶部电话信息*/
function changeTopTel(span, val) {
    if (span.className == "active")
        return;
    $("#toptelBtnDiv").find(".active").removeAttr("class");
    span.className = "active";

    //$("#toptelDiv").find("div").css("display", "none");

    $("#toptelDiv").find("div:visible").fadeOut('fast', function() {
        var div = $("#toptel_" + val);
        div.fadeIn("fast");
    });
    return;
}

/*业务办理*/
function changeTelCity(a, val) {
    var aList = a.parentNode.getElementsByTagName("A");
    var ul = fid("telDIV").getElementsByTagName("UL");
    for (var i = 0; i < ul.length; i++) {
        if (i == val) {
            aList[i].className = "active";
            ul[i].style.display = "";
        } else {
            aList[i].className = "";
            ul[i].style.display = "none";
        }
    }
}

/*线路车票背景切换*/
function changeIMG(a, val) {
    if (!IsIE6()) {
        return;
    }

    if (val == 0)
        a.style.backgroundImage = 'url("/Images/pic_small_bg_h.png")';
    else
        a.style.backgroundImage = 'url("/Images/pic_small_bg.png")';
}

// 多行滚动
(function($) {
    $.fn.extend({
        Scroll: function(opt, callback) {
            if (!opt) opt = {};
            var _this = this.eq(0).find("ul:first");
            var lineH = _this.find("li:first").height(),
                    line = opt.line ? parseInt(opt.line, 10) : parseInt(this.height() / lineH, 10),
                    speed = opt.speed ? parseInt(opt.speed, 10) : 1000, //卷动速度，数值越大，速度越慢（毫秒）
                    timer = opt.timer ? parseInt(opt.timer, 10) : 5000; //滚动的时间间隔（毫秒）
            if (line == 0) line = 1;
            var upHeight = 0 - line * lineH;
            scrollUp = function() {
                _this.animate({
                    marginTop: upHeight
                }, speed, function() {
                    for (i = 1; i <= line; i++) {
                        _this.find("li:first").appendTo(_this);
                    }
                    _this.css({ marginTop: 0 });
                });
            }
            _this.hover(function() {
                clearInterval(timerID);
            }, function() {
                timerID = setInterval("scrollUp()", timer);
            }).mouseout();
        }
    })
})(jQuery);

/*横向滚动*/
function scrollLeft(beginId, endId, scrollerId, speed) {
    var begin = fid(beginId);
    var end = fid(endId);
    var scroller = fid(scrollerId);
    end.innerHTML = begin.innerHTML;
    function Marquee() {
        if (scroller.scrollLeft > begin.offsetWidth)
            scroller.scrollLeft = 0;
        else
            scroller.scrollLeft++;
    }
    var go = setInterval(Marquee, speed);
    scroller.onmouseout = function() { go = setInterval(Marquee, speed) }
    scroller.onmouseover = function() { clearInterval(go) }
}

function visibleDIV() {
    var onePicId = fid("onePicTabel");
    var twoPicId = fid("twoPicTabel");
    var picDIV = fid("picDIV");
    var speed = 10000;
    function visible() {
        if (onePicId.style.display == "none") {
            twoPicId.style.display = "none";
            $(onePicId).fadeIn("fast");
        } else {
            onePicId.style.display = "none";
            $(twoPicId).fadeIn("fast");
        }
    }
    var go = setInterval(visible, speed);
    picDIV.onmouseout = function() { go = setInterval(visible, speed) }
    picDIV.onmouseover = function() { clearInterval(go) }
}

function zoomImg(o) {
    var zoom = parseInt(o.style.zoom, 10) || 100;
    zoom += event.wheelDelta / 12;
    if (zoom > 0) o.style.zoom = zoom + '%';
    return false;
}

function setSWFobject(swf, divId, width, height, style) {
    var params = {};
    params.menu = "false";
    params.quality = "high";
    params.wmode = "transparent";
    swfobject.embedSWF(swf, divId, width, height, "9.0.0", "/js/swfobject/expressInstall.swf", null, params, { style: style });
}

//按回车键执行提交form表单(有验证操作)
function submitForm(evt, id, group) {
    var oEvent = (window.event) ? window.event : evt;
    if (oEvent.keyCode == 13) {
        if (WebForm_DoPostBackWithOptions) {
            WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(id, '', true, group, '', false, true));
            WebForm_DoPostBackWithOptions
        }
    }
}

//按回车键执行其它提交操作
function submitInfo(evt, id) {
    var oEvent = (window.event) ? window.event : evt;
    if (oEvent.keyCode == 13) {
        if (__doPostBack) {
            //__doPostBack(id, '');
        }
    }
}

//查询线路
function submitSearchLineForm(evt, id, idG, idT,tag,idGc,idTc) {
    var oEvent = (window.event) ? window.event : evt;
    if (oEvent.keyCode == 13) {
        searchLine(id, idG, idT, tag, idGc, idTc);
    }
}

//导航栏
function showHideNavDIV(li, val) {
    //if (li.className != "active") {
    //li.className = ((val == 0) ? "hover" : "");
    //}

    var div = $(li).find("DIV").get(0);

    if (div == undefined)
        return;
    if (val == 1) {
        $(div).css("display", "none");
    } else {
        $(div).css("display", "inline-block");
    }
}

var HomepageFavorite = {
    url: 'http://www.gdhk.cn',
    title: '粤港汽车运输联营有限公司',
    //设为首页
    Homepage: function() {
        if (document.all) {
            document.body.style.behavior = 'url(#default#homepage)';
            document.body.setHomePage(this.url);
        }
        else if (window.sidebar) {
            if (window.netscape) {
                try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
                }
                catch (e) {
                    alert("该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true");
                }
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', this.url);
        }
    },
    //加入收藏
    Favorite: function Favorite() {
        try {
            window.external.addFavorite(this.url, this.title);
        }
        catch (e) {
            try {
                window.sidebar.addPanel(this.title, this.url, "");
            }
            catch (e) {
                alert("加入收藏失败！请手动添加。");
            }
        }
    }
}


//加载更多线路名称
function loadMoreLine(div, val) {
    var b = $(div).find("b").get(0);
    var lDIV = $(div).find("div.l").get(0);
    if (val == 0) {
        b.style.display = "none";
        lDIV.style.display = "inline-block";
        div.className = "moreLineContent-Hover";
    }
    else {
        b.style.display = "inline-block";
        lDIV.style.display = "none";
        div.className = "moreLineContent";
        return;
    }

    var img = $(div).find("img.load").get(0);
    if (img) {
        img.style.display = "inline-block";
        $.ajax({
            type: "POST",
            url: "/LineInfo.aspx?loadMore=0",
            async: false,
            data: "&ajax=0",
            success: function(data) {
                $(lDIV).html(data);
            }
        });
    }
}

//function searchLine(id, idG, idT,tag) {
//    var date = fid(id).value;
//    var txtGo = fid(idG).value;
//    var txtTo = fid(idT).value;
//    location.href = "/SearchLine.aspx?tag=" + escape(tag) + "&d=" + escape(date) + "&g=" + escape(txtGo) + "&t=" + escape(txtTo);
//    return;
//}
function searchLine(id, idG, idT, tag,idGc,idTc) {
    var date = fid(id).value;
    var txtGo = fid(idG).value;
    var txtTo = fid(idT).value;
    var txtGoCity = fid(idGc).value;
    var txtToCity = fid(idTc).value;
    location.href = "/SearchLine.aspx?tag=" + escape(tag) + "&d=" + escape(date) + "&g=" + escape(txtGo) + "&t=" + escape(txtTo)+"&gc="+escape(txtGoCity)+"&tc="+escape(txtToCity);
    return;
}


//function lineStationHover(span, val) {
//    if (val == 0) {
//        span.className = 'hover';
//    } else {
//        span.className = '';
//    }

//    try {
//        var label = $(span).find("LABEL").get(0);
//        if (val == 0)
//            $(label).animate({ 'marginTop': '-34px' }, 'fast');
//        else
//            $(label).animate({ 'marginTop': '-27px' }, 'fast');
//    } catch (e) { }
//}
