﻿if(!window.$){
    $ = function(){
        var elements = new Array();
        for (var i=0;i<arguments.length;i++){
            var element=arguments[i];
        if (typeof element=='string'){
            element=document.getElementById(element);
        }
        if (arguments.length==1){
            return element;
        }
        elements.push(element);
    }
    return elements;}
}

//当指定ID的控件值为空时，提示msg的内容。
function alertEmpty(strID, msg){
    if($(strID).value==""){
        alert(msg);
        $(strID).focus();
        return true;
    }
    return false;
}

//当指定ID的控件值为指定的内容时，提示msg的内容。
function alertContent(strID, msg, content){
    if($(strID).value==content){
        alert(msg);
        $(strID).focus();
        return true;
    }
    return false;
}
        
//当指定ID的控件值未通过验证时，提示msg的内容。
function alertVerify(strID, msg, verifyFun)
{
    if(!verifyFun($(strID).value)){
        alert(msg);
        $(strID).focus();
        return true;
    }  
return false;
}
    
//验证电子邮件
function verifyEmail(strEmail){
    var regEmail=/\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    return strEmail.match(regEmail);
}
    
//验证日期
function verifyDate(strDate){
    var regDate = /^(?:(?!0000)[0-9]{4}([-/.]?)(?:(?:0?[1-9]|1[0-2])([-/.]?)(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])([-/.]?)(?:29|30)|(?:0?[13578]|1[02])([-/.]?)31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-/.]?)0?2([-/.]?)29)$/;
    return strDate.match(regDate);
}
    
//手机号验证
function verifyMobile(strMobile)
{
    var regMobile=/^0?\d{11}$/;
    return strMobile.match(regMobile);
}
    
//控制框架高度的自动变化。
function setWinHeight(obj)
{
    var win=obj;
    if (document.getElementById)
    {
        if (win && !window.opera)
        {
            if (win.contentDocument && win.contentDocument.body.offsetHeight)
                win.height = win.contentDocument.body.offsetHeight;
            else if(win.Document && win.Document.body.scrollHeight)
                win.height = win.Document.body.scrollHeight;
        }
    }
} 

//设置DOM元素的透明度
function setOpacity(id, opacity){
    var oBoard = document.getElementById(id); 
    if(oBoard.style.filter != undefined){
        if(typeof opacity=='number'){
            oBoard.style.filter="Alpha(opacity="+opacity*100+")";
        }
    }
    else if(oBoard.style.opacity != undefined){
        oBoard.style.opacity=opacity;
    }
}

//使页面不可用
function disablePage(){
    var width= Math.max(document.body.clientWidth,document.documentElement.clientWidth);
    var height=Math.max(document.body.clientHeight,document.documentElement.clientHeight);
             
    document.body.innerHTML+="<div id='markPanel' style='background-color: White; position: absolute; width: "+
    width+"px; height: "+(height)+"px; left: 0px; top: 0px;'></div>"
        
    //设置透明度
    setOpacity("markPanel",0.7);
        
    //调整高度
    onscroll=function(){
        var totalHeight = document.documentElement.scrollTop + document.documentElement.clientHeight;
        var oPanel = document.getElementById("markPanel");
        if(totalHeight > height && oPanel){
            oPanel.style.height=totalHeight;
        }
    }
} 

//使页面可用
function enablePage(){
    var oPanel = document.getElementById("markPanel");
    if(oPanel){
        document.body.removeChild(oPanel);
    }
}


