// JavaScript Document
var wfly=new Object();

//去掉字符串两边的空格
String.prototype.Trim = function(){ 
      return this.replace(/(^\s*)|(\s*$)/g, "");
	 }
//去掉字符串左边的空格	 
String.prototype.LTrim=function(){
	  return this.replace(/(^\s*)/g, "");
	}
//去掉字符串右边的空格	
String.prototype.RTrim=function(){
	  return this.replace(/(\s*$)/g, "");
	}	

//获取ID对象
wfly.$=function(id){
	  return "string" == typeof id ? document.getElementById(id) : id;
	 }
	 
//四舍五入函数
wfly.ForDight=function(Dight,How){
		return Math.round(Dight*Math.pow(10,How))/Math.pow(10,How);
	 }
	 
//判断浏览器的是否为IE以及版本	 
wfly.isIE=function(){
	  return (document.all) ? true : false;
	}
wfly.isIEV=function(version){
	  return wfly.isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == version);
	}	
	
//表单验证	
wfly.Form={
	reg:{
		 UserName: /^([a-z]|[A-Z])[0-9a-zA-Z_]{4,19}$/,  //用户名
		 Password: /^[0-9a-zA-Z_\@]{6,12}$/,    //用户密码
		 Email:/^[a-zA-Z]([a-zA-Z0-9]*[-_.]?[a-zA-Z0-9]+)+@([\w-]+\.)+[a-zA-Z]{2,}$/  //E-Mail
		},
	 isUserName:function(val){
		   return wfly.Form.reg["UserName"].test(val);
	     },	  
	 isPassword:function(val){
		   return wfly.Form.reg["Password"].test(val);
		 },	   
	 isEmail:function(val){
		   return wfly.Form.reg["Email"].test(val);
		 }
	}

wfly.Window={
	//弹出模式窗口
	showModalDialog:function(URL,width,height){
    	var iWidth=width; //窗口宽度
        var iHeight=height;//窗口高度
        var iTop=(window.screen.height-iHeight)/3;
        var iLeft=(window.screen.width-iWidth)/2;
        window.showModalDialog(URL,window,"dialogHeight: "+iHeight+"px; dialogWidth: "+iWidth+"px;dialogTop: "+iTop+"; dialogLeft: "+iLeft+"; resizable: no; status: no;scroll:no");
	},
	//弹出一般窗口
	ShowDialog:function(URL,width,height){
		   var iWidth=width; //窗口宽度
           var iHeight=height;//窗口高度
           var iTop=(window.screen.height-iHeight)/3;
           var iLeft=(window.screen.width-iWidth)/2;
           window.open(URL,"Detail","Scrollbars=no,Toolbar=no,Location=no,Direction=no,Resizeable=no,Width="+iWidth+" ,Height="+iHeight+",top="+iTop+",left="+iLeft); 
	}
}


//使用onload=DrawImage(this,长,宽);
function DrawImage(ImgD,w,h){
	var image=new Image();
	image.src=ImgD.src;
	if(image.width>0 && image.height>0){
		flag=true;
		if(image.width/image.height>= w/h){
			if(image.width>w){
				ImgD.width=w;
				ImgD.height=(image.height*w)/image.width;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
	//ImgD.alt=image.width+"×"+image.height;
		}else{
			if(image.height>h){
				ImgD.height=h;
				ImgD.width=(image.width*h)/image.height;
			}else{
				ImgD.width=image.width;
				ImgD.height=image.height;
			}
		//ImgD.alt=image.width+"×"+image.height;
		}
	}
}
