//üü

// FileTypes for Download/Upload
var arrAllowedFileTypes = new Array ('.doc', '.docx', '.pdf', '.xls', '.xlsx', '.ppt', '.pptx', '.pps', '.ppsx', '.txt', ".png", ".jpeg", ".jpg", ".gif" );

var oFileIcons = new Object();									var oFileTypes = new Object();
oFileIcons['doc'] = 'img/file/word.png';						oFileTypes['doc'] = 'Microsoft Office Word 97 - 2003-Dokument';
oFileIcons['docx'] = 'img/file/word.png';						oFileTypes['docx'] = 'Microsoft Office Word-Dokument';
oFileIcons['pdf'] = 'img/file/acrobat.png';						oFileTypes['pdf'] = 'Adobe Acrobat Dokument';
oFileIcons['xls'] = 'img/file/excel.png';						oFileTypes['xls'] = 'Microsoft Office Excel 97 - 2003-Arbeitsblatt';
oFileIcons['xlsx'] = 'img/file/excel.png';						oFileTypes['xlsx'] = 'Micorosoft Office Excel-Arbeitsblatt';
oFileIcons['ppt'] = 'img/file/powerpoint.png';					oFileTypes['ppt'] = 'Microsoft Office PowerPoint 97 - 2003-Präsentation';
oFileIcons['pptx'] = 'img/file/powerpoint.png';					oFileTypes['pptx'] = 'Microsoft Office PowerPoint-Präsentation';
oFileIcons['pps'] = 'img/file/powerpoint.png';					oFileTypes['pps'] = 'Microsoft Office PowerPoint 97 - 2003-Bildschirmpräsentation';
oFileIcons['ppsx'] = 'img/file/powerpoint.png';					oFileTypes['ppsx'] = 'Microsoft Office PowerPoint-Bildschirmpräsentation';
oFileIcons['txt'] = 'img/file/text.png';						oFileTypes['txt'] = 'Textdokument';
oFileIcons['png'] = 'img/file/picture.png';						oFileTypes['png'] = 'PNG-Bild';
oFileIcons['jpeg'] = 'img/file/picture.png';					oFileTypes['jpeg'] = 'JPEG-Bild';
oFileIcons['jpg'] = 'img/file/picture.png';						oFileTypes['jpg'] = 'JPEG-Bild';
oFileIcons['gif'] = 'img/file/picture.png';						oFileTypes['gif'] = 'GIF-Bild';



/*******************************  Error Handler *************************/

function showError (text)
{
	if (typeof console != "undefined")
	{
		console.error ("Ein Fehler ist aufgetreten: " + text);
	}
	if (Ext.isEmpty (text))		return;			// Leere Fehlermeldungen zeigen wir gar nicht an ...
	
	Ext.Msg.hide();		// Evt. offene Fenster verstecken (Progress undso)
	var win = new Ext.Window
	({
		title: 'Fehler!',
		height: 500,
		width: 700,
		layout: 'fit',
		modal: true,
		items:
		[
			{
				xtype: 'panel',
				padding: 5,
				html: text,
				autoScroll: true
			}
		]
	});
	win.show();
}

/******************************* Global AJAX-Data Error Handler *************************/
/*
	// show a spinner during all Ajax requests
	Ext.Ajax.on('requestcomplete', function (conn, response)
	{
		var resp = Ext.util.JSON.decode (response.responseText);

		if (resp['success'] == false)
		{
			if (resp['reason'] != undefined)
			{
				// Allgemeine Fehlermeldung
				showError (resp['reason'], 'main-status');
			}
			else
			{
				// Fehlermeldungen ein Formular betreffend; Markiere diese entsprechend
				for (var i = 0; i < resp['errors']['field'].length; i++)
				{
					var item = resp['errors']['field'][i];
					Ext.getCmp (item['id']).markInvalid (item['msg']);
				}
			}
		}
	});
	Ext.Ajax.on('requestexception', function (conn, response) { showError (response.responseText, 'main-status') });

*/

/**************** Debug-function: Recursive  Array to String ****************/


 function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;

	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";

	if(typeof(arr) == 'object') { //Array/Hashes/Objects
		for(var item in arr) {
			var value = arr[item];

			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

/*********** Erweitert einen String um eine "startsWith" und eine "endsWith"-Funktion *****************/
String.prototype.startsWith = function(str)
{
    return (this.match ("^" + str) == str);
}
String.prototype.endsWith = function (str)
{
	return (this.match (str + "$") == str);
}
String.prototype.firstUpperCase = function ()
{
	return this.substr (0, 1).toUpperCase().concat (this.substr (1, this.length - 1));
}

/**
  *	Provides a php-like way to count the elements
  *	of an array or object
  * @param arr The array or object
  *	@return The number of elements
  */
function count (arr)
{
	var i = 0;
	for (var k in arr)
	{
		if (typeof arr[k] != "function")
			i++;
	}
	return i;
}

/**
  * Formatiert eine Zahl
  * @param zahl Die Zahl, die formatiert werden soll 
  * @param number (optional) Die Anzahl der Nachkommastellen auf die die Zahl gerundet werden soll (default: 0)
  * @param fix (optional) Dieser Parameter bestimmt, ob die formatierte Zahl eine feste Anzahl von Nachkommastellen
  * haben soll. Ist der Wert true, dann werden evtl. fehlende Stellen mit einer Null aufgeüllt. 
  * @return Die Formatierte Zahl
  */  
function formatZahl(zahl, k, fix) {
    if(!k) k = 0;
    var neu = '';
 
	var dec_point = ',';
	var thousands_sep = '.';
 
    // Runden
    var f = Math.pow(10, k);
    zahl = '' + parseInt(zahl * f + (.5 * (zahl > 0 ? 1 : -1)) ) / f ;
 
    // Komma ermittlen
    var idx = zahl.indexOf('.');
 
    // fehlende Nullen einfügen
    if(fix)    {
         zahl += (idx == -1 ? '.' : '' )
         + f.toString().substring(1);
    }
	var sign = zahl < 0;
	if(sign) zahl = zahl.substring(1);
    idx = zahl.indexOf('.');
 
	// Nachkommastellen ermittlen
    if( idx == -1) idx = zahl.length;
    else neu = dec_point + zahl.substr(idx + 1, k);
 
 
    while(idx > 0)    {
        if(idx - 3 > 0)
        neu = thousands_sep + zahl.substring( idx - 3, idx) + neu;
        else
        neu = zahl.substring(0, idx) + neu;
        idx -= 3;
    }
    
    return (sign ? '-' : '') + neu;
}
