var HgContactForm = new Abstract();

HgContactForm.extend({
	
	/************************************
		Constructor
	************************************/
	Initialize: function(nameElement, emailElement, subjectElement, messageElement, modalPopup)
	{
		this.$_nameElement		= nameElement;
		this.$_emailElement		= emailElement;
		this.$_subjectElement	= subjectElement;
		this.$_messageElement	= messageElement;
		this.$_modalPopup		= modalPopup;
		
		this.$_modalPopup
			.addEvent('open', this._OnPopupOpen.bind(this))
			.addEvent('close', this._OnPopupClose.bind(this))
		;
	},
	
	/************************************
		Properties
	************************************/
	GetName: function()
	{
		return $(this.$_nameElement).value;
	},
	
	SetName: function(name)
	{
		$(this.$_nameElement).value = name;
		return this;
	},
	
	GetEmail: function()
	{
		return $(this.$_emailElement).value;
	},
	
	SetEmail: function(email)
	{
		$(this.$_emailElement).value = email;
		return this;
	},
	
	GetSubject: function()
	{
		return $(this.$_subjectElement).value;
	},
	
	SetSubject: function(subject)
	{
		$(this.$_subjectElement).value = subject;
		return this;
	},
	
	GetMessage: function()
	{
		return $(this.$_messageElement).value;
	},
	
	SetMessage: function(message)
	{
		$(this.$_messageElement).value = message;
		return this;
	},
	
	
	/************************************
		Private Methods
	************************************/
	_HideForm: function()
	{
		var children = $('HgContactForm').getChildren()[0].getChildren();
			
		var
			effect1 = new Fx.Styles(children[0], {duration:200, transition:Fx.Transitions.Quart.easeOut}),
			effect2 = new Fx.Styles(children[1], {duration:250, transition:Fx.Transitions.Quart.easeIn});
		
		effect1.start({
			'opacity':0
		});
		
		effect2.start({
			'opacity':1
		});
	},
	
	_ShowForm: function()
	{
		var children = $('HgContactForm').getChildren();
		
		if (children[0])
			children[0].setStyle('opacity', 1);
		
		if (children[1])
			children[1].setStyle('opacity', 0);
	},
	
	
	/************************************
		Public Methods
	************************************/
	Send: function()
	{
		var myAjax = new Ajax(
			'/ajax/sendenquiry',
			{
				method		: 'post',
				onComplete	: this._OnSendComplete.bind(this),
				data		: {
					'name'		: this.GetName(),
					'email'		: this.GetEmail(),
					'subject'	: this.GetSubject(),
					'message'	: this.GetMessage()
				}
			}
		);
		
		this._HideForm();
		myAjax.request();
	},
	
	ClearForm: function()
	{
		return this.SetName('').SetEmail('').SetSubject('').SetMessage('');
	},
	
	
	/************************************
		Event Handling
	************************************/
	_OnSendComplete: function()
	{
		this.$_modalPopup.Hide();
		this.ClearForm();
	},
	
	_OnPopupOpen: function()
	{
		
	},
	
	_OnPopupClose: function()
	{
		this._ShowForm();
	}
});
