
function Ajax_Handler(_newUrl,_newMethod)
{this.url=null;this.method='POST';this.requestData=new Array();this.onStart=null;this.onLoading=null;this.onLoaded=null;this.onInteractive=null;this.onCompletion=null;this.onError=null;this.onCreateFail=null;this.onFail=null;this.xmlHttp=null;this.queryPrefix='?';this.argSeparator='&';this.requestString=null;this.encodeString=true;this.status=new Array(null,null);this.thread=null;this.responseText=null;this.responseXML=null;var self=null;this.setUrl=function(url)
{this.url=url;}
this.setMethod=function(method)
{if(method==null)
{return;}
var method=method.toUpperCase();if(method=='POST'||method=='GET')
{this.method=method;}}
this._createXmlHttp=function()
{if(window.ActiveXObject)
{try
{this.xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');}
catch(e)
{try
{this.xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');}
catch(e2)
{}}}
else if(window.XMLHttpRequest)
{try
{this.xmlHttp=new XMLHttpRequest();}
catch(e)
{}}
if(this.xmlHttp==null)
{this.onCreateFail();}}
this.addRequestVar=function(name,value)
{this.requestData.push(new Array(name,value));}
this.clearRequestVars=function()
{this.requestData=new Array();}
this.run=function()
{this.onStart();this._createXmlHttp();if(this.xmlHttp==null)
{this.onFail();return false;}
else
{self=this;this.xmlHttp.onreadystatechange=this._readyState;if(this.method=='GET')
{this.xmlHttp.open(this.method,this._buildUrl()+this.queryPrefix+this._buildQuery(),true);this.xmlHttp.send(null);}
else if(this.method=='POST')
{this.xmlHttp.open(this.method,this._buildUrl(),true);this.xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');this.xmlHttp.send(this._buildQuery());}}}
this._readyState=function()
{switch(self.xmlHttp.readyState)
{case 1:self.onLoading();break;case 2:self.onLoaded();break;case 3:self.onInteractive();break;case 4:self.responseText=self.xmlHttp.responseText;self.responseXML=self.xmlHttp.responseXML;try
{self.status=new Array(self.xmlHttp.status,self.xmlHttp.statusText);}
catch(e)
{}
if(self.status[0]=='200')
{self.onCompletion();}
else
{self.onError();}
break;}}
this._buildUrl=function()
{return this.url;}
this._buildQuery=function()
{var requestQuery='';if(this.requestData.length>0)
{var parts=new Array();for(key in this.requestData)
{parts.push(this.requestData[key][0]+'='+this.requestData[key][1]);}
requestQuery+=parts.join(this.argSeparator);}
return requestQuery;}
this._resetFunctions=function()
{this.onStart=function(){}
this.onLoading=function(){}
this.onLoaded=function(){}
this.onInteractive=function(){}
this.onCompletion=function(){}
this.onError=function(){}
this.onCreateFail=function(){}
this.onFail=function(){}}
this._init=function(newUrl,newMethod)
{this._resetFunctions();this.setUrl(newUrl);this.setMethod(newMethod);}
this._init(_newUrl,_newMethod);}
cityRetrieve=null;function mtgAdvsBCheck(form)
{var propertyType=null;for(i=0;i<form.propertyType.length;i++)
{if(form.propertyType[i].checked==true)
{propertyType=form.propertyType[i].value;break;}}
if(form.city.value&&form.city.value>0&&propertyType!=null)
{cityRetrieve=new Ajax_Handler('mtgAdvancedSearch.htm','POST');cityRetrieve.addRequestVar('city',form.city.value);cityRetrieve.addRequestVar('subAction','getUrl');cityRetrieve.addRequestVar('starRating',form.starRating.value);cityRetrieve.addRequestVar('propertyType',propertyType);cityRetrieve.onCompletion=mtgAdvsBRedirect;cityRetrieve.run();return false;}
else
{alert('Please select a city and property type before submitting');}
return false;}
function mtgAdvsBGetCities(value)
{cityRetrieve=new Ajax_Handler('mtgAdvancedSearch.htm','POST');cityRetrieve.addRequestVar('stateId',value);cityRetrieve.addRequestVar('subAction','getCities');cityRetrieve.addRequestVar('contentVersion','1');cityRetrieve.onCompletion=mtgAdvsBReplaceCities;cityRetrieve.run();}
function mtgAdvsBReplaceCities()
{document.getElementById('mtgAdvsBCities').innerHTML=cityRetrieve.responseText;}
function mtgAdvsBRedirect()
{window.location=cityRetrieve.responseText;}