var CWL={version:'2.0.0 beta'};CWL.data={};CWL.dd={};CWL.gmap={};CWL.page={};CWL.util={};CWL.inherit=function(superClass,subClass){for(var p in superClass.prototype){if(!subClass.prototype[p]){subClass.prototype[p]=superClass.prototype[p];}}};CWL.Page=function(){};CWL.Page.prototype={gmapLat:'35.6675',gmapLon:'139.7666',gmapZoom:4,requestCallback:function(obj){},requestMethod:'GET',requestParams:{},requestUrl:'/',ajaxRequest:function(){Ext.Ajax.request({method:this.requestMethod,url:this.requestUrl,params:this.requestParams,scope:this,success:function(obj){this.requestCallback(obj);}});},showGMap:function(id){this.gmap=new GMap2(document.getElementById(id));this.gmap.addControl(new GLargeMapControl());this.gmap.addControl(new GMapTypeControl());this.gmap.setCenter(new GLatLng(this.gmapLat,this.gmapLon),this.gmapZoom);}};Ext.override(Ext.dd.DDProxy,{startDrag:function(X,Y){var source=Ext.get(this.getEl());var ghost=Ext.get(this.getDragEl());ghost.addClass('cwl_dd_gadget');ghost.setStyle('opacity',0.25);ghost.dom.innerHTML=source.dom.innerHTML;source.addClass('cwl_dd_gadget_target');source.child('.cwl_dd_gadget_title_bar').setStyle('visibility','hidden');source.child('.cwl_dd_gadget_body').setStyle('visibility','hidden');this.benchmarkY=Y;},endDrag:function(e){var source=Ext.get(this.getEl());var ghost=Ext.get(this.getDragEl());var margin=source.getMargins();ghost.setStyle('visibility','visible');ghost.moveTo(source.getX()+margin.left,source.getY()+margin.top,{callback:function(){source.removeClass('cwl_dd_gadget_target');source.child('.cwl_dd_gadget_title_bar').setStyle('visibility','visible');source.child('.cwl_dd_gadget_body').setStyle('visibility','visible');ghost.removeClass('cwl_dd_gadget');ghost.clearOpacity();ghost.dom.innerHTML=null;ghost.setStyle('visibility','hidden');}});},onDragOver:function(e,id){var source=Ext.get(this.getEl());var destination=Ext.get(id);if(destination.is('.cwl_dd_gadget')){var y=e.getPageY();if(this.benchmarkY>y){source.insertBefore(destination);}
else if(this.benchmarkY<y){source.insertAfter(destination);}
Ext.dd.DragDropMgr.refreshCache({CWL_DD_GADGET:true});this.benchmarkY=y;}
else if(destination.is('.cwl_dd_target')){if(!destination.contains(source)){destination.appendChild(source);Ext.dd.DragDropMgr.refreshCache({CWL_DD_GADGET:true});this.benchmarkY=source.getBottom();}}}});CWL.dd.Gadget=function(obj){this.id=obj.id;this.title=obj.title;this.body=obj.body;this.anchor=obj.anchor;this.description=obj.description;};CWL.dd.Gadget.prototype={GROUP:'CWL_DD_GADGET',collapse:true,collapseButton:'/CWL/js/cwl/images/collapse.gif',expandButton:'/CWL/js/cwl/images/expand.gif',isTarget:true,lock:false,getDescription:function(){return this.description;},getId:function(){return this.id;},getTemplate:function(){var T={tag:'div',cls:'cwl_dd_gadget_title'};var TA;if(this.anchor!=undefined){TA={tag:'a'};for(var key in this.anchor){TA[key]=this.anchor[key];}
TA.html=this.title;T.children=[TA];}
else{T.html=this.title;}
var I={tag:'img',cls:'cwl_dd_gadget_collapse_expand_button'};if(this.collapse){I.src=this.expandButton;}
else{I.src=this.collapseButton;}
var BA={tag:'a',href:'javascript:void(0)',onclick:'CWL.dd._gadgets[\''+this.id+'\'].pressCollapseExpandButton();',children:[I]};var BTN={tag:'div',cls:'cwl_dd_gadget_button',children:[BA]};var C={tag:'div',style:'clear:both'};var TB={tag:'div',cls:'cwl_dd_gadget_title_bar',children:[T,BTN,C]};var BD={tag:'div',cls:'cwl_dd_gadget_body',html:this.body};if(this.collapse){BD.style='display:none';}
else{BD.style='display:block';}
var G={tag:'div',id:this.id,cls:'cwl_dd_gadget',children:[TB,BD]};return Ext.DomHelper.createTemplate(G);},getTitle:function(){return this.title;},hide:function(){Ext.get(this.id).setStyle('display','none');},pressCollapseExpandButton:function(){var b=Ext.get(this.id).child('.cwl_dd_gadget_body');var i=Ext.get(this.id).child('.cwl_dd_gadget_collapse_expand_button');if(this.collapse){b.setStyle('display','block');i.dom.src=this.collapseButton;}
else{b.setStyle('display','none');i.dom.src=this.expandButton;}
this.collapse=!this.collapse;},setBody:function(body){this.body=body;var b=Ext.get(this.id).child('.cwl_dd_gadget_body');b.dom.innerHTML=body;},setDescription:function(description){this.description=description;},setTitle:function(title){this.title=title;var e=Ext.get(this.id).child('.cwl_dd_gadget_title');var t=title;if(this.anchor!=undefined){var A={tag:'a'};for(var key in this.anchor){A[key]=this.anchor[key];}
A.html=title;t=Ext.DomHelper.createTemplate(A).apply();}
e.dom.innerHTML=t;},show:function(){Ext.get(this.id).setStyle('display','block');}};CWL.dd.Target=function(id){this.id=id;this.ddtarget=new Ext.dd.DDTarget(id,this.GROUP);this.gadgets=[];var tmpl={tag:'div',id:'cwl_dd_target_entity'};this.entity=Ext.DomHelper.append(Ext.get(id),tmpl);};CWL.dd.Target.prototype={GROUP:'CWL_DD_TARGET',addGadget:function(gadget){this.gadgets.push(gadget);CWL.dd._gadgets[gadget.getId()]=gadget;gadget.getTemplate().append(this.entity);var ddp=new Ext.dd.DDProxy(gadget.getId(),gadget.GROUP);ddp.groups[this.GROUP]=true;ddp.groups[gadget.GROUP]=true;ddp.isTarget=gadget.isTarget;if(gadget.lock){ddp.lock();}},clearGadgets:function(){this.gadgets=[];var a=Ext.get(this.ddtarget.getEl()).query('.cwl_dd_gadget');for(var i=0;i<a.length;i++){Ext.get(a[i]).remove();}},getGadget:function(id){var g;for(var i=0;i<this.gadgets.length;i++){if(this.gadgets[i].getId()==id){g=this.gadgets[i];break;}}
return g;},refresh:function(){Ext.get(this.entity).setStyle('display','block');}};CWL.dd.TargetManager=function(selector){var a=Ext.DomQuery.select(selector);for(var i=0;i<a.length;i++){this[a[i].id]=new CWL.dd.Target(a[i].id);}
CWL.dd._gadgets={};};CWL.dd.TargetManager.prototype={getTarget:function(id){return this[id];}};CWL.gmap.InfoWindow=function(obj){this.id=obj.id;this.title=obj.title;this.body=obj.body;};CWL.gmap.InfoWindow.prototype={maxWidth:300,open:function(gmarker){var content=function(o){var T={tag:'div',cls:'cwl_gmap_infowindow_title',html:o.title};var D={tag:'div',cls:'cwl_gmap_infowindow_body',children:[o.body]};var A={tag:'div',id:'cwl_if_'+o.id,cls:'cwl_gmap_infowindow',children:[T,D]};return Ext.DomHelper.createTemplate(A).apply();}(this);var opts={maxWidth:this.maxWidth};gmarker.openInfoWindowHtml(content,opts);},setBody:function(body){this.body=body;},setTitle:function(title){this.title=title;}};CWL.gmap.Marker=function(obj){this.id=obj.id;this.gmarker=new GMarker(new GLatLng(obj.lat,obj.lon));};CWL.gmap.Marker.prototype={draw:function(gmap){gmap.addOverlay(this.gmarker);},hide:function(){this.gmarker.hide();},getGMarker:function(){return this.gmarker;},getId:function(){return this.id;},getInfoWindow:function(){return this.infoWindow;},getLat:function(){return this.gmarker.getLatLng().lat();},getLon:function(){return this.gmarker.getLatLng().lng();},openInfoWindow:function(){if(this.infoWindow!=undefined){this.infoWindow.open(this.gmarker);}},setInfoWindow:function(infoWindow){this.infoWindow=infoWindow;GEvent.bind(this.gmarker,'click',this,this.openInfoWindow);},show:function(){this.gmarker.show();},showMapBlowup:function(){this.gmarker.showMapBlowup();}};CWL.gmap.MarkerManager=function(gmap){this.gmap=gmap;this.markers=[];this.minX=180.0;this.minY=90.0;this.maxX=-180.0;this.maxY=-90.0;};CWL.gmap.MarkerManager.prototype={addMarker:function(marker){this.markers.push(marker);marker.draw(this.gmap);var markerLat=marker.getLat();var markerLon=marker.getLon();if(this.minX>markerLon){this.minX=markerLon;}
if(this.minY>markerLat){this.minY=markerLat;}
if(this.maxX<markerLon){this.maxX=markerLon;}
if(this.maxY<markerLat){this.maxY=markerLat;}},getBounds:function(){var sw=new GLatLng(this.minY,this.minX);var ne=new GLatLng(this.maxY,this.maxX);return new GLatLngBounds(sw,ne);},getCenter:function(){var lat=(eval(this.minY)+eval(this.maxY))/2;var lon=(eval(this.minX)+eval(this.maxX))/2;return new GLatLng(lat,lon);},getMarker:function(id){var m;for(var i=0;i<this.markers.length;i++){if(this.markers[i].getId()==id){m=this.markers[i];break;}}
return m;},getMarkers:function(){return this.markers;},refresh:function(){var b=this.gmap.getBounds();for(var i=0;i<this.markers.length;i++){var markerLat=this.markers[i].getLat();var markerLon=this.markers[i].getLon();if(b.containsLatLng(new GLatLng(markerLat,markerLon))){this.markers[i].show();}
else{this.markers[i].hide();}}},removeMarker:function(marker){this.minX=180.0;this.minY=90.0;this.maxX=-180.0;this.maxY=-90.0;var a=[];for(var i=0;i<this.markers.length;i++){if(marker.getId()!=this.markers[i].getId()){var markerX=this.markers[i].getLon();var markerY=this.markers[i].getLat();if(this.minX>markerX){this.minX=markerX;}
if(this.minY>markerY){this.minY=markerY;}
if(this.maxX<markerX){this.maxX=markerX;}
if(this.maxY<markerY){this.maxY=markerY}
a.push(this.markers[i]);}}
this.markers=a;this.gmap.removeOverlay(marker.getGMarker());}};CWL.util.Cookie={EXPIRES:'Tue, 01-Jan-2030 00:00:00 GMT',get:function(key){var value;var cookie=document.cookie;var a=cookie.split('; ');for(var i=0;i<a.length;i++){var kv=a[i].split('=');if(kv[0]==key){value=kv[1];break;}}
return value;},set:function(key,value){var uri=window.location.pathname;var path=uri.substr(0,uri.lastIndexOf('/',uri.length+1)+1);document.cookie=key+'='+value+'; expires='+CWL.util.Cookie.EXPIRES+'; path='+path+';';}};CWL.util.HTML={encodeCRLF:function(s){return s.replace(/\x0d\x0a|\x0d|\x0a/g,'<br>');}};CWL.util.TextFieldMonitor=function(id,scope,callback){this.target=Ext.get(document.getElementById(id));this.scope=scope;this.callback=callback;};CWL.util.TextFieldMonitor.prototype={interval:200,_monitor:function(){var str='';var self=this;var closure=function(){if(str!=self.target.getValue()){str=self.target.getValue();self.scope.callback=self.callback;self.scope.callback(str);self.scope.callback=undefined;}};return closure;},start:function(){var timer;this.target.on('focus',function(){timer=setInterval(this._monitor(),this.interval);},this);this.target.on('blur',function(){clearInterval(timer);});}};CWL.data.Body=function(obj){this.data=obj;this.button=[];};CWL.data.Body.prototype={_getDescription:function(){var d=this.data.description.replace(/\x0d\x0a|\x0d|\x0a/g,'<br>');return d;},_getImg:function(){var I={};if(this.data.image){var url='/CWL/www/point/pict/'+this.data.uid+'/'+this.data.id+'/T2_'+this.data.image+'.jpg';I={tag:'img',src:url,align:'right'};}
return I;},addButton:function(obj){obj.style+='float:right;';this.button.push(obj);},getHtml:function(){var img=this._getImg();var desc=this._getDescription();var base={tag:'div',children:[img,desc]};var button={tag:'div',style:'text-align:right',children:this.button};var D={tag:'div',children:[base,button]};return Ext.DomHelper.createTemplate(D).apply();}};
