//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//INIT DirectoryContent
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (Browser.Engine.name == "trident" && Browser.Engine.version < 5) {
	var ie6 = true;
}
var ItemID='';
var linkDirectory=false;
var targetDiv;
var category;
if ((aktivnav == 0 && subAktiv == 0)){
		targetDiv = 'c_Mietangebote';
	}
if ((aktivnav == 0 && subAktiv == 1)){
	targetDiv = 'c_Kaufangebote';
}
if ((aktivnav == 0 && subAktiv == 2)){
	targetDiv = 'c_Industrieland';
}
var deskJS;
var listObj;
var response;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//INIT Content
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
window.addEvent('resize',function(){
	location.href = location.href;	
});
window.addEvent('domready', function() {
	
	var container = $('fading');
	var hovArr = container.getElements('img');
	new Asset.images(hovArr, {
		onComplete: function(){
			new fade();
		}
	});
	steps=0;
	slider=0;
	if ($('thumb') != null) {
		$('thumb').destroy();
	}
	if ($('track')!=null){
		$('track').destroy();
	}
	new Element('div', {
		'id': 'track'
	}).inject($('container'));
	new Element('div', {
		'id': 'thumb'
	}).inject($('track'));
	makeScrollbar($('content'), $('track'), $('thumb'));
	new navi();
	
	
	deskJS = new Class({
		
		// Implements
		Implements: addDeskJS
		
		//options
		,options: {
			_verzLocal:0
			,verzUser: 'brunbauplanung'
			,_verzDebug:1
		}
		// Initialization
		,initialize: function(options) {
			// set options
			this.setOptions(options);
			// HistoryManager
			HistoryManager = new HistoryManager();
			this.history = HistoryManager.register(
				'verz'
				,['']
				,function(values){
					if(values.length > 1){
						this._directLink('verz', values[0], values[1], values[2]);
					} 
				}.bind(this)
				,function(values){
					return 'verz(' + values[0] + '_' + values[1] + '_' + values[2] + ')';
				}.bind(this)
				,/verz\((.*)_(.*)_(.*)\)/
			);
			HistoryManager.start();
			
			var cat ='';
			
			if(id != '21' && id!='23'){
				if ((aktivnav == 0) && (subAktiv == 0)){
					cat = 'Mietangebote';
				}
				else if ((aktivnav == 0 && subAktiv == 1)){
					cat = 'Kaufangebote';
				}
				else if ((aktivnav == 0 && subAktiv == 2)){
					cat = 'Bauland';
				}
				else 
				if(linkDirectory==true){
					cat=category;
				}
			}
			this._verzReqStr = {
				type: 'all'
				,user: this.options.verzUser
				,table: {
					listingdatas: 'ld'
					,listingrows: 'lr'
					,listings: 'l'
				}
				,condition: {
					'lr.rubrikname': cat
				}
				,fields: 'lr.*,ld.*'
				,order: 'ld.position ASC'
				,language: lang
			}
			this._verzReq('showNews');
		}
		// Aufruf durch Verzeichnisverlinkung
		,_directLink: function(mode, DBstr, lrID, ldID){
			linkDirectory=true;
			if (lrID == 25) {
				targetDiv = 'c_Mietangebote';
				category='Mietangebote';
				if(ldID==14){
					ItemID=0;
				}
				if(ldID==20){
					ItemID=1;
				}
				if(ldID==21){
					ItemID=2;
				}
			}
			if (lrID == 26) {
				targetDiv = 'c_Kaufangebote';
				category='Kaufangebote';
				ItemID=0;
			}
			if (lrID == 27) {
				targetDiv = 'c_Bauland';
				category='Bauland';
				if(ldID==25){
					ItemID=0;
				}
				if(ldID==30){
					ItemID=1;
				}
				if(ldID==37){
					ItemID=2;
				}
			}
			new core();
			
		}
		,showNews: function(res){
		var chkStr;
		var urlroot;
		chkStr = window.location.href.search(/192.168/);
		if(chkStr != -1) urlroot = '';
		else urlroot = root;
		var items = 0;
		var left ='';
		var height ='';
		var namePic1=root+'images/img_01.jpg';
		var namePic2=root+'images/img_02.jpg';
		var namePic3=root+'images/img_03.jpg';
		response = res;
		listObj = JSON.decode(response);
		if (linkDirectory == true) {
			$('DirectoryContent').setStyle('visibility','visible');
			showDetail(response.result[ItemID],0);
		}
		response.result.each(function(entry,key){
			if( key%2 == 0 ){
				left= '0px';
				if (key!=0){
					height= -(key-1)*155+'px';
					if(Browser.Engine.trident){
						height=-((key-1)*165)+'px';
					}
				}
			}
			else{
				left = '200px';
				if(key>1){
					height =-(key-1)*165+'px';
					if(Browser.Engine.trident){
						height=-((key-1)*165)+'px';
					}
				}
				else{
					height = -177+'px';
					if(Browser.Engine.trident){
						height=-168+'px';
					}
				}
			}
			
			m = key % 2 == 0 ? 40 : 0;
			
			objContainer = new Element('div',{
				'styles':{
					'float': 'left'
					,'margin-right': m
					,'width': 180
				}
			}).inject($(targetDiv))
			
			if($defined(entry.ld.bilder.media)){
				
				entry.ld.bilder.media.each(function(pic, picCounter){
					if (picCounter == 0) {
						new Element('img', {
							'src': root + 'upload/100x_verz_' + pic.name,
							'styles': {
								'height': 114 + 'px',
								'cursor':'pointer'
							},
							'id': 'img' + picCounter
							,events: {
								'click': function(){
									showDetail(entry,key);
								}
							}
						}).inject(objContainer)
					}
				});
			}
			
			new Element('div',{
				'html': '<b>'+entry.ld.bezeichnung+'</b><br>'+entry.ld.adresse+'<br><br>'
				,'styles':{
					'width':'180px'
					,'cursor':'pointer'
					,'padding-top':'5px'
				}
				,'id':'entry'+key
				,'class':'dirList'
				,events:{
					'click':function(){
						showDetail(entry, key);
					}
				}
			}).inject(objContainer)
			items = key;
		});
		
		objContainer = new Element('div',{
			'styles':{
				'clear': 'both'
			}
		}).inject($(targetDiv))

		if(items>=2){
			steps=0;
			slider=null;
			$('thumb').destroy();
			$('track').destroy();
			new Element('div', {
				'id': 'track'
			}).inject($('container'));
			new Element('div', {
				'id': 'thumb'
			}).inject($('track'));
			makeScrollbar($('content'),$('track'),$('thumb'));
		}
		
	}
	});
	//new core();
	overlay = new Element('div', {
		'id': 'BoxOverlay',
		'styles': {
			'display': 'block',
			'z-index': '998',
			'position': 'absolute',
			'top': '0',
			'left': '0',
			'background-color': '#000',
			'opacity': 0
		}
	}).inject(document.body);
	deskJS = new deskJS();
	
});

var steps
var slider;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Scrollbar FUNCTION
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function makeScrollbar(content, Xscrollbar, handle, horizontal, ignoreMouse){
	steps=0;
	p=0;
	steps = (horizontal ? (content.getScrollSize().x - content.getSize().x) : (content.scrollHeight+p - content.getSize().y))
	
	if (steps > 0) {
		Xscrollbar.setStyle('display', 'block');
		handle.setStyle('display', 'block');
	}
	else {
		Xscrollbar.setStyle('display', 'none');
		handle.setStyle('display', 'none');
	}
	slider = new Slider(Xscrollbar, handle, {
		steps: steps,
		mode: (horizontal ? 'horizontal' : 'vertical'),
		onChange: function(step){
			var x = (horizontal ? step : 0);
			var y = (horizontal ? 0 : step);
			content.scrollTo(x, y);
		}
	}).set(0);
	if (!(ignoreMouse)) {
		$$('#scrollBody', '#container', '.subnav', '#header', '#footer', content, Xscrollbar).addEvent('mousewheel', function(e){
			e = new Event(e).stop();
			var step = slider.step - (e.wheel / 2) * 30;

			slider.set(step);
		});
	}
	$(document.body).addEvent('mouseleave', function(){
		slider.drag.stop();
	});
}
var container;
var images
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Fade Class
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var fade = new Class({
	initialize: function(){
		/* settings */
		var showDuration = 5000;
		if($defined(container)){
			container = null;
		}
		container = $('fading');
		images = container.getElements('img');
		var currentIndex = 0;
		var interval;
		/* opacity and fade */
		images.each(function(img,i){ 
			if(i > 0) {
				img.set('opacity',0);
			}
		});
		/* worker */
		var show = function() {
			images[currentIndex].fade('out');
			images[currentIndex = currentIndex < images.length - 1 ? currentIndex+1 : 0].fade('in');
		};
		/* start once the page is finished loading */
//		window.addEvent('load',function(){
			interval = show.periodical(showDuration);
//		})
	}
})
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Navi Class
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var navi = new Class({
	initialize: function(){
		//SUBMENUDIVS SUCHEN
		alldiv = $$('.subnav');	
		alldiv.each(function(div,item,index) {
			//sobald ein Hauptnavigationspunkt aktiv ist, ist die Subnav dauernd sichtbar
			if(item == aktivnav || 'home' == aktivnav){
				if(item=aktivnav && aktivnav !='home'){
					this.showSub(div.id);
				}
			}
			//setze mouseenter und mouseleve Erreignisse
			if(item !=aktivnav){
				if(div.className == "subnav"){
					if (div.id != 'subnav'+aktivnav){
						div.addEvent('mouseenter',function(e) {
							this.showSub(div.id);
						}.bind(this));
						div.addEvent('mouseleave',function(e) {
							this.hideSub(div.id);
						}.bind(this));
					}
				}
			}
		},this);

		//ALLEN MAINNAVS AKTION ZUORDNEN BEI OVER
		var allmenu = $('nav').getElements('li');

		allmenu.each(function(li,item,index) {
			if (Browser.Engine.name == "trident" && Browser.Engine.version < 5) {
				li.setStyle('width','135px');
			}
			$('subnav' + item).setStyle('width', li.getStyle('width'));
			var posi = li.getPosition().x+1;
			if(item == aktivnav){
				$('mainNav'+item).setStyle('background-color','#8e7f71');
				if ($defined($('subnav' + item))){
					$('subnav' + item).setStyle('left', posi + 'px');
					$('subnav' + item).setStyle('height', '0px');
					$('subnav' + item).setStyle('opacity', 0.9);
					$('subnav' + item).setStyle('display', 'block');
					
					aniheight = 103;

					var blenddown = new Fx.Tween($('subnav' + item), {
						duration: 400
					});
					blenddown.start('height', $('subnav' + item).getStyle('height'), aniheight + "px");
				}
			}
			li.addEvent('mouseenter',function(e) {
				$('mainNav'+item).setStyle('background-color','#8e7f71');
				if ($defined($('subnav' + item)) && item != aktivnav){
					aniheight = 103;
					$('subnav' + item).setStyle('left', posi + 'px');
					$('subnav' + item).setStyle('height', aniheight);
					$('subnav' + item).setStyle('opacity', 0);
					$('subnav' + item).setStyle('display', 'block');
					var blenddown = new Fx.Tween($('subnav' + item), {
						duration: 200
					});
					blenddown.start('opacity', $('subnav' + item).getStyle('opacity'), 0.9);
					$('mainNav'+item).addEvent('mouseleave',function(e){
							$('mainNav' + item).setStyle('background-color', '');
						});
					li.addEvent('mouseleave',function(e) {
						if ($defined($('subnav' + item))) {
							$('subnav'+item).setStyle('opacity',0);
							$('subnav'+item).setStyle('display','none');
						}
						
					});
					if ($defined($('subnav' + item))) {
						$('subnav' + item).addEvent('mouseenter', function(e){
							$('mainNav' + item).setStyle('background-color', '#8e7f71');
						});
						$('subnav' + item).addEvent('mouseleave', function(e){
							$('mainNav' + item).setStyle('background-color', '');
						});
					}
					else{
						
					}
				}
	 		});
			li.addEvent('mouseleave',function(e) {
				if (item != aktivnav) {
					$('mainNav' + item).setStyle('background-color', '#725f4e');
				}
	 		});
		});
	},
	
	showSub: function(subelement){	
		var no = subelement.substr( subelement.length-1, 1);
		$(subelement).setStyle('opacity',0.9);
		$(subelement).setStyle('display','block');
	},
	
	hideSub: function(subelement){
		var no = subelement.substr( subelement.length-1, 1);
		$(subelement).setStyle('opacity',0);
		$(subelement).setStyle('display','none');
	}
});
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//show directory detail
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function showDetail(item,key){
	if ($$('.fadeIMG').length > 3) {
		$$('.fadeIMG').each(function(pic, id){
			if (id > 2) {
				pic.destroy();
			}
		})
		new fade();
	}
	var targetText = $(targetDiv);
	var targetImage1 = $('fade1');
	var targetImage2 = $('fade2');
	var targetImage3 = $('fade3');
	var entry;
	var contentToDisplay = $('DirectoryContent');
	
	entry = item;
	if ($defined(entry.ld.bilder.media[0])) 
		namePic1 = root + 'upload/360x_verz_' + entry.ld.bilder.media[0].name;
	if ($defined(entry.ld.bilder.media[1])) 
		namePic2 = root + 'upload/360x_verz_' + entry.ld.bilder.media[1].name;
	else {
		namePic2 = root + 'upload/360x_verz_' + entry.ld.bilder.media[0].name;
	}
	if ($defined(entry.ld.bilder.media[2])) 
		namePic3 = root + 'upload/360x_verz_' + entry.ld.bilder.media[2].name;
	else {
		namePic3 = root + 'upload/360x_verz_' + entry.ld.bilder.media[0].name;
	}
	targetText.style.visibility = 'hidden';
	contentToDisplay.style.visibility = 'visible';
	$('fade1').removeAttribute('src');
	$('fade2').removeAttribute('src');
	$('fade3').removeAttribute('src');
	$('fade1').setAttribute('src',namePic1);
	$('fade2').setAttribute('src',namePic2);
	$('fade3').setAttribute('src',namePic3);
	
	var header = new Element('div',{
		'width': 430
		
	}).inject($('DirectoryContent'))
	
	if(entry.ld.bezeichnung !='zur Zeit sind leider keine Angebote verfügbar'){
		new Element('div',{
			'html': '<b> <font color="#293A68"><br/><br/>'+entry.ld.bezeichnung+'</font></b><br />'+ entry.ld.adresse +'<br /><br />'+entry.ld.detail.text+'<br /><br /><b>Ihre Vorteile:</b>&nbsp;'+entry.ld.beschreibung.text +'<br /><br /><b>Bezug:</b>&nbsp;'+entry.ld.bezug+'<br /><br /><b>Kontaktperson:&nbsp;</b>'+entry.ld.zuestaendig+'<br /><br /><b>Telefon:&nbsp;</b>'+entry.ld.tel+'<br><br>'
		}).inject($('DirectoryContent'))
	}
	else{
		new Element('div',{
			'html': '<b>zur Zeit sind leider keine Angebote verfügbar</b>'
			}).inject($('DirectoryContent'))
	}

	var topLinks = ($('DirectoryContent').getScrollHeight());
	var topHeight = topLinks;
	if (topLinks <= ($('DirectoryContent').getHeight())){
		topHeight=305;
	}

	new Element('div',{
		'html': '<a href="'+window.location.href+'">zurück zur Übersicht</a><br />'
		,'styles':{
			'position':'absolute'
			,'height':'11px'
			,'left':0
			,'top':'7px'
		}
		,events: {
			'click': function(){
				targetText.style.visibility = 'visible';
				contentToDisplay.style.visibility = 'hidden';
			}
		}
	}).inject(header)
	var contactForm = new Element('div', {
		'html': '<a href="#"><b> Kontakt </b></a>',
		'styles': {
			'position': 'absolute',
			'height': '20px',
			'width': '90px',
			'right': '0px',
			'background-color': '#B1B1B1',
			'top': '0px'
		},
		'class': 'dirInterest',
		events: {
			'click': function(){
				getDocs(entry.ld.bezeichnung + ':', entry.ld.adresse);
				return false;
				targetText.style.visibility = 'visible';
				contentToDisplay.style.visibility = 'hidden';
			}
		}
	})
	if ($defined(entry.ld.pdfs.media)) {
		entry.ld.pdfs.media.each(function(subitems, subkey){
			if (subitems.name.contains('dossier')||subitems.name.contains('dokumentation')) {
			new Element('div', {
				'html': '<a href="' + root + 'upload/' + decodeURIComponent(subitems.name) + '" target="_blank" style="width:100px; overflow:hidden;"><b> Dokumentation </b></a>',
				'styles': {
					'position': 'absolute',
					'height': '20px',
					'width': '90px',
					'top': 0 + 'px',
					'left': '150px',
					'background-color': '#B1B1B1'
				},
				'class': 'dirInterest',
				'id':'btnDocumentation'
			}).inject(header)
			}
			if (subitems.name.contains('anmeldung')) {
				new Element('div', {
					'html': '<a href="' + root + 'upload/' + decodeURIComponent(subitems.name) + '" target="_blank" style="width:100px; overflow:hidden;"><b> Anmeldung </b></a>',
					'styles': {
						'position': 'absolute',
						'height': '20px',
						'width': '90px',
						'top': 0 + 'px',
						'left': '245px',
						'background-color': '#B1B1B1'
					},
					'class': 'dirInterest',
					'id':'btnAnmeldung'
				}).inject(header)
			}
		});
		if(ie6==true){
			$('btnDocumentation').setStyle('left','135px');
			$('btnAnmeldung').setStyle('left','240px');
		}
	}
	contactForm.inject($('DirectoryContent'));
	new Element('div',{
		'html': '<a href="'+window.location.href+'">zurück zur Übersicht</a><br>'
		,'styles':{
			'position':'relative'
			,'height':'20px'
			,'width':'190px'
			,'bottom':'0px'
			,'left':'0px'
			,'background-color':'#f5f2e9'
		}
		,events: {
			'click': function(){
				targetText.style.visibility = 'visible';
				contentToDisplay.style.visibility = 'hidden';
			}
		}
		,'class':'linkBack'
	}).inject($('DirectoryContent'))
	steps=-1;
	slider=null;
	$('thumb').destroy();
	$('track').destroy();
	new Element('div', {
		'id': 'track'
	}).inject($('container'));
	new Element('div', {
		'id': 'thumb'
	}).inject($('track'));
	makeScrollbar($('content'), $('track'), $('thumb'));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//prepares interest form FUNCTION
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getDocs(objTitel,objSubTitel){
	var title=objTitel +'<br>'+objSubTitel;
	popupWindow(0,title);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//popup FUNCTION
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function popupWindow(camNo,Wtitle){
	$('BoxOverlay').setStyles({
		width: window.getScrollWidth() + 'px',
		height: window.getScrollHeight() + 'px'
	});
	var popHeight;
	var popWidth;
	winWidth = 760;
	topmargin = window.getScrollHeight() / 2 - 320;
	
	winHeight = 720;
	winPad = '5px 20px 20px 20px';
	
	win = 'Unterlagen';
	
	Wcenter = winWidth / 2 + 20;
	cm = ' ';
	popWidth='600px';
	popHeight='390px';
	if (ie6 == true) {
		p = 'absolute';
		topmargin = 100;
	}
	else {
		p = 'fixed';
	}	
	
	var evDetail = new Element('div', {
		'html' : ''
		,'id': win
		,'styles': {
			'position': p,
			'width': popWidth,
			'top': topmargin,
			'left': '50%',
			'z-index': '999',
			'height': popHeight,
			'margin-left': '-' + Wcenter + 'px',
			'padding': winPad,
			'text-align': 'left',
			'overflow': 'hidden',
			'display': 'block',
			'opacity': 0,
			'background-repeat':'no-repeat'
		}
	});
	evDetail.inject(document.body,'top');

	var inner = new Element('div', {
		'html' : cm
		,'id':'innerF'
		,'styles': {
			'width': '650px',
			'height':'490px',
			'padding': '50px 20px 20px 10px'
			,'margin':40
			,'text-align': 'left'
		}
	});
	
	inner.inject(evDetail);
	var titlebar = new Element('div', {
		'id': 'titlebar',
		'html': Wtitle
		,'styles': {
			'position': 'absolute',
			'top': 0,
			'left': 8,
			'height': '18px',
			'padding': '55px 0 0 60px',
			'font-size': '14px',
			'font-weight': 'bold',
			'width': winWidth + 20,
			'color': '#2A2017'
		}
	});
	titlebar.inject(inner);
	
	new Element('div',{
		'html': 'Bitte füllen Sie das Formular vollständig aus<br/><br/>'
	}).inject(inner);
	
	if (camNo == 0) {
		infoFORM = FORMinformation(Wtitle);
		infoFORM.inject(inner);
		AjaxSend($('resform'), $('innerF'));
	
	}

	var closer = new Element('div', {
		'id': 'closer',
		'styles': {
			'position': 'absolute',
			'top': '25px',
			'left': '25px'
			,'z-index': 9999
		}
	}).inject($(win));

	closerA = new Element('a', {
		'href': 'javascript:closeOverlay("' + win + '")'

	}).inject(closer);
	
	closerImg = new Element('img', {
		'src': root + 'images/closebox.png',
		'border': 0
	}).inject(closerA);
	
		var fadein = new Fx.Tween($(win), {
		duration: 200
		,onComplete: function(){
			if(popHeight=='720px'){
				$(win).setStyle('background-image','url('+root+'images/boxbg.png)');
			}
			else{
				$(win).setStyle('background-image','url('+root+'images/boxbg_small.png)');
			}

		}
	});
	fadein.start('opacity', '0', '1');
	
	var fadein2 = new Fx.Tween($('BoxOverlay'), {
		duration: 150
	});
	fadein2.start('opacity', '0', '0.6');
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//set informations for form FUNCTION
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function FORMinformation(objTitel,objSubTitel){

	var fld = [{
		'feld0': {
			'str': 'Name',
			'bez': 'Name',
			'cls': 'chk',
			'ftype': 'text',
			'params': ''
		}
	},{
		'feld1': {
			'str': 'Vorname',
			'bez': 'Vorname',
			'cls': 'chk',
			'ftype': 'text',
			'params': ''
		}
	},{
		'feld2': {
			'str': 'Adresse',
			'bez': 'Adresse',
			'cls': 'chk',
			'ftype': 'text',
			'params': ''
		}
	},{
		'feld3': {
			'str': 'PLZ',
			'bez': 'PLZ',
			'cls': 'chk',
			'ftype': 'text',
			'params': ''
		}
	}, {
		'feld4': {
			'str': 'Ort',
			'bez': 'Ort',
			'cls': 'chk',
			'ftype': 'text',
			'params': ''
		}
	},{
		'feld5': {
			'str': 'E-Mail',
			'bez': 'Mail',
			'cls': 'chk',
			'ftype': 'text',
			'params': ''
		}
	},{
		'feld6': {
			'str': 'Telefon',
			'bez': 'Telefon',
			'cls': 'chk',
			'ftype': 'text',
			'params': ''
		}
	},{
		'feld7': {
			'str': 'Bemerkungen',
			'bez': 'Bemerkungen',
			'cls': 'nochk',
			'ftype': 'area',
			'params': 'value=""'
		}
	},{
		'feld8': {
			'str': '',
			'bez': 'reservieren',
			'cls': 'sbmt',
			'ftype': 'submit',
			'params': 'value="Unterlagen bestellen"'
		}
	},{
		'feld9': {
			'str': '',
			'bez': 'logfile',
			'cls': 'nochk',
			'ftype': 'hidden',
			'params' : 'value="log_Unterlagen"'
		}
	},{
		'feld10': {
			'str': '',
			'bez': 'title',
			'cls': 'nochk',
			'ftype': 'hidden',
			'params' : 'value="Unterlagenbestellung auf brunbauplanung.ch"'
		}
	},{
		'feld11': {
			'str': '',
			'bez': 'objTitle',
			'cls': 'nochk',
			'ftype': 'hidden',
			'params' : 'value="'+objTitel+' - '+objSubTitel+'"'
		}
	}]
	return createForm(fld);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//creates form FUNCTION
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function createForm(fld){
	
	frm = new Element('form', {
		'method': 'post',
		'class': 'ajaxsend',
		'id': 'resform',
		'styles': {
			'clear': 'both'
		}
	});
	
	tab = new Element('table', {
		'cellpadding': '2',
		'cellspacing': '0',
		'border': '0',
		'width': '400',
		'height': '1%'
	});
	
	tab.inject(frm);
	
	thead = new Element('thead').inject(tab);
	tbody = new Element('tbody').inject(tab);
	
	fld.each(function(f, item){
		
		tr = new Element('tr');
		tr.inject(tbody);
		td = new Element('td', {
			'html': f['feld' + item].str,
			'valign': 'top'
		});
		td.inject(tr);
		
		if(f['feld' + item].ftype != 'area') {
			td = new Element('td', {
				'align': 'left',
				'valign': 'top',
				'html': '<input style="padding:0;margin:0;width:200px;border:1px #ccc solid;font-size:11px;font-family:verdana" '+ 'type="'+ f['feld' + item].ftype + '" name="' + f['feld' + item].bez + '" class="' + f['feld' + item].cls + '" ' + f['feld' + item].params + '>'
			});
		}else{
			td = new Element('td', {
				'html': '<textarea style="width:200px;border:1px #ccc solid;font-size:11px;font-family:verdana"' + 'name="'+f['feld' + item].bez + '" class="' + f['feld' + item].cls + '" ></textarea>'
			});
		}
		td.inject(tr);
	});
	return frm;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//send FUNCTION
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function AjaxSend(form, target){

	$$('.sbmt')[0].addEvent('click', function(){
		return chk(form);
	});
	
	form.addEvent('submit', function(e){
		
		e.stop();
		path = 'http://www.brunbauplanung.ch.ch/'
		this.set('send', {
			method: 'post',
			url: root+'includes/sendmail.php',
			
			onRequest: function(){
				target.empty();
				target.innerHTML = '<div style="position:absolute;top:60px;">LOADING: Bestellung wird verarbeitet...</div>';
			},
			onComplete: function(response){
				target.empty();
				target.innerHTML = '<div style="position:absolute;top:60px;">Formular erfolgreich verschickt. Besten Dank für Ihr Interesse.<br><a href="#" onclick="closeOverlay(\'Unterlagen\')">Fenster schliessen</a></div>';
			}
		});
		this.send();
	});
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//check form inputs i.e. name FUNCTION
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function chk(frm){

	$$('input').each(function(inp){
		inp.addEvent('keydown', function(){
			inp.setStyle('background-color', '#ffffff');
		})
	});
	
	msg = new Array();
	err = false;
	allinp = frm.getElementsByTagName("input").length;
	inp = frm.getElementsByTagName("input");
	x = 0;
	for (i = 0; i < allinp; i++){
		
		if (inp[i].value == "" && inp[i].className == "chk") {
			err = true;
			inp[i].setStyle('background-color', '#FFEFEF');
			msg[x] = inp[i].name;
			x++;
		}
		
		try {
			if (inp[i].type == 'checkbox' && inp[i].checked == false && inp[i].className == "chk") {
				err = true;
				msg[x] = inp[i].name;
				x++;
			}
		}catch (err){}
	}
	if (err == true){
		ausgabe = msg.join(", ");
		alert("Bitte ergänzen Sie die Felder: " + ausgabe);
		return false;
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//close popup form FUNCTION
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function closeOverlay(win){
	
	var fadeout = new Fx.Tween(win, {
		duration: 25,
		onComplete: function(){
			$(win).destroy();
		}
	});
	
	fadeout.start('opacity', '1', '0');
	
	var fadeout2 = new Fx.Tween('BoxOverlay', {
		duration: 250,
		onComplete: function(){
			$('BoxOverlay').setStyle('opacity', 0);
		}
	});
	
	fadeout2.start('opacity', '0.7', '0');
}
