(function(){var G=document,K=window;function B(O){if(typeof O=="string"){O=G.getElementById(O)}return O}function D(Q,P,O){if(K.addEventListener){Q.addEventListener(P,O,false)}else{if(K.attachEvent){var R=function(){O.call(Q,K.event)};Q.attachEvent("on"+P,R)}}}var C=function(){var O=G.createElement("div");return function(P){O.innerHTML=P;var Q=O.childNodes[0];O.removeChild(Q);return Q}}();function E(P,O){return P.className.match(new RegExp("(\\s|^)"+O+"(\\s|$)"))}function F(P,O){if(!E(P,O)){P.className+=" "+O}}function L(Q,O){var P=new RegExp("(\\s|^)"+O+"(\\s|$)");Q.className=Q.className.replace(P," ")}if(document.documentElement.getBoundingClientRect){var M=function(O){var T=O.getBoundingClientRect(),X=O.ownerDocument,U=X.body,P=X.documentElement,S=P.clientTop||U.clientTop||0,V=P.clientLeft||U.clientLeft||0,Y=1;if(U.getBoundingClientRect){var R=U.getBoundingClientRect();Y=(R.right-R.left)/U.clientWidth}if(Y>1){S=0;V=0}var W=T.top/Y+(window.pageYOffset||P&&P.scrollTop/Y||U.scrollTop/Y)-S,Q=T.left/Y+(window.pageXOffset||P&&P.scrollLeft/Y||U.scrollLeft/Y)-V;return{top:W,left:Q}}}else{var M=function(O){if(K.jQuery){return jQuery(O).offset()}var Q=0,P=0;do{Q+=O.offsetTop||0;P+=O.offsetLeft||0}while(O=O.offsetParent);return{left:P,top:Q}}}function A(Q){var S,P,R,O;var T=M(Q);S=T.left;R=T.top;P=S+Q.offsetWidth;O=R+Q.offsetHeight;return{left:S,right:P,top:R,bottom:O}}function I(R){if(!R.pageX&&R.clientX){var Q=1;var O=document.body;if(O.getBoundingClientRect){var P=O.getBoundingClientRect();Q=(P.right-P.left)/O.clientWidth}return{x:R.clientX/Q+G.body.scrollLeft+G.documentElement.scrollLeft,y:R.clientY/Q+G.body.scrollTop+G.documentElement.scrollTop}}return{x:R.pageX,y:R.pageY}}var H=function(){var O=0;return function(){return"ValumsAjaxUpload"+O++}}();function N(O){return O.replace(/.*(\/|\\)/,"")}function J(O){return(/[.]/.exec(O))?/[^.]+$/.exec(O.toLowerCase()):""}Ajax_upload=AjaxUpload=function(Q,O){if(Q.jquery){Q=Q[0]}else{if(typeof Q=="string"&&/^#.*/.test(Q)){Q=Q.slice(1)}}Q=B(Q);this._input=null;this._button=Q;this._disabled=false;this._submitting=false;this._justClicked=false;this._parentDialog=G.body;if(window.jQuery&&jQuery.ui&&jQuery.ui.dialog){var R=jQuery(this._button).parents(".ui-dialog");if(R.length){this._parentDialog=R[0]}}this._settings={action:"upload.php",name:"userfile",data:{},autoSubmit:true,responseType:false,onChange:function(S,T){},onSubmit:function(S,T){},onComplete:function(T,S){}};for(var P in O){this._settings[P]=O[P]}this._createInput();this._rerouteClicks()};AjaxUpload.prototype={setData:function(O){this._settings.data=O},disable:function(){this._disabled=true},enable:function(){this._disabled=false},destroy:function(){if(this._input){if(this._input.parentNode){this._input.parentNode.removeChild(this._input)}this._input=null}},_createInput:function(){var P=this;var O=G.createElement("input");O.setAttribute("type","file");O.setAttribute("name",this._settings.name);var R={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 Q in R){O.style[Q]=R[Q]}if(!(O.style.opacity==="0")){O.style.filter="alpha(opacity=0)"}this._parentDialog.appendChild(O);D(O,"change",function(){var S=N(this.value);if(P._settings.onChange.call(P,S,J(S))==false){return }if(P._settings.autoSubmit){P.submit()}});D(O,"click",function(){P.justClicked=true;setTimeout(function(){P.justClicked=false},3000)});this._input=O},_rerouteClicks:function(){var P=this;var Q,O={top:0,left:0},R=false;D(P._button,"mouseover",function(S){if(!P._input||R){return }R=true;Q=A(P._button);if(P._parentDialog!=G.body){O=M(P._parentDialog)}});D(document,"mousemove",function(T){var S=P._input;if(!S||!R){return }if(P._disabled){L(P._button,"hover");S.style.display="none";return }var U=I(T);if((U.x>=Q.left)&&(U.x<=Q.right)&&(U.y>=Q.top)&&(U.y<=Q.bottom)){S.style.top=U.y-O.top+"px";S.style.left=U.x-O.left+"px";S.style.display="block";F(P._button,"hover")}else{R=false;if(!P.justClicked){S.style.display="none"}L(P._button,"hover")}})},_createIframe:function(){var P=H();var O=C('<iframe src="javascript:false;" name="'+P+'" />');O.id=P;O.style.display="none";G.body.appendChild(O);return O},submit:function(){var O=this,R=this._settings;if(this._input.value===""){return }var P=N(this._input.value);if(!(R.onSubmit.call(this,P,J(P))==false)){var Q=this._createIframe();var T=this._createForm(Q);T.appendChild(this._input);T.submit();G.body.removeChild(T);T=null;this._input=null;this._createInput();var S=false;D(Q,"load",function(W){if(Q.src=="javascript:'%3Chtml%3E%3C/html%3E';"||Q.src=="javascript:'<html></html>';"){if(S){setTimeout(function(){G.body.removeChild(Q)},0)}return }var V=Q.contentDocument?Q.contentDocument:frames[Q.id].document;if(V.readyState&&V.readyState!="complete"){return }if(V.body&&V.body.innerHTML=="false"){return }var U;if(V.XMLDocument){U=V.XMLDocument}else{if(V.body){U=V.body.innerHTML;if(R.responseType&&R.responseType.toLowerCase()=="json"){if(V.body.firstChild&&V.body.firstChild.nodeName.toUpperCase()=="PRE"){U=V.body.firstChild.firstChild.nodeValue}if(U){U=window["eval"]("("+U+")")}else{U={}}}}else{var U=V}}R.onComplete.call(O,P,U);S=true;Q.src="javascript:'<html></html>';"})}else{G.body.removeChild(this._input);this._input=null;this._createInput()}},_createForm:function(Q){var P=this._settings;var R=C('<form method="post" enctype="multipart/form-data"></form>');R.style.display="none";R.action=P.action;R.target=Q.name;G.body.appendChild(R);for(var S in P.data){var O=G.createElement("input");O.type="hidden";O.name=S;O.value=P.data[S];R.appendChild(O)}return R}}})();
