(function(B){B.dimensions={version:"1.2"};B.each(["Height","Width"],function(D,C){B.fn["inner"+C]=function(){if(!this[0]){return }var F=C=="Height"?"Top":"Left",E=C=="Height"?"Bottom":"Right";return this.is(":visible")?this[0]["client"+C]:A(this,C.toLowerCase())+A(this,"padding"+F)+A(this,"padding"+E)};B.fn["outer"+C]=function(F){if(!this[0]){return }var H=C=="Height"?"Top":"Left",E=C=="Height"?"Bottom":"Right";F=B.extend({margin:false},F||{});var G=this.is(":visible")?this[0]["offset"+C]:A(this,C.toLowerCase())+A(this,"border"+H+"Width")+A(this,"border"+E+"Width")+A(this,"padding"+H)+A(this,"padding"+E);return G+(F.margin?(A(this,"margin"+H)+A(this,"margin"+E)):0)}});B.each(["Left","Top"],function(D,C){B.fn["scroll"+C]=function(E){if(!this[0]){return }return E!=undefined?this.each(function(){this==window||this==document?window.scrollTo(C=="Left"?E:B(window)["scrollLeft"](),C=="Top"?E:B(window)["scrollTop"]()):this["scroll"+C]=E}):this[0]==window||this[0]==document?self[(C=="Left"?"pageXOffset":"pageYOffset")]||B.boxModel&&document.documentElement["scroll"+C]||document.body["scroll"+C]:this[0]["scroll"+C]}});B.fn.extend({position:function(){var H=0,G=0,F=this[0],I,C,E,D;if(F){E=this.offsetParent();I=this.offset();C=E.offset();I.top-=A(F,"marginTop");I.left-=A(F,"marginLeft");C.top+=A(E,"borderTopWidth");C.left+=A(E,"borderLeftWidth");D={top:I.top-C.top,left:I.left-C.left}}return D},offsetParent:function(){var C=this[0].offsetParent;while(C&&(!/^body|html$/i.test(C.tagName)&&B.css(C,"position")=="static")){C=C.offsetParent}return B(C)}});function A(C,D){return parseInt(B.curCSS(C.jquery?C[0]:C,D,true))||0}})(jQuery);
$.fn.ajaxSubmit=function(options){if(typeof options=='function')
options={success:options};options=$.extend({url:this.attr('action')||window.location,type:this.attr('method')||'GET'},options||{});var a=this.formToArray(options.semantic);if(options.beforeSubmit&&options.beforeSubmit(a,this,options)===false)return this;var veto={};$.event.trigger('form.submit.validate',[a,this,options,veto]);if(veto.veto)
return this;var q=$.param(a);if(options.type.toUpperCase()=='GET'){options.url+=(options.url.indexOf('?')>=0?'&':'?')+q;options.data=null;}
else
options.data=q;var $form=this,callbacks=[];if(options.resetForm)callbacks.push(function(){$form.resetForm();});if(options.clearForm)callbacks.push(function(){$form.clearForm();});if(!options.dataType&&options.target){var oldSuccess=options.success;callbacks.push(function(data,status){$(options.target).attr("innerHTML",data).evalScripts().each(oldSuccess,[data,status]);});}
else if(options.success)
callbacks.push(options.success);options.success=function(data,status){for(var i=0,max=callbacks.length;i<max;i++)
callbacks[i](data,status);};var files=$('input:file',this).fieldValue();var found=false;for(var j=0;j<files.length;j++)
if(files[j])
found=true;if(options.iframe||found)
fileUpload();else
$.ajax(options);$.event.trigger('form.submit.notify',[this,options]);return this;function fileUpload(){var form=$form[0];var opts=$.extend({},$.ajaxSettings,options);var id='jqFormIO'+$.fn.ajaxSubmit.counter++;var $io=$('<iframe id="'+id+'" name="'+id+'" />');var io=$io[0];var op8=$.browser.opera&&window.opera.version()<9;if($.browser.msie||op8)io.src='javascript:false;document.write("");';$io.css({position:'absolute',top:'-1000px',left:'-1000px'});var xhr={responseText:null,responseXML:null,status:0,statusText:'n/a',getAllResponseHeaders:function(){},getResponseHeader:function(){},setRequestHeader:function(){}};var g=opts.global;if(g&&!$.active++)$.event.trigger("ajaxStart");if(g)$.event.trigger("ajaxSend",[xhr,opts]);var cbInvoked=0;var timedOut=0;setTimeout(function(){$io.appendTo('body');io.attachEvent?io.attachEvent('onload',cb):io.addEventListener('load',cb,false);var encAttr=form.encoding?'encoding':'enctype';var t=$form.attr('target');$form.attr({target:id,method:'POST',encAttr:'multipart/form-data',action:opts.url});if(opts.timeout)
setTimeout(function(){timedOut=true;cb();},opts.timeout);form.submit();$form.attr('target',t);},10);function cb(){if(cbInvoked++)return;io.detachEvent?io.detachEvent('onload',cb):io.removeEventListener('load',cb,false);var ok=true;try{if(timedOut)throw'timeout';var data,doc;doc=io.contentWindow?io.contentWindow.document:io.contentDocument?io.contentDocument:io.document;xhr.responseText=doc.body?doc.body.innerHTML:null;xhr.responseXML=doc.XMLDocument?doc.XMLDocument:doc;if(opts.dataType=='json'||opts.dataType=='script'){var ta=doc.getElementsByTagName('textarea')[0];data=ta?ta.value:xhr.responseText;if(opts.dataType=='json')
eval("data = "+data);else
$.globalEval(data);}
else if(opts.dataType=='xml'){data=xhr.responseXML;if(!data&&xhr.responseText!=null)
data=toXml(xhr.responseText);}
else{data=xhr.responseText;}}
catch(e){ok=false;$.handleError(opts,xhr,'error',e);}
if(ok){opts.success(data,'success');if(g)$.event.trigger("ajaxSuccess",[xhr,opts]);}
if(g)$.event.trigger("ajaxComplete",[xhr,opts]);if(g&&!--$.active)$.event.trigger("ajaxStop");if(opts.complete)opts.complete(xhr,ok?'success':'error');setTimeout(function(){$io.remove();xhr.responseXML=null;},100);};function toXml(s,doc){if(window.ActiveXObject){doc=new ActiveXObject('Microsoft.XMLDOM');doc.async='false';doc.loadXML(s);}
else
doc=(new DOMParser()).parseFromString(s,'text/xml');return(doc&&doc.documentElement&&doc.documentElement.tagName!='parsererror')?doc:null;};};};$.fn.ajaxSubmit.counter=0;$.fn.ajaxForm=function(options){return this.ajaxFormUnbind().submit(submitHandler).each(function(){this.formPluginId=$.fn.ajaxForm.counter++;$.fn.ajaxForm.optionHash[this.formPluginId]=options;$(":submit,input:image",this).click(clickHandler);});};$.fn.ajaxForm.counter=1;$.fn.ajaxForm.optionHash={};function clickHandler(e){var $form=this.form;$form.clk=this;if(this.type=='image'){if(e.offsetX!=undefined){$form.clk_x=e.offsetX;$form.clk_y=e.offsetY;}else if(typeof $.fn.offset=='function'){var offset=$(this).offset();$form.clk_x=e.pageX-offset.left;$form.clk_y=e.pageY-offset.top;}else{$form.clk_x=e.pageX-this.offsetLeft;$form.clk_y=e.pageY-this.offsetTop;}}
setTimeout(function(){$form.clk=$form.clk_x=$form.clk_y=null;},10);};function submitHandler(){var id=this.formPluginId;var options=$.fn.ajaxForm.optionHash[id];$(this).ajaxSubmit(options);return false;};$.fn.ajaxFormUnbind=function(){this.unbind('submit',submitHandler);return this.each(function(){$(":submit,input:image",this).unbind('click',clickHandler);});};$.fn.formToArray=function(semantic){var a=[];if(this.length==0)return a;var form=this[0];var els=semantic?form.getElementsByTagName('*'):form.elements;if(!els)return a;for(var i=0,max=els.length;i<max;i++){var el=els[i];var n=el.name;if(!n)continue;if(semantic&&form.clk&&el.type=="image"){if(!el.disabled&&form.clk==el)
a.push({name:n+'.x',value:form.clk_x},{name:n+'.y',value:form.clk_y});continue;}
var v=$.fieldValue(el,true);if(v&&v.constructor==Array){for(var j=0,jmax=v.length;j<jmax;j++)
a.push({name:n,value:v[j]});}
else if(v!==null&&typeof v!='undefined')
a.push({name:n,value:v});}
if(!semantic&&form.clk){var inputs=form.getElementsByTagName("input");for(var i=0,max=inputs.length;i<max;i++){var input=inputs[i];var n=input.name;if(n&&!input.disabled&&input.type=="image"&&form.clk==input)
a.push({name:n+'.x',value:form.clk_x},{name:n+'.y',value:form.clk_y});}}
return a;};$.fn.formSerialize=function(semantic){return $.param(this.formToArray(semantic));};$.fn.fieldSerialize=function(successful){var a=[];this.each(function(){var n=this.name;if(!n)return;var v=$.fieldValue(this,successful);if(v&&v.constructor==Array){for(var i=0,max=v.length;i<max;i++)
a.push({name:n,value:v[i]});}
else if(v!==null&&typeof v!='undefined')
a.push({name:this.name,value:v});});return $.param(a);};$.fn.fieldValue=function(successful){for(var val=[],i=0,max=this.length;i<max;i++){var el=this[i];var v=$.fieldValue(el,successful);if(v===null||typeof v=='undefined'||(v.constructor==Array&&!v.length))
continue;v.constructor==Array?$.merge(val,v):val.push(v);}
return val;};$.fieldValue=function(el,successful){var n=el.name,t=el.type,tag=el.tagName.toLowerCase();if(typeof successful=='undefined')successful=true;if(successful&&(!n||el.disabled||t=='reset'||t=='button'||(t=='checkbox'||t=='radio')&&!el.checked||(t=='submit'||t=='image')&&el.form&&el.form.clk!=el||tag=='select'&&el.selectedIndex==-1))
return null;if(tag=='select'){var index=el.selectedIndex;if(index<0)return null;var a=[],ops=el.options;var one=(t=='select-one');var max=(one?index+1:ops.length);for(var i=(one?index:0);i<max;i++){var op=ops[i];if(op.selected){var v=$.browser.msie&&!(op.attributes['value'].specified)?op.text:op.value;if(one)return v;a.push(v);}}
return a;}
return el.value;};$.fn.clearForm=function(){return this.each(function(){$('input,select,textarea',this).clearFields();});};$.fn.clearFields=$.fn.clearInputs=function(){return this.each(function(){var t=this.type,tag=this.tagName.toLowerCase();if(t=='text'||t=='password'||tag=='textarea')
this.value='';else if(t=='checkbox'||t=='radio')
this.checked=false;else if(tag=='select')
this.selectedIndex=-1;});};$.fn.resetForm=function(){return this.each(function(){if(typeof this.reset=='function'||(typeof this.reset=='object'&&!this.reset.nodeType))
this.reset();});};/**
	extends jQuery to create inplace editing-objects
	- by johannes.

	parameter:
	- type: 'input' (standard) || 'textarea'
	- onBlur: function!
	- input_min_width
	- input_max_width
	- area_min_width
	- area_max_width
	- area_min_height
	- area_max_height
	- input_class: name of the css-class for inputs
	- area_class: name of the css-class for textareas
*/
jQuery.fn.extend({
	yCreateInplace: function(parameter) {
		// init
		input_min_width = 200;
		input_max_width = 400;
		area_min_width = 200;
		area_max_width = 400;
		area_min_height = 100;
		area_max_height = 200;
		input_class = 'inplace_input';
		area_class = 'inplace_area';
		type = 'input'; // input || textarea

		// if parameter given
		if (parameter) {
			if (parameter.input_min_width) input_min_width = parameter.input_min_width;
			if (parameter.input_max_width) input_max_width = parameter.input_max_width;
			if (parameter.area_min_width) area_min_width = parameter.area_min_width;
			if (parameter.area_max_width) area_max_width = parameter.area_max_width;
			if (parameter.area_min_height) area_min_height = parameter.area_min_height;
			if (parameter.area_max_height) area_max_height = parameter.area_max_height;
			if (parameter.input_class) input_class = parameter.input_class;
			if (parameter.area_class) area_class = parameter.area_class;
			if (parameter.type) type = parameter.type;
		}

		inputId = 'inplace_' + $(this).attr('id');
		spanId = 'inpl_span_' + $(this).attr('id');

		// highlight on mouseover
		$(this).mouseover(function(){
			$(this).addClass('inplace_over')
		});
		$(this).mouseout(function(){
			$(this).removeClass('inplace_over')
		});

		$(this).click(function(){
			html = '';
			html = $(this).html();
			// converting br to newlines..
			html = br2nl(html);

			// width and height
			wth = $(this).width();
			hgt = $(this).height();
			wth+=10;

			if (type == 'textarea') {
				hgt+=20;
				if (hgt < area_min_height) hgt = area_min_height;
				else if (hgt > area_max_height) hgt = area_max_height;
				if (wth < area_min_width) wth = area_min_width;
				else if (wth > area_max_width) wth = area_max_width;
			}
			else {
				if (wth < input_min_width) wth = input_min_width;
				else if (wth > input_max_width) wth = input_max_width;
			}

			$(this).hide();

			if (type == 'textarea') {
				// "span" is needed due to an ie-bug..
				$(this).after("<span id='"+spanId+"'><textarea class='"+area_class+"' id='"+inputId+"'>"+html+"</textarea></span>");
			}
			else {
				$(this).after("<span id='"+spanId+"'><input type='text' class='"+input_class+"' id='"+inputId+"' value='"+html+"'/></span>");
			}
			input = $('#'+inputId);
			input.css({width: wth, height: hgt});
			input.focus();

			cont = $(this);

			input.blur(function() {
				html = '';
				html = $(this).val();
				html = nl2br(html);
				cont.html(html);
				cont.show();

				// call function if given
				if (parameter.onBlur) parameter.onBlur(cont);

				$("#"+spanId).remove();
			});
		});
	}
});

jQuery.fn.extend({
	tooltip: function(position,tip) {
		var top = position.top;
		var left = position.left;
		top += 30;
		$('body').append("<div id='tooltip'>"+tip+"</div>");
		$('#tooltip').css({top: top, left: left});
	}
});

jQuery.fn.extend({

	initInput: function(options) {
		if (options.left_string) left_string = options.left_string;
		if (options.is_virgin) $(this).attr('virgin',options.is_virgin);
		else $(this).attr('virgin','1');

		spanid = randomString();
		$(this).attr('spanid',spanid);

		me = $(this);

		// set value
		$(this).val(options.value);

		$(this).focus(function() {
			//$(this).css({color: '#000'});
			if (options.on_focus) options.on_focus();
			if ($(this).attr('virgin') == '1') {
				$(this).val('');
			}
		});

		$(this).keyup(function() {
			$(this).attr('virgin','0');
		});

		$(this).blur(function() {
			//$(this).css({color: '#848484'})
			if ($(this).val() == '') {
				$(this).val(options.value);
				$(this).attr('virgin','1');
			}
		});

		if (options.num_chars > 0) {
			// remove if already existent
			$(this).next('.charsleft').remove();
			offset = options.num_chars;
			if($(this).val())
				offset = options.num_chars - $(this).val().length;
			$(this).after("<div class='charsleft'><span id='"+spanid+"'>"+offset+"</span> "+left_string+"</div>");

			$(this).keyup(function(){

				spanid = $(this).attr('spanid');

				text = $(this).val();
				left = options.num_chars - text.length;

				if (left < 1 ) {
					new_text = text.substr(0,options.num_chars);
					$(this).val(new_text);
					left = '0';
				}

				$('#'+spanid).html(left);
			});
		}
	}
});

jQuery.fn.extend({
	popup: function(options) {
		$(this).click(function() {
			yInfo(options.info);
		});
	}
});

/* class for calendar-handling
   you can provide an url which returns an array of days which should be marked.
   The parameter given to the script behind the url is the current month
*/
function yCalendar() {

	this.init_calendar = function(el,year,month,day,marked_days_url) {

		this.el = el;
		this.current_year = parseInt(year);
		this.current_month = parseInt(month);
		this.current_day = parseInt(day);
		this.current_selected_month = this.current_month;
		this.current_selected_year = this.current_year;
		this.marked_days_url = marked_days_url;

		this.mark_days();
		this.calendar_handlers();
	}

	this.change_calendar = function(calendar_id,modus) {
		calendar = this;
		switch(modus) {
			case -1:
				if(calendar.current_selected_month==1){
					this.current_selected_month=12;
					this.current_selected_year--;
				} else {
					this.current_selected_month--;
				}
				break;
			case 1:
				if(this.current_selected_month==12){
					this.current_selected_month=1;
					this.current_selected_year++;
				}else{
					this.current_selected_month++;
				}
				break;
		}
		day = '01';
		no_day_selected = 1;
		if(this.current_selected_month==this.current_month && this.current_selected_year==this.current_year) {
			day = this.current_day;
			no_day_selected = 0;
		}
		$.ajax({
				type: 'POST',
				url: '/ajax/calendar/change_calendar.html',
				data: {
					id: calendar_id,
					time: calendar.current_selected_year + '-' + calendar.current_selected_month + '-' + day,
					no_day_selected: no_day_selected
				},
				success: function(str) {
					$('#'+calendar_id+'_inner_table').html(str);
					calendar.calendar_handlers();
					calendar.mark_days();
				}
		});

	}

	this.calendar_handlers = function() {
		$('#'+this.el+' .calendar_entry').hover(function() {
			$(this).addClass('activated');
			},function() {
				$(this).removeClass('activated');
		});

		$('#'+this.el+' td.calendar_entry').click(function() {
			temp = (this.id).split('_');
			calendar = eval(temp[0]);
			$('#'+ temp[0] + '_day_' + calendar.current_day).removeClass('current');
			calendar.current_month=calendar.current_selected_month;
			calendar.current_year=calendar.current_selected_year;
			calendar.current_day = temp[2];
			$('#'+ temp[0] + '_day_' + calendar.current_day).addClass('current');
			click_calendar(temp[0]);
		});
	}

	this.get_db_date = function() {
		year = this.current_year;
		month = this.current_month;
		day = this.current_day;
		if (month < 10) month = '0'+month;
		if (day < 10) day = '0'+day;

		return year+'-'+month+'-'+day;
	}

	this.get_date = function(marked_days) {
		date = new Date(this.current_year,this.current_month,this.current_day,0,0,0);
		return date;
	}

	this.mark_days = function() {
		temp = this.el;
		$.ajax({
				type: 'POST',
				url: this.marked_days_url,
				data: {
					month: this.current_selected_year + '-' + this.current_selected_month
				},
				success: function(str) {
					//document.write(str);
					//alert(str);
					marked_days = str.split(",");
					for (i=0;i<marked_days.length;i++) {
						$('#'+ temp + '_day_' + marked_days[i]).addClass('marked');
					}
				}
		});
	}
}
// GLOBALS

win_chat = null;

// FUNCTIONS

function init_buttons() {
	// set button-styles
	$('.input_submit').mouseover(function() {
		$(this).addClass('input_submit_act');
	});
	$('.input_submit').mouseout(function() {
		$(this).removeClass('input_submit_act');
	});
	$('.input_cancel').mouseover(function() {
		$(this).addClass('input_cancel_act');
	});
	$('.input_cancel').mouseout(function() {
		$(this).removeClass('input_cancel_act');
	});
}

function ySlideDown(item) {
	if ($(item).css('display') == 'none') {
		$(item).slideDown(100);
	}
}

function ySlideUp(item) {
	if ($(item).css('display') != 'none') {
		($(item).slideUp(100));
	}
}

function ySlideToggle(item) {
	if($(item).css('display') != 'none') {
		($(item).slideUp(100));
	} else {
		$(item).slideDown(100);
	}
}

function slide(div){
	$('#'+div).slideToggle('slow')
}


/**
	TOOLS
*/

/***********************************/
// Formatiert eine Zahl fuer die Ausgabe.
// Folgende Merkmale koennen beeinflusst werden: Anzahl Nachkommastellen, Dezimalpunkt und tausender Trennzeichen.
// String number_format (Float number, Number decimals, String dec_point, String thousands_sep)
function number_format (number, decimals, dec_point, thousands_sep)
{
	  var exponent = "";
	  var numberstr = number.toString ();
	  var eindex = numberstr.indexOf ("e");
	  if (eindex > -1)
	  {
	    	exponent = numberstr.substring (eindex);
	    	number = parseFloat (numberstr.substring (0, eindex));
  	}

	  if (decimals != null)
	  {
	    	var temp = Math.pow (10, decimals);
	    	number = Math.round (number * temp) / temp;
	  }
	  var sign = number < 0 ? "-" : "";
	  var integer = (number > 0 ?
	      	Math.floor (number) : Math.abs (Math.ceil (number))).toString ();

	  var fractional = number.toString ().substring (integer.length + sign.length);
	  dec_point = dec_point != null ? dec_point : ".";
	  fractional = decimals != null && decimals > 0 || fractional.length > 1 ?
	               (dec_point + fractional.substring (1)) : "";
	  if (decimals != null && decimals > 0)
	  {
	    	for (i = fractional.length - 1, z = decimals; i < z; ++i)
	      		fractional += "0";
	  }

	  thousands_sep = (thousands_sep != dec_point || fractional.length == 0) ?
	                  thousands_sep : null;
	  if (thousands_sep != null && thousands_sep != "")
	  {
		for (i = integer.length - 3; i > 0; i -= 3)
	      	integer = integer.substring (0 , i) + thousands_sep + integer.substring (i);
	  }

	  return sign + integer + fractional + exponent;
}
/***********************************/

function form_to_object(form_id) {
	values = new Object();

	// select
	$(form_id).find('select').each(function() {
		var elem_name = $(this).attr('name');
		values[elem_name] = $(this).val();
	});
	// textarea
	$(form_id).find('textarea').each(function() {
		var elem_name = $(this).attr('name');
		values[elem_name] = $(this).val();
	});
	// input
	$(form_id).find('input').each(function() {
		var elem_name = $(this).attr('name');
		values[elem_name] = $(this).val();
	});

	return values;
}

/**
* Function : dump()
* Arguments: The data - array,hash(associative array),object
*    The level - OPTIONAL
* Returns  : The textual representation of the array.
* This function was inspired by the print_r function of PHP.
* This will accept some data as the argument and return a
* text that will be a more readable version of the
* array/hash/object that is given.
*/
function dump(arr,level,html) {
	var dumped_text = "";
	if(!level) level = 0;
	if (!html) next = "\n";
	else next = "<br />";

	//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 + "' ..." + next;
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\""+next;
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}

function nl2br(text) {
	text = text.replace(/\n/g,"<br \/>");
	return text;
}

function br2nl(text) {
	text = text.replace(/(<br>)|(<BR>)/g,"\n");
	return text;
}

serialize = function(elem) {
  if (elem == null || elem == undefined || elem.constructor == Function) return 'N;';

  switch (elem.constructor) {
    case String:  return 's:' + elem.length + ':"' + elem + '";';
    case Number:  return (elem % 1 ? 'd:' : 'i:') + elem + ';';
    case Boolean: return 'b:' + (elem ? '1' : '0') + ';';
    case Date:    return serialize(elem.getTime());
    case RegExp:  return serialize(elem.toSource());
    case Error:   return serialize(elem.message);
    case Array:
    case Object:
      var content = '', i = 0;
      for (var j in elem) { content += serialize(j) + serialize(elem[j]); i++; }
      return 'a:' + i + ':{' + content + '}';
    default:
      return serialize(elem.toString());
  }
}

function randomString() {
	var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
	var string_length = 8;
	var randomstring = '';
	for (var i=0; i<string_length; i++) {
		var rnum = Math.floor(Math.random() * chars.length);
		randomstring += chars.substring(rnum,rnum+1);
	}
	return randomstring;
}

function show_div(div){
	if(document.getElementById(div)){
		if(document.getElementById(div).style.display == "none"){
			document.getElementById(div).style.display = "block"
		}else{
			document.getElementById(div).style.display = "none"
		}
	}
}

function trim(s) {
  while (s.substring(0,1) == ' ') {
    s = s.substring(1,s.length);
  }
  while (s.substring(s.length-1,s.length) == ' ') {
    s = s.substring(0,s.length-1);
  }
  return s;
}


function str_replace(search, replace, subject) {
    return subject.split(search).join(replace);
}

///////////////////// ARRAY-FUNCTIONS //////////////////////

function in_array(haystack,needle){
	for(i=0;i<haystack.length;i++){
		if(haystack[i]==needle)
			return true;
	}
	return false;
}

///////////////////////////// Cities ///////////////////

function city_suggest(needle,div_id,js_id){
	$('#cities_suggest_box').html('');

	$.ajax({
		type: 'POST',
		url: '/ajax/common/cities.html',
		data: {
			method: "suggest",
			needle: needle,
			country: $('#country').val(),
			div_id: div_id,
			js_id:js_id
		},
		success: function(result) {
			$('#'+div_id).html(result);
			if(result.length>0){
				$('#'+div_id).show();
			}else{
				$('#'+div_id).hide();

			}
		}
	});
}

function set_city(location_id, city){
	$('#s_cities').val(city);
	$('#location_id').val(location_id);
	$('#cities_suggest_box').hide();
	//alert($('#location_id').val());
}

function set_big_city(location_id, city){
	$('#big_city').val(city);
	$('#s_big_city').append(city);
	$('#s_big_city').show();
	$('#location_id').val(location_id);
	$('#big_city_suggest').hide();
	yModalHide();
}

function set_search_big_city(location_id, city,js_id){
	$('#big_city').val(city);
	$('#s_big_city').show();
	$('#big_city_suggest').hide();
	$('#location_id').val(location_id);
	yModalHide();
	//set_search_city(location_id,js_id);
}

function set_search_city(location_id,js_id){
	$.ajax({
		type: 'POST',
		url: '/ajax/common/cities.html',
		data: {
			method: "get_location",
			location_id: location_id
		},
		success: function(result) {
			if($('#search_location'+js_id))
				$('#search_location'+js_id).prepend(result);
			if(js_id=="")
				big_city_action();
		}
	});

}

function change_region(caller, js_id) {
	if ($(caller).val() == "other") {
		location.href = "/search/cities.html";
	}
}


///************ [+] REQUESTS ************************//
function accept_request(accept, action_id, user_id, group_id){
	$.ajax({
		type: 'POST',
		url: '/ajax/contacts/contacts.html',
		data: {
			method: "accept_request",
			accept: accept,
			action_id: action_id,
			group_id: group_id,
			user_id: user_id
		},
		success: function(result) {
			location.reload();
		}
	});
}
///************ [-] REQUESTS **********************************//


function mark(div){
	document.getElementById(div).select();
}


/*************** [+] POPUPS ************************************/



/* opens an popup-window with following params:
   url: url of the content
   height: height of the popup
   width: width of the popup
   name: name of the popup-window, which can be referenced by calling another hyperlink,
   	     if you specify no name, than you can open several popups

*/

function open_popup(url,height,width,name) {
	if(!name) name="_blank";
	win = window.open(url,name,"width="+width+",innerWidth="+width+",height="+height+",innerHeight="+height+",top=100,left=100,dependent=yes,hotkeys=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=yes,toolbar=no");
	win.focus();
	return win;
}



/*************** [-] POPUPS ************************************/

function new_password(){
	$.ajax({
		type: 'POST',
		url: '/ajax/common/new_password.html',
		data: {
			email:$('#email').val()
		},
		success: function(result) {
			$('#system_msg').html(result);
		}
	});
}

function check_login(){
	$.ajax({
		type: 'POST',
		url: 'ajax/common/check_login.html',
		data: {
			email:$('#email').val(),
			pw: $('#pw').val()
		},
		success: function(result) {
			$('#system_msg').html(result);
		}
	});
}

/*City-Suggest-Box validation*/

function check_location(id_v){
	if($('#location_id'+id_v).val()==0){
		city_val="";
		if($('#ipt_village_'+id_v).val()!="" && $('#ipt_city_'+id_v).val()==""){
			city_val = $('#ipt_village_'+id_v).val();
		}else if($('#ipt_city_'+id_v).val()!="" && $('#location_id'+id_v).val()=='0'){
			city_val = $('#ipt_city_'+id_v).val();
		}
		if(city_val!=""){
			$('#suggest_villages_'+id_v).hide();
			$('#suggest_cities_'+id_v).hide();
			$.ajax({
				type: 'POST',
				url: '/ajax/common/cities.html',
				data: {
					method: "check_location",
					city: city_val,
					country: $('#country').val()
				},
				success: function(result) {
					if(trim(result) != ""){
						$('#location_id'+id_v).val(result);
						if($('#ipt_city_'+id_v).val()==$('#ipt_village_'+id_v).val())
							$('#near_city_'+id_v).hide();
						$('#city_msg').hide();
						return '1';
					}else{
						$('#near_city_'+id_v).show();
						$('#ipt_city_'+id_v).focus();
						return '0';
					}
				}
			});
		}
	}
}

// taken over from main.tpl.php - have to be cleaned and inserted
/*function open_chat(rec_id){
  url = "/popups/y_chat.html?rec_id="+rec_id;
  win_chat = open_popup(url,500,650,'win_chat');
  win_chat.focus();
}*/

function open_chat(rec_id,check){
	if(check==1){
		$.ajax({
			type: 'POST',
			url: '/ajax/chat/chat.html',
			data: {
				method: "check_privacy",
				recipient_id: rec_id
			},
			success: function(result) {
				if(result=="0"){
					url = "/popups/y_chat.html?rec_id="+rec_id;
					open_popup(url,500,650,'win_chat');
				}else{
					url = "/contacts/err_chat.html?e="+result+"&rec_id="+rec_id;
					location.href = url;
				}
			}
		});
	}else{
		url = "/popups/y_chat.html?rec_id="+rec_id;
		open_popup(url,500,650,'win_chat');
	}
}

function close_chat() {
  if(win_chat != null) {
    win_chat.close();
  }
}

function notification_set_left() {
  var offset = $('#chatinfo').offset();
  if(offset) {
    if($.browser.msie) {
      var left = offset.left+250-document.documentElement.scrollLeft;
    } else {
      var left = offset.left+260-window.pageXOffset;
    }
    $('.notification').css('left',left +"px");
  }
}

function notification_set_top() {
  var offset = $('#notifications_0').offset();
  if(offset) {
    top = offset.top;
    $('#notifications_1').css('top',(top-45)+"px");
    //$('#notifications_2').css('top',(top-88)+"px");
  }
}

/**
		needed due to ie-bug using jquery's 'load()'
	*/
function img_pos(elem) {
	var top = 65 - ($(elem).height()/2) -2; // -2 = border
	$(elem).css({position: 'relative', top: top});
}

// START

$(document).ready(function(){

	// fix to remove "click to activate and use this control" in ie..
	theObjects = document.getElementsByTagName("object");
	for (var i = 0; i < theObjects.length; i++) {
		theObjects[i].outerHTML = theObjects[i].outerHTML;
	}

        // hide dotted border
	$('img').click(function() {
		this.blur();
	});
	$('a').click(function() {
		this.blur();
	});


	// set form-styles
	$("input[@type='text']").each(function() {
		// set class only if no other class is set
		if (!$(this).attr('class')) $(this).addClass('input_text');
	});
	$("input[@type='password']").each(function() {
		// set class only if no other class is set
		if (!$(this).attr('class')) $(this).addClass('input_text');
	});

	init_buttons();

        $('#del_note_0').click(function(){
          $("#notifications_0").hide();
	});

        $('#del_note_1').click(function(){
          $("#notifications_1").hide();
	});

        $('#del_note_2').click(function(){
          $("#notifications_2").hide();
	});
});
/* questions [+] */

	function interviews_signes_left(id){
		l = $('#answer_'+id).val().length;
		$('#sp_signsleft_'+id).html(l + " Zeichen");
		if(l<160 || l>500){ // zu wenig oder zuviel zeichen
			$('#sp_signsleft_'+id).css({color:'#f00'});
			$('#ok_'+id).hide();
		}else{
			$('#sp_signsleft_'+id).css({color:'#848484'});
			$('#ok_'+id).show();
		}
		if(l>500){
			temp = $('#answer_'+id).val().substr(0,500);
			$('#answer_'+id).val(temp);
		}
	}

/* questions [-] *//* blogview [+] */
function common_bookmarkService(value) {
	if(value != "0") {
		switch(value) {
			case "1": window.open("http://www.blinkbits.com/bookmarklets/save.php?v=1&amp;title="+encodeURIComponent(document.title)+"&amp;source_url="+encodeURIComponent(location.href));
				break;
			case "2": window.open('http://www.blinklist.com/index.php?Action=Blink/addblink.php&amp;Url='+encodeURIComponent(location.href)+'&amp;Title='+encodeURIComponent(document.title));
				break;
			case "3": window.open('http://blogmarks.net/my/new.php?mini=1&amp;simple=1&amp;url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title));
				break;
			case "4": window.open('http://www.bonitrust.de/account/bookmark/?bookmark_url='+unescape(location.href));
				break;
			case "5": window.open('http://www.bookmarks.cc/bookmarken.php?action=neu&amp;url='+(document.location.href)+'&amp;title='+(document.title));
				break;
			case "6": window.open('http://del.icio.us/post?v=2&amp;url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title));
				break;
			case "7": window.open('http://digg.com/submit?phase=2&amp;url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title));
				break;
			case "8": window.open('http://www.diigo.com/post?url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title));
				break;
			case "9": window.open('http://www.favit.de/submit.php?url='+(document.location.href));
				break;
			case "10": window.open('http://www.favoriten.de/url-hinzufuegen.html?bm_url='+encodeURIComponent(location.href)+'&amp;bm_title='+encodeURIComponent(document.title));
				break;
			case "11": window.open('http://www.folkd.com/page/submit.html?step2_sent=1&amp;url='+encodeURIComponent(location.href)+'&amp;check=page&amp;add_title='+encodeURIComponent(document.title)+'&amp;add_state=public');
				break;
			case "12":window.open('http://www.furl.net/storeIt.jsp?u='+encodeURIComponent(location.href)+'&amp;keywords=<?echo $tags;?>&amp;t='+encodeURIComponent(document.title));
				break;
			case "13": window.open('http://www.google.com/bookmarks/mark?op=add&amp;hl=de&amp;bkmk='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title));
				break;
			case "14": window.open('http://www.icio.de/add.php?url='+encodeURIComponent(location.href));
				break;
			case "15": window.open('http://linkarena.com/bookmarks/addlink/?url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title));
				break;
			case "16": window.open('http://www.linksilo.de/index.php?area=bookmarks&amp;func=bookmark_new&amp;addurl='+encodeURIComponent(location.href)+'&amp;addtitle='+encodeURIComponent(document.title));
				break;
			case "17": window.open('http://ma.gnolia.com/bookmarklet/add?url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title));
				break;
			case "18": window.open('http://www.netscape.com/submit/?U='+encodeURIComponent(location.href)+'&amp;T='+encodeURIComponent(document.title));
				break;
			case "19": window.open('http://www.netvouz.com/action/submitBookmark?url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title)+'&amp;popup=yes');
				break;
			case "20": window.open('http://www.newsider.de/submit.php?url='+(document.location.href));
				break;
			case "21": window.open('http://www.newskick.de/submit.php?url='+(document.location.href));
				break;
			case "22": window.open('http://www.oneview.de/quickadd/neu/addBookmark.jsf?URL='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title));
				break;
			case "23": window.open('http://www.power-oldie.com/');
				break;
			case "24": window.open('http://reddit.com/submit?url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title));
				break;
			case "25": window.open('http://www.social-bookmarking.dk/bookmarks/?action=add&amp;title='+encodeURIComponent(document.title)+'&amp;address='+(document.location.href));
				break;
			case "26": window.open('http://social-bookmarking.seekxl.de/?add_url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title));
				break;
			case "27": window.open('http://www.simpy.com/simpy/LinkAdd.do?title='+encodeURIComponent(document.title)+'&amp;href='+encodeURIComponent(location.href));
				break;
			case "28": window.open('http://slashdot.org/bookmark.pl?url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title));
				break;
			case "29": window.open('http://smarking.com/editbookmark/?url='+ location.href);
				break;
			case "30": window.open('http://www.spurl.net/spurl.php?v=3&amp;title='+encodeURIComponent(document.title)+'&amp;url='+encodeURIComponent(document.location.href));
				break;
			case "31": window.open('http://www.stumbleupon.com/submit?url='+encodeURIComponent(location.href)+'&amp;title='+encodeURIComponent(document.title));
				break;
			case "32": window.open('http://technorati.com/faves?add='+encodeURIComponent(location.href));
				break;
			case "33": window.open('http://myweb2.search.yahoo.com/myresults/bookmarklet?t='+encodeURIComponent(document.title)+'&amp;u='+encodeURIComponent(location.href));
				break;
			default: "";
		}
	}
}
/* blogview [-] */



/* invite [+] */
function common_add_and_init(html) {
	$('#recipients').append(html);
	num_rec++;

// init
	$('.rcp .del').mouseover(function() {
		$(this).attr({src: '/resources/images/screens/delete_act.gif'});
	});
	$('.rcp .del').mouseout(function() {
		$(this).attr({src: '/resources/images/screens/delete.gif'});
	});
	$('.rcp .del').click(function() {
		$(this).parents('.rcp').remove();
		num_rec--;
	});
}
/* invite [-] */
/* nav [+] */
function contacts_open_add_label(){
	if(add_label_shown) {
		$('#new_label').hide();
		$('#add_label_plus').html("+");
		add_label_shown=false;
		$('#label_error').hide();
	} else {
		$('#add_label').hide();
		$('#new_label').show();
		add_label_shown=true;
		$('#add_label_plus').html("-");

	}
}
/* nav [-] */


/* new_mail [+] */

function new_mail_release(uid, id) {
	var value;
	value = $('#'+id).val();

	$.ajax({
		type: 'POST',
		url:'/ajax/user/userprofile.html',
		data: {
			method: 'update_mail_constraint',
			user_id: uid,
			field: id,
			data: value
		},
		success: function(result) {
			$('#contacts_newmail_contraints_errorbox').html(result);
			$("#contacts_newmail_contraints_errorbox").css("display", "inline").fadeOut(2000);
		}
	});
}

function save_data_release() {
	var ar_data = new Array();

	ar_data.push($('#data_0').val());
	ar_data.push($('#data_1').val());

	if(document.getElementById('data_2').checked){
		ar_data.push(1);
	} else {
		ar_data.push(0);
	}
	if(document.getElementById('data_3').checked){
		ar_data.push(1)
	} else {
		ar_data.push(0);
	}
	if(document.getElementById('data_4').checked){
		ar_data.push(1);
	} else {
		ar_data.push(0);
	}
	if(document.getElementById('data_5').checked){
		ar_data.push(1);
	} else {
		ar_data.push(0);
	}
	if(document.getElementById('data_6').checked){
		ar_data.push(1);
	} else {
		ar_data.push(0);
	}

	$.ajax({
		type: 'POST',
		url: '/ajax/user/userprofile.html',
		data: {
			method: 'update_datarelease',
			str_data: ar_data.join(",")
		},
		success: function(result) {
			$('.ud_errorbox').html(result);
			$(".ud_errorbox").css("display", "inline").fadeOut(2000);
		}
	})
}


/* new_mail [-] */function home_randomText(arg_array) {
	var now = new Date();
	var i=(now.getSeconds())%arg_array.length;
	$('#randText').text(arg_array[i]);
}/* photo_upload [+] */
function photos_check_new_album(){
	if($('#album').val()=="new"){
		$('#new_album').show();
	}else{
		$('#new_album').hide();
	}
}

function photos_make_upload(){
	$('#uploader').hide();
	$('#inprogress').show();
}
/* photo_upload [-] */function notes_init(str) {
	var don_t_move = false;

	$('#notes tr').mouseover(function() {
		$(this).css('backgroundColor','#f6f6f6');
	});
	$('#notes tr').mouseout(function() {
		$(this).css('backgroundColor','#fff');
	});

	// for avoiding changing the page when hitting report-button
	$('.elem_acquire').click(function() {
		don_t_move = true;
	});
	/*
	$('#notes tr').click(function() {
		if(!don_t_move) {
			window.location.href = $('.user_notes_a').attr("href");
		}
		don_t_move = false;
	});
	*/

	$('#add_note .notes_left_div textarea').keyup(function() {
		if($(this).val().length>=160) {
			$('#add_note .left_div .textarea_counter').html("0");
			$(this).val($(this).val().substring(0,160));
		} else {
			$('#add_note .notes_left_div .textarea_counter').html(160 - $(this).val().length);
		}
	});

	$('#add_note .notes_left_div textarea').focus(function() {
		if($(this).val() == str) {
			$(this).val("");
		}
		//$(this).removeClass("inactive");
	});

	$('#add_note .notes_left_div textarea').blur(function() {
		if($(this).val()=="") {
			$('#add_note .notes_left_div .textarea_counter').html("160");
			$(this).val(str);
			$(this).addClass("inactive");
		}
	});



	$('.mousover_img').mouseover(function() {
		$(this).css('backgroundColor','#feb863');
	});
	$('.mousover_img').mouseout(function() {
		$(this).css('backgroundColor','#ffffff');
	});
}/* newsletter [+] */
function popups_toggle(div){
	$('#'+div).toggle();
}

function popups_add_text(adder){
	$("#body").val($("#body").val()+adder);
	$("#body").focus();
}
/* newsletter [-] */

/* y_chat [+] */
function popups_resize_chat(){
	popups_set_inner_height();
	$('#chat_win').height(inner_height-185);
	document.getElementById("chat_win").scrollTop = document.getElementById("chat_win").scrollHeight;
}

function popups_set_inner_height(){
	if (navigator.appName.indexOf("Explorer") != -1){//IE
		inner_height = document.body.clientHeight;
	}else{//Netscape/Mozilla
		inner_height = innerHeight;
	}
}

function popups_set_scroller(){
	if(scroll_pos>0){
		$('#scroller_top_active').show();//html("<img src='/resources/images/chat/scroller_top_active.gif' onClick=\"javascript:scroll('up')\" />");
		$('#scroller_top_inactive').hide();
	}else{
		$('#scroller_top_active').hide();//html("<img src='/resources/images/chat/scroller_top_inactive.gif' />");
		$('#scroller_top_inactive').show();
	}
	if(real_height-max_height-scroll_pos+12 > 0){ //+12 wegen der eigenh�he des Scrollbalkens von 24px
		$('#scroller_bottom_active').show();//html("<img src='/resources/images/chat/scroller_bottom_active.gif' onClick=\"javascript:scroll('down')\" />");
		$('#scroller_bottom_inactive').hide();
	}else{
		$('#scroller_bottom_inactive').show();//html("<img src='/resources/images/chat/scroller_bottom_inactive.gif' />");
		$('#scroller_bottom_active').hide();
	}
}

function popups_scroll(direction,snum){
	if(direction == 'up'){
		scroll_pos -= snum*25;
	}
	if(direction == 'down'){
		scroll_pos += snum*25;
	}
	document.getElementById("div_bodylist").scrollTop = scroll_pos;
	popups_set_scroller();
}

function popups_resize_bodylist(num){
	/* H�he der Bodylist definieren */
	// innerHeight - doppelte Hohe der Scroller und des Headers => 24+24+30 = 78 + padding = 80
	popups_set_inner_height();
	max_height = inner_height-80;
	// jeder Eintrag hat eine H�he von rund 25px
	b_height = (num*25);
	if(max_height<b_height){
		//scroller aktivieren und h�he des divs festsetzen
		$('#div_bodylist').height(max_height-14);
		$('#div_bodylist').css("overflow","hidden");
	}else{
		$('#div_bodylist').height(b_height);
	}
	popups_set_scroller();
}

function popups_init_bl_scroll(active_num){ //scrollt die Bodyliste so hin, das der aktuelle Gespr�chspartner zu sehen ist
	diff 		= real_height-max_height-scroll_pos+12;
	anum 		= active_num*25;
	if (navigator.appName.indexOf("Explorer") != -1){//IE
		toscroll 	= diff-anum+75;
	}else{
		toscroll 	= anum-diff;
	}
	if(toscroll>0){ // Es mu� gescrollt werden
		times	= toscroll/25;
		popups_scroll('down',times);
	}
}

function popups_check_inbox(){
	$.ajax({
		type: 'POST',
		url: '/ajax/chat/chat.html',
		data: {
					method:'fetch_unread_msg'
				},
		success: function(result) {
			if(result!=""){
				all_info = result.split("[;;;]");
				new_msg_user_ids = all_info[0].split(";");
				for(i=0;i<new_msg_user_ids.length;i++){
					temp = new_msg_user_ids[i].split(",");
					if(document.getElementById('num_cmails_'+temp[0])){
						$('#num_cmails_'+temp[0]).removeClass("num_cmails");
						$('#num_cmails_'+temp[0]).addClass("new_msgs");
						$('#num_cmails_'+temp[0]).html(temp[1]);
					}
				}

				online_status = all_info[1].split(";");
				for(i=0;i<online_status.length;i++){
					temp = online_status[i].split(",");
					if(temp[1]=='1'){ //user ist online
						$("#body_"+temp[0]).removeClass("is_off");
						 $("#body_"+temp[0]).addClass("is_on");
					}else{ //user ist offline
						$("#body_"+temp[0]).removeClass("is_on");
						$("#body_"+temp[0]).addClass("is_off");
					}
				}
			}
		}

	});
}

function popups_delete_contact(thread_id){
	$.ajax({
		type: 'GET',
		url: '/ajax/chat/chat.html',
		data: {
					method:'delete_contact',
					thread_id: thread_id
				},
		success: function(result) {
			location.reload();
		}
	});
}

function popups_check_chat(thr_id,user_id,recp_name){ // checkt auch ob online / offline
	$.ajax({
		type: 'POST',
		url: '/ajax/chat/chat.html',
		data: {
					method:'fetch_msg',
					thread_id: thr_id ,
					user_id: user_id
				},
		success: function(result) {
			if(result.indexOf("<!DOCTYPE")==3){
				window.close();
			}else{
				if(result!=""){
					if(result!="offline"){
						$('#is_offline').hide();
						if(is_online==true){
							new_mails = result.split("[###;;;;###]");
							for(i=0;i<new_mails.length;i++){
								if(new_mails[i]!=""){
									mail = new_mails[i].split("[###;;###]");
									$("#chat_win").append("<div class='d_msg'><span class='chat_time'>"+mail[1]+"</span>&nbsp;<b><span class='recipient'>"+ recp_name +"</span></b><br />"+mail[0]+"</div>");
								}
							}
							document.getElementById("chat_win").scrollTop = document.getElementById("chat_win").scrollHeight;
							num_mails = Number(num_mails)+Number(new_mails.length);
							$('.num_active_thread').html(num_mails);
						}else{
							location.reload(); //bodylist neu mitladen laden
						}
					}else{
						if(is_online){

							$('#body_send').hide();
							$('#is_offline').show();
							is_online=false;
						}
					}
				}else{
					if(is_online == false){
						location.reload(); //bodylist neu mitladen laden
					}
				}
			}
		}

	});
}

function popups_send_msg(recp,thr_id,name){
	chat_body = $('#text_body').val();
	if(chat_body!=""){
		$.ajax({
			type: 'GET',
			url: '/ajax/chat/chat.html',
			data: {
						method:'send_msg',
						recipient_id: recp,
						thread_id: thr_id,
						body:chat_body
					},
			success: function(result) {
				/*mydate  = new Date();
			    mH  	= mydate.getHours();
			    mi  	= mydate.getMinutes();
			    if(mi<=9)
			    	mi ="0"+mi;
			    <span class='chat_time'>"+mH+":"+mi+"</span> */
				$("#chat_win").append("<div class='d_msg'><b><span class='me'>"+ name +"</span></b><br />"+result+"</div>");
				//$("div#chat_win").css('top', '5px');
				document.getElementById("chat_win").scrollTop = document.getElementById("chat_win").scrollHeight;
				$('#text_body').val("");
				$('#text_body').focus();
				num_mails++;
				$('.num_active_thread').html(num_mails);
			}
		});
	}

}

function popups_ask_delete(thread_id,confirm_text){
	if(confirm(confirm_text)){
		popups_delete_contact(thread_id);
	}
}

/* y_chat [-] *//* confirm [+] */
function register_new_activation_mail(u_id){
	$('#val_box').hide();
	$.ajax({
		type: 'POST',
		url: '/ajax/register/confirm.html', // muss noch implementiert werden ...
		data: {
					method:'newcode',
					user_id: u_id
				},
		success: function(result) {
			m_error = result.substr(0,1);
			$('#val_box').html(result.substr(1));
			$('#val_box').show();
		}
	});
}

function register_change_response_adress(u_id){
	$('#new_act_mail').hide();
	$.ajax({
		type: 'POST',
		url: '/ajax/register/confirm.html', // muss noch implementiert werden ...
		data: {
					method:'newemail',
					new_email: $('#new_email').val(),
					user_id: u_id
				},
		success: function(result) {
			//feedback
			m_error = result.substr(0,1);
			if(m_error == "0"){ //ok
				$('#new_adress').hide();
				$('#new_act_mail').hide();
			}
			$('#val_box').html(result.substr(1));
			$('#val_box').show();
		}
	});
}

function register_toggle(elem){
	$(elem).toggle();
}
/* confirm [-] */

/* register [+] */
function register_versalien_check(str){
	if(str.length>0){
		str		= jQuery.trim(str);
		str		= str.toLowerCase();
		//@s und . entfernen
		str 	= str.split('@web').join('');
		str 	= str.split('@gmx').join('');
		str 	= str.split('@yahoo').join('');
		str 	= str.split('@').join('');
		str 	= str.split('.de').join('');
		str 	= str.split('.net').join('');
		str 	= str.split('.com').join('');
		//str 	= str.split('.').join('');
		l_cap	= str.substring(0,1).toUpperCase();
		str		= l_cap+str.substring(1);
		//nach Leerzeichen oder Bindestrichen suchen und den Nachfolgenden Buchstaben auch gro�schreiben:
		for(pos=0;pos<str.length;pos++){
			if(str.charAt(pos)=='-' || str.charAt(pos)==' '){
				w_1 	= str.substr(0,pos);
				w_2	 	= str.substr((Number(pos)+Number(2)));
				l_cap 	= str.substr((Number(pos)+Number(1)),1).toUpperCase();
				str		= w_1+str.substr(pos,1)+l_cap+w_2;
			}
		}
	}

	return str;
}

function register_init_bg(){
	$('#tr_register_searching').css({ backgroundColor:'#fff' });
	$('#tr_register_orientation').css({ backgroundColor:'#fff' });
}

function register_check_nums(str_val){
	if(str_val!=""){
		if(str_val.search(/\d+/) >= 0){
			return "1";
		}
		return "0";
	}else{
		return "0";
	}
}

function register_check_email(e_mail){
	$.ajax({
		type: 'POST',
		url: '/ajax/register/validate.html',
		data: {
					method:'check_mail',
					email: e_mail
				},
		success: function(result) {
			if(jQuery.trim(result) != "true") {
				$('#s_e_mail').html(result);
				$('#s_e_mail').show();
			}else{
				$('#s_e_mail').hide();
				$('#error_e_mail').html("<img src='/resources/images/register/hook.png' alt='ok' />");
				$('#error_e_mail').show();
			}
		}
	});
}

function register_pw_check(pw){
	forbidden = /[\'\"]/gi;
	error = pw.match(forbidden);
	if(error){
		ergo = -1;
	}else{
		ergo = register_check_pw_security(pw);
		if(ergo<0)
			ergo=0;
	}
	return ergo;
}

function register_check_pw_security(pw){
		var num_signs 	= 0;
		var num_numbers = 0;
		var num_all 	= 0;

		var r_signs		= /[a-z]/gi;
		var r_all 		= /\D/gi;
		var r_nums 		= /\d/gi;

		rsigns 	= pw.match(r_signs); // all alphanumeric
		if(rsigns)
			num_signs = rsigns.length;

		rnumbers = pw.match(r_nums); // all numbers
		if(rnumbers)
			num_numbers = rnumbers.length;

		rall 	= pw.match(r_all); // all signs without whitespace
		if(rall)
			num_all = rall.length;

		num_extra	= num_all - num_signs; // all extrasigns

		return Number(num_signs*15)+Number(num_numbers*20)+Number(num_extra*30)-((6-num_all)*10);
}


function register_check_name(str) {

	var needle = /@/;
	var matchPos = str.search(needle);

	if(matchPos != -1) {
		return 1;
	}
	else {
		return 0;
	}
}

function register_set_agb(){
	if(gl_agb == 0){
		gl_agb = 1;
	}else{
		gl_agb = 0;
	}
}
/* register [-] *//* cities [+] */
function search_send(){
	$(".src_buttons").hide();
	document.forms['b_city'].submit();
}

/* cities [-] */

/* network_expand [+] */
function search_calculate_status(sta){
	var status = sta;

	if(document.getElementById("statustext"))
		document.getElementById("statustext").innerHTML = status;
	$.ajax({
				type: 'POST',
				url: '/ajax/user/userprofile.html',
				data: {
							method:'get_statusbar',
							status: status
						},
				success: function(result) {
					if(document.getElementById("m_st_bar"))
						document.getElementById("m_st_bar").innerHTML = result;
				}
	});
}
/* network_expand [-] */

/* global search [+] */
function search_init() {
	$('.connection_list .text_elem_tr').mouseover(function() {
		$(this).css('backgroundColor','#f2f2f2');
	});
	$('.connection_list .text_elem_tr').mouseout(function() {
		$(this).css('backgroundColor','#fff');
	});
}
/* global search [-] */
/* edit_about [+] */
function user_set_zodiac(){
	$.ajax({
				type: 'POST',
				url: '/ajax/user/userprofile.html',
				data: {
							method:'get_zodiac',
							day: $('#birthday_day').val(),
							month: $('#birthday_month').val()
						},
				success: function(result) {
					$('#zodiac').html(result);
				}
			});
}

function user_set_searching(s_id){
		if(document.getElementById('searching_'+s_id).checked){
			$('#searching').val($('#searching').val()+","+s_id);
		}else{
			$('#searching').val(str_replace(s_id,"",$('#searching').val()));
		}
	}

function user_set_spoken_languages(s_id){
	if(document.getElementById('spoken_languages_'+s_id).checked){
		$('#spoken_languages').val($('#spoken_languages').val()+","+s_id);
	}else{
		$('#spoken_languages').val(str_replace(s_id,"",$('#spoken_languages').val()));
	}
}
/* edit_about [-] */

/* edit_account [+] */
function user_init(){
	$('#save_all').show();
	$('.editbox .list tr').removeClass('editing');
	$('#new_pw').val("");
	$('#new_pw2').val("");
	$('#old_pw').val("");
	$('#new_email').val("");
	$('#new_email2').val("");
	$('#show_preferred_timezone').html($('#timezone').val());
	$('#show_preferred_timezone').show();
	$('#form_preferred_timezone').hide();
}
/* edit_account [-] */

/* edit_contact [+] */
function user_save_all(){
	$('#error').hide();
	$('#user_save_all').hide();
	$('#suggest_cities_1').hide();
	$('#suggest_villages_1').hide();

	telephone_val = $('#telephone').val();
	if(telephone_val == "")
		telephone_val = "-";
	mobile_val = $('#mobile').val();
	if(mobile_val == "")
		mobile_val = "-";
	street_val = $('#street').val();
	if(street_val == "")
		street_val = "-";
	city_val = $('#ipt_village_1').val();
	if(city_val == "")
		city_val = "-";
	zip_val = $('#zip').val();
	if(zip_val == "")
		zip_val = "-";

	$.ajax({
		type: 'POST',
		url: '/ajax/common/cities.html',
		data: {
			method: "check_location",
			city: $('#ipt_city_1').val(),
			country: $('#country').val()
		},
		success: function(result) {
			if(trim(result) != ""){
				$('#location_id1').val(result);
				$.ajax({
					type: 'POST',
					url: '/ajax/user/userprofile.html',
					data: {
						method:'update_userprofile_step_3',
						name: $('#name').val(),
						forname: $('#forname').val(),
						familyname: $('#familyname').val(),
						telephone: telephone_val,
						mobile: mobile_val,
						street: street_val,
						city: city_val,
						zip: zip_val,
						country_id: $('#country').val(),
						location_id: $('#location_id1').val()
					},
					success: function(result) {
						$('#user_save_all').hide();
						$('.editbox .list tr').removeClass('editing');
						location.reload();
					}
				});
			}else{
				$('#error').show();
				$('#near_city_1').show();
				$('#user_save_all').show();
			}
		}
	});
}
/* edit_contact [-] */

/* edit_lifestyle [+] */
function user_set_cuisine(id){
	pos = jQuery.inArray(id,gl_cuisine);
	if(pos == -1){
			gl_cuisine.push(id);
	}else{
		gl_cuisine.splice(pos,1);
	}
}

function user_set_life_priorities(id){
	pos = jQuery.inArray(id,gl_life_priorities);
	if(pos == -1){
			gl_life_priorities.push(id);
	}else{
		gl_life_priorities.splice(pos,1);
	}
}
/* edit_lifestyle [-] */

/* photo_upload [+] */
function user_check_new_album(){
	if($('#album').val()=="new"){
		$('#new_album').show();
	}else{
		$('#new_album').hide();
	}
}

function user_make_upload(){
	$('#uploader').hide();
	$('#inprogress').show();
}
/* photo_upload [-] */

/* profile [+] */
function user_block_user(param,u_id){
	$.ajax({
		type: 'POST',
		url:'/ajax/user/userprofile.html',
		data: {
			method: param,
			user_id: u_id
		},
		success: function() {
			location.reload();
		}
	});
}

function user_disconnect_user(u_id){
	$.ajax({
		type: 'POST',
		url:'/ajax/user/userprofile.html',
		data: {
			method: 'disconnect',
			user_id: u_id
		},
		success: function() {
			location.reload();
		}
	});
}

function save_data_release() {
	var ar_data = new Array();

	ar_data.push($('#data_0').val());
	ar_data.push($('#data_1').val());

	if(document.getElementById('data_2').checked){
		ar_data.push(1);
	} else {
		ar_data.push(0);
	}
	if(document.getElementById('data_3').checked){
		ar_data.push(1)
	} else {
		ar_data.push(0);
	}
	if(document.getElementById('data_4').checked){
		ar_data.push(1);
	} else {
		ar_data.push(0);
	}
	if(document.getElementById('data_5').checked){
		ar_data.push(1);
	} else {
		ar_data.push(0);
	}
	if(document.getElementById('data_6').checked){
		ar_data.push(1);
	} else {
		ar_data.push(0);
	}
	if(document.getElementById('data_7').checked){
		ar_data.push(1);
	} else {
		ar_data.push(0);
	}

	$.ajax({
		type: 'POST',
		url: '/ajax/user/userprofile.html',
		data: {
			method: 'update_datarelease',
			str_data: ar_data.join(",")
		},
		success: function(result) {
			$('.ud_errorbox').html(result);
			$(".ud_errorbox").css("display", "inline").fadeOut(2000);
		}
	})
}
/* profile [-] */