// Captcha JS object
//
//
// Dependencies:
//		moo.ajax.js
//
// Notes:
//		make sure that cCF is the url of the JSON file for the captcha info
//		

function Captcha(cCF, displayNodeId, captchaInputId, captchaMId) {
	this.cII = captchaInputId;
	this.cMI = captchaMId;
	this.nI = displayNodeId;
	this.cCF = cCF;
	this.cI = document.createElement('img');
	
	this.displayCaptcha = function () {
		this.cI.src='/images/ajax-loader.gif';
		this.cI.width=16;
		this.cI.height=16;
		if(!document.getElementById("captchaimage")) {
			this.cI.id='captchaimage';
			document.getElementById(eval(cN+".nI")).appendChild(this.cI);
		}
		
		new ajax(this.cCF, {postBody: 'edit=1', onComplete: this.newCaptcha});
	};
	
	this.newCaptcha = function (z) {
		
		z = z.responseText;
		this.c = eval('('+z+')');
		eval(cN+".cI.src=\""+this.c.image_url+"\"");
		eval(cN+".cI.width=125");
		eval(cN+".cI.height=35");
		eval(cN+".cI.onload='fixPNG(this)'");
		document.getElementById(eval(cN+".cII")).value = "";
		document.getElementById(eval(cN+".cMI")).value=this.c.md5sum;
	};
}                                                                                   

function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ? 
		             "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.style.cssText
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}

