﻿function imgAutoSize(img,MaxWidth,MaxHeight) 
{ 
 var HeightWidth=img.offsetHeight/img.offsetWidth;//设置高宽比
 var WidthHeight=img.offsetWidth/img.offsetHeight;//设置宽高比
 if(img.readyState!="complete")return false;//确保图片完全加载 
 if(img.offsetWidth>MaxWidth){
  img.width=MaxWidth;
  img.height=MaxWidth*HeightWidth;
 }
 if(img.offsetHeight>MaxHeight){
  img.height=MaxHeight;
  img.width=MaxHeight*WidthHeight;
 }
} 




function getObject(objectId) {
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getObject

//过滤HTMl脚本
function removeHTML(strText)
{
var regEx = /<[^>]*>/g;
return strText.replace(regEx, "");
}


//' 函数名: trim
//  功能描述  ：去掉空格
//	传入参数  :
//		str   待检字符	
//	返回值 ：去掉空格的字符串
//	创建时间:2005-01-19
function trim(str) {
    return str.replace(/(^\s*)|(\s*$)/g, "");
}


// JScript 文件



//' 函数名: isNumber
//  功能描述  ：数字检查
//	传入参数  :
//		c   待检字符	
//		 返回值 ：最大值
//		 创建时间:2005-01-19
function isNumber(oNum) {
  var   pattern   =   /^(\d+)$/;   //   正则表达式   
  return (pattern.test(oNum));   //   测试字符串是8位或9位的数字

}


function isDouble(sDouble){
  var re = /^\d+(?=\.{0,1}\d+$|$)/
  return re.test(sDouble)
}



function isEmail(c)
{
	var chk=true;
	if ( c=='' || !c.match(/^[\w\.\-]+@([\w\-]+\.)+[a-z]{2,4}$/ig)){chk=false}
	return chk;

}

function isDomain(c)
{
	var chk=true;
	if(c==''|| !c.match(/^[a-zA-Z0-9]{3,16}$/ig)){chk=false}
	return chk;
}

//' 函数名: isChar
//  功能描述  ：英文字母检查
//	传入参数  :
//		c   待检字符	
//		 返回值 ：最大值
//		 创建时间:2005-01-19
//
function isChar(c) {
    if (((c>='a') && (c<='z')) || ((c>='A') && (c<='Z')))
        return true;
    else
    {
        return false;
    }    
}


//
//' 函数名: isCode
//  功能描述  字符检查
//	传入参数  :
//		c   待检字符	
//		 返回值 ：最大值
//
function isCode(c) 
{
    if (((c>='a') && (c<='z')) || ((c>='A') && (c<='Z')) || ((c>='0') && (c<='9')) || (c=='_'))
       {
        return true;
        }
    else
    {
        return false;
    }
}

//
//' 函数名: isTel
//  功能描述  电话号码检查
//	传入参数  :
//		str   待检字符	
//	返回值 ：无
function isTel(str){
       var reg=/^([0-9]|[\-])+$/g ;
       if(str.length<7 || str.length>18){
        return false;
       }
       else{
         return reg.exec(str);
       }
}

//
//' 函数名: isZipCode
//  功能描述  邮政编码检查
//	传入参数  :
//		zip   待检字符	
//	返回值 ：无
//	创建时间:2005-01-19
//
function isZipCode(zip) {
    if (zip!=null)
    {
        zip=trim(zip);
        if(zip.length ==0 || zip.length ==5 || zip.length ==6)
        {
            if(!isNumber(zip))
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
    else    
    return true;
}


//
//
//' 函数名: checkCNCode
//  功能描述  中文字符判断
//	传入参数  :
//		str  待检字符
//	返回值 ：无
//	创建时间:2005-01-19
//
function checkCNCode(str) {
var reg=/^[\u0391-\uFFE5]+$/;
return reg.test(str)
}


function isName(c)
{
	var chk=true;
	if(c==''|| !c.match(/^[a-zA-Z0-9]{3,20}$/ig)){chk=false}
	return chk;
}

String.prototype.isDate = function()
{
   var r = this.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/); 
   if(r==null)return false; var d = new Date(r[1], r[3]-1, r[4]); 
   return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]);
}

String.prototype.isTime = function()
{
  var r = this.match(/^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/); 
  if(r==null)return false; var d = new Date(r[1], r[3]-1,r[4],r[5],r[6],r[7]); 
  return (d.getFullYear()==r[1]&&(d.getMonth()+1)==r[3]&&d.getDate()==r[4]&&d.getHours()==r[5]&&d.getMinutes()==r[6]&&d.getSeconds()==r[7]);
}


String.prototype.isUrl = function()
{
  var reg=/^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;
  return reg.test(this);
}

String.prototype.trim=function()
{
  return this.replace(/(^\s*)|(\s*$)/g, "");
}


 

