﻿/*

*/
function BomHelper() {
    this.ie = "";
    this.firefox = "";
    this.chrome = "";
    this.opera = "";
    this.safari = "";
}
//检测浏览器版本，并保存
BomHelper.prototype.checkBrowerType = function() {
    var ua = navigator.userAgent.toLowerCase();
    var s;
    (s = ua.match(/msie ([\d.]+)/)) ? this.ie = s[1] :
    (s = ua.match(/firefox\/([\d.]+)/)) ? this.firefox = s[1] :
    (s = ua.match(/chrome\/([\d.]+)/)) ? this.chrome = s[1] :
    (s = ua.match(/opera.([\d.]+)/)) ? this.opera = s[1] :
    (s = ua.match(/version\/([\d.]+).*safari/)) ? this.safari = s[1] : 0;
}
//获取ajax对象
BomHelper.prototype.ajaxObj = function() {
    var xmlHttp = null;
    if (this.ie != "") {
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (ex1) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (ex2) {
                alert("创建ajax对象失败,本网站只支持ie6以上版本浏览器,请刷新页面重试");
            }
        }
    } else {
        try {
            xmlHttp = new XMLHttpRequest();
        } catch (ex3) {
            alert("创建ajax对象失败,请刷新页面重试");
        }
    }
    return xmlHttp;
}
//发送ajax的GET请求
BomHelper.prototype.ajaxGet = function(sUrl, fnAjax) {
    var xmlHttp = this.ajaxObj();
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4)
            fnAjax(xmlHttp.responseText);
    }
    if (sUrl.indexOf("?") == -1)
        sUrl = sUrl + "?flesh=" + Math.random();
    else
        sUrl = sUrl + "&flesh=" + Math.random();
    xmlHttp.open("GET", sUrl, true);
    xmlHttp.send(null);
}
//发送ajax的post请求
BomHelper.prototype.ajaxPost = function(sUrl, sPostData, fnAjax) {
    var xmlHttp = this.ajaxObj();

    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4)
            fnAjax(xmlHttp.responseText);
    }
    if (sPostData == "")
        sPostData = sPostData + "flesh=" + Math.random();
    else
        sPostData = sPostData + "&flesh=" + Math.random();
    xmlHttp.open("POST", sUrl, true);
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlHttp.send(sPostData);
}
//若是IE7以上版本，则要求它使用IE7
BomHelper.prototype.useIE7 = function() {
    document.write("<meta content=\"IE=EmulateIE7\" http-equiv=\"X-UA-Compatible\">");
}

var bomHelper = new BomHelper();
bomHelper.checkBrowerType();

