function soaplib(){this.wsdlURL=undefined;this.wsdl=undefined;this.onFailure=undefined;this.session=undefined;}soaplib.init=function(a,c,b){this.wsdlURL=a;this.wsdl=undefined;this.onFailure=c?c:function(){};this.session=b;if(document.location.protocol=="https:"){this.baseURL="https://"+location.host+"/";}else{this.baseURL="http://"+location.host+"/";}};soaplib.setWSDL=function(a){this.wsdlURL=a;this.wsdl=undefined;};soaplib.generateCommand=function(a,e){var c="";if(typeof(a)==="string"){if(!e){e={};}if(!e.session&&this.session){e.session=this.session;}var g=json2xml(e);c="<"+a+" xmlns='http://menandmice.com/webservices/'>"+g+"</"+a+">";}else{if(($(a).find("session").length===0)&&this.session){var d=a.ownerDocument.createElement("session");var b=a.ownerDocument.createTextNode(this.session);d.appendChild(b);a.appendChild(d);}c=soaplib.xml2Str(a);}return"<?xml version='1.0' encoding='utf-8'?><soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body>"+c+"</soap:Body></soap:Envelope>";};soaplib.call=function(g,h,i,d){d=d?d:{};var a=d.onFailure?d.onFailure:this.onFailure;var c=d.async!==false;var j=this;try{if(!this.wsdl&&(d.skipResultParsing!==true)){gLogger.assert(c);$.ajax({url:this.baseURL+this.wsdlURL,global:false,type:"GET",contentType:"text/xml; charset='utf-8'",dataType:"xml",complete:function(l,k){if((k==="success")&&(l.responseXML.getElementsByTagName("faultcode").length===0)){j.wsdl=j.parseWSDL(l.responseXML);j.call(g,h,i,d);}else{a(l.responseXML,k);}}});return;}var b=this.generateCommand(g,h);$.ajax({url:this.baseURL+"_mmwebext/mmwebext.dll?Soap",global:false,async:c,type:"POST",contentType:"text/xml; charset='utf-8'",dataType:"xml",data:b,complete:function(n,k){try{if((k==="success")&&(n.responseXML.getElementsByTagName("faultcode").length===0)){if(i){var m=n.responseXML;if((d.skipResultParsing!==true)&&(typeof(g)==="string")){m=j.parseResponseUsingWSDL(g,m,j.wsdl);}i(m);}}else{a(n.responseXML,k);}}catch(l){alert("Error:"+l.message);}}});}catch(e){if(d.showError!==false){alert("Error:"+e.message);}throw (e);}};soaplib.parseWSDL=function(d){var b=[];var a=d.getElementsByTagName("s:element");var e=true;if(a.length===0){a=d.getElementsByTagName("element");e=false;}for(var c=0;c<a.length;c++){if(e){if(a[c].attributes.getNamedItem("name")&&a[c].attributes.getNamedItem("type")){b[a[c].attributes.getNamedItem("name").nodeValue]=a[c].attributes.getNamedItem("type").nodeValue;}}else{if(a[c].attributes.name&&a[c].attributes.type){b[a[c].attributes.name.value]=a[c].attributes.type.value;}}}return b;};soaplib.getTypeFromWSDL=function(c,a){var b=a[c]+"";return(b=="undefined")?"":b;};soaplib.xml2Str=function(a){try{return(new XMLSerializer()).serializeToString(a);}catch(b){return a.xml;}};soaplib.extractValue=function(e,a){var b=e.nodeValue;switch(this.getTypeFromWSDL(e.parentNode.nodeName,a).toLowerCase()){case"s:boolean":return b+""=="1";case"s:int":case"s:long":return(b!=null)?parseInt(b+"",10):0;case"s:double":return(b!=null)?parseFloat(b+""):0;case"s:datetime":if(b==null){return null;}else{b=b+"";b=b.substring(0,(b.lastIndexOf(".")==-1?b.length:b.lastIndexOf(".")));b=b.replace(/T/gi," ");b=b.replace(/-/gi,"/");var c=new Date();c.setTime(Date.parse(b));return c;}case"s:string":default:return(b!=null)?b+"":"";}};soaplib.node2Object=function(h,b){if(!h){return null;}var c=0;if(h.nodeType==3||h.nodeType==4){return this.extractValue(h,b);}if(h.childNodes.length==1&&(h.childNodes[0].nodeType==3||h.childNodes[0].nodeType==4)){return this.node2Object(h.childNodes[0],b);}var d=this.getTypeFromWSDL(h.nodeName,b).toLowerCase().indexOf("arrayof")!=-1;if(!d){var g="";if(h.hasChildNodes()){g=new Object();}for(c=0;c<h.childNodes.length;c++){var e=this.node2Object(h.childNodes[c],b);g[h.childNodes[c].nodeName]=e;}return g;}else{var a=new Array();for(c=0;c<h.childNodes.length;c++){a[a.length]=this.node2Object(h.childNodes[c],b);}return a;}};soaplib.parseResponseUsingWSDL=function(c,e,b){try{var d=c+"Response";var a=null;try{a=e.selectNodes('.//*[local-name()="'+d+'"]');}catch(g){}if(!a){a=e.getElementsByTagName(d);}if(a.length==1){return this.node2Object(a[0],b);}}catch(g){throw new Error("Failed to parse response to "+c+". Please notify support@menandmice.com.");}return undefined;};soaplib.defaultOnFailure=function(c,a){var b=$(c).find("faultstring").text();yuidialogs.simpleDialog("Warning",b);};function soap_queue(b,a){var c=function(){};this.defaultCallbacks={};this.defaultCallbacks.onSuccess=b&&b.onSuccess?b.onSuccess:c;this.defaultCallbacks.onBefore=b&&b.onBefore?b.onBefore:c;this.defaultCallbacks.onProgress=b&&b.onProgress?b.onProgress:c;this.defaultCallbacks.onFailure=b&&b.onFailure?b.onFailure:soaplib.onFailure;this.soapoptions=a?a:{};this.queue=[];this.result_queue=[];}soap_queue.prototype.add=function(c,a,b){var d={};d.command=c;d.param=clone(a);d.userData=b;this.queue.push(d);};soap_queue.prototype.addFirst=function(c,a,b){var d={};d.command=c;d.param=clone(a);d.userData=b;this.queue.unshift(d);};soap_queue.prototype.run=function(a){if(this.running){throw new Error("Attemting to rerun running queue");}this.callbacks={};for(f in this.defaultCallbacks){this.callbacks[f]=this.defaultCallbacks[f];}if(a){for(f in a){this.callbacks[f]=a[f];}}if(this.callbacks.onFailure){this.soapoptions.onFailure=this.callbacks.onFailure;}this.result_queue=[];this.total_queue_length=this.queue.length;if(this.total_queue_length!==0){this.running=true;this.callbacks.onBefore(this);this._runNextQueueElem(undefined,false);}else{this.callbacks.onSuccess(this);this.clear();}};soap_queue.prototype.is_running=function(){return this.running;};soap_queue.prototype.length=function(){return this.total_queue_length;};soap_queue.prototype.empty=function(){return this.length()===0;};soap_queue.prototype.remaining=function(){return this.queue.length;};soap_queue.prototype.clear=function(){if(this.is_running()){throw new Error("Attemting to clear running queue");}this.queue=[];this.running=false;this.total_queue_length=0;};soap_queue.prototype.stop=function(){this.running=false;this.clear();};soap_queue.prototype.findDoneCommand=function(a,b){var d=b?b:0;for(var c=0;c<this.result_queue.length;c++){if(this.result_queue[c].command===a){if(d===0){return this.result_queue[c];}else{d--;}}}return null;};soap_queue.prototype._runNextQueueElem=function(b,d){if(b!==undefined){var e=this.queue.shift();e.result=b;e.failed=d;this.result_queue.push(e);this.callbacks.onProgress(this,e);}if(this.remaining()===0){this.running=false;this.callbacks.onSuccess(this);this.clear();}else{var c=this,a=this.soapoptions.onFailure,g=clone(this.soapoptions);g.onFailure=function(j,h){var i=a?function(k,l){return a(j,h,k,l);}:function(){return soaplib.defaultOnFailure(j,h);};if(!i(c,c.queue[0])){c.running=false;c.clear();}else{c._runNextQueueElem(j,true);}};soaplib.call(this.queue[0].command,this.queue[0].param,function(h){c._runNextQueueElem(h,false);},g);}};
