//等比缩放图片,Kennytian@msn.com
//<img src="images/KennyLogo.gif" border="0" style="zoom: 0.1" onload="resizeImage(this, 80, 60)"/>
function resizeImage(obj, width, height) { 
  myImage = new Image();
  myImage.src = obj.src;
  if (myImage.width>0 && myImage.height>0) { 
    var rate = 1;
    if (myImage.width>width || myImage.height>height)
    {
      if (width/myImage.width<height/myImage.height)
        rate = width/myImage.width;
      else
        rate = height/myImage.height;
    }
    if (window.navigator.appName == "Microsoft Internet Explorer")
      obj.style.zoom = rate;
    else {
      obj.width = myImage.width*rate;
      obj.height = myImage.height*rate;
    }
  }
}

function isNum(str) {
  var re = /^[0-9]*[1-9][0-9]*$/;
  //if(!re.test(str) || str.length < 0) return false;
  return re.test(str)
}

//返回字符串长度
function checkLength(string) {
  string = string.replace(/\[em([0-9]+)\]/g,'');
  var docLen = 0;
  for(var i = 0; i <string.length; i++ ) {   
    if(string.charCodeAt(i)>255) docLen += 2;   
    else docLen += 1;   
  }
  return docLen;
}

//return boolean
function chkUsername(username) {
  var re = /^([a-zA-Z0-9])([a-zA-Z0-9\-_@.]+)$/;
  if (!re.test(username) || username.length < 4 || username.length > 31) {
    //showMsg('userDiv','非法用户名','#F00',4);
    alert("非法用户名");
    return false;
  }
  else {
    //showMsg('userDiv','合法用户名','green',4);
    alert("合法用户名");
	return true;
  }
}

var timer;
function showMsg(msgDiv,msgText,color,iTime) {
  $(msgDiv).style.display="inline";
  $(msgDiv).innerHTML = "<span style=\"color:"+color+";\">"+msgText+"</span>";
  if(iTime!=null )
    timer = setTimeout("closeMsg('"+msgDiv+"')", iTime*1000);
}

function fGetCode(id) {
  var vcode = $(id);
  vcode.src='ValidateCode.aspx?randNum='+Math.random()+"";
}

function title_color(txb,color) {
  $(txb).style.color = color;
}

function $(oid) {
  return document.getElementById(oid);
}

function closeMsg(msgDiv) {
  $(msgDiv).style.display="none";
  $(msgDiv).innerHTML="";
}
