var $=require("jquery"),Form=require("./form.js"),CommonVerify=function(e,r){r=r||null;var t=$.extend({generateServer:"",selectorTarget:"",selectorGenerate:"",selectorCountdown:"",selectorRegenerate:"",selectorCaptcha:"",selectorCaptchaImg:"",interval:60,tipError:function(e){r?r.tipError(e):alert(e)},sendError:function(e){r?r.tipError(e):alert(e)}},e),o=0,a=function(){var e=$(t.selectorCountdown);e.is("input")?e.val(o+" s"):e.html(o+" s"),o>0?(o--,setTimeout(a,1e3),$(t.selectorCountdown).show(),$(t.selectorRegenerate).hide()):(e.hide(),$(t.selectorCountdown).hide(),$(t.selectorRegenerate).show())},n=!1,c=function(){var e=$(t.selectorTarget).val(),c=null;return t.selectorCaptcha&&!(c=$(t.selectorCaptcha).val())?(t.tipError("图片验证码为空"),!1):!n&&(n=!0,r&&r.loadingOn(),$.post(t.generateServer,{target:e,captcha:c},function(e){r&&r.loadingOff(),n=!1,Form.defaultCallback(e,{success:function(e){e.data&&alert(e.data),$(t.selectorGenerate).hide(),o=t.interval,a()},error:function(e){$(t.selectorCaptchaImg).click(),e.data&&alert(e.data),t.sendError(e.msg)}},r)}),!1)};$(t.selectorGenerate).on("click",c),$(t.selectorRegenerate).on("click",c)};module.exports=CommonVerify;