/*
06/06/2010 10.33
$js = "window.addEvent('domready', function(){checkCaptcha('".$form."','".$buttonid."','".$pswid."','".$msgid."'); })";
  function checkCaptcha(form) {
*/
//window.addEvent("domready",function(){
function checkCaptcha(form, buttonid, pswid, msgid, msg ) {
	$(buttonid).setProperty('disabled', 'true');
	var box = $(msgid);
	var fx = box.effects({duration: 1000, transition: Fx.Transitions.Quart.easeOut});

    $(pswid).addEvent("change",function(){
    	$(buttonid).setProperty('disabled', 'true');
    if ( $(pswid).value.length > 0 ){


        var url="index.php?option=com_"+form+"&amp;task=chkCaptcha&amp;format=raw&amp;"+pswid+"="+this.getValue()+"&amp;campo="+pswid+"&amp;fid="+buttonid;
        box.style.display="block";
    		box.setHTML(msg);
        var a=new Ajax(url,{
            method:"get",
            onComplete: function(response){
                var resp=Json.evaluate(response);

                if (resp.msg==='false'){
                 $(pswid).value='';
                 $(pswid).focus();
                   $(buttonid).setProperty('disabled', 'true');
                }else{
                	$(buttonid).removeProperty('disabled');
                }

                fx.start({
                    	}).chain(function() {
                    		box.setHTML(resp.html);
                    		this.start.delay(1000, this, {'opacity': 0});
                    	}).chain(function() {
                    		box.style.display="none";
                    		this.start.delay(1000, this, {'opacity': 1});
                    	});

            }
        }).request();
      }
    });
};
//-----15/03/2010 20.57-------//
function checkTestCaptcha(formid,form, buttonid,pswid,msgid ) {
           	/*
           	$("refreshtest").addEvent("click",function(){
		var url2="index.php?option=com_auser&format=raw&task=viewCaptacha"
		var a2=new Ajax(url2,{
					method:"get",
					onComplete: function(response){
						var resp=Json.evaluate(response);			
						 	 $('verticalForm').setHTML('');	
               $('verticalForm').setHTML(resp.html);	
				   }
			   }).request();
		});	
		*/
            var box = $(msgid);
	          var fx = box.effects({duration: 1000, transition: Fx.Transitions.Quart.easeOut});
            var formbox=formid;
           $(formid).addEvent('submit', function(e) {
				   new Event(e).stop();
      
            		  box.style.display="block";     
            		  box.setHTML('Check in progress...');	                             
               
               var url="index.php?option=com_"+form+"&amp;task=chkCaptcha&amp;format=raw&amp;"+pswid+"="+$(pswid).value+"&amp;campo="+pswid+"&amp;fid="+buttonid; 
                var a=new Ajax(url,{
                    method:"get",
                    onComplete: function(response){
                        var resp=Json.evaluate(response);
                        if (resp.msg==='false'){
                         $(pswid).value='';
                         $(pswid).focus();;
                        }
                        if (resp.msg==='true'){
                          $(formid).remove();	  
                          $('ajax-captcha-desc').setHTML('Captcha solved');	                      
                        box.style.display="block"; 
                        box.setHTML(resp.html);	      
                        }                      
                                
              
                         fx.start({	
		                    	}).chain(function() {
		                    		box.setHTML(resp.html);
		                    		this.start.delay(2500, this, {'opacity': 0});
		                    	}).chain(function() {
		                    		box.style.display="none";
		                    		this.start.delay(5001, this, {'opacity': 1});
		                    	});
                    }
                }).request();
              //} //la if  
             })
    }              

//-----15/03/2010 20.57-------//

	
