function form_koordinatentransformation(lang){
	if (lang == 'de'){var title = 'Online - Koordinatentransformation';}
	else {
		var title = 'Online Coordinate Transformation';
	};
	
	Ext.apply(Ext.form.VTypes, {  
	 	'numeric': function(){  
	       
	         /***************************************************************** 
	         DESCRIPTION: Validates that a string contains only valid numbers. 
	         PARAMETERS: 
	            strValue - String to be tested for validity 
	         RETURNS: 
	            True if valid, otherwise false. 
	         ******************************************************************/  
	           var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;  
	           return function(strValue){  
	               //check for numeric characters  
	               return objRegExp.test(strValue);
	           }  
	 	}(),  
	 	'numericText': 'Only numbers are allowed'  
	});  
	
	var introTxt = 'Mit dem Formular k&ouml;nnen einzelne Koordinaten zwischen den in Deutschland ';
	introTxt += 'g&auml;ngigen Koordinatensystemen umgerechnet werden.</br></br>';
	introTxt += 'Die Grundlage f&uuml;r die Berechnung bilden die Methoden zur Koordinatentransformation, ';
	introTxt += 'welche die <a href="http://proj4js.org/" target="_blank">proj4js</a> - ';
	introTxt += 'Bibliothek zur Verf&uuml;gung stellt.</br></br>';
	
	var srsStore =  new Ext.data.ArrayStore({
        id: 'srsStore',
        autoLoad: false,
        fields: [
            'srs',
            'displayText',
            'description',
            'minx',
            'miny',
            'maxx',
            'maxy'
        ],
        data: [
        	['EPSG:4326', 'WGS84', 'Geographische Koordinaten in Dezimalgrad\nEllipsoid WGS84, Datum WGS84\nX: 13.5 Y: 51.01',5,16,46,56],
        	['EPSG:900913', 'Google', 'Google Mercator projection',null,null,null,null],
        	['EPSG:31466', 'GK2', 'Gauss-Krueger-Abbildung im 2. Meridianstreifen\nEllipsoid Bessel, Datum Potsdam',2280000,3360000,5080000,6320000],
        	['EPSG:31467', 'GK3', 'Gauss-Krueger-Abbildung im 3. Meridianstreifen\nEllipsoid Bessel, Datum Potsdam',3040000,4120000,5070000,6310000],
        	['EPSG:31468', 'GK4', 'Gauss-Krueger-Abbildung im 4. Meridianstreifen\nEllipsoid Bessel, Datum Potsdam',3877000,4957000,5080000,6320000],
        	['EPSG:31469', 'GK5', 'Gauss-Krueger-Abbildung im 5. Meridianstreifen\nEllipsoid Bessel, Datum Potsdam',4551000,5711000,5015000,6335000],
        	['EPSG:32632', 'UTM32N', 'Universal Transverse Mercator-Abbildung, 32. Zone\nEllipsoid WGS84, Datum WGS84',75000,1550000,5070000,6310000],
        	['EPSG:32633', 'UTM33N', 'Universal Transverse Mercator-Abbildung, 33. Zone\nEllipsoid WGS84, Datum WGS84',-425000,700000,5020000,6340000]
        ]
    });
	
	var src_srs = new Ext.form.ComboBox({
	    // all of your config options
		tpl: '<tpl for="."><div ext:qtip="<b>{srs}</b>" class="x-combo-list-item">{displayText}</div&gt;</tpl>',tpl: '<tpl for="."><div ext:qtip="<b>{srs}</b> {displayText}" class="x-combo-list-item">{displayText}</div></tpl>',
		fieldLabel: 'Bezugssystem',
		id: 'src_srs',
		store: srsStore,
		forceSelection: true,
		typeAhead: true,
		triggerAction: 'all',
		emptyText: 'WGS84', //'Select a source system ...',
    	selectOnFocus:true,
		mode: 'local',
		valueField: 'srs',
		editable: false,
		width: 164,
    	displayField: 'displayText',
    	listeners: {
    		select: function(cb){
    			var cbSrsStore = cb.store;
    			var selectedValue = Ext.get('src_srs').getValue();
    			var recId = cbSrsStore.find('displayText', selectedValue);
    			var beispielText = cbSrsStore.getAt(recId).data['description'];
    			var el = Ext.getCmp('srcBeispiel');
    			el.setValue(beispielText);
    		}    		
    	}
    });
	
	var tar_srs = new Ext.form.ComboBox({
	    // all of your config options
		tpl: '<tpl for="."><div ext:qtip="<b>{srs}</b>" class="x-combo-list-item">{displayText}</div></tpl>',
		fieldLabel: 'Bezugssystem',
	    id: 'tar_srs',
		store: srsStore,
		forceSelection: true,
		typeAhead: true,
		triggerAction: 'all',
		emptyText:'Select a target system ...',
    	selectOnFocus:true,
		mode: 'local',
		valueField: 'srs',
		editable: false,
		width: 164,
    	displayField: 'displayText',
    	listeners: {
    		select: function(cb){
    			var cbSrsStore = cb.store;
    			var selectedValue = Ext.get('tar_srs').getValue();
    			var recId = cbSrsStore.find('displayText', selectedValue);
    			var beispielText = cbSrsStore.getAt(recId).data['description'];
    			var el = Ext.getCmp('tarBeispiel');
    			el.setValue(beispielText);
    			// Beginne Berechnung wenn HW und RW gegeben
    			var srsSrc = Ext.get('src_srs').getValue();  //alert('srcSrs: ' + srsSrc);
    			var Xsrc = Ext.getCmp('srcX_wert').getValue(); //alert('Xsrc: ' + Xsrc);
    			var Ysrc = Ext.getCmp('srcY_wert').getValue(); //alert('Ysrc: ' + Ysrc);
    			var recId = srsStore.find('displayText', srsSrc); 
    			var epsgSrc = srsStore.getAt(recId).data['srs']; //alert('epsgSrc: ' + epsgSrc);
    			var recId = srsStore.find('displayText', selectedValue);
    			var epsgDest = srsStore.getAt(recId).data['srs']; //alert('epsgDest: ' + epsgDest);
    			if(Xsrc != null && Ysrc != null && epsgSrc != null && epsgDest != null){
    				calcTransform(Xsrc, Ysrc, epsgSrc, epsgDest);
    			}
    		}    		
    	}
	});
	
	var src_example = new Ext.form.TextArea({
		width: '90%',
		id: 'srcBeispiel',
		cls: 'koordtrans_bsp',
		fieldLabel: 'Beispiel',
		emptyText: 'Ausgangssystem',
		//readOnly: true,
		editable: false,
    	style: {backgroundColor:'#efefef'}
	});
	
	var tar_example = new Ext.form.TextArea({
		width: '90%',
		id: 'tarBeispiel',
		cls: 'koordtrans_bsp',
		fieldLabel: 'Beispiel',
		emptyText: 'Zielsystem',
		//readOnly: true,
		editable: false,
    	style: {backgroundColor:'#efefef'}
	});
	
	var srcX_koordinate = new Ext.form.TextField({
    	fieldLabel: 'X - Rechtswert',
    	id: 'srcX_wert',
    	vtype: 'numeric',
    	listeners: {
    		/* Prüfe Wertebereich */
    		blur: function(e){
    			var selectedValue = Ext.get('src_srs').getValue(); 
    			var selectedDestValue = Ext.get('tar_srs').getValue(); 
    			var recId = srsStore.find('displayText', selectedValue);
    			var recDestId = srsStore.find('displayText', selectedDestValue);
    			var epsgDest = null;
    			if(recDestId >= 0){
    				epsgDest = srsStore.getAt(recDestId).data['srs'];
    			}
    			if(recId >= 0){
    				var minx = srsStore.getAt(recId).data['minx'];
	    			var maxx = srsStore.getAt(recId).data['maxx'];
	    			var miny = srsStore.getAt(recId).data['miny'];
	    			var maxy = srsStore.getAt(recId).data['maxy'];
	    			var epsgSrc = srsStore.getAt(recId).data['srs'];
    				var validateX = validateXCoordinates(e.getValue(), minx, maxx);
    				var validateY = validateYCoordinates(Ext.getCmp('srcY_wert').getValue(), miny, maxy);
    				if(validateX == true && validateY == true){
	    				calcTransform(e.getValue(), Ext.getCmp('srcY_wert').getValue(), epsgSrc, epsgDest);
	    			}
	    			else if (validateX == false) {
	    				Ext.Msg.alert('Hinweis', 'X - Rechtswert ausserhalb des g&uuml;tigen Wertebereiches.');
	    			}
    			}
    			else {
    				Ext.Msg.alert('Hinweis', 'Bitte ein Koordinatensystem ausw&auml;hlen.');
    			}
    		}
    	}
	});
	var srcY_koordinate = new Ext.form.TextField({
		fieldLabel: 'Y - Hochwert',
    	id: 'srcY_wert',
    	vtype: 'numeric',
    	listeners: {
    		/* Prüfe Wertebereich */
    		blur: function(e){
    			var selectedValue = Ext.get('src_srs').getValue(); 
    			var selectedDestValue = Ext.get('tar_srs').getValue(); 
    			var recId = srsStore.find('displayText', selectedValue);
    			var recDestId = srsStore.find('displayText', selectedDestValue);
    			var epsgDest = null;
    			if(recDestId >= 0){
    				epsgDest = srsStore.getAt(recDestId).data['srs'];
    			}
    			if(recId >= 0){
	    			var miny = srsStore.getAt(recId).data['miny'];
	    			var maxy = srsStore.getAt(recId).data['maxy'];
	    			var minx = srsStore.getAt(recId).data['minx'];
	    			var maxx = srsStore.getAt(recId).data['maxx'];
	    			var epsgSrc = srsStore.getAt(recId).data['srs'];
	    			var validateY = validateYCoordinates(e.getValue(), miny, maxy);
	    			var validateX = validateXCoordinates(Ext.getCmp('srcX_wert').getValue(), minx, maxx);
	    			if(validateY == true && validateX == true){
	    					calcTransform(Ext.getCmp('srcX_wert').getValue(), e.getValue(), epsgSrc, epsgDest);
	    			}
	    			else if (validateY == false) {
	    				Ext.Msg.alert('Hinweis', 'Y - Hochwert ausserhalb des g&uuml;tigen Wertebereiches.');
	    			}
    			}
    			else {
    				Ext.Msg.alert('Hinweis', 'Bitte ein Koordinatensystem ausw&auml;hlen.');
    			}
    		}
    	}
	});
	
	var tarX_koordinate = new Ext.form.TextField({
		id: 'tarXKoordinate',
		fieldLabel: 'X - Rechtswert',
		//readOnly: true,
		editable: false,
    	name: 'tarX_wert',
    	style: {backgroundColor:'#efefef'}    	
	});
	var tarY_koordinate = new Ext.form.TextField({
		id: 'tarYKoordinate',
    	fieldLabel: 'Y - Hochwert',
		//readOnly: true,
		editable: false,
    	name: 'tarY_wert',
    	style: {backgroundColor:'#efefef'}
	});

	var srcForm = new Ext.form.FormPanel({
		title: 'Ausgangssystem',
		id: 'Ausgangssystem',
		items: [src_srs, src_example, srcX_koordinate, srcY_koordinate]
	});
	
	var tarForm = new Ext.form.FormPanel({
		title: 'Zielsystem',
		items: [tar_srs, tar_example, tarX_koordinate, tarY_koordinate]
	});
		
	var tablayout = {
		layout: 'table',
		layoutConfig: {
        	columns: 2
    	},
    	items:[{
    		html: introTxt,
    		colspan: 2
    	},{
    		items: srcForm,
    		width: '280'
    	},{
    		items: tarForm,
    		width: '280'
    	},{
    		contentEl: 'map_koord',
    		width: '600',
    		height: '258',
    		colspan: 2
    	}]
	};
	
	
	//alert(Ext.getCmp('map_koord'));
	var coordPanel = new Ext.Panel({
		title: title,
		id: 'coordTransformPanel',
		width: 630,
		height: 550,
		frame: true,
		//style: {marginLeft: '10px', marginTop: '10px'},
		items: [tablayout],
		listeners :{
    			afterrender: function(){
    			visdat.mapGo('koordinatentransformation');
    		}
    	}
	});
	
	return coordPanel;
}

validateXCoordinates = function(x, minx, maxx){
	if(minx <= x && x <= maxx){
		return true;
	}
	else {
		return false;
	}
}

validateYCoordinates = function(y, miny, maxy){
	if(miny <= y && y <= maxy){
		return true;	
	}
	else {
		return false;
	}
}

calcTransform = function(x,y,epsgSrc,epsgDest){
	var sourceSrs = new Proj4js.Proj(epsgSrc);   
	if(epsgDest != null){
		var destSrs = new Proj4js.Proj(epsgDest);
	}
	else {
		var destSrs = new Proj4js.Proj(epsgSrc);
	}
	
	var p = new Proj4js.Point(parseFloat(x),parseFloat(y)); 
	Proj4js.transform(sourceSrs, destSrs, p); 
	Ext.getCmp('tarXKoordinate').setValue(p.x); 
	Ext.getCmp('tarYKoordinate').setValue(p.y);
}
	




