function Arcfour(){this.i=0;this.j=0;this.S=new Array();}
function ARC4init(key){var i,j,t;for(i=0;i<256;++i)
this.S[i]=i;j=0;for(i=0;i<256;++i){j=(j+this.S[i]+key[i%key.length])&255;t=this.S[i];this.S[i]=this.S[j];this.S[j]=t;}
this.i=0;this.j=0;}
function ARC4next(){var t;this.i=(this.i+1)&255;this.j=(this.j+this.S[this.i])&255;t=this.S[this.i];this.S[this.i]=this.S[this.j];this.S[this.j]=t;return this.S[(t+this.S[this.i])&255];}
Arcfour.prototype.init=ARC4init;Arcfour.prototype.next=ARC4next;function prng_newstate(){return new Arcfour();}
var rng_psize=256;var rng_state;var rng_pool;var rng_pptr;function rng_seed_int(x){rng_pool[rng_pptr++]^=x&255;rng_pool[rng_pptr++]^=(x>>8)&255;rng_pool[rng_pptr++]^=(x>>16)&255;rng_pool[rng_pptr++]^=(x>>24)&255;if(rng_pptr>=rng_psize)rng_pptr-=rng_psize;}
function rng_seed_time(){rng_seed_int(new Date().getTime());}
if(rng_pool==null){rng_pool=new Array();rng_pptr=0;var t;if(navigator.appName=="Netscape"&&navigator.appVersion<"5"&&window.crypto){var z=window.crypto.random(32);for(t=0;t<z.length;++t)
rng_pool[rng_pptr++]=z.charCodeAt(t)&255;}
while(rng_pptr<rng_psize){t=Math.floor(65536*Math.random());rng_pool[rng_pptr++]=t>>>8;rng_pool[rng_pptr++]=t&255;}
rng_pptr=0;rng_seed_time();}
function rng_get_byte(){if(rng_state==null){rng_seed_time();rng_state=prng_newstate();rng_state.init(rng_pool);for(rng_pptr=0;rng_pptr<rng_pool.length;++rng_pptr)
rng_pool[rng_pptr]=0;rng_pptr=0;}
return rng_state.next();}
function rng_get_bytes(ba){var i;for(i=0;i<ba.length;++i)ba[i]=rng_get_byte();}
function SecureRandom(){}
SecureRandom.prototype.nextBytes=rng_get_bytes;var dbits;var canary=0xdeadbeefcafe;var j_lm=((canary&0xffffff)==0xefcafe);function BigInteger(a,b,c){if(a!=null)
if("number"==typeof a)this.fromNumber(a,b,c);else if(b==null&&"string"!=typeof a)this.fromString(a,256);else this.fromString(a,b);}
function nbi(){return new BigInteger(null);}
function am1(i,x,w,j,c,n){while(--n>=0){var v=x*this[i++]+w[j]+c;c=Math.floor(v/0x4000000);w[j++]=v&0x3ffffff;}
return c;}
function am2(i,x,w,j,c,n){var xl=x&0x7fff,xh=x>>15;while(--n>=0){var l=this[i]&0x7fff;var h=this[i++]>>15;var m=xh*l+h*xl;l=xl*l+((m&0x7fff)<<15)+w[j]+(c&0x3fffffff);c=(l>>>30)+(m>>>15)+xh*h+(c>>>30);w[j++]=l&0x3fffffff;}
return c;}
function am3(i,x,w,j,c,n){var xl=x&0x3fff,xh=x>>14;while(--n>=0){var l=this[i]&0x3fff;var h=this[i++]>>14;var m=xh*l+h*xl;l=xl*l+((m&0x3fff)<<14)+w[j]+c;c=(l>>28)+(m>>14)+xh*h;w[j++]=l&0xfffffff;}
return c;}
if(j_lm&&(navigator.appName=="Microsoft Internet Explorer")){BigInteger.prototype.am=am2;dbits=30;}
else if(j_lm&&(navigator.appName!="Netscape")){BigInteger.prototype.am=am1;dbits=26;}
else{BigInteger.prototype.am=am3;dbits=28;}
BigInteger.prototype.DB=dbits;BigInteger.prototype.DM=((1<<dbits)-1);BigInteger.prototype.DV=(1<<dbits);var BI_FP=52;BigInteger.prototype.FV=Math.pow(2,BI_FP);BigInteger.prototype.F1=BI_FP-dbits;BigInteger.prototype.F2=2*dbits-BI_FP;var BI_RM="0123456789abcdefghijklmnopqrstuvwxyz";var BI_RC=new Array();var rr,vv;rr="0".charCodeAt(0);for(vv=0;vv<=9;++vv)BI_RC[rr++]=vv;rr="a".charCodeAt(0);for(vv=10;vv<36;++vv)BI_RC[rr++]=vv;rr="A".charCodeAt(0);for(vv=10;vv<36;++vv)BI_RC[rr++]=vv;function int2char(n){return BI_RM.charAt(n);}
function intAt(s,i){var c=BI_RC[s.charCodeAt(i)];return(c==null)?-1:c;}
function bnpCopyTo(r){for(var i=this.t-1;i>=0;--i)r[i]=this[i];r.t=this.t;r.s=this.s;}
function bnpFromInt(x){this.t=1;this.s=(x<0)?-1:0;if(x>0)this[0]=x;else if(x<-1)this[0]=x+DV;else this.t=0;}
function nbv(i){var r=nbi();r.fromInt(i);return r;}
function bnpFromString(s,b){var k;if(b==16)k=4;else if(b==8)k=3;else if(b==256)k=8;else if(b==2)k=1;else if(b==32)k=5;else if(b==4)k=2;else{this.fromRadix(s,b);return;}
this.t=0;this.s=0;var i=s.length,mi=false,sh=0;while(--i>=0){var x=(k==8)?s[i]&0xff:intAt(s,i);if(x<0){if(s.charAt(i)=="-")mi=true;continue;}
mi=false;if(sh==0)
this[this.t++]=x;else if(sh+k>this.DB){this[this.t-1]|=(x&((1<<(this.DB-sh))-1))<<sh;this[this.t++]=(x>>(this.DB-sh));}
else
this[this.t-1]|=x<<sh;sh+=k;if(sh>=this.DB)sh-=this.DB;}
if(k==8&&(s[0]&0x80)!=0){this.s=-1;if(sh>0)this[this.t-1]|=((1<<(this.DB-sh))-1)<<sh;}
this.clamp();if(mi)BigInteger.ZERO.subTo(this,this);}
function bnpClamp(){var c=this.s&this.DM;while(this.t>0&&this[this.t-1]==c)--this.t;}
function bnToString(b){if(this.s<0)return"-"+this.negate().toString(b);var k;if(b==16)k=4;else if(b==8)k=3;else if(b==2)k=1;else if(b==32)k=5;else if(b==4)k=2;else return this.toRadix(b);var km=(1<<k)-1,d,m=false,r="",i=this.t;var p=this.DB-(i*this.DB)%k;if(i-->0){if(p<this.DB&&(d=this[i]>>p)>0){m=true;r=int2char(d);}
while(i>=0){if(p<k){d=(this[i]&((1<<p)-1))<<(k-p);d|=this[--i]>>(p+=this.DB-k);}
else{d=(this[i]>>(p-=k))&km;if(p<=0){p+=this.DB;--i;}}
if(d>0)m=true;if(m)r+=int2char(d);}}
return m?r:"0";}
function bnNegate(){var r=nbi();BigInteger.ZERO.subTo(this,r);return r;}
function bnAbs(){return(this.s<0)?this.negate():this;}
function bnCompareTo(a){var r=this.s-a.s;if(r!=0)return r;var i=this.t;r=i-a.t;if(r!=0)return r;while(--i>=0)if((r=this[i]-a[i])!=0)return r;return 0;}
function nbits(x){var r=1,t;if((t=x>>>16)!=0){x=t;r+=16;}
if((t=x>>8)!=0){x=t;r+=8;}
if((t=x>>4)!=0){x=t;r+=4;}
if((t=x>>2)!=0){x=t;r+=2;}
if((t=x>>1)!=0){x=t;r+=1;}
return r;}
function bnBitLength(){if(this.t<=0)return 0;return this.DB*(this.t-1)+nbits(this[this.t-1]^(this.s&this.DM));}
function bnpDLShiftTo(n,r){var i;for(i=this.t-1;i>=0;--i)r[i+n]=this[i];for(i=n-1;i>=0;--i)r[i]=0;r.t=this.t+n;r.s=this.s;}
function bnpDRShiftTo(n,r){for(var i=n;i<this.t;++i)r[i-n]=this[i];r.t=Math.max(this.t-n,0);r.s=this.s;}
function bnpLShiftTo(n,r){var bs=n%this.DB;var cbs=this.DB-bs;var bm=(1<<cbs)-1;var ds=Math.floor(n/this.DB),c=(this.s<<bs)&this.DM,i;for(i=this.t-1;i>=0;--i){r[i+ds+1]=(this[i]>>cbs)|c;c=(this[i]&bm)<<bs;}
for(i=ds-1;i>=0;--i)r[i]=0;r[ds]=c;r.t=this.t+ds+1;r.s=this.s;r.clamp();}
function bnpRShiftTo(n,r){r.s=this.s;var ds=Math.floor(n/this.DB);if(ds>=this.t){r.t=0;return;}
var bs=n%this.DB;var cbs=this.DB-bs;var bm=(1<<bs)-1;r[0]=this[ds]>>bs;for(var i=ds+1;i<this.t;++i){r[i-ds-1]|=(this[i]&bm)<<cbs;r[i-ds]=this[i]>>bs;}
if(bs>0)r[this.t-ds-1]|=(this.s&bm)<<cbs;r.t=this.t-ds;r.clamp();}
function bnpSubTo(a,r){var i=0,c=0,m=Math.min(a.t,this.t);while(i<m){c+=this[i]-a[i];r[i++]=c&this.DM;c>>=this.DB;}
if(a.t<this.t){c-=a.s;while(i<this.t){c+=this[i];r[i++]=c&this.DM;c>>=this.DB;}
c+=this.s;}
else{c+=this.s;while(i<a.t){c-=a[i];r[i++]=c&this.DM;c>>=this.DB;}
c-=a.s;}
r.s=(c<0)?-1:0;if(c<-1)r[i++]=this.DV+c;else if(c>0)r[i++]=c;r.t=i;r.clamp();}
function bnpMultiplyTo(a,r){var x=this.abs(),y=a.abs();var i=x.t;r.t=i+y.t;while(--i>=0)r[i]=0;for(i=0;i<y.t;++i)r[i+x.t]=x.am(0,y[i],r,i,0,x.t);r.s=0;r.clamp();if(this.s!=a.s)BigInteger.ZERO.subTo(r,r);}
function bnpSquareTo(r){var x=this.abs();var i=r.t=2*x.t;while(--i>=0)r[i]=0;for(i=0;i<x.t-1;++i){var c=x.am(i,x[i],r,2*i,0,1);if((r[i+x.t]+=x.am(i+1,2*x[i],r,2*i+1,c,x.t-i-1))>=x.DV){r[i+x.t]-=x.DV;r[i+x.t+1]=1;}}
if(r.t>0)r[r.t-1]+=x.am(i,x[i],r,2*i,0,1);r.s=0;r.clamp();}
function bnpDivRemTo(m,q,r){var pm=m.abs();if(pm.t<=0)return;var pt=this.abs();if(pt.t<pm.t){if(q!=null)q.fromInt(0);if(r!=null)this.copyTo(r);return;}
if(r==null)r=nbi();var y=nbi(),ts=this.s,ms=m.s;var nsh=this.DB-nbits(pm[pm.t-1]);if(nsh>0){pm.lShiftTo(nsh,y);pt.lShiftTo(nsh,r);}
else{pm.copyTo(y);pt.copyTo(r);}
var ys=y.t;var y0=y[ys-1];if(y0==0)return;var yt=y0*(1<<this.F1)+((ys>1)?y[ys-2]>>this.F2:0);var d1=this.FV/yt,d2=(1<<this.F1)/yt,e=1<<this.F2;var i=r.t,j=i-ys,t=(q==null)?nbi():q;y.dlShiftTo(j,t);if(r.compareTo(t)>=0){r[r.t++]=1;r.subTo(t,r);}
BigInteger.ONE.dlShiftTo(ys,t);t.subTo(y,y);while(y.t<ys)y[y.t++]=0;while(--j>=0){var qd=(r[--i]==y0)?this.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);if((r[i]+=y.am(0,qd,r,j,0,ys))<qd){y.dlShiftTo(j,t);r.subTo(t,r);while(r[i]<--qd)r.subTo(t,r);}}
if(q!=null){r.drShiftTo(ys,q);if(ts!=ms)BigInteger.ZERO.subTo(q,q);}
r.t=ys;r.clamp();if(nsh>0)r.rShiftTo(nsh,r);if(ts<0)BigInteger.ZERO.subTo(r,r);}
function bnMod(a){var r=nbi();this.abs().divRemTo(a,null,r);if(this.s<0&&r.compareTo(BigInteger.ZERO)>0)a.subTo(r,r);return r;}
function Classic(m){this.m=m;}
function cConvert(x){if(x.s<0||x.compareTo(this.m)>=0)return x.mod(this.m);else return x;}
function cRevert(x){return x;}
function cReduce(x){x.divRemTo(this.m,null,x);}
function cMulTo(x,y,r){x.multiplyTo(y,r);this.reduce(r);}
function cSqrTo(x,r){x.squareTo(r);this.reduce(r);}
Classic.prototype.convert=cConvert;Classic.prototype.revert=cRevert;Classic.prototype.reduce=cReduce;Classic.prototype.mulTo=cMulTo;Classic.prototype.sqrTo=cSqrTo;function bnpInvDigit(){if(this.t<1)return 0;var x=this[0];if((x&1)==0)return 0;var y=x&3;y=(y*(2-(x&0xf)*y))&0xf;y=(y*(2-(x&0xff)*y))&0xff;y=(y*(2-(((x&0xffff)*y)&0xffff)))&0xffff;y=(y*(2-x*y%this.DV))%this.DV;return(y>0)?this.DV-y:-y;}
function Montgomery(m){this.m=m;this.mp=m.invDigit();this.mpl=this.mp&0x7fff;this.mph=this.mp>>15;this.um=(1<<(m.DB-15))-1;this.mt2=2*m.t;}
function montConvert(x){var r=nbi();x.abs().dlShiftTo(this.m.t,r);r.divRemTo(this.m,null,r);if(x.s<0&&r.compareTo(BigInteger.ZERO)>0)this.m.subTo(r,r);return r;}
function montRevert(x){var r=nbi();x.copyTo(r);this.reduce(r);return r;}
function montReduce(x){while(x.t<=this.mt2)
x[x.t++]=0;for(var i=0;i<this.m.t;++i){var j=x[i]&0x7fff;var u0=(j*this.mpl+(((j*this.mph+(x[i]>>15)*this.mpl)&this.um)<<15))&x.DM;j=i+this.m.t;x[j]+=this.m.am(0,u0,x,i,0,this.m.t);while(x[j]>=x.DV){x[j]-=x.DV;x[++j]++;}}
x.clamp();x.drShiftTo(this.m.t,x);if(x.compareTo(this.m)>=0)x.subTo(this.m,x);}
function montSqrTo(x,r){x.squareTo(r);this.reduce(r);}
function montMulTo(x,y,r){x.multiplyTo(y,r);this.reduce(r);}
Montgomery.prototype.convert=montConvert;Montgomery.prototype.revert=montRevert;Montgomery.prototype.reduce=montReduce;Montgomery.prototype.mulTo=montMulTo;Montgomery.prototype.sqrTo=montSqrTo;function bnpIsEven(){return((this.t>0)?(this[0]&1):this.s)==0;}
function bnpExp(e,z){if(e>0xffffffff||e<1)return BigInteger.ONE;var r=nbi(),r2=nbi(),g=z.convert(this),i=nbits(e)-1;g.copyTo(r);while(--i>=0){z.sqrTo(r,r2);if((e&(1<<i))>0)z.mulTo(r2,g,r);else{var t=r;r=r2;r2=t;}}
return z.revert(r);}
function bnModPowInt(e,m){var z;if(e<256||m.isEven())z=new Classic(m);else z=new Montgomery(m);return this.exp(e,z);}
BigInteger.prototype.copyTo=bnpCopyTo;BigInteger.prototype.fromInt=bnpFromInt;BigInteger.prototype.fromString=bnpFromString;BigInteger.prototype.clamp=bnpClamp;BigInteger.prototype.dlShiftTo=bnpDLShiftTo;BigInteger.prototype.drShiftTo=bnpDRShiftTo;BigInteger.prototype.lShiftTo=bnpLShiftTo;BigInteger.prototype.rShiftTo=bnpRShiftTo;BigInteger.prototype.subTo=bnpSubTo;BigInteger.prototype.multiplyTo=bnpMultiplyTo;BigInteger.prototype.squareTo=bnpSquareTo;BigInteger.prototype.divRemTo=bnpDivRemTo;BigInteger.prototype.invDigit=bnpInvDigit;BigInteger.prototype.isEven=bnpIsEven;BigInteger.prototype.exp=bnpExp;BigInteger.prototype.toString=bnToString;BigInteger.prototype.negate=bnNegate;BigInteger.prototype.abs=bnAbs;BigInteger.prototype.compareTo=bnCompareTo;BigInteger.prototype.bitLength=bnBitLength;BigInteger.prototype.mod=bnMod;BigInteger.prototype.modPowInt=bnModPowInt;BigInteger.ZERO=nbv(0);BigInteger.ONE=nbv(1);function parseBigInt(str,r){return new BigInteger(str,r);}
function linebrk(s,n){var ret="";var i=0;while(i+n<s.length){ret+=s.substring(i,i+n)+"\n";i+=n;}
return ret+s.substring(i,s.length);}
function byte2Hex(b){if(b<0x10)
return"0"+b.toString(16);else
return b.toString(16);}
function pkcs1pad2(s,n){if(n<s.length+11){alert("Message too long for RSA");return null;}
var ba=new Array();var i=s.length-1;while(i>=0&&n>0)ba[--n]=s.charCodeAt(i--);ba[--n]=0;var rng=new SecureRandom();var x=new Array();while(n>2){x[0]=0;while(x[0]==0)rng.nextBytes(x);ba[--n]=x[0];}
ba[--n]=2;ba[--n]=0;return new BigInteger(ba);}
function RSAKey(){this.n=null;this.e=0;this.d=null;this.p=null;this.q=null;this.dmp1=null;this.dmq1=null;this.coeff=null;}
function RSASetPublic(N,E){if(N!=null&&E!=null&&N.length>0&&E.length>0){this.n=parseBigInt(N,16);this.e=parseInt(E,16);}
else
alert("Invalid RSA public key");}
function RSADoPublic(x){return x.modPowInt(this.e,this.n);}
function RSAEncrypt(text){var m=pkcs1pad2(text,(this.n.bitLength()+7)>>3);if(m==null)return null;var c=this.doPublic(m);if(c==null)return null;var h=c.toString(16);if((h.length&1)==0)return h;else return"0"+h;}
RSAKey.prototype.doPublic=RSADoPublic;RSAKey.prototype.setPublic=RSASetPublic;RSAKey.prototype.encrypt=RSAEncrypt;if(!window.iwin){var iwin={};}
iwin.Auth={};Auth=iwin.Auth;iwin.Auth.errors={};iwin.Auth.errors.login={BAD_AUTH:'login.BAD_AUTH',USERNAME_MISSING:'login.USERNAME_MISSING',PASSWORD_MISSING:'login.PASSWORD_MISSING',MULTIPLE_ACCOUNTS:'login.MULTIPLE_ACCOUNTS'};iwin.Auth.errors.register={USERNAME_TAKEN:'register.USERNAME_TAKEN',USERNAME_TOO_SHORT:'register.USERNAME_TOO_SHORT',USERNAME_TOO_LONG:'register.USERNAME_TOO_LONG',USERNAME_INVALID_CHARS:'register.USERNAME_INVALID_CHARS',USERNAME_PROFANITY:'register.USERNAME_PROFANITY',PASSWORD_MISMATCH:'register.PASSWORD_MISMATCH',PASSWORD_TOO_SHORT:'register.PASSWORD_TOO_SHORT',EMAIL_TAKEN:'register.EMAIL_TAKEN',EMAIL_INVALID:'register.EMAIL_INVALID'};iwin.Auth.errors.reset={EMAIL_MISMATCH:'reset.EMAIL_MISMATCH',EMAIL_INVALID:'reset.EMAIL_INVALID',MULTIPLE_ACCOUNTS:'reset.MULTIPLE_ACCOUNTS',NO_ACCOUNT:'reset.NO_ACCOUNT'};iwin.Auth.errors.resolve=function(prefix,errorKeys){var results=$A();errorKeys.each(function(key){if(key.startsWith(prefix))
results.push(key);else
results.push(prefix+key);});return results;};iwin.Auth.event={login:{start:function(){document.fire('iwin:auth:login:start')},success:function(username){document.fire('iwin:auth:login:success',{username:username})},problem:function(problems){document.fire('iwin:auth:login:problem',iwin.Auth.errors.resolve('login.',problems))},failure:function(){document.fire('iwin:auth:login:failure')}},logout:{start:function(){document.fire('iwin:auth:logout:start')},success:function(){document.fire('iwin:auth:logout:success')},failure:function(){document.fire('iwin:auth:logout:failure')}},register:{start:function(){document.fire('iwin:auth:register:start')},success:function(){document.fire('iwin:auth:register:success')},problem:function(problems){document.fire('iwin:auth:register:problem',iwin.Auth.errors.resolve('register.',problems))},usernameSuggest:function(json){document.fire('iwin:auth:register:usernameSuggest',json);},failure:function(){document.fire('iwin:auth:register:failure')}},registerValidate:{start:function(){document.fire('iwin:auth:register-validate:start')},success:function(){document.fire('iwin:auth:register-validate:success')},problem:function(problems){document.fire('iwin:auth:register-validate:problem',iwin.Auth.errors.resolve('register.',problems))},failure:function(){document.fire('iwin:auth:register-validate:failure')}},reset:{start:function(){document.fire('iwin:auth:reset:start')},success:function(){document.fire('iwin:auth:reset:success')},problem:function(problems){document.fire('iwin:auth:reset:problem',iwin.Auth.errors.resolve('reset.',problems))},failure:function(){document.fire('iwin:auth:reset:failure')}}};iwin.Auth.login=function(username,password){function hashCreds(username,password){var nonce=null;new Ajax.Request('/user/session/nonce',{asynchronous:false,method:'GET',requestHeaders:{'Accept':'text/plain'},onException:function(req,e){console.error(e);},onFailure:function(req){console.error(req.status);},onSuccess:function(req){nonce=req.responseText;}});var userLC=username.toLowerCase();var pass=SHA256(password);var hash=SHA256(nonce+':'+userLC+':'+pass);var login={username:username,hash:hash};console.debug('Creating login object: nonce=%s username=%s password=%s userLC=%s pass=%s hash=%s',nonce,username,password,userLC,pass,hash);return login;};function tokenCreds(username,password){var hardwareId=window.external.GetSystemHID();var userLC=username.toLowerCase();var pass=SHA256(password);var token=SHA256(hardwareId+':'+userLC+':'+pass);var login={username:username,hardwareId:hardwareId,token:token};console.debug('Creating login object: hardwareId=%s username=%s password=%s userLC=%s pass=%s token=%s',hardwareId,username,password,userLC,pass,token);return login;};(function(){iwin.Auth.event.login.start();try{var probs=new Array();if(!username||username.length==0)
probs.push(iwin.Auth.errors.login.USERNAME_MISSING);if(!password||password.length==0)
probs.push(iwin.Auth.errors.login.PASSWORD_MISSING);if(probs.length>0){iwin.Auth.event.login.problem(probs);return;}
var currentUsername=iwin.Auth.getCurrentUsername();if(currentUsername&&currentUsername.toLowerCase()===username.toLowerCase()){iwin.Auth.event.login.success(currentUsername);}
else{var login=(iwin.Util.isInArcade()||iwin.Util.isInGameLauncher()||iwin.Util.isInEUS())?tokenCreds(username,password):hashCreds(username,password);var json=Object.toJSON(login);console.debug('PUT /user/session/credentials: %s',json);new Ajax.Request('/user/session/credentials?_method=PUT',{asynchronous:false,method:'post',contentType:'application/json',postBody:json,onException:function(req,e){console.error(e);if(iwin.Util.isInArcade())
window.external.SetLoginFailed();iwin.Auth.event.login.failure();},onFailure:function(req){console.error(req.status);if(iwin.Util.isInArcade())
window.external.SetLoginFailed();iwin.Auth.event.login.failure();},onSuccess:function(req){var canonicalUsername=req.responseJSON.username;if(iwin.Util.isInArcade()||iwin.Util.isInGameLauncher()||iwin.Util.isInEUS()){window.external.SetLoginInfo(canonicalUsername,login.token);window.external.UpdateOpalsInfo();}
iwin.Auth.event.login.success(canonicalUsername);},on401:function(req){if(iwin.Util.isInArcade()||iwin.Util.isInGameLauncher()||iwin.Util.isInEUS())
window.external.SetLoginFailed();iwin.Auth.event.login.problem([iwin.Auth.errors.login.BAD_AUTH]);},on409:function(req){if(iwin.Util.isInArcade()||iwin.Util.isInGameLauncher()||iwin.Util.isInEUS())
window.external.SetLoginFailed();iwin.Auth.event.login.problem([iwin.Auth.errors.login.MULTIPLE_ACCOUNTS]);}});}}
catch(err){console.error(err);if(iwin.Util.isInArcade()||iwin.Util.isInGameLauncher()||iwin.Util.isInEUS())
window.external.SetLoginFailed();iwin.Auth.event.login.failure();}}).defer();};iwin.Auth.autologin=function(){try{if(iwin.Util.isInGameLauncher()&&!iwin.Auth.getCurrentUsername()){var username=window.external.GetOpalUserName();var token=window.external.GetOpalLoginToken();var hardwareId=window.external.GetSystemHID();if(username&&token&&hardwareId){var login={username:username,hardwareId:hardwareId,token:token};var json=Object.toJSON(login);new Ajax.Request('/user/session/credentials?_method=PUT',{asynchronous:false,method:'post',contentType:'application/json',postBody:json,onException:function(req,e){},onFailure:function(req){},onSuccess:function(req){iwin.Auth.event.login.success(req.responseJSON.username);}});}}}
catch(err){}};iwin.Auth.redirectOnLogout=function(path){Event.observe(document,'iwin:auth:logout:success',function(){window.location.href=(path?path:"/");});}
iwin.Auth.logout=function(){(function(){iwin.Auth.event.logout.start();try{console.debug('DELETE /user/session/credentials');new Ajax.Request('/user/session/credentials?_method=DELETE',{asynchronous:false,method:'post',contentType:'application/json',requestHeaders:{'Accept':'application/json'},onException:function(req,e){console.error(e);iwin.Auth.event.logout.failure();},onFailure:function(req){console.error(req.status);iwin.Auth.event.logout.failure();},onSuccess:function(req){if(iwin.Util.isInArcade()||iwin.Util.isInGameLauncher()||iwin.Util.isInEUS()){try{window.external.DoLogout();}catch(e){}
window.external.UpdateOpalsInfo();}
iwin.Auth.event.logout.success();}});}
catch(err){console.error(err);iwin.Auth.event.logout.failure();}}).defer();};iwin.Auth.validating=null;iwin.Auth.register=function(username,password,confirmPassword,email,emailOptIn,validateOnly){var e='10001';var n='C0A2394275F3F2D971104F61FB557724BDDDD2DF6BC713EBECA24F43BBA030255A8E312B57325C28FC0A7D1CC1D99F53B577318155E48C899EE31170CA92F197D1F288D911F85C1370C5A1DB9C2ABC8893ACB2A9726288967AF8EE373084BD2FFC447C2E772A31ED379C9243A3C998AF1E10C5BB0CA99ACE2295E28769D907D81017A8C9449592E58887B8B4B4224C9DC345D8D3270F2CBD30656E73035A9DB678916F5AF6AC77E4D6A7D04A4840F408E76B3FF59DA9A15A5866E063F9D60C0168B5CD57370566A8C3E669129C9E0BB34CFE1E0EB0214831312B48B5F40DFBA3EA93BC1DFD3C9B60665CAE503A5A767C68F145876B96E1F02758B0669B50CFDD';var encrypt=function(cleartext){var rsa=new RSAKey();rsa.setPublic(n,e);var ciphertext=rsa.encrypt(cleartext);return ciphertext;};(function(){if(!validateOnly&&confirmPassword!=password){console.debug('passwords do not match, converting to validation.');validateOnly=true;}
if(validateOnly)
iwin.Auth.event.registerValidate.start();else
iwin.Auth.event.register.start();try{var validatingPasswordMismatch=false;if(validateOnly){if(!(username||password||confirmPassword||email)){console.debug('nothing to validate yet, skipping validation');return;}
if(!username)
username="iwinregval";if(!email)
email='iwinregval@iwin.com';if(!password)
password='iwinregval';if(!confirmPassword)
confirmPassword='iwinregval';else if(confirmPassword!=password)
validatingPasswordMismatch=true;if(iwin.Auth.validating&&iwin.Auth.validating.username==username&&iwin.Auth.validating.password==password&&iwin.Auth.validating.confirmPassword==confirmPassword&&iwin.Auth.validating.email==email){console.debug('no change, skipping validation');return;}
else{iwin.Auth.validating={username:username,password:password,confirmPassword:confirmPassword,email:email};}}
else{if(confirmPassword!=password){var probs=new Array();probs.push(iwin.Auth.errors.register.PASSWORD_MISMATCH);iwin.Auth.event.register.problem(probs);return;}}
var encpassword=encrypt(password);var reg={username:username,password:encpassword,passwordEncrypted:true,email:email,emailOptIn:emailOptIn};if(validateOnly)
reg.validateOnly=true;var json=Object.toJSON(reg);console.debug('POST /user/registrations: %s',json);new Ajax.Request('/user/registrations',{asynchronous:false,method:'post',contentType:'application/json',postBody:json,onException:function(req,e){console.error(e);if(validateOnly)
iwin.Auth.event.registerValidate.failure();else
iwin.Auth.event.register.failure();},onFailure:function(req){console.error(req.status);if(validateOnly)
iwin.Auth.event.registerValidate.failure();else
iwin.Auth.event.register.failure();},on400:function(req){var errorObj=req.responseJSON;if(validateOnly){var probs=$A(errorObj.problems);if(validatingPasswordMismatch){probs.push(iwin.Auth.errors.register.PASSWORD_MISMATCH);}
iwin.Auth.event.registerValidate.problem(probs);}else{iwin.Auth.event.register.problem($A(errorObj.problems));}
if(errorObj.suggestedUsernames){iwin.Auth.event.register.usernameSuggest($A(errorObj.suggestedUsernames));}},onSuccess:function(req){if(validateOnly){if(validatingPasswordMismatch){var probs=new Array();probs.push(iwin.Auth.errors.register.PASSWORD_MISMATCH);iwin.Auth.event.registerValidate.problem(probs);}
else
iwin.Auth.event.registerValidate.success();}
else{iwin.Auth.event.register.success();iwin.Auth.login(username,password);}}});}
catch(err){console.error(err);if(validateOnly)
iwin.Auth.event.registerValidate.failure();else
iwin.Auth.event.register.failure();}}).defer();};iwin.Auth.resetCredentials=function(email,confirmEmail){(function(){iwin.Auth.event.reset.start();try{var probs=new Array();if(!email||!iwin.Util.isEmailValid(email))
probs.push(iwin.Auth.errors.reset.EMAIL_INVALID);if(confirmEmail!=email)
probs.push(iwin.Auth.errors.reset.EMAIL_MISMATCH);if(probs.length>0){iwin.Auth.event.reset.problem(probs);return;}
var obj={email:email};var json=Object.toJSON(obj);console.debug('POST /user/reset-credentials: %s',json);new Ajax.Request('/user/reset-credentials',{asynchronous:false,method:'post',contentType:'application/json',postBody:json,onException:function(req,e){console.error(e);iwin.Auth.event.reset.failure();},onFailure:function(req){console.error(req.status);iwin.Auth.event.reset.failure();},on400:function(req){var errorObj=req.responseJSON;iwin.Auth.event.reset.problem($A(errorObj.problems));},onSuccess:function(req){iwin.Auth.event.reset.success();}});}
catch(err){console.error(err);iwin.Auth.event.reset.failure();}}).defer();};iwin.Auth.getCurrentUsername=function(){var creds=iwin.Auth.getCurrentCredentials();return(creds==null?null:creds.username);}
if(!iwin.Util.hasSession){iwin.Util.hasSession=function(){return(readCookie('JSESSIONID')!=null);};}
iwin.Auth.getCurrentCredentials=iwin.Util.cacheWrap(function(){var creds=null;if(iwin.Util.hasSession()){new Ajax.Request('/user/session/credentials',{asynchronous:false,method:'GET',requestHeaders:{'Accept':'application/json'},onException:function(req,e){console.error(e);},onFailure:function(req){console.error(req.status);},onSuccess:function(req){creds=req.responseJSON;}});}
return creds;},10000);Event.observe(document,'iwin:auth:login:success',function(){iwin.Auth.getCurrentCredentials(true);});Event.observe(document,'iwin:auth:logout:success',function(){iwin.Auth.getCurrentCredentials(true);});Event.observe(document,'dom:loaded',iwin.Auth.autologin);function Auth_logout(){iwin.Auth.logout();}
if(!window.iwin){var iwin={};}
iwin.AuthUI={};AuthUI=iwin.AuthUI;iwin.AuthUI.event={};iwin.AuthUI.event.fire=function(event,target){(target?target:document).fire(event);};iwin.AuthUI.event.login={show:iwin.AuthUI.event.fire.curry('iwin:auth-ui:login:show'),hide:iwin.AuthUI.event.fire.curry('iwin:auth-ui:login:hide')};iwin.AuthUI.event.register={show:iwin.AuthUI.event.fire.curry('iwin:auth-ui:register:show'),hide:iwin.AuthUI.event.fire.curry('iwin:auth-ui:register:hide')};iwin.AuthUI.event.forgot={show:iwin.AuthUI.event.fire.curry('iwin:auth-ui:forgot:show'),hide:iwin.AuthUI.event.fire.curry('iwin:auth-ui:forgot:hide')};iwin.AuthUI.messages=[];iwin.AuthUI.messages[iwin.Auth.errors.login.BAD_AUTH]='The username or password was incorrect. Please try again.';iwin.AuthUI.messages[iwin.Auth.errors.login.USERNAME_MISSING]='Username is required.';iwin.AuthUI.messages[iwin.Auth.errors.login.PASSWORD_MISSING]='Password is required.';iwin.AuthUI.messages[iwin.Auth.errors.login.MULTIPLE_ACCOUNTS]='Multiple users were found with this email address.  Please try again with your username, or contact <a href="/support">Customer Service</a> for assistance.';iwin.AuthUI.messages[iwin.Auth.errors.register.USERNAME_TAKEN]='That username is already in use.';iwin.AuthUI.messages[iwin.Auth.errors.register.USERNAME_TOO_SHORT]='The username must be at least 3 characters long.';iwin.AuthUI.messages[iwin.Auth.errors.register.USERNAME_TOO_LONG]='The username must be no more than 20 characters long.';iwin.AuthUI.messages[iwin.Auth.errors.register.USERNAME_INVALID_CHARS]='The username may only contain letters, numbers, dashes, and underscores.';iwin.AuthUI.messages[iwin.Auth.errors.register.USERNAME_PROFANITY]='That username is already in use. Please try another.';iwin.AuthUI.messages[iwin.Auth.errors.register.PASSWORD_MISMATCH]='Passwords do not match.';iwin.AuthUI.messages[iwin.Auth.errors.register.PASSWORD_TOO_SHORT]='The password must be at least 4 characters long.';iwin.AuthUI.messages[iwin.Auth.errors.register.EMAIL_TAKEN]='The email address is already in use.';iwin.AuthUI.messages[iwin.Auth.errors.register.EMAIL_INVALID]='The email address doesn\'t appear valid.';iwin.AuthUI.messages[iwin.Auth.errors.reset.EMAIL_INVALID]='The email address doesn\'t appear valid.';iwin.AuthUI.messages[iwin.Auth.errors.reset.EMAIL_MISMATCH]='Email addresses do not match.';iwin.AuthUI.messages[iwin.Auth.errors.reset.MULTIPLE_ACCOUNTS]='Multiple users were found with this email address.  Please contact <a href="/support">Customer Service</a> for assistance.';iwin.AuthUI.messages[iwin.Auth.errors.reset.NO_ACCOUNT]='No account found with that email address.';iwin.AuthUI.messages.toDisplay=function(problems){problems=problems.uniq();var msg='';problems.each(function(e){if(iwin.AuthUI.messages[e]){msg+='<li/>'+iwin.AuthUI.messages[e]+'</li>';}
else{console.error('Could not find message for error code %s',e);}});return msg;};iwin.AuthUI.detachedMode=false;iwin.AuthUI.forceDetachedMode=function(){iwin.AuthUI.detachedMode=true;};iwin.AuthUI.isModal=false;iwin.AuthUI.CommonUI=function(name){this.name=name;this.initialized=false;this.spacing=2;this.xShift=10;this.target=null;this.elements={overlay:null,root:null,msg:null,err:null,top:{arrow:null,flat:null},close:{arrow:null,flat:null},bottom:{arrow:null,flat:null},form:null,submitButton:null,submittingImage:null,suggestedUsernames:null};this.reposition=function(){if(this.initialized&&this.elements.root.visible()){if(this.target&&!iwin.AuthUI.detachedMode){this.positionOn(this.target);}else{this.positionCenter();}}};this.positionCenter=function(){console.debug(this.name+' - positionCenter');var viewportDimensions=document.viewport.getDimensions();var uiDimensions=this.elements.root.getDimensions();this.elements.top.arrow.hide();this.elements.top.flat.show();this.elements.bottom.flat.show();this.elements.bottom.arrow.hide();var top=(viewportDimensions.height/2)-(uiDimensions.height/2);if(top>200){top=200;}else if(top<5){top=5;}
this.elements.root.style.top=top+'px';var left=(viewportDimensions.width/2)-(uiDimensions.width/2);if(left<5){left=5;}
this.elements.root.style.left=left+'px';};this.positionOn=function(target){console.debug(this.name+' - positionOn');var viewportDimensions=document.viewport.getDimensions();var uiDimensions=this.elements.root.getDimensions();var targetDimensions=this.target.getDimensions();var targetPosition=this.target.cumulativeOffset();var targetAbsCenterX=targetPosition.left+(targetDimensions.width/2);var targetAbsCenterY=targetPosition.top+(targetDimensions.height/2);var targetAbsBottomY=targetPosition.top+targetDimensions.height;var canFitAbove=targetPosition.top>uiDimensions.height;var targetAboveCenter=targetAbsCenterY<=viewportDimensions.height/2;if(targetAboveCenter||!canFitAbove)
{this.elements.top.arrow.show();this.elements.top.flat.hide();this.elements.bottom.flat.show();this.elements.bottom.arrow.hide();this.elements.root.style.top=(targetAbsBottomY+this.spacing)+'px';}
else
{this.elements.top.flat.show();this.elements.top.arrow.hide();this.elements.bottom.arrow.show();this.elements.bottom.flat.hide();this.elements.root.style.top=(targetPosition.top-(uiDimensions.height+this.spacing))+'px';}
var left=targetAbsCenterX+this.xShift-(uiDimensions.width/2);var right=left+uiDimensions.width;if(right>viewportDimensions.width){left=viewportDimensions.width-uiDimensions.width;}else if(left<0){left=0;}
this.elements.root.style.left=left+'px';console.debug(this.name+' - positioning ui to %i, %i',this.elements.root.style.left,this.elements.root.style.top);};this.doShow=function(target,msg,modal){console.debug(this.name+' - doShow');try{if(this.initialized){this.target=null;this.reset();var args=$A(arguments);var arg=args.shift();if(Object.isElement(arg)){this.target=arg;arg=args.shift();}
if(Object.isString(arg)&&arg.length>0){this.elements.msg.update(arg);this.elements.msg.show();arg=args.shift();}
if(arg===true||iwin.AuthUI.isModal){iwin.AuthUI.isModal=true;this.elements.close.arrow.hide();this.elements.close.flat.hide();}
if(this.target&&!iwin.AuthUI.detachedMode){this.positionOn(this.target);}else{this.positionCenter();this.elements.overlay.show();}
this.elements.root.show();if(this.elements.form&&this.elements.form.visible()){this.elements.form.focusFirstElement();}
return true;}
return false;}
catch(err){console.error(err);return false;}};this.doHide=function(){console.debug(this.name+' - doHide');if(this.initialized&&this.elements.root.visible()){this.elements.root.hide();this.elements.overlay.hide();iwin.AuthUI.isModal=false;return true;}
return false;};this.reset=function()
{iwin.Auth.validating=null;this.elements.overlay.hide();this.elements.root.hide();this.elements.top.arrow.show();this.elements.top.flat.hide();this.elements.close.arrow.show();this.elements.close.flat.show();this.elements.msg.update();this.elements.msg.hide();this.elements.err.update();this.elements.err.hide();this.elements.form.reset();this.elements.submittingImage.hide();this.elements.submitButton.show();this.elements.bottom.flat.show();this.elements.bottom.arrow.hide();};this.resetForError=function(msg){this.elements.submittingImage.hide();this.elements.submitButton.show();this.elements.err.update(msg);this.elements.err.show();};this.clearErrors=function(){this.elements.err.hide();this.elements.err.update();};this.submitting=function(){this.elements.submitButton.hide();this.elements.submittingImage.show();};};iwin.AuthUI.LoginUI=function(){this.init=function(){console.debug(this.name+' initializing...');this.pfLink=null;this.elements.overlay=$('signin-overlay');this.elements.root=$('sign_in_box');this.elements.msg=$('sign_in_infomsg');this.elements.err=$('sign_in_errormsg');this.elements.top.arrow=$('sign_in_title_arrow');this.elements.top.flat=$('sign_in_title_flat');this.elements.close.arrow=this.elements.top.arrow.select('.close').shift();this.elements.close.flat=this.elements.top.flat.select('.close').shift();this.elements.bottom.arrow=$('sign_in_bottom_arrow');this.elements.bottom.flat=$('sign_in_bottom_flat');this.elements.form=$('sign_in_form');this.elements.submitButton=$('sign_in_button');this.elements.submittingImage=$('sign_in_submitting_img');var hider=this.hide.bindAsEventListener(this);this.elements.close.arrow.observe('click',hider);this.elements.close.flat.observe('click',hider);var showforgot=(function(event){console.debug('clicking forgot link');iwin.AuthUI.Forgot.show(this.target);Event.stop(event);}).bindAsEventListener(this);$$('#forgot_links a').each(function(element){console.debug('adding handler to forgot link');element.observe('click',showforgot);});var showreg=(function(event){console.debug('clicking signup link');iwin.AuthUI.Register.show(this.target);Event.stop(event);}).bindAsEventListener(this);console.debug('adding handler to forgot link');$('signin_signup_link').observe('click',showreg);this.elements.form.observe('submit',(function(event){this.submit();Event.stop(event);}).bindAsEventListener(this));Event.observe(document,'iwin:auth-ui:login:hide',(function(event){this.pfLink=null;}).bindAsEventListener(this));Event.observe(document,'iwin:auth:login:success',(function(event){if((iwin.Util.isInArcade()||iwin.Util.isInGameLauncher())&&this.pfLink&&this.pfLink.match(/^link\:\/\/PF\/[0-9]+\/[0-9]+\/[0-9]+\/0$/)){var pfLink=this.pfLink;this.hide();window.location.href=pfLink;}
this.hide();}).bindAsEventListener(this));Event.observe(document,'iwin:auth-ui:register:show',this.hide.bindAsEventListener(this));Event.observe(document,'iwin:auth-ui:forgot:show',this.hide.bindAsEventListener(this));Event.observe(document,'iwin:auth:login:start',this.submitting.bindAsEventListener(this));Event.observe(document,'iwin:auth:login:problem',(function(event){this.resetForError(iwin.AuthUI.messages.toDisplay(event.memo));}).bindAsEventListener(this));Event.observe(document,'iwin:auth:login:failure',(function(event){this.resetForError('Sign In service temporarily unavailable.');}).bindAsEventListener(this));Event.observe(window,'resize',this.reposition.bind(this));this.initialized=true;console.debug(this.name+' initialization complete.');};this.show=function(target,msg,modal){if(this.doShow(target,msg,modal)){iwin.AuthUI.event.login.show(this.target);}};this.hide=function(e){if(this.doHide()){iwin.AuthUI.event.login.hide(this.target);}
if(e){Event.stop(e);}};this.submit=function(){try{var usernameField=this.elements.form.username;var passwordField=this.elements.form.password;usernameField.value=$F(usernameField).strip();passwordField.value=$F(passwordField).strip();iwin.Auth.login($F(usernameField),$F(passwordField));}catch(err){console.error(err);}};};iwin.AuthUI.LoginUI.prototype=new iwin.AuthUI.CommonUI('login-ui');iwin.AuthUI.Login=new iwin.AuthUI.LoginUI();function pfAuthLogin(gameId,skuId,licenseId){if(iwin.AuthUI.Login){iwin.AuthUI.Login.pfLink='link://PF/'+gameId+'/'+skuId+'/'+licenseId+'/0';iwin.AuthUI.Login.show();}}
iwin.AuthUI.RegisterUI=function(){this.init=function(){console.debug(this.name+' initializing...');this.elements.overlay=$('register-overlay');this.elements.root=$('register_box');this.elements.msg=$('register_infomsg');this.elements.err=$('register_errormsg');this.elements.top.arrow=$('register_title_arrow');this.elements.top.flat=$('register_title_flat');this.elements.close.arrow=this.elements.top.arrow.select('.close').shift();this.elements.close.flat=this.elements.top.flat.select('.close').shift();this.elements.bottom.arrow=$('register_bottom_arrow');this.elements.bottom.flat=$('register_bottom_flat');this.elements.form=$('register_form');this.elements.submitButton=$('register_button');this.elements.submittingImage=$('register_submitting_img');this.elements.suggestedUsernames=$('suggestedUsernames');Event.observe(this.elements.form.username,'focus',(function(event){this.validate(this.elements.form.username);}).bindAsEventListener(this));Event.observe(this.elements.form.password,'focus',(function(event){this.validate(this.elements.form.password);}).bindAsEventListener(this));Event.observe(this.elements.form.confirmPassword,'focus',(function(event){this.validate(this.elements.form.confirmPassword);}).bindAsEventListener(this));Event.observe(this.elements.form.email,'focus',(function(event){this.validate(this.elements.form.email);}).bindAsEventListener(this));var hider=this.hide.bindAsEventListener(this);$$('#register_box .title .close').each(function(element){element.observe('click',hider);});this.elements.form.observe('submit',(function(event){this.submit();Event.stop(event);}).bindAsEventListener(this));Event.observe(document,'iwin:auth-ui:login:show',this.hide.bindAsEventListener(this));Event.observe(document,'iwin:auth-ui:forgot:show',this.hide.bindAsEventListener(this));Event.observe(document,'iwin:auth:register:usernameSuggest',(function(event){this.suggestUsernameReset();this.suggestUsernameShow(event.memo);}).bindAsEventListener(this));Event.observe(document,'iwin:auth:register-validate:problem',(function(event){if(event.memo.indexOf('register.USERNAME_TAKEN')!=-1&&this.elements.form.username.value){iwin.AuthUI.messages[iwin.Auth.errors.register.USERNAME_TAKEN]='"'+this.elements.form.username.value+'" is already in use.';}
this.resetForError(iwin.AuthUI.messages.toDisplay(event.memo));}).bindAsEventListener(this));Event.observe(document,'iwin:auth:register-validate:success',(function(event){this.clearErrors();this.suggestUsernameReset();}).bindAsEventListener(this));Event.observe(document,'iwin:auth:register:start',this.submitting.bindAsEventListener(this));Event.observe(document,'iwin:auth:register:success',this.hide.bindAsEventListener(this));Event.observe(document,'iwin:auth:register:problem',(function(event){if(event.memo.indexOf('register.USERNAME_TAKEN')!=-1&&this.elements.form.username.value){iwin.AuthUI.messages[iwin.Auth.errors.register.USERNAME_TAKEN]='"'+this.elements.form.username.value+'" is already in use.';}
this.resetForError(iwin.AuthUI.messages.toDisplay(event.memo));}).bindAsEventListener(this));Event.observe(document,'iwin:auth:register:failure',(function(event){this.resetForError('Registration service temporarily unavailable.');}).bindAsEventListener(this));Event.observe(window,'resize',this.reposition.bind(this));this.initialized=true;console.debug(this.name+' initialization complete.');};this.suggestUsernameReset=function(){if(this.elements.suggestedUsernames){this.elements.suggestedUsernames.update();this.elements.suggestedUsernames.hide();}
this.elements.form.username.previous().setStyle({color:'#000',fontWeight:'normal'});};this.suggestUsernameShow=function(suggestions){var suggestedHtml='<span>Here are some suggestions:</span><ul>';suggestions.each(function(item,index){suggestedHtml+='<li><a href="#" onclick="$(\'register_form\').username.value=\''+item+'\';$(\'register_form\').password.focus();">'+item+'</a></li>';});suggestedHtml+='</ul>';this.elements.form.username.previous().setStyle({color:'#FF0000',fontWeight:'bold'});if(this.elements.suggestedUsernames!==null){this.elements.suggestedUsernames.update(suggestedHtml);this.elements.suggestedUsernames.show();}else{this.elements.suggestedUsernames=new Element('div',{'id':'suggestedUsernames'});this.elements.suggestedUsernames.insert({top:suggestedHtml});this.elements.form.username.insert({after:this.elements.suggestedUsernames});}};this.show=function(target,msg,modal){if(this.doShow(target,msg,modal)){iwin.AuthUI.event.register.show(this.target);}};this.hide=function(e){if(this.doHide()){iwin.AuthUI.event.register.hide(this.target);this.suggestUsernameReset();}
if(e){Event.stop(e);}};this.submit=function(){try{var usernameField=this.elements.form.username;var passwordField=this.elements.form.password;var confirmPasswordField=this.elements.form.confirmPassword;var emailField=this.elements.form.email;var emailOptInField=this.elements.form.emailOptIn;usernameField.value=$F(usernameField).strip();passwordField.value=$F(passwordField).strip();confirmPasswordField.value=$F(confirmPasswordField).strip();emailField.value=$F(emailField).strip();iwin.Auth.register($F(usernameField),$F(passwordField),$F(confirmPasswordField),$F(emailField),emailOptInField.checked);}catch(err){console.error(err);}};this.validate=function(triggered){try{var usernameField=this.elements.form.username;var passwordField=this.elements.form.password;var confirmPasswordField=this.elements.form.confirmPassword;var emailField=this.elements.form.email;var emailOptInField=this.elements.form.emailOptIn;usernameField.value=$F(usernameField).strip();passwordField.value=$F(passwordField).strip();confirmPasswordField.value=$F(confirmPasswordField).strip();emailField.value=$F(emailField).strip();if(triggered&&triggered.createTextRange){var range=triggered.createTextRange();range.moveStart('character',(triggered.value.length));range.select();}
iwin.Auth.register($F(usernameField),$F(passwordField),$F(confirmPasswordField),$F(emailField),emailOptInField.checked,true);}catch(err){console.error(err);}};};iwin.AuthUI.RegisterUI.prototype=new iwin.AuthUI.CommonUI('register-ui');iwin.AuthUI.Register=new iwin.AuthUI.RegisterUI();iwin.AuthUI.ForgotUI=function(){this.init=function(){console.debug(this.name+' initializing...');this.elements.overlay=$('forgot-overlay');this.elements.root=$('forgot_box');this.elements.msg=$('forgot_infomsg');this.elements.err=$('forgot_errormsg');this.elements.top.arrow=$('forgot_title_arrow');this.elements.top.flat=$('forgot_title_flat');this.elements.close.arrow=this.elements.top.arrow.select('.close').shift();this.elements.close.flat=this.elements.top.flat.select('.close').shift();this.elements.bottom.arrow=$('forgot_bottom_arrow');this.elements.bottom.flat=$('forgot_bottom_flat');this.elements.form=$('forgot_form');this.elements.submitButton=$('forgot_button');this.elements.submittingImage=$('forgot_submitting_img');var hider=this.hide.bindAsEventListener(this);$$('#forgot_box .title .close').each(function(element){element.observe('click',hider);});this.elements.form.observe('submit',(function(event){this.submit();Event.stop(event);}).bindAsEventListener(this));Event.observe(document,'iwin:auth-ui:login:show',this.hide.bindAsEventListener(this));Event.observe(document,'iwin:auth-ui:register:show',this.hide.bindAsEventListener(this));Event.observe(document,'iwin:auth:reset:start',this.submitting.bindAsEventListener(this));Event.observe(document,'iwin:auth:reset:success',this.success.bindAsEventListener(this));Event.observe(document,'iwin:auth:reset:problem',(function(event){this.resetForError(iwin.AuthUI.messages.toDisplay(event.memo));}).bindAsEventListener(this));Event.observe(document,'iwin:auth:reset:failure',(function(event){this.resetForError('Credentials service temporarily unavailable.');}).bindAsEventListener(this));Event.observe(window,'resize',this.reposition.bind(this));this.initialized=true;console.debug(this.name+' initialization complete.');};this.show=function(target,msg,modal){console.debug(this.name+' - show');if(!msg){msg='Enter the e-mail address associated with your iWin account, and will email your username and a temporary password.';}
if(this.elements.form){this.elements.form.show();}
if(this.doShow(target,msg,modal)){iwin.AuthUI.event.forgot.show();}};this.hide=function(e){console.debug(this.name+' - hide');if(this.doHide()){iwin.AuthUI.event.forgot.hide(this.target);}
if(e){Event.stop(e);}};this.success=function(){this.elements.err.hide();this.elements.form.hide();this.elements.msg.show();this.elements.msg.update('An email has been sent containing your username and a temporary password.');};this.submit=function(){try{var emailField=this.elements.form.email;var confirmEmailField=this.elements.form.confirmEmail;emailField.value=$F(emailField).strip();confirmEmailField.value=$F(confirmEmailField).strip();iwin.Auth.resetCredentials($F(emailField),$F(confirmEmailField));}catch(err){console.error(err);}};};iwin.AuthUI.ForgotUI.prototype=new iwin.AuthUI.CommonUI('forgot-ui');iwin.AuthUI.Forgot=new iwin.AuthUI.ForgotUI();iwin.AuthUI.html={};iwin.AuthUI.html.preloadImages='<div id="auth-ui-preload-images" style="display: none;">'
+'    <img src="/user/images/user.gif" alt=""/>'
+'    <img src="/user/images/loading.gif" alt="Loading..."/>'
+'</div';iwin.AuthUI.html.signin={};iwin.AuthUI.html.signin.popup='<div id="sign_in_box" class="auth_ui" style="display: none;">'
+'    <div id="sign_in_title_flat" class="title title_flat">'
+'        <span>Sign In</span>'
+'        <div class="close"><a href="#"> </a></div>'
+'    </div>'
+'    <div id="sign_in_title_arrow" class="title title_arrow">'
+'        <span>Sign In</span>'
+'        <div class="close"><a href="#"> </a></div>'
+'    </div>'
+'    <div id="sign_in_body" class="body">'
+'        <div id="sign_in_infomsg" class="info_msg"></div>'
+'        <ul id="sign_in_errormsg" class="error_msg"></ul>'
+'        <form id="sign_in_form">'
+'            <div class="full">'
+'                <div class="field_label">Username/Email</div>'
+'                <input type="text" name="username"/>'
+'            </div>'
+'            <div class="full">'
+'                <div class="field_label">Password</div>'
+'                <input type="password" name="password"/>'
+'            </div>'
+'            <input id="sign_in_button" class="submit" type="submit" value=""/>'
+'            <img id="sign_in_submitting_img" class="submitting" src="/user/images/loading.gif" width="16" height="16" alt="Submitting..."/>'
+'        </form>'
+'        <div id="forgot_links" class="secondary_text">'
+'            Forgot your:'
+'            <a href="/user/credentials/forgot">Username</a> | '
+'            <a href="/user/credentials/forgot">Password</a>'
+'        </div>'
+'        <div class="secondary_text">'
+'            Don\'t have an account? '
+'            <a id="signin_signup_link" href="/user/registration">Sign up</a>'
+'        </div>'
+'    </div>'
+'    <div id="sign_in_bottom_flat" class="bottom bottom_flat">'
+'    </div>'
+'    <div id="sign_in_bottom_arrow" class="bottom bottom_arrow">'
+'    </div>'
+'</div>';iwin.AuthUI.html.signin.overlay='<div id="signin-overlay" class="auth-ui-overlay" style="display: none;"> </div>';iwin.AuthUI.html.register={};iwin.AuthUI.html.register.popup='<div id="register_box" class="auth_ui" style="display: none;">'
+'    <div id="register_title_flat" class="title title_flat">'
+'        <span>Sign Up</span>'
+'        <div class="close"><a href="#"> </a></div>'
+'    </div>'
+'    <div id="register_title_arrow" class="title title_arrow">'
+'        <span>Sign Up</span>'
+'        <div class="close"><a href="#"> </a></div>'
+'    </div>'
+'    <div id="register_body" class="body">'
+'        <div id="register_infomsg" class="info_msg"></div>'
+'        <ul id="register_errormsg" class="error_msg"></ul>'
+'        <form id="register_form">'
+'            <div class="full">'
+'                <div class="field_label">Username</div>'
+'                <input type="text" name="username"/>'
+'            </div>'
+'            <div class="full">'
+'                <div class="field_label">Password</div>'
+'                <input type="password" name="password"/>'
+'            </div>'
+'            <div class="full">'
+'                <div class="field_label">Confirm Password</div>'
+'                <input type="password" name="confirmPassword"/>'
+'            </div>'
+'            <div class="full">'
+'                <div class="field_label">Email</div>'
+'                <input type="text" name="email"/>'
+'            </div>'
+'            <div class="secondary_text">'
+'                <input type="checkbox" name="emailOptIn" checked="checked"/>'
+'                <span>Yes, please send me iWin\'s newsletter and special promotions</span><br/>'
+'                <span class="opalPromo">Earn 500 Extra Opals!</span>'
+'            </div>'
+'            <input id="register_button" class="submit" type="submit" value=""/>'
+'            <img id="register_submitting_img" class="submitting" src="/user/images/loading.gif" width="16" height="16" alt="Submitting..."/>'
+'        </form>'
+'    </div>'
+'    <div id="register_bottom_flat" class="bottom bottom_flat">'
+'    </div>'
+'    <div id="register_bottom_arrow" class="bottom bottom_arrow">'
+'    </div>'
+'</div>';iwin.AuthUI.html.register.overlay='<div id="register-overlay" class="auth-ui-overlay" style="display: none;"> </div>';iwin.AuthUI.html.forgot={};iwin.AuthUI.html.forgot.popup='<div id="forgot_box" class="auth_ui" style="display: none;">'
+'    <div id="forgot_title_flat" class="title title_flat">'
+'        <span>Reset My User Details</span>'
+'        <div class="close"><a href="#"> </a></div>'
+'    </div>'
+'    <div id="forgot_title_arrow" class="title title_arrow">'
+'        <span>Reset My User Details</span>'
+'        <div class="close"><a href="#"> </a></div>'
+'    </div>'
+'    <div id="forgot_body" class="body">'
+'        <div id="forgot_infomsg" class="info_msg"></div>'
+'        <ul id="forgot_errormsg" class="error_msg"></ul>'
+'        <form id="forgot_form">'
+'            <div class="full">'
+'                <div class="field_label">Email address</div>'
+'                <input type="text" name="email"/>'
+'            </div>'
+'            <div class="full">'
+'                <div class="field_label">Confirm Email address</div>'
+'                <input type="text" name="confirmEmail"/>'
+'            </div>'
+'            <input id="forgot_button" class="submit" type="submit" value=""/>'
+'            <img id="forgot_submitting_img" class="submitting" src="/user/images/loading.gif" width="16" height="16" alt="Submitting..."/>'
+'        </form>'
+'    </div>'
+'    <div id="forgot_bottom_flat" class="bottom bottom_flat">'
+'    </div>'
+'    <div id="forgot_bottom_arrow" class="bottom bottom_arrow">'
+'    </div>'
+'</div>';iwin.AuthUI.html.forgot.overlay='<div id="forgot-overlay" class="auth-ui-overlay" style="display: none;"> </div>';iwin.AuthUI.html.load=function(){var uiContainer=new Element('div',{'id':'auth-ui'});uiContainer.insert(iwin.AuthUI.html.preloadImages);uiContainer.insert(iwin.AuthUI.html.signin.overlay);uiContainer.insert(iwin.AuthUI.html.register.overlay);uiContainer.insert(iwin.AuthUI.html.forgot.overlay);uiContainer.insert(iwin.AuthUI.html.signin.popup);uiContainer.insert(iwin.AuthUI.html.register.popup);uiContainer.insert(iwin.AuthUI.html.forgot.popup);document.body.appendChild(uiContainer);};function AuthUI_Login_show(target,msg){iwin.AuthUI.Login.show(target,msg);}
function AuthUI_Login_hide(){iwin.AuthUI.Login.hide();}
function AuthUI_Register_show(target,msg){iwin.AuthUI.Register.show(target,msg);}
function AuthUI_Register_hide(){iwin.AuthUI.Register.hide();}
Event.observe(document,'dom:loaded',function(){console.debug('Initializing Auth UI');iwin.AuthUI.html.load();iwin.AuthUI.Login.init();iwin.AuthUI.Register.init();iwin.AuthUI.Forgot.init();document.fire('iwin:auth-ui:ready');});