(function(){function p(a){if(typeof a=="string")a=g.getElementById(a);return a}function k(a,b,c){if(l.addEventListener)a.addEventListener(b,c,false);else l.attachEvent&&a.attachEvent("on"+b,function(){c.call(a,l.event)})}function q(a,b){a.className.match(RegExp("(\\s|^)"+b+"(\\s|$)"))||(a.className+=" "+b)}function m(a,b){var c=RegExp("(\\s|^)"+b+"(\\s|$)");a.className=a.className.replace(c," ")}function r(a){if(!a.pageX&&a.clientX){var b=1,c=document.body;if(c.getBoundingClientRect){b=c.getBoundingClientRect();
b=(b.right-b.left)/c.clientWidth}return{x:a.clientX/b+g.body.scrollLeft+g.documentElement.scrollLeft,y:a.clientY/b+g.body.scrollTop+g.documentElement.scrollTop}}return{x:a.pageX,y:a.pageY}}var g=document,l=window,n=function(){var a=g.createElement("div");return function(b){a.innerHTML=b;b=a.childNodes[0];a.removeChild(b);return b}}(),o=document.documentElement.getBoundingClientRect?function(a){var b=a.getBoundingClientRect(),c=a.ownerDocument;a=c.body;c=c.documentElement;var d=c.clientTop||a.clientTop||
0,f=c.clientLeft||a.clientLeft||0,e=1;if(a.getBoundingClientRect){e=a.getBoundingClientRect();e=(e.right-e.left)/a.clientWidth}if(e>1)f=d=0;return{top:b.top/e+(window.pageYOffset||c&&c.scrollTop/e||a.scrollTop/e)-d,left:b.left/e+(window.pageXOffset||c&&c.scrollLeft/e||a.scrollLeft/e)-f}}:function(a){if(l.jQuery)return jQuery(a).offset();var b=0,c=0;do{b+=a.offsetTop||0;c+=a.offsetLeft||0}while(a=a.offsetParent);return{left:c,top:b}},s=function(){var a=0;return function(){return"ValumsAjaxUpload"+
a++}}(),t=function(){var a;return function(){if(a)return a;if(typeof XMLHttpRequest!=="undefined")a=new XMLHttpRequest;else for(var b=["Microsoft.XmlHttp","MSXML2.XmlHttp.5.0","MSXML2.XmlHttp.4.0","MSXML2.XmlHttp.3.0","MSXML2.XmlHttp.2.0"],c=0;c<b.length;c++)try{a=new ActiveXObject(b[c]);break}catch(d){}return a}}();Ajax_upload=AjaxUpload=function(a,b){if(a.jquery)a=a[0];else if(typeof a=="string"&&/^#.*/.test(a))a=a.slice(1);a=p(a);this._input=null;this._button=a;this._justClicked=this._submitting=
this._disabled=false;this._parentDialog=g.body;if(window.jQuery&&jQuery.ui&&jQuery.ui.dialog){var c=jQuery(this._button).parents(".ui-dialog");if(c.length)this._parentDialog=c[0]}this._settings={action:"upload.php",name:"userfile",data:{},autoSubmit:true,responseType:false,closeConnection:"",hoverClass:"hover",onChange:function(){},onSubmit:function(){},onComplete:function(){}};for(var d in b)this._settings[d]=b[d];this._createInput();this._rerouteClicks()};AjaxUpload.prototype={setData:function(a){this._settings.data=
a},disable:function(){this._disabled=true},enable:function(){this._disabled=false},destroy:function(){if(this._input){this._input.parentNode&&this._input.parentNode.removeChild(this._input);this._input=null}},_createInput:function(){var a=this,b=g.createElement("input");b.setAttribute("type","file");b.setAttribute("name",this._settings.name);var c={position:"absolute",margin:"-5px 0 0 -175px",padding:0,width:"220px",height:"30px",fontSize:"14px",opacity:0,cursor:"pointer",display:"none",zIndex:2147483583};
for(var d in c)b.style[d]=c[d];if(b.style.opacity!=="0")b.style.filter="alpha(opacity=0)";this._parentDialog.appendChild(b);k(b,"change",function(){var f=this.value.replace(/.*(\/|\\)/,"");if(a._settings.onChange.call(a,f,/[.]/.exec(f)?/[^.]+$/.exec(f.toLowerCase()):"")!=false)a._settings.autoSubmit&&a.submit()});k(b,"click",function(){a._justClicked=true;setTimeout(function(){a._justClicked=false},2500)});this._input=b},_rerouteClicks:function(){var a=this,b,c={top:0,left:0},d=false;k(a._button,
"mouseover",function(){if(!(!a._input||d)){d=true;var f=a._button,e,i;i=o(f);e=i.left;i=i.top;b={left:e,right:e+f.offsetWidth,top:i,bottom:i+f.offsetHeight};if(a._parentDialog!=g.body)c=o(a._parentDialog)}});k(document,"mousemove",function(f){var e=a._input;if(e&&d)if(a._disabled){m(a._button,a._settings.hoverClass);e.style.display="none"}else{f=r(f);if(f.x>=b.left&&f.x<=b.right&&f.y>=b.top&&f.y<=b.bottom){e.style.top=f.y-c.top+"px";e.style.left=f.x-c.left+"px";e.style.display="block";q(a._button,
a._settings.hoverClass)}else{d=false;var i=setInterval(function(){if(!a._justClicked){if(!d)e.style.display="none";clearInterval(i)}},25);m(a._button,a._settings.hoverClass)}}})},_createIframe:function(){var a=s(),b=n('<iframe src="javascript:false;" name="'+a+'" />');b.id=a;b.style.display="none";g.body.appendChild(b);return b},submit:function(){var a=this,b=this._settings;if(this._input.value!==""){var c=this._input.value.replace(/.*(\/|\\)/,"");if(b.onSubmit.call(this,c,/[.]/.exec(c)?/[^.]+$/.exec(c.toLowerCase()):
"")!=false){var d=this._createIframe(),f=this._createForm(d);f.appendChild(this._input);if(b.closeConnection&&/AppleWebKit|MSIE/.test(navigator.userAgent)){var e=t();e.open("GET",b.closeConnection,false);e.send("")}f.submit();g.body.removeChild(f);this._input=f=null;this._createInput();var i=false;k(d,"load",function(){if(d.src=="javascript:'%3Chtml%3E%3C/html%3E';"||d.src=="javascript:'<html></html>';")i&&setTimeout(function(){g.body.removeChild(d)},0);else{var h=d.contentDocument?d.contentDocument:
frames[d.id].document;if(!(h.readyState&&h.readyState!="complete"))if(!(h.body&&h.body.innerHTML=="false")){var j;if(h.XMLDocument)j=h.XMLDocument;else if(h.body){j=h.body.innerHTML;if(b.responseType&&b.responseType.toLowerCase()=="json"){if(h.body.firstChild&&h.body.firstChild.nodeName.toUpperCase()=="PRE")j=h.body.firstChild.firstChild.nodeValue;j=j?window.eval("("+j+")"):{}}}else j=h;b.onComplete.call(a,c,j);i=true;d.src="javascript:'<html></html>';"}}})}else{g.body.removeChild(this._input);this._input=
null;this._createInput()}}},_createForm:function(a){var b=this._settings,c=n('<form method="post" enctype="multipart/form-data"></form>');c.style.display="none";c.action=b.action;c.target=a.name;g.body.appendChild(c);for(var d in b.data){a=g.createElement("input");a.type="hidden";a.name=d;a.value=b.data[d];c.appendChild(a)}return c}};$.fn.ajaxUpload=function(a){new AjaxUpload(this,a);return this}})(jQuery);
