﻿$(function() {

    /*头部搜索 内页用*/
    var sal = $("#search_menu").find("a");
    sal.click(function() {
        sal.removeClass("active");
        $(this).blur().addClass("active");
        $("#search_type").val(sal.index(this));
        return false;
    });

    /*所有页面公用，页面头部3张图片滚动js*/
    var temp = $("#__temp_top_image_run");
    temp.append(temp.children().eq(0).clone(true));
    function top_run() {
        setInterval(function() {
            var temp = $("#__temp_top_image_run");
            var next = temp.attr("scrollTop") + temp.height() >= temp.attr("scrollHeight") ? 0 : temp.attr("scrollTop") + temp.height();
            temp.animate({ scrollTop: next }, 500, function() {
                if (temp.attr("scrollTop") + temp.height() >= temp.attr("scrollHeight"))
                    temp.attr("scrollTop", 0);
            });
        }, 3000);
    }
    top_run();

    //切换框架
    $(".title_bar_menu").each(function() {
        var $this = $(this);
        var listitems = $this.find("a").not(".moreqg");
        var content = $this.parent().next();
        var height = content.height();
        listitems.click(function() {
            content.stop();
            var of = content[0].scrollTop / height - listitems.removeClass("active").index(this);
            if (of < 0)
                of = -of;
            content.animate({ "scrollTop": height * listitems.removeClass("active").index(this) }, 200 * of);
            $(this).blur().addClass("active");
            return false;
        }).eq(0).click();
    });

    //带框架页面 头部搜索
    $("#search_keyword").keypress(function(e) {
        if (e.keyCode == 13) {
            $("#search_submit").click();
            return false;
        }
    });
    //带框架页面 登陆
    $("#txt_CompanyLoginName,#txt_CompanyLoginPwd").keypress(function(e) {
        if (e.keyCode == 13) {
            $("#btn_Logins").click();
            return false;
        }
    });

    //头部搜索
    $("#search_submit").click(function() {
        $.ajax({
            url: "Inc/Search_Login.ashx",
            data: { Action: "Call_TopSearch", ADKeys: escape($("#search_keyword").val()), NowFlag: $("#search_type").val() },
            type: "GET",
            async: true,
            cache: false,
            success: function(d) {
                if (d == 0) { alert("搜索出现错误！"); } else { if (d == 1) { alert("请输入搜索内容！"); } else { location.replace(d); } }
                delete (_this);
            }
        })

    });

    //登录
    $("#btn_Logins").click(function() {
        document.getElementById("LoadingCompany").style.display = "";
        document.getElementById("CompanyLoginNo").style.display = "none";
        document.getElementById("CompanyLoginYes").style.display = "none";
        document.getElementById("LoadingCompany").innerHTML = "<img src=\"skin/images/loading.gif\" />&nbsp;登录中……";
        $.ajax({
            url: "Inc/Search_Login.ashx",
            data: { Action: "Call_CompanyLogin", LoginName: escape($("#txt_CompanyLoginName").val()), BackUrl: escape($("#txt_CompanyLoginPwd").val()) },
            type: "GET",
            async: true,
            cache: false,
            success: function(d) {
                if (d == 0) { alert("登录出现错误！"); } else { location.replace(d); }
                delete (_this);
            }
        })

    });

    $(function() {
        $.ajax({
            url: "Inc/Search_Login.ashx",
            data: { Action: "CheckCSession" },
            type: "GET",
            async: true,
            cache: false,
            success: function(d) {
                document.getElementById("LoadingCompany").style.display = "none";
                if (d == 0) {
                    document.getElementById("CompanyLoginNo").style.display = "";
                } else
                { document.getElementById("CompanyLoginYes").style.display = ""; document.getElementById("Login_CompanyName_Html").innerHTML = d; }
            }
        })
    });

})

/*
在页面输出一个flash动画，需要参数：动画路径、宽度、高度
调用形式如下：
<SCRIPT language=JavaScript>
<!--
fnFlashObject('/ad1/flash/bjypt.swf',468,60)
//-->
</SCRIPT>
*/
function fnFlashObject(byPath, byWidth, byHeight)
{
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="' + byWidth + '" height="' + byHeight + '">');
    document.write(' <param name="movie" value="' + byPath + '">');
    document.write(' <param name="quality" value="high">');
    document.write(' <param name="menu" value="false">');
	document.write(' <param name="SCALE" value="exactfit">');
	document.write(' <param name="wmode" value="opaque">');
    document.write(' <embed src="' + byPath + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + byWidth + '" height="' + byHeight + '"></embed>');
    document.write('</object>');
}

