﻿/*
功能：常用JS
作者：杨挺
修改日期：2010-04-13
公司：北京糖果网络技术有限公司
*/
function getCookie(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
    if (arr = document.cookie.match(reg))
        return unescape(arr[2]);
    else
        return null;
};
function setCookie(name, value) {
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    window.document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + "; path=/";
};


String.prototype.Trim = function() {
    return this.replace(/(^\s*)|(\s*$)/g, "");
};

String.prototype.LTrim = function() {
    return this.replace(/(^\s*)/g, "");
};

String.prototype.RTrim = function() {
    return this.replace(/(\s*$)/g, "");
};


/*
reallyDo：被搜索的子字符串。
replaceWith：用于替换的子字符串。
*/
String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
    if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
        return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi" : "g")), replaceWith);
    } else {
        return this.replace(reallyDo, replaceWith);
    }
};   
 

function getOs() {
    var OsObject = "";
    if (navigator.userAgent.indexOf("MSIE") > 0) {
        return "MSIE";
    }
    if (isFirefox = navigator.userAgent.indexOf("Firefox") > 0) {
        return "Firefox";
    }
    if (isSafari = navigator.userAgent.indexOf("Safari") > 0) {
        return "Safari";
    }
    if (isCamino = navigator.userAgent.indexOf("Camino") > 0) {
        return "Camino";
    }
    if (isMozilla = navigator.userAgent.indexOf("Gecko/") > 0) {
        return "Gecko";
    }
    if (isOpera = navigator.userAgent.indexOf("Opera") > 0) {
        return "Opera";
    }
};
function CPos(x, y) {
    this.x = x;
    this.y = y;
};



/*检测IE版本*/
function checkIE() {
    var X, V, N;
    V = navigator.appVersion;
    N = navigator.appName;
    if (N == "Microsoft Internet Explorer")
        X = parseFloat(V.substring(V.indexOf("MSIE") + 5, V.lastIndexOf("Windows")));
    else
        X = parseFloat(V);
    if (X >= 6.0 && X < 7.0) {
        return "6";
    }
    else if (X >= 7.0 && X < 8.0) {
        return "7";
    }
    else {
        return "8";
    }
};

/*
生成AJAX方法
*/
function createReq() {
    var httpReq;
    if (window.XMLHttpRequest) {
        httpReq = new XMLHttpRequest();
        if (httpReq.overrideMimeType) {
            httpReq.overrideMimeType('text/html');
        }
    }
    else if (window.ActiveXObject) {
        try {
            httpReq = new ActiveXObject('Msxml2.XMLHTTP');
        }
        catch (e) {
            try {
                httpReq = new ActiveXObject('Microsoft.XMLHTTP');
            }
            catch (e) {
            }
        }
    }
    return httpReq;
};

/*获取按键值*/
function quickQueryCust(evt) {
    evt = (evt) ? evt : ((window.event) ? window.event : ""); 
    var key = evt.keyCode ? evt.keyCode : evt.which; 
    return key;
};

/*过滤关键字*/
function filterKw(str) {
    if (String(str).Trim().length > 0) {
        if (String(str).indexOf("|", 0) >= 0) {
            return false;
        }
        if (String(str).indexOf("||", 0) >= 0) {
            return false;
        }
        if (String(str).indexOf(",", 0) >= 0) {
            return false;
        }
        if (String(str).indexOf(";", 0) >= 0) {
            return false;
        }
        return true;
    }
    return true;
};

/*过滤关键字*/
function filterKw1(str) {
    if (String(str).Trim().length > 0) {
        if (String(str).indexOf("|", 0) >= 0) {
            return false;
        }
        if (String(str).indexOf("||", 0) >= 0) {
            return false;
        }
        if (String(str).indexOf(",", 0) >= 0) {
            return false;
        }
        if (String(str).indexOf(";", 0) >= 0) {
            return false;
        }
        return true;
    }
    return true;
};


/*过滤在线收藏夹关键字*/
function filterFavKw(str) {
    if (String(str).Trim().length > 0) {
        if (String(str).indexOf("|", 0) >= 0) {
            return false;
        }
        if (String(str).indexOf("||", 0) >= 0) {
            return false;
        }
        if (String(str).indexOf("};{", 0) >= 0) {
            return false;
        }
        if (String(str).indexOf("],[", 0) >= 0) {
            return false;
        }      
        return true;
    }
    return true;
};


/*退出*/
function loginOut() {         
    $.ajax({
        type: "get",
        url: "../handler/LoginOut.ashx",
        cache: false,
        global: false, /*禁用全局Ajax事件*/       
        beforeSend: function(XMLHttpRequest) {
        },
        success: function(data, textStatus) {        
            if (data == "0")
                Dialog.alert("提示:执行后台方法出错");            
        },
        complete: function(XMLHttpRequest, textStatus) {
        },
        error: function() {
            /*请求出错处理*/
            Dialog.alert("提示：调用文件路径出错");
        }
    });
};

function showMsg() {
    Dialog.alert("提示:这项功能正在内测中。。");
};
function ShowTips(str) {
    var msgw, msgh, bordercolor;
    msgw = 250; //Width
    msgh = 50; //Height             
    titleheight = 25 //title Height;
    bordercolor = "#336699"; //boder color
    titlecolor = "#99CCFF"; //title color   

    var sWidth, sHeight;

    sWidth = document.body.clientWidth;
    sHeight = document.body.clientHeight;

    var bgObj = document.createElement("div");
    bgObj.setAttribute('id', 'bgDiv');
    bgObj.style.position = "absolute";
    bgObj.style.top = "0";
    bgObj.style.background = "#ffffff";
    bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
    bgObj.style.opacity = "0.0";
    bgObj.style.left = "0";
    bgObj.style.width = sWidth + "px";
    bgObj.style.height = sHeight + "px";
    bgObj.style.zIndex = "10000";
    document.body.appendChild(bgObj);

    var msgObj = document.createElement("div")
    msgObj.setAttribute("id", "msgDiv");
    msgObj.setAttribute("align", "center");
    msgObj.setAttribute("vAlign", "middle");
    msgObj.style.background = "white";
    msgObj.style.border = "3px solid " + bordercolor;
    msgObj.style.position = "absolute";
    msgObj.style.left = (sWidth - msgw) / 2 + "px";
    if ((window.screen.availHeight - window.screenTop) < document.body.clientHeight)
        msgObj.style.top = (window.screen.availHeight - window.screenTop - msgh) / 2 + "px";
    else
        msgObj.style.top = (sHeight - msgh) / 2 + "px";
    msgObj.style.font = "12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
    msgObj.style.width = msgw + "px";
    msgObj.style.height = msgh + "px";
    msgObj.style.textAlign = "center";
    msgObj.style.lineHeight = "25px";
    msgObj.style.zIndex = "10001";
    document.body.appendChild(msgObj);

    var txt = document.createElement("p");
    txt.style.margin = "1em 0";
    txt.setAttribute("id", "msgTxt");
    txt.style.fontSize = "14px";
    txt.style.color = "green";
    txt.style.fontWeight = "bold";
    txt.innerHTML = str;
    document.getElementById("msgDiv").appendChild(txt);
};

function HideTips() {
    var bgObj = document.getElementById("bgDiv");
    if (bgObj != null)
        document.body.removeChild(bgObj);
    var msgObj = document.getElementById("msgDiv");
    if (msgObj != null)
        document.body.removeChild(msgObj);
};    
