﻿// JScript 文件
function DownImage(ImgD,MaxWidth,MaxHeight,alignX,alignY)
{
	alignX=alignX||1;
	alignY=alignY||1;
    var image=new Image();
    image.src=ImgD.src;
    if(image.width>0 && image.height>0)
	{
		var rate = (MaxWidth/image.width < MaxHeight/image.height)?MaxWidth/image.width:MaxHeight/image.height;
		var wid=0;
		var hid=0;
		if(rate <= 1)
		{
			wid=ImgD.width=image.width*rate;
			hid=ImgD.height=image.height*rate;
		}
		else
		{
			wid=ImgD.width=image.width;
			hid=ImgD.height=image.height;
		}
		if(alignX==1)
		{
			var ii=(MaxWidth-wid)/2;
			ImgD.style.marginLeft=ImgD.style.marginRight=ii+"px";
		}
		if(alignY==1)
		{
			var ii=(MaxHeight-hid)/2;
			ImgD.style.marginTop=ImgD.style.marginBottom=ii+"px";
		}
    }
}

function LoadVerifyImage(obj)
{
	var randval = Math.random();
	obj.src= "/Tools/VerifyImage.aspx?r=" + randval;
}

//检查字节长度
function bytes(str){
	if(typeof(str)!='string'){
		str = str.value;
	}
	var len = 0;
	for(var i = 0; i < str.length; i++){
		if(str.charCodeAt(i) > 127){
			len++;
		}
		len++;
	}
	return len;
}
 