// JavaScript Document
function myAddPanel(title,url,desc)
{
	if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function'))//Gecko
	{
		window.sidebar.addPanel(title,url,desc);
	}
	else//IE
	{
		window.external.AddFavorite(url,title);
	}
}

String.prototype.trim=function(){
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
function $(n){
	return document.getElementById(n);
}
function dw(s){
	document.write(s);
}
//替换引号为中文
String.prototype.filter = function(){
   return this.replace(/\'/g,'’').replace(/\"/g,'“');
}
//取得字符传的字节长度
String.prototype.bLength = function (){	
	var str = this;
	var len = 0;
	for (i=0;i<str.length;i++){
		if (str.charCodeAt(i)>255) 
			len+=2; 
		else 
			len++;			
	}
	return len;
}
//判断是否符合 e-mail 的形式
String.prototype.isEmail = function(){
	if(/^([a-zA-Z0-9_\.-]+)@(([a-zA-Z0-9_-]+)\.)+[a-zA-Z]{2,4}$/.test(this)) {return true;}
	return false;
}
//判断是否数字
function isnum(nnn){
	if (/^\d+.?\d*$/ig.test(nnn)){
		return true;
	}
	return false;
}

//图片按比例缩放
function DrawImage(ImgD,iwidth,iheight){
	//参数(图片,允许的宽度,允许的高度)
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
		flag=true;
		if(image.width/image.height>= iwidth/iheight){
			if(image.width>iwidth){ 
				ImgD.width=iwidth;
				ImgD.height=(image.height*iwidth)/image.width;
			}else{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
		}else{
			if(image.height>iheight){ 
				ImgD.height=iheight;
				ImgD.width=(image.width*iheight)/image.height; 
			}else{
				ImgD.width=image.width; 
				ImgD.height=image.height;
			}
		}
	}
}
