﻿var onloaded = new Array();
function __login() {
    UserInfo.Login($get('username').value, $get('password').value,
            function() {
                $get("userinfo").innerHTML = "登录成功，正在获取个人信息……";
                var view = "/Views/bannerlogined.html?" + new Date();
                GetView(view, function(html) {
                    try {
                        if (page_logined) {
                            page_logined();
                        }
                    }
                    catch (e) {
                    }
                    $get("userinfo").innerHTML = html;
                });
            });
        }


        function ApplicationLogin(onlogined) {

            UserInfo.Login($("#appusername").val(), $("#apppassword").val(),
             function() {
                 $get("userinfo").innerHTML = "登录成功，正在获取个人信息……";
                 var view = "/Views/bannerlogined.html?" + new Date();
                 GetView(view, function(html) {
                     try {
                         if (page_logined) {
                             page_logined();
                         }
                     }
                     catch (e) {
                     }
                     $get("userinfo").innerHTML = html;
                 });

                 closeWindow("loginform");
                 if (onlogined) {
                     onlogined();
                 }
             });
         }
       
       $("#formclose").click(function() {
       closeWindow("loginform");
       }
        );

function __logout() {
    UserInfo.Logout(function() {
        var view = "/Views/bannerunlogined.html?" + new Date();
        GetView(view, function(html) {
            try {
                if (page_logouted) {
                    page_logouted();
                }
            }
            catch (e) {
            }
            $get("userinfo").innerHTML = html;
        });
    });
}
function __showbannelloginpanel() {
    InvokeService("UserInfo", "IsLogined", {},
    function(result) {
        var url;
        if (result) {
            url = "/Views/bannerlogined.html?" + new Date();
        }
        else {
            url = "/Views/bannerunlogined.html?" + new Date();
        }
        GetView(url, function(html) {
            $get("userinfo").innerHTML = html;
        });
    },
    function() {
    });
}
function __showCurrentArea() {
    InvokeService("AreaService", "CurrentArea", {},
    function(result) {
        $("#cityname").html(result);
    },
    function() {
    });
}
if (typeof (currenttab) == "undefined") {
    var currenttab = 0;
    if (window.location.href.toLowerCase().indexOf("/wx") != -1) {
        currenttab = 2;
        $("#bannersearchtype").val("维修站");
    }
    if (window.location.href.toLowerCase().indexOf("/cp") != -1) {
        currenttab = 1;
    }
    if (window.location.href.toLowerCase().indexOf("/article") != -1) {
        currenttab = 4;
        $("#bannersearchtype").val("资讯");
        
    }
    if (window.location.href.toLowerCase().indexOf("/articles") != -1) {
        currenttab = 4;
        $("#bannersearchtype").val("资讯");
    }
}
//频道页切换
$(".bannerchannel").mouseover(function() {
    var tab = $(this);
    var index = parseInt(tab.attr("index"));
    if (tab.attr("index") != currenttab) {
        tab.attr("class", "bannerchannel2");
    }
});
$(".bannerchannel").mouseout(function() {
    var tab = $(this);
    var index = parseInt(tab.attr("index"));
    if (tab.attr("index") == currenttab) {
        //tab.css("background-position", "0 -34px");
    }
    else {
        tab.attr("class", "bannerchannel");
    }
});
$(".bannerchannel").click(function() {
    var tab = $(this);
    var index = parseInt(tab.attr("index"));
    var url;
    url = tab.children("a").eq(0).attr("href")
    window.location.href = url;
});
$(".bannerchannel").each(function() {
    if ($(this).attr("index") == currenttab) {
        $(this).attr("class", "bannerchannel2");
        $(this).css("background-position", "0 -34px");
        return false;
    }
});
$("#changecity").click(function() {
    var url = window.location.href;
    url = encodeURIComponent(url);
    url = "/changecity.html?url=" + url;
    window.location.href = url;
    return false;
});
$("#bannersearchtext").keydown(function(keycode) {
    if (keycode.keyCode == 13) {
        bannersearch();
        return false;
    }
});
__showbannelloginpanel();
__showCurrentArea();