﻿function sethomepage(obj,vrl){
    try{obj.style.behavior='url(#default#homepage)';if(!obj.setHomePage(vrl)){obj.style.behavior="";};}
    catch(e){
        if(window.netscape) {
            try {netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); } 
            catch (e) { alert("此操作被浏览器拒绝！\n请在浏览器地址栏输入“about:config”并回车\n然后将[signed.applets.codebase_principal_support]设置为'true'"); }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage',vrl);
        }
    }
}
function setbookmark(){
    var title=document.title
    var url=document.location.href
    if (window.sidebar) window.sidebar.addPanel(title, url,"");
    else if( window.opera && window.print ){
    var mbm = document.createElement('a');
    mbm.setAttribute('rel','sidebar');
    mbm.setAttribute('href',url);
    mbm.setAttribute('title',title);
    mbm.click();}
    else if( document.all ) window.external.AddFavorite( url, title);
}
function QueryStr(name){
    var loc = location.href.toLowerCase();
    var p = loc.match(/^http:\/\/(.*)\.duoduo\.cc\/search\/+([\w-./?%&=]*)?$/);
    if(p){
        var temp, val = p[2];
        if(!name){
            var t = {}, arr = [], regx = new RegExp("^([\\w]+)_(.*)$");
            if(val.indexOf("/") != -1){ arr = val.split("/"); }else{ arr.push(val); }
            for(var i = 0; i < arr.length; i++){ temp = arr[i].match(regx); if(!temp){ continue; }else{ t[temp[1]] = temp[2]; } }
            return t;
        }else{
            temp = val.match(new RegExp("(^|/)" + name + "_(.*)(/|$)"));
            return !temp ? null : temp[2];
        }
    }
    return null;
}
function logout(type){
    type = type||"1";
    $.ajax({
        type: "get",
        url: "/aspx/ajaxUser.aspx?type=" + type + "&tout=yes&" + Math.random(),
        success: function(msg){
            eval("msg = " + unescape(msg));
            if(msg.logout){$(".head_user span").html("你好，游客！");}
        }
    });
}
jQuery(function(){
/************************************************
    $.ajax({
        type:"get",
        url:"/aspx/ajaxUser.aspx?type=1&check=1&" + Math.random(),
        success:function(info){
            eval("info = " + unescape(info));
            if(parseInt(info.type) == 1){
                var news = "";
                if(info.news != "" && info.news != "0"){news = "|&nbsp;<a class='useinfo' href='/Consumer/myMailBox.aspx'>新消息：" + info.news + "</a>&nbsp;";}
                var str = info.result + "！" + news + "|&nbsp;多多币：" + info.value + "&nbsp|&nbsp;<a class='useinfo' href='/Consumer/Default.aspx'>进入我的多多</a>&nbsp;|&nbsp;<a class='useinfo' href='javascript:logout(" + info.type + ");'>退出</a>";
                $("#lbl_UserInfo").html(str);
            }
        }
    });
************************************************/
    var query = QueryStr()||{};
    if(!query.a){query.a = $.QueryString("a");}
    if(!query.m){query.m = $.QueryString("m");}
    if(!query.ppc){query.ppc = $.QueryString("ppc");}
    if(!query.op){query.op = $.QueryString("op");}
    if(!query.key){query.key = $.QueryString("key");}
    if(query.ppc){$("#search_ppc")[0].options[parseInt(query.ppc)].selected = true;}
    if(query.key){$("#search_edit").val(decodeURIComponent(query.key));}
    if(M_Area)
    {
        var len = M_Area.Value.length;
        var oOption;
        for(var i = 0; i < len; i++)
        {
            if(M_Area.Value[i][0]%1000 == 0)
            {
                if(M_Area.Value[i][0] == parseInt(query.a))
                {
                    oOption = "<option value=\"" + M_Area.Value[i][0] + "\" selected=\"selected\" style=\"color:Red;\">---" + M_Area.Value[i][1] + "</option>";
                }else{
                    oOption = "<option value=\"" + M_Area.Value[i][0] + "\" style=\"color:Red;\">---" + M_Area.Value[i][1] + "</option>";
                }
            }
            else
            {
                if(M_Area.Value[i][0] == parseInt(query.a))
                {
                    oOption = "<option value =\"" + M_Area.Value[i][0] + "\" selected=\"selected\">" + M_Area.Value[i][1] + "</option>";
                }else{
                    oOption = "<option value =\"" + M_Area.Value[i][0] + "\">" + M_Area.Value[i][1] + "</option>";
                }
            }
            $("#search_area").append(oOption);
        }
    }
    if(MenuClass)
    {
        var len = MenuClass.length;
        var oOption;
        for(var i = 0; i < len; i++)
        {
            if(MenuClass[i][0]%1000 == 0)
            {
                oOption = "<optgroup style=\"color:Red;\" label=\"---" + MenuClass[i][1] + "\"></optgroup>";
            }
            else
            {
                if(MenuClass[i][0] == parseInt(query.m))
                {
                    oOption = "<option value=\"" + MenuClass[i][0] + "\" selected=\"selected\">" + MenuClass[i][1] + "</option>";
                }else{
                    oOption = "<option value=\"" + MenuClass[i][0] + "\">" + MenuClass[i][1] + "</option>";
                }
            }
            $("#search_menu").append(oOption);
        }
    }
/*************************************************/
    $("a.active_menu[id]").click(function(){
        $("div.menu_business").hide();
        var id = (parseInt(this.id.substring(2))/10).toString();
        $("#mi_"+id).show();
        $("a.active_red","div.menu_search").removeClass("active_red").addClass("active_menu").parent("span").removeClass("search_point");
        $(this).blur().removeClass("active_menu").addClass("active_red").parent("span").addClass("search_point");
    });
    if(query.a){
        if(query.a%1000==0){
            $("a.active_area[href^='/Search/a_" + query.a + "']").remove("active_area").addClass("active_red").parent("span").addClass("search_point");
        }else{
            var pid = parseInt(query.a/1000)*1000;
            $("a.active_area[href^='/Search/a_" + pid + "']").remove("active_area").addClass("active_red").parent("span").addClass("search_point");
            $("a.active_area_item[href^='/Search/a_" + query.a + "']").remove("active_area_item").addClass("active_red");
        }
    }
    if(query.m){
        var pid = parseInt(query.m/10000)*10000;
        $("a.active_menu[id='m_" + pid + "']").remove("active_menu").addClass("active_red").parent("span").addClass("search_point");
        $("a.active_menu_item[href*='/m_" + query.m + "']").remove("active_menu_item").addClass("active_red");
        var m = (parseInt(query.m/1000)*100).toString();$("#mi_"+m).show();
    }else{
	$("#m_10000").removeClass("active_menu").addClass("active_red").parent("span").addClass("search_point");
	$("#mi_1000").show();
    }
    if(query.op){$("a#op_" + query.op).remove("active_term_item").addClass("active_red");}
    if(query.ppc){$("a#ppc_" + query.ppc).remove("active_term_item").addClass("active_red").parent("span").addClass("search_point");}
/*************************************************/
    $("#search_quick_submit").click(function(){
        var area = $("#search_area").val();
        var menu = $("#search_menu").val();
        var ppc = $("#search_ppc")[0].selectedIndex;
        var s = false || (area != "0")?true:false || (menu != "0")?true:false || (ppc != 0)?true:false;
        if(s){
            //var url = "sr.aspx?a=" + area + "&m=" + menu + "&ppc=" + ppc + "&f=ds";
            var url = "/Search" + (area!="0"?"/a_"+area:"") + (menu!="0"?"/m_"+menu:"") + (ppc!="0"?"/ppc_"+ppc:"");
            window.location.href = url;
        }else{
            Alert("请至少选择一个搜索条件！");
        }
    });
    $("#search_edit").focus(function(){
        var obj = $(this), val = obj.val(), txt = '请输入您感兴趣的餐厅名称或关键字';
        if(val == txt){obj.val('');return;}
    }).blur(function(){
        var obj = $(this), val = obj.val(), txt = '请输入您感兴趣的餐厅名称或关键字';
        if(val == ''){obj.val(txt);return;}
    }).keydown(function(){
        var e = arguments[0]||window.event;
        var code = e.keyCode||e.charCode;
        if(code == 13){$("#search_submit").focus();}
    });
    $("#search_submit").click(function(){
        var url = "";
        var str = $("#search_edit").val();
        str = str.replace(/[%&*.|?<>:;\'\"\s]/g,"");
        if(str == "请输入您感兴趣的餐厅名称或关键字" || str == ""){
            Alert("请输入搜索关键字！",null,null,null,function(){$("#search_edit").focus();});
        }else{
            url = "/Search/key_" + encodeURIComponent(str);
            $('<div style="display:none;"><form id="frm_search" method="post" action="' + url + '"></form></div>').appendTo("body");
            $("#frm_search").submit();
        }
    });
});
function Marquee(){
    this.ID = document.getElementById(arguments[0]);
    if(!this.ID){
       alert("您要设置的\"" + arguments[0] + "\"初始化错误\r\n请检查标签ID设置是否正确!");
       this.ID = -1;
       return;
    }
    this.Direction = this.Width = this.Height = this.DelayTime = this.WaitTime = this.CTL = this.StartID = this.Stop = this.MouseOver = 0;
    this.Step = 1;
    this.Timer = 30;
    this.DirectionArray = {"top":0 , "up":0 , "bottom":1 , "down":1 , "left":2 , "right":3};
    if(typeof arguments[1] == "number" || typeof arguments[1] == "string"){this.Direction = arguments[1];}
    if(typeof arguments[2] == "number"){this.Step = arguments[2];}
    if(typeof arguments[3] == "number"){this.Width = arguments[3];}
    if(typeof arguments[4] == "number"){this.Height = arguments[4];}
    if(typeof arguments[5] == "number"){this.Timer = arguments[5];}
    if(typeof arguments[6] == "number"){this.DelayTime = arguments[6];}
    if(typeof arguments[7] == "number"){this.WaitTime = arguments[7];}
    if(typeof arguments[8] == "number"){this.ScrollStep = arguments[8];}
    this.ID.style.overflow = this.ID.style.overflowX = this.ID.style.overflowY = "hidden";
    this.ID.noWrap = true;
    this.IsNotOpera = (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
    if(arguments.length >= 7){this.Start();}
}
Marquee.prototype.Start = function(){
    if(this.ID == -1){return;}
    if(this.WaitTime < 800){this.WaitTime = 800;}
    if(this.Timer < 20){this.Timer = 20;}
    if(this.Width == 0){this.Width = parseInt(this.ID.style.width);}
    if(this.Height == 0){this.Height = parseInt(this.ID.style.height);}
    if(typeof this.Direction == "string"){this.Direction = this.DirectionArray[this.Direction.toString().toLowerCase()];}
    this.HalfWidth = Math.round(this.Width / 2);
    this.HalfHeight = Math.round(this.Height / 2);
    this.BakStep = this.Step;
    this.ID.style.width = this.Width + "px";
    this.ID.style.height = this.Height + "px";
    if(typeof this.ScrollStep != "number"){this.ScrollStep = this.Direction > 1 ? this.Width : this.Height;}
    var templateLeft = "<table cellspacing='0' cellpadding='0' style='border-collapse:collapse;display:inline;'><tr><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>MSCLASS_TEMP_HTML</td><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>MSCLASS_TEMP_HTML</td></tr></table>";
    var templateTop = "<table cellspacing='0' cellpadding='0' style='border-collapse:collapse;'><tr><td>MSCLASS_TEMP_HTML</td></tr><tr><td>MSCLASS_TEMP_HTML</td></tr></table>";
    var msobj = this;
    msobj.tempHTML = msobj.ID.innerHTML;
    if(msobj.Direction <= 1){msobj.ID.innerHTML = templateTop.replace(/MSCLASS_TEMP_HTML/g,msobj.ID.innerHTML);}
    else{
        if(msobj.ScrollStep == 0 && msobj.DelayTime == 0){ msobj.ID.innerHTML += msobj.ID.innerHTML;}
        else{ msobj.ID.innerHTML = templateLeft.replace(/MSCLASS_TEMP_HTML/g,msobj.ID.innerHTML); }
    }
    var timer = this.Timer;
    var delaytime = this.DelayTime;
    var waittime = this.WaitTime;
    msobj.StartID = function(){msobj.Scroll()}
    msobj.Continue = function(){
        if(msobj.MouseOver == 1){ setTimeout(msobj.Continue,delaytime); }else{ 
            clearInterval(msobj.TimerID);
            msobj.CTL = msobj.Stop = 0;
            msobj.TimerID = setInterval(msobj.StartID,timer);
        }
    }
    msobj.Pause = function(){
        msobj.Stop = 1;
        clearInterval(msobj.TimerID);
        setTimeout(msobj.Continue,delaytime);
    }
    msobj.Begin = function()
    {
        msobj.ClientScroll = msobj.Direction > 1 ? msobj.ID.scrollWidth / 2 : msobj.ID.scrollHeight / 2;
        if((msobj.Direction <= 1 && msobj.ClientScroll <= msobj.Height + msobj.Step) || (msobj.Direction > 1 && msobj.ClientScroll <= msobj.Width + msobj.Step)){
            msobj.ID.innerHTML = msobj.tempHTML;
            delete(msobj.tempHTML);
            return;
        }
        delete(msobj.tempHTML);
        msobj.TimerID = setInterval(msobj.StartID,timer);
        if(msobj.ScrollStep < 0){return;}
        msobj.ID.onmousemove = function(event){
            if(msobj.ScrollStep == 0 && msobj.Direction > 1){
                var event = event || window.event;
                if(window.event){
                    if(msobj.IsNotOpera){
                        msobj.EventLeft = event.srcElement.id == msobj.ID.id ? event.offsetX - msobj.ID.scrollLeft : event.srcElement.offsetLeft - msobj.ID.scrollLeft + event.offsetX;
                    }else{
                        msobj.ScrollStep = null;
                        return;
                    }
                }else{ msobj.EventLeft = event.layerX - msobj.ID.scrollLeft; }
                msobj.Direction = msobj.EventLeft > msobj.HalfWidth ? 3 : 2;
                msobj.AbsCenter = Math.abs(msobj.HalfWidth - msobj.EventLeft);
                msobj.Step = Math.round(msobj.AbsCenter * (msobj.BakStep*2) / msobj.HalfWidth);
            }
        }
        msobj.ID.onmouseover = function(){
            if(msobj.ScrollStep == 0){return;}
            msobj.MouseOver = 1;
            clearInterval(msobj.TimerID);
        }
        msobj.ID.onmouseout = function(){
            if(msobj.ScrollStep == 0){
                if(msobj.Step == 0){msobj.Step = 1;}
                return;
            }
            msobj.MouseOver = 0;
            if(msobj.Stop == 0){
                clearInterval(msobj.TimerID);
                msobj.TimerID = setInterval(msobj.StartID,timer);
            }
        }
    }
    setTimeout(msobj.Begin,waittime);
}
Marquee.prototype.Scroll = function(){
    switch(this.Direction){
        case 0:
            this.CTL += this.Step;
            if(this.CTL >= this.ScrollStep && this.DelayTime > 0){
                this.ID.scrollTop += this.ScrollStep + this.Step - this.CTL;
                this.Pause();
                return;
            }else{
                if(this.ID.scrollTop >= this.ClientScroll){this.ID.scrollTop -= this.ClientScroll;}
                this.ID.scrollTop += this.Step;
            }
            break;
        case 1:
            this.CTL += this.Step;
            if(this.CTL >= this.ScrollStep && this.DelayTime > 0){
                this.ID.scrollTop -= this.ScrollStep + this.Step - this.CTL;
                this.Pause();
                return;
            }else{
                if(this.ID.scrollTop <= 0){this.ID.scrollTop += this.ClientScroll;}
                this.ID.scrollTop -= this.Step;
            }
            break;
        case 2:
            this.CTL += this.Step;
            if(this.CTL >= this.ScrollStep && this.DelayTime > 0){
                this.ID.scrollLeft += this.ScrollStep + this.Step - this.CTL;
                this.Pause();
                return;
            }else{
                if(this.ID.scrollLeft >= this.ClientScroll){this.ID.scrollLeft -= this.ClientScroll;}
                this.ID.scrollLeft += this.Step;
            }
            break;
        case 3:
            this.CTL += this.Step;
            if(this.CTL >= this.ScrollStep && this.DelayTime > 0){
                this.ID.scrollLeft -= this.ScrollStep + this.Step - this.CTL;
                this.Pause();
                return;
            }else{
                if(this.ID.scrollLeft <= 0){this.ID.scrollLeft += this.ClientScroll;}
                this.ID.scrollLeft -= this.Step;
            }
            break;
    }
}