//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//INIT DirectoryContent
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (Browser.Engine.name == "trident" && Browser.Engine.version < 5) {
	var ie6 = true;
}
var AreaBig=false;
var PriceBig=false;
var operator ='<';
var txtNoEntry='';
window.addEvent('domready',function(){
	if (Browser.Engine.name == "trident" && Browser.Engine.version < 5) {
		DD_belatedPNG.fix('.bg');
	}
	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);
	emptyDetail();
	var filterLoc = '';
	var filterObj = '';
	var filterArea = '';
	var filterPrice = '';
	new Element('div',{
		'id':'dirFilter'
	}).inject($('directory'));
	new Element('select',{
		'id':'location',
		events:{
			'change': function(){
				filterLoc= this.options[this.selectedIndex].value;
				new news();
				if(filterLoc!='*'){
					reqObj.condition['ld.ort'] = filterLoc;
				}
				i=1;
				while(i<=$('dirList').children.length){
					var a = i-1;
					
					if ($('entry'+parseInt(a)) != null){
						$('entry'+parseInt(a)).destroy();
					}
					i++;
					
				}
				if($('entryBig')){
					$('entryBig').destroy();
					$('detail_img').destroy();
					$('dirPDF').destroy();
					$('dirInterest').destroy();
					$('headCont').destroy();
					$('ulPic').destroy();
				}
				$('dirList').getChildren().destroy();
			}
		}
	}).inject($('dirFilter'));
	new Element('select',{
		'id':'object',
		events:{
			'change': function(){
				new news();
				filterObj= this.options[this.selectedIndex].value;
				if(filterObj!='*'){
					reqObj.condition['lr.rubrikname'] = filterObj;
				}
				i=1;
				while(i<=$('dirList').children.length){
					var a = i-1;
					if ($('entry'+parseInt(a)) != null){
						$('entry'+parseInt(a)).destroy();
					}
					i++;
				}
				if($('entryBig')){
					$('entryBig').destroy();
					$('detail_img').destroy();
					$('dirPDF').destroy();
					$('dirInterest').destroy();
					$('headCont').destroy();
					$('ulPic').destroy();
				}
				$('dirList').getChildren().destroy();
			}
		}
	}).inject($('dirFilter'));
	new Element('select',{
		'id':'area',
		events:{
			'change': function(){
				new news();
				filterArea= this.options[this.selectedIndex].value;
				if(filterArea!='*'){
					reqObj.condition['ld.flaeche'] = filterArea;
				}
				i=1;
				while(i<=$('dirList').children.length){
					var a = i-1;
					if ($('entry'+parseInt(a)) != null){
						$('entry'+parseInt(a)).destroy();
					}
					i++;
				}
				if($('entryBig')){
					$('entryBig').destroy();
					$('detail_img').destroy();
					$('dirPDF').destroy();
					$('dirInterest').destroy();
					$('headCont').destroy();
					$('ulPic').destroy();
				}
				$('dirList').getChildren().destroy();
			}
		}
	}).inject($('dirFilter'));
	new Element('select',{
		'id':'price',
		events:{
			'change': function(){
				new news();
				filterPrice=this.options[this.selectedIndex].value;
				if(filterPrice!='*'){
					reqObj.condition['ld.preis'] = filterPrice;
				}
				i=1;
				while(i<=$('dirList').children.length){
					var a = i-1;
					if ($('entry'+parseInt(a)) != null){
						$('entry'+parseInt(a)).destroy();
					}
					i++;
				}
				if($('entryBig')){
					$('entryBig').destroy();
					$('detail_img').destroy();
					$('dirPDF').destroy();
					$('dirInterest').destroy();
					$('headCont').destroy();
					$('ulPic').destroy();
				}
				$('dirList').getChildren().destroy();
			}
		}}).inject($('dirFilter'));
		var strLocation;
		var strObject;
		var strArea;
		var strPrice;
		if(lang=='de'){
			strLocation ='Ort';
			strObject ='Objekt';
			strArea='Fläche';
			strPrice='Preis';
		}
		else if(lang=='en'){
			strLocation ='Location';
			strObject ='Object';
			strArea='Square footage';
			strPrice='Price';
		}
	new Element('option',{'value':'*','html':strLocation}).inject($('location'));
	new Element('option',{'value':'*','html':strObject}).inject($('object'));
	new Element('option',{'value':'*','html':strArea}).inject($('area'));
	new Element('option',{'value':'*','html':strPrice}).inject($('price'));
	new core();
});
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// checks if the detail div is empty or not and shows text if it is empty
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function emptyDetail(){
	new Element('div', {
		'id': 'noElem',
		'html': txt,
		'styles': {
			'color': '#ffffff',
			'padding':'20px'
		}
	}).inject($('dirDetail'));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//CORE / implements _verzReq
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

var core = new Class({
	initialize: function(){
		if($defined(tags) && (tags.verz_Angebote == 1))new news();
	}

})
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//show directory on site CLASS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
var news = new Class({
	
	Implements: [Options, Events]
	
	,options: {
		root: root
		,_verzLocal:0
		,_verzUser: 'immosurselva'
		,_verzDebug:1
		,_verzTables: ['']
	}
	
	,initialize: function(){
		var filterLoc = $('location').value;
		var filterObj =$('object').value;
		var filterArea= $('area').value;
		var filterPrice =$('price').value;
		
		var multiReqObj = [];
		this.options._verzTables.each(function(items, key){
			
			this.partStr = items;
			
			reqObj = {
				'type': 'all'
				,'user': this.options._verzUser
				,'table': {
					listingdatas: 'ld'
					,listingrows: 'lr'
					,listings: 'l'
				}
				,'condition': {
					
				}
				,'fields': 'lr.*,ld.*'
				,'order': 'ld.top DESC'
				,'language': LANG
			};
			
			
			multiReqObj.push(this.setUserPart(reqObj));
		}, this);
		if (filterLoc!='*'){
			reqObj.condition['ld.ort'] = filterLoc;
		}
		if (filterObj!='*'){
			reqObj.condition['lr.rubrikname'] = filterObj;
		}
		if (filterArea!='*'){
			if (AreaBig == true) {
				reqObj.condition['ld.flaeche >'] = parseInt(filterArea);
			}
			else {
				reqObj.condition['ld.flaeche <'] = parseInt(filterArea);
			}
//			var intArea = parseInt(filterArea)-100;
			
//			reqObj.condition['ld.flaeche >'] = intArea;
		}
		if (filterPrice!='*'){
			if (PriceBig == true) {
				reqObj.condition['ld.preis >'] = parseInt(filterPrice);
			}
			else {
				reqObj.condition['ld.preis <'] = parseInt(filterPrice);
			}
		}
		this._verzReqStr = multiReqObj;
		this._verzReq('showNews');
	}
	// Überschreiben des Tablepart
	,setUserPart: function(obj){
		
		if(this.partStr && this.partStr != 'agentur'){
			
			obj['table'] = {};
			obj['table']['listings' + this.partStr] = 'l';
			obj['table']['listingrows' + this.partStr] = 'lr';
			obj['table']['listingdatas' + this.partStr] = 'ld';
		}
		
		return obj;
	}
	,showNews: function(res){
		///////////////////////////////////////////////////////////////////
		var LocFilterArr = new Array();
		var filterTextLoc = new Array();
		// delete multiple entries (array)
		function dme(a1){
			var a2 = new Array();
			var a3 = new Array();
			for(var i = 0; i < a1.length; i++){
				if(typeof(a2[a1[i]]) == "undefined"){
					a2[a1[i]] = true;
					a3[a3.length] = a1[i];
				}
			}
			var a4 = new Array();
			for(var i = 0; i < a3.length; i++){a4[a4.length] = a3[i]}
			return a4;
		}
		var b = 0;

		function textLocation(){
			res.result.each(function(filter,id){
				LocFilterArr[id] = filter.ld.ort;
				filterTextLoc=dme(LocFilterArr);
			})
			return filterTextLoc;
		};
		var arrayText = textLocation();
		var item = $('location').children;
		if (item.length ==1){
			arrayText.each(function(text, id){
				new Element('option',{'value':text,'html':text,'id':'opt'+id}).inject($('location'))
			})
		}
		var ObjFilterArr = [];
		var filterTextObj =[];
		var item = $('object').children;
		
		function textObj(){
			res.result.each(function(item, key){
				text = res.result[key].lr.rubrikname
				
				ObjFilterArr[key] = text;
				filterTextObj = dme(ObjFilterArr);
			})
			return filterTextObj.sort();
		}
		var arrayTextObj = textObj();
		var Objs = arrayTextObj.sort();
		var item = $('object').children;
		if (item.length == 1) {
			Objs.each(function(text, id){
				var l = text.length;
				new Element('option', {
					'value':text,
					'html':text,
					'id': 'opt' + id
				}).inject($('object'))
			})
		}
		
		
		var AreFilterArr = [];
		var filterTextAre =[];
		function textArea(){
			res.result.each(function(item, id){
				text = res.result[id].ld.flaeche
				var txtSmaler='';
				intSl = parseInt(text);
				if (intSl>1 && intSl<=100){
					txtSmaler=100;
				}
				else if(intSl>100 && intSl<=200){
					txtSmaler=200;
				}
				else if(intSl>200 && intSl<=300){
					txtSmaler='300';
				}
				else if(intSl>300 && intSl<=400){
					txtSmaler=400;
				}
				else if(intSl>400 && intSl<=500){
					txtSmaler=500;
				}
				else if(intSl>500 && intSl<=600){
					txtSmaler=600;
				}
				else if(intSl>600 && intSl<=700){
					txtSmaler=700;
				}
				else if(intSl>700 && intSl<=800){
					txtSmaler='800';
				}
				else if(intSl>800 && intSl<=900){
					txtSmaler='900';
				}
				else if(intSl>900){
					txtSmaler='901';
					AreaBig=true;
				}
				AreFilterArr[id] = txtSmaler;
				filterTextAre = dme(AreFilterArr);
			})
			return filterTextAre.sort();
		}
		var arrayTextAre = textArea();
		var Areas = arrayTextAre.sort();
		var item = $('area').children;
		if (item.length == 1) {
			Areas.each(function(text, id){
				if (AreaBig==true){
					operator='>';
				}
				var l = text.length;
				new Element('option', {
					'value':text,
					'html':operator+ text+ 'm&#178;',
					'id': 'opt' + id
				}).inject($('area'))
			})
		}
		var PriFilterArr = [];
		var filterTextPri =[];
		function textPrice(){
			res.result.each(function(item, id){
				text = res.result[id].ld.preis
				var txtSmaler='';
				intSl = parseInt(text);
				if (intSl>0 && intSl<=100){
					txtSmaler=100;
				}
				else if(intSl>100 && intSl<=200){
					txtSmaler=200;
				}
				else if(intSl>200 && intSl<=300){
					txtSmaler=300;
				}
				else if(intSl>300 && intSl<=400){
					txtSmaler=400;
				}
				else if(intSl>400 && intSl<=500){
					txtSmaler=500;
				}
				else if(intSl>500 && intSl<=600){
					txtSmaler=600;
				}
				else if(intSl>600 && intSl<=700){
					txtSmaler=700;
				}
				else if(intSl>700 && intSl<=800){
					txtSmaler=800;
				}
				else if(intSl>800 && intSl<=900){
					txtSmaler=900;
				}
				else if(intSl>900){
					PriceBig=true;
					txtSmaler=901;
				}
				PriFilterArr[id] = txtSmaler;
				filterTextPri = dme(PriFilterArr);
			})
			return filterTextPri.sort();
		}
		var arrayTextPri = textPrice();
		var item = $('price').children;
		if (item.length == 1) {
			arrayTextPri.each(function(text, id){
				var l = text.length;
				if (PriceBig==true){
					operator='>';
				}
				var valTxt;
				if(text.length== 0){
					valTxt='Preis auf Anfrage';
				}
				else{
					valTxt = operator+text+'Chf';
				}
				new Element('option', {
					'value':text,
					'html': valTxt,
					'id': 'opt' + id
				}).inject($('price'))
			})
		}
		///////////////////////////////////////////////////////////////////
		$('directory').setStyle('visibility','visible');
		$('content').setStyle('visibility','hidden');
		
		var chkStr;
		var urlroot;
		chkStr = window.location.href.search(/192.168/);
		if(chkStr != -1) urlroot = '';
		else urlroot = root;
		var targetDiv;
		if(lang=='de'){
			txtNoEntry = 'F&uuml;r Ihre Suchkriterien wurden leider keine Resultate gefunden.';
		}
		else{
			txtNoEntry = 'There were no entries found wich are comparable with your filter requirements';
		}
		if(res.result.length == 0){
			new Element('div', {
				'id':'noEntry',
				'html':txtNoEntry,
				'style':{
					'color':'#000000'
				}
			}).inject($('dirList'));
		}
		res.result.each(function(entry,key){
			targetDiv = 'dirList';
			var namePic1=root+'images/img_01.jpg';
			
			if($defined(entry.ld.bilder.media)){
				if($defined(entry.ld.bilder.media[0]))namePic1 = root+'upload/500x328_verz_'+entry.ld.bilder.media[0].name;
				entry.ld.bilder.media.each(function(pic, picCounter){
					if (picCounter == 0) {
						new Element('img', {
							'src': root + 'upload/500x328_verz_' + pic.name,
							'id': 'img' + picCounter,
							'class':'list_img'
							,events:{
								'click':function(){
									enlargeEntry(res,$('entry'+key),key,entry);
								}
							}
						}).inject($(targetDiv))
					}
				});
			}
			var area='';
			var chambres='';
			var price='';
			var ort;
			var X_str='';
			
			if(entry.ld.flaeche != ''){
				X_str= LANG == 'de' ? 'Fläche' : 'Square footage';
				area = '<br>'+X_str+': '+entry.ld.flaeche+'m&#178;';
			}
			if(entry.ld.zimmer!=''){
				X_str= LANG == 'de' ? 'Zimmer' : 'Rooms';
				chambres='<br>'+X_str+': '+entry.ld.zimmer;
			}
			if(entry.ld.preis != ''){
				X_str= LANG == 'de' ? 'Preis' : 'Price';
				price='<br>'+X_str+': '+entry.ld.preis;
			}
			if (entry.ld.plz != '' && entry.ld.ort!=''){
				ort=entry.ld.plz+' '+entry.ld.ort;
			}
			
			var mehr = LANG == 'de' ? 'mehr Informationen' : 'more information';
			
			new Element('div',{
				'html': '<font color="#cf4b25">'+entry.lr.rubrikname+'</font><br><font color="#91827d"><b>'+entry.ld.titel+'</b></font><br>'+ort+area+chambres+price+'<br/><br/><u>'+mehr+'</u>'
				,'id':'entry'+key
				,'class':'entry_list'
				,events:{
					'click':function(){
						enlargeEntry(res,this,key,entry);
					}
				}
			}).inject($(targetDiv))
		});
		
	}
	
});
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//enlarges Directory entry
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function enlargeEntry(res,item,key,entry){
	if ($('noElem') != null) {
		$('noElem').destroy();
	}
	res.result.each(function(item,y){
		$('entry'+y).setStyle('background-color','#ffffff');
	});
	item.setStyle('background-color','#ded9d8');
	var i=0;
	var targetText = $('entry'+key);
	var sourceList = $$('entry_list');
	var dirElements= $('dirDetail');

	if($('entryBig')){
		$('entryBig').destroy();
		$('detail_img').destroy();
		$('dirPDF').destroy();
		$('dirInterest').destroy();
		$('headCont').destroy();
		$('ulPic').destroy();
	}
	
	
	
	var contentToDisplay = $('dirDetail');

	var lenghtPics = 0;
	var ids = [];
	if($defined(entry.ld.bilder.media)){
		picarray=[];
		if($defined(entry.ld.bilder.media[0]))namePic1 = root+'upload/500x328_verz_'+entry.ld.bilder.media[0].name;
		entry.ld.bilder.media.each(function(pic, picCounter){
			picarray[picCounter]= pic;
			
			if (picCounter == 0) {
				new Element('img', {
					'src': root + 'upload/500x328_verz_' + pic.name,
					'id': 'detail_img',
					'class':'detail_img'
					,'styles':{
						'margin-top':20
						,'top':0
					}
				}).inject($('dirDetail'))
			}
		});
		var a =0;
		
		new Element('ul', {
					'html': '',
					'id': 'ulPic',
					'styles': {
						'margin': '10px 0 0 25px',
						'padding': 0
					}
				}).inject($('dirDetail'))
		
		entry.ld.bilder.media.each(function(pic, picCounter){
			a++;
			ids.push(picCounter);
			
			if (entry.ld.bilder.media.length != 1) {
				if (picCounter == 0) {
					new Element('li', {
						'html': '&lt;',
						'styles': {
							'cursor': 'pointer'
						},
						events: {
							'click': function(){
								if (i != 0 && i != 77) {
									ids.each(function(item, id){
										$('li_PicNav' + item).setStyle('color', '#ffffff');
									})
									i--;
									$('li_PicNav' + i).setStyle('color', '#000000');
									$('detail_img').setAttribute('src', root + 'upload/500x328_verz_' + picarray[i].name);
								}
								else {
									ids.each(function(item, id){
										$('li_PicNav' + item).setStyle('color', '#ffffff');
									})
									i = a - 1;
									$('li_PicNav' + i).setStyle('color', '#000000');
									$('detail_img').setAttribute('src', root + 'upload/500x328_verz_' + picarray[i].name);
								}
							}
						}
					}).inject($('ulPic'))
				}
				
				if (picCounter == 1) {
					new Element('li', {
						'html': '&gt;',
						'styles': {
							'cursor': 'pointer'
						},
						events: {
							'click': function(){
								var pnLenght = 0;
								if (picarray.length == 3) {
									pnLenght = picarray.length - 2;
								}
								else {
									pnLenght = picarray.length - 1;
								}
								if (i >= pnLenght) {
									ids.each(function(item, id){
										$('li_PicNav' + item).setStyle('color', '#ffffff');
									})
									i = 0;
									$('li_PicNav' + i).setStyle('color', '#000000');
									$('detail_img').setAttribute('src', root + 'upload/500x328_verz_' + picarray[i].name);
								}
								else {
									ids.each(function(item, id){
										$('li_PicNav' + item).setStyle('color', '#ffffff');
									})
									i++;
									
									$('li_PicNav' + i).setStyle('color', '#000000');
									$('detail_img').setAttribute('src', root + 'upload/500x328_verz_' + picarray[i].name);
								}
							}
						}
					}).inject($('ulPic'))
				}
			}
			
		})
		entry.ld.bilder.media.each(function(pic, picCounter){
			
			var namePicNav = picCounter+1;
			ids.push(picCounter);
			new Element('li',{
				'html':namePicNav
				,'styles': {
					'cursor':'pointer'
				}
				,'id':'li_PicNav'+picCounter
				,'class':'li_PicNav'
				,events: {
				'click': function(){
					i = picCounter;
					ids.each(function(item,id){
						$('li_PicNav'+item).setStyle('color','#ffffff');
					})
					$('li_PicNav'+picCounter).setStyle('color','#000000');
					
					$('detail_img').setAttribute('src', root + 'upload/500x328_verz_' +picarray[picCounter].name);
				}
			}}).inject($('ulPic'))
			$('li_PicNav' + 0).setStyle('color', '#000000');
		})
	}
	
	
	headCont = new Element('div',{
		'styles':{
			'height':'23px'
			,'clear': 'both'
			,'margin-left':25
			,'padding-top':15
			
		},
		'id': 'headCont'
	}).inject($('dirDetail'))
	
	
	var unterlagen = LANG == 'de' ? 'Unterlagen bestellen' : 'order documentation';
	
	new Element('div',{
		'html': '<u>'+unterlagen+'</u>'
		,'styles':{
			'cursor':'pointer'
			,'height':'23px'
			,'float': 'left'
			
		}
		,'class':'dirInterest'
		,'id':'dirInterest'
		,events: {
			'click': function(){
				getDocs(entry.ld.titel,entry.ld.plz+' '+entry.ld.ort);
				return false;
			}
		}
	}).inject(headCont)
	new Element('div',{
		'html': '<u>PDF-Download</u>'
		,'styles':{
			'cursor':'pointer'
			,'height':'23px'
			,'float': 'left'
			,'margin-left':25
				
		}
		,'class':'linkBack'
		,'id':'dirPDF'
		,events: {
			'click': function(){
				
				window.location.href= root+'pdfgen/immosurselva.php?id='+entry.ld.id+'&pdf=1&lang='+LANG;

				return false;
			}
		}
		
	}).inject(headCont)

	
	
	
	var area='';
	var chambres='';
	var price='';
	var ort='';
	var specification ='';
	if(entry.ld.flaeche != ''){
		
		var fl = LANG == 'de' ? 'Fläche' : 'Square footage';
		
		area = '<br><font color="#333333">'+fl+':</font> <font color="#ffffff">'+entry.ld.flaeche+'m&#178;'+'</font>';
	}
	if(entry.ld.zimmer!=''){
		
		var rooms = LANG == 'de' ? 'Zimmer' : 'Rooms';
		
		chambres='<br><font color="#333333">'+rooms+':</font> <font color="#ffffff">'+entry.ld.zimmer+'</font>';
	}
	
	var price = LANG == 'de' ? 'Preis' : 'Price';
	if(entry.ld.preis != ''){
		price='<br><font color="#333333">'+price+':</font> <font color="#ffffff">'+entry.ld.preis+'</font>';
	}
	
	var adr = LANG == 'de' ? 'Adresse' : 'Adress';
	
	if (entry.ld.plz != '' && entry.ld.ort!=''){
		ort='<br /><font color="#333333">'+adr+':</font><font color="#ffffff"> '+entry.ld.plz+' '+entry.ld.ort+'</font>';
	}
	
	var besch = LANG == 'de' ? 'Beschrieb: ' : '';
	
	if (entry.ld.text.text != ''){
		specification='<br><br><font color="#333333">'+besch+'</font><font color="#ffffff">'+entry.ld.text.text+'</font><br><br>';
	}
	new Element('div',{
		'html': '<br /><b><font color="#333333">'+entry.ld.titel+'</font></b><br />'+ort+area+price+chambres+specification
		,'id':'entryBig'
		,'styles':{
			'position':'relative',
			'top':'5px',
			'left':'25px',
			'width':'393px'
		}
	}).inject($('dirDetail'))
	var topLinks = ($('dirDetail').getScrollHeight());
	var topHeight = topLinks;
	if (topLinks <= ($('dirDetail').getHeight())){
		topHeight=305;
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//prepares interest form FUNCTION
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getDocs(objTitel,objSubTitel){
	var title=objTitel +'<br/>'+objSubTitel;
	popupWindow(objTitel,objSubTitel);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//popup FUNCTION
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function popupWindow(Wtitle, subTitle){
	if (ie6){
		$('dirFilter').setStyle('visibility','hidden');
	}
	
	$('BoxOverlay').setStyles({
		width: window.getScrollWidth() + 'px',
		height: window.getScrollHeight() + 'px'
	});
	var popHeight;
	var popWidth;
	winWidth = 760;
	topmargin = window.getScrollHeight() / 2 - 320;
	
	winHeight = 720;
	winPad = '10px 20px 20px 20px';
	
	win = 'Unterlagen';
	
	Wcenter = winWidth / 2 + 20;
	cm = ' ';
	popWidth='600px';
	popHeight='390px';
	if (ie6 == true) {
		p = 'absolute';
		topmargin = 100;
	}
	else {
		p = 'fixed';
	}

	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');

	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);
	titlebar = new Element('div', {
		'id': 'titlebar',
		'html': Wtitle +' '+subTitle
		,'styles': {
			'position': 'absolute',
			'top': 0,
			'left': 8,
			'height': '18px',
			'padding': '55px 0 0 60px',
			'font-size': '16px',
			'font-weight': 'bold',
			'width': winWidth + 20,
			'color': '#2A2017'
		}
	});
	titlebar.inject(inner);
	
		infoFORM = FORMinformation(Wtitle,subTitle);
		infoFORM.inject(inner);
		AjaxSend($('resform'), $('innerF'));
	

	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 + '")',
		events: {
			'click': function(){
				if (ie6) {
					$('dirFilter').setStyle('visibility', 'visible');
				}
			}
		}
	}).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){

if (LANG == 'de') {

	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': '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': '',
			'style': 'color="red"'
		}
	}, {
		'feld8': {
			'str': '',
			'bez': 'reservieren',
			'cls': 'sbmt',
			'ftype': 'submit',
			'params': 'value="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 coraycapaul.ch"'
		}
	}, {
		'feld11': {
			'str': '',
			'bez': 'objTitle',
			'cls': 'nochk',
			'ftype': 'hidden',
			'params': 'value="' + objTitel + ' - ' + objSubTitel + '"'
		}
	}]
	
	
}else{
	var fld = [{
		'feld0': {
			'str': 'Name',
			'bez': 'Name',
			'cls': 'chk',
			'ftype': 'text',
			'params': ''
		}
	}, {
		'feld1': {
			'str': 'First name',
			'bez': 'Vorname',
			'cls': 'chk',
			'ftype': 'text',
			'params': ''
		}
	}, {
		'feld2': {
			'str': 'Adress',
			'bez': 'Adresse',
			'cls': 'chk',
			'ftype': 'text',
			'params': ''
		}
	}, {
		'feld3': {
			'str': 'ZIP',
			'bez': 'PLZ',
			'cls': 'chk',
			'ftype': 'text',
			'params': ''
		}
	}, {
		'feld4': {
			'str': 'City',
			'bez': 'Ort',
			'cls': 'chk',
			'ftype': 'text',
			'params': ''
		}
	}, {
		'feld5': {
			'str': 'Mail',
			'bez': 'Mail',
			'cls': 'chk',
			'ftype': 'text',
			'params': ''
		}
	}, {
		'feld6': {
			'str': 'Phone',
			'bez': 'Telefon',
			'cls': 'chk',
			'ftype': 'text',
			'params': ''
		}
	}, {
		'feld7': {
			'str': 'Comments',
			'bez': 'Bemerkungen',
			'cls': 'nochk',
			'ftype': 'area',
			'params': '',
			'style': 'color="red"'
		}
	}, {
		'feld8': {
			'str': '',
			'bez': 'reservieren',
			'cls': 'sbmt',
			'ftype': 'submit',
			'params': 'value="order"'
		}
	}, {
		'feld9': {
			'str': '',
			'bez': 'logfile',
			'cls': 'nochk',
			'ftype': 'hidden',
			'params': 'value="log_Unterlagen"'
		}
	}, {
		'feld10': {
			'str': '',
			'bez': 'title',
			'cls': 'nochk',
			'ftype': 'hidden',
			'params': 'value="Unterlagenbestellung auf coraycapaul.ch / english"'
		}
	}, {
		'feld11': {
			'str': '',
			'bez': 'objTitle',
			'cls': 'nochk',
			'ftype': 'hidden',
			'params': 'value="' + objTitel + ' - ' + objSubTitel + '"'
		}
	}]
}

	return createForm(fld);
	$('resform').setStyle('color','#000000')
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//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 + '" />'
			});
		}
		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.coraycapaul.ch/'
		this.set('send', {
			method: 'post',
			url: root+'includes/sendmail.php',
			
			onRequest: function(){
				target.empty();
				target.innerHTML = '<div style="position:absolute;top:60px;color:#000">LOADING: Bestellung wird verarbeitet...</div>';
			},
			onComplete: function(response){
				target.empty();
				target.innerHTML = '<div style="position:absolute;top:60px;color:#000">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 ergaenzen 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');
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//REQUEST CLASS
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/*
/*
 * Request.implement
 * 
 * Requestfunktionen
 * Connectbereich für den Verzeichnisaufruf
 * 
 * @version		1.0
 * 
 * @author		GO4WEB Internet Agentur
 * @copyright		2010 Author
 *
 */
var VerzCore = {
	
	
	/*
	 * Options
	 * 
	 * _verzUser = ''		name des User
	 */
	_verzOptions: function(options){
		this.setOptions(options);
	}
	
	,_verzReqData: function(){
		
		this._verzReqStr = {
			type: 'all'
			,user: this.options._verzUser
			,table: {
				listingdatas: 'ld'
				,listingrows: 'lr'
				,listings: 'l'
			}
			,condition: {
//				OR abfrage
//				,0: {
//					'm.sommer': '1',
//					'm.winter':'1'
//				}
			}
			,fields: 'lr.*,ld.*'
			,order: 'ld.id DESC'
			,language: LANG
		}
	}
	
	,_verReqChange: function(reqObj, changObj){
		
		var buildObj, addStr, newTbl={};
		var tblList = {listingdatas: 'ld', listingrows: 'lr', listings: 'l'};
		
		if(reqObj) buildObj = reqObj;
		else buildObj = this._verzReqStr;
		if($defined(changObj['table']) && $type(changObj['table']) == 'string'){
			if(changObj['table'] == '') addStr = '';
			else addStr = '_' + changObj['table'];
			$H(tblList).each(function(items, key){
				newTbl[key + addStr] = items;
			});
			changObj['table'] = newTbl;
		}
		$H(changObj).each(function(items, key){
			reqObj[key] = items;
		});
		
		return reqObj;
	}
	
	,_verzReq: function(onCompletFunc){
		
		if(this.options._verzDebug == 1) debugStr = '&debug=1';
		else debugStr = '';
		
		if(!this._verzReqStr) this._verzReqData();
		
		// tempsStr
		if($defined(this._verzTempReqStr) && this._verzTempReqStr){
			reqStr = this._verzTempReqStr;
			this._verzTempReqStr = false;
		}else{
			reqStr = this._verzReqStr;
		}
		
		// Falls Arrayreq nur mit einem Element
		if(reqStr.length == 1) reqStr = reqStr[0];
		
		
		new Request({
			url: 'index.php'
			,method: 'post'
			,data: 'mode=verzeichnis&local=' + this.options._verzLocal + debugStr +'&request=' + encodeURIComponent(JSON.encode(reqStr))
			,noCache: true
			,onComplete: function(response){
				var req = JSON.decode(response);
				fDelay = 0;
				
				this[onCompletFunc].delay(fDelay, this, [req]);
				
			}.bind(this)
		}).send();
	}
	
	/*
	 * _verzFormMulti	Merg des MultiformRequest mit tableName adding
	 * 
	 * sortPath		SortPath Falls das Object nach dem Merg sortiert werden soll (siehe _verzFormSort)
	 * order		Order des Sorting
	 *
	 */
	,_verzFormMulti: function(req, sortPath, order){
		
		var newReqArr = [];
		var reqOut = [];
		var count = 0;
		
		if(!$defined(req.result)) req.result = [req.result];
		req.result.each(function(items, key){
			var tblName = req.tblName[key];
			items.each(function(subitems, subkey){
				if($defined(subitems.lr)) subitems.lr['tableName'] = tblName;
				if($defined(subitems.ld)) subitems.ld['tableName'] = tblName;
				newReqArr.push($H(subitems));
			});
			count++;
		}, this);
				
		if(sortPath) newReqArr = this._verzFormSort(newReqArr, sortPath, order);
		
		reqOut['count'] = newReqArr.length;
		reqOut['result'] = newReqArr;
		
		return reqOut;
	}
	
	/*
	 * _verzFormSort	Umsortierung eines Hash (Achtung Object muss zu Hash formatiert werden)
	 * 
	 * array		Zu sortierenden Hash
	 * path			Sortierpfad (ld.datum)
	 * order		desc / asc
	 * 
	 */
	,_verzFormSort: function(array, path, order){
		
		for (var i = 0; i < array.length; i++) {
			
			var currVal = array[i].getFromPath(path);
			var currElem = array[i];
			
			var j = i - 1;
			while ((j >= 0) && (array[j].getFromPath(path) > currVal)) {
				array[j + 1] = array[j];
				j--;
			}
			array[j + 1] = currElem;
		}
		
		if(order == 'desc') array.reverse();
		
		return array;
	}
}
news.implement(VerzCore);
