function ajax_login (f) {
	new Ajax.Updater({ success: f.parentNode, failure: 'login-status' }, '/perl/ajax_login.pl', {
		parameters: Form.serialize($('login-form')),
		evalScripts: true

	});
	return false;
}
function ajax_logout (f) {
	new Ajax.Updater(f.parentNode, '/perl/ajax_login.pl', {
		parameters: Form.serialize($('logout-form')),
		evalScripts: true

	});
	return false;

}
function ENN_listing_reply (obj, id) {
	alert(obj.innerHTML);
}
var Listing = Class.create ({
	initialize: function (a) {
		this.a = $(a);
		this.url = a.href.replace(/listing/, "listing/ajax");
		this.lt = a.parentNode;
		this.ll = this.lt.parentNode;
		this.ld = Element.next(this.lt);

		Event.observe(this.a, 'click', this.show.bind(this));
	},
	show: function (event) {
		new Effect.BlindUp(this.ld, {duration: .5});
		new Effect.BlindUp(this.lt, {duration: .5});
		if(!this.tgt) {
			this.tgt = new Element('div').setStyle ({display:'none'});
			this.hidebutton = new Element('a', {href:'#'}).setStyle({cssFloat: 'right', marginRight: '10px'}).update("Hide Listing");
			this.hidebutton2 = new Element('a', {href:'#'}).setStyle({display: 'block', marginTop: '10px' }).update("Hide Listing");
			this.hidebutton.observe('click', this.hide.bind(this));
			this.hidebutton2.observe('click', this.hide.bind(this));
			this.tgt.appendChild($(this.hidebutton));
			this.ll.appendChild(this.tgt);
			new Ajax.Updater(this.tgt, this.url, {
					onComplete: function(response) {
						new Effect.BlindDown(this.tgt, {duration: .5});
						this.tgt.appendChild($(this.hidebutton2));
					}.bind(this),
					 insertion: Insertion.Bottom,
					 evalScripts: true
			});
		}
		else {
			new Effect.BlindDown(this.tgt, {duration: .5});
		}
		Event.stop(event);
	},
	hide: function (event) {
		new Effect.BlindUp(this.tgt, {duration: .5});
		new Effect.BlindDown(this.lt, {duration: .5});
		new Effect.BlindDown(this.ld, {duration: .5});
		Event.stop(event);
	}


	
});

function ENN_classifieds_print_listing (button,lli) {
	var llis = $$('div.listing-list-item');
	if (ENN_print_toggle_status == 'on') {
		$('section-description').show();
		for (var i = 0; i < llis.length; i++) {
			if (llis[i] != lli)
				$(llis[i]).show();
		}
		ENN_print_toggle(button);
		button.innerHTML = button.innerHTML.replace(/Restore View/, 'Print Listing');
	}
	else {
		$('section-description').hide();
		for (var i = 0; i < llis.length; i++) {
			if (llis[i] != lli)
				$(llis[i]).hide();
		}
		ENN_print_toggle(button);
		button.innerHTML = button.innerHTML.replace(/Print Listing/, 'Restore View');
		window.print();
	}
	

}

Event.observe(window,'load', function () {
	var lls = $$('div.ll-middle');
	for (var i = 0; i < lls.length; i++) {
		var as = lls[i].select('a');
		as.each(function(a) {new Listing(a)});
	}
});

Event.observe(window,'load', function () {
	var navs = $('nav-categories').select('a');
	for (var i = 0; i < navs.length; i++) {
		if(navs[i].innerHTML == ENN_section) {
			$(navs[i]).setStyle({background: 'black', color:'white'});
			$(navs[i].parentNode).setStyle({background: 'black', color:'white'});
		}
	}
});