function loadMask() {
	new Ext.LoadMask(Ext.getBody(), {msg: 'Seite wird geladen...'}).show();
}

function redirect(targetUrl) {
	loadMask();
	window.location = targetUrl;
}


function _ajxRequest(_url, _params, _callback, _form) {
	if (Ext && Ext.isReady) {
		var ajaxConnection = new Ext.data.Connection();
		//var mask = new Ext.LoadMask(Ext.getBody(), {msg: 'Bitte warten...'});
		//mask.show();
	    ajaxConnection.request({
	        url: _url,
	        method: 'POST',
	        params: _params,
	        form: _form,
	        success: function(responseObject) {
	    		//mask.hide();
	            var retVal = Ext.util.JSON.decode(responseObject.responseText);
	            if (_callback != null) {
	            	_callback(retVal);
	            }
	        },
	        failure: function(responseObject) {
	        	//mask.hide();
	        	alert(responseObject.status);
	            Ext.Msg.alert('Status', 'Fehler!');
	        }
		});	    
	    return true;
	}
	else {
		return false;
	}
}


function ajxRequestConfirm(_url, _params, _message, _callback) {
	if (Ext && Ext.isReady && _message != '') {
		Ext.MessageBox.confirm('Best&auml;tigung', _message, 
			function(btn) { 
				if (btn == 'yes') {
					return _ajxRequest(_url,_params,_callback);
				}
			}
		);
	}
	else {
		return false;
	}
}  


function ajxFormRequest(_url, _params, _form, _callback) {
	return _ajxRequest(_url,_params,_callback, _form);
}

function ajxRequest(_url, _params, _callback) {
	return _ajxRequest(_url,_params,_callback);
}



function _addOptionStr(options, property, val) {
  if (val && ((isNaN(val) && String(val).length > 0) || val > 0)) {
    if (options.length > 0) {
    	options = options + ",";
    }
    options = options + property+"="+val;
  }
  return options;
}



function openWnd(wndName, url, width, height,resizable, scrollbars) {
	var options = "";
	options = _addOptionStr(options, "width",width);
	options = _addOptionStr(options, "height",height);
	  
	if (resizable) {
		resizable = 'yes';
	}
	else {
		resizable = 'no';
	}
	options = _addOptionStr(options, "resizable",resizable);
	  
	if (scrollbars) {
		scrollbars = 'yes';
	}
	else {
		scrollbars = 'no';
	}
	options = _addOptionStr(options, "scrollbars",scrollbars);
	var wnd = window.open(url,wndName, options);
	wnd.focus();
	return wnd;
}

	  


function openPrintDlg(btnHolder, close) {
	if (btnHolder) {
		var oldVal = btnHolder.style.visibility;
		btnHolder.style.visibility = 'hidden';
	}
	window.print();
	if (close) {
		window.close();
	}
	if (btnHolder) {
		btnHolder.style.visibility = oldVal;
	}
}
