
var tp_captchaMgr = Class.create();
tp_captchaMgr.prototype = {
   initialize: function(domain) {
	this.imgCaptcha='tp_imgCaptcha';
	this.code='tp_cc';
	this.domain="";
	if(this.initialize.arguments[0]){this.domain=domain;}
	this.url=this.domain+"/apis/scripts/updatecaptcha.ashx";
	this.useXMLHttpRequest=true;
	if(this.initialize.arguments[1]){if(this.initialize.arguments[1]==false){this.useXMLHttpRequest=false;}}
   },
   
   updateCaptcha: function()
	{ 
	//var u=this.domain+"/apis/scripts/updatecaptcha.ashx";
	//alert(this.url);
	//var myAjax = new Ajax.Request(this.url +"&"+Math.random(),{method: 'get', parameters: "", onComplete: this.replaceCaptcha.bind(this)});
	if (this.useXMLHttpRequest==false)
		{
		tp_remoteMgr.addScript("tp_remotemgr.updatecaptcha.",this.url +"&rnd="+Math.random()+"&xmlhttp=false");
		}
	else
		{
		var myAjax = new Ajax.Request(this.url +"?rnd="+Math.random()+"&xmlhttp=true",{method: 'get', parameters: "", onComplete: this.replaceCaptcha.bind(this)});
		}
	},
	
   updateURL: function(u)
	{ 
	this.url=u;
	},

   replaceCaptcha: function(r)  
	{
	try{	
		var tp_updatedImage = r.responseText.evalJSON();		
		var i = ProtoProxy.tp_GetID(this.imgCaptcha);
		var c = ProtoProxy.tp_GetID(this.code);
		i.src=tp_updatedImage.src;
		c.value=tp_updatedImage.cc;		
	}
	catch(e){"error: " + alert(e.message);}
	}
}	
