if(typeof de=='undefined')de = {};
de.atkon = {
	addLoadEvent: function(func) {
		var oldonload = window.onload;
		if(typeof window.onload != 'function')window.onload = func;
		else window.onload = function(){oldonload();func();}
	},
	redraw_sIFR: function(){
		if(!helvetica)var helvetica = {src:'fileadmin/view/basf/baselayout/css/NewHelveticaBold.swf',wmode:'transparent',ratios: [7,1.32,11,1.31,13,1.24,14,1.25,19,1.23,27,1.2,34,1.19,42,1.18,47,1.17,48,1.18,69,1.17,74,1.16,75,1.17,1.16]};
		if(sIFR)sIFR.replace(helvetica,{selector:'h1,h2,h3',css: ['.sIFR-root {color: #209FD1;font-weight:bold;margin-bottom:5px;m}','a,a:hover {color:#209FD1; text-decoration:none;}']});
	},
	show_hideToggle: function(element){
		var dom = (typeof element=='string') ? document.getElementById(element): element;
		if(dom)dom.style.display = dom.style.display!='none' ? 'none': 'block';
		de.atkon.customExtend(dom);
	},
	customExtend: function(obj){
		if(!obj)return false;
		if(obj.id=='tx-atkonsearch-extended'){
			if(obj.style.display!='none'){
				obj.style.marginBottom = '0px';
			}
			else {
				obj.style.marginBottom = '-10px';
			}
		}
	},
	replaceUnderscores: function(){
		de.atkon.HTMLTextReplace('h1','_','<br/>');
		de.atkon.HTMLTextReplace('h2','_','<br/>');
		de.atkon.HTMLTextReplace('h3','_','<br/>');
		var h = de.atkon.getElementsByClassName('blueText');
		//alert(h.length);
		//for(i=0; i<h.length; i++)de.atkon.HTMLTextReplace(h[i],'_','<br/>');
	},
	HTMLTextReplace: function(obj,needle,replace){
		var heads = typeof(obj)=='string' ? document.getElementsByTagName(obj) : obj;
		needle = RegExp(needle,'g');
		
		for(i=0; i<heads.length; i++){
			if(!heads[i].firstChild)break;
			html = heads[i].firstChild.nodeType!=3 ? heads[i].innerHTML.match(/\>(.*)\</)[1] :  heads[i].innerHTML.match(/(.*)/)[0];
			heads[i].innerHTML = heads[i].innerHTML.replace(html,html.replace(needle,replace));
		}
	},
	replaceFormidableImg: function(){
		var imgsrc = 'http://213.239.195.166:443/typo3conf/ext/ameos_formidable/api/base/rdt_date/res/lib/js_calendar/img.gif';
		var imgchg = 'fileadmin/view/basf/baselayout/images/icons/calendar_icon.gif';
		var imgs = document.getElementsByTagName('img');
		if(imgs.length>0){
			for(var i=0; i<imgs.length; i++){
				if(imgs[i].src == imgsrc)imgs[i].src = imgchg;
			}
		}
	},
	sortTopicRadioButtonOnClick: function(){
		if(_form = document.getElementById('tx-atkondamfrontend-sortTopic-form')){
			var _input = _form.getElementsByTagName('input');
			for(var i=0; i<_input.length; i++){
				_input[i].onclick = function(){
					document.getElementById('tx-atkondamfrontend-sortTopic-form').submit();
				}
			}
		}
	},
	__PROCESSED: false,
	__process: function(str,n){
		var dom;
		var supress = de.atkon.__PROCESSED ? false : de.atkon.getElementsByClassName('currentPos').length>0 ? true : false ;
		if(!supress && (dom = document.getElementById(str)) ){
			var prefix = str.substr(0,str.lastIndexOf('-'));
			var span = dom.getElementsByTagName('span');
			var n = Math.abs(n%span.length);
			var div;
			for(i=0; i<span.length; i++){
				if(div = document.getElementById(prefix+'-'+i)){
					div.style.display='none';
					span[i].className = '';
				}
			}
			if(document.getElementById(prefix+'-'+n)){
				document.getElementById(prefix+'-'+n).style.display='block';
				span[n].className = 'currentPos';
			}
		}
		de.atkon.redraw_sIFR();
		de.atkon.__PROCESSED = true;
	},
	__tooltip: function(obj,text){
		var target = obj;
		var matched = true;
		var p,a,s;
		
		while(target.className.indexOf('singleResult')<0){
			if(!target.parentNode){
				matched = false;
				break;
			}
			target=target.parentNode;
		}
		if(matched){
			p = target.getElementsByTagName('p');
			p = p[p.length-1];
			s = p.getElementsByTagName('small')[0];
			
			s.innerHTML = text;
		}
		if(!obj.onmouseout)obj.onmouseout = function(){
			de.atkon.__tooltip(this,"");		
		}
	},
	applyMagnifying: function(){
		if(li = document.getElementById('loupe')){
			var a = li.getElementsByTagName('a')
			var scales = [-1.15,0,1.15];
			for(var i=0; i<a.length; i++){
				if(a[i])a[i].href='javascript:zoomFontSize('+scales[i]+');';
			}
		}
	},
	searchBoxText: function(){
		var defaultTexts = new Array('enter text...','Suchwort eingeben ...');
		if(i = document.getElementById('input_search')){
			de.atkon.searchBoxTextReplaceCache = '';
			i.onclick =  function(){
				var v = this.value;
				
				if(defaultTexts.search(v)!==false){
					de.atkon.searchBoxTextReplaceCache = v;
					this.value = '';
				}
			};
			i.onblur = function(){
				var v = this.value;
				this.value = v=='' ? de.atkon.searchBoxTextReplaceCache : v;
			}
		}
	},
	getElementsByClassName: function(name, obj){
		var obj = obj || document;
		var a=[],c=null,ch=obj.childNodes,i=0,j=0,child,e;
		
		if(!ch || !ch.length) return null;
				
		for(i=0;i<ch.length; i++){
			child = ch[i];
			if(!child)continue;
			
			if(child.className && child.className.split(' ').search(name)!==false)a.push(child);
			
			if(c = de.atkon.getElementsByClassName(name,child)){
				for(j=0; j<c.length; j++)a.push(c[j]);
			}
		}
		return a;
	},
	createDelegate: function(instance, method){
		return function(){
			return method.apply(instance, arguments);
		}
	}
}

de.atkon.addLoadEvent(
	function(){
		de.atkon.applyMagnifying();
		de.atkon.replaceUnderscores();
		de.atkon.replaceFormidableImg();
		de.atkon.searchBoxText();
		de.atkon.sortTopicRadioButtonOnClick();
		de.atkon.__process('tx-srfeuserregister-pi1-process',0);
		de.atkon.show_hideToggle('tx-atkonsearch-extended');
	}
)


Array.prototype.search = function(val){
	for(i=0; i<this.length; i++)if(this[i]==val)return i;
	return false;
}

/* Array.push() not Implemented in IE5.01 */
if(typeof(Array.push)=='undefined'){
	Array.prototype.push = function(){
		for(i=0; i<arguments.length; i++)this[this.length]=arguments[i];
		return this.length;
	}
}

function zoomFontSize(percent) 
{ 
    var fontSize = document.body.style.fontSize; 
    if(fontSize == '' || percent == 0) 
    { 
		fontSize = '100%'; 
    } 
    var newSize = parseInt(fontSize) + percent; 
    document.body.style.fontSize = newSize + '%'; 

	resizeLogo(); 
} 

function resizeLogo() 
{ 
    if (document.getElementById("subNav") != null && document.getElementById("banderole") != null) 
    { 
                if (document.getElementById("banderole").style.width == null || document.getElementById("banderole").style.width == '') 
                { 
                        document.getElementById("banderole").style.width = '100%'; 
                } 
                document.getElementById("banderole").style.width = document.getElementById("subNav").offsetWidth + "px"; 

                if(document.getElementById("banderole2") != null) { 
                        document.getElementById("banderole2").style.width = document.getElementById("subNav").offsetWidth + "px"; 
                } 
                if(document.getElementById("logo") != null) { 
                        document.getElementById("logo").style.width = document.getElementById("subNav").offsetWidth + "px"; 
                } 
        } 
} 
