window.addEvent('domready', function() {
	if( document.id('main-div')){
			$('main-div').set('styles', {'display':'block'});
	}
		
	if (document.id('drop_down_menu')) {
		document.id('drop_down_menu').getElements('li.menu').each(
				function(elem) {
					var list = elem.getElement('ul.links');
					var alink = elem.getFirst('a');
					var pos = 'upperLeft';
					if (list) {
						list.inject(document.id('menu-container'), 'bottom');
						list.position( {
							position : pos,
							edge : pos,
							relativeTo : alink,
							offset : {
								x : 0,
								y : 29
							}
						});
						list.setStyle('display', 'block');
						list.fade('hide');
						list.addEvents( {
							'mouseenter' : function() {
								list.fade('in');
								alink.addClass('active');
							},
							'mouseleave' : function() {
								list.fade('out');
								alink.removeClass('active');
							}
						});
						elem.addEvents( {
							'mouseenter' : function() {
								list.fade('in');
							},
							'mouseleave' : function() {
								list.fade('out');
							}
						});
					}
				});
	}
	if (document.id('top_drop_down_menu')) {
		document.id('top_drop_down_menu').getElements('li.menu').each(
				function(elem) {
					var list = elem.getElement('ul.links');
					var alink = elem.getFirst('a');
					var pos = 'upperLeft';
					if (list) {
						list
								.inject(document.id('top-menu-container'),
										'bottom');
						list.position( {
							position : pos,
							edge : pos,
							relativeTo : alink,
							offset : {
								x : 0,
								y : 15
							}
						});
						list.setStyle('display', 'block');
						list.fade('hide');
						list.addEvents( {
							'mouseenter' : function() {
								list.fade('in');
								alink.addClass('active');
							},
							'mouseleave' : function() {
								list.fade('out');
								alink.removeClass('active');
							}
						});
						elem.addEvents( {
							'mouseenter' : function() {
								list.fade('in');
							},
							'mouseleave' : function() {
								list.fade('out');
							}
						});
					}
				});
	}

	resize_columns();

	var searchbox = $('search-text');
	if (searchbox) {
		searchbox.addEvents( {
			'focus' : function() {
				if ('Search' == this.getProperty('value')) {
					this.setProperty('value', '');
				}
			},
			'keyup' : function(sk) {
				if (sk.key == 'enter') {
					run_search();					
				}
			}
		});
	}
});

function resize_columns() {
	var footer_over = 0;
	var s1 = $(document.body).getElement('div.leftcol');
	var s2 = $(document.body).getElement('div.rightcol');
	if (s1.getSize().y > s2.getSize().y) {
		s2.set('styles', {
			'height' : s1.getSize().y + footer_over
		});
	} else {
		s1.set('styles', {
			'height' : s2.getSize().y - footer_over
		});
	}
}

function validate_email(thisform, field, alerttxt) {
	with (field) {
		apos = value.indexOf("@");
		dotpos = value.lastIndexOf(".");
		if (apos < 1 || dotpos - apos < 2) {			
			var error_place = thisform.getElement('.form-error-msg');
			if (error_place) {
				error_place.innerHTML = alerttxt;
			}
			return false;
		} else {
			return true;
		}
	}
}

function validate_form(thisform) {
	with (thisform) {
		if (typeof (email) != "undefined") {
			if (validate_email($(thisform), email, "Not a valid e-mail address!") == false) {
				email.focus();
				return false;
			}
		}
	}
}

