﻿/**
*     封装Ajax 传输类
*     URL:传过去处理的页面地址
*    callBackFunction:成功后调用的方法
*    errorFunction:失败后调用的方法
*    用法： var mAjaxer = new Ajaxer("url",callBackFunction,errorFunction)
*                 mAjaxer.send();
*  by:李涛
*/
var Ajaxer = function(URL, callBackFunction, errorFunction) {
    this.AjaxMethod = "POST";                            //默认传输方式 POST;
    this.SendObject = null;                                //传输的内容，默认null    
    this.ResponseType = "Text";                        //返回值类型
    this.Async = true;                                       //是否异步方式

    function createXMLHttp() {
        var xmlhttp;
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (ex) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (ex) {
                xmlhttp = new XMLHttpRequest();
            }
        }
        return xmlhttp;
    }

    var xmlHttp;

    this.send = function() {
        xmlHttp = null;
        xmlHttp = createXMLHttp();
        if (xmlHttp == null) {
            alert("创建xmlHTTP失败！");
        } else {
            xmlHttp.onreadystatechange = this.SendBack;
            xmlHttp.open(this.AjaxMethod, URL, this.Async);
            xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            xmlHttp.send(this.SendObject);
        }
    }

    this.SendBack = function() {
        if (xmlHttp.readyState == 4) {
            if (xmlHttp.status == 200) {
                var res;
                res = xmlHttp.responseText;
                callBackFunction(res);
            } else {
            var error = eval(error + "=" + "{\"code\":\"" + xmlHttp.status + "\",\"message\":\"" + xmlHttp.statusText + "\"}");
                errorFunction(error);
            }
        }
    }
}

//单击复选框时那个选中
function SelectAll(tempControl, gridname) {
    var theBox = tempControl;
    xState = theBox.checked;
    var grid = document.getElementById(gridname);
    var arr = grid.rows.length - 1;
    for (var i = arr; i >= 0; i--) {
        var cellname = grid.rows[i].cells[0];
        var inputs = cellname.getElementsByTagName("INPUT");
        if (inputs[0].checked != xState) {
            inputs[0].click();
        }
    }

}

