﻿// ********************************************** clickEventHandler *************************************************//
var GetElementId = Class.create();
GetElementId.prototype = {
		initialize: function() {
			window.document.onclick = this.onMouseClick.bindAsEventListener(this);
	},
	onMouseClick:function(evt){
	
			hideUserProfile('')
			$('suggest').innerHTML = '' ;
			
		switch(evt.id){
			default:
			break;
		} 
	}
}
function ClickEvtHandler(){var evtHandler = new GetElementId()}
// ********************************************** Box by zbyszek und Kejo *******************************************//


function getCitySuggest(id,mode,design, zipid, cityid, filename,l){
	if(l === undefined || l === null)
		l=3;
		
	cl = '21171a3d7e4c40b251d885';
	m_l = ($F(id)).length;
	if(m_l >= l){
		new Ajax.Request('/AjaxRequest_cl_'+cl+'_me_'+mode, {
			method:'post',
			parameters:'d='+design+"&zipid="+zipid+"&cityid="+cityid+"&file="+filename+"&cityName="+$F(id),
			onSuccess: function(transport) {
				$('suggest').innerHTML = transport.responseText;
			}
		});
		
		pos = Position.page($(id));
		$('suggest').style.left = pos[0]+'px';
		$('suggest').style.top = pos[1]+24+'px';
	}else{
		$('suggest').innerHTML = '';
	}
}
// ********************************************** Box by zbyszek und Kejo EOF *******************************************//
// ***********************************************   tools ********************************************//
function copyDataToField2 (field_id) {
	$('street_17').value = $F('street2_17');
	$('streetList').innerHTML = '';
}

function usesNewStreet() {
	$('newstreet').value = "1";
	$('streetList').innerHTML = '';
}

function copySelectfieldData(src, dest) {
	$(dest).value = $(src).options[$(src).selectedIndex].text;
}

function copyDataToZipCity(src, dest_zip, dest_city, dest_region) {
	val = $(src).value;
	val = val.split(" ");
	$(dest_zip).value = val[0];
	
	city = "";
	if (val.length > 3) {
		for (u = 1; u < (val.length - 1); u++) {
			if (u != 1) { city = city + " " + val[u]; }
			else { city = val[u]; }
		}
	}
	else {
		city = val[1];
	}
	$(dest_city).value = city;

	if ($(dest_region) != null) {
		region = val[(val.length - 1)];
		region = region.replace(/\(/, "").replace(/\)/, "");
		regionId = RegionToId(region);
		$(dest_region).value = regionId;
	}
}

function RegionToId(region) {
	regionId=0;
	switch (region) {
		case "Rheinland-Pfalz": regionId = 119; break;
		case "Baden-Württemberg": regionId = 120; break;
		case "Nordrhein-Westfalen": regionId = 121; break;
		case "Hessen": regionId = 122; break;
		case "Schleswig-Holstein": regionId = 123; break;
		case "Sachsen-Anhalt": regionId = 124; break;
		case "Bayern": regionId = 125; break;
		case "Thüringen": regionId = 126; break;
		case "Niedersachsen": regionId = 127; break;
		case "Mecklenburg-Vorpommern": regionId = 128; break;
		case "Sachsen": regionId = 129; break;
		case "Brandenburg": regionId = 130; break;
		case "Saarland": regionId = 131; break;
		case "Berlin": regionId = 132; break;
		case "Bremen": regionId = 133; break;
		case "Hamburg": regionId = 134; break;
	}
	return regionId;
}

var allowHide = true;

function showShadowDiv() {
	pageSize = getPageSize();
	if (pageSize[1] > pageSize[3]) { divHeight = pageSize[1]; }
	else { divHeight = pageSize[3]; }
	$("shadowDiv").style.width = pageSize[0]+"px";
	$("shadowDiv").style.height = divHeight+"px";
	$("shadowDiv").style.zIndex = "9";
	$("shadowDiv").style.display = "block";
	hideFlash();
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else {
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
	if (self.innerHeight) {
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	return arrayPageSize;
}

function hideUserProfile(field) {
	if ($("dd__")) {
		Element.hide("dd__");
	}
	if ($("dd__"+field)) {
		Element.hide("dd__"+field);
	}
}

function hideShadowDiv() {
	if (allowHide) {
		$("shadowDiv").style.display = "none";
	}
	showFlash();
}

////////////////////////////////////////////////////////////////
// current mouseposition
////////////////////////////////////////////////////////////////

var docEl = (typeof document.compatMode != "undefined" && document.compatMode != "BackCompat")? "documentElement" : "body";
var MouseX;
var MouseY;

function init_mousemove() {
	if(document.layers) document.captureEvents(Event.MOUSEMOVE);
	document.onmousemove =	dpl_mouse_pos;
}

function dpl_mouse_pos(e) {
	var xPos    =  e? e.pageX : window.event.x;
	var yPos    =  e? e.pageY : window.event.y;

	if (document.all && !document.captureEvents) {
		xPos    += document[docEl].scrollLeft;
		yPos    += document[docEl].scrollTop;
	}

	MouseX = xPos;
	MouseY = yPos;
	if (document.layers) routeEvent(e);
}

init_mousemove();

// ***********************************************  tools EOF  ********************************************//
// ********************************************** tooltip by Hase **********************************************//
function tooltip(d,E,b,i,a){
  d=document;E=d.documentElement;b=d.body;if(!E)return;
  frame_tooltip = $('divToolTip').innerHTML;
  frame_tipbox = $('divToolTipBox').innerHTML;
  for(i=0;a=b.getElementsByTagName("a")[i];i++){
    if(a.title && (a.rel == 'citytooltip' || a.rel == 'cityinfobox')) {
      with(a.t=d.createElement("div")){
        id="tooltip"
        if (a.rel == 'citytooltip') {
        	$('divToolTip').innerHTML = frame_tooltip.replace(/{text}/g, a.title.replace(/\|/g,"<br />"));
	        innerHTML = $('divToolTipMaster').innerHTML;
		}
        else {
        	$('divToolTipBox').innerHTML = frame_tipbox.replace(/{text}/g, a.title.replace(/\|/g,"<br />"));
    	    innerHTML = $('divToolTipBoxMaster').innerHTML;
       }
      }
      a.onmouseover=function(e){
        with(this){title="";onmousemove(e)}
        b.appendChild(this.t)
      }
      a.onmouseout=function(x){
        with(this){title=t.innerHTML.replace(/<br \/>/g,"\|")}
        if(x=d.getElementById("tooltip"))b.removeChild(x)
      }
      a.onmousemove=function(e){
		var pos = Position.cumulativeOffset(this), 
			dim = $(this.t).getDimensions();
		if (navigator.appName.indexOf('Netscape') != -1) { winWidth = self.innerWidth }
		else if (navigator.appName.indexOf('Microsoft') != -1) { winWidth = document.body.clientWidth };
		if (this.t.style.width+(pos[0]+dim['width']) > (winWidth-20)) {
			overflow = winWidth - (this.t.style.width+(pos[0]+dim['width'])) - 30;
			$(this.t).style.left = (pos[0]+overflow)+"px";
		}
		else {
			$(this.t).style.left = (pos[0])+"px";
		}
      	e=e||event;
      	$(this.t).style.top=e.clientY+(E.scrollTop||b.scrollTop)+"px";
      	$(this.t).style.zIndex = '11';
      }
    }
  }
}
function addEvent(O,E,F,x){
  return(x=O.addEventListener)?x(E,F,1):(x=O.attachEvent)?x('on'+E,F):!1
}
addEvent(window,'load',tooltip);
addEvent(window,'load',ClickEvtHandler);
// ********************************************** tooltip by Hase EOF **********************************************//
//********************************************************* User Profile by Thorsten un Hase *********************************************//
var UserProfile = Class.create();
UserProfile.prototype = {
	
	initialize: function(e,ajaxurl) {
		this.divPrefix = 'dd__';
		this.mouseLeaveObserver = false;
		this.delayJoin = 1000;
		this.delayQuit = 500;
		this.ajaxurl = ajaxurl;
		this.timer = null;
		this.MouseX = 0;
		this.MouseY = 0;
		
		this.bFx = this.checkMouseLeave.bindAsEventListener(UserProfile,this,true);
		this.eFx = this.checkMouse.bindAsEventListener(UserProfile,this,true);
		
		this.element = $(e);
		
		if (!this.element) alert("Element "+e+" not found!");
		if (!this.element.id) alert("Element "+e+" has no id!");
		
		Event.observe(this.element,'mouseover',this.eFx);
	},
	
	checkMouse: function (ev,obj,wait) {
		if (wait == true) {
			window.setTimeout(function(){obj.checkMouse(ev,obj,false);}, obj.delayJoin);
		}
		else {
			Position.cumulativeOffset(this.element);
			if (Position.within(this.element,MouseX,MouseY)) {
				if(!$(obj.divPrefix+obj.element.id)) obj.showPreview(obj);
				Event.observe(document.body,'mouseover',obj.bFx);
				obj.setPosition(obj);
				$(obj.divPrefix+obj.element.id).show();
				showShadowDiv();
			}
			else if (this.element.down("img")) {
				if (Position.within(this.element.down("img"),MouseX,MouseY)) {
					if(!$(obj.divPrefix+obj.element.id)) obj.showPreview(obj);
					Event.observe(document.body,'mouseover',obj.bFx);
					obj.setPosition(obj);
					$(obj.divPrefix+obj.element.id).show();
					showShadowDiv();
				}
			}
		}
	},
	
	checkMouseLeave: function (ev,obj,wait) {
		if (Event.element(ev).id != obj.element.id && Event.element(ev).id != (obj.divPrefix+obj.element.id) && !Event.element(ev).descendantOf(obj.divPrefix+obj.element.id) ) {
			if (wait == true) {
				window.setTimeout(function(){obj.checkMouseLeave(ev,obj,false);}, obj.delayQuit);
			}
			else {
				if ($(obj.divPrefix+obj.element.id) !== null) {
					Position.cumulativeOffset($(obj.divPrefix+obj.element.id));
					if (!Position.within($(obj.divPrefix+obj.element.id),MouseX,MouseY)) {
						Event.stopObserving(document.body,'mouseover',obj.bFx);
						$(obj.divPrefix+obj.element.id).hide();
						hideShadowDiv();
					}
				}
			}
		}
	},
	
	setPosition: function(obj) {
		divWidth = 465;
		divHeight = 204;

		var pos = Position.cumulativeOffset(obj.element), 
			dim = $(obj.element).getDimensions();
		
		if (navigator.appName.indexOf('Netscape') != -1) { winWidth = self.innerWidth }
		else if (navigator.appName.indexOf('Microsoft') != -1) { winWidth = document.body.clientWidth };
	
		$(obj.divPrefix+obj.element.id).style.width = divWidth+"px";
		$(obj.divPrefix+obj.element.id).style.height = divHeight+"px";
		if (divWidth+(pos[0]+dim['width']/2) > (winWidth-100)) {
			overflow = winWidth - (divWidth+(pos[0]+dim['width']/2)) - 100;
			$(obj.divPrefix+obj.element.id).style.left = (pos[0]+overflow)+"px";
		}
		else {
			$(obj.divPrefix+obj.element.id).style.left = (pos[0])+"px";
		}
		$(obj.divPrefix+obj.element.id).style.top = ((pos[1]+(dim['height']/2))-50)+"px";
	},
	
	showPreview: function(obj) {
		with (div = document.createElement('div')) {
			id = obj.divPrefix+obj.element.id;
			style.position = "absolute";
			style.overflow = 'auto';
			style.zIndex = '10';
		}
		$(document.body).appendChild(div);
		obj.setPosition(obj);
		new Draggable(div);
		showShadowDiv();
		var url = "/AjaxRequest_cl_321f241f744342db5bd374c4cc54e8703fa55d1b8602_me_070a0f555d4241bc5ae2_userid_"+obj.element.id;
 		new Ajax.Updater(div,url,{method: 'post'});
	}
}
function showUserProfile(user,left,top){
	
		divWidth = 495;
		divHeight = 224;
		if(!$("dd__")){
		with (div = document.createElement('div')) {
			
			id = "dd__";
			style.position = "absolute";
			style.width = divWidth+"px";
			style.height = divHeight+"px";
			style.position = "absolute";
			if(top === undefined)
				style.top = "400px";
			else
				style.top = top+"px";
			if(left === undefined)
				style.left = "650px";
			else
				style.left = left+"px";
			style.overflow = 'auto';
			style.zIndex = '10';
			
		}
		document.body.appendChild($(div));
		
		new Draggable($(div));
		}else{
			Element.show("dd__");
		}
		showShadowDiv();
		var url = "/AjaxRequest_cl_2d26382e5758755f81d874c4bc60ee693f90821d8315_me_070a0f525e3c35dc5ce37e_userId_"+user;
 		new Ajax.Updater($("dd__"),url,{method: 'post'});
	
}
function removeUserProfile(user){
	$("dd__"+user).remove();
	hideShadowDiv();
}
//********************************************************* User Profile by Thorsten un Hase EOF *********************************************//
//********************************************************* HomePage by Zbyszek ***************************************************************//
function homepage(link,scrolling,log,id){
	if (log == true && id != null) {
		new Ajax.Request(
			'/AjaxRequest_cl_21171a3d7e4849b25ae28a_me_040e2527684d4bba53',{
				method:'post',
				parameters:$H({mode:'bannerlog',cmd:'click',bid:id}).toQueryString()
			}
		);
	}
	if (scrolling == null)
		scrolling = "no";
		
	var objBody = document.getElementsByTagName("body").item(0);
		objBody.setAttribute('id','bodyoverlay');
	
		var objOverlay = document.createElement("div");
		objOverlay.setAttribute('id','pageoverlay');
		objOverlay.style.display = 'none';
		objBody.appendChild(objOverlay);
		
		var objPage = document.createElement("div");
		objPage.setAttribute('id','pagebox');
		objBody.appendChild(objPage);
	
		var objOuterFrameContainer = document.createElement("div");
		objOuterFrameContainer.setAttribute('id','outerFrameContainer');
		objOuterFrameContainer.style.display = 'none';
		objPage.appendChild(objOuterFrameContainer);
		
		var objTopHandler = document.createElement("div");
			objTopHandler.setAttribute('id','topHandler');
			objTopHandler.setAttribute('class','topHandler');
			objOuterFrameContainer.appendChild(objTopHandler);
		
		var objRedirectButton = new Image();	
			objRedirectButton.src = "image/Default/max.gif";
			objRedirectButton.onclick = function(){
				Element.hide('overlay');
				Element.hide('outerFrameContainer');
				myCallBackOnFinish();
				window.open(link,"company");
			};
			objTopHandler.appendChild(objRedirectButton);
				
		var objCloseButton = new Image();
			objCloseButton.src = "image/Default/button-close.gif";
			objCloseButton.onclick = function(){
				Effect.Fade('pageoverlay', { duration: 1.0});
				Effect.Fade('outerFrameContainer', { duration: 1.0, afterFinish: myCallBackOnFinish});
			};
			objTopHandler.appendChild(objCloseButton);
			
		var objFrame = document.createElement("iframe");
			objFrame.setAttribute('src',link);
			objFrame.setAttribute('frameborder','0');
			objFrame.setAttribute('width','800');
			objFrame.setAttribute('height','630');
			objFrame.setAttribute('scrolling',scrolling);
			objOuterFrameContainer.appendChild(objFrame);
		var arrayPageSize = getPageSize();
		Element.setHeight('pageoverlay', arrayPageSize[1]);
		new Effect.Appear('pageoverlay', { duration: 0.2, from: 0.0, to: 0.8});
		new Effect.Appear('outerFrameContainer', { duration: 2.0});
};
function myCallBackOnFinish(obj){
	
	var element = document.getElementById("bodyoverlay");
		element.removeChild($("pageoverlay"));
		element.removeChild($("pagebox"));
}		

function showHomePage(id) {
	new Ajax.Request(
		'/AjaxRequest_cl_240e2527684d_me_040e2527684d64b755e882f3b03ae8702a8a',{
			method:'post',
			parameters:$H({mode:'bannerlog',cmd:'click',bid:id}).toQueryString()
		}
	);
}
//***************************************************** homepage by Zbyszek EOF **********************************************///
function updateSearchForm(formId,cityName,zipName,cityId){
	
	
    if(zipName !== undefined && zipName !== null)
	 $(formId).zip.value = zipName;
	 
	if(cityName !== undefined && cityName !== null)
	 $(formId).city.value = cityName;
	 
	if(cityId !== undefined && cityId !== null)
	 $(formId).cityid.value = cityId;
	var m_form = $(formId); 

	setTimeout(function(){m_form.submit()}, 1000, this);
}

function testPassword(passwd) {
	var intScore   = 0
	var strVerdict = "weak"
	var strLog     = ""
	
	// PASSWORD LENGTH
	if (passwd.length<5)                         // length 4 or less
	{
		intScore = (intScore+3)
	}
	else if (passwd.length>4 && passwd.length<8) // length between 5 and 7
	{
		intScore = (intScore+18)
	}
	else if (passwd.length>7 && passwd.length<16)// length between 8 and 15
	{
		intScore = (intScore+20)
	}
	else if (passwd.length>15)                    // length 16 or more
	{
		intScore = (intScore+20)
	}
	
	if (passwd.match(/[a-z]/))                              // [verified] at least one lower case letter
	{
		intScore = (intScore+1)
	}
	
	if (passwd.match(/[A-Z]/))                              // [verified] at least one upper case letter
	{
		intScore = (intScore+5)
	}
	
	// NUMBERS
	if (passwd.match(/\d+/))                                 // [verified] at least one number
	{
		intScore = (intScore+5)
	}
	
	if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
	{
		intScore = (intScore+5)
	}
	
	
	// SPECIAL CHARs
	if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
	{
		intScore = (intScore+8)
	}
	
								 // [verified] at least two special characters
	if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
	{
		intScore = (intScore+5)
	}

	// COMBOS
	if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) 
	{
	// both letters and numbers       
		intScore = (intScore+2)
	}

	if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) // [verified] both letters and numbers
	{
		intScore = (intScore+2)
	}

	// [verified] letters, numbers, and special characters (Subirana)
	if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
	{
		intScore = (intScore+2)
	}
	
	return intScore;
}

function runPassword(strPassword, strFieldID) 
{
	// Check password
	intScore = testPassword(strPassword);
	
	// Set new width
	if(intScore < 16)
	{
	    strColor = "red";
		strText = "Sehr unsicher!";
		nRound = 10;
	}
	else if (intScore > 15 && intScore < 25)
	{
	    strText = "Unsicher";
		strColor = "orange";
		nRound = 30;
	}
	else if (intScore > 24 && intScore < 35)
	{
	    strText = "Mittel";
		strColor = "#ffd801";
		nRound = 50;
	}
	else if (intScore > 34 && intScore < 45)
	{
	    strText = "Sicher";
		strColor = "green";
		nRound = 80;
	}
	else
	{
		strText = "Sehr sicher!";
		strColor = "#3bce08";
		nRound = 100;
	}
		
	// Get controls
	var ctlBar = $(strFieldID + "_bar"); 
	var ctlText = $(strFieldID + "_text");
	if (!ctlBar || !ctlText) 
		return;
		
	ctlBar.style.width =  "80px";
	ctlBar.style.backgroundColor = strColor;
	ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText +"</span>";
}
function ajax(className,methodName,bindToForm,divToUpdate,objectParams,jsonParams,adittionalGet){
	
	var url = "/AjaxRequest_cl_"+className+"_me_"+methodName;
	if(adittionalGet !== null && adittionalGet !== undefined)
		url += "_"+adittionalGet;
	if(jsonParams !== null && jsonParams !== undefined){
		var pars = eval(jsonParams);
		//alert("1 "+pars)
	}
	else if(objectParams !== null && objectParams !== undefined){
		var pars = objectParams;
	}
	else if(bindToForm !== null && bindToForm !== undefined){
		var pars = $(bindToForm).serialize();
	}	
	else
	var pars = '';	
	var myAjax = new Ajax.Request(
		url, {method: 'post',
		asynchronous: false,
		parameters: pars,
		onLoading: function(e){
		},
		onComplete: function(e){
			$(divToUpdate).innerHTML = e.responseText;
		}
	});
}

function profileSAcreate() {
	with (div = document.createElement('div')) {
		id = "psa";
		style.zIndex = "99";
		style.position = "absolute";
		style.left = "0px";
		style.top = "0px";
		style.width = "400px";
		style.backgroundColor = "#ffffff";
		style.border = "1px solid #000000";
		style.display = "none";
	}
	document.body.appendChild($(div));
}

function profileSA(userId, cls, meth){
	if ($('psa') == null) {
		profileSAcreate();
	}
	new Ajax.Request("/AjaxRequest_cl_"+cls+"_me_"+meth+"_userid_"+userId, {
		onSuccess : function(resp) {
			Effect.Appear($("psa"),{duration:0.3});
			$("psa").style.position = "absolute";
			$("psa").style.left = "200px";
			$("psa").style.top = (MouseY-100)+"px";
			$("psa").innerHTML = resp.responseText;
			$("psa").style.zIndex = "11";
		},
		onFailure : function(resp) {
		},
		parameters : "userId="+userId
	});
}
		
function profileSAsetterBlock(cls, meth, editUser){
		var sendText = "";
		if ($('my_text') != null) { sendText = $F('my_text'); }
		new Ajax.Request("/AjaxRequest_cl_"+cls+"_me_"+meth+"_userid_"+editUser, {
		method:'post',
		parameters:$H({	editUser: editUser, text: sendText}).toQueryString(),
						onComplete:function(e){Effect.Fade('psa',{duration:0.3});}})
	}
	
function profileSAsetterUnBlock(cls, meth, editUser){
		new Ajax.Request("/AjaxRequest_cl_"+cls+"_me_"+meth+"_userid_"+editUser, {
		method:'post',
		parameters:$H({	editUser: editUser}).toQueryString(),
						onComplete:function(e){Effect.Fade('psa',{duration:0.3});}})
	}
	
function handleAdressbook(cl, me, id, type, field, design) {
	new Ajax.Request("/AjaxRequest_cl_"+cl+"_me_"+me, {
		method:'post',
		onSuccess : function(resp) {
			text = resp.responseText;
			if (text == "forget") {
				switch (design) {
					case 2:
						fieldText = "Firma nicht merken";
					break;
					default:
						fieldText = "<img src=\"/image/Default/adress_delete.jpg\" alt=\"Aus dem Adressbuch löschen\"  style=\"border:0px;clear: none;float:left; margin-right: 4px;\" /><span style=\"float:left;\">Aus dem Adressbuch l&ouml;schen</span>";
					break;
				}
				$(field).innerHTML = fieldText;
			}
			else {
				switch (design) {
					case 2:
						fieldText = "Firma merken";
					break;
					default:
						fieldText = "<img src=\"/image/Default/adress_add.jpg\" alt=\"Zum Adressbuch hinzufügen\" style=\"border:0px;clear: none;float:left;margin-right: 4px;\" /><span style=\"float:left;\">Zum Adressbuch hinzuf&uuml;gen</span>";
					break;
				}
				$(field).innerHTML = fieldText;
			}
		},
		parameters:"id="+id+"&type="+type
	});
}

function forceLogin(redirectUrl,loginMessage) {
	$("_login__redirect").value = encodeURIComponent(redirectUrl);
	$("_login__data").value = loginMessage;
	$("_login").submit();
}

function forceActivationCommunity(redirectUrl) {
	$("_activate_community_redirect").value = encodeURIComponent(redirectUrl);
	$("_activate_community").submit();
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}
//******************************* banner updater******************************//
function rewriteBanner(nr){
	Event.observe(window,'load',function(){
			
			// check if wallpaper banner 
			try {
				if(qmcity24wp) {
					setBannerWallpaper();
				}  
				}catch(error) {}
		
				doRewriteBanner(nr);
		})
}

function doRewriteBanner(nr) {
	$('banner'+nr).innerHTML = $('bloader'+nr).innerHTML
	while ($('bloader'+nr).firstChild) {
				$('bloader'+nr).removeChild($('bloader'+nr).firstChild);
	}
}

// *** Tooltip Object ***
var Tooltip = Class.create();
Tooltip.prototype = {
	initialize: function(el, options) {
		this.el = $(el);
		this.initialized = false;
		this.setOptions(options);
		
		// Event handlers
		this.showEvent = this.show.bindAsEventListener(this);
		this.hideEvent = this.hide.bindAsEventListener(this);
		this.updateEvent = this.update.bindAsEventListener(this);
		Event.observe(this.el, "mouseover", this.showEvent );
		Event.observe(this.el, "mouseout", this.hideEvent );
		
		// Removing title from DOM element to avoid showing it
		this.content = this.el.title;
		this.el.title = "";

		// If descendant elements has 'alt' attribute defined, clear it
		this.el.descendants().each(function(el){
			if(Element.readAttribute(el, 'alt'))
				el.alt = "";
		});
	},
	setOptions: function(options) {
		this.options = {
			backgroundColor: 'white', // Default background color
			borderColor: '#666', // Default border color
			textColor: '', // Default text color (use CSS value)
			textShadowColor: '', // Default text shadow color (use CSS value)
			maxWidth: 500,	// Default tooltip width
			align: "left", // Default align
			delay: 100, // Default delay before tooltip appears in ms
			mouseFollow: false, // Tooltips follows the mouse moving
			opacity: 1, // Default tooltips opacity
			appearDuration: 0.1, // Default appear duration in sec
			hideDuration: 0.1 // Default disappear duration in sec
		};
		Object.extend(this.options, options || {});
	},
	show: function(e) {
		this.xCord = Event.pointerX(e);
		this.yCord = Event.pointerY(e);
		if(!this.initialized)
			this.timeout = window.setTimeout(this.appear.bind(this), this.options.delay);
	},
	hide: function(e) {
		if(this.initialized) {
			this.appearingFX.cancel();
			if(this.options.mouseFollow)
				Event.stopObserving(this.el, "mousemove", this.updateEvent);
			new Effect.Fade(this.tooltip, {duration: this.options.hideDuration, afterFinish: function() { Element.remove(this.tooltip) }.bind(this) });
		}
		this._clearTimeout(this.timeout);
		
		this.initialized = false;
	},
	update: function(e){
		this.xCord = Event.pointerX(e);
		this.yCord = Event.pointerY(e);
		this.setup();
	},
	appear: function() {
		// Building tooltip container
		this.tooltip = Builder.node("div", {className: "tooltip", style: "display: none;" }, [
			Builder.node("div", {className:"xtop"}, [
				Builder.node("div", {className:"xb1", style:"background-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb2", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb3", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb4", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"})
			]),
			this.content_div = Builder.node("div", {className: "xboxcontent", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ((this.options.textColor != '') ? "; color:" + this.options.textColor : "") + ((this.options.textShadowColor != '') ? "; text-shadow:2px 2px 0" + this.options.textShadowColor + ";" : "")}),
			Builder.node("div", {className:"xbottom"}, [
				Builder.node("div", {className:"xb4", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb3", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb2", style: "background-color:" + this.options.backgroundColor + "; border-color:" + this.options.borderColor + ";"}),
				Builder.node("div", {className:"xb1", style:"background-color:" + this.options.borderColor + ";"})
			]),
		]);
		
		this.content_div.innerHTML = this.content;
		document.body.insertBefore(this.tooltip, document.body.childNodes[0]);
		
		Element.extend(this.tooltip); // IE needs element to be manually extended
		this.options.width = this.tooltip.getWidth();
		this.tooltip.style.width = this.options.width + 'px'; // IE7 needs width to be defined
		
		this.setup();
		
		if(this.options.mouseFollow)
			Event.observe(this.el, "mousemove", this.updateEvent);
			
		this.initialized = true;
		this.appearingFX = new Effect.Appear(this.tooltip, {duration: this.options.appearDuration, to: this.options.opacity });
	},
	setup: function(){
		// If content width is more then allowed max width, set width to max
		if(this.options.width > this.options.maxWidth) {
			this.options.width = this.options.maxWidth;
			this.tooltip.style.width = this.options.width + 'px';
		}
			
		// Tooltip doesn't fit the current document dimensions
		if(this.xCord + this.options.width >= Element.getWidth(document.body)) {
			this.options.align = "right";
			this.xCord = this.xCord - this.options.width + 20;
		}
		
		this.tooltip.style.left = this.xCord - 7 + "px";
		this.tooltip.style.top = this.yCord + 12 + "px";
	},
	
	_clearTimeout: function(timer) {
		clearTimeout(timer);
		clearInterval(timer);
		return null;
	}
};

//Screen collection (ruf)
Screen = Class.create({

	initialize: function() {
		this.fxScroll = null;
	},
	
	// Dim Screen
	dim: function() {
	
		this.fxScroll = function() {
			if (!$('__screen_dim')) return; 
			// move div			
			var sco = document.viewport.getScrollOffsets();
			var dim = document.viewport.getDimensions();
			if ($('__screen_dim')) $('__screen_dim').setStyle({top:sco.top+'px',left:sco.left+'px',width:dim.width+'px', height:dim.height+'px'});
		}
		
		Event.observe(window,'scroll', this.fxScroll);
		hideSelectBoxes();
		hideFlash();
		var so = document.viewport.getScrollOffsets();
		var screen = getPageSize();
		var elem =new Element('div',{'id':'__screen_dim','style':'width:'+screen[0]+'px; height:'+screen[1]+'px; display:none; position:absolute; left:0px; top:0px; display:none; z-index:50; background-color: #333333'});
		$(document.body).insert({top: elem});
		new Effect.Appear('__screen_dim', { duration: 0.5, from: 0, to: 0.3});
	},
	
	undim: function() {
		Event.stopObserving(window,'scroll',this.fxScroll)
		new Effect.Fade('__screen_dim', { duration: 0.2, afterFinish: function() {$('__screen_dim').remove()}});
		showSelectBoxes();
		showFlash();
	}
	
});


// grey out screen, ruf
MessageModal = Class.create({
   
  initialize: function(message,buttons,fx,insertElem,darkScreen ) {
  	this.fxBtnCancel = function(event) {Event.stopObserving(window,'scroll',this.fxScroll); this.removeMessage(); };
  	this.fxBtnOk = function(event) { 
  		if(this.fx) if (this.fx() == false) return;
		this.removeMessage();
  		Event.stopObserving(window,'scroll',this.fxScroll) };
  	this.fx = null;
  	this.fxScroll = null;
  	this.darkScreen = true;
  	if (darkScreen == false) this.darkScreen = false;
  	//direct
  	this.show(message,buttons,fx,insertElem,darkScreen);
  	
  },
  
  show: function(message,buttons,fx,insertElem,darkScreen) {
		// hide special elements
		var old = false; 
		
		if ($('modal_grey')) {
			this._deleteBox();
			old = true; 			
		}
		
		hideSelectBoxes();
		this._hideElements();

		//save reference function 
		if (fx) this.fx = fx.ok;
		
		// Create Event
		this.fxScroll = function() {
			// move div
			var sco = document.viewport.getScrollOffsets();
			var dim = document.viewport.getDimensions();
			if ($('modal_grey')) $('modal_grey').setStyle({top:sco.top+'px',left:sco.left+'px',width:dim.width+'px', height:dim.height+'px'});
			
			var elem = $('msgBox');
			var top = Math.round(((document.viewport.getHeight() - elem.getHeight()) / 2) + sco[1]).toString(10);
			var left = Math.round(((document.viewport.getWidth() - elem.getWidth()) / 2) + sco[0]).toString(10);
			elem.setStyle({left: left+'px', top: top+'px'});
		}
		Event.observe(window,'scroll', this.fxScroll);
		
		if (this.darkScreen) {
			var elem =new Element('div',{'id':'modal_grey','style':'position:absolute; left:0px; top:0px; display:none; z-index:50; background-color: #333333'});
			$(document.body).insert({top: elem});
		}
		
		switch (buttons) {
			case 'ok':
				message = message + '<div style="display:block; text-align:center"><input id="btnModOk" type="button" value="OK"></div>';
				break;
			case 'okcancel':
				message = message + '<div style="display:block; text-align:center"><input id="btnModOk" type="button" value="OK"> <input id="btnModCancel" type="button" value="Abbrechen"></div>';
		}
		
		iElem = $(insertElem);
		if (!iElem) iElem = document.body;
		var x = iElem.insert({top: new Element('div',{id:'msgBox',style:'z-index:51; visbility:hidden; padding: 10px; position:absolute; opacity: 1.0; background-color:white; border: 2px solid gray'})}).down().update(message);
		
		if ($('btnModOk')) $('btnModOk').observe('click', this.fxBtnOk.bindAsEventListener(this));
		if ($('btnModCancel')) $('btnModCancel').observe('click', this.fxBtnCancel.bindAsEventListener(this));
		
		var scroll = document.viewport.getScrollOffsets();
		var top = Math.round(((document.viewport.getHeight() - x.getHeight()) / 2) + scroll[1]).toString(10);
		var left = Math.round(((document.viewport.getWidth() - x.getWidth()) / 2) + scroll[0]).toString(10);
		x.setStyle({left: left+'px', top: top+'px'});
		
		if (this.darkScreen) {
			// stretch overlay to fill page and fade in
			var so = document.viewport.getScrollOffsets();
			var screen = getPageSize();
			Element.setWidth('modal_grey',screen[0]);
			Element.setHeight('modal_grey',screen[1]+so.top);
		}
		$('msgBox').visible();
				
		if (!old && this.darkScreen) new Effect.Appear('modal_grey', { duration: 0, from: 0, to: 0.8});
	},

	removeMessage: function() {

		if (!$('modal_grey') && !$('msgBox')) return;
		if ($('modal_grey')) {
			showSelectBoxes();
			this._showElements();
			//$('modal_grey').remove();
			//$('msgBox').remove()
			new Effect.Fade('modal_grey', { duration: 0.2, afterFinish: function() {$('modal_grey').remove();$('msgBox').remove() }});
		} else {
			new Effect.Fade('msgBox', { duration: 0.8, afterFinish: function() { $('msgBox').remove();}});
		}
	},
	
	_deleteBox: function() {
		if(this.fxScroll) { 
			Event.stop(this.fxScroll);
			this.fxScroll = null;
		}
		if ($('msgBox')) $('msgBox').remove();
	},
	
	updateMessage: function(message) {
		if (!$('msgBox')) return;
		$('msgBox').update(message);
	},
	
	_hideElements: function() {
		var flashObjects = document.getElementsByTagName("object");
		for (i = 0; i < flashObjects.length; i++) {
			flashObjects[i].style.visibility = "hidden";
		}
		
		var flashEmbeds = document.getElementsByTagName("embed");
		for (i = 0; i < flashEmbeds.length; i++) {
			flashEmbeds[i].style.visibility = "hidden";
		}
	},
	
	_showElements: function() {
		var flashObjects = document.getElementsByTagName("object");
		for (i = 0; i < flashObjects.length; i++) {
			flashObjects[i].style.visibility = "visible";
		}
		
		var flashEmbeds = document.getElementsByTagName("embed");
		for (i = 0; i < flashEmbeds.length; i++) {
			flashEmbeds[i].style.visibility = "visible";
		}
	}
	
});

/*
function setBannerWallpaper() {
	$('top').setStyle({overflow:'visible'}).down('li.right').setStyle({marginRight:'-171px', overflow:'visible', position: 'relative'});
	$('banner4458').setStyle({overflow:'visible',position:'relative','marginTop':'-12px'});
}
*/
function setBannerWallpaper() {
	$('top').setStyle({overflow:'visible'}).down('li.right').setStyle({marginRight:'-12px', overflow:'visible', position: 'relative'});
	$('banner4458').setStyle({overflow:'visible',position:'relative','marginTop':'-102px'});
}

