var Property = Class.create();

Property.prototype = {
	initialize: function( el ){
		this.el = $(el);
		this.id = this.el.id.split('_')[1];
		try{
			var sendToFriends = this.el.getElementsByClassName( 'SendFriend', this.el );
			for( stfc=0; stfc<sendToFriends.length; stfc++ ){
				this.__init_sendToFriend( sendToFriends[stfc] );
			}
		}catch(e){}
	},
	sendToFriend: function( el ){
		var args = Form.serialize( el );
		args += '&link=' + document.location;
		new Ajax.Request(
			'/map_search/sendToFriend/',
			{
				method:'POST',
				parameters:args,
				onSuccess:this.cb_sendToFriend.bind(this, el),
				onError:this.eb_sendToFriend.bind(this, el)
			}
		);
	},
	cb_sendToFriend: function( xhr, ajax, el ){
		try{
			el.parentNode.select( '.ErrorMessage' )[0].innerHTML = 'The Message Has Been Sent.';
		}catch(e){}
	},
	eb_sendToFriend: function( xhr, ajax, el ){
		try{
			el.select( '.ErrorMessage' )[0].innerHTML = 'Error Soup';
		}catch(e){}
	},
	__init_sendToFriend: function( stf_el ){
		var btn = stf_el.select( '.Send' )[0];
		var form = stf_el.getElementsByTagName('form')[0];
		Event.observe( btn, 'click', this.sendToFriend.bind( this, form ) );
	}
}

Property.InitPage = function(){
	var props = $$('.property');
	for( propc=0; propc<props.length; propc++ ){
		try{ new Property( props[ propc ] ); }
		catch( e ){ alert(e); }
	}
}

Event.observe( window, 'load', Property.InitPage );