/*
 COPYRIGHT 2009 ESRI

 TRADE SECRETS: ESRI PROPRIETARY AND CONFIDENTIAL
 Unpublished material - all rights reserved under the
 Copyright Laws of the United States and applicable international
 laws, treaties, and conventions.

 For additional information, contact:
 Environmental Systems Research Institute, Inc.
 Attn: Contracts and Legal Services Department
 380 New York Street
 Redlands, California, 92373
 USA

 email: contracts@esri.com
 */

if(!dojo._hasResource["esri.IdentityManager"]){dojo._hasResource["esri.IdentityManager"]=true;dojo.provide("esri.IdentityManager");dojo.require("dijit.Dialog");dojo.require("dijit.form.Button");dojo.require("dijit.form.ValidationTextBox");dojo.require("esri.utils");dojo.require("esri.IdentityManagerBase");dojo.declare("esri.IdentityManager",[esri.IdentityManagerBase],{constructor:function(_1){dojo.mixin(this,_1);},_dialogContent:"<div class='dijitDialogPaneContentArea'>"+"<div style='padding-bottom: 5px; word-wrap: break-word;'>${info}</div>"+"<div style='margin: 0px; padding: 0px; height: 10px;'></div>"+"<div class='esriErrorMsg' style='display: none; color: white; background-color: #D46464; text-align: center; padding-top: 3px; padding-bottom: 3px;'>${errorMsg}</div>"+"<div style='margin: 0px; padding: 0px; height: 10px;'></div>"+"<table style='width: 100%;'>"+"<tr>"+"<td><label>${lblUser}</label><br/>"+"<input data-dojo-type='dijit.form.ValidationTextBox' data-dojo-props='type:\"text\", \"class\":\"esriIdUser\", required:true, trim:true, style:\"width: 100%;\"' /></td>"+"</tr>"+"<tr>"+"<td><label>${lblPwd}</label><br/>"+"<input data-dojo-type='dijit.form.ValidationTextBox' data-dojo-props='type:\"password\", \"class\":\"esriIdPwd\", required:true, style:\"width: 100%;\"' /></td>"+"</tr>"+"</table>"+"</div>"+"<div class='dijitDialogPaneActionBar'>"+"<button data-dojo-type='dijit.form.Button' data-dojo-props='type:\"button\", \"class\":\"esriIdSubmit\"'>${lblOk}</button>"+"<button data-dojo-type='dijit.form.Button' data-dojo-props='type:\"button\", \"class\":\"esriIdCancel\"'>${lblCancel}</button>"+"</div>",onDialogCreate:function(){},onDialogCancel:function(){},signIn:function(_2,_3){if(!this._nls){this._nls=esri.bundle.identity;}if(!this._loginDialog){this._loginDialog=(this.dialog=this._createLoginDialog());this.onDialogCreate();}var _4=this._loginDialog,_5=new dojo.Deferred(function(){_4.onCancel();});if(_4.open){var _6=new Error("BUSY");_6.code="IdentityManager."+1;_6.log=dojo.config.isDebug;_5.errback(_6);return _5;}esri.hide(_4.errMsg_);_4.dfd_=_5;_4.serverInfo_=_3;_4.resUrl_=_2;dojo.attr(_4.resLink_,{"title":_2,"innerHTML":"("+(this.getResourceName(_2)||this._nls.lblItem)+")"});dojo.attr(_4.serverLink_,{"title":_3.server,"innerHTML":(_3.server.toLowerCase().indexOf("arcgis.com")!==-1?"ArcGIS Online":_3.server)+" "});_4.txtPwd_.set("value","");_4.show();return _5;},_createLoginDialog:function(){var _7=this._nls,_8=esri.substitute(_7,this._dialogContent);_8=esri.substitute({resource:"<span class='resLink' style='word-wrap: break-word;'></span>",server:"<span class='serverLink' style='word-wrap: break-word;'></span>"},_8);var _9=new dijit.Dialog({title:_7.title,content:_8,"class":"esriSignInDialog",style:"width: 18em;",esriIdMgr_:this,keypressed_:function(_a){if(_a.charOrCode===dojo.keys.ENTER){this.execute_();}},execute_:function(){var _b=this.txtUser_.get("value"),_c=this.txtPwd_.get("value"),_d=this.dfd_,_9=this;if(!_b||!_c){return;}this.btnSubmit_.set("label",_7.lblSigning);var _e=esri.id.findCredential(_9.serverInfo_.server,_b),_f=function(_10){_9.btnSubmit_.set("label",_7.lblOk);_9.btnSubmit_.set("disabled",false);esri.hide(_9.errMsg_);_9.hide();dijit._DialogLevelManager.hide(_9);var _11=_9.serverInfo_;_9.dfd_=_9.serverInfo_=_9.generateDfd_=_9.resUrl_=null;var _12,_13,_14=_e;if(_10){_12=_10.token;_13=esri._isDefined(_10.expires)?Number(_10.expires):null;if(_14){_14.userId=_b;_14.token=_12;_14.expires=_13;_14.validity=_11.shortLivedTokenValidity;}else{_14=new esri.Credential({userId:_b,server:_11.server,token:_12,expires:_13,validity:_11.shortLivedTokenValidity});}}_d.callback(_14);};if(_e&&!_e._enqueued){_f();return;}_9.btnSubmit_.set("disabled",true);_9.generateDfd_=esri.id.generateToken(this.serverInfo_,{username:_b,password:_c}).addCallback(_f).addErrback(function(){_9.btnSubmit_.set("disabled",false);_9.generateDfd_=null;_9.btnSubmit_.set("label",_7.lblOk);esri.show(_9.errMsg_);});},cancel_:function(){if(_9.generateDfd_){_9.generateDfd_.cancel();}var dfd=_9.dfd_,_15=_9.resUrl_,_16=_9.serverInfo_;_9.btnSubmit_.set("disabled",false);_9.dfd_=_9.serverInfo_=_9.generateDfd_=_9.resUrl_=null;esri.hide(_9.errMsg_);dijit._DialogLevelManager.hide(_9);_9.esriIdMgr_.onDialogCancel({resourceUrl:_15,serverInfo:_16});var err=new Error("ABORTED");err.code="IdentityManager."+2;err.log=dojo.config.isDebug;dfd.errback(err);}});var _17=_9.domNode;_9.txtUser_=dijit.byNode(dojo.query(".esriIdUser",_17)[0]);_9.txtPwd_=dijit.byNode(dojo.query(".esriIdPwd",_17)[0]);_9.btnSubmit_=dijit.byNode(dojo.query(".esriIdSubmit",_17)[0]);_9.btnCancel_=dijit.byNode(dojo.query(".esriIdCancel",_17)[0]);_9.resLink_=dojo.query(".resLink",_17)[0];_9.serverLink_=dojo.query(".serverLink",_17)[0];_9.errMsg_=dojo.query(".esriErrorMsg",_17)[0];_9.connect(_9.txtUser_,"onKeyPress",_9.keypressed_);_9.connect(_9.txtPwd_,"onKeyPress",_9.keypressed_);_9.connect(_9.btnSubmit_,"onClick",_9.execute_);_9.connect(_9.btnCancel_,"onClick",_9.onCancel);_9.connect(_9,"onCancel",_9.cancel_);return _9;}});}