using System;
using System.Collections.Generic;
using System.Web;
using System.Text;
using System.Web.UI;


/// <summary>
///JavaScript 的摘要说明
/// </summary>
public class JavaScript
{
	public JavaScript()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}
    /// <summary>
    /// 服务器端弹出消息框，页面需要添加引用
    /// <script type="text/javascript" src="../easyui/jquery-1.7.1.min.js"></script>
    /// <script type="text/javascript" src="../easyui/easyloader.js"></script>
    /// </summary>
    /// <param name="msg">消息文本</param>
    /// <param name="page">this.page</param>
    public static void messageBox(string msg, Page page,string url)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<script type='Text/JavaScript'>");
        sb.Append("$(function () { $.ligerDialog.alert(\"" + msg + "\", \"提示\",\"success\",function (result) { window.location.href ='" + url + "'; }); });");
        sb.Append("</script>");
        page.ClientScript.RegisterStartupScript(page.GetType(), "Messager", sb.ToString());
    }
    /// <summary>
    /// 服务器端弹出确认消息，
    /// 页面需添加隐藏按钮：(_btn_ok) 和(_btn_cancel)
    /// <asp:Button ID="_btn_ok" runat="server" onclick="_btn_ok_Click" 
    ///      Text="_btn_ok" CausesValidation="False" UseSubmitBehavior="False" style="display:none;"/>
    /// </summary>
    /// <param name="msg">确认消息</param>
    /// <param name="page">this.page</param>
    public static void confirmBox(string msg, Page page)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<script type='Text/JavaScript'>");
        sb.Append("$(function(){easyloader.locale = 'zh_CN';");
        sb.Append("easyloader.load('messager', function(){");
        sb.Append("$.messager.confirm('系统提示', '");
        sb.Append(msg);
        sb.Append("', function(c){if(c)");
        sb.Append("$('#_btn_ok').click();");
        sb.Append("else ");
        sb.Append("$('#_btn_cancel').click();");
        //$('#_btn_cancel').click();
        sb.Append("});});});");
        sb.Append("</script>");
        page.ClientScript.RegisterStartupScript(page.GetType(), "Messager", sb.ToString());
    }
    //实现事件可变动方法
    public static void confirmBoxother(string msg, Page page, string text1, string text2)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<script type='Text/JavaScript'>");
        sb.Append("$(function(){easyloader.locale = 'zh_CN';");
        sb.Append("easyloader.load('messager', function(){");
        sb.Append("$.messager.confirm('系统提示', '");
        sb.Append(msg);
        sb.Append("', function(c){if(c)");
        sb.Append("$('#" + text1 + "').click();");
        sb.Append("else ");
        sb.Append("$('#" + text2 + "').click();");
        //$('#_btn_cancel').click();
        sb.Append("});});});");
        sb.Append("</script>");
        page.ClientScript.RegisterStartupScript(page.GetType(), "Messager", sb.ToString());
    }

    public static void confirmBoxmy(string msg, Page page)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<script type='Text/JavaScript'>");
        sb.Append("$(function(){easyloader.locale = 'zh_CN';");
        sb.Append("easyloader.load('messager', function(){");
        sb.Append("$.messager.confirm('系统提示', '");
        sb.Append(msg);
        sb.Append("', function(c){start();if(c)");
        sb.Append("$('#_btn_ok').click();");
        sb.Append("else ");
        sb.Append("$('#_btn_cancel').click();");
        //$('#_btn_cancel').click();
        sb.Append("});});});");
        sb.Append("</script>");
        page.ClientScript.RegisterStartupScript(page.GetType(), "Messager", sb.ToString());
    }

    public static void clientFunction(string funName, Page page)
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("<script type='Text/JavaScript'>");
        sb.Append(" $(function(){");
        sb.Append(funName);
        sb.Append("();})");
        sb.Append("</script>");
        page.ClientScript.RegisterStartupScript(page.GetType(), "Messager", sb.ToString());
    }


}