if (navigator.userAgent.match(/Firefox\/4/)) {
	runOnLoadFinish(function() {
		Ext.select('form').each(function(f) {
			foreach(f.dom.elements, function(el) {
				var pattern = el.getAttribute ? el.getAttribute('pattern') : null, reg = '.*';
				if (pattern) {
					reg = '.*';
					switch (pattern) {
						case "pass" :
							reg = '^.{7,}$';
							break;
						case "text" :
							reg = '^[a-zA-Z0-9äöü&szlig;]+$';
							break;
						case "int" :
							reg = '^[0-9]+$';
							break;
						case "lt" :
							reg = '^[0-9]+$';
							break;
						case "gt" :
							reg = '^[0-9]+$';
							break;
						case "plz" :
							reg = '\b((?:0[1-46-9]\d{3})|(?:[1-357-9]\d{4})|(?:[4][0-24-9]\d{3})|(?:[6][013-9]\d{3}))\b';
							break;
						case "mail" :
							reg = '[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}\b';
							break;
						case "date" :
							reg = '\b(((0?[1-9]|[12][0-9])\.(0?[1-9]|1[0-2])\.)|(30\.((0?[13-9])|(1[0-2]))\.)|(31\.(0?[13578]|1[02])\.))(\d{2}|(19|20)\d{2})\b';
							break;
						case "alldates" :
							reg = '^\b((((0?[1-9]|[12][0-9])\.(0?[1-9]|1[0-2])\.)|(30\.((0?[13-9])|(1[0-2]))\.)|(31\.(0?[13578]|1[02])\.))(\d{2}|(19|20)\d{2}))|((0?[1-9]|1[0-2])\.((19|20)\d{2}|\d{2}))\b';
							break;
						case "time" :
							reg = '\b([01][0-9]|2[0-3]):[0-5][0-9]\b';
							break;
					};
					el.setAttribute('pattern', reg);
				}
			});
		});
		cmslogin = function(f) {
			if (f.elements['username'].value.length && f.elements['password'].value.length) {
				f.elements['response'].value = MD5(f.elements['password'].value);
				f.elements['password'].value = "";
				f.elements['password'].setAttribute('valid', 'true');
				f.elements['password'].removeAttribute('required');
				return (true);
			};
			return (false);
		};
	});
};
if (navigator.userAgent.match(/MSIE\s9/)) {
	if ((typeof Range !== "undefined") && !Range.prototype.createContextualFragment) {
		Range.prototype.createContextualFragment = function(html) {
			var frag = document.createDocumentFragment(), div = document.createElement("div");
			frag.appendChild(div);
			div.outerHTML = html;
			return frag;
		};
	};
	Ext.Element.prototype.getAttributeNS = function(ns, name) {
		var d = this.dom;
		return d.getAttributeNS(ns, name) || d.getAttribute(ns + ":" + name) || d.getAttribute(name) || d[name];
	};
};

var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
Ext.onReady( function() {
	/*******************************************************************************************************************
	 * Startseite Bildermanipulation
	 */
	var bereich1 = Ext.get('bereich1');
	if (bereich1) {
		Ext.select('#bereich1 img').each( function(el) {
			var wb1 = bereich1.getWidth();
			var elw = el.getWidth();
			if (elw > wb1) {
				var neww = wb1 - 27;
				var faktor = neww / elw;
				var newh = el.getHeight() * faktor;
				el.setWidth(neww);
				el.setHeight(newh);
			}
		});
	}
	/** ******************************* */
	var box;
	var initlink = Ext.select('.extwndowlink');
	initlink.each( function(el) {
		var lnk = el.dom;
		var conf_title = 'Weitere Informationen';
		var conf_modal = true;
		var conf_width = 740;
		var conf_height = 420;
		var conf_display_header = false;
		lnk.onclick = function() {
			box = Ext.MessageBox.show({
				title :conf_title,
				msg :'<img src=\"' + basepath + '_/scripts/ext/resources/images/default/grid/loading.gif\" alt=\"\" style=\"border:0; vertical-align:middle;\"> Loading...',
				animEl :lnk,
				modal :conf_modal,
				fn : function() {
					Ext.MessageBox.hide();
					box.getDialog().header.dom.style.display = 'block';
					Ext.MessageBox.getDialog().bwrap.removeClass('xdlgbodyxtra');
				}
			});
			//
			if (conf_display_header == false) {
				box.getDialog().header.dom.style.display = 'none';
			}
			var url = lnk.href;
			Ext.Ajax.request({
				url :url,
				success : function(req) {
					var treg = /<!--\sINHALT\s-->(.+)<!--\sINHALT\s-->/gi;
					var bd = treg.exec(req.responseText.split(/\n/).join(''));
					if (bd && bd[1]) {
						var txt = bd[1];
						txt = '<div id="blubber" style="width:' + (conf_width - 40) + 'px; overflow-x:hidden;overflow-y:auto;">' + txt + '</div>';
						Ext.MessageBox.updateText(txt);
						Ext.MessageBox.getDialog().center();
						if (Ext.MessageBox.getDialog().size.height > 500) {
							Ext.get("blubber").dom.style.height = "470px";
							Ext.MessageBox.getDialog().resizeTo(conf_width, 500);
						} else {
							Ext.MessageBox.getDialog().resizeTo(conf_width, Ext.MessageBox.getDialog().size.height);
						}
						// Ext.MessageBox.getDialog().resizeTo(conf_width,conf_height);
			}
		}
			});
			Ext.MessageBox.getDialog().bwrap.addClass('xdlgbodyxtra');
			/*
			 * var toolbox = Ext.get(Ext.MessageBox.getDialog().toolbox.dom.id); var box = Ext.get('appendto');
			 * toolbox.appendTo(box); toolbox.dom.style.zIndex = "1000000"; debugger;
			 */
			/*
			 * Ext.MessageBox.getDialog().center(); Ext.MessageBox.getDialog().toolbox.setXY([-10,-10], true);
			 */
			return (false);
		}
	});
});
function showFullImage(url, lnk, mw, mh) {
	var conf_title = "";
	var conf_modal = true;
	var txt = '<img id="boxelem" src=\"' + url + '\" alt=\"\" style=\"border:0; vertical-align:middle;\">';
	var minwidth = parseInt(mw);
	var minheight = parseInt(mh);
	box = Ext.MessageBox.show({
		title :conf_title,
		msg :'Lade...',
		animEl :lnk,
		width :minwidth,
		height :minheight,
		modal :conf_modal,
		fn : function() {}
	});
	Ext.MessageBox.updateText(txt);
	Ext.MessageBox.getDialog().center();
	var w = Ext.get('boxelem').getWidth();
	var h = Ext.get('boxelem').getHeight();
	if (w < minwidth) w = minwidth;
	if (h < minheight) h = minheight;
	Ext.MessageBox.getDialog().resizeTo(w + 20, h + 50);
};
function showinBigBox(box, el, firstrun , autostart ) {
	var dur = .5;
	var box = box || 'topmeldungenlist';
	var firstrun = firstrun || false;
	var autostart  = autostart ||  false; 
	
	if (autostart === false && firstrun == false ){
		window.clearInterval(autoBoxTimeOut);

		
	}
	if (firstrun == true) {
		var squares = Ext.select(".square");
		var buttons = Ext.get("buttons");
		squares.each( function(el) {
			el.appendTo(buttons);
			el.fadeIn({
				duration :dur,
				useDisplay :true
			});
		});
	}
	var elid = 'tm' + el;
	var inh = Ext.get(elid);
	var squares = Ext.select(".square");
	squares.each( function(el) {
		el.removeClass("activesquare");
	});
	if (inh) {
		var boxel = Ext.get(box);
		if (boxel) {
			var h = boxel.getHeight();
			var sollh = 231 - 50; // 20 = boxen zählboxen
			boxel.setHeight(sollh);
			Ext.get('square' + el).addClass('activesquare');
			boxel.fadeOut({
				duration :dur,
				useDisplay :true,
				callback : function() {
					boxel.dom.innerHTML = inh.dom.innerHTML;
					boxel.fadeIn({
						duration :dur,
						useDisplay :true
					});
				}
			});
			// boxel.setHeight (sollh);
		}
	}
};
function runAutoMaticBox() {
	var square = Ext.select('.square');
	var box = 'topmeldungenlist';
	var boxel = Ext.get(box);
	var nextismine = false; 
	elids = new Array(); 
	
	square.each( function(el) {
		if (el.dom.id.indexOf('square') != -1) {
			var nr = el.dom.id.split('square');
			elids.push(nr[1]);
			
		}
	});
	
	var j = 0; 
	for(i=0; i<=elids.length; i++){
		j = i; 
		var inh = Ext.get('tm'+elids[i]);
		if (boxel.dom.innerHTML == inh.dom.innerHTML  ){
			
			
			
			j = j+1; 
			if (j >= elids.length){
				j = 0; 
			}
			showinBigBox('topmeldungenlist', elids[j], false , true ); 
			return true; 
		}
		
	}
	
	
};


function callBackForm ( langid ){
	var artId = 128; /* DE Formular **/ 
	switch(langid){
		case '76':	artId = 255; break; 
	}
	
	document.location.href = "/"+artId; 
	
}

function startSiteClick ( langid ){
	
	var redirect = "/de/";
	switch(langid){
		case '76':
		redirect = "/en/"; 
		break;
		
		case '309':
		redirect = "/ru/"; 
		break; 
	}
	document.location.href = redirect;
	
};

var autoBoxTimeOut; 
runOnLoad( function() {
	var boxel = Ext.get('topmeldungenlist');
	if (boxel){
	autoBoxTimeOut =  window.setInterval( runAutoMaticBox , 5000 );
	}
	
});
