﻿function PyDajax(params,returnXML,callbackObject,callbackFunction){this.baseUrl="/Ajax.aspx";this.http=this.getHTTP();if(0<arguments.length){if(params.substring){this.params=[params]}else{this.params=params}if(true==returnXML){this.returnXML=true}else{this.returnXML=false}this.callbackObject=callbackObject;if(callbackFunction){this.callback=callbackFunction}else{this.callback=null}}};PyDajax.prototype.toString=function(){return"PyDajax"};PyDajax.prototype.getHTTP=function(){if(!window.ActiveXObject){return new XMLHttpRequest()}else if(-1==navigator.userAgent.toLowerCase().indexOf("msie 5")){return new ActiveXObject("Msxml2.XMLHTTP")}else{return new ActiveXObject("Microsoft.XMLHTTP")}};PyDajax.prototype.createCallback=function(callbackObject,callbackFunction){return function(){callbackFunction.apply(callbackObject,arguments)}};PyDajax.prototype.fetch=function(url,xml){this.http.open("GET",url,false);this.http.send("");if(true==xml){return this.http.responseXML}else{return this.http.responseText}};PyDajax.prototype.send=function(){var serialized,async,i;if(this.callback){async=true}else{async=false}serialized="";for(i=0;i<this.params.length;i++){if(0<serialized.length){serialized+="\t"}serialized+=this.params[i]}serialized+='\t'+document.location;serialized=encodeURI(serialized);this.http.open("POST",this.baseUrl,async);this.http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");this.http.setRequestHeader("Content-Length",serialized.length);if(true==async){this.http.onreadystatechange=this.createCallback(this,this.checkHttpState)}this.http.send(serialized);if(false==async){return this.getResponse()}};PyDajax.prototype.checkHttpState=function(){if(4==this.http.readyState){if(this.callback){this.callback.call(this.callbackObject,this.getResponse())}}};PyDajax.prototype.getResponse=function(){try{switch(this.http.status){case 200:if(true==this.returnXML){return this.http.responseXML}else{return this.http.responseText}case 202:throw new CustomError(this.http.responseText);case 405:throw new CustomError("The requested method does not exist.");case 500:throw new CustomError("Something unexpected occurred while processing your request.");default:throw new CustomError("The PlanYourDive server had a hiccup or something.  Please try again in a minute or two.")}}catch(e){if(!this.callback){throw e}else{showError(e);return null}}};