OSRequest.prototype=new Request;OSRequest.prototype.Server="http://openspace.ordnancesurvey.co.uk/osmapapi";OSRequest.prototype.BoundaryPath="/boundary";OSRequest.prototype.GazetteerPath="/gazetteer";OSRequest.prototype.PostCodePath="/postcode";OSRequest.prototype.SupportPath="/jsapi";OSRequest.prototype.TilePath="/ts";OSRequest.prototype.APIKey="557D7E14A2AF4B64E0405F0AF1603530";OSRequest.prototype.keyURL=URLClean(document.URL,true);function OSRequest(b,f,h,g,d,i,e,c,a){this.base=Request;this.base(f?"":undefined,a?a:wrapOSCB,undefined,false);this.userCB=e;this.wrOSCB=c;this.destroy=destroyOS;if(f){window[this.nm+this.id]=this;this.cbText=this.cbText.replace(new RegExp("(\\[|\\])","g"),"");this.src=this.Server+b+"?q="+encodeURIComponent(f)+"&callback="+encodeURIComponent(h?h:this.cbText)+"&key="+encodeURIComponent(g?g:this.APIKey)+"&url="+encodeURIComponent(d?d:this.keyURL)+"&f="+encodeURIComponent(i?i:"json");this.request()}}function wrapOSCB(a){this.userCB(this.wrOSCB(a&&(a.length==1)?a[0]:a))}function destroyOS(){try{window[this.nm+this.id]=undefined;delete window[this.nm+this.id]}catch(a){}OSRequest.prototype.destroy.apply(this)}OSGazetteerRequest.prototype=new OSRequest;function OSGazetteerRequest(){this.getLonLat=getOSGazLonLat;this.getLocations=getOSGazLocations}function getOSGazLonLat(b,a){this.base=OSRequest;this.base(this.GazetteerPath,b,null,null,null,null,a,getOSGazLonLatWrap)}function getOSGazLocations(b,a){this.base=OSRequest;this.base(this.GazetteerPath,b,null,null,null,null,a,getOSGazLocationsWrap)}function getOSGazLonLatWrap(d){var h=null;try{var b=d.GazetteerResult.items.Item;if(b.length==undefined){b=[b]}if(b.length>0){var c=b[0].name;var a=b[0].location["gml:Point"];var i=a["gml:pos"];var g=i.split(" ");h=window.OpenLayers?new OpenLayers.LonLat(parseFloat(g[0]),parseFloat(g[1])):{lon:parseFloat(g[0]),lat:parseFloat(g[1])}}}catch(f){}return h}function getOSGazLocationsWrap(l){var h=[];try{var c=l.GazetteerResult.items.Item;if(!(c instanceof Array)){c=[c]}for(var d=0,o=c.length;d<o;d++){var a=c[d].name;var f=c[d].county;var j=c[d].type;var n=c[d].location["gml:Point"];var k=n["gml:pos"];var b=k.split(" ");var m=window.OpenLayers?new OpenLayers.LonLat(parseFloat(b[0]),parseFloat(b[1])):{lon:parseFloat(b[0]),lat:parseFloat(b[1])};var p=new OSGazetteerEntry(a,f,j,m);h.push(p)}}catch(g){}return h}function OSGazetteerEntry(c,b,d,a){this.name=c;this.county=b;this.type=d;this.location=a}OSPostCodeRequest.prototype=new OSRequest;function OSPostCodeRequest(){this.getLonLat=getOSPCLonLat}function getOSPCLonLat(b,a){this.base=OSRequest;this.base(this.PostCodePath,b,null,null,null,null,a,getOSPCLonLatWrap)}function getOSPCLonLatWrap(a){var d=null;try{var c=a.PostcodeResult.location["gml:Point"]["gml:pos"].split(" ");d=window.OpenLayers?new OpenLayers.LonLat(parseFloat(c[0]),parseFloat(c[1])):{lon:parseFloat(c[0]),lat:parseFloat(c[1])}}catch(b){}return d}OSSupportRequest.prototype=new OSRequest;function OSSupportRequest(){this.getBoundaryCount=getOSBoundaryCount;this.getGazetteerCount=getOSGazetteerCount;this.getPostcodeCount=getOSPCCount;this.getTileCount=getOSTileCount}function OSSupWrapCallBack(b){var a=this.wrOSCB(b&&(b.length==1)?b[0]:b);this.userCB(a.c,a.m)}function getOSBoundaryCount(a){this.base=OSRequest;this.base(this.SupportPath,"boundarycount",null,null,null,null,a,getOSBoundaryCountWrap,OSSupWrapCallBack)}function getOSBoundaryCountWrap(b){var a={c:-1,m:-1};try{a.c=b.APIBoundaryCountVO.boundarysUsed;a.m=b.APIBoundaryCountVO.maxBoundarys}catch(c){}return a}function getOSGazetteerCount(a){this.base=OSRequest;this.base(this.SupportPath,"gazetteercount",null,null,null,null,a,getOSGazetteerCountWrap,OSSupWrapCallBack)}function getOSGazetteerCountWrap(b){var a={c:-1,m:-1};try{a.c=b.APIGazetteerCountVO.gazetteersUsed;a.m=b.APIGazetteerCountVO.maxGazetteers}catch(c){}return a}function getOSPCCount(a){this.base=OSRequest;this.base(this.SupportPath,"postcodecount",null,null,null,null,a,getOSPCCountWrap,OSSupWrapCallBack)}function getOSPCCountWrap(b){var a={c:-1,m:-1};try{a.c=b.APIPostcodeCountVO.postcodesUsed;a.m=b.APIPostcodeCountVO.maxPostcodes}catch(c){}return a}function getOSTileCount(a){this.base=OSRequest;this.base(this.SupportPath,"tilecount",null,null,null,null,a,getOSTileCountWrap,OSSupWrapCallBack)}function getOSTileCountWrap(b){var a={c:-1,m:-1};try{a.c=b.APITileCountVO.tilesUsed;a.m=b.APITileCountVO.maxTiles}catch(c){}return a};
