var Captcha = Class.create({
	initialize:function(url,id){
		this.url=url;
		this.id=id;
		this.imgUrl='';
		if (Object.isElement($(id))){
    	this.ele = $(id); 
		} else {
			alert('cannot found Captcha input box : '+id);
			return false;
		}

    var code='\
			<img id="' + this.id + '_CAPTCHA_IMG' + '" src="' + this.setUrl() + '" style="vertical-align:bottom;" />\
			<img id="' + this.id + '_CAPTCHA_REFRESH' + '" src="_lib/captcha/refresh.gif" style="vertical-align:bottom;cursor:pointer; margin-left:3px;" alt="更換另一張圖片" />\
			<br />\
		';
    
    this.ele.insert({before:code});
		this.eventRefreshClick=this.reset.bindAsEventListener(this);
    Event.observe(this.id + '_CAPTCHA_REFRESH', 'click', this.eventRefreshClick);

	},
	
	setUrl:function(){
		this.imgUrl+=this.url + '?id=' + this.id + '&' + Math.random();
		return this.imgUrl;
	},
	
	reset:function(){
		$(this.id + '_CAPTCHA_IMG').src=this.setUrl();
	}
	
});	