var utils;
var mh;
var mw;

var ImgD;
if(!utils)
{
	utils={};
}

/**
 * 根据图片比例加载图片
 * @author 吕靖
 * @param maxHeight 该图片的最大高度
 * @param MaxWidth 该图片的最大宽度
 * @param img 图片对象
 * 
 * 说明：在图片的onload事件中调用该方法
 * */
utils.loadImg=function(MaxHeight,MaxWidth,img)
{
	var image=new Image();
	//var HeightWidth=image.offsetHeight/image.offsetWidth;//设置高宽比 
	//var WidthHeight=image.offsetWidth/image.offsetHeight;//设置宽高比 
	$(image).css({"max-width":MaxWidth,"max-height":MaxHeight,"vertical-align":"middle"});
	image.src = img.src;
	if(image.complete == false)return false;//确保图片完全加载 
	
	
	if(image.width>0 && image.height>0){
		if(image.width/image.height>= MaxWidth/MaxHeight){
			if(image.width>MaxWidth){
				img.width=MaxWidth;
				img.height=(image.height*MaxWidth)/image.width;
            }else{
            	img.width=image.width; 
            	img.height=image.height;
            }

		}
		else
		{
			if(image.height>MaxHeight){
				img.height=MaxHeight;
				img.width=(image.width*MaxHeight)/image.height;
            }else{
            	img.width=image.width; 
            	img.height=image.height;
            } 

		}
		
	}
	
//	if(image.offsetWidth>mw){ 
		//img.width=MaxWidth; 
		//img.height=MaxWidth*HeightWidth; 
//		$(image).css({width:mw,height:mw*HeightWidth});
//	} 
//	if(image.offsetHeight>mh){ 
		//img.height=MaxHeight; 
		//img.width=MaxHeight*WidthHeight; 
//		$(image).css({width:mh*WidthHeight,height:mh});
//	}
	
	
}

utils.loadImg1=function(MaxHeight,MaxWidth,img)
{
	mh = MaxHeight;
	mw = MaxWidth;
	image.src = img.src;
	ImgD=img;
	setTimeout("utils.loadImg1()",1000);
}
/**
 * 获取file文本域的完整的路径，解决firfox8和ie8只能获取文件名问题
 * @author 吕靖
 * @param file 文本域对象
 * 
 * */
utils.getFileFull=function(file)
{
	if($.browser.mozilla)
	{
		if (file.files) {
            try {
            netscape.security.PrivilegeManager.enablePrivilege( 'UniversalFileRead' )
            }
            catch (err) {}
            };
            
            return file.value;
	}
	else if($.browser.msie)
	{
		if($.browser.version="8.0")
		{
			file.select();
			return document.selection.createRange().text;
		}
		else
		{
			return file.value;
		}
	}
	else
	{
		return file.value;
	}
}

/**
 * 清空file文本域的值
 * @author 吕靖
 * @param file 文本域对象
 * 
 * */
utils.clearFile=function(file)
{
	
	$(file).wrap("<form id='temForm'></form>");
	document.getElementById("temForm").reset();
	$(file).insertBefore("#temForm");
	$("form").remove("#temForm");
}


