
<!-- //

/**
 *	dynaimcBox.js
 *
 *	@author: gg@seso.at
 */


function rbm_dynamicBox(name, container) {
	
	var self = this;

	this.name = name;
	this.container = container;

	var tabCache = [];
	var tabCount = 0;
	
	var pointCache = [];
	var pointCount = 0;
	
	var radioCache = [];
	var radioCount = 0;
	
	var lboxCache = [];
	var lboxCount = 0;
	
	var rowCache = [];
	var rowCount = 0;
	
	var activeBox = 0;
	
	var activeTab = 1;
	
	var tmpHref = null;
	
	var avatarCheck = false;
	var agbCheck = false;
	
	
	var form = new Array('private_', 'public_', 'datum_', 'tags_', 'titel_', 'beschreibung_');

	
	this.addRow = function(active, container) {
	
		rowCache[++rowCount] = new rbm_tab(active, container);
	};
	
	
	
	// adds a new tab to the box
	
	this.addTab = function(title, container) {
	
		tabCache[++tabCount] = new rbm_tab(title, container);
	};
	
	
	
	// adds a new point to the box
	
	this.addPoint = function(title, container, open) {
		
		var p = {};
			p.title = title;
			p.container = container;
			p.open = (open) ? open : false
	
		pointCache[++pointCount] = p;
	};
	
	
	// adds a new lightbox to the box
	
	this.addLightBox = function(link, container, hideCloseBtn) {
		
		var o = new Object();
			o.link = link;
			o.container = container;
			o.closeBtn = (hideCloseBtn == false) ? false : true;
	
		lboxCache[++lboxCount] = o;
	};
	
	
	
	// set the active tab at the begin
	
	this.setActiveTab = function(index) {
		
		activeTab = index;
	}
	
	
	
	// paints the box and writes it in the main-container
	
	this.init = function() {

		if (pointCache.length > 0) {
			
			createPointHeaders();
		}
		
		if (tabCache.length > 0) {
			
			createTabHeader();
			self.selectTab(activeTab);
		}
		
		if (radioCache.length > 0) {
			
			createRadioPoints();
		}
		
		if (lboxCache.length > 0) {
			
			createLightBox();
		}
		
		if (rowCache.length > 0) {
			
			createActiveRows();
		}
	};
	
	
	

	function createActiveRows() {
		
		var i, j, t;
		
		for (i=1; i<rowCache.length; i++) {
			
			var row = document.getElementById(rowCache[i].container);
			
			var form = new Array();

			form[0] = row.getElementsByTagName('INPUT');
			form[1] = row.getElementsByTagName('SELECT');

			for (t=0; t<form.length; t++) {
			
				for (j=0; j<form[t].length; j++) {

					type = form[t][j].getAttribute('type');
					
					if (type && type == 'checkbox') {
						
						form[t][j].setAttribute('index', i);
						
						form[t][j].checked = rowCache[i].title;
						
						if (env.isIE) {
				
							form[t][j].attachEvent("onchange", self.changeActiveRow);
						}
							
						else {
							
							form[t][j].onchange = self.changeActiveRow;
						}
					}
					
					else form[t][j].disabled = !rowCache[i].title;
				}
			}

		}
	}
	
	
	
	this.changeActiveRow = function(e) {
		
		var element = (e.srcElement) ? e.srcElement : e.target;
		
		var row = document.getElementById(rowCache[element.getAttribute('index')].container); 
		
		var form = new Array();
		
		form[0] = row.getElementsByTagName('INPUT');
		form[1] = row.getElementsByTagName('SELECT');
		
		for (t=0; t<form.length; t++) {
			
			for (j=0; j<form[t].length; j++) {
				
				type = form[t][j].getAttribute('type');
				
				if (type != 'checkbox') form[t][j].disabled = !element.checked;
			}
		}
	}
	
	
	
	
	// activates the tab with the given index
	
	this.selectTab = function(index) {

		if (activeTab) {

			// change the active tabHead
			document.getElementById(self.name+"_tabHead_"+activeTab).className = "tabHead";
			
			// hide the active tabContent
			document.getElementById(tabCache[activeTab].container).style.display = 'none';
		}

		// change the new tabHead
		document.getElementById(self.name+"_tabHead_"+index).className += " act";
		
		// show the new tabContent
		document.getElementById(tabCache[index].container).style.display = 'block';
		
		activeTab = index;
	
	};

	
	
	// create the header of the tabBox
	
	function createTabHeader() {
	
		var h, d, a, i;
	
		h = document.createElement('div');
		h.className = "tabHeader";
		h.setAttribute("id", "tabHeader");
		
		for (var t=1; t<tabCache.length; t++) {
			
			d = document.createElement('DIV');
			d.className = "tabHead";
			d.setAttribute("id", self.name+"_tabHead_"+t);

			i = document.createTextNode(tabCache[t].title);

			a = document.createElement('a');
			a.setAttribute("href", "javascript:"+self.name+".selectTab("+t+");");
			a.setAttribute("onclick", "this.blur();");
			
			a.appendChild(i);
			
			d.appendChild(a);
			
			h.appendChild(d);
		}
		
		document.getElementById(self.container).appendChild(h);
	}
	
	
	
	// decorate the headers of the points with a hyperlink
	
	function createPointHeaders() {
		
		var a, d, h, n, t;

		for (var p=1; p<pointCache.length; p++) {
			
			d = document.createElement('DIV');
			d.className = "pointHead";
			d.setAttribute("id", self.name+"_pointHead_"+p);
	
			a = document.createElement('A');
			a.setAttribute("href", "javascript:"+self.name+".expandPoint("+p+");");
			a.setAttribute("onclick", "this.blur();");
			
			t = document.getElementById(pointCache[p].title);
			// JBU 19.10.2009 add style.display:none, so SuperFi's different design will be initially compressed/collapsed either
			document.getElementById(pointCache[p].container).style.display = "none";
			
			n = t.parentNode;
			
			h = t.cloneNode(true);

			a.appendChild(h);
			
			d.appendChild(a);

			n.replaceChild(d, t);
			
			if (pointCache[p].open == true) self.expandPoint(p);
		}
	}
	
	
	
	// expand a point
	
	this.expandPoint = function(index) {
		
		document.getElementById(pointCache[index].container).style.display = "block";

		var p = document.getElementById(self.name+"_pointHead_"+index);
		
		p.className += " pact";
		
		p.getElementsByTagName("A")[0].setAttribute("href", "javascript:"+self.name+".collapsePoint("+index+");");
	};
	
	
	
	// collapse a point
	
	this.collapsePoint = function(index) {
		
		document.getElementById(pointCache[index].container).style.display = "none";

		var p = document.getElementById(self.name+"_pointHead_"+index);
		
		p.className = "pointHead";
		
		p.getElementsByTagName("A")[0].setAttribute("href", "javascript:"+self.name+".expandPoint("+index+");");
	};
	
	

	this.addRadio = function(input, container) {
	
		radioCache[++radioCount] = new rbm_tab(input, container);
	};
	

	
	function createRadioPoints() {

		var r;

		for (var i=1; i<radioCache.length; i++) {
		
			r = document.getElementById(radioCache[i].title);
			
			r.setAttribute("index", i);

			if (env.isIE) {
				
				r.attachEvent("onclick", self.selectRadio);
			}
				
			else {
				
				r.onchange = self.selectRadio;
			}
		}
	}
	
	
	this.selectRadio = function(e) {
		
		var element = (e.srcElement) ? e.srcElement : e.target;
		
		var i = element.getAttribute("index");
		
		resetRadios();
		
		document.getElementById("label_"+radioCache[i].title).style.color = "#0099CC";
		document.getElementById(radioCache[i].container).style.display = "block";
	};
	
	
	
	function resetRadios() {
		
		for (var i = 1; i < radioCache.length; i++) {
			
			document.getElementById("label_"+radioCache[i].title).style.color = "#FFFFFF";
			document.getElementById(radioCache[i].container).style.display = "none";
		}
	}
	
	
	
	this.changeForm = function(type, value) {
		
		switch (type) {
			
			case "zahlungsart":
			
				if (value > 0) {
					
					document.getElementById('formContainer_lastschrift').style.display = "none";
					document.getElementById('formContainer_kreditkarte').style.display = "block";
				}
				
				else {
					
					document.getElementById('formContainer_lastschrift').style.display = "block";
					document.getElementById('formContainer_kreditkarte').style.display = "none";
				}
			
				break;
				
			default: break;
		}
	}

	
	function createLightBox() {
		
		// create background-layer
		
		var body = document.getElementsByTagName('BODY')[0];
		
		
		if (!document.getElementById('lightBox_bg_layer')) {
		
			var bg = document.createElement('DIV');
				bg.className = 'lightBox_bg_layer';
				bg.setAttribute('id', 'lightBox_bg_layer');
				
				if (lboxCache[1].closeBtn === true) {
				
					if (env.isIE) {
						
						bg.attachEvent("onclick", self.closeLightBox);
					}
						
					else {
						
						bg.onclick = self.closeLightBox;
					}
				
				}
			
			body.appendChild(bg);
		}
		
		

		for (var i=1; i<lboxCache.length; i++) {
			
			var a = document.getElementById(lboxCache[i].link);
			
			if (a) {
			
				a.setAttribute('index', i);
				
				if (env.isIE) {
					
					a.attachEvent("onclick", self.showLightBox);
				}
					
				else {
					
					a.onclick = self.showLightBox;
				}
			}
			
			
			var box = document.getElementById(lboxCache[i].container);
	
				
			// create lightbox-frame
			
			var l = document.createElement('DIV');
				l.className = "lightbox";
				l.setAttribute('id', lboxCache[i].container);
			
			
			// border top
			
			var bt = document.createElement('DIV');
				bt.className = "border";
				
			var glt = document.createElement('DIV');
				glt.className = "glowLeftTop";
				
				bt.appendChild(glt);
				
			var gt = document.createElement('DIV');
				gt.className = "glowTop";
				
				bt.appendChild(gt);
				
			var grt = document.createElement('DIV');
				grt.className = "glowRightTop";
				
				bt.appendChild(grt);
				
			l.appendChild(bt);
			
			
			// container
			
			var c = document.createElement('DIV');
				c.className = "container";

			var cl = document.createElement('DIV');
				cl.id = 'lightboxContentMain';
				cl.className = "contentLayer lightboxContent";
				
				if (lboxCache[i].closeBtn === true) {
			
					var x = document.createElement('DIV');
						x.className = "close";
						x.innerHTML = "<a href=\"javascript:"+self.name+".closeLightBox();\">schlie&szlig;en X</a>";
						cl.appendChild(x);
				}
				
				cl.innerHTML += box.innerHTML;
				
				c.appendChild(cl);
			
			l.appendChild(c);
			
			
			// border bottom
			
			var bb = document.createElement('DIV');
				bb.className = "border";
				
			var glb = document.createElement('DIV');
				glb.className = "glowLeftBottom";
				
				bb.appendChild(glb);
				
			var gb = document.createElement('DIV');
				gb.className = "glowBottom";
				
				bb.appendChild(gb);
				
			var grb = document.createElement('DIV');
				grb.className = "glowRightBottom";
				
				bb.appendChild(grb);


			l.appendChild(bb);
			
			
			var r = document.getElementById("rbm_clearNS");
			
			if (!r) {
						
				var r = document.createElement('DIV');
					r.id = "rbm_clearNS";
					r.className = "rbm clearNS";
			}
				
			r.appendChild(l);	
			
			body.appendChild(r);
			
			box.parentNode.removeChild(box);
		}
	};
	
	
	
	this.openLightBox = function(index, param) {

		activeBox = index;

		var box = document.getElementById(lboxCache[activeBox].container);
		
		var a = box.getElementsByTagName('A')[0];
		
		var href = a.getAttribute('href');
		
			tmpHref = href;
		
			href += param;
			
		a.setAttribute('href', href);

		self.calcLightBox();
		
		window.onresize = self.calcLightBox;
		
		return false;
	};
	
	
	
	this.showLightBox = function(e) {
		
		var element = (e.srcElement) ? e.srcElement : e.target;

		activeBox = element.getAttribute('index');
		
		self.calcLightBox();
		
		window.onresize = self.calcLightBox;
		
		return false;
	};
	
	
	
	this.closeLightBox = function() {
		
		if (tmpHref !== null) {
		
			var box = document.getElementById(lboxCache[activeBox].container);
			
			var a = box.getElementsByTagName('A')[0];
				a.setAttribute('href', tmpHref);
			
			tmpHref = null;
		}
		
		document.getElementById(lboxCache[activeBox].container).style.display = 'none';
		document.getElementById('lightBox_bg_layer').style.display = 'none';
		
		activeBox = 0;
		
		// show selects
			
		if (env.browser == 'ie6') {
			
			var selects = document.getElementsByTagName('SELECT');
			
			for (var s=0; s<selects.length; s++) {
				
				selects[s].style.visibility = 'visible';
			}
		}
	};
	
	
	
	this.calcLightBox = function() {

		if (activeBox > 0) {
	
			var vw, vh;
			
			var box = document.getElementById(lboxCache[activeBox].container);
			
			var html = document.getElementsByTagName('HTML')[0];
			var body = document.getElementsByTagName('BODY')[0];
			
			 	vh = (env.browser == 'safari3') ? body.scrollHeight : html.scrollHeight;
			 	vw = html.offsetWidth;
	
			var bg = document.getElementById('lightBox_bg_layer');
				bg.style.height = vh + 'px';
				bg.style.width = vw + 'px';
				bg.style.display = "block";
			
			vw = body.scrollWidth;
			vh = body.scrollHeight;
 
			document.getElementById(lboxCache[activeBox].container).style.display = 'block';
			
			var t = Math.round((vh - box.offsetHeight)/2);
			var l = Math.round((vw - box.offsetWidth)/2);

			if (env.isIE) {

				t += document.documentElement.scrollTop;
			}
			
			else if (env.browser == 'safari3') {
				
				t += window.pageYOffset / 2;
			}
			
			else {
				
				t += window.pageYOffset;
			}
	
			box.style.top =  t + 'px';
			box.style.left = l + 'px';
			
			
			// hide selects
			
			if (env.browser == 'ie6') {
				
				var selects = document.getElementsByTagName('SELECT');
				
				for (var s=0; s<selects.length; s++) {
					
					selects[s].style.visibility = 'hidden';
				}
			}
		}
	}
	
	
	
	
	this.openPopup = function(url) {
		
		var w = 700;
		var h = 388;
		
		// w3c
		 
		 if (typeof window.innerWidth != 'undefined') {
		      
			  x = window.innerWidth;
		      y = window.innerHeight;
		 }
		 
		// ie6
		
		 else {
		 
		 	x = document.documentElement.clientWidth;
		    y = document.documentElement.clientHeight;
		 }
		 
		 
		x = (x-w)/2;
		y = (y-h)/2;

		window.open(url, "popup_3d", "width="+w+", height="+h+", screenX="+x+", screenY="+y+", dependent=yes, location=no, menubar=no, resizable=no, scrollbars=no, status=no");
	}



	this.showLogin = function(){

		with (document.getElementById(container).style) {
	
			if (display == 'none'){

				display = 'block';

				document.getElementById(name).style.height = '179px';

				if (env.browser == 'ie6'){
					
					login_iframe_fix(container, true)
				}

				
			} else {
				
				display = 'none';
				document.getElementById(name).style.height = '20px';

				if (env.browser == 'ie6'){
					
					login_iframe_fix(container, false)

				}

			}

		}

	}

	this.initLogin = function(){

		loginFormStyle = document.getElementById(container).style.display = 'none';

	}

	this.submitLogin = function(evt){
		
		if (env.browser != 'safari3') {

			if (evt.srcElement){
				
				target = evt.srcElement.id;
			}
			
			else target = evt.currentTarget.id;
	
			if (evt.keyCode == 13) {
	
				if (target == "login_rufnummer"){
	
					mediaTable.requestCode();
					document.getElementById('login_sms').focus();
				}
		
				else if (target == "login_sms" || target == "login_save"){
	
					mediaTable.performLogin();

				}
			}
		}

	}

	function login_iframe_fix(div_id, state){
			
		var div = document.getElementById(div_id);

		if(state)
		{
			var iframe = document.createElement('iframe');
			document.getElementById('login_iframe_fix').appendChild(iframe);
			
			iframe.id = 'login_iframe';
			iframe.style.position = 'absolute';
			iframe.style.width = div.offsetWidth;
			iframe.style.height = div.offsetHeight - 48;
			iframe.style.top = div.style.top - 4;
			iframe.style.left = div.style.left;
			iframe.style.zIndex = 95; 
			iframe.style.display = 'block';
			iframe.scrolling = 'no';
			iframe.frameBorder = 0;
		}
		else
		{
			document.getElementById('login_iframe_fix').removeChild(document.getElementById('login_iframe'));
		}

	}
	
	
	
	
	this.uploadTakeAll = function(flag, id) {
		
		var values = {};

		for (k in form) {

			f = document.getElementById(form[k]+id);
			
			values[form[k]] = f.value;
			
			if (env.isIE) {
				
				if (flag == true) f.attachEvent("onblur", self.uploadBroadcast);
			}
				
			else {
				
				f.onblur = (flag == true) ? self.uploadBroadcast : null;
			}
		}

		
		var d = (flag == true) ? 'DISABLED' : false;
		
		
		for (var i=1; i<=pointCount; i++) {
			
			if (i != id) {
				
				for (k in form) {

					document.getElementById(form[k]+i).disabled = d;
					
					document.getElementById(form[k]+i).value = (d == false) ? "" : values[form[k]];
				}
				
				document.getElementById('properties_'+i).disabled = d;
			}
			
		}
		
	}
	
	
	this.uploadBroadcast = function(e) {
		
		e = (e.srcElement) ? e.srcElement : e.target;
		
		var id = e.getAttribute("id").split('_')[1];
		
		var form = e.getAttribute("id").split('_')[0];
		
		for (var i=1; i<=pointCount; i++) {
			
			if (i != id) document.getElementById(form+'_'+i).value = e.value;
		}
	}


	this.addInputField = function (id,pattern,errormsg){
	
		if (typeof inputFields == 'undefined') inputFields = new Array();
		
		i = inputFields.length;

		inputFields[i] = new Object();
		inputFields[i]['id'] = id;
		inputFields[i]['pattern'] = pattern;
		inputFields[i]['errormsg'] = errormsg;

	}

	this.checkInputField = function(id,pattern){
	
		var reg = new RegExp(pattern); 
	
		with(document.getElementById(id)){
		
			return reg.test(value); 

		}

	}

	this.checkInput = function(){
	
		var errormsg = '';
		
		for (var i = 0; i < inputFields.length; i++) {
			
			if (!self.checkInputField(inputFields[i]['id'],inputFields[i]['pattern'])){
			
				errormsg += '<p>' + inputFields[i]['errormsg'] + '</p>';

			}

		}

		if (errormsg != ''){
		
			document.getElementById('errormsg').innerHTML = errormsg;
			document.getElementById('errormsg').className = 'error';

		}else document.getElementById('FormOptIn').submit();

	}
	
	
	
	this.setAvatarCheck = function(flag) {
		
		avatarCheck = flag;
	}
	
	
	this.setAGBCheck = function(flag) {
		
		agbCheck = flag;
	}
	
	
	this.submitProfile = function(formId) {
		
		var error = "";
		
		if (document.getElementById('text_profile_upload_photo').value.length > 0) {
			
			if (!avatarCheck) {
				
				error += "<p>Akzeptieren Sie den Verhaltenskodex!</p>";
			}
		}
		
		if (document.getElementById('accept_agb')) {

			if (!agbCheck) {
				
				error += "<p>Akzeptieren Sie die AGBs!</p>";
			}
		}
		
		if (error.length == 0) {
			
			document.getElementById(formId).submit();
		}
		
		else {
			
			document.getElementById('errorContainer').innerHTML = error;
		}
	}

	
}



// tab entity

function rbm_tab(title, container) {

	this.title = title;
	this.container = container;
}	


// -->

