//*****************************************************************
//函数名: strLen
//输 入: strtemp --- 要检查的字符串
//输 出: 字符串的长度
//功 能: 用来确定字符的长度,汉字占2个,数字英文占一个
//*****************************************************************
function strLen(strtemp)
{
return strtemp.replace(/[^/x00-/xff]/g,'ff').length;
}
//*****************************************************************
//函数名: SetFocus
//输 入: ID,为页面中控件的ID名
//输 出: 设置当前焦点的位置
//功 能: 设置当前焦点的位置
//*****************************************************************
function SetFocus(ID){document.getElementById(ID).focus();}
//*****************************************************************
//函数名:ShowMsgAndSetFocus
//输 入: ID,为页面中控件的ID名,str为错误提示字符串
//输 出: 弹出错误提示信息,同时将当前的焦点位置移动到指定的位置
//功 能: 弹出错误提示信息,并设置当前焦点的位置
//*****************************************************************
function ShowMsgAndSetFocus(str,ID){
alert(str);
if(document.getElementById(ID))
{
document.getElementById(ID).focus();
}
else
{
ID.focus();
}
//document.getElementById(ID).focus();
}
//*****************************************************************
//函数名:IsEmpty
//输 入: ID,为页面中控件的ID名
//输 出: 如果要检测的控件值为空则返回 true,否则返回false
//功 能: 检测是否为空
//*****************************************************************
function IsEmpty(ID,errorstr)
{
var pattern =/^(/s)*$/;
if (pattern.test(document.getElementById(ID).value))
return true;
else
return false;
}
//*****************************************************************
//函数名: ChkLen
//输 入: ID,为页面中控件的ID名,min长度下限,max长度上限
//输 出: 如果要检测的控件值在长度下限和长度上限之间则返回 true,否则返回false
//功 能: 检测指定控件的值是否超出范围
//*****************************************************************
function ChkLen(ID,Min,Max)
{
var len=strLen(document.getElementById(ID).value);
if ((len>=Min)&(len<=Max))
return true;
else
return false;
}
//*****************************************************************
//函数名: ChkAlike
//输 入: ID1,ID2,为页面中要比较控件的ID名
//输 出: 如果要检测的两个控件的值相同则返回 true,否则返回false
//功 能: 检测指定控件的值是否相同(检查时会去掉所有的空格符,包括tab键和换行符)
//*****************************************************************
function ChkAlike(ID1,ID2)
{
var str1;
var str2;
var re=/(/s*)(/S*)(/s*)(/S*)(/s*)/;
str1=document.getElementById(ID1).value.replace(re, "$2$4");
str2=document.getElementById(ID2).value.replace(re, "$2$4");
if (str1==str2)
return true;
else
return false;
}
//*****************************************************************
//函数名:IsSpecial
//输 入: ID,为页面中控件的ID名
//输 出: 如果要检测的控件值为<、>、'的字符则返回 true,否则返回false
//功 能: 检测是否为字母,数字或下划线外的字符
//*****************************************************************
function IsSpecial(ID)
{
if (/[<>']+/.test(document.getElementById(ID).value))
return true;
else
return false;
}
//*****************************************************************
//函数名:IsPhone
//输 入: ID,为页面中控件的ID名
//输 出: 如果要检测的控件值为电话号码则返回 true,否则返回false
//功 能: 检测是否为手机号
//*****************************************************************
function IsPhone(ID)
{
var pattern =/^[0-9;;/-/+/(/)()+-]*$/;
var pattern2 =/^(/s)*$/;
if (pattern2.test(document.getElementById(ID).value)){return true;}
if (pattern.test(document.getElementById(ID).value))
return true;
else
return false;
}
//*****************************************************************
//函数名: IsNum
//输 入: ID,为页面中控件的ID名
//输 出: 如果要检测的控件值只有数字则返回 true,否则返回false
//功 能: 检测指定控件的值是否只有数字(0-9)
//*****************************************************************
function IsNum(ID)
{
var pattern =/^[0-9]*$/;
var pattern2 =/^(/s)*$/;
//var objvalue = document.getElementById(ID).value;
var objvalue;
if(document.getElementById(ID))
{
objvalue = document.getElementById(ID).value;
}
else
{
objvalue = ID.value;
}
if (pattern2.test(objvalue)){return true;}
if (pattern.test(objvalue))
return true;
else
return false;
}
//*****************************************************************
//==================================================================================================
//将代码转换为名字
function CodeToName(){
var arr,from="",Separator1="",Separator2="",str="";
this.From = function(value){
from = value;
}
this.Separator1 = function(value){
Separator1 = value;
}
this.Separator2 = function(value){
Separator2 = value;
}
this.Open = function(){
arr = from.split(";");
}
this.Close = function(){
arr=null;
}
this.GetName = function(value){
if (Separator1==""){
str = value;
return twofenfind(0,arr.length-2);
}
else{
var arrtemp,strtemp="";
arrtemp = value.replace(" ","").split(Separator1);
for(i=0;i<arrtemp.length;i++){
if(arrtemp[i]!=""){
str = arrtemp[i];
if(strtemp!="")strtemp=strtemp+Separator2;
strtemp=strtemp+twofenfind(0,arr.length-2);
}
}
return strtemp;
}
}
function twofenfind(i,j){
var t=Math.ceil((i+j)/2),arri,arrj,arrt;
arri = arr[i].split(",");arrj = arr[j].split(",");
if (arri[0]<str && str<arrj[0] &&(j-i)>1)
{
arrt = arr[t].split(",");
if (str==arrt[0]) {return arrt[1];}
if (str<arrt[0])
{
return twofenfind(i,t);
}
else
{
return twofenfind(t,j);
}
}
else
{
if (arri[0]==str) return arri[1];
if (arrj[0]==str) return arrj[1];
return "";
}
}
}
//*****************************************************************
//函数名: HideMe
//输 入: idName -------要隐藏的控件ID名
//输 出: 无
//功 能: 隐藏指定控件
//****************************************************************
function HideMe(idName){
var obj = document.getElementById(idName);
if(obj){
if (obj.style.display=='')
obj.style.visibility="hidden";
else
obj.style.display="none";
}
}
//*****************************************************************
//函数名: ShowLwin
//输 入: idName -------要显示的控件ID名
//输 出: 无
//功 能: 显示指定控件
//****************************************************************
function ShowLwin(idName){
var obj = document.getElementById(idName);
if(obj){
if (obj.style.display=='')
obj.style.visibility="visible";
else
obj.style.display="block";
}
}