
//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;
}

if(typeof DebugDump != 'function') function DebugDump() {}

/* 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
		
		var contentcontainer = Ext.get('contentcontainer');
		if(contentcontainer) this.contentHeight = Ext.get('contentcontainer').getHeight();
		//this.setFooter();
		//this.linkExternalLinks();
		
		//if(!this.window) this.buildWindow();
		
		/*if($('search-q')) {
			$('search-q').focus();
		}*/
		
		this.overlays = 'ext'; //lightview / ext
		
		//if(typeof console == 'object') console.log('x window: %o',window.print);
		//window.onbeforeprint = function( alert('hey, lets print'); );
		
	}

	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.showLogin = function(lgel) {
		
		var loginbox = Ext.get('loginbox');
		//loginbox.setOpacity(0.85);
		loginbox.slideIn('t', {
			easing: 'easeOut',
			duration: .25
		});
		
		this.addEvent(document,'mousedown',this.autohidenav = function(event) {this.hideNav(event);}.bind(this));
	}

	this.hideNav = function(event) {
		
		var el;
		el = this.gettarget(event);
		
		var lgnavEl = document.getElementById('loginbox');
		if (el == lgnavEl) return;
		xEl = Ext.get(el);
		
		var pEl = xEl.findParentNode('#loginbox');
		
		if (!pEl) {
			var loginbox = Ext.get('loginbox');
			loginbox.switchOff({
				easing: 'easeIn',
				duration: .3,
				remove: false,
				useDisplay: true
			});
			this.removeEvent(document,'mousedown',this.autohidenav);
		}
	}
	
	//---------------------------------------------------------------------------------------
	
	this.preloadImages = function(images){
        var preload = Ext.get(document.body).createChild({tag:"div", style:"display:none"});
 		//if(typeof console == 'object') console.log('x preload: '+images.length+': %o',images);
        
        if(images && images.length > 0) {
			Ext.each(images, function(image){
				if (typeof(image)=='string'){
				 image={src:image}
				}
								
				if (image.src){
					preload.createChild({tag:"img", src:image.src});
				}
				
				if (image.fullSrc){
					preload.createChild({tag:"img", src:image.fullSrc});
				}
			}, this);
        } else if(typeof images == 'object') {
        	for(img_sid in images) {
  				if (images[img_sid].src){
					preload.createChild({tag:"img", src:images[img_sid].src});
					//if(typeof console == 'object') console.log('x preload: images[img_sid].src: %o',images[img_sid].src);
				}      		
        	} 
        }
    }

	
	//---------------------------------------------------------------------------------------
	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.adjustSize = function(r) {
		sizeUnit = "%";
		defaultSize = 100;
		maxSize = 160;
		minSize = 98;	
	}


	//---------------------------------------------------------------------------------------
	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.
		//DebugDump(document.forms['iflogin'],'document.forms ');
		document.forms['iflogin'].submit();
	}
	
//---------------------------------------------------------------------------------------
/*	this.toggleView = function(elId,force) {
		if(!$(elId)) return false;
		if($(elId).style.display == 'none') $(elId).style.display = '';
		else $(elId).style.display = 'none';
	}*/
	
	this.toggleView = function(elId,force) {
		if(!elId) return false;
		if(document.getElementById(elId).style.display == 'none') document.getElementById(elId).style.display = '';
		else document.getElementById(elId).style.display = 'none';
	}

	//---------------------------------------------------------------------------------------

	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();
	}


	this.extendFormField = function(fieldId,checkfieldvalue,confirmmessage) {
		var field = document.getElementById(fieldId);
		if (field.value != checkfieldvalue) return;
		
		var fieldtype = document.getElementById(fieldId).type;
		var n = prompt(confirmmessage,"")
		if (n == null) return;
		if (n.length >0) {	
			switch(fieldtype) {
				case"select-one":
					NeuerEintrag = new Option(n,n,false,true);
					field.options[field.options.length] = NeuerEintrag;
				break;
			}	
		}
	}	

	// 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,e) {
		
	
		// if its an iphone or android phone
		var uagent = navigator.userAgent.toLowerCase();
		if((e) &&
			(uagent.match(/iphone/i)) ||
			(uagent.match(/android/i))
		) {
			var t = this.gettarget(e);
			if(t) {
				var href = t.getAttribute('href');
				if(href && href.indexOf('tel:') >= 0) { // use href
					try { window.location.href = href; }
					catch(err) { return false; }
				} else { // use message
					try { window.location.href = 'tel:'+m; }
					catch(err) { return false; }				
				}
				return true;
			}
		}
		
		if(this.magnifier_is_visible == true) {
			//this.hideMagnifier(false);
			setTimeout(function(){ this.magnify(m); }.bind(this), 300);
			return;
		}
		IF.magnifier_is_visible = true;
		
/*
.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();
		
		if(!this.mag) {
			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';
			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);
	

		} else this.mag.style.display = '';
		
		this.mag.innerHTML = m;
		
		if(typeof Ext == 'object') {
			var mag_bg = Ext.get(this.mag_bg);
			mag_bg.fadeIn({
				endOpacity:.75, 
				duration:.25,
				easing:'easeOut',
				useDisplay:true,
				callback:function() {
					IF.magnifier_is_visible = true;
					
				}
			});
		} else {
			op = 0.7;
			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)+")";
			IF.magnifier_is_visible = true;
		}
		
		if(!this.hideme) {
			this.addEvent(document,'mousedown',this.hideme = function(event) {this.hideMagnifier(event);}.bind(this));
		}
		if (e && e.stopPropagation) {
			e.stopPropagation();
		} else if(e) {
			e.cancelBubble = true;
		} 
		
	}
	//---------------------------------------------------------------------------------------
	this.hideMagnifier = function(event) {
	
		var el;
		el = this.gettarget(event);
		if (el == this.mag) return;
		if (el == this.mag_bg) return;
		
		//PAGEdom.removeNode(this.mag);
		this.mag.style.display = 'none';
		mag_bg = this.mag_bg;
		if(typeof Ext == 'object') {
			var mag_bg = Ext.get(this.mag_bg);
			mag_bg.fadeOut({
				endOpacity: 0, 
				duration: .25,
				easing:'easeIn',
				useDisplay:true,
				//remove:true,
				callback:function() {
					IF.magnifier_is_visible = false;
				}
			});
		} else {
			//PAGEdom.removeNode(this.mag_bg);
			this.mag.style.display = 'none';
			IF.magnifier_is_visible = false;
		}
	}	
	
	this.sau_Effect_rmNode = function(obj) {
		//PAGEdom.removeNode(obj.element);
		//KS.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 = 50000;
			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-accept-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-accept-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-accept-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-accept-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-accept-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.rot13init = function() {
	  var map = new Array();
	  var s   = "abcdefghijklmnopqrstuvwxyz";
	  
	  for (i=0; i<s.length; i++)
		map[s.charAt(i)]            = s.charAt((i+13)%26);
	  for (i=0; i<s.length; i++)
		map[s.charAt(i).toUpperCase()]  = s.charAt((i+13)%26).toUpperCase();
	  return map;
	}
	
	this.rot13map = false;
	this.rot13=function(a) {
	  if (!this.rot13map) this.rot13map=this.rot13init();
	  s = "";
	  for (i=0; i<a.length; i++) {
		  var b = a.charAt(i);
		  s += (b>='A' && b<='Z' || b>='a' && b<='z' ? this.rot13map[b] : b);
		}
	  return s;
	}
	
	this.decMailto=function(eAddr) {
		document.location = 'mailto:'+this.rot13(eAddr);
		return false;
	}   
	
	//---------------------------------------------------------------------------------------
	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 KUNZE () {
	
	this.init = function() {

		this.initTabs();
		
		this.clearOnFocus();
		
		this.initCarousel();
		
		if(Ext.ux && Ext.ux.Lightbox) Ext.ux.Lightbox.register('a.obj-imgs', true);
		else if(Ext.ux && Ext.ux.extbox) Ext.ux.extbox.register('a.obj-imgs', true);
		if(Ext.get('searchtabs') && typeof etabs == 'object') this.initSearch(etabs);
		if(Ext.get('plan_wr_r')) this.loadGmapPanel();
		if(Ext.get('plan_wr_st')) this.loadHomeGmapPanel();
		

		this.showTechPropertiesQtips();
		
		
		/* // change all selects to combo boxes - make no sense...
		var selects = Ext.DomQuery.select('select','.content');
		for(sidx=0;sidx<selects.length;sidx++) {
			
			DebugDump(selects[sidx],'selects '+selects[sidx].id);
			
			var item = Ext.get(selects[sidx]);
			DebugDump(item,'item');
			
			// make ext select
			// forceSelection
			converted = new Ext.form.ComboBox({
				typeAhead: true,
				triggerAction: 'all',
				transform:selects[sidx].id,
				//fieldClass:item.dom.classNames(),
				//width:135,
				forceSelection:true
			});			
			
		}*/
		
		
		//FancyForm.start();
		/*
		$$('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';			
		*/
		
		// return true;
		// 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: '/local/tools/x/ajax_search.php'
				}),
				reader: new Ext.data.JsonReader({
					totalProperty: 'totalCount',
					root: 'records',
					id: 'group_key'
				},[
					{name: 'description', mapping: 'description'},
					{name: 'group_key', mapping: 'group_key'},
					{name: 'category', mapping: 'category'},
					{name: 'tpl', mapping: 'tpl'},
					{name: 'uri', mapping: 'uri'}
					//,{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">',
					'{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('search'),
				value: orgValue,
				displayField:'title',
				name:'q',
				typeAhead: false,			
				cls:'sff-cls',
				fieldClass:'x-nostyle-field',
				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...'),
				//listAlign:['bl',[-2,-3]],
				listWidth: (Ext.isIE) ? 230 : 240,
				listClass:'ff-search-list-item',
				store: ds,
				enableKeyEvents:true,
				in_list:false,
				itemSelector: 'div.ff-search-item',
				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();
					} 
					
					this.list.alignTo("quicksearch", "tl-bl", [0, 0]);
					//this.list.alignTo("xff", "tl-bl", [-16, -5]);
					
				},
				onBlur:function(){
					if (this.inKeyMode) this.collapse();
				},	
				listeners: {
					'keypress':{fn:function(c,e){
						//if(typeof console == 'object') console.log('typeof e '+typeof e+': %o',typeof e);
						if(typeof e == 'undefined' || !e) return true;
						var obj = e.target || e.srcElement;
						var v = c.getValue();
						//if(typeof console == 'object') console.log('e.keyCode '+ e.keyCode+': %o',e.keyCode);
						//if(typeof console == 'object') console.log('c.in_list '+ c.in_list+': %o',c.in_list);
						//return;
						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='/suche?q='+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(typeof console == 'object') console.log('select x '+ c.in_list+': %o',c.in_list);
						//if(typeof console == 'object') console.log('select x '+ record.data.description+': %o',record.data.description);
						//DebugDump(record.data,'record.data');
						//return;
						if(record.data.description == 'close') {
							c.collapse();
							c.in_list = false;
						} else if(record.data.group_key.length == 0) {
							var v = Ext.getCmp('xff').getValue();
							window.location.href='/suche?q='+v;
						} else {
							//var group_key =  String(record.data.group_key).toLowerCase();
							//window.location = String.format('/produkte/{0}', group_key);
							window.location = record.data.uri;
						}
					}}
				},
				width:200
			});		
		}


		this.submenuimages = [{
			src:'/local/media/images/leftnavi/navpunkt1sel.png'
		},{
			src:'/local/media/images/leftnavi/navpunkt2sel.png'
		},{
			src:'/local/media/images/leftnavi/navpunkt3sel.png'
		},{
			src:'/local/media/images/leftnavi/navpunkt4sel.png'
		},{
			src:'/local/media/images/leftnavi/0208_kunze_navi_produktsuche_over.png'
		}];		
		if(typeof this.submenuimages == 'object') IF.preloadImages.defer(500,IF,[this.submenuimages]);
		
		var madeby = Ext.get('madeby');
		if(madeby) {
			madeby.qtip = new Ext.ToolTip({
				target: madeby.id,
				cls:'xlocal',
				anchor: 'top',
				autoHide: true,
				dismissDelay:0,
				anchorOffset: 10,
				trackMouse: true,
				maxWidth:500,
				html: 'web development by'
			});		
		}
		
	}
	
	this.initCarousel = function() {
		if($('carousel') && (typeof carousel_items == 'object')) {
			//http://extjs-ux.org/docs/?class=Ext.ux.layout.Carousel
			new Ext.Panel({
				id:'my1carousel',
				renderTo: 'carousel',
				height:190,
				width:700,	
				cls:'x-local 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.initTabs = function() {
		// go through items classname tabs
		var tabs = Ext.DomQuery.select('div.tabs');
		var TB = [];
		for(i=0;i<tabs.length;i++) {
			TB[i] = new Tabs();
			TB[i].init(tabs[i]);
		}
		
	}
	//---------------------------------------------------------------------------------------
	
	this.loadQuickView = function(field,newValue,oldValue) {
		var f = this.getForm();
		var url = '/local/tools/x/ajax_get_quicksearch.php';
		var quickview = Ext.get('quickview'+f.baseParams.cat_sid);
		if(quickview) quickview.mask($L('Loading'), 'x-mask-loading');
		
		
		if(field == 'reset') {
			//var params = f.baseParams;
			var r_fields = this.findByType('xrangefield');
			for(i=0;i<r_fields.length;i++) {
				r_fields[i].onReset();
			}
			//f.reset();
			var params = Ext.apply(f.baseParams,f.getValues());
		} else var params = Ext.apply(f.baseParams,f.getValues());
		
		Ext.Ajax.request({
			url: url,
			f:f,
			scope:this,
			success: function(response,options){
				
				//if(typeof console == 'object') console.log('x response: %o',response);
				
				var responseData = Ext.util.JSON.decode(response.responseText);//passed back from server
				// update quickview-options.params.cat_sid with responseData.countProducts
				Ext.get('quickview'+options.params.cat_sid).unmask();
				Ext.get('quickview'+options.params.cat_sid).update(''+responseData.countProducts);
				
				var cf = options.f.findField('fields_root_ajaxbody_editor_quickview_countcat'+options.params.cat_sid);
				if(cf) {
					cf.setValue(''+responseData.countProducts);
					//cf.originalValue = cf.getValue();
				}
				
				// deactivate form fields				
				if(responseData.deactivate_tps && responseData.deactivate_tps.length >0) {
					var deact = responseData.deactivate_tps;
					for(didx=0;didx<deact.length;didx++) {
						var d = Ext.getCmp('fields_root_ajaxbody_editor_tpsid_'+deact[didx]+'cat3');
						if(d) d.disable();
					}
				}
				
				// activate form fields activate_tps
				if(responseData.activate_tps && responseData.activate_tps.length >0) {
					var act = responseData.activate_tps;
					for(aidx=0;aidx<act.length;aidx++) {
						var d = Ext.getCmp('fields_root_ajaxbody_editor_tpsid_'+act[aidx]+'cat3');
						if(d) d.enable();
					}
				}	
				
			},
			failure: function(response,options){ 
				// do nothing
			},
			params: params
		});			
		
		
	}
	
	this.initSearch = function(p) {
		
		var defaults = {
			labelWidth:225,
			monitorValid:false,
			//formlayout:'column',
			aftermetaloaded: function(cp,meta) {
				// get all combo boxes and add change event for live quickview
				FNK.loadQuickView.defer(100,cp);
				
				var fields = Ext.DomQuery.select('input',cp.id);
				for(sidx=0;sidx<fields.length;sidx++) {
					var item = Ext.getCmp(fields[sidx].id);
					if(item) {
						switch(item.getXType()) {
							case'combo':
								item.addListener('collapse',FNK.loadQuickView,cp); //,item, [Object options] 
/*
myGridPanel.mon(myGridPanel.getSelectionModel(), {
    selectionchange: handleSelectionChange,
    buffer: 50
});
*/								
								
								break;
						}
						
					}
				}
			}
			/*listeners:{
			afterlayout: {scope:this,single:true,fn: function(cp) {
				// get all combo boxes and add change event for live quickview
				DebugDump(this,'afterlayout');
				FNK.loadQuickView.defer(100,cp);
				
				var fields = Ext.DomQuery.select('input',cp.id);
				for(sidx=0;sidx<fields.length;sidx++) {
					var item = Ext.getCmp(fields[sidx].id);
					if(item) {
						switch(item.getXType()) {
							case'combo':
								item.addListener('change',FNK.loadQuickView,cp); //,item, [Object options] 
								break;
						}
						
					}
				}
			}}}*/
		}; 
		var t_items = [];
		for(i=0;i< p.tabs.length;i++) {
			if(typeof p.tabs[i] != 'object') continue;
			t_items[i] = Ext.apply(p.tabs[i],defaults);
		}
		
				
		this.tabs = new Ext.TabPanel({
			id:'searchtabstabpanel',
			renderTo:'searchtabs',
			activeTab: 0,
			cls:'xlocal',
			ctCls:'xlocal',
			height:220,
			//autoHeight:true,
			defaults:{layout:'fit'},
			//resizeTabs:true, // turn on tab resizing
			//minTabWidth: 300,
			enableTabScroll:false,
			//plugins: new Ext.ux.TabCloseMenu(),
			layoutOnTabChange:true,
			items:t_items
		});   		
		
	}
	
	this.quickview = function(fp,cat_sid) {
		
	}
	
	this.submitSearch = function(fp,cat_sid) {
		var f = fp.getForm();
		f.standardSubmit=true;
		fp.baseParams['triggers'] = 'search';
		//fp.baseParams['test'] = '1';
		var values = {};
		if (fp.baseParams && !fp.paramsAdded) {
			// add hidden items for all baseParams
			var idx=0;
			for (i in fp.baseParams) {
				fp.add({
					xtype: 'hidden',
					name: i,
					id: 'bp'+i,
					value: fp.baseParams[i]
				});
				values['bp'+i] = fp.baseParams[i];
				idx++;
			}
			
			fp.doLayout();
			f.setValues(values);
			// set a custom flag to prevent re-adding
			fp.paramsAdded = true;
		}
		f.url=location.href;
		//DebugDump(f.getValues(),'values');
		f.submit(); //{params:{triggers:'search',noxml:'1'},waitMsg:$L('Saving Data....')}
		
	}
	
	
	this.handleSearchCompareItems = function(e,el,sid) {
		
		// make an object of clicked items...
		xEl = Ext.get(el);
		if(typeof this.search_compare_items != 'object') this.search_compare_items = [];
		if(xEl.hasClass('selected')) {
			xEl.removeClass('selected');
			this.tmp_search_compare_items = this.search_compare_items;
			this.search_compare_items = [];
			Ext.each(this.tmp_search_compare_items,function(i){
				if(sid != i) {
					this.search_compare_items[this.search_compare_items.length] = i;
				}
			},this);
		} else {
			xEl.addClass('selected');
			this.search_compare_items[this.search_compare_items.length] = sid; 
		}
		
		$('product_sids').value = this.search_compare_items.join(',');
		//DebugDump(this.search_compare_items,'this.search_compare_items');
		//Ext.get('product_sids').set(value:this.search_compare_items.join(','));
		//DebugDump($('product_sids').value,'product_sids '+$('product_sids').value);
	}
	
	//---------------------------------------------------------------------------------------
	
	this.loadGmapPanel = function() {
		FNK.overlayIdx=0;
		var h = (IF.contentHeight > 740) ? 740 : IF.contentHeight;
		
		FNK.panel = new Ext.ux.GMapPanel({
			//layout: 'fit',
			frame: false,
			border: false,
			height: 900,//h,
			width: 860,
			cls:'xlocal',
			x: 1, 
			y: 1,
			renderTo: 'plan_wr_r',// Ext.getBody(), // 'plan_wr_r',//

			zoomLevel: 2,
			gmapType: 'map',
			mapConfOpts: ['enableDoubleClickZoom','enableDragging'], //'enableScrollWheelZoom',
			mapControls: ['GSmallMapControl','GMapTypeControl','NonExistantControl'],
			setCenter: {
				//-10.1, 14.4
				lat:'-10.1',//'44.2',
				lng:'14.4',//'-19.2',
				geoCodeAddr: '',
				marker: {title: 'Die Mitte',clear:true},
				mark:'hidden'
			}
		});

		//FNK.panel.show();
		FNK.panel.showLocations('distributor','distributor');
	
	}

	//---------------------------------------------------------------------------------------
	
	this.loadHomeGmapPanel = function() {
		FNK.overlayIdx=0;
		FNK.panel = new Ext.ux.GMapPanel({
			frame: false,
			border: false,
			height: (IF.contentHeight > 0) ? IF.contentHeight : 400,
			width: 500,
			cls:'xlocal',
			x: 1, 
			y: 1,
			renderTo: 'plan_wr_st',
			zoomLevel: 13,
			gmapType: 'map',
			mapConfOpts: ['enableDoubleClickZoom','enableDragging','G_SATELLITE_MAP'], //'enableScrollWheelZoom', 'enableGoogleBar' (searchbar),
			mapControls: ['GSmallMapControl','GMapTypeControl','NonExistantControl'],// ['GLargeMapControl3D()','GNavLabelControl()','GMapTypeControl','NonExistantControl'], //['GSmallMapControl','GMapTypeControl','NonExistantControl']
			markers:[{
				lat:'48.01966',
				lng:'11.59049',
				marker: {
					title: 'Standort spanhebende Fertigung',
					clear:true,
					image_src: DOMAIN_SUBFOLDER_WWW_ROOT+'local/media/images/icons/kunze-gmap.png',
					icon_size:{width:18,height:22}
				}			
			},{
				lat:'48.032956',
				lng:'11.586003',
				geoCodeAddr: '',
				marker: {
					title: 'Kunze Folien GmbH',
					clear:true,
					image_src: DOMAIN_SUBFOLDER_WWW_ROOT+'local/media/images/icons/kunze-gmap.png',
					icon_size:{width:18,height:22}
				},
				mark:'hidden'
			}],
			setCenter: {
				lat:'48.01966',
				lng:'11.59049',
				marker: {
					title: 'Standort spanhebende Fertigung',
					clear:true,
					image_src: DOMAIN_SUBFOLDER_WWW_ROOT+'local/media/images/icons/kunze-gmap.png',
					icon_size:{width:18,height:22}
				}
			}
			/*setCenter: {
				lat:'48.032956',
				lng:'11.586003',
				geoCodeAddr: '',
				marker: {
					title: 'Kunze Folien GmbH',
					clear:true,
					image_src: DOMAIN_SUBFOLDER_WWW_ROOT+'local/media/images/icons/kunze-gmap.png',
					icon_size:{width:18,height:22}
				},
				mark:'hidden'
			}*/
		});	
		
	}
	
	
	//---------------------------------------------------------------------------------------
	this.loadData= function(data) {
		//DebugDump(data,'data');
		this.data = data;
	}	
	
	//---------------------------------------------------------------------------------------
	this.clearOnFocus = function() { // ext version
		/**
		* Clears all input/textareas with classname "clearonfocus"
		* on focus-Mouseevent. -- works bad on textareas with much text...
		*/
		
		var cofs = Ext.DomQuery.jsSelect('.cof');
		
		Ext.each(cofs,function(input) {
			var input = Ext.get(input);
			input._defaultValue = input.getAttribute('title');
			if((input._defaultValue) && (input._defaultValue.length > 0)) {
				if((!input.id) || (input.id.length == 0)) input.id = 'id'+new Date().format('YmdHis')+'_'+(1+Math.floor((Math.random()*32767)));
				//DebugDump(input,'input');
				input.dom.removeAttribute('title');
				
				input.qtip = new Ext.ToolTip({
					target: input.id,
					cls:'xlocal',
					anchor: 'top',
					autoHide: true,
					dismissDelay:0,
					anchorOffset: 10,
					html: input._defaultValue
				});
				
				input.addListener('focus', function(ev,input) {
					var input = Ext.get(input);
					if(input.getValue() == input._defaultValue) {
						$(input.id).value = '';
						//input.set({value:''});
						
					}
					input.addClass('on-focus');
					input.qtip.show();
				});
				input.addListener('blur', function(ev,input) {
					var input = Ext.get(input);
					if(input.getValue() == '') {
						//input.set({value:input._defaultValue});
						$(input.id).value=input._defaultValue;
					}
					input.removeClass('on-focus');	
					input.qtip.hide();
				});
			}
			
		});	
	}

	this.clearOnFocusOld = function() { // prototype version
		/**
		* 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.str_replace = function(search, replace, subject) {
	  var result = "";
	  var  oldi = 0;
	  for (i = subject.indexOf (search)
		 ; i > -1
		 ; i = subject.indexOf (search, i))
	  {
		result += subject.substring (oldi, i);
		result += replace;
		i += search.length;
		oldi = i;
	  }
	  return result + subject.substring (oldi, subject.length);
	}
	
	this.showTechPropertiesQtips = function() {
		
		if($('properties') && $('techdatatable')) {
			// if #properties and #techdatatable
			// gehe durch die tabelle, hole alle ths der beschreibungen und lege ein qtip auf die dazugehörige tr...?				
			var techdatatable = Ext.get('techdatatable');
			if(!techdatatable) return false;
			var pt = techdatatable.child('table');
			if(!pt) return false;
			var etrs = pt.select('tr');
			if(!etrs) return false;
			//DebugDump(etrs,'etrs '+etrs.elements.length);
			var trs = etrs.elements;
			//DebugDump(trs,'trs '+trs.length);
			
			for(tridx=0;tridx<trs.length;tridx++) {
				var eTr = Ext.get(trs[tridx]);
				if((!eTr.id) || (eTr.id.length == 0)) eTr.id = 'id'+new Date().format('YmdHis')+'_'+(1+Math.floor((Math.random()*32767)));
				th_desc = eTr.child('th.align-left',false);
				//DebugDump(th_desc,'th_desc '+th_desc.innerHTML);
				if(th_desc) {
					if(th_desc.hasClass('category')) continue;
					//DebugDump(th_desc,'th_desc '+th_desc.dom.innerHTML);
					var txt = th_desc.dom.innerHTML;
					txt = this.str_replace(' ','&nbsp;',txt)+'&nbsp;&nbsp;&nbsp;';
					eTr.qtip = new Ext.ToolTip({
						target: eTr.id,
						cls:'xlocal',
						anchor: 'top',
						autoHide: true,
						dismissDelay:0,
						anchorOffset: 10,
						trackMouse: true,
						maxWidth:500,
						html: txt
					});					
				}
				
			}
		}
			
	}
	
	//---------------------------------------------------------------------------------------
	this.orderProductModel=function(e,product_sid) {

		if(!product_sid) {
			Ext.Msg.alert('Error', 'No product found');
			return false;
		}
		
		if(e) var evTarget = IF.gettarget(e); //'.x-grid3-row'
		else var evTarget = document.body;
		if(!evTarget.id) evTarget.id = false;
		
		var win_id = 'order_model_win';
		var form_id = win_id+'_form';
		//DebugDump(win_id,'win_id '+win_id); 
		//DebugDump(form_id,'form_id '+form_id); 
		
		var baseParams = {product_sid:product_sid};
		
		var default_conf = {
			xtype:'xphposlocalform'
			,bParams:baseParams
			,id: form_id
			,p_id: form_id
			,cls:'xlocal x-orderform'
			//,p_height: h
			//,p_width: w
			,win_id: win_id
			//,grid_id: this.id
			,sid:product_sid
			,content_key:'product_orderform'
			,waitMsgTarget:win_id
		};

		if(typeof conf != 'object') var conf = {};
		Ext.apply(conf,default_conf); 
		var pos = this.getPosition(450,500);

		var win_conf = {
			 id: win_id
			,form_id: form_id
			,animateTarget:evTarget.id
			,modal: true
			//,x:pos.x
			//,y:pos.y
			,title:$L('order_model')
			,iconCls: 'x-cart-ico'
			,width: 450
			,height: 500
			,cls:'xlocal'
			,stateful:false
			//,stateEvents:["resize"] //"drop","close","collapse","expand"
			//,stateId:this.win_id+this.content_key				//,x:x
			//,y:y
			,plain:true
			,layout:'fit'
			,closable:true
			,border:false
			,items:conf
			/*,listeners: {
				beforestatesave:function(p,state) {
					if(p && p.maximized) return false;
				}
			}*/				
		};

		//Ext.apply(conf,win_conf);
		var win = new Ext.Window(win_conf);
		//win.add(conf);
		win.doLayout();	
		
		win.on("close", this.onCloseProductModelWin, this);    
		/*win.on("show", function(w) {
				//FNK.checkAndSetPosition(w);
			},win,{delay:100}
		);*/ 

		//win.show(evTarget.id).defer(250);
		win.show.defer(50,win,[evTarget.id]);
		//win.show();
	}
	
	this.onCloseProductModelWin = function(w) {
		
	}
	
	this.submitOrderModel=function(fp,c) {
		//DebugDump(fp,'fp');
		//DebugDump(c,'c');
		
		var f = fp.getForm();
		var url = '/local/tools/x/ajax_order_model.php';
		var win = Ext.get(fp.p_id);
		if(win) win.mask($L('Saving'), 'x-mask-loading');
		Ext.Ajax.request({
			url: url,
			fp:fp,
			f:f,
			c:c,
			mask:true,
			scope:this,
			success: function(response,options){
				var responseData = Ext.util.JSON.decode(response.responseText);//passed back from server
				//DebugDump(responseData,'responseData');
				if(responseData['num_order_models'] > 0) {
					var num_cartitems = responseData['num_order_models'];
					// update cart
					var cartitems = Ext.get('cartitems');
					if(!cartitems) return false;
					if(num_cartitems == 1) cartitems.update(responseData['num_order_models'] +' '+$L('product'));
					else cartitems.update(responseData['num_order_models'] +' ' + $L('products'));
					
					var order_model_win = Ext.getCmp('order_model_win');
					
					// contexts save_cart / order
					switch(options.c) {
						case'save_cart':
							Ext.get(options.fp.p_id).unmask();
							order_model_win.close();
							cartitems.frame("049bdf", 1,{duration:0.5});
							break;
						case'order':
							order_model_win.close();
							location.href = '/kontakt/warenkorb';
							break;
					}
				} else {
					Ext.get(options.fp.p_id).unmask();
				}
				
			},
			failure: function(response,options){ 
				// do nothing
			},
			params: Ext.apply(f.baseParams,f.getValues())
		});	
	}
	
	this.deleteCartItem = function(productvariant_sid,product_sid) {
		
		var params = {productvariant_sid:productvariant_sid,product_sid:product_sid,c:'del'};
		var url = '/local/tools/x/ajax_order_model.php';
		
		// delete li
		var productvariant = Ext.get('productvariant'+productvariant_sid);
		productvariant.remove();
		// check if there are more items
		var product = Ext.get('product'+product_sid);
		has_childs = product.child('li');
		if(!has_childs) product.remove();
		// check if there ANY cartitems left
		var allcartitems = Ext.get('allcartitems');
		has_childs = allcartitems.child('ul');
		if(!has_childs) allcartitems.update('<p>'+$L('no_cart_items_found')+'</p>');
		
		Ext.Ajax.request({
			url: url,
			mask:true,
			scope:this,
			success: function(response,options){
				var responseData = Ext.util.JSON.decode(response.responseText);//passed back from server
				//DebugDump(responseData,'responseData');
				
				if(responseData['num_order_models'] == 0 || responseData['num_order_models'] >0) {
					var num_cartitems = responseData['num_order_models'];
					// update cart
					var cartitems = Ext.get('cartitems');
					if(num_cartitems == 1) cartitems.update(responseData['num_order_models'] +' '+$L('product'));
					else cartitems.update(responseData['num_order_models'] +' '+$L('products'));
				}
				
			},
			failure: function(response,options){ 
				// do nothing
			},
			params: params
		});			
		
	}
	
	//---------------------------------------------------------------------------------------
	
	this.newProduct = function(form,action) {
		
		Ext.getCmp(form.p_id).has_been_submitted = true;
		var data = action.result.metaData.data;
		var sid = false;
		for(i=0;i<data.length;i++) {
			if(data[i]['key'] == 'sid') var sid = data[i]['value'];
		}
		
		if(sid && sid.length >0) {
			
			PHPOS.addTab($L('hmproduct'),'hmproductlist'+sid,'x-cart-ico','xhmproducteditor',{
				content_key:'xhmproducteditor',
				product_sid:sid,
				sid:sid
			},{autoScroll:false,content_key:'xhmproducteditor',sid:sid});
			
			if(typeof form.win_id != 'undefined') Ext.getCmp(form.win_id).close();
		}		
		
	}
	
	this.duplicateProduct = function(form,tid,sid) {
		
		var ed = Ext.get(tid);
		ed.mask($L('Duplicating Record...'));
		
		var fields = form.getValues();		
		fields.noxml = true;
		fields.triggers = 'ajaxduplicatehmproduct';

		var url = '/ajax/dotrigger/hmproduct/'+sid;		
		Ext.Ajax.request({
			scope:this,
			method:'post',
			url: url,
			tid:tid,
			success: function(response,options){
				Ext.get(options.tid).unmask();
				var rData = Ext.util.JSON.decode(response.responseText);//passed back from server
				if(rData.product_sid) {
					var product_sid = rData.product_sid;
					PHPOS.addTab($L('hmproduct'),'hmproductlist'+product_sid,'x-cart-ico','xhmproducteditor',{
						content_key:'xhmproducteditor',
						product_sid:product_sid,
						sid:product_sid
					},{autoScroll:false,content_key:'xhmproducteditor',sid:product_sid});						
				} else Ext.Msg.alert("Error", rData.errorMsg);
				
			},
			failure: function(response,options){ 
			},
			params: fields
		});		

		
	}	
	
	//---------------------------------------------------------------------------------------
	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.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.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($('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);
	}	

	// deny submit on return
	this.check4Return = function(event) {
		if(typeof event == 'undefined' || !event) return true;
		var obj = event.target || event.srcElement;
		if((event.type == 'keypress' && event.keyCode == 13 )) {
			if ( event.preventDefault )
				event.preventDefault()
			else event.returnValue = false;		
		}
		return true;
	}
	
	//---------------------------------------------------------------------------------------
	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 inputs = Ext.DomQuery.jsSelect('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();			
			this.mask($L('Please wait, uploading file(s)...'));
		}
		return true;
	} 
	
	this.mask = function(msg) {
		if(!msg) var msg = $L('Loading...')
		//var m = Ext.getBody().mask();
		IF.coverbackground(true,0.9);
		var tpl = '';
		tpl += '<div id="maskmsg">';
		tpl += msg;
		tpl += '';
		tpl += '';
		tpl += '';
		tpl += '';
		tpl += '</div>';
		Ext.getBody().insertHtml('beforeEnd',tpl);
		window.scrollTo(0,0);
	}

	
	// checkPositions of Windows
	//-------------------------------------------------------------------------- //

	this.checkAndSetPosition = function(win) {
		
		scrolltop = PAGEdom.docScrollTop();
		var WHeight = GetWindowHeight();
		var WWidth = GetWindowWidth();
		var update_position = false;
		max = (scrolltop+WHeight);

		// height
		if(win.y<0) update_position = true;
		if(win.y<scrolltop) update_position = true;
		if((win.y+win.height)>(scrolltop+WHeight)) update_position = true;

		// width
		scrollleft = PAGEdom.docScrollLeft();
		var WWidth = GetWindowWidth();	
		if(win.x<0) update_position = true;
		if(win.x<scrollleft) update_position = true;
		if((win.x+win.width)>(scrollleft+WWidth)) update_position = true;		

		if(update_position) {
			win.setPosition(((WWidth/2)-(win.width/2)),(scrolltop+50));
		}

	}	

	// checkPositions of Windows
	//-------------------------------------------------------------------------- //

	this.getPosition = function(win_width,win_height) {
		
		scrolltop = PAGEdom.docScrollTop();
		var WHeight = GetWindowHeight();
		var WWidth = GetWindowWidth();
		max = (scrolltop+WHeight);
		// width
		scrollleft = PAGEdom.docScrollLeft();
		var WWidth = GetWindowWidth();	
	
		return {x:((WWidth/2)-(win_width/2)),y:(scrolltop+50)};
	}	
}

var FNK = new KUNZE();
var DOMAIN_SUBFOLDER_WWW_ROOT = 'http://'+window.location.hostname+'/';
//DebugDump(DOMAIN_SUBFOLDER_WWW_ROOT,'DOMAIN_SUBFOLDER_WWW_ROOT');

function Tabs() {
	
	this.selectedTab = false;
	
	this.init = function(tel) {
				
		this.parent = Ext.get(tel);
		if(!this.parent) return false;
		// get all hrefs and initialize tab and search for selected tab
		var ahrefs = Ext.DomQuery.select('a',tel);
		for(a=0;a<ahrefs.length;a++) {
			var xEL = Ext.get(ahrefs[a]);
			if(xEL.hasClass('selected')) this.selectedTab = xEL;
			xEL.addListener('click',this.selectTab,this,[xEL]);
		}
	}
	
	this.selectTab = function(ev,el) {
		if(this.selectedTab) {
			this.selectedTab.removeClass('selected');
			var lEl = Ext.get('prod'+this.selectedTab.id);
			lEl.setStyle('display','none');
		}
		var xEl = Ext.get(el);
		xEl.addClass('selected');
		var nlEl = Ext.get('prod'+xEl.id);
		nlEl.setStyle('display','block');
		this.selectedTab = xEl;
		return false;
	}
	
}


//--------------------------------------------------------------------------------------- //
if(typeof Ext == 'object') {

	// application main entry point
	Ext.onReady(function() {

		Ext.BLANK_IMAGE_URL = '/images/spacer.gif';
		
		/*****************************************************
		*/ function _____P___Ext_FNKForm() {}
		/**************************************************
		****/
		
		//Ext.namespace("Ext.ux");
		//if(typeof console == 'object') console.log('x typeof Ext.ux: %o',typeof Ext.ux);
		//if(typeof console == 'object') console.log('x typeof Ext.ux.MetaForm: %o',typeof Ext.ux.MetaForm);
		
		if(typeof Ext.ux == 'object' && typeof Ext.ux.MetaForm == 'function') {

			/*****************************************************
			*/ function _____P___Ext_PHPOSForm() {}
			/**************************************************
			****/
			
			Ext.ux.PHPOSLocalForm = function(config) {
				if (!config) config = {};
				// call parent constructor
			
				if(!config.id) config.id = 'ed_form';
				if(!config.sid) config.sid = 'new';
				if(!config.content_key) {
					Ext.Msg.alert('Error', 'No content key found');
				}
				
				if(!config.labelAlign) config.labelAlign = 'left';
				if(!config.bbarHeight) config.bbarHeight = 30;
				
				if(typeof config.bParams == 'string') {
					var bParams = {noxml:'1'};
					var baseParams = Ext.urlDecode(config.bParams);
					Ext.apply(baseParams,bParams); 	
				} else if(typeof config.bParams == 'object') {
					var baseParams = {noxml:'1'};
					Ext.apply(baseParams,config.bParams); 	
				} else var baseParams = {noxml:'1'};
				
				loadMask = true;
				//if(config.loadMask == false) loadMask = config.loadMask;	
				
				if(!config.labelAlign) config.labelAlign = 'left';
				if(config.autoScroll !== false) config.autoScroll = true;
				
				
				Ext.apply(config, {
					url:'/ajax/xeditor/'+config.content_key+'/'+config.sid
					//,waitMsgTarget:config.id
					,bUrl:'/ajax/xeditor/'
					,collapsible:false
					,autoScroll:config.autoScroll
					,baseParams:baseParams
					/*,listeners: {
						//render: PHPOS.bbarStopStatusbar
					}*/
					,bbar: new Ext.ux.StatusBar({
						height:config.bbarHeight,
						enableOverflow:true,
						autoWidth:true
					})
					,defaults:{
						//labelAlign: config.labelAlign
						//,labelWidth: 200
					}
					,layoutConfig: {
						// layout-specific configs go here
						labelSeparator: ''
					}		
				}); // eo apply	
				
				Ext.ux.PHPOSLocalForm.superclass.constructor.call(this, config);
			};
			
			Ext.extend(Ext.ux.PHPOSLocalForm, Ext.ux.MetaForm, {
					// private
					onRender: function(ct, position) {
						Ext.ux.PHPOSLocalForm.superclass.onRender.call(this, ct, position);		
					}
				}
			);
				   
			// register xtype
			Ext.reg('xphposlocalform', Ext.ux.PHPOSLocalForm);
			
			/*****************************************************
			*/ function _____P___Ext_FNKForm() {}
			/**************************************************
			****/
		
			Ext.ux.FNKMForm = function(config) {
				if (!config) config = {};
				// call parent constructor
			
				if(!config.id) config.id = 'ed_form';
				if(!config.sid) config.sid = 'new';
				if(!config.content_key) {
					Ext.Msg.alert('Error', 'No content key found');
				}
				
				if(!config.labelAlign) config.labelAlign = 'left';
				if(!config.bbarHeight) config.bbarHeight = 30;
				
				if(typeof config.bParams == 'string') {
					var bParams = {noxml:'1'};
					var baseParams = Ext.urlDecode(config.bParams);
					Ext.apply(baseParams,bParams); 	
				} else if(typeof config.bParams == 'object') {
					var baseParams = {noxml:'1'};
					Ext.apply(baseParams,config.bParams); 	
				} else var baseParams = {noxml:'1'};
				
				loadMask = true;
				//if(config.loadMask == false) loadMask = config.loadMask;	
				
				if(!config.labelAlign) config.labelAlign = 'left';
				if(config.autoScroll !== false) config.autoScroll = true;
				
				
				Ext.apply(config, {
					url:'/ajax/xeditor/'+config.content_key+'/'+config.sid
					//,waitMsgTarget:config.id
					,bUrl:'/ajax/xeditor/'
					,collapsible:false
					,autoScroll:config.autoScroll
					,baseParams:baseParams
					,bbar:false
					//,bbar: new Ext.ux.StatusBar({
						//height:config.bbarHeight,
						//enableOverflow:true,
						//autoWidth:true
					//})
					,defaults:{
						//labelAlign: config.labelAlign
						//,labelWidth: 200
					}
					,layoutConfig: {
						// layout-specific configs go here
						labelSeparator: ''
					}		
				}); // eo apply	
				
				Ext.ux.FNKMForm.superclass.constructor.call(this, config);
			};
			
			Ext.extend(Ext.ux.FNKMForm, Ext.ux.MetaForm, {
					// private
					onRender: function(ct, position) {
						//Ext.ux.TinyMCE.superclass.onRender.call(this, ct, position);
						//if(typeof console == 'object') console.log('x FNKMForm onRender typeof position: %o',typeof position);
						//if(typeof console == 'object') console.log('x  FNKMForm onRender position: %o',position);
						Ext.ux.FNKMForm.superclass.onRender.call(this, ct,position);		
					}
				}
			);
				   
			// register xtype
			Ext.reg('xfnkform', Ext.ux.FNKMForm);
			
			
			/*****************************************************
			*/ function _____P___Ext_ProductValueField() {}
			/**************************************************/
			
			Ext.ux.RangeField = Ext.extend(Ext.form.Field, {
				/**
				 * @cfg {String/Object} defaultAutoCreate DomHelper element spec
				 * Let superclass to create hidden field instead of textbox. Hidden will be submittend to server
				 */
				 defaultAutoCreate:{tag:'input', type:'hidden'}
				/**
				 * @cfg {Number} timeWidth Width of time field in pixels (defaults to 100)
				 */
				/**
				 * private
				 * creates DateField and TimeField and installs the necessary event handlers
				 */
				,initComponent:function() {
					// call parent initComponent
					Ext.ux.RangeField.superclass.initComponent.call(this);
					//DebugDump(this,'this '+this.id);
					
					this.baseName = this.hiddenName;
					this.hiddenName = this.hiddenName+'[none]';
					this.name = this.hiddenName;
					//if(this.default_value) this.setValue(this.default_value);
					//DebugDump(this,'this '+this.value);
					
					// create Combo From
					//DebugDump(aConfig,'aConfig '+aConfig.value);
					//DebugDump(this.astore,'this.astore ');
					if(this.astore) { // only on combo boxes?
						var astore = new Ext.data.ArrayStore({
							fields: [{name:'list_value'},{name:'list_label'}],
							data : this.astore['data']
						});
						//DebugDump(astore,'astore');
					}					
					
					
					var aConfig = Ext.apply({}, {
						id:this.id + '-a',
						name:this.baseName+'[combo-a]',
						hiddenName:this.baseName+'[a]',
						//,format:this.displayDateFormat || Ext.form.DateField.prototype.format
						width:75,
						store: astore,
						displayField:'list_label',
						valueField:'list_value',
						forceSelection:true,
						typeAhead: true,
						mode: 'local',
						triggerAction: 'all',
						editable:true,
						emptyText:$L('Select...'),
						selectOnFocus:true
						/*,listeners:{
							  blur:{scope:this, fn:this.onBlur}
							 ,focus:{scope:this, fn:this.onFocus}
						}*/
					}, this.aConfig);
								
		
					this.df = new Ext.form.ComboBox(aConfig);
					//DebugDump(this.df,'this.df');
					this.df.ownerCt = this;
		
					
					// create TimeField
					if(this.bstore) { // only on combo boxes?
						var bstore = new Ext.data.ArrayStore({
							fields: [{name:'list_value'},{name:'list_label'}],
							data : this.bstore['data']
						});
						//DebugDump(bstore,'bstore');
					}	
					
					var bConfig = Ext.apply({}, {
						id:this.id + '-b',
						name:this.baseName+'[combo-b]',
						hiddenName:this.baseName+'[b]',
						//,format:this.displayDateFormat || Ext.form.DateField.prototype.format
						width:75,
						store: bstore,
						displayField:'list_label',
						valueField:'list_value',
						forceSelection:true,
						typeAhead: true,
						mode: 'local',
						triggerAction: 'all',
						emptyText:$L('Select...'),
						selectOnFocus:true
						/*,listeners:{
							  blur:{scope:this, fn:this.onBlur}
							 ,focus:{scope:this, fn:this.onFocus}
						}*/
					}, this.bConfig);
					
					if(this.hide_timefield === true) this.tf = new Ext.form.Hidden(bConfig);
					else this.tf = new Ext.form.ComboBox(bConfig);
					this.tf.ownerCt = this;
					//this.tf.hidden = true;
					//DebugDump(this.tf,'bConfig '+bConfig.value);
					
					//onTriggerClick
					// relay events
			//		this.relayEvents(this.df, ['focus', 'specialkey', 'invalid', 'valid']);
			//		this.relayEvents(this.tf, ['focus', 'specialkey', 'invalid', 'valid']);
					
			//		this.on('specialkey', this.onSpecialKey, this);
					this.on('disable', this.onDisable, this);
					this.on('enable', this.onEnable, this);
					this.on('reset', this.onReset, this);
					
				} // eo function initComponent
				// }}}
				// {{{
				/**
				 * private
				 * Renders underlying DateField and TimeField and provides a workaround for side error icon bug
				 */
				,onRender:function(ct, position) {
					// don't run more than once
					if(this.isRendered) {
						return;
					}
			
					// render underlying hidden field
					Ext.ux.RangeField.superclass.onRender.call(this, ct, position);
			
					// render DateField and TimeField
					// create bounding table
					var t;
					if('below' === this.timePosition || 'bellow' === this.timePosition) {
						t = Ext.DomHelper.append(ct, {tag:'table',style:'border-collapse:collapse',children:[
							 {tag:'tr',children:[{tag:'td', style:'padding-bottom:1px', cls:'ux-datetime-date'}]}
							,{tag:'tr',children:[{tag:'td', cls:'ux-datetime-time',html:$L('to')}]}
							,{tag:'tr',children:[{tag:'td', cls:'ux-datetime-time'}]}
						]}, true);
					}
					else {
						t = Ext.DomHelper.append(ct, {tag:'table',style:'border-collapse:collapse',children:[
							{tag:'tr',children:[
								{tag:'td',style:'padding-right:4px', cls:'ux-datetime-date'},{tag:'td',style:'padding-right:4px', cls:'ux-range-label',html:$L('to')},{tag:'td', cls:'ux-datetime-time'}
							]}
						]}, true);
					}
			
					this.tableEl = t;
			//        this.wrap = t.wrap({cls:'x-form-field-wrap'});
					this.wrap = t.wrap();
					//this.wrap.on("mousedown", this.onMouseDown, this, {delay:10});
			
					// render DateField & TimeField
					this.df.render(t.child('td.ux-datetime-date'));
					this.tf.render(t.child('td.ux-datetime-time'));
			
					// workaround for IE trigger misalignment bug
					//if(Ext.isIE && Ext.isStrict) {
						//t.select('input').applyStyles({top:0});
					//}
			
					
			//		this.df.el.swallowEvent(['keydown', 'keypress']);
			//		this.tf.el.swallowEvent(['keydown', 'keypress']);
			
					// create icon for side invalid errorIcon
					/*if('side' === this.msgTarget) {
						var elp = this.el.findParent('.x-form-element', 10, true);
						this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
			
						this.df.errorIcon = this.errorIcon;
						this.tf.errorIcon = this.errorIcon;
					}*/
			
					// create icon for side invalid errorIcon
					if('side' === this.msgTarget) {
						var elp = this.el.findParent('.x-form-element', 10, true);
						if(elp) {
							this.errorIcon = elp.createChild({cls:'x-form-invalid-icon'});
						}
			
						var o = {
							 errorIcon:this.errorIcon
							,msgTarget:'side'
							,alignErrorIcon:this.alignErrorIcon.createDelegate(this)
						};
						Ext.apply(this.df, o);
						Ext.apply(this.tf, o);
			//            this.df.errorIcon = this.errorIcon;
			//            this.tf.errorIcon = this.errorIcon;
					}
			
					// setup name for submit
			//		this.el.dom.name = this.hiddenName || this.name || this.id;
			
					// prevent helper fields from being submitted
			//		this.df.el.dom.removeAttribute("name");
			//		this.tf.el.dom.removeAttribute("name");
			
					// we're rendered flag
					this.isRendered = true;
					
					//DebugDump(this.field_values,'field_values');
					if(this.field_values && this.field_values['a']) this.df.setValue(this.field_values['a']);
					if(this.field_values && this.field_values['b']) this.tf.setValue(this.field_values['b']);			
					
					// update hidden field
					// this.updateHidden();
					// this.setValue(this.el.dom.value);
				} // eo function onRender
				
				,onDisable:function(t) {
					if(t) {
						this.df.disable();
						this.tf.disable();
					}
				}
				
				,onEnable:function(t) {
					if(t) {
						this.df.enable();
						this.tf.enable();
					}
				}
				
				,onReset:function() {
					this.df.enable();
					this.tf.enable();
					this.df.reset();
					this.tf.reset();					
				}
			
			}); // eo extend
			
			// register xtype
			Ext.reg('xrangefield', Ext.ux.RangeField);
		
		}
		IF.init();
		FNK.init();
		if(typeof PHPOS == 'object') PHPOS.initForeign();
	}); // eo function onReady




states = [
        ['AL', 'Alabama', 'The Heart of Dixie'],
        ['AK', 'Alaska', 'The Land of the Midnight Sun'],
        ['AZ', 'Arizona', 'The Grand Canyon State'],
        ['AR', 'Arkansas', 'The Natural State'],
        ['CA', 'California', 'The Golden State'],
        ['CO', 'Colorado', 'The Mountain State'],
        ['CT', 'Connecticut', 'The Constitution State'],
        ['DE', 'Delaware', 'The First State'],
        ['DC', 'District of Columbia', "The Nation's Capital"],
        ['FL', 'Florida', 'The Sunshine State'],
        ['GA', 'Georgia', 'The Peach State'],
        ['HI', 'Hawaii', 'The Aloha State'],
        ['ID', 'Idaho', 'Famous Potatoes'],
        ['IL', 'Illinois', 'The Prairie State'],
        ['IN', 'Indiana', 'The Hospitality State'],
        ['IA', 'Iowa', 'The Corn State'],
        ['KS', 'Kansas', 'The Sunflower State'],
        ['KY', 'Kentucky', 'The Bluegrass State'],
        ['LA', 'Louisiana', 'The Bayou State'],
        ['ME', 'Maine', 'The Pine Tree State'],
        ['MD', 'Maryland', 'Chesapeake State'],
        ['MA', 'Massachusetts', 'The Spirit of America'],
        ['MI', 'Michigan', 'Great Lakes State'],
        ['MN', 'Minnesota', 'North Star State'],
        ['MS', 'Mississippi', 'Magnolia State'],
        ['MO', 'Missouri', 'Show Me State'],
        ['MT', 'Montana', 'Big Sky Country'],
        ['NE', 'Nebraska', 'Beef State'],
        ['NV', 'Nevada', 'Silver State'],
        ['NH', 'New Hampshire', 'Granite State'],
        ['NJ', 'New Jersey', 'Garden State'],
        ['NM', 'New Mexico', 'Land of Enchantment'],
        ['NY', 'New York', 'Empire State'],
        ['NC', 'North Carolina', 'First in Freedom'],
        ['ND', 'North Dakota', 'Peace Garden State'],
        ['OH', 'Ohio', 'The Heart of it All'],
        ['OK', 'Oklahoma', 'Oklahoma is OK'],
        ['OR', 'Oregon', 'Pacific Wonderland'],
        ['PA', 'Pennsylvania', 'Keystone State'],
        ['RI', 'Rhode Island', 'Ocean State'],
        ['SC', 'South Carolina', 'Nothing Could be Finer'],
        ['SD', 'South Dakota', 'Great Faces, Great Places'],
        ['TN', 'Tennessee', 'Volunteer State'],
        ['TX', 'Texas', 'Lone Star State'],
        ['UT', 'Utah', 'Salt Lake State'],
        ['VT', 'Vermont', 'Green Mountain State'],
        ['VA', 'Virginia', 'Mother of States'],
        ['WA', 'Washington', 'Green Tree State'],
        ['WV', 'West Virginia', 'Mountain State'],
        ['WI', 'Wisconsin', "America's Dairyland"],
        ['WY', 'Wyoming', 'Like No Place on Earth']
    ];


	
	/*****************************************************
	 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');
	  }
	}
}

