
//alert("huhu");


/*****************************************************
*/ function __P___Language() {}
/******************************************************/
 
lang = 'de';
lang_show_failed_keys = '';

if(typeof INT != 'object') INT = new Object();
/*INT['firstname'] = new Object();
INT['firstname']['de'] = 'Vorname';
INT['firstname']['en'] = 'First Name';*/

function $L(key) {
	
	this.lang = lang;
	this.def_lang = 'en';
	
	if(!INT[key]) {
		return key+lang_show_failed_keys;
	} else if(INT[key]) {
		if(INT[key][this.lang]) return INT[key][this.lang];
		else if(INT[key][this.def_lang]) return INT[key][this.def_lang];
		else return key+lang_show_failed_keys;
	} else return key+lang_show_failed_keys;
}


function ShowAlert() {
	return false;
}

/* Menu Functions */

//---------------------------------------------------------------------------------------
//-- Menu Functions ---------------------------------------------------------------------
//---------------------------------------------------------------------------------------

function Interface () {
	
	this.window = false;
	this.title = '';
	
	this.init = function() {
		// quicksearch, submit on return
		/*if(qs = document.getElementById('quicksearch')) {
			this.quicksearchEL = document.getElementById('quicksearch');
			this.addEvent(qs,'keydown',this.quicki = function(event) {this.quicksearch(event);}.bind(this));
		}*/ // done with submit button
		
		//this.setFooter();
		//this.linkExternalLinks();
		
		//if(!this.window) this.buildWindow();
		
		if($('search-q')) {
			$('search-q').focus();
		}
		
		this.overlays = 'ext'; //lightview / ext
		
	}

	this.setLang = function(lang) {
		// simple
		document.location.href = '/'+lang+myPlainPagePath;		
	}
	
	this.quicksearch = function(event) {
		if(event.keyCode != 13) return;
		this.do_search();
	}
	
	this.do_search = function() {
		document.location.href = '/suche/'+this.quicksearchEL.value;
	}
	
	this.donotinterruptsubmits = function() {
		this.coverbackground('visible',0.8);
		// get sid
		PA = new ProgressAnimation();
		PA.viewProgress(this.cover,false,'Bild wird geladen',false,0.5);
	}
	
	this.jumpTo = function(path) {
		window.open(path);
	}

	//---------------------------------------------------------------------------------------
	this.adjustSize = function(r) {
		sizeUnit = "%";
		defaultSize = 100;
		maxSize = 160;
		minSize = 98;	
	}


	//---------------------------------------------------------------------------------------
	this.setFooter = function() {
		el_id = 'navteaserarea';
		// wie kann ich das anders machen?
		// ohne javascript, wird man den footer nicht sehen, keine gute sache
		// damit kommt man nicht zum impressum
		if(!document.getElementById('footer')) return;
		ft = document.getElementById('footer');
		if(!document.getElementById('navteaserarea')) {
			ft.style.visibility = 'visible';
			return;
		}
		if(!PAGEdom) return;
		nt = document.getElementById('navteaserarea'); // contains left subnav and navboxes
		if(document.getElementById(el_id)) {			
			nt = document.getElementById(el_id); // contains left subnav and navboxes
			var nt_dp = PAGEdom.toDocumentPosition(nt); // get document position of navteaserarea
		} else if(document.getElementById('content')) {
			nt = document.getElementById('content'); // contains left subnav and navboxes
			var nt_dp = PAGEdom.toDocumentPosition(nt); // get document position of navteaserarea		
		}
		/*var nt_dp = PAGEdom.toDocumentPosition(nt); // get document position of navteaserarea
		//DebugDump(nt_dp,'nt_dp.y '+nt_dp.y);
		//DebugDump(scrollTop,'scrollTop '+scrollTop);
		var wHeight = PAGEdom.getWindowHeight();
		var pHeight = document.body.offsetHeight; // Safari needs body.offsetHeight //PAGEdom.getPageHeight();
		//DebugDump(pHeight,'pHeight '+pHeight);
		//DebugDump(wHeight,'wHeight '+wHeight);
		if(pHeight
		&& wHeight
		&& pHeight<wHeight) {
			nt.style.height = (wHeight-ft.offsetHeight-nt_dp.y-1)+'px'; // window.height - footer - navteaser position
		}*/


		var nt_dp_bottom = nt_dp.y + nt.offsetHeight;
		//DebugDump(nt_dp,'nt_dp.y '+nt_dp.y+ ' / ' +nt_dp_bottom);
		// DebugDump(scrollTop,'scrollTop '+scrollTop);
		var wHeight = PAGEdom.getWindowHeight();
		var pHeight = document.body.offsetHeight; // Safari needs body.offsetHeight //PAGEdom.getPageHeight();
		//DebugDump(wHeight,'wHeight '+wHeight);
		//DebugDump(pHeight,'pHeight '+pHeight);
		if(pHeight
		&& wHeight
		&& pHeight < wHeight) {
			nt.style.height = (wHeight-ft.offsetHeight-nt_dp.y)+'px'; // window.height - footer - navteaser position
			//DebugDump(nt.style.height,'1 nt.style.height '+nt.style.height);
		} else if(nt_dp_bottom
		&& wHeight
		&& nt_dp_bottom > wHeight) {
			// do nothing
			//DebugDump(nt.style.height,'2 nt.style.height '+nt.style.height);	
		} else { // tja wenn pHeight > wHeight ist muss man doch auch nichts mehr machen
			//nt.style.height = (wHeight-ft.offsetHeight-nt_dp.y)+'px'; // window.height - footer - navteaser position
			//DebugDump(nt.style.height,'3 nt.style.height '+nt.style.height);		
		}


		op = 1;
		ft.style.opacity = op; // set opacity for effect : filter:alpha(opacity=50); -moz-opacity:0.5; opacity:0.5; 
		ft.style.filter = "alpha(opacity:"+Math.round(op*100)+")";

	}

	//---------------------------------------------------------------------------------------
	this.loginOperation = function(operation,formname) {
		//alert();
		document.forms[0].operation.value = operation;
		document.forms[0].onsubmit(); // workaround browser bugs.
		document.forms[0].submit();
	}
	
	//---------------------------------------------------------------------------------------
	this.logout = function() {
		document.forms['iflogin'].operation.value = '[logout]';
		document.forms['iflogin'].action = '/';
		document.forms['iflogin'].onsubmit(); // workaround browser bugs.
		document.forms['iflogin'].submit();
	}	
	//---------------------------------------------------------------------------------------
	this.toggleMode = function() {
		if(mode) mode_value = mode;
		else if (document.getElementById('list_rdbms')) mode_value = "admin";
		else mode_value = "browse";
		//mode_el = document.getElementById("mymode");
		switch (mode_value) {
			case"admin":
				document.getElementById("mymode").value = 'browse';
				//mode_value = document.getElementById("mymode").value;
				break;
			case"browse":
				document.getElementById("mymode").value = 'admin';
				//mode_value = document.getElementById("mymode").value;
				break;			
		}
		//alert(document.getElementById("mymode").value);
		document.forms['iflogin'].onsubmit(); // workaround browser bugs.
		document.forms['iflogin'].submit();
	}
	
	//---------------------------------------------------------------------------------------

	this.linkExternalLinks = function() {
		if(is_phpos_environment) return;
		//return;
		 var links = document.getElementsByTagName('A');
		 for (var i=0; i<links.length; i++) { 
		  // var anchor = anchors[i]; 
		  var v = links[i].getAttribute("href");
		  var c = links[i].getAttribute("onclick");
		  
		   if (!c
		   && v
		   && v.indexOf('http') != -1) {
			 //DebugDump(c,'external link found');
			 //DebugDump(v,'external link found');
			 //this.addEvent(document,'click',function() {return false;}.bind(this));
			 links[i].setAttribute('target',"_blank");
			}
			
			 
		 } 

		/*links = document.getElementsByTagName('A');
		for(i=0;i<links.length;i++) {
			var atts = links[i].attributes;//getAttribute('href');
			DebugDump(atts,'external link found');
			for(p=0;p<atts.length;p++) {
				DebugDump(atts[p],''+p);
			}		
		}*/
	}

	this.jumpToExternalLink = function(myUrl,myName,hitId,hitName) {
	
		var jumpPage = "/link/external";
		var path = myUrl;
		jumpPage = jumpPage+"?path="+path;
		if ((hitName && hitName.length > 0) && (hitName && hitName.length >0)) jumpPage = jumpPage+"&object_id="+hitId+"&object_name="+hitName;
		mywin = window.open(jumpPage,myName);
		mywin.focus();
		
	}

	// browser
	//---------------------------------------------------------------------------------------
	this.browserSubmit = function(v,i,eidb,formname) {
		//alert('huhu'); return;
		if(!formname) formname = 'contentform';
		document.getElementById(i).value = v;
		document.forms[formname].onsubmit(); // workaround browser bugs.
		document.forms[formname].submit();
	}

	this.setDirPath = function(id,order_dir,eidb) {
		document.getElementById(eidb+'order').value = id;
		this.browserSubmit(order_dir,eidb+'order_dir');
	} 
		
	this.changeDirPath = function(id,order_dir,eidb) {
		img_path = '/images_admin/embedded_browser/';
		document.getElementById(eidb+'order').value = id;
		switch(order_dir) {
			case"desc":
				document.getElementById(id+'_order_dir_dot').src = img_path+"asc_blue_dot.gif";
				order_change = 'asc';
			break;
			case"asc":
				document.getElementById(id+'_order_dir_dot').src = img_path+"desc_blue_dot.gif";
				order_change = 'desc';
			break;	
		}	
		this.browserSubmit(order_change,eidb+'order_dir');
	} 
	
	// submit
	this.justSubmit = function(formname) {
		if(!formname) formname = 'contentform';
		document.forms[formname].onsubmit(); // workaround browser bugs.
		document.forms[formname].submit();	
	}

	// submit
	this.setHiddenAndSubmit = function(hidden_value,hidden_id,formname) {
		if(!formname) formname = 'contentform';
		document.getElementById(hidden_id).value = hidden_value;
		document.forms[formname].onsubmit(); // workaround browser bugs.
		document.forms[formname].submit();
	}

	// submit
	this.setHidden = function(hidden_value,hidden_id,formname) {
		if(!formname) formname = 'contentform';
		document.getElementById(hidden_id).value = hidden_value;
	}	
	//---------------------------------------------------------------------------------------
	//---------------------------------------------------------------------------------------
	this.magnifier_is_visible = false;
	this.magnify = function(m) {
		var mtop, st, ww;
		
		if(this.magnifier_is_visible == true) {
			setTimeout(function(){ this.magnify(m); }.bind(this), 300);
			return;
		}
		
		
/*
.menuitemGNW {
	position: absolute;
	visibility: hidden;
}

.fllGN {
	background-image: url(/images_admin/icons/kr_hl.png);
	background-repeat: no-repeat;
	background-position: left top;
	width: 36px; 
	height:72px; 
	float:left;
}

.fllGNib {
	background-image: url(/images_admin/icons/kr_hr.png);
	background-repeat: no-repeat;
	background-position: right top;	
	height:72px; 
	width: 36px;
	float:left;
}

.fllGNCT {
	float:left;
	background-color: #000;
	margin: 1px 0 0 0;
	he

*/		
		st = PAGEdom.docScrollTop();
		mtop = (st+160)+'px';
		ww = GetWindowWidth();
		this.mag = document.createElement('div');
		this.mag.style.position = 'absolute';
		this.mag.style.zIndex = 10020;
		this.mag.style.left = 60+'px';
		this.mag.style.top = mtop;		
		this.mag.style.width = (ww-120)+'px';	
		this.mag.style.textAlign = 'center';
		//this.mag.style.height = '180px';
		this.mag.style.padding = '3px';
		this.mag.style.fontWeight = 'bold';
		//this.mag.style.fontSize = '400%';
		this.mag.style.fontSize = '60px';
		this.mag.style.lineHeight = '60px';
		this.mag.style.color = '#fff';
		//this.mag.style.border = '1px solid red';
		
		this.mag.innerHTML = m;
		document.getElementsByTagName('body')[0].appendChild(this.mag);
		
		this.mag_bg = document.createElement('div');
		this.mag_bg.style.position = 'absolute';
		this.mag_bg.style.zIndex = 10019;
		this.mag_bg.style.left = 60+'px';
		this.mag_bg.style.top = mtop;		
		this.mag_bg.style.width = (this.mag.offsetWidth)+'px';//(ww-60)+'px';
		this.mag_bg.style.height = this.mag.offsetHeight+'px';//'200px';
		
		op = 0.1;
		this.mag_bg.style.opacity = op; // set opacity for effect : filter:alpha(opacity=50); -moz-opacity:0.5; opacity:0.5; 
		this.mag_bg.style.filter = "alpha(opacity:"+Math.round(op*100)+")";
		
		
		rk = document.createElement('div');
		rk.className = 'fllGN';
		this.mag_bg.appendChild(rk);
		
		ct = document.createElement('div');
		ct.style.width = (this.mag.offsetWidth - 72)+'px';
		ct.className = 'fllGNCT';
		this.mag_bg.appendChild(ct);	
		
		lk = document.createElement('div');
		lk.className = 'fllGNib';
		this.mag_bg.appendChild(lk);		
		
		document.getElementsByTagName('body')[0].appendChild(this.mag_bg);
		
		new Effect.Opacity(this.mag_bg, {duration:0.3, from:0.1, to:0.7,afterFinish: function() {IF.magnifier_is_visible = true;}});
		
		//new Effect.Appear(this.mag_bg,{duration:0.5});
		//new Effect.Appear(this.mag,{duration:0.5});
		//new Effect.SlideDown(menuitems[i],{duration:0.8});
		//new Effect.BlindDown(menuitems[i],{duration:0.8});
		//new Effect.Grow(menuitems[i],{duration:0.8});		

		//this.mag.style.backgroundColor = '#ffffff';
		this.addEvent(document,'mousedown',this.hideme = function(event) {this.hideMagnifier(event);}.bind(this));
	}
	//---------------------------------------------------------------------------------------
	this.hideMagnifier = function(event) {
	
		var el;
		el = this.gettarget(event);
		
		// If the active button was clicked on, exit.
		if (el == this.mag) return;
		if (el == this.mag_bg) return;
	
		// If the element is not part of a menu, reset and clear the active
		// button.
		
		PAGEdom.removeNode(this.mag);
		mag_bg = this.mag_bg;
		new Effect.Opacity(this.mag_bg, {duration:0.3, from:0.7, to:0,afterFinish: this.sau_Effect_rmNode});
		//new Effect.Puff(this.mag_bg, {duration:0.5,afterFinish: rmNode});
		//PAGEdom.removeNode(this.mag_bg);
	}	
	
	this.sau_Effect_rmNode = function(obj) {
		PAGEdom.removeNode(obj.element);
		IF.magnifier_is_visible = false;
	}
	//---------------------------------------------------------------------------------------
	
	//---------------------------------------------------------------------------------------
	this.coverbackground = function(vs,op) {
		
		if(!op) op = 0;
		
		if(!this.cover) {
			this.cover = document.createElement('div');
			this.cover.style.position = 'absolute';
			this.cover.style.zIndex = 5;
			this.cover.style.left = 0+'px';
			this.cover.style.top = 0+'px';
			this.cover.style.opacity = op; // set opacity for effect : filter:alpha(opacity=50); -moz-opacity:0.5; opacity:0.5; 
			this.cover.style.filter = "alpha(opacity:"+Math.round(op*100)+")";
			this.cover.style.backgroundColor = "#fff";
			document.getElementsByTagName('body')[0].appendChild(this.cover);
		}
		
		if(!vs) {
			this.cover.style.visibility = 'hidden';
		} else {
			ww = GetWindowWidth();
			wh = GetWindowHeight();
			st = PAGEdom.docScrollTop();
			bodyheight = st+wh;
			bodyheight = document.body.offsetHeight;
			this.cover.style.width = (ww-15)+'px';
			this.cover.style.height = ((bodyheight-15))+'px';
			this.cover.style.visibility =  'visible';			
		}
	}
	
	//---------------------------------------------------------------------------------------
	this.setField = function(sourcefield_id,targetfield_id,value,disable) {

		sourcefield = $(sourcefield_id);
		targetfield = $(targetfield_id);
		//DebugDump(sourcefield.value,'sourcefield.value');
		if(targetfield.value != value) {
			targetfield.value = value;
		}
	
	}
	
	//---------------------------------------------------------------------------------------
	this.getPHPOSContent = function(event,sid,conf) { //,{width:200,height:400,autosize:false}
		
		
		if(this.overlays == 'ext') {
			//DebugDump(conf,'conf');
			//DebugDump(sid,'sid '+sid);
			if(event) var evTarget = this.gettarget(event); //'.x-grid3-row'
			var win = Ext.getCmp('xcontentwindow');
			if(!win) {
				var d = {
					animateTarget: evTarget ? evTarget.id : false,
					modal:false,
					autoLoad:{
						url:'/ajax/getphposcontent/'+sid,
						callback: function() {
							Ext.addBehaviors({
							   // add a listener for click on all anchors in element with id foo
							   '#xcontentwindow h3.expandable-header@click' : function(e, t){
								   // do something
								   FNK.displayDown(e,t);
							   }					
							});
						}
					},//'/ajax/getphposcontent/'+sid,
					id:'xcontentwindow',
					//minWidth:350,
					stateful:false,
					shadow:true,
					shadowOffset:8,
					shim:false,		
					bodyStyle:'padding: 10px 7px 10px 7px;',
					autoScroll:true,
					//waitMsgTarget:evTarget.id,
					//iconCls:'x-content-ico',
					closable:false,
					defaultButton:0,
					//border:false,
					//modal:true,
					//plain:true,
					buttons:[{
						 text: $L('close')
						,scope:this
						,handler:function(button) {
							button.ownerCt.close();
						}							
					}],				
					bodyCfg: {
						//tag: 'center',
						cls: 'outercontent'
					},
					cls:'x-friendnik'
					
				};
				
				if(typeof conf != 'object') var conf = {};
				o = Ext.apply(conf,d);
				
				var win = new Ext.Window(o);
			} else {
				win.load({
					url:'/ajax/getphposcontent/'+sid,
					callback: function() {
						Ext.addBehaviors({
						   // add a listener for click on all anchors in element with id foo
						   '#xcontentwindow h3.expandable-header@click' : function(e, t){
							   // do something
							   //DebugDump(t,'t');
						   }
						});						
					}
				});
				if(conf && conf.width) win.setWidth(conf.width);
				if(conf && conf.height) win.setHeight(conf.height);
				win.center();
			}
			win.show.defer(50, win,evTarget.id);
		
		} else {
		
		if(typeof conf != 'object') conf = {};

			default_conf = {
				width:400,
				height:600,
				autosize: true,
				topclose: true,
				overflow: 'auto',
				fullscreen: false
			};		
			
			var conf = Ext.apply(default_conf,conf);
			//DebugDump(conf,'conf');
			if(event) Event.stop(event);
			
			Lightview.show({
				href: '/ajax/getphposcontent/'+sid,
				rel: 'ajax',
				options: {
					autosize: conf.autosize,
					width: conf.width,
					height: conf.height,
					topclose: conf.topclose,
					myOverflow: conf.overflow,
					sid:sid,
					ajax: {
						onSuccess: function(transport) {
							//DebugDump(transport.responseText,'transport.responseText');
						},
						onComplete: function(a){
							//DebugDump(this,'onComplete this');
							//DebugDump(a,'onComplete a');
							//DebugDump(Lightview,'Lightview');
							if(Lightview.view.options.myOverflow == 'auto') { // dunno, why lightview is not doing it by it self :(
								var ic = $('phposcontent_'+Lightview.view.options.sid);
								ic.style.width = ((Lightview.view.options.width)-5)+'px';
								ic.style.height = ((Lightview.view.options.height)-15)+'px';
								ic.style.overflow = 'auto';
							}
						},
						parameters: {sid:sid,noxml:true}
					}
				}
			});		
		}
	}
	
	//---------------------------------------------------------------------------------------
	this.getContent = function(event,context,classname,sid) { // die hier is nich so dolle....
		
		switch(context) {
			case'contact':
				this.contactWindow(event,context,classname,sid);
				break;
			case'rqp':
				this.requestPasswordWindow(event,context,classname,sid);
				break;
			case'sendarticle':
			case'send':
				this.getAdviseWindow(event,context,classname,sid);
				break;
			default:
				// get ajax content
		}
	}

	this.contactWindow = function(event,t,c,sid) {
		Event.stop(event);
		Lightview.show({
			href: '/php-os/app_local/scripts/ajax_contact.php',
			rel: 'ajax',
			options: {
				autosize: true,
				topclose: true,
				ajax: {
					onSuccess: function(transport) {
						//DebugDump(transport.responseText,'transport.responseText');
					},
					onComplete: function(){
						// once the request is complete we observe the form for a submit
						$('adviseform').observe('submit', IF.submitContactWindow);
						if($('aam_email') && $('aam_email').value.length == 0) $('aam_email').focus();
						BB.clearOnFocus();
					},
					parameters: {t:t,c:c,sid:sid}
				}
			}
		});	
	}
	
	// lightview submit callback
	this.submitContactWindow = function(event) {
	  // block default form submit
	  Event.stop(event);
		  
	  Lightview.show({
		href: '/php-os/app_local/scripts/ajax_contact.php',
		rel: 'ajax',
		options: {
		  title: 'results',
		  menubar: false,
		  topclose: true,
		  autosize: true,
		  ajax: {
			parameters: Form.serialize('adviseform'), // the parameters from the form
			onComplete: function(){
				// once the request is complete we observe the form for a submit
				if($('adviseform')) $('adviseform').observe('submit', IF.submitContactWindow);
				BB.clearOnFocus();
			}	
		  }
		}
	  });
	}	
	
	this.requestPasswordWindow = function(event,t,c,sid) {
		
		if(this.overlays == 'ext') {

			if(event) var evTarget = this.gettarget(event); //'.x-grid3-row'
			var win = Ext.getCmp('rqp');
			if(!win) {
				var d = {
					animateTarget: evTarget ? evTarget.id : false,
					modal:false,
					//autoLoad:'/php-os/app_local/scripts/ajax_request_password.php',
					id: 'rqp',
					//minWidth:350,
					stateful:false,
					shadow:true,
					shadowOffset:8,
					shim:false,		
					bodyStyle:'padding:10px;',
					autoScroll:true,
					title:$L('request_password'),
					//waitMsgTarget:evTarget.id,
					//iconCls:'x-content-ico',
					closable:false,
					defaultButton:0,
					width:400,
					height:200,
					//border:false,
					//modal:true,
					//plain:true,
					items:[{
						id: 'rqpform',
						url:'/php-os/app_local/scripts/ajax_request_password.php',
						waitMsgTarget:'rqp',
						xtype:'requestpassword'
					}],
					buttons:[{
						 text: $L('cancel')
						,scope:this
						,handler:function(button) {
							button.ownerCt.close();
						}							
					},{
						 text: $L('send')
						,scope:this
						,handler:function(button) {
							var rqpform = Ext.getCmp('rqpform');
							rqpform.getForm().submit({
								params:{
									triggers:'ajaxrqp',
									noxml:'1'
								},
								failure:function(form,action){
									FNK.showMessage({
										bt: false,
										height:150,
										width:300,
										modal:true,
										iconCls:'x-horsesshuh-ico',
										title:$L('warning'),
										html: (action.result && action.result['errorText']) ? '<p class="winmsg">'+action.result['errorText']+'</p>' : '<p class="winmsg">'+$L('An error occured! Please use a valid eMail address...')+'</p>',
										defaultButton:0,
										y:300,
										buttons:[{
											 text: $L('ok')
											,scope:this
											,handler:function(button) {
												button.ownerCt.close();
											}							
										}]
									});										
								},
								success:function(form,action) {
									if(action.result && action.result.success) {
										FNK.showMessage({
											bt: false,
											height:150,
											width:300,
											iconCls:'x-horsesshuh-ico',
											title:$L('hint'),
											html:'<p class="winmsg">'+action.result['msg']+'</p>',
											defaultButton:0,
											y:300,
											buttons:[{
												 text: $L('ok')
												,scope:this
												,handler:function(button) {
													button.ownerCt.close();
												}							
											}]
										});
										
										Ext.getCmp('rqp').close();
										
									} else {
										FNK.showMessage({
											bt: false,
											modal:true,
											height:150,
											width:300,
											iconCls:'x-horsesshuh-ico',
											title:$L('warning'),
											html: (action.result && action.result['errorText']) ? '<p class="winmsg">'+action.result['errorText']+'</p>' : '<p class="winmsg">'+action.result['msg']+'</p>',
											defaultButton:0,
											y:300,
											buttons:[{
												 text: $L('ok')
												,scope:this
												,handler:function(button) {
													button.ownerCt.close();
												}							
											}]
										});	
									}
								},
								waitMsg:'Saving...'
							});
							//this.getForm().submit({params:{triggers:'ajaxsaverecord',noxml:'1'},failure:function(form,action){Ext.Msg.alert("Error", action.result.msg);},success:function(form,action){ Ext.getCmp(form.p_id).has_been_submitted = true; Ext.getCmp(form.win_id).close();}});'
							//IF.submitAjaxRequestPassword();
							//button.ownerCt.close();
							
						}							
					}],				
					bodyCfg: {
						//tag: 'center',
						cls: 'outercontent'
					},
					cls:'x-friendnik'
					
				};
				
				if(typeof conf != 'object') var conf = {};
				o = Ext.apply(conf,d);
				
				var win = new Ext.Window(o);
			}
			win.show.defer(50, win,evTarget.id);
			
		} else {
		
			Event.stop(event);
			Lightview.show({
				href: '/php-os/app_local/scripts/ajax_request_password.php',
				rel: 'ajax',
				options: {
					autosize: true,
					topclose: true,
					ajax: {
						onSuccess: function(transport) {
							//DebugDump(transport.responseText,'transport.responseText');
							
						},
						onComplete: function(){
							// once the request is complete we observe the form for a submit
							$('adviseform').observe('submit', IF.submitAjaxRequestPassword);
							if($('aam_email') && $('aam_email').value.length == 0) $('aam_email').focus();
						},
						parameters: {t:t,c:c,sid:sid}
					}
				}
			});		
		}
	}
	
	// lightview submit callback
	this.submitAjaxRequestPassword = function(event) {
	  // block default form submit
	  
	  if(this.overlays == 'ext') {
			Ext.Ajax.request({
				url: '/php-os/app_local/scripts/ajax_request_password.php',
				scope: this,
				success: function(response,options){
				var rData = Ext.util.JSON.decode(response.responseText);//passed back from server

				if(rData && rData.success) {
					this.showMessage({
						bt: this.bt ? this.bt.id : false,
						sid:sid,
						height:150,
						width:300,
						iconCls:'x-horsesshuh-ico',
						title:$L('hint'),
						html:'<p class="winmsg">'+rData['msg']+'</p>',
						defaultButton:0,
						y:300,
						buttons:[{
							 text: $L('ok')
							,scope:this
							,handler:function(button) {
								button.ownerCt.close();
							}							
						}]
					});
					
				} else {
					this.showMessage({
						bt: this.bt ? this.bt.id : false,
						sid:sid,
						height:150,
						width:300,
						iconCls:'x-horsesshuh-ico',
						title:$L('warning'),
						html: (rData && rData['errorText']) ? '<p class="winmsg">'+rData['errorText']+'</p>' : '<p class="winmsg">'+$L('An error occured! Probably your session expired...')+'</p>',
						defaultButton:0,
						y:300,
						buttons:[{
							 text: $L('ok')
							,scope:this
							,handler:function(button) {
								button.ownerCt.close();
							}							
						}]
					});					
					this.enable(options.bt);
				}					
				},
				failure: function(){
					
				},
				params: {noxml:'1',email: Ext.get('rqp_email').dom.value}
			});
	  
	  } else {
		  
		  Event.stop(event);
		  Lightview.show({
			href: '/php-os/app_local/scripts/ajax_request_password.php',
			rel: 'ajax',
			options: {
			  title: 'results',
			  menubar: false,
			  topclose: true,
			  autosize: true,
			  ajax: {
				parameters: Form.serialize('adviseform'), // the parameters from the form
				onComplete: function(){
					// once the request is complete we observe the form for a submit
					if($('adviseform')) $('adviseform').observe('submit', IF.submitAjaxRequestPassword);
				}	
			  }
			}
		  });
	  }
	}	
	
	// lightview submit form
	this.getAdviseWindow = function(event,t,c,sid) {

		Event.stop(event);
		Lightview.show({
			href: '/php-os/app_local/scripts/ajax_advise_mail.php',
			rel: 'ajax',
			options: {
				autosize: true,
				topclose: true,
				ajax: {
					onSuccess: function(transport) {
						//DebugDump(transport.responseText,'transport.responseText');
					},
					onComplete: function(){
						// once the request is complete we observe the form for a submit
						$('adviseform').observe('submit', IF.submitAjaxFormDemonstration);
						if($('aam_recipientmail') && $('aam_recipientmail').value.length == 0) $('aam_recipientmail').focus();
					},
					parameters: {t:t,c:c,sid:sid}
				}
			}
		});
	}

	// lightview submit callback
	this.submitAjaxFormDemonstration = function(event) {
	  // block default form submit
	  Event.stop(event);
		  
	  Lightview.show({
		href: '/php-os/app_local/scripts/ajax_advise_mail.php',
		rel: 'ajax',
		options: {
		  title: 'results',
		  menubar: false,
		  topclose: true,
		  autosize: true,
		  ajax: {
			parameters: Form.serialize('adviseform'), // the parameters from the form
			onComplete: function(){
				// once the request is complete we observe the form for a submit
				if($('adviseform')) $('adviseform').observe('submit', IF.submitAjaxFormDemonstration);
			}	
		  }
		}
	  });
	}
	
	
	
	//---------------------------------------------------------------------------------------
	
	this.windowPrint = function() {
		window.print();
	}
	
	this.printDonation = function(printform) {
		
		
		var firstformEL = false;
	//if (!def_printversion_available) return alert('Es ist keine Druckansicht f\u00FCr diese Seite verf\u00FCgbar...');
		var contentEL = document.getElementById('content');
		var contentforms = contentEL.getElementsByTagName('FORM');
		for (var i=0; i<contentforms.length; i++) { 
			if(contentforms[i]) { firstformEL = contentforms[i]; break; }
		}	
		
		if(firstformEL) {
			//var o_target = firstformEL.target;
			var o_action = firstformEL.action;
			//firstformEL.target = printform;
			firstformEL.action = printform;
		}
		this.printVersion();
		//window.print();
		if(firstformEL) {
			//firstformEL.target = o_target;
			firstformEL.action = o_action;	
		}
	}

	this.printVersion = function() {
		var firstformEL = false;
	//if (!def_printversion_available) return alert('Es ist keine Druckansicht f\u00FCr diese Seite verf\u00FCgbar...');
		var contentEL = document.getElementById('content');
		var contentforms = contentEL.getElementsByTagName('FORM');
		for (var i=0; i<contentforms.length; i++) { 
			if(contentforms[i]) { firstformEL = contentforms[i]; break; }
		}
		//firstformEL.submit();
		//alert(firstformEL.name);
		if(firstformEL) var Ppath = firstformEL.action;//parent.content.myPlainPagePath;
		else var Ppath = parent.content.myPlainPagePath;
		
		var Pname = "PrintVersion";
		var no_w = '/none';
		var no_w = checkUrl(no_w);
		var WHeight = GetWindowHeight()-100;
		mywin = window.open(no_w,Pname,"top=20,left=30,width=540,height="+WHeight+",scroll=yes,scrollbars=yes,titlebar=no,status=no,toolbar=no,location=no,directories=no,menubar=yes,resizable=yes");
		
		Ppath = Ppath+"?print=true";
		var Ppath = checkUrl(Ppath);		
		//spendenformulardrucken
		if(firstformEL) {
			
			var o_target = firstformEL.target;
			var o_action = firstformEL.action;
			//alert(o_target);
			firstformEL.target = Pname;
			firstformEL.action = Ppath;
			firstformEL.onsubmit(); // workaround browser bugs.
			firstformEL.submit();
			firstformEL.target = o_target;
			firstformEL.action = o_action;			
		} else {
			mywin.location.href =createUrl(Ppath);
		}
		
		
		
		/*if (document.forms[formname]) { // this part will be true from now on
			var createdTempHidden = false;
			if (document.createElement) {
				switch (SmartAgent){
					case "Netscape6":
					case "MSIE5.5":
					case "Opera5":
					case "Khtml":
						try {
							var tempFormObj;
							var tempHiddenObj;
							tempFormObj = parent.content.document.forms[0];
							var tempHidden = 	parent.content.document.createElement('input');
							tempHidden.setAttribute('type','hidden');
							tempHidden.setAttribute('name','print');
							tempHidden.setAttribute('value','true');
							tempHiddenObj = tempFormObj.appendChild(tempHidden);
							var createdTempHidden = true;
						} catch(e) {
							Ppath = Ppath+"?print=true";
						}
						break;
				case "Netscape4":
				case "MSIE5":
				default:
					var Ppath = Ppath+"?print=true";
					var Ppath = createUrl(Ppath);
					break;
				}
			} else {
				var Ppath = Ppath+"?print=true";
				var Ppath = createUrl(Ppath);
			}
			setActionAndSubmit(Pname,Ppath,'parent.content.document.forms[0]');
			if (createdTempHidden) tempFormObj.removeChild(tempHidden);
		} else {
			var Ppath = Ppath+"?print=true"; 
			mywin.location.href =createUrl(Ppath);
		}
		*/
		
		if(mywin) mywin.focus();
	}

	//---------------------------------------------------------------------------------------
	this.buildWindow = function() {
		
		// window
		//bodyroot = document.getElementsByTagName('form')[0];
		if(!document.getElementById('content')) return;
		bodyroot = document.getElementById('content');
		this.w_wrapper = document.createElement("div");	
		

		this.w_wrapper.id = 'window';
		this.w_wrapper.className = 'window';
		this.w_wrapper.style.position = 'absolute';
		//this.w_wrapper.style.display = 'none';
		this.w_wrapper.style.visibility = 'hidden';
		this.w_wrapper.width = 300;
		this.w_wrapper.height = 300;
		this.w_wrapper.style.width = this.w_wrapper.width+'px';
		this.w_wrapper.style.height = this.w_wrapper.height+'px';
		this.w_wrapper.style.overflow = 'auto';
		//this.w_wrapper.style.border = '1px solid black';
		//this.w_wrapper.style.backgroundColor = 'white';
		//this.w_wrapper.style.zIndex = 100000;
		WWidth = GetWindowWidth();
		WHeight = GetWindowHeight();
		dst = PAGEdom.docScrollTop();
		var topheight = (((WHeight+dst)/2)-(this.w_wrapper.height/2));
		if(topheight<133) topheight = 133;
		this.w_wrapper.style.top = topheight+'px';
		var leftwidth = ((WWidth/2)-(this.w_wrapper.width/2));
		if(leftwidth<250) leftwidth = 250;
		this.w_wrapper.style.left = leftwidth+'px';
		bodyroot.appendChild(this.w_wrapper);

		this.makeNewWndow();
				
	}
	
	this.makeNewWndow = function() {
		this.window = new ContentWindow(this.title,this.w_wrapper.id);
		this.window.client_area_id = 'windowclientarea';
		this.window.title_id = 'windowtitlearea';
		this.window.init(this.window);	
	}
	
	//---------------------------------------------------------------------------------------
	this.showMessage = function(o) {
		
		var d = {
			animEl: o.bt ? o.bt.id : false,
			modal:false,
			minWidth:350,
			stateful:false,
			shadow:true,
			shadowOffset:8,
			shim:false,
			closable:false,
			cls:'x-friendnik'
		};
		
		if(typeof o != 'object') var o = {};
		o = Ext.apply(o,d);
		
		var win = new Ext.Window(o);
		win.show.defer(50, win,[o.bt.id]);
		
	}	
	

	//---------------------------------------------------------------------------------------
	this.gettarget = function(event) {

		if(window
		&& (window.event)
		&& (window.event.srcElement)) {
			t = window.event.srcElement;
		} else {
			t = (event.target.tagName ? event.target : event.target.parentNode);
		}
		return t;
	}	
	

	//---------------------------------------------------------------------------------------
	this.addEvent = function(el,evname,func) {
	
		if (el.attachEvent) { // IE
			el.attachEvent("on" + evname, func);
		} else if (el.addEventListener) { // Gecko / W3C
			el.addEventListener(evname, func, true);
		} else {
			el["on" + evname] = func;
		}
	
	}
	
	//---------------------------------------------------------------------------------------
	this.removeEvent = function(el,evname,func) {
	
		if (el.detachEvent) { // IE
			el.detachEvent("on" + evname, func);
		} else if (el.removeEventListener) { // Gecko / W3C
			el.removeEventListener(evname, func, true);
		} else {
			el["on" + evname] = null;
		}
	
	}
}

IF = new Interface(); 
OnLoadFunctions[OnLoadFunctions.length] = "IF.init();";

var reg = 'phpos'; 
var is_phpos_environment = document.location.href.match(reg);
if(!is_phpos_environment) {
	browserSubmit = IF.browserSubmit;
	setDirPath = IF.setDirPath;
	changeDirPath = IF.changeDirPath;
}

//--------------------------------------------------------------------------------------- //
function checkSubmit() { // weiss nich, ob ich das brauche... ist der onsubmit gerade
	return true;
}
//--------------------------------------------------------------------------------------- //
function SmartBrowser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isOP    = false;  // Opera
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "Opera";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isOP = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as Netscape 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }

  s = "MSIE";
  if ((i = ua.indexOf(s))) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
}

var SMbrowser = new SmartBrowser();
//--------------------------------------------------------------------------------------- //
function Friendnik () {
	
	this.init = function() {
		

		//setTimeout(function(){this.initCarousel();}.bind(this), 500);
		this.initCarousel();
		
		FancyForm.start();
		this.clearOnFocus();
		
		// init service link handling
		if($('servicenik')) {
			$('servicenik').value = $L('your_nik_at_this_site');
			$('servicelink').value = $L('new_link_to');
			$('servicenik').value = $L('your_nik_at_this_site');
			$('servicenik').observe(
				'keyup',function(event) {
					FNK.liveLink(event);
				}
			);
			
		}
		
		if($('prfcol1')) {
			this.fixContentHeight();
		}
		
		$$('form label').each(function(e) {
			e.observe('click', switchSelectAll4Label);
		});
		
		// preload wait image
		/*Preloaded1 = new Image();
		Preloaded1.src = '/javascripts/ext/resources/images/default/grid/loading.gif';	*/	
		Preloaded2 = new Image();
		Preloaded2.src = '/local/media/images/loading/circle.gif';	
		Preloaded3 = new Image();
		Preloaded3.src = '/local/media/images/loading/run.png';			

		Ext.addBehaviors({
		   // add a listener for click on all anchors in element with id foo
		   '#xcontentwindow h3@click' : function(e, t){
			   // do something
			   // DebugDump(t,'t');
		   }
		   //,
			
		 	/*  // add the same listener to multiple selectors (separated by comma BEFORE the @)
		   '#foo a, #bar span.some-class@mouseover' : function(){
			   // do something
		   }*/	
		});	
		
		// Quicksearch
		if(Ext.get('ff')) {
			var ff = Ext.get('ff');
			var orgValue = ff.getValue();
			ff.remove();
			// find friends
		   var ds = new Ext.data.Store({
				proxy: new Ext.data.HttpProxy({
					url: '/php-os/app_local/scripts/ajax_usersearch.php'
				}),
				reader: new Ext.data.JsonReader({
					totalProperty: 'totalCount',
					root: 'records',
					id: 'nickname'
				},[
					{name: 'nickname', mapping: 'nickname'},
					{name: 'fullname', mapping: 'fullname'},
					{name: 'tpl', mapping: 'tpl'},
					{name: 'hgl_friend_class', mapping: 'hgl_friend_class'}
					//,{name: 'reg_timestamp', mapping: 'reg_timestamp', type: 'date', dateFormat: 'timestamp'}
				])
			});
		
			// Custom rendering Template
			var resultTpl = new Ext.XTemplate(
				'<tpl for="."><div class="ff-search-item{hgl_friend_class}">',
					'{tpl}<div class="fixfloat"></div>',//'<h3><span>{fullname}</span>{nickname}</h3>', //{reg_timestamp:date("M j, Y")}<br />by 
				'</div></tpl>'
			);			
			var converted = new Ext.form.ComboBox({
				ctCls:'ffs-wr',
				emptyText:$L('find_friends'),
				value: orgValue,
				displayField:'title',
				name:'f',
				typeAhead: false,			
				cls:'sff-cls',
				triggerAction: 'all',
				id:'xff',
				minChars:3,
				renderTo:'sff',
				itemCls:'sff-itemcls',
				focusClass:'on-focus',
				style:'font-size:12px;',
				hideLabel:true,
				hideTrigger:true,
				tpl: resultTpl,
				loadingText: $L('Searching...'),
				store: ds,
				enableKeyEvents:true,
				in_list:false,
				itemSelector: 'div.ff-search-item',
				/*onSelect: function(record){ // override default onSelect to do redirect
					if(record.data.nickname == 'close') {
						
					} else if(record.data.nickname.length == 0) {
						var v = Ext.getCmp('xff').getValue();
						window.location.href='/find?f='+v;
					} else window.location = String.format('/profile/{0}', record.data.nickname);
				},*/
				onLoad:function(c,r,o){
					this.in_list=false;
					if(!this.hasFocus){
							return;
					}
					if(this.store.getCount() > 0){
						this.expand();
						this.restrictHeight();
						if(this.lastQuery == this.allQuery){
							if(this.editable){
								this.el.dom.select();
							} 
						}
					} 
					else {
						this.onEmptyResults();
					} 
				},
				onBlur:function(){
					if (this.inKeyMode) this.collapse();
				},	
				listeners: {
					'keypress':{fn:function(c,e){
						if(typeof e == 'undefined' || !e) return true;
						var obj = e.target || e.srcElement;
						var v = c.getValue();
						if(e.keyCode == 38 || e.keyCode == 40) { // up and down
							c.in_list = true;
						} else if(c.in_list == false && e.keyCode == 13 && v && v.length > 2){
							window.location.href='/find?f='+v;
						} else {
							c.in_list = false;
						}
					}},
					'select':{fn:function(c,record,i){
						c.in_list = true; // this is maybe to much... ? we will see

						if(record.data.nickname == 'close') {
							c.collapse();
						} else if(record.data.nickname.length == 0) {
							var v = Ext.getCmp('xff').getValue();
							window.location.href='/find?f='+v;
						} else window.location = String.format('/profile/{0}', record.data.nickname);
						
					}}
				},
				width:200
			});		
		}
		

	}
	
	this.initCarousel = function() {
		if($('carousel') && (typeof carousel_items == 'object')) {
			//DebugDump(carousel_items,'carousel_items '+carousel_items.length);
			//http://extjs-ux.org/docs/?class=Ext.ux.layout.Carousel
			new Ext.Panel({
				id:'my1carousel',
				renderTo: 'carousel',
				height:65,
				width:345,	
				cls:'x-friendnik x-icarousel',
				layoutConfig: {					
					pagedScroll: true,
					loopCount:1,
					//loopPictureDelay:0.25
					scrollButtonPosition:'split',
					scrollDuration:0.15,
					marginScrollButtons: 1						
				},				
				layout: 'carousel',
				items: carousel_items 				
			});		
		}	
	}
	
	// deny submit, on searches with less than 2 chars	
	this.checkFriendsFormLength = function(event) {
		
		if(typeof event == 'undefined' || !event) return true;

		var obj = event.target || event.srcElement;
		if((event.type == 'keypress' && event.keyCode == 13 ) || (event.type == 'submit')) {
			if($('xff') && $('xff').value.length < 2) {
				if ( event.preventDefault )
					event.preventDefault()
				else event.returnValue = false;		
			}
			else if($('ff') && $('ff').value.length < 2) {
				if ( event.preventDefault )
					event.preventDefault()
				else event.returnValue = false;		
			}
		}
		return true;
	}
	
	//---------------------------------------------------------------------------------------
	
	this.showNoLinksHint = function() {
		var mylinks = Ext.get('tm1769');// my links
		var pos = mylinks.getXY();
		var insert = '<img src="/local/media/images/text/links-not-entered-notice-'+lang+'.gif" style="position:absolute;top:-335px;left:'+(pos[0]-30)+'px;" id="nolinkshint" width="268" height="117" />'; //display:none;
		var dh = Ext.DomHelper;
		var el = dh.insertFirst('globalWrapper',insert,true);
		setTimeout(function(){this.reallyShowNoLinksHint(el,pos);}.bind(this), 1500);
	}
	
	this.reallyShowNoLinksHint = function(el,pos) {
		el.shift({
			y: (pos[1]-120),
			opacity: 1,
			easing: 'easeIn',
			duration: .35
		});
		setTimeout(function(){this.hideShowNoLinksHint(el,pos);}.bind(this), 30000);
	}
	
	this.hideShowNoLinksHint = function(el,pos) {
		el.switchOff({
			easing: 'easeOut',
			duration: .5,
			remove: false,
			useDisplay: false		
		});
	}
	
	//---------------------------------------------------------------------------------------
	this.fixContentHeight = function() {
		var h = $('prfcol1').offsetHeight;
		var h2 = $('prfcol2').offsetHeight;
		if(h > h2) {
			$('prfcol2').style.height = h+'px';
		}
	}
	
	//---------------------------------------------------------------------------------------
	this.clearOnFocus = function() {
		/**
		* Clears all input/textareas with classname "clearonfocus"
		* on focus-Mouseevent.
		*/
		$$('.cof').each(function(input) {
			input._defaultValue = input.readAttribute('title');
			input.observe('focus', function(ev) {
				if(input.value == input._defaultValue) {
					input.value = '';
				}
				input.addClassName('on-focus');
			});
			input.observe('blur', function(ev) {
				if(input.value == '') {
					input.value = input._defaultValue;
				}
				input.removeClassName('on-focus');				
			});
			
		});	
	}
	
	//---------------------------------------------------------------------------------------
	this.inputValues = new Array();
	/*
	 * clearOnFocusSA = StandAlone - to be called in html onfocus 
	 */
	this.clearOnFocusSA = function(input) {
	  $(input).addClassName('on-focus');
	  if(this.inputValues[$(input).getAttribute('id')] == null) {
	  	var l_code = $(input).getAttribute('rel');
	  	var value = $(input).value;
	  	if(value != $L(l_code)) return false;
		this.inputValues[$(input).getAttribute('id')] = value;
		$(input).value = '';
	  }
	}
	
	/*
	 * fillOnBlurSA = StandAlone - to be called in html onblur
	 * fills the element with the value stored in Array inputValues[]
	 */
	this.fillOnBlurSA = function(input) {
	  $(input).removeClassName('on-focus');
	  if(input.value == '' && this.inputValues[$(input).getAttribute('id')] != null) {
		$(input).value = this.inputValues[$(input).getAttribute('id')];
		delete this.inputValues[$(input).getAttribute('id')];
	  }
	}
	//---------------------------------------------------------------------------------------
	this.switchToPassword = function(input, target) {
	  Element.hide(input);
	  Element.show(target);
	  Element.removeClassName($(target), 'invisible');
	  $(target).focus();
	  $(target).addClassName('on-focus');
	  $(input).addClassName('on-focus');
	  /*var inputE = $(input);
	  var tabindex = inputE.getAttribute('tabindex');
	  inputE.removeAttribute('tabindex');
	  Element.writeAttribute(target, 'tabindex', tabindex);
		*/
	}
	
	this.switchToTextfield = function(input, target) {
	 
	  if(input.value.length == 0) {
		Element.hide(input);
		Element.show(target);
		/*var inputE = $(input);
		var tabindex = inputE.getAttribute('tabindex');
		inputE.removeAttribute('tabindex');
		$(target).setAttribute('tabindex', tabindex);
	  	*/
	  }
	  $(target).removeClassName('on-focus');
	  $(input).removeClassName('on-focus');
	}
	
	//---------------------------------------------------------------------------------------
	// Verzögerung !! 
	this.nick_timer = 0;
	this.checkNickname = function(ev,el) {
		// onkeyup - verzögerung
		if(this.nick_timer) {
			clearTimeout(this.nick_timer);
			this.nick_timer = setTimeout(function(){this.do_checkNickname(ev,el);}.bind(this), 500);
		} else {
			this.nick_timer = setTimeout(function(){this.do_checkNickname(ev,el);}.bind(this), 500);
		}	
	}

	this.do_checkNickname = function(ev,el) {
		
		// check if nickname available
		if((!el) || (!el.value) || el.value.length == 0) return false;
		$(el.id).style.backgroundImage = 'none';
		$(el.id).style.backgroundPosition = 'right 8px';
		$(el.id).style.backgroundRepeat = 'no-repeat';
		if($(el.id).hasClassName('on-focus')) {
			var indImg = '/images/interface/ajax-loader_bgrey.gif';
		} else {
			var indImg = '/images/interface/ajax-loader_bw.gif';
		}
		$(el.id).style.backgroundImage = 'url("'+indImg+'")';
		
		var url = '/php-os/app_local/scripts/ajax_check_username.php';		
		Ext.Ajax.request({
			url: url,
			success: function(response,options){
				var responseData = Ext.util.JSON.decode(response.responseText);//passed back from server
				if(responseData.success != true) {
					$(el.id+'_error').innerHTML = responseData.errors;
					$(el.id).addClassName('error');
				} else {
					$(el.id).removeClassName('error');
					$(el.id+'_error').innerHTML = '&nbsp;';
				}
				$(el.id).style.backgroundImage = 'none';
				//setTimeout(function(){$(el.id).style.backgroundImage = 'none';}.bind(this), 500)
			},
			failure: function(response,options){ 
				$(el.id).style.backgroundImage = 'none';
			},
			params: {nickname:el.value}
		});			
	}
	
	
	//---------------------------------------------------------------------------------------
	// Profile Functions
	//---------------------------------------------------------------------------------------	
	

	
	this.btid = 1;
	this.beMyFriend = function(sid,button) {
		
		var btid = 'button'+this.btid;
		this.btid++;
		var send_a_message = false;
		
		if(send_a_message == true) {
			this.showMessage({
				bt:button,
				sid:sid,
				height:300,
				width:300,
				iconCls:'x-horsesshuh-ico',
				title:$L('friendshiprequest'),
				html:'<p class="winmsg">'+$L('shure_you_wish_this_friendship')+'</p>',
				defaultButton:1,
				y:300,
				items:[new Ext.form.FormPanel({
					id: 'bemyfriendform',
					labelAlign:'top',
					style:'padding: 5px 5px 0 5px;',
					items: [{
						xtype:'hidden',
						name: 'friend_sid',
						value: sid
					},{
						xtype:'textarea',
						fieldLabel:$L('bemyfriend_msg_label'),
						hideLabel:false,
						labelAlign:'top',
						height:100,
						name: 'message',
						id: 'friend_msg',
						anchor:'100%',
						emptyText:$L('default_be_my_friend_msg'),
						allowBlank:true
					}]				
				})],
				buttons:[{
					 text: $L('cancel')
					,scope:this
					,handler:function(button) {
						button.ownerCt.close();
					}							
				},{
					 text: $L('yes')
					,scope:this
					,handler:function(button) {
						bemyfriendformpanel = Ext.getCmp('bemyfriendform');
						var values = bemyfriendformpanel.getForm().getValues();
						button.ownerCt.close();
						this.reallyBeMyFriend(sid,button.ownerCt.bt,values);
					}							
				}]
			});
			
		} else {
			this.showMessage({
				bt:button,
				sid:sid,
				height:150,
				width:300,
				iconCls:'x-horsesshuh-ico',
				title:$L('friendshiprequest'),
				html:'<p class="winmsg">'+$L('shure_you_wish_this_friendship')+'</p>',
				defaultButton:1,
				y:300,
				buttons:[{
					 text: $L('cancel')
					,scope:this
					,handler:function(button) {
						button.ownerCt.close();
					}							
				},{
					 text: $L('yes')
					,scope:this
					,handler:function(button) {
						button.ownerCt.close();
						this.reallyBeMyFriend(sid,button.ownerCt.bt,false);
					}							
				}]
			});
		}
		//this.reallyBeMyFriend(sid,button);
		
	}
	
	this.reallyBeMyFriend = function(sid,button,values) {

		this.disable(button);
		var post = '';
		post += 'fields[friend_sid]=' + URLEncode(sid);
		if(typeof values == 'object') post += 'fields[friend_msg]=' + URLEncode(values.message);
		post += '&control[method]=bemyfriend';
		post += '&control[class]=friend';
		
		
		var url = '/php-os/app_local/scripts/update.php';		
		Ext.Ajax.request({
			scope:this,
			method:'post',
			bt:button,
			url: url,
			success: function(response,options){
				var rData = Ext.util.JSON.decode(response.responseText);//passed back from server
				
				this.hideMessage(options.bt.id);
				if(rData && rData.msg) {
					this.setMissionMessage('1',rData['msg']);
				}
				/*var rData = Ext.util.JSON.decode(response.responseText);//passed back from server

				if(rData && rData.success) {
					this.showMessage({
						bt: this.bt ? this.bt.id : false,
						sid:sid,
						height:150,
						width:300,
						iconCls:'x-horsesshuh-ico',
						title:$L('hint'),
						html:'<p class="winmsg">'+rData['msg']+'</p>',
						defaultButton:0,
						y:300,
						buttons:[{
							 text: $L('ok')
							,scope:this
							,handler:function(button) {
								button.ownerCt.close();
							}							
						}]
					});
					
				} else {
					this.showMessage({
						bt: this.bt ? this.bt.id : false,
						sid:sid,
						height:150,
						width:300,
						iconCls:'x-horsesshuh-ico',
						title:$L('warning'),
						html: (rData && rData['errorText']) ? '<p class="winmsg">'+rData['errorText']+'</p>' : '<p class="winmsg">'+$L('An error occured! Probably your session expired...')+'</p>',
						defaultButton:0,
						y:300,
						buttons:[{
							 text: $L('ok')
							,scope:this
							,handler:function(button) {
								button.ownerCt.close();
							}							
						}]
					});					
					this.enable(options.bt);
				}*/
			},
			failure: function(response,options){ 
				this.showMessage({
					bt: this.bt ? this.bt.id : false,
					sid:sid,
					height:150,
					width:300,
					iconCls:'x-horsesshuh-ico',
					title:$L('warning'),
					html: '<p class="winmsg">'+$L('An error occured! Please try again later..')+'</p>',
					defaultButton:0,
					y:300,
					buttons:[{
						 text: $L('ok')
						,scope:this
						,handler:function(button) {
							button.ownerCt.close();
						}							
					}]
				});					
				this.enable(options.bt);
			},
			params: post
		});	
		
	}
	
	
	this.fs_messages = 0;
	this.setFriendshipStatus = function(sid,button,flag_type) {
		this.disable(button);
		var post = '';
		post += 'fields[sid]='+URLEncode(sid);
		post += '&fields[flag_type]='+URLEncode(flag_type);
		post += '&control[method]=setfriendstatus';
		post += '&control[class]=friend';
		
		var url = '/php-os/app_local/scripts/update.php';	
		Ext.Ajax.request({
			scope:this,
			method:'post',
			bt:button,
			sid:sid,
			url: url,
			success: function(response,options){
				var rData = Ext.util.JSON.decode(response.responseText);//passed back from server
				//if(typeof console == 'object') console.log(response.responseText,response);
				if(rData && rData.success !== false) {
					this.hideMessage('request'+options.sid);
					var requestmessages = Ext.get('requestmessages');//$('requestmessages');
					var insert = '<div style="display:none;" id="fsmsg'+this.fs_messages+'">'+rData['msg']+'</div>';
					this.fs_messages++;
					var dh = Ext.DomHelper;
					var el = dh.insertFirst('requestmessages',insert,true);

					el.slideIn('t',{
						easing: 'easeIn',
						duration: .5,
						scope:this,
						useDisplay: true
					});			
					
					// countdown down
					var counter = $('fsrnum').innerHTML;
					var counter = parseInt(counter);
					if(counter >0) counter--;
					$('fsrnum').innerHTML = counter;
					
				} else {
					this.showMessage({
						bt: this.bt ? this.bt.id : false,
						sid:sid,
						height:150,
						width:300,
						iconCls:'x-horsesshuh-ico',
						title:$L('warning'),
						html: (rData && rData['errorText']) ? '<p class="winmsg">'+rData['errorText']+'</p>' : '<p class="winmsg">'+$L('An error occured! Probably your session expired...')+'</p>',
						defaultButton:0,
						y:300,
						buttons:[{
							 text: $L('ok')
							,scope:this
							,handler:function(button) {
								button.ownerCt.close();
							}							
						}]
					});		
					this.enable(options.bt);
					
				}
			},
			failure: function(response,options){ 
				this.showMessage({
					bt: this.bt ? this.bt.id : false,
					sid:sid,
					height:150,
					width:300,
					iconCls:'x-horsesshuh-ico',
					title:$L('warning'),
					html: '<p class="winmsg">'+$L('An error occured! Please try again later..')+'</p>',
					defaultButton:0,
					y:300,
					buttons:[{
						 text: $L('ok')
						,scope:this
						,handler:function(button) {
							button.ownerCt.close();
						}							
					}]
				});				
				this.enable(options.bt);
				
			},
			params: post
		});			
		
		
	}
	
	this.deleteConnection = function(sid,button) {

		this.showMessage({
			bt:button,
			sid:sid,
			height:150,
			width:300,
			iconCls:'x-horsesshuh-ico',
			title:$L('warning'),
			html:'<p class="winmsg">'+$L('shure_you_wish_to_delete_this_connection')+'</p>',
			defaultButton:0,
			y:300,
			buttons:[{
				 text: $L('cancel')
				,scope:this
				,handler:function(button) {
					button.ownerCt.close();
				}							
			},{
				 text: $L('yes')
				,scope:this
				,handler:function(button) {
					button.ownerCt.close();
					this.reallyDeleteConnection(sid,button.ownerCt.bt);
				}							
			}]
		});
	
	}
	
	this.reallyDeleteConnection = function(sid,button) {
		this.disable(button);
		
		var post = '';
		post += 'fields[sid]='+URLEncode(sid);
		//post += '&fields[flag_type]='+URLEncode(button.value);
		post += '&control[method]=deletefriendstatus';
		post += '&control[class]=friend';
		
		this.hideMessage('con'+sid);
		
		var url = '/php-os/app_local/scripts/update.php';		
		Ext.Ajax.request({
			scope:this,
			method:'post',
			bt:button,
			sid:sid,
			url: url,
			success: function(response,options){
				var rData = Ext.util.JSON.decode(response.responseText);//passed back from server

				if(rData && rData.success !== false) {
					//this.hideMessage('con'+options.sid);
					// countdown down
					var counter = $('recordscount').innerHTML;
					var counter = parseInt(counter);
					if(counter >0) counter--;
					$('recordscount').innerHTML = counter;
					
				} else {
					this.showMessage({
						bt: this.bt ? this.bt.id : false,
						sid:sid,
						height:150,
						width:300,
						iconCls:'x-horsesshuh-ico',
						title:$L('warning'),
						html: (rData && rData['errorText']) ? '<p class="winmsg">'+rData['errorText']+'</p>' : '<p class="winmsg">'+$L('An error occured! Please try again later...')+'</p>',
						defaultButton:0,
						y:300,
						buttons:[{
							 text: $L('ok')
							,scope:this
							,handler:function(button) {
								button.ownerCt.close();
							}							
						}]
					});		
					this.enable(options.bt);
				}
			},
			failure: function(response,options){ 
				this.showMessage({
					bt: this.bt ? this.bt.id : false,
					sid:sid,
					height:150,
					width:300,
					iconCls:'x-horsesshuh-ico',
					title:$L('warning'),
					html: '<p class="winmsg">'+$L('An error occured! Please try again later..')+'</p>',
					defaultButton:0,
					y:300,
					buttons:[{
						 text: $L('ok')
						,scope:this
						,handler:function(button) {
							button.ownerCt.close();
						}							
					}]
				});					
				this.enable(options.bt);
				
			},
			params: post
		});					
	}

	this.order = function(s,t) {
		
		var active = $('order').value;
		if(s != active) {
			$('order_'+active).removeClassName('active');
			$('order_'+active).addClassName('inactive');
			$('order_'+s).removeClassName('inactive');
			$('order_'+s).addClassName('active');
			$('order').value = s;
			if($('order_'+s).hasClassName('sort-asc')) {
				$('order_dir').value = 'asc';
			} else {
				$('order_dir').value = 'desc';			
			}			
		} else {
			if($('order_'+s).hasClassName('sort-asc')) {
				$('order_'+s).removeClassName('sort-asc');
				$('order_'+s).addClassName('sort-desc');
				$('order_dir').value = 'desc';
			} else {
				$('order_'+s).removeClassName('sort-desc');
				$('order_'+s).addClassName('sort-asc');
				$('order_dir').value = 'asc';			
			}
		}
		
		IF.justSubmit('contentform');
	}	
	
	//---------------------------------------------------------------------------------------
	//---------------------------------------------------------------------------------------
	this.services = {}; this.servicesopen = false; this.hasChanges = false; // formname

	
	this.check4Changes = function(e) {
		
		if(this.hasChanges !== false) {
			
			var tEl = IF.gettarget(e);

			this.showMessage({
				bt: tEl ? tEl : false,
				tEl:tEl,
				height:150,
				width:300,
				iconCls:'x-horsesshuh-ico',
				title:$L('hint'),
				html:'<p class="winmsg">'+$L('you_have_unsaved_changes')+'</p>',
				defaultButton:2,
				y:300,
				buttons:[{
					 text: $L('cancel')
					,scope:this
					,handler:function(button) {
						//FNK.hasChanges = false;
						button.ownerCt.close();
						//location.href = tEl.getAttribute('href');
					}							
				},{
					 text: $L('donot_save')
					,scope:this
					,handler:function(button) {
						FNK.hasChanges = false;
						button.ownerCt.close();
						location.href = tEl.getAttribute('href');
					}							
				},{
					 text: $L('save_changes')
					,scope:this
					,handler:function(button) {
						button.ownerCt.close();
						IF.justSubmit(FNK.hasChanges);
					}							
				}]
			});
						
			return false;
		}
		return true;
	}
	
	//---------------------------------------------------------------------------------------
	this.getServices = function(ev,el) {
		
		if(this.servicesopen == true) return false;
		this.servicesopen = true;
		if(!this.plus_services) this.plus_services = Ext.get('plus_services');
		var services = Ext.get('services');
		setTimeout(function(){ Ext.get('servicelink').blur(); }, 500);
		
		//services.setOpacity(0);
		window.scrollTo(0, 0);
		services.setStyle('display','');
		var s = services.getSize();
		var sv_input = Ext.get('contentWrapper');
		var pos = sv_input.getXY();
		var xPos = 5;
		height = ((pos[1]-s.height)+sv_input.getHeight()) -5;
		if(height < 170) height = 100;
		var height = 100;
		
		var bd = Ext.getBody();
		var m = bd.mask();
		var bdPos = bd.getViewSize();
		
		if((s.height+height) > bdPos.height) {
			var servicescontainer = Ext.get('servicescontainer');
			services.setHeight((bdPos.height-height-30));
			services.setWidth((s.width+20));
			var xPos = 10;
			servicescontainer.setHeight((bdPos.height-height-100));
			servicescontainer.setStyle('overflow','auto');
		}
		services.setXY([(pos[0]-xPos),height]);
		services.slideIn('t',{
			useDisplay:true,
			easing: 'easeIn',
			duration: 1
		});		
	}
	
	// register services
	this.addService = function(s,o) {
		this.services[s] = o;
		// set and select privacy
		if($('privacy'+s)) {
			$('privacy'+s).value = o.visibility;			
		}
	}
	
	this.activeService = false; this.defServicelinkHint = false;
	this.setService = function(o) {
		
		this.activeService = o;
		
		// set sid, name and url
		//$('servicelink').disabled=false;
		this.servicesopen = false;
		$('servicelink').value = this.activeService.desc;
		if(!this.defServicelinkHint) this.defServicelinkHint = $('servicelink_hint').innerHTML;
		$('servicelink_hint').innerHTML = str_replace('#nik#', '-YOUR-USERNAME-', this.activeService.url);

		// hide services
		var services = Ext.get('services');
		services.slideOut('t',{
			useDisplay:true,
			//endOpacity: 0,
			easing: 'easeOut',
			duration: 1,
			scope:this,
			callback:function() {
				// focus to nik 
				Ext.getBody().unmask();
				$('servicenik').value = '';
				setTimeout(function(){ Ext.get('servicenik').focus(); }, 500); // ie crashes or makes no focus... ?
				this.progress_blink_plus = true;
				//this.blinkPlus();
			}
		});	
	}
	
	// blink plus	
	this.progress_blink_plus = true;
	this.blinkPlus = function() {
		//plus_services
		if(!this.progress_blink_plus) return;

		this.plus_services.fadeOut({
			useDisplay:true,
			endOpacity: 0,
			concurrent:true,
			easing: 'easeIn',
			duration: 2,
			scope:this,
			callback:function() {
				this.plus_services.fadeIn({
					useDisplay:true,
					endOpacity: 1,
					//startOpacity: 0.2,
					concurrent:true,
					easing: 'easeOut',
					scope:this,
					duration: 2,
					callback:function() {
						//this.plus_services.pause(1);
						this.blinkPlus();
					}
				});
			}
		});		
	}
	
	this.liveLink = function(ev) {
		if(this.activeService) {
			if(ev.keyCode == 13) {
				this.addServiceLink();
				return false;
			}
			if(this.activeService) {
				$('servicelink_hint').innerHTML = str_replace('#nik#',$('servicenik').value, this.activeService.url);
			}
		} else {
			this.getServices();
			setTimeout(function(){ Ext.get('servicenik').blur(); }, 500);
		}
	}
	
	this.createServiceTitle = function(s,nik) {
		switch(s.flag_type) {
			default:
				var pUrl = str_replace('#nik#',nik, s.url); // create url
				var title = s.desc+', '+nik;
				if(s.flag_online_profile == 'y') {
					var wUrl = str_replace('http://','',pUrl); // create url
					var t = '<a href="'+pUrl+'" target="_blank">'+wUrl+'</a>';
				} else {
					var t = title;
				}
		}
		
		s.nik = nik;
		return t;
		
	}
	
	this.getRowField = function(sid,fd) {
		if(!$('userservice'+sid)) return false;
		var sid_el = $('userservice'+sid).select('input.'+fd); // get sid
		return sid_el[0]; // set sid			
	}
	
	this.addServiceLink = function() {
		
		var nik = $('servicenik').value;
		if(nik.length < 2) return false;

		if(this.activeService) {
			
			this.progress_blink_plus = false;
			
			// url
			var url = ''; // not needed anymore
			var title = this.createServiceTitle(this.activeService,nik);
			var user_sid = '';
			if($('fields_root_editor_sid')) user_sid = $('fields_root_editor_sid').value;
			
			if($('userservice'+this.activeService.sid) && (1==2)) { // if this service exists
				var acs = this.activeService.sid;
				//idx = $('userservice'+acs).getAttribute('rel'); // get and set index
				idx = this.services[acs].idx; // geht beides
				
				// save and set nik value
				$('servicetitle'+acs).innerHTML = title; // update title
				//this.services[acs].nik = nik;
				var nikEl = this.getRowField(acs,'nik');
				nikEl.value = nik;
				var sidEl = this.getRowField(acs,'sid');
				
				// update!!!
				// save service
				var post = '';
				post += '&control[method]=updateObj';
				post += '&control[class]=usersocial';
				post += '&fields[sid]='+sidEl.value;
				post += '&fields[nik]='+nik;
				var url = '/php-os/app_local/scripts/update.php';		
				Ext.Ajax.request({
					scope:this,
					method:'post',
					activeService:this.activeService,
					idx:idx,
					url: url,
					success: function(response,options){
						// success message
						// success message
						var responseData = Ext.util.JSON.decode(response.responseText);//passed back from server
						if(responseData && responseData.msg && responseData.msg.length > 0) {
							this.setMissionMessage(1,responseData.msg);
						}							
					},
					failure: function(response,options){ 
						// failure
					},
					params: post
				});						
				
			} else { // create new service 
				
				var template = '';
				if(this.activeService.img_src.length > 0) {
					template += '<img src="{7}" alt="{8}" style="vertical-align:bottom;" /> ';
				}
				template += '<span id="servicetitle{5}">{1}</span>';
				template += '<input type="text" id="ieNik{5}" name="{2}[{5}][ienik]" value="{4}" style="display:none;" class="rounded-corners size-small" />';
				template += '<img id="ieNikAccept{5}" src="/local/media/images/form/accept.png" onclick="FNK.rUpdateServiceLink(event,{5},{})" style="display:none;" class="accept-img" />'
				template += '<input type="hidden" class="sid" name="{2}[{5}][sid]" id="fields_root_editor_add_links_{5}_sid" value="{3}" />';
				//template += '<input type="hidden" name="{2}[{5}][user_sid]" id="fields_root_editor_add_links_{5}_user_sid" value="'+user_sid+'" />'; // do I need this? should be allways editor->fields[sid]
				template += '<input type="hidden" name="{2}[{5}][social_sid]" id="fields_root_editor_add_links_{5}_social_sid" value="{6}" />';
				template += '<input type="hidden" class="nik" name="{2}[{5}][nik]" id="fields_root_editor_add_links_{5}_nik" value="{4}" />';
				template += '<span class="visibleSetting">'; //+$L('visible_to_title')+': '
				template += '<a href="#" onclick="IF.getPHPOSContent(event,19,{width:400,height:400,autosize:false,overflow:\'auto\'}); return false;" class="help">[?]</a> ';
				template += '<select name="{2}[{5}][visibility]" class="rounded-corners" id="privacy{5}" onchange="FNK.setServicePrivacy(event,\'{5}\')">';
				template += '<option value="everyone">'+$L('Everyone')+'</option>';
				template += '<option value="registered">'+$L('Registered_Only')+'</option>';
				template += '<option value="friends">'+$L('Friends_Only')+'</option>';
				template += '<option value="me">'+$L('Me_Only')+'</option>';
				template += '</select> ';
				template += '</span>';
				template += '<img class="edit" onclick="FNK.editServiceLink({5});" src="/images/icons/edit.gif" alt="'+$L('edit')+'" title="'+$L('edit_entry')+'" />';
				template += '<img id="deletelink{5}" class="delete" src="/images/icons/delete-opaq.gif" alt="'+$L('delete')+'" title="'+$L('delete_entry')+'" />';
				
				// 0 $list_link_url
				// 1 $list_link_title
				// 2 $LIST_POST_KEYB
				// 3 $list_sid
				// 4 $list_nik
				// 5 idx
				// 6 list_social_sid	
				// 7 img_src	
				// 8 social desc

				var userservice_sid = 'new';
				var all = $$('p.count-list'); // get all services
				if(all && all.length > 0) idx = all.length;
				else idx = 0;
				
				var t = String.format(template,url,title,'fields[root.browser]',userservice_sid,$('servicenik').value,idx,this.activeService.sid,this.activeService.img_src,this.activeService.desc); //fields[root.editor][add_links]
				
				// create new service, class="link-list" id="userservice${list_sid}"
				if($('userservice'+idx)) {
					
					var newService = $('userservice'+idx);
					newService.innerHTML = t;
				} else {
					
					var newService = document.createElement("p");
					newService.className = 'link-list count-list';
					//newService.addClassName('link-list'); //newService.addClassName('count-list');
					newService.setAttribute('rel',idx);
					newService.id = 'userservice'+idx;
					newService.innerHTML = t;
					$('userservicelinks').appendChild(newService);
				}
				
				// save service
				this.services[idx] = this.activeService;
				this.services[idx].idx = idx;
				this.services[idx].nik = nik;

				// set and select privacy
				$('privacy'+idx).value = $('service_link_privacy').value;	
				
				// save service
				var post = '';
				post += '&control[method]=insertObj';
				post += '&control[class]=usersocial';
				post += '&fields[social_sid]='+this.activeService.sid;
				post += '&fields[nik]='+nik;
				post += '&fields[visibility]='+$('service_link_privacy').value;
				var url = '/php-os/app_local/scripts/update.php';		
				Ext.Ajax.request({
					scope:this,
					method:'post',
					activeService:this.activeService,
					idx:idx,
					url: url,
					success: function(response,options){
						// success message
						var rData = Ext.util.JSON.decode(response.responseText);//passed back from server
						if(rData) {	
							options.rData = rData;
							$('fields_root_editor_add_links_'+options.idx+'_sid').value = rData['response'];
							//Ext.fly('deletelink'+options.activeService.sid).on('click', FNK.deleteServiceLink(rData['response'],options.activeService.sid));
							Ext.get('deletelink'+options.idx).on({
								'click': { scope:options, fn: function() {
									FNK.deleteServiceLink(this.rData['response'],this.idx);
								}}
							});

							if(rData && rData.msg && rData.msg.length > 0) {
								this.setMissionMessage(1,rData.msg);
							}								
						}
					},
					failure: function(response,options){ 
						// failure
					},
					params: post
				});						
				
			}
			
		
			// start from beginning
			$('servicenik').value = $L('your_nik_at_this_site');
			$('servicelink').value = $L('new_link_to');
			
			$('servicelink_hint').innerHTML = this.defServicelinkHint;
			//this.getServices(); // directly add a new link
			if($('no_service_links_hint')) $('no_service_links_hint').style.display = 'none';

			//$('servicelink').blur();		
			//$('servicenik').blur();
			//$('fields_root_editor_add_links_'+idx+'_privacy').focus();
			//$('field_save').focus();
			//$('service_link_privacy').focus();
			$('privacy'+idx).focus();
			this.activeService = false;
		}
	}

	this.deleteServiceLink = function(r_sid,s_sid) {

		this.showMessage({
			//bt:button,
			height:150,
			width:300,
			iconCls:'x-horsesshuh-ico',
			title:$L('warning'),
			html:'<p class="winmsg">'+$L('shure_you_wish_to_delete_this_link')+'</p>',
			defaultButton:0,
			//y:300,
			buttons:[{
				 text: $L('cancel')
				,scope:this
				,handler:function(button) {
					button.ownerCt.close();
				}							
			},{
				 text: $L('yes')
				,scope:this
				,handler:function(button) {
					button.ownerCt.close();
					this.reallyDeleteServiceLink(r_sid,s_sid);
				}							
			}]
		});	
	}
	
	this.reallyDeleteServiceLink = function(r_sid,s_sid) {
		if($('userservice'+s_sid)) {
			$('userservice'+s_sid).remove();

			// ajax which removes the services of this user 
			if(r_sid && r_sid.length > 0) {
				var url = '/php-os/app_local/scripts/ajax_delete_userservice.php';		
				Ext.Ajax.request({
					url: url,
					scope:this,
					success: function(response,options){
						// success message
						var responseData = Ext.util.JSON.decode(response.responseText);//passed back from server
						if(responseData && responseData.msg && responseData.msg.length > 0) {
							this.setMissionMessage(1,responseData.msg);
						}	
					},
					failure: function(response,options){ 
						// dunno
					},
					params: {sid:r_sid}
				});	
			}
		}
	}
	
	this.editServiceLink = function(sid) {
		if(!$('userservice'+sid)) return false;
		// hide title
		$('servicetitle'+sid).style.display='none';
		// inline editor
		$('ieNik'+sid).addClassName('on-focus');
		$('ieNik'+sid).style.display='';
		$('ieNik'+sid).focus();
		$('ieNikAccept'+sid).style.display='';
		$('ieNikID'+sid).style.display='';
		
		Event.observe($('ieNik'+sid), 'keydown', FNK.updateServiceLink.bindAsEventListener(this, sid, this.services[sid]));
		this.bodycancel = Event.observe(document.body, 'click', FNK.autocancel.bindAsEventListener(this, sid, this.services[sid]));
	}
	
	this.updateServiceLink = function(e,sid,o) {
		//var data = $A(arguments);
		if(e.keyCode == 13) {
			this.rUpdateServiceLink(e,sid,o);
		}		
	}
	
	this.rUpdateServiceLink = function(e,sid,o) { // sid = social_sid
		// hide inline editor
		
		
		var nik = $('ieNik'+sid).value;
		if(nik.length < 2) return false;
		
		
		$('ieNik'+sid).style.display='none';
		$('ieNikAccept'+sid).style.display='none';
		$('ieNikID'+sid).style.display='none';
		var nikTitle = this.createServiceTitle(this.services[sid],nik);
		
		// show title
		$('servicetitle'+sid).innerHTML = nikTitle; 
		$('servicetitle'+sid).style.display='';
		
		// update hidden field
		var nikEl = this.getRowField(sid,'nik');
		nikEl.value = nik;
		var sidEl = this.getRowField(sid,'sid');

		// save service
		var post = '';
		post += '&control[method]=updateObj';
		post += '&control[class]=usersocial';
		post += '&fields[sid]='+sidEl.value;
		post += '&fields[nik]='+nik;
		var url = '/php-os/app_local/scripts/update.php';		
		Ext.Ajax.request({
			scope:this,
			method:'post',
			url: url,
			success: function(response,options){
				// success message
				var responseData = Ext.util.JSON.decode(response.responseText);//passed back from server
				if(responseData && responseData.msg && responseData.msg.length > 0) {
					this.setMissionMessage(1,responseData.msg);
				}
			},
			failure: function(response,options){ 
				// failure
			},
			params: post
		});		

		Event.stopObserving(document.body, 'click');
		Event.stopObserving($('ieNik'+sid), 'keydown');
		return false;	
	}
	
	this.setServicePrivacy = function(e,sid) { // sid = social_sid
		// save privacy
		var sidEl = this.getRowField(sid,'sid');
		
		var post = '';
		post += '&control[method]=updateObj';
		post += '&control[class]=usersocial';
		post += '&fields[sid]='+sidEl.value;
		post += '&fields[visibility]='+$('privacy'+sid).value;
		var url = '/php-os/app_local/scripts/update.php';		
		Ext.Ajax.request({
			scope:this,
			method:'post',
			url: url,
			success: function(response,options){
				// success message
				var responseData = Ext.util.JSON.decode(response.responseText);//passed back from server
				if(responseData && responseData.msg && responseData.msg.length > 0) {
					this.setMissionMessage(1,responseData.msg);
				}				
			},
			failure: function(response,options){ 
				// failure
			},
			params: post
		});		
	
	}
	
	this.setMissionMessage = function(i,msg) {
		
		// mm1, mmessage1
		// hide 
		var mm = Ext.get('mm'+i);
		if(!mm) return false;
		if(mm.getStyle('display') == 'none') {
			mm.slideIn('t',{
				easing: 'easeOut',
				duration: .5,
				scope:this,
				useDisplay: true
			});	
		}
		$('mmessage'+i).innerHTML= msg;
		
	}
	
	//---------------------------------------------------------------------------------------
	this.hideGlobalMessage = function(id,sid) {
		this.hideMessage(id);
		//$('space-if-no-highlight').removeClassName('invisible');
		
		// save on blacklist
		var post = '';
		post += 'fields[sid]='+URLEncode(sid);
		post += '&control[method]=setread';
		post += '&control[class]=globalmessageblacklist';
		
		var url = '/php-os/app_local/scripts/update.php';		
		Ext.Ajax.request({
			scope:this,
			method:'post',
			sid:sid,
			url: url,
			success: function(response,options){
				//var rData = Ext.util.JSON.decode(response.responseText);//passed back from server
			},
			failure: function(response,options){ 
			},
			params: post
		});					
		
	}
	
	//---------------------------------------------------------------------------------------
	this.autocancel = function(e,sid,o) {
		if(e) {
			var el = Event.element(e);
			if(el.id == ('ieNik'+sid)) return;
			container = PAGEdom.getContainer(el, $('userservice'+sid));
			if(container != null) return;
		}
		if($('ieNik'+sid)) $('ieNik'+sid).style.display='none';
		Event.stopObserving($('ieNik'+sid), 'keydown');
		Event.stopObserving(document.body, 'click');
		if($('ieNikAccept'+sid)) $('ieNikAccept'+sid).style.display='none';
		if($('ieNikID'+sid)) $('ieNikID'+sid).style.display='none';
		if($('servicetitle'+sid)) $('servicetitle'+sid).style.display='';
		//this.bodycancel = 0;
	}
	
	//---------------------------------------------------------------------------------------
	this.checkAllByClassName = function(id,classname) {

	}
	
	//---------------------------------------------------------------------------------------
	this.hideMessage = function(id,context) {
		
		// hide 
		var mm = Ext.get(id);
		if(!mm) return false;
		mm.slideOut('t',{
			easing: 'easeOut',
			duration: .5,
			scope:this,
			//remove: true,
			useDisplay: true
		});
				
	}
	
	//---------------------------------------------------------------------------------------
	this.displayDown = function(e,t) {
		var l = Ext.get(t);
		var p = l.next(false,true);
		var pl = Ext.get(p);
		if(p && pl.hasClass('collapsed-content') && (pl.is('h3') != true)) {
			if(pl.getStyle('display') == 'none') pl.setStyle('display','block');
			else pl.setStyle('display','none');
			this.displayDown(e,p);
		}
	}
	
	//---------------------------------------------------------------------------------------
	this.disable = function(obj) {

		//if(typeof console == 'object') console.log('x obj: %o',obj);
		for(id in obj) {
			//if(typeof console == 'object') console.log('x obj.id: %o',obj.id);
			if(obj && obj.id && obj.id.length >0 && $(obj.id)) {
				$(obj.id).addClassName('disabled');
				$(obj.id).disabled = true;
			}
		}			
	}
	
	this.enable = function(obj) {
		for(id in obj) {
			//DebugDump(obj.id,id);
			if(obj && obj.id && obj.id.length >0 && $(obj.id)) {
				$(obj.id).removeClassName('disabled');
				$(obj.id).disabled = false;
			}
		}
	}
	
	//---------------------------------------------------------------------------------------
	this.hideContainer = function(obj) {
		for(id in obj) {
			//DebugDump(obj.id,id);
			if($(obj.id)) {
				$(obj.id).addClassName('hidden');
				//$(obj.id).disabled = true;
			}
		}			
	}
	
	this.showContainer = function(obj) {
		for(id in obj) {
			//DebugDump(obj.id,id);
			if($(obj.id)) {
				$(obj.id).removeClassName('hidden');
				//$(obj.id).disabled = false;
			}
		}
	}	
	
	//---------------------------------------------------------------------------------------
	this.showMessage = function(o) {
		
		var d = {
			animEl: o.bt ? o.bt.id : false,
			modal: o.modal ? true : false,
			minWidth:350,
			stateful:false,
			shadow:true,
			shadowOffset:8,
			shim:false,	
			closable:false,
			cls:'x-friendnik'
		};
		
		if(typeof o != 'object') var o = {};
		o = Ext.apply(o,d);
		
		var win = new Ext.Window(o);
		if(o.bt) win.show.defer(50, win,[o.bt.id]);
		else win.show.defer(50, win);
	}	
	
	//---------------------------------------------------------------------------------------
	this.check4FileUpload = function(event) {
		
		if(typeof event == 'undefined' || !event) return true;
	
		var obj = event.target || event.srcElement;
			
		if ( obj.type != "textarea" && event && event.keyCode == 13 ){
			
			if ( event.preventDefault )
				event.preventDefault()
			else event.returnValue = false;
		};
		
		// check if file is going to be uploaded
		var inputs = $$('input[type=file]');
		var has_value = false;
		if(inputs) {
			for(i=0;i<inputs.length;i++) {
				if(inputs[i].value.length>0) has_value = true;
			}
		}
		if(has_value) { // mask background and show uploading file
			//var myMask = new Ext.LoadMask(Ext.getBody(), {msg:$L('Please wait, uploading file...')});
			//myMask.show();
			window.scrollTo(0, 0);
			this.mask($L('Please wait, uploading file...'));
		}

		return true;
	} 
	
	this.mask = function(msg) {
		if(!msg) var msg = $L('Loading...')
		var m = Ext.getBody().mask();

		var tpl = '';
		tpl += '<div id="horseloading">';
		tpl += '<img src="/local/media/images/loading/run.png" width="698" height="474" />';
		tpl += '<div class="horse-loading-msgwr">';
		tpl += '<img src="/local/media/images/loading/circle.gif" width="66" height="66" />';
		tpl += msg;
		tpl += '';
		tpl += '';
		tpl += '';
		tpl += '';
		tpl += '</div>';
		tpl += '</div>';
		Ext.getBody().insertHtml('beforeEnd',tpl);
	}
	
}

var FNK = new Friendnik();

//--------------------------------------------------------------------------------------- //
if(typeof Ext == 'object') {
	Ext.BLANK_IMAGE_URL = '/images/spacer.gif';
	// application main entry point
	Ext.onReady(function() {
		FNK.init();
	}); // eo function onReady



	
	/*****************************************************
	*/ function __P___RequestPasswordForm() {}
	/******************************************************/
	
	// Setup LoginForm
	IF.RequestPasswordForm = Ext.extend(Ext.form.FormPanel, {
	 initComponent:function() {
		 Ext.apply(this, {
			frame:true,
			url:'/php-os/app_local/scripts/ajax_request_password.php',
			method:'post',
			labelAlign: 'top',
			cls:'x-friendnik',
			iconCls:'x-mail-tab',
			//title: $L('login'),
			bodyStyle:'padding:5px',
			id: 'rqpform',
			defaultType: 'textfield',
			defaults: {width: 230},
			layoutConfig: {
				labelSeparator: ''
			},		
			items: [{
				xtype:'hidden',
				name: 'operation',
				value:'requestpassword'
			},{
				//xtype:'textfield',
				fieldLabel:$L('email'),
				hideLabel:true,
				name: 'email',
				id: 'rqp_email',
				anchor:'100%',
				allowBlank:false
			},{
				xtype: 'tbtext',
				text:$L('request_password_hint')
			}]
		}); // eo apply
	
		// call parent
		IF.RequestPasswordForm.superclass.initComponent.apply(this, arguments);
		
	} // eo function initComponent
	
	});
	// Register New Event Form
	Ext.reg('requestpassword', IF.RequestPasswordForm);

}
//--------------------------------------------------------------------------------------- //

function switchSelectAll4Label(event) {
var childNodes = Event.element(event).childNodes;
for(var i in childNodes) {
  if(childNodes[i].type == 'checkbox') {
	element = childNodes[i];
	// check / uncheck all when the "select all" checkbox is pressed
	if(element.hasClassName('switcher')) {
	  // unfortunately IE understands the checking exactly opposite than gecko or webkit browser :(
	  if(Prototype.Browser.IE) {
	  //  element.checked ? runThroughInputs4SelectAll(element, false) : runThroughInputs4SelectAll(element, true);
		if(element.checked) {
		  runThroughInputs4SelectAll(element, false);
		  setChecked(element, true);
		}else{
		  runThroughInputs4SelectAll(element, true);
		  setChecked(element, false);
		}
	  // webkit, opera and gecko browsers..
	  }else{
		element.checked ? runThroughInputs4SelectAll(element, true) : runThroughInputs4SelectAll(element, false);
	  }
	// if any other checkbox is clicked, the "select all" checkbox should be disabled if not
	// all other ones are checked and it should be enabled if all are checked
	}else{
	  var checkboxAmount = 0;
	  var checkedCheckboxes = 0;
	  // IE changes the Checked attribute to after finishing this script, so we must set it manually
	  if(Prototype.Browser.IE) {
		element.checked ? element.checked = 0 : element.checked = 1;
	  }
	  // run through every input checkbox field and change count checked ones and all checkboxes with the same name
	  $$('form input').each(function(e) {
		if(e.type == 'checkbox' && !e.hasClassName('switcher') &&  e.getAttribute('rel') == element.getAttribute('rel')) {
		  e.checked ? checkedCheckboxes++ : checkedCheckboxes;
		  checkboxAmount++;
		}
	  });

	  // set "select all" checkbox to true
	  if(checkedCheckboxes == checkboxAmount) {
		$$('form input').each(function(e) {		
		  if(e.type == 'checkbox' && e.hasClassName('switcher') &&  e.getAttribute('rel') == element.getAttribute('rel')) {
			setChecked(e, true);
		  }
		});
	  // set "select all" checkbox to false
	  }else{
		$$('form input').each(function(e) {	
		  if(e.type == 'checkbox' && e.hasClassName('switcher') &&  e.getAttribute('rel') == element.getAttribute('rel')) {
			setChecked(e, false);
		  }
		});
	  }
	}
  }
}
}

/**
* just to avoid code duplication...
* runs through all input checkboxes in form.select_all
*/ 
function runThroughInputs4SelectAll(element, bool) {
	$$('form input').each(function(e) {
	  if(e.type == 'checkbox'  && e.getAttribute('rel') == element.getAttribute('rel')) { //e.name.indexOf(element.name) >= 0
		setChecked(e, bool);
	  }
	});
}

/**
* sets the label class to checked and checks the input itself
*
* @var element Object
* @var bool Boolean for checking/unchecking the element
*/
function setChecked(element, bool) {
if(element.type == 'checkbox') {
  var label = element.parentNode;
  if(bool) {
	element.checked = 1;
	element.setAttribute('checked', 'checked');
	label.removeClassName('unchecked');
	label.addClassName('checked');
  }else{
	element.checked = 0;
	element.removeAttribute('checked');
	label.removeClassName('checked');
	label.addClassName('unchecked');
  }
}
}
