var __modjs = {
	
	/* ===================== */
	/* Contact */
	/* ===================== */
	
	contact_send : function () {
	
		var validation = new _Validation();
		
		if (validation.check_fields('contact_form')) {
			
			$('contact_form').request({
				onComplete: function(){
					
					Effect.Appear('message_delivered', { duration : 0.3 } );
					
					$A($('contact_form').getElements('input')).each(function(elm){
					
						if (elm.type == 'button') return;
						elm.clear();
					});
				}
			});
			
		} else {
			
			alert('Please fill in the required fields');
		}
		
	},
	
	tmp_news_listing : function (block_id) {
		var container = $('ident_'+block_id).getElementsByClassName('content')[0].down();
		
		new Ajax.Updater(container, '/congresses.module/news/data='+block_id, { evalScripts : true, postBody : data });
	},
	
	/* ===================== */
	/* News */
	/* ===================== */
	
	news_read : function (entry_id, block_id) {
		var container = $('ident_'+block_id).getElementsByClassName('content')[0].down();
		
		new Ajax.Updater(container, '/congresses.module/news/read='+entry_id+'/block_id='+block_id, { evalScripts : true });
	},
	
	news_listing : function (block_id) {
		var container = $('ident_'+block_id).getElementsByClassName('content')[0].down();
		
		new Ajax.Updater(container, '/congresses.module/news/data='+block_id, { evalScripts : true });
	},
	
	/* ===================== */
	/* Registration */
	/* ===================== */
	
	postform : function (data) {
	
		if (formValidation.check_fields('quickie_form')) {
		
			this.switchSection('next');
			
			var target = this.idName + this.currentSection;
			
			new Ajax.Updater(target, '/congresses.module/registration/section=hotels', { evalScripts : true, postBody : data });
			
			if ($('abfile')) {
				formupload.go();
			}
			
		} else {
		
			return false;
		
		}
	
	},
	
	tours : function (data) {
		
		this.switchSection('next');
		
		var target = this.idName + this.currentSection;
		
		new Ajax.Updater(target, '/congresses.module/registration/section=tours', { evalScripts : true, postBody : data });
		
	},
	
	summary : function (data) {
	
		if (formValidation.check_fields('quickie_form')) {
		
			this.switchSection('next');
			
			var target = this.idName + this.currentSection;
			
			new Ajax.Updater(target, '/congresses.module/registration/section=summary', { evalScripts : true, postBody : data });
			
			if ($('abfile')) {
				formupload.go();
			}
			
		} else {
		
			return false;
		
		}
				
	},
	
	summaryNoPayment : function (data) {
		
		if (formValidation.check_fields('quickie_form')) {
		
			this.switchSection('next');
			
			var target = this.idName + this.currentSection;
			
			new Ajax.Updater(target, '/congresses.module/registration/section=summary/nopayment=true', { evalScripts : true, postBody : data });
			
			if ($('abfile')) {
				formupload.go();
			}
			
		} else {
		
			return false;
		
		}
				
	},
	
	hoteldata : function (from, till, id) {
		
		if (!from) return;
		if (!till) return;
		if (!id) return;
		
		new Ajax.Updater('hotel_list'+id, '/congresses.module/registration/section=hotels/availability=true/id='+id, { evalScripts : true, postBody : 'from='+from+'&till='+till });
	},
	
	hotelroom : function (elm, classname, id) {
		
		$A($('hotel_list'+id).getElementsByClassName(classname)).each(function(element){
			if (elm.value == 'none') {
				element.disabled = '';
			} else {
				if (element.id != elm.id) {
					element.disabled = 'disabled';
				}
			}
		});
		
	},
	
	formAccompanyingPerson : function (state) {
		if (state == 0) {
			$('acc_per_naw').hide();
		} else {
			$('acc_per_naw').show();
		}
	},
	
	ownlodging : function (value, id) {
		if (value.empty()) {
			$('accomodationlist'+id).show();
		} else {
			$('accomodationlist'+id).hide();
		}
	},
	
	book_seperatly : function (elm) {
		if (elm.checked) {
			$('accompanyingperson_div').show();
								modjs.hoteldata($F('arrival_accompanyingperson'), $F('departure_accompanyingperson'), 2);
								modjs.ownlodging($F('ownlodging'), 2);
		} else {
			$('accompanyingperson_div').hide();
		}
	},
	
	validate : function(what) {
		
		switch (what) {
			
			case 'hotels':
				
	
				
			break;
		}
		
		return true;
		
	},
	
	/* ===================== */
	/* Sections */
	/* ===================== */
	
	idName : false,
	currentSection : false,
	
	createSections : function (classname, idname, default_section) {
				
		var sections = $('portal').getElementsByClassName(classname);
		
		$A(sections).each(function(section, id){
			
			section.hide();
			
			if (id == default_section) {
				section.show();
				
				this.currentSection = id;
				
				this.progressBar($('portal').getElementsByClassName('pbBarprogress')[0]);
			}
			
			section.id = idname+'_'+id;
			
		}.bind(this));
		
		this.idName = idname+'_';
	},
	
	switchSection : function (direction) {
				
		var prevSection = this.idName + (parseInt(this.currentSection));
		
		if (direction == 'next') {
			var nextSection = this.idName + (parseInt(this.currentSection+1));
			
			this.progressBar($('portal').getElementsByClassName('pbBarprogress')[(parseInt(this.currentSection+1))]);
			
		} else {
			var nextSection = this.idName + (parseInt(this.currentSection-1));
			
			this.progressBar($('portal').getElementsByClassName('pbBarprogress')[(parseInt(this.currentSection-1))]);
		}
		
		$(prevSection).hide();
		$(nextSection).show();
		
		if (direction == 'next') {
			this.currentSection = parseInt(this.currentSection+1);
		} else {
			this.currentSection = parseInt(this.currentSection-1);
		}
		
	},
	
	currentProgressItem : false,
	
	progressBar : function (item) {
		
		if (!item) return;
		
		if (this.currentProgressItem) {
			this.currentProgressItem.removeClassName('active');
		}
		
		item.addClassName('active');
		
		this.currentProgressItem = item;
		
	}
	
}

function checkTerms(directPost) {
	
	if ($('terms').checked) {
		
		if (directPost) {	
			document.form1.submit();
		} else {
			
			new Ajax.Updater('step_1', $('form1').action + '/payment=false', { evalScripts : true });
		}
		
	} else {
		alert('In order to continue you have to agree with the terms and conditions.');
		return false;
	}
}


var fileupload = Class.create({
	initialize: function(action, formid, fileid, events) {
		var _this = this;
		this.upload = new AjaxUpload('abfile', {
			action: action,
			name: 'abfile',
			data: {},
			autoSubmit: false,
			onChange: function(file, extension) {
				$(fileid).update('Upload: ' + file);
				if (events.onChange)
					events.onChange();
			},
			onSubmit: function(file, extension) {
				_this.upload.setData($(formid).serialize(true));
				if (events.onSubmit)
					events.onSubmit();
			},
			onComplete: function(file, response) {
				if (events.onComplete)
					events.onComplete(response);
			}
		});
	},
	go: function() {
		this.upload.submit();
	}
});

function submitNewsletter(data) {

	var error = 0;

	if ($('subscribe_name').value == '' || $('subscribe_name').value == 'Name') {
		alert('Please enter your name');
		error ++ ;
	}
	if ($('subscribe_email').value == '' || $('subscribe_email').value == 'E-mail') {
		alert('Please enter your e-mail');
		
		error ++ ;
	}

	if (error == 0) {

	new Ajax.Request($('newsletter_form').action, {
		method: 'post',
		onSuccess: function(transport) {
			$('message').innerHTML = transport.responseText;
			
			new Effect.Fade('subscribe_form', { duration: 0.3, afterFinish : function () {
				new Effect.Appear('message', {duration: 0.3});
			} });
			
			setTimeout(function() {
				new Effect.Fade('message', { duration: 0.3, afterFinish : function () {
					new Effect.Appear('subscribe_form', {duration: 0.3});
				} });
			},3500);
			
		},
		postBody : data
	});
	
	}
	
}

var SIDString = '';

function getRandomLetter() {
	return String.fromCharCode(getRandom(65, 90));
}

function getRandom(lowerBound, upperBound) {
	return Math.floor((upperBound - lowerBound + 1) * Math.random() + lowerBound);
}

function SetSID()
{
	if (SIDString.length > 0)
	{
		return SIDString;
	}

	sidc = 0;

	while (sidc < 32)
	{
		SIDString = SIDString + getRandomLetter();
		sidc++;
	}
	return SIDString;
}

function clearField(input, default_value) {
	
	if (input.value == '') {
		input.value = default_value;
	} else {
		input.value = input.value;
	}
	
	if (input.value == default_value) {
		input.value = '';
	}
}