/**
 * @namespace com.thesis.control.ValidateCode
 * @author 钟军锐 August.R@263.net
 */

/** @id ValidateCode */
function ValidateCode(sID,sURL,sBtnID,bInit){
	this.vcImage = document.getElementById(sID);
	this.sURL = sURL;
	this.btn = null;
	if(sBtnID) this.btn = document.getElementById(sBtnID);
	if(typeof this.vcImage == "undefined" || this.vcImage == null ) return null;
	if(this.vcImage.nodeName.toLocaleUpperCase() != "IMG") return null;
	if(typeof ValidateCode._initialized == "undefined"){
		ValidateCode._initialized = true;
		/** @id changeImage */
		ValidateCode.prototype.changeImage = function(){
			this.vcImage.src = this.sURL + "?id=" + Math.random()*10000;
		}
		/** @id initialize */
		ValidateCode.prototype.initialize = function(oRoot){
			uEvent.addBrowserHandler(oRoot.vcImage,"click",function(){
				oRoot.changeImage();
			});
			if(this.btn){
				uEvent.addBrowserHandler(oRoot.btn,"click",function(){
					oRoot.changeImage();
				});
			}
			this.vcImage.style.cursor="pointer";
			this.vcImage.title = "点击更换验证码";
		}
	}
	
	this.initialize(this);
	if(bInit)
		this.changeImage();
}

