﻿// JScript 文件
//<![CDATA[
var userreg=/^([a-zA-Z]{1}([a-zA-Z0-9]|[_]){4,19}){1}([,][a-zA-Z]{1}([a-zA-Z0-9]|[_]){4,19}){0,}$/;
var denyinputAllowEmpty=/(<|>)|(^\s{1,}$)/;//允许空值
var denyinputDenyEmpty=/(<|>)|(^\s{0,}$)/;//不允许空值
var regempty=/^s{0}$/;//空值
var regyear=/^((19){1}|(20){1})[0-9]{1}[0-9]{1}$/;
var regdate=/^((19){1}|(20){1})[0-9]{1}[0-9]{1}\/((0[1-9]{1})|(1[0-2]{1}))\/((0[1-9]{1})|([1-2]{1}[0-9]{1})|(3[0-1]{1}))$/;
var regdecimal=/^([0-9]{1,8}\.[0-9]{1,2})|[0-9]{1,8}$/;//浮点数
var reginteger=/^[0-9]{1,9}$/;//整数

function Encode(strValue)
    {
        /*
        JavaScript中replace() 方法如果直接用str.replace("-","!") 只会替换第一个 匹配的字符.
        而str.replace(/\-/g,"!")则可以替换掉全部匹配的字符（g为全局标志）。
        */
        //&lt;&gt;<>
        var Tmp;
        //Tmp=strValue.replace(/\</g,"＜");
        Tmp=strValue.replace(/\</g,"[");
        //Tmp=Tmp.replace(/\>/g,"＞");
        Tmp=Tmp.replace(/\>/g,"]");
        //Tmp=Tmp.replace(/\\"/g,"＂");
        //Tmp=Tmp.replace(/\'/g,"＇");
        return Tmp;
    }
        
    //Dencode函数已在后台实现,在此无用.
function Dencode(strValue)
    {
        var Tmp;
        //Tmp=strValue.replace(/\＜/g,"<");
        Tmp=strValue.replace(/\[/g,"<");
        //Tmp=Tmp.replace(/\＞/g,">");
        Tmp=Tmp.replace(/\]/g,">");
        //Tmp=Tmp.replace(/\＂/g,"\"");
        //Tmp=Tmp.replace(/\＇/g,"'");
        return Tmp;
    }

//-------form focus style-----------

function suckerfish(type, tag, parentId)
{
    if (window.attachEvent)
    {
        window.attachEvent("onload",
            function()
            {
                var sfEls = (parentId == null) ? document.getElementsByTagName(tag) : document.getElementById(parentId).getElementsByTagName(tag);
                type(sfEls);
            }
        );
    }
}

sfFocus = function(sfEls)
{
    for (var i=0; i < sfEls.length; i++)
    {
        
        sfEls[i].onfocus=function()
        {
            if(this.className=="txtpwd")this.className = "sffocus";
        }

        sfEls[i].onblur= function()
        {
            if((this.className == "sffocus")&&(this.type=="text" || this.type=="password" || this.type=="textarea"))
                this.className="txtpwd";
        }
    }
}
suckerfish(sfFocus, "input");
suckerfish(sfFocus, "textarea"); 


//图片按比例缩放 
function DrawImage(objImg,maxwidth,maxheight)
{ 
    var v_MaxWidth = maxwidth;  //定义允许图片宽度 
    var v_MaxHeight =maxheight; //定义允许图片高度 
    
    var imgTmp=new Image();
    imgTmp.src=objImg.src;
    
    var oldWidth=imgTmp.width;
    var oldHeight=imgTmp.height;
    
    if(imgTmp.width>0 && imgTmp.height>0) //如果有图片显示
    { 
        if(imgTmp.width/imgTmp.height>= v_MaxWidth/v_MaxHeight)//如果图片大小超出了限制大小
        {//宽度超标的多
            if(imgTmp.width>v_MaxWidth)
            {   
			    imgTmp.width=v_MaxWidth;
			    imgTmp.height=oldHeight * v_MaxWidth/oldWidth;
            }
            else{/*不用调整*/} 
        } 
        else//高度超标的多
        { 
            if(imgTmp.height>v_MaxHeight)
            {   
			    imgTmp.width=oldWidth * v_MaxHeight/oldHeight;
			    imgTmp.height=v_MaxHeight; 
            }
            else{/*不用调整*/} 
        }
        objImg.width=imgTmp.width;
        objImg.height=imgTmp.height; 
    }
}

//]]>
