﻿//提交(填充返回數據到指定單元中)
function ajaxSubmitSet(id, url, excfunction) {
    var dataArr = $("form").serialize();
    $.ajax({
        type: "post",
        url: url,
        data: dataArr,
        success: function(html) {
            $("#" + id).html(html); //彈出提示信息
            if (excfunction != "") {
                eval(excfunction);
            }
        }
    });
}
//(返回提交處理頁的提示信息)
function ajaxSubmit(id, url, excfunction) {
    var dataArr = $("form").serialize();
    $.ajax({
        type: "post",
        url: url,
        data: dataArr,
        success: function(msg) {
            switch (msg) {
                case "1": //表示操作成功
                    alert("操作成功！");
                    break;
                case "0": //表示操作失敗
                    alert("操作失敗！");
                    return;
                    break;
                default: //彈出提示信息
                    alert(msg);
                    return;
                    break;
            }
            if (excfunction != "") {
                eval(excfunction);
            }
        }
    });
}
//用戶登錄
function ajaxLogin() {
    var dataArr = $("form").serialize();
    $.ajax({
        type: "post",
        url: "logincheck.aspx",
        data: dataArr,
        success: function(msg) {
            switch (msg) {
                case "1": //表示操作成功
                    location.href = "index.aspx";
                    break;
                case "0": //表示操作失敗
                    alert("您填寫的帳號名或密碼有誤！");
                    return;
                    break;
                default: //彈出提示信息
                    alert(msg);
                    return;
                    break;
            }
        }
    });
}
function ajaxFormSubmit(id, url, excfunction) {
    var dataArr = $("form").serialize();
    $.ajax({
        type: "post",
        url: url,
        data: dataArr,
        success: function(msg) {
            switch (msg) {
                case "1": //表示操作成功
                    alert("操作成功！");
                    break;
                case "0": //表示操作失敗
                    alert("操作失敗！");
                    return;
                    break;
                default: //彈出提示信息
                    alert(msg);
                    return;
                    break;
            }
            if (excfunction != "") {
                eval(excfunction);
            }
        }
    });
}
//提交(不返回提交處理頁的數據)
function ajaxSubmitNoGet(id, url, excfunction) {
    var dataArr = $("form").serialize();
    $.ajax({
        type: "post",
        url: url,
        data: dataArr,
        success: function() {
            if (excfunction != "") {
                eval(excfunction);
            }
        }
    });
}

function ajaxSubmitNoGets(url, excfunction, dataArr) {
    $.ajax({
        type: "post",
        url: url,
        data: dataArr,
        success: function() {
            if (excfunction != "") {
                eval(excfunction);
            }
        }
    });
}
//地址欄參數提交
function ajaxUrlTransact(id, url, excfunction) {
    $.ajax({
        url: url,
        success: function(html) {
            if (id != "") {
                $("#" + id).html(html);
            }
            if (excfunction != "") {
                eval(excfunction);
            }
        }
    });
}
//獲取數據填充
function setAjaxTransact(id, url, excfunction) {
    if (id != "") {
        $("#" + id).html("<div style='padding:10px'><img src='../images/loading.gif' align='center'/> Loading</div>");
    }
    $.ajax({
        url: url,
        success: function(html) {
            if (id != "") {
                $("#" + id).html(html);
            }
            if (excfunction != "") {
                eval(excfunction);
            }
        }
    });
}
//獲取數據填充(從返回資料中讀取指定欄位的信息)
function setAjaxTransactGetNodeName(id, url, excfunction, nodename) {
    $("#" + id).html("<div style='padding:10px'><img src='../images/loading.gif' align='center'/> Loading</div>");
    $.ajax({
        url: url,
        success: function(html) {
            //html="<form enctype=\"multipart\/form-data\">"+$(nodename,html).html()+"</form>";
            $("#" + id).html(html);
            if (excfunction != "") {
                eval(excfunction);
            }
        }
    });
}
//上傳
function UploadSubmit(id, url, fileinput, excfunction) {
    var dataArr = $("form").serialize();
    $.ajaxFileUpload
    (
	    {
	        url: url + '&' + dataArr,
	        secureuri: false,
	        fileElementId: fileinput,
	        success: function(data) {
	            switch (data.body.innerHTML) {
	                case "1": //表示操作成功
	                    alert("操作成功！");
	                    break;
	                case "0": //表示操作失敗
	                    alert("操作失敗！");
	                    return;
	                    break;
	                default: //彈出提示信息
	                    alert("1" + data.body.innerHTML);
	                    return;
	                    break;
	            }
	            if (excfunction != "") {
	                eval(excfunction);
	            }
	        }
	    }
    )
}
//上傳，當表單控件過多，數據量大時用
function NewUploadSubmit(id, formid, url, fileinput, excfunction) {
    $.ajaxFileUpload
    (
	    {
	        url: url,
	        secureuri: false,
	        fileElementId: fileinput,
	        submitFormId: formid,
	        success: function(data) {
	            switch (data.body.innerHTML) {
	                case "1": //表示操作成功
	                    alert("操作成功！");
	                    break;
	                case "0": //表示操作失敗
	                    alert("操作失敗！");
	                    return;
	                    break;
	                default: //彈出提示信息
	                    alert(data.body.innerHTML);
	                    return;
	                    break;
	            }
	            if (excfunction != "") {
	                eval(excfunction);
	            }
	        }
	    }
    )
}
//上傳，當表單控件過多，數據量大時用(基金專用)
function UploadSubmitForFund(id, formid, url, fileinput, excfunction) {
    $.ajaxFileUpload
    (
	    {
	        url: url,
	        secureuri: false,
	        fileElementId: fileinput,
	        submitFormId: formid,
	        success: function(data) {
	            switch (data.body.innerHTML) {
	                case "1": //表示操作成功
	                    alert("操作成功！");
	                    break;
	                case "0": //表示操作失敗
	                    alert("操作失敗！");
	                    location.href = location.href;
	                    return;
	                    break;
	                default: //彈出提示信息
	                    alert(data.body.innerHTML);
	                    return;
	                    break;
	            }
	            if (excfunction != "") {
	                eval(excfunction);
	            }
	        }
	    }
    )
}
//刪除判斷
function Confirm(msg)
{
    if(msg=="" || msg==undefined)
        return window.confirm("確定要刪除嗎？");
    else
        return window.confirm(msg);
        
}
//返回Fckeditor控件的值
function getEditorHTMLContents(EditorName) { 
    var oEditor = FCKeditorAPI.GetInstance(EditorName); 
    var content = oEditor.GetXHTML(true)
    content=escape(content);
    return(content); 
}
//邦定選擇日期
function InputSelectDate(id)
{
    var arr=id.split(",");
    for(i=0;i<arr.length;i++)
    {
        $("#"+arr[i]).click(function(){
	        WdatePicker();
	    });
	}
}
//邦定選擇日期
function ItemSelectDate(item)
{
    $(item).each(function(){
        $(this).click(function(){
	        WdatePicker();
	    });
    })
}
//響應到對應的Input控件
function ImgSelectDate(id)
{
    WdatePicker({el:$dp.$(id)});
}
//檢查session是否過期，參數"excfunction"為執行方法,當session末過期時執行
function SessionCheck(excfunction) {
    $.ajax({ 
	    type: "post",  
	    url : "/manage/sessioncheck.aspx", 
	    data: "",
	    success: function(msg)
	    {
            if(msg=="0")
            {
                alert("登錄超時，請重新登錄！");
                location.href="/manage/login.aspx"
            }
            else
            {
                eval(excfunction);
            }
	    }   
    });
}
//控制文本框只能輸入數字(集合)
function InputNumberText(objText,maxlen)
{
    $(objText).each(function (i) {
		$(this).attr("onpaste","return false");
		$(this).attr("oncontextmenu","return false");
		$(this).attr("onmouseover","select()");
		if(maxlen>0)
		{
		    $(this).attr("maxlength",maxlen);
		}
		$(this).keypress(function(e){
			if((e.which<48 || e.which>57) && e.which!=8 && e.which!=0)
			{
				 return false;
			}
		})
	});
}
//根据文本框ID(单个)
function SingleNumberText(obj,maxlen)
{
    var objText="#"+obj;
	$(objText).attr("onpaste","return false");
	$(objText).attr("oncontextmenu","return false");
	$(objText).attr("onmouseover","select()");
	$(objText).attr("onblur","IsNumber(this)");
	if(maxlen>0)
	{
	    $(objText).attr("maxlength",maxlen);
	}
	$(objText).keypress(function(e){
		if((e.which<48 || e.which>57) && e.which!=8 && e.which!=0)
		{
			 return false;
		}
	})
}
function IsNumber(obj)
{
    if(isNaN(obj.value))
	{
		 alert("請填寫數字！")
		 obj.value="";
		 return false;
	}
}

//Bolin
//ajax
function NewAjax(id, url, Eventjs, dataArr) {
    $.ajax({
        type: 'post',
        url: url,
        data: dataArr,
        cache: false,
        success: function(html) {
            if (id != "") {
                $("#" + id).html(html);
            }
            if (typeof Eventjs == "function") {
                Eventjs();
            }
            else if (typeof Eventjs == "string") {
                eval(Eventjs);
            }
        }
    });
}
function LoadingAjax(id, url, Eventjs, dataArr) {
    if (id != "") {
        $("#" + id).html("<div style='padding:10px'><img src='../images/loading.gif' align='center'/>Loading</div>");
    }
    $.ajax({
        type: 'post',
        url: url,
        data: dataArr,
        cache: false,
        success: function(html) {
            if (id != "") {
                $("#" + id).html(html);
            }
            if (typeof Eventjs == "function") {
                Eventjs();
            }
            else if (typeof Eventjs == "string") {
                eval(Eventjs);
            }          
        },
        error:function(){
            $("#" + id).html("查無資料！");
        }
    });
}
//提交或修改 ajax
function SubUpdate_Ajax(url, EventJS, dataArr) {
    $.ajax({
        type: 'post',
        url: url,
        data: dataArr,
        cache: false,
        success: function(html) {
            switch (html) {
                case "1": //表示操作成功
                    alert("操作成功！");
                    break;
                case "0": //表示操作失敗
                    alert("操作失敗！");
                    return;
                    break;
                default: //彈出提示信息
                    alert(html);
                    return;
                    break;
            }
            if (typeof EventJS == "function") {
                EventJS();
            }
            else if (typeof EventJS == "string") {
                eval(EventJS);
            }
        }
    });
}

//上傳
function UploadFileAjax(url, fileinput, excfunction, dataArr) {
    $.ajaxFileUpload
    (
	    {
	        url: url + "?" + dataArr,
	        secureuri: false,
	        fileElementId: fileinput,
	        success: function(html) {
	            switch (html.body.innerHTML) {
	                case "1": //表示操作成功
	                    alert("操作成功！");
	                    break;
	                case "0": //表示操作失敗
	                    alert("操作失敗！");
	                    return;
	                    break;
	                default: //彈出提示信息
	                    alert(html.body.innerHTML);
	                    return;
	                    break;
	            }
	            if (excfunction != "") {
	                eval(excfunction);
	            }
	        }
	    }
    )
}

//上傳
function UploadSubmit1(id, url, fileinput, excfunction) {
    var dataArr = $("form").serialize();
    $.ajaxFileUpload
    (
	    {
	        url: url + '&' + dataArr,
	        secureuri: false,
	        fileElementId: fileinput,
	        success: function(data) {
	            switch (data.body.innerHTML) {
	                case "1": //表示操作成功
	                    alert("操作成功！");
	                    break;
	                case "0": //表示操作失敗
	                    alert("操作失敗！");
	                    return;
	                    break;
	                default: //彈出提示信息
	                    alert(data.body.innerHTML);
	                    return;
	                    break;
	            }
	            if (excfunction != "") {
	                eval(excfunction);
	            }
	        }
	    }
    )
}

//序列化Form將Form中所有控件當作參數
function SerializeFormAjax(id, url, excfunction) {
    var dataArr = $("form").serialize();
    $.ajax({
        type: "post",
        url: url,
        data: dataArr,
        success: function(html) {
            $("#" + id).html(html); 
            if (excfunction != "") {
                eval(excfunction);
            }
        }
    });
}

//序列化Form將Form中所有控件當作參數
function SerializeFormWorkAjax(url, excfunction) {
    var dataArr = $("form").serialize();
    $.ajax({
        type: "post",
        url: url,
        data: dataArr,
        success: function(html) {
            switch (html) {
                case "1": //表示操作成功
                    alert("操作成功！");
                    break;
                case "0": //表示操作失敗
                    alert("操作失敗！");
                    return;
                    break;
                default: //彈出提示信息
                    alert(html);
                    return;
                    break;
            }
            if(typeof Eventjs =="function")
            {
                Eventjs();
            }
            else if(typeof Eventjs =="string")
            {
                eval(Eventjs);
            }
        }
    });
}

//序列化Form將Form中所有控件當作參數
function SerializeFormWorkAjaxReturn(url, excfunction,id,attrtitle) {
    var dataArr = $("form").serialize();
    $.ajax({
        type: "post",
        url: url,
        data: dataArr,
        success: function(html) {
            if (html == "") {
                return;
            }
            else if (html == "0") {
                alert("操作失敗！");
                return;
            }
            else {
                if (attrtitle != "") {
                    $(id).attr(attrtitle, html);
                } else {
                    $(id).html(html);
                }
                alert("操作成功！");
            }
            if (excfunction != "") {
                eval(excfunction);
            }
        }
    });
}
//登陸判斷
function SessionLogin(url,SuccessJS,EorroJS,DataArr) {
    $.ajax({
        type: 'post',
        url: url,
        data: DataArr,
        cache: false,
        success: function(html) {
            switch (html) {
                case "1": //表示操作成功
                    if (typeof SuccessJS == "function") {
                        SuccessJS();
                    }
                    else if (typeof SuccessJS == "string") {
                        eval(SuccessJS);
                    }
                    break;
                case "0": //表示操作失敗
                    if (typeof EorroJS == "function") {
                        EorroJS();
                    }
                    else if (typeof EorroJS == "string") {
                        eval(EorroJS);
                    }
                    break;
                default: //彈出提示信息
                    if (typeof EorroJS == "function") {
                        EorroJS();
                    }
                    else if (typeof EorroJS == "string") {
                        eval(EorroJS);
                    }
                    break;
            }
        }
    });
}


function AdvAjax(url, dataArr) {
    $.ajax({
        type: 'post',
        url: url,
        data: dataArr,
        cache: false,
        success: function(html) {
            document.writeln(html);
        }
    });
}

//獲取Select控件當前選取值
function GetSelectValue(NewID)
{
    var index=$("#"+NewID)[0].selectedIndex;
    var txt=$("#"+NewID)[0].options[index].value;
    return txt;
}

function GetSelectText(NewID) {
    var index = $("#" + NewID)[0].selectedIndex;
    var txt = $("#" + NewID)[0].options[index].text;
    return txt;
}

//控制文本框只能輸入數字(集合)
function InputNumberText(objText, maxlen) {
    $(objText).each(function(i) {
        $(this).attr("onpaste", "return false");
        $(this).attr("oncontextmenu", "return false");
        $(this).attr("onmouseover", "select()");
        if (maxlen > 0) {
            $(this).attr("maxlength", maxlen);
        }
        $(this).keypress(function(e) {
            if ((e.which < 48 || e.which > 57) && e.which != 8 && e.which != 0) {
                return false;
            }
        })
    });
}

//警語
function getAphorism(id,url) {
    $.ajax({
        type: "get",
        url: url,
        success: function(html) {
            $("#" + id).html(html);
        }
    });
}

function AllImage(Maxwidth) {
    var con = document.getElementById("LogListImg");
    if (con != null) {
        var imgs; 
        imgs = con.getElementsByTagName("IMG");
        for (var i = 0; i < imgs.length; i++)
            with (imgs[i]) {
            height = width > Maxwidth ? height * (Maxwidth / width) : height;
            width = width > Maxwidth ? Maxwidth : width;
        }
    }
}

function UpdateImg(ShowImg, Maxwidth) {
    $(ShowImg).each(function() {
        $(this).attr("height", $(this).attr("width") > Maxwidth ? $(this).attr("height") * (Maxwidth / $(this).attr("width")) : $(this).attr("height"));
        $(this).attr("width", $(this).attr("width") > Maxwidth ? Maxwidth : $(this).attr("width"));
    });
}