﻿if (!iMap){
	var iMap=new Object();
}
Ext.onReady(function(){
		Ext.ns("iMap.addressSearch");
		iMap.addressSearch.Btn=new Ext.Button({
				text:'go',
				renderTo:'addressSearchBtn',
				handler:function(){
					if (iMap.addressSearch.input.getValue()==''){
						Ext.MessageBox.alert(iMap.lang.errorTitle, iMap.lang.specifyAddress);
						}else{
						if (! iMap.geocoder){iMap.geocoder=new GClientGeocoder();};
						iMap.geocoder.getLocations(iMap.addressSearch.input.getValue(), iMap.addressSearch.geocoderCallback);
					}
				}
		});
		iMap.addressSearch.geocoderCallback=function(response){
		    iMap.addressSearch.marker=null;
			if (!response || response.Status.code != 200) {
				Ext.MessageBox.alert('Error', 'Code '+response.Status.code+' Error Returned');
				} else {
				iMap.addressSearch.place = response.Placemark[0];
				var addressinfo = iMap.addressSearch.place.AddressDetails;
				var accuracy = addressinfo.Accuracy;
				if (accuracy === 0) {
					Ext.MessageBox.alert(iMap.lang.errorTitleAddressNotFound, iMap.lang.errorTextAddressNotFound);
					} else {
					if (accuracy<4){
					    Ext.MessageBox.alert(iMap.lang.errorTitleAddressNotFound, iMap.lang.errorTextAddressNotFound);
					    iMap.setBounds( iMap.addressSearch.place.Point.coordinates[1]-0.0001, iMap.addressSearch.place.Point.coordinates[0]-0.0001,iMap.addressSearch.place.Point.coordinates[1]+ 0.0001, iMap.addressSearch.place.Point.coordinates[0]+ 0.0001);
					    iMap.addressSearch.marker=new _G1(new _G2(iMap.addressSearch.place.Point.coordinates[1], iMap.addressSearch.place.Point.coordinates[0]));//,iMap.icons["adress"]);
					} else{
					    iMap.setBounds( iMap.addressSearch.place.Point.coordinates[1]-0.0001, iMap.addressSearch.place.Point.coordinates[0]-0.0001,iMap.addressSearch.place.Point.coordinates[1]+ 0.0001, iMap.addressSearch.place.Point.coordinates[0]+ 0.0001);
					    iMap.addressSearch.marker=new _G1(new _G2(iMap.addressSearch.place.Point.coordinates[1], iMap.addressSearch.place.Point.coordinates[0]),iMap.icons["adress"]);
	                    iMap.map.addOverlay(iMap.addressSearch.marker);
					
					}
				}
			}
		}
		iMap.addressSearch.input=new Ext.form.TextField({
				renderTo:'addressSearchInput',
				xtype:'numberfield',
				autoHeight:true,
				autoWidth:true,
			
			
				listeners: {
                    specialkey: function(field, e){
                      if (e.getKey() == e.ENTER) {
                        if (iMap.addressSearch.input.getValue()==''){
						Ext.MessageBox.alert(iMap.lang.errorTitle, iMap.lang.specifyAddress);
						}else{
						if (! iMap.geocoder){iMap.geocoder=new GClientGeocoder();};
						iMap.geocoder.getLocations(iMap.addressSearch.input.getValue(), iMap.addressSearch.geocoderCallback);
					}
                     }
                    }
                }
		})
		Ext.ns("iMap.faceSearch");
		iMap.faceSearch.Btn=new Ext.Button({
				text:'go',
				renderTo:'faceSearchBtn',
				handler:function(){
				    iMap.doCmd('searchFace', iMap.faceSearch.input.getValue());
				}
		});
		iMap.faceSearch.input=new Ext.form.TextField({
				renderTo:'faceSearchInput',
				xtype:'numberfield',
				autoHeight:true,
				autoWidth:true,
				selectOnFocus:true,
			
				listeners: {
                    specialkey: function(field, e){
                      if (e.getKey() == e.ENTER) {
                     //   iMap.doCmd('searchFace',[iMap.faceSearch.input.getValue(),1]);
                        iMap.doCmd('searchFace',iMap.faceSearch.input.getValue());
                     }
                    }
                }
		})
		iMap.faceSearch.notFound=function(){
			Ext.MessageBox.alert(iMap.lang.errorTitleFaceNotFound, iMap.lang.errorTextFaceNotFound);
			
		}
});

