﻿//ajax调用方式
//jPrompt("提示:请输入要点菜的数量", "1", "添加订购", 
//            function (dishNum) { }
//        });


/*****
功能:jAlert的其他方式调用
*****/


/*****
功能:GetRequest 获取请求信息
调用方式:
var requestList = new Object();
requestList = GetRequest();
var dishIdTmp = requestList['dishId'];//直接读取dishId的传递
*****/
function GetRequest()
{
    var url = location.search; //获取 url 中"?"符后的字串 
    var theRequest = new Object();
    if (url.indexOf("?") != -1)
    {
        var str = url.substr(1);
        strs = str.split("&");
        for (var i = 0; i < strs.length; i++)
        {
            theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}
// GetRequest END 

$("document").ready(function ()
{
    $("tr").each(function (i)
    {
        var className = ["odd", "even"][i % 2];
        $(this).addClass(className);
        $(this).hover(
            function ()
            {
                $(this).removeClass(className);
                $(this).addClass("highlight");
            },
            function ()
            {
                $(this).removeClass("hightlight");
                $(this).addClass(className);
            }
        )
    });
});


//打开对话框
function opdlg(id, url, title, isMax)
{
    var dlg = new $.dialog({ id: id, iconTitle: false, title: title, cover: true, opacity: 0.1, width: 550, height: 450, autoPos: { left: 'center', top: 'center' }, page: url });
    dlg.ShowDialog();
    if (isMax)
    {
        dlg.maxSize();
    }
    return false;
}

//按比例自动缩放图片
function DrawImage(ImgD, maxWidth, maxHeight)
{
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= maxWidth / maxHeight) {
            if (image.width > maxWidth) {
                ImgD.width = maxWidth;
                ImgD.height = (image.height * maxHeight) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
        else {
            if (image.height > maxHeight) {
                ImgD.height = maxHeight;
                ImgD.width = (image.width * maxHeight) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
}

//添加到收藏夹
function AddFavorite(sURL, sTitle)
{
    try
    {
        window.external.addFavorite(sURL, sTitle);
    }
    catch (e)
    {
        try
        {
            window.sidebar.addPanel(sTitle, sURL, "");
        }
        catch (e)
        {
            alert("加入收藏失败，请使用Ctrl+D进行添加");
        }
    }
}

//设置首页
function SetHome(obj, vrl)
{
    try
    {
        obj.style.behavior = 'url(#default#homepage)'; obj.setHomePage(vrl);
    }
    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);
        }
    }
}
