// PNG图片透明处理 
function correctPNG() {
    var arVersion = navigator.appVersion.split("MSIE")
    var version = parseFloat(arVersion[1])
    if ((version >= 5.5) && (document.body.filters)) {
        for (var j = 0; j < document.images.length; j++) {
            var img = document.images[j]
            var imgName = img.src.toUpperCase()
            if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                var imgStyle = "display:inline-block;" + img.style.cssText
                if (img.align == "left") imgStyle = "float:left;" + imgStyle
                if (img.align == "right") imgStyle = "float:right;" + imgStyle
                if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
                var strNewHTML = "<span " + imgID + imgClass + imgTitle
             + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
             + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
             + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
                img.outerHTML = strNewHTML
                j = j - 1
            }
        }
    }
}

// 底部链接
function UserNameClick() {
    if (event.ctrlKey) {
        // window.open(unescape('/Cx_Login.aspx'));
        window.open('/Cx_Login.aspx', "CxCms", "scrollbars=no,status=no,resizable=no,top=0,left=0,width=" + $(window).width() + ",height=" + $(window).height());
    }
}
function pageload() {
    correctPNG();
}


function request(paras) {
    var url = location.href;
    var paraString = url.substring(url.indexOf("?") + 1, url.length).split("&");
    var paraObj = {}
    for (i = 0; j = paraString[i]; i++) {
        paraObj[j.substring(0, j.indexOf("=")).toLowerCase()] = j.substring(j.indexOf("=") + 1, j.length);
    }
    var returnValue = paraObj[paras.toLowerCase()];
    if (typeof (returnValue) == "undefined") {
        return "";
    } else {
        return returnValue;
    }
}




//取字符串参数
function QueryCharString(str) {
    var name, value, i;
    var str = str;
    var num = str.indexOf("?")
    if (num > 0) {
        str = str.substr(num + 1);
        var arrtmp = str.split("&");
        for (i = 0; i < arrtmp.length; i++) {
            num = arrtmp[i].indexOf("=");
            if (num > 0) {
                name = arrtmp[i].substring(0, num);
                value = arrtmp[i].substr(num + 1);
                this[name] = value;
            }
        }
    }
}

//常用表单验证
//只能英文
function onlyEng() {
    if (!(event.keyCode >= 65 && event.keyCode <= 90))
        event.returnvalue = false;
}
//只能数字<input onkeydown=”onlyNum();”>
function onlyNum() {
    if (!((event.keyCode >= 48 && event.keyCode <= 57) || (event.keyCode >= 96 && event.keyCode <= 105)))
        event.returnvalue = false;
}
//只能是英文字符和数字
/*<input onkeyup=”value=”/oblog/value.replace(/[\W]/g,””)
“onbeforepaste=”clipboardData.setData(’text’,clipboardData.getData(’text’).replace(/[^\d]/g,”))”>*/

//验证邮箱格式<input type=text onblur=isEmail(this.value)>
function isEmail(strEmail) {
    if (strEmail.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

//清除空格
function trim(str) {
    str = str.replace(/^\s+/g, '');
    for (var i = str.length - 1; i >= 0; i--) {
        if (!/^\s$/.test(str.substr(i, 1))) break;
    }
    return str.substring(0, i + 1)
}





/**
* method 验证特殊字符
* 
* @param checkedObject
*            需要验证的字符串
* @return 包含特殊字符true,不包含false
*/
function isLegalString(checkedObject) {
    var re = /<|>|'|;|&|#|"|\$|\*|\.|\[|\]|\{|\}|\%|\`|\||\:|\,|\\|\//;
    return re.test(checkedObject);
}
/**
* method 检查字符串长度
* 
* @param maxLen
*            允许最大长度
* @param checkedObject
*            被检查字符串
* @return 如果不大于max返回true 否则false
*/
function checkLength(maxLen, checkedObject) {
    var isTrue = true;
    var len = checkedObject.replace(/[^\x00-\xff]/g, "**").length;
    if (len > maxLen) {
        isTrue = false;
    }
    return isTrue;
}
/**
* method 测试Email格式是否正确
* 
* @param checkedObject
* @return 如果正确返回true 否则返回false
*/
function checkEmail(checkedObject) {
    var re = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
    return re.test(checkedObject);
}
/**
* method 检查字符串是否为空
* 
* @param checkedObject
* @return 如果不为空返回true 否则返回false
*/
function isNull(checkedObject) {
    var isTrue = true;
    var len = checkedObject.length;
    if (len == 0) {
        isTrue = false;
    }
    return isTrue;
}
/**
* method 检查是否全是数字
* 
* @param checkedObject
*            被检查对象
* @return 如果全是返回true否则false
*/
function isNum(checkedObject) // 这个方法相当与是判断字符串中的每个字符是不是数字
{
    var re = /[^0-9]/;
    var isTrue = !re.test(checkedObject);
    return isTrue;
}
/**
* method 检查是否全是中文
* 
* @param checkedObject
* @return 如果全是返回true否则false
*/
function isChinese(checkedObject) {
    var re = /[u00-uFF]/;
    var isTrue = !re.test(checkedObject);
    return isTrue;
}


/**
* method 获得子窗体显示到屏幕的垂直中间位置
* 
* @param height
*            子窗体的高度
* @return
*/
function getTop(height) {
    // 30指的是子窗体的底边框的大小
    var top = (screen.availHeight - height - 30) * .5;
    return top;
}
/**
* method 获得子窗体显示到屏幕的水平中间位置
* 
* @param width
* @return
*/
function getLeft(width) {
    // 10指的是子窗体的左边框大小
    var left = (screen.availWidth - width - 10) * .5;
    return left;
}





function TagClick(obj) {
    var tags = document.getElementById("MainMenuItems").getElementsByTagName("a");
    for (i = 0; i < tags.length; i++) {
        tags.item(i).className = '';
        document.getElementById("SecondMenuItems" + i).style.display = "none";
    }
    document.getElementById("tag" + obj).className = 'hover';
    document.getElementById("SecondMenuItems" + obj).style.display = "block";
    var menus = document.getElementById("SecondMenuItems" + obj).getElementsByTagName("a");
    for (i = 0; i < menus.length; i++) {
        menus.item(i).className = '';
    }
}
function MenuClick(obj, num) {
    var tags = document.getElementById("SecondMenuItems" + num).getElementsByTagName("a");
    for (i = 0; i < tags.length; i++) {
        tags.item(i).className = '';
    }
    document.getElementById("menu" + obj).className = 'hover';
}



//JS设置radiobuttonlist值
function setcheck(id, ddd)//id表示控件ID号,ddd表示值
{
    var radiolist = id;
    for (var i = 0; i < document.getElementById(radiolist).rows.length; i++) {
        for (var x = 0; x < document.getElementById(radiolist).rows[i].cells.length; x++) {
            if (document.getElementById(radiolist).rows[i].cells[x].firstChild != "undefine") {
                if (document.getElementById(radiolist).rows[i].cells[x].firstChild.value == ddd) {
                    document.getElementById(radiolist).rows[i].cells[x].firstChild.checked = true;
                }

            }
        }
    }
}

//打开窗口
function openWindow(url, title, width, height) {
    window.open(url, title, "scrollbars=no,status=no,resizable=no,top=" + (screen.height - height) / 2 + ",left=" + (screen.width - width) / 2 + ",width=" + width + ",height=" + height);
}
function resizeWindow() {
    try {
        self.moveTo(0, 0);
        self.resizeTo(screen.availWidth, screen.availHeight);
    } catch (err) {

    }
}

//图片自动缩放
function DrawImage(ImgD, FitWidth, FitHeight) {
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= FitWidth / FitHeight) {
            if (image.width > FitWidth) {
                ImgD.width = FitWidth;
                ImgD.height = (image.height * FitWidth) / image.width;
            }
            else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
        else {
            if (image.height > FitHeight) {
                ImgD.height = FitHeight;
                ImgD.width = (image.width * FitHeight) / image.height;
            }
            else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
        }
    }
}


