﻿///////////////////////////
// 全局公共JS
///////////////////////////
var Ajax_Defind = {
PATH: "http://www.equan.com/ajax/Ajax.ashx?ReferClass=",
    
    GET: 1, //以get方式请求
    POST: 2, //以post方式请求
    JSON: 4, //以json方式返回
    XML: 8, //以xml方式返回
    HTML: 16, //以html方式返回
    TXT: 64, //以纯文本方式返回
    Async: 32, //以异步方式发送
    PHA: 50, //以post方式请求，以html方式返回，以异步方式发送
    PJA: 38, //以post方式请求，以json方式返回，以异步方式发送
    PTA: 98, //以post方式请求，以text方式返回，以异步方式发送
    GHA: 49, //以Get方式请求，以html方式返回，以异步方式发送
    GJA: 37, //以Get方式请求，以json方式返回，以异步方式发送
    GTA: 97 //以Get方式请求，以text方式返回，以异步方式发送
}; 
function AjaxSubmit(action, flag, data, response){

    this.Type = "GET";
    this.Data = data;
    this.Flag = flag;
    this.Action = action;
    this.Response = response;
    this.DataType = "";
    
    this.Request = function(){
    
        this.Async = this.Flag == (this.Flag | Ajax_Defind.Async);
        if (this.Flag == (this.Flag | Ajax_Defind.JSON)) 
            this.DataType = "json";
        if (this.Flag == (this.Flag | Ajax_Defind.XML)) 
            this.DataType = "xml";
        if (this.Flag == (this.Flag | Ajax_Defind.HTML)) 
            this.DataType = "html";
        if (this.Flag == (this.Flag | Ajax_Defind.TXT)) 
            this.DataType = "text";
        if (this.Flag == (this.Flag | Ajax_Defind.GET)) 
            this.Type = "GET";
        if (this.Flag == (this.Flag | Ajax_Defind.POST)) 
            this.Type = "POST";
        
        $.ajax({
            dataType: this.DataType,
            type: this.Type,
            async: this.Async,
            url: Ajax_Defind.PATH + this.Action,
            data: this.Data,
            success: this.Response,
            error: this.Error
        });
    }
}
 
function EQuanBox(title, showCancel, onok){

    EQuanWeeBox(title, "设置", showCancel, onok);
}
 
function EQuanWeeBox(context, title, showCancel, onok){

    if (onok == undefined || onok == null) {
        onok = function(box){
            box.close();
        }
    }
    $.weeboxs.open(context, {
        title: title,
        okBtnName: '确定',
        showCancel: showCancel,
        cancelBtnName: '取消',
        onok: onok
    });
}
 
function IsUndefinedOrNull(object){
    return object == undefined || object == null;
    
} 
function HtmlEncode(_html, _now, _new){

    if (_html == null || _html == "") 
        return _html;
    while (_html.indexOf(_now) > -1) {
        _html = _html.replace(_now, _new);
    }
    
    return _html;
} 
function Html_LT_Encode(_html){

    var _temp = HtmlEncode(_html, ";", "；");
    _temp = HtmlEncode(_temp, "<", "&lt;");
    _temp = HtmlEncode(_temp, "&lt;", "& lt;");
    _temp = HtmlEncode(_temp, "&gt;", "& gt;");
    
    return _temp;
} 
function ContainCount(_text, _t){

    var index = 0;
    var count = 0;
    
    do {
        index = _text.indexOf(_t, index) + 1;
        count++;
    }
    while (index != 0);
    return count - 1;
} 
function DataCompare(_d, _t){

    return (_d - _t) / 86400000;
} 
function DateFormat(_date){

    return _date.getFullYear() +
    "-" +
    (_date.getMonth() + 1) +
    "-" +
    _date.getDate();
} 
function HtmlSubstring(_html, _len, _str){

    if (_html == null) 
        return null;
    if (_html.length <= _len) 
        return _html;
    if (_str == null) 
        _str = "...";
    
    return _html.substring(0, _len) + _str;
    
} 
function DocSetCookie(_key, _val){

    var date = new Date();
    date.setFullYear(2099, 11, 30);
    document.cookie = _key + "=" + _val + ";expires=" + date.toUTCString();
    
} 
function DocGetCookieByKey(_key){

    if (_key == null) 
        return null;
    
    var strCookie = document.cookie;
    if (strCookie == null) 
        return null;
    
    var arr = strCookie.split(";");
    if (arr == null || arr.length == 0) 
        return null;
    
    for (var i = 0; i < arr.length; i++) {
    
        var map = arr[i].split("=");
        if (map[0].replace(" ", "") == _key) 
            return map[1];
    }
    
    return null;
}

