/*
 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.dijit.Print"]){dojo._hasResource["esri.dijit.Print"]=true;dojo.provide("esri.dijit.Print");dojo.require("dijit.Menu");dojo.require("dijit.form.Button");dojo.require("esri.tasks.PrintTask");dojo.declare("esri.dijit.Print",null,{onPrintComplete:function(){},onError:function(){},onPrintStart:function(){},constructor:function(_1,_2){_1=_1||{};this.url=_1.url;this.map=_1.map;this.templates=_1.templates;var _3=esri.bundle.widgets.print;this._printText=_3.NLS_print;this._printingText=_3.NLS_printing;this._printoutText=_3.NLS_printout;if(!this.templates){this.templates=[{label:this._printText,format:"PNG32",layout:"MAP_ONLY",exportOptions:{width:800,height:1100,dpi:96}}];}this.printDomNode=dojo.create("div");dojo.addClass(this.printDomNode,"esriPrint");_2=dojo.byId(_2);_2.appendChild(this.printDomNode);},startup:function(){this._createPrintButton();},destroy:function(){this.map=null;dojo.destroy(this.printDomNode);},hide:function(){esri.hide(this.printDomNode);},show:function(){esri.show(this.printDomNode);},printMap:function(_4){this.onPrintStart();this._printButton.setAttribute("label",this._printingText);this._printButton.setAttribute("disabled",true);var _5=this.map;var _6=new esri.tasks.PrintTask(this.url);var _7=new esri.tasks.PrintParameters();_7.map=_5;_7.template=_4;_6.execute(_7,dojo.hitch(this,this._printComplete),dojo.hitch(this,this._printError));},_createPrintButton:function(){var _8=this.templates;if(_8.length===1){this._printButton=new dijit.form.Button({label:this._printText,onClick:dojo.hitch(this,function(){this.printMap(_8[0]);})});this.printDomNode.appendChild(this._printButton.domNode);}else{this._printButton=new dijit.form.ComboButton({label:this._printText,onClick:dojo.hitch(this,function(){this.printMap(_8[0]);})});this.printDomNode.appendChild(this._printButton.domNode);var _9=new dijit.Menu({style:"display: none;"});dojo.forEach(_8,function(_a){var _b=new dijit.MenuItem({label:_a.label,onClick:dojo.hitch(this,function(){this.printMap(_a);})});_9.addChild(_b);},this);this._printButton.setAttribute("dropDown",_9);}dojo.addClass(this._printButton.domNode,"esriPrintButton");},_printComplete:function(_c){this.onPrintComplete(_c);var _d=window.location.host.split(".");var _e=_d.length>1?_d[_d.length-2]+"."+_d[_d.length-1]:window.location.host;var _f=_c.url.split("://")[1].split("/")[0].split(".");var _10=_f.length>1?_f[_f.length-2]+"."+_f[_f.length-1]:_c.url.split("://")[1].split("/")[0];if(_e.toLowerCase()===_10.toLowerCase()){window.open(_c.url);this._removeAllChildren(this.printDomNode);this._createPrintButton();}else{this._printButton.domNode.style.display="none";var _11=dojo.create("a",{href:_c.url,target:"_blank",innerHTML:this._printoutText});dojo.connect(_11,"onclick",dojo.hitch(this,this._hyperlinkClick));this._removeAllChildren(this.printDomNode);dojo.addClass(_11,"esriPrintout");this.printDomNode.appendChild(_11);}},_printError:function(err){this._removeAllChildren(this.printDomNode);this._createPrintButton();console.error(err);this.onError(err);},_hyperlinkClick:function(){this._removeAllChildren(this.printDomNode);this._createPrintButton();},_removeAllChildren:function(_12){while(_12.hasChildNodes()){_12.removeChild(_12.lastChild);}}});}