/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","dojox.form.uploader.plugins.HTML5"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["dojox.form.uploader.plugins.HTML5"]){_4._hasResource["dojox.form.uploader.plugins.HTML5"]=true;_4.provide("dojox.form.uploader.plugins.HTML5");_4.declare("dojox.form.uploader.plugins.HTML5",[],{errMsg:"Error uploading files. Try checking permissions",uploadType:"html5",postCreate:function(){this.connectForm();this.inherited(arguments);if(this.uploadOnSelect){this.connect(this,"onChange","upload");}},upload:function(_7){this.onBegin(this.getFileList());if(this.supports("FormData")){this.uploadWithFormData(_7);}else{if(this.supports("sendAsBinary")){this.sendAsBinary(_7);}}},submit:function(_8){_8=!!_8?_8.tagName?_8:this.getForm():this.getForm();var _9=_4.formToObject(_8);console.log("form data:",_9);this.upload(_9);},sendAsBinary:function(_a){if(!this.getUrl()){console.error("No upload url found.",this);return;}var _b="---------------------------"+(new Date).getTime();var _c=this.createXhr();_c.setRequestHeader("Content-Type","multipart/form-data; boundary="+_b);var _d=this._buildRequestBody(_a,_b);if(!_d){this.onError(this.errMsg);}else{_c.sendAsBinary(_d);}},uploadWithFormData:function(_e){if(!this.getUrl()){console.error("No upload url found.",this);return;}var fd=new FormData();_4.forEach(this.inputNode.files,function(f,i){fd.append(this.name+"s[]",f);},this);if(_e){for(var nm in _e){fd.append(nm,_e[nm]);}}var _f=this.createXhr();_f.send(fd);},_xhrProgress:function(evt){if(evt.lengthComputable){var o={bytesLoaded:evt.loaded,bytesTotal:evt.total,type:evt.type,timeStamp:evt.timeStamp};if(evt.type=="load"){o.percent="100%",o.decimal=1;}else{o.decimal=evt.loaded/evt.total;o.percent=Math.ceil((evt.loaded/evt.total)*100)+"%";}this.onProgress(o);}},createXhr:function(){var xhr=new XMLHttpRequest();var _10;xhr.upload.addEventListener("progress",_4.hitch(this,"_xhrProgress"),false);xhr.addEventListener("load",_4.hitch(this,"_xhrProgress"),false);xhr.addEventListener("error",_4.hitch(this,function(evt){this.onError(evt);clearInterval(_10);}),false);xhr.addEventListener("abort",_4.hitch(this,function(evt){this.onAbort(evt);clearInterval(_10);}),false);xhr.onreadystatechange=_4.hitch(this,function(){if(xhr.readyState===4){console.info("COMPLETE");clearInterval(_10);this.onComplete(_4.eval(xhr.responseText));}});xhr.open("POST",this.getUrl());_10=setInterval(_4.hitch(this,function(){try{if(typeof (xhr.statusText)){}}catch(e){clearInterval(_10);}}),250);return xhr;},_buildRequestBody:function(_11,_12){var EOL="\r\n";var _13="";_12="--"+_12;var _14=[];_4.forEach(this.inputNode.files,function(f,i){var _15=this.name+"s[]";var _16=this.inputNode.files[i].fileName;var _17;try{_17=this.inputNode.files[i].getAsBinary()+EOL;_13+=_12+EOL;_13+="Content-Disposition: form-data; ";_13+="name=\""+_15+"\"; ";_13+="filename=\""+_16+"\""+EOL;_13+="Content-Type: "+this.getMimeType()+EOL+EOL;_13+=_17;}catch(e){_14.push({index:i,name:_16});}},this);if(_14.length){if(_14.length>=this.inputNode.files.length){this.onError({message:this.errMsg,filesInError:_14});_13=false;}}if(!_13){return false;}if(_11){for(var nm in _11){_13+=_12+EOL;_13+="Content-Disposition: form-data; ";_13+="name=\""+nm+"\""+EOL+EOL;_13+=_11[nm]+EOL;}}_13+=_12+"--"+EOL;return _13;}});_6.form.addUploaderPlugin(_6.form.uploader.plugins.HTML5);}}};});