ckajax=new Object();ckajax.T=[];ckajax.CTime=60*1000;ckajax.C=[];ckajax.getCached=function(url,post,fcn,user,pswd,headers){var c=ckajax.C[url];if(post==null&&c!=null&&(new Date()).getTime()<(c[0]+ckajax.CTime)){if(fcn==null){return c[1];}else{return fcn(200,'OK',c[1]);}}return ckajax.getText(url,post,fcn,user,pswd,headers);};ckajax.getText=function(url,post,fcn,user,pswd,headers){var xhr,h=document.location.host,tran=ckajax.T.length,start=(new Date()).getTime();if(h=='')h=null;var ua=navigator.userAgent,cors=ua.indexOf('MSIE 6')==-1&&ua.indexOf('MSIE 7')==-1&&ua.indexOf('Firefox/2')==-1&&ua.indexOf('Firefox/3.0')==-1;if(!cors&&url.indexOf(':/\/')!=-1&&url.indexOf(':/\/'+h+'/')==-1)return 'Error: Script host must match page host.';if(window.XMLHttpRequest){try{xhr=new XMLHttpRequest();}catch(e){return 'Error: Could not open XMLHttpRequest,old browser?';}}else if(window.ActiveXObject){try{xhr=new ActiveXObject('Msxml2.XMLHTTP');}catch(e){try{xhr=ActiveXObject('Microsoft.XMLHTTP');}catch(e){return 'Error: Could not open ActiveXObject,old browser?';}}}else{return 'Error: Cannot load any XMLHttpRequest objects,really old browser?';}if(!('withCredentials' in xhr)&&typeof XDomainRequest!='undefined')xhr=new XDomainRequest();if(fcn){xhr.onreadystatechange=function(){if(xhr.readyState==4){var now=(new Date()).getTime();try{var t=xhr.status;}catch(e){return fcn(-1,'unk','Could not contact server,try again later');}if(xhr.status==200)ckajax.C[url]=[now,xhr.responseText];ckajax.T[tran]=now-start;if(typeof debug=='function')debug('ckajax.T['+tran+']['+url+']='+ckajax.T[tran]);fcn(xhr.status,xhr.statusText,xhr.responseText);}};}try{xhr.open((post!=null ? 'POST' : 'GET'),url,fcn!=null,user,pswd);xhr.setRequestHeader('Origin','http:/\/'+h);xhr.setRequestHeader('Access-Control-Request-Method','GET,POST');if(post!=null)xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');if(headers!=null){var hdr=headers.split('\n');for(var i=0;i<hdr.length;i++){if(hdr[i].length==0)continue;var nv=hdr[i].split(': ');xhr.setRequestHeader(nv[0],nv[1]);}}xhr.send(post);}catch(e){return 'Error: Could not send request;is the target even there?';}if(fcn!=null)return 'OK';if(xhr.status!=200)return 'Error: '+xhr.status+' status: '+xhr.statusText;ckajax.T[tran]=(new Date()).getTime()-start;return ckajax.C[url]=xhr.responseText;};ckajax.importJS=function(url,fcn){var s=document.createElement('script');s.type='text/javascript';s.src=url;document.getElementsByTagName('head')[0].appendChild(s);if(fcn!=null)setTimeout(fcn,100);};function gel(id){return document.getElementById(id);}var ckOldOnLoad=window.onload;var ckp=new CKPass();window.onload=function(){if(ckOldOnLoad!=null)ckOldOnLoad();ckp.loaded=true;ckp.clicked=false;var e=gel('ckInPswd');e.value='';e.onfocus=ckp.onClick;ckp.checkPswd();};function CKPass(){this.loaded=true;this.clicked=false;this.N=new Image();this.N.src='images/redx.gif';this.Y=new Image();this.Y.src='images/greencheck.gif';this.blank=new Image();this.blank.src='images/blank.gif';this.low=2;this.upp=2;this.dig=2;this.oth=0;this.tot=8;this.ent=2.9999999;if(CKPass.words==null){ckajax.getText('words2.txt',null,function(stat,statStr,resp){if(stat==200){CKPass.words=resp;}else{alert('Problem getting words: HTTP '+stat+' / '+statStr);}});}this.onClick=function(){if(this.clicked)return;this.clicked=true;gel('ckInPswd').value='';};this.checkWords=function(P){var idx=0,end=0,W=CKPass.words;if(W==null)return null;P=P.toLowerCase();while((end=W.indexOf('\n',idx))!=-1){w=W.substr(idx,end-idx);if(P.indexOf(w)!=-1)return w;idx=end+1;}return null;};this.checkPswd=function(){var T=this;if(!T.calcEntropy)T=CKPass.me;CKPass.me=T;var basedOn=T.checkWords(gel('ckInPswd').value),basedHTML='';if(basedOn){gel('ckEnt').src=((T.ckEnt<=ent)? T.Y : T.N).src;basedHTML='<font color=red><b>Based on: \''+basedOn+'\'</b></font>';}gel('basedOn').innerHTML=basedHTML;var str=gel('ckInPswd').value,tot=str.length,low=0,dig=0,upp=0,oth=0;for(i=0;i<str.length;i++){c=str.charAt(i);if('a' <=c&&c <='z')low++;else if('A' <=c&&c <='Z')upp++;else if('0' <=c&&c <='9')dig++;else{oth++;}}gel('ckLow').src=((T.low<=low)? T.Y : T.N).src;gel('low').innerHTML=low;gel('ckUpp').src=((T.upp<=upp)? T.Y : T.N).src;gel('upp').innerHTML=upp;gel('ckDig').src=((T.dig<=dig)? T.Y : T.N).src;gel('dig').innerHTML=dig;gel('oth').innerHTML=oth;gel('ckTot').src=((T.tot<=tot)? T.Y : T.N).src;gel('tot').innerHTML=tot;var ent=T.calcEntropy(str);gel('ckEnt').src=((T.ent<=ent)? T.Y : T.N).src;gel('ckEntOut').innerHTML=ent;var dys=T.getDaysToGuess(basedOn,low,upp,dig,oth,tot,gel('ckGperD').value);dys=Math.floor(dys);dys=(999999999 < dys)? 999999999 : dys;gel('ckDaysOut').innerHTML=dys;gel('ckPswdOK').src=(dys < 365)? T.N.src : T.Y.src;setTimeout(T.checkPswd,500);};this.getDaysToGuess=function(basedOn,low,upp,dig,oth,tot,i){var d=1.0,fact=function(n){if(n==0)return 1;return n * fact(n-1);};if(basedOn){d=45425;}else{if(low!=0)d *=Math.pow(26,low);if(upp!=0)d *=Math.pow(26,upp);if(dig!=0)d *=Math.pow(10,dig);if(oth!=0)d *=Math.pow(10,oth);d *=fact(tot)/ fact(low)/ fact(upp)/ fact(dig);}return d /(i * 60 * 60 * 24);};this.calcEntropy=function(pswd){var ai=new Array();for(var i=0;i<pswd.length;i++){var c=pswd.charCodeAt(i);if(ai[c]==undefined)ai[c]=0;ai[c]++;}entropy=0;for(var i=0;i<ai.length;i++){if(ai[i]!=undefined&&ai[i]!=0){var d=ai[i]/ pswd.length;entropy+=d * Math.log(1.0 / d);}}entropy /=Math.log(2);var p=entropy,v=0,ret='';p-=v=Math.floor(p);p *=10;ret+=v+'.';p-=v=Math.floor(p);p *=10;ret+=v;p-=v=Math.floor(p);p *=10;ret+=v;return ret;};}

